Skip to content

Commit

Permalink
Make LatencyInfo to be class
Browse files Browse the repository at this point in the history
LatencyInfo has grown to be more than a pure data holder
struct. Make it a class so that we have a clean API
surface that can access/modify the data members.

BUG=None
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

Review URL: https://codereview.chromium.org/1245753003

Cr-Commit-Position: refs/heads/master@{#341831}
  • Loading branch information
yufengshen authored and Commit bot committed Aug 5, 2015
1 parent cbb29c5 commit 45effdc
Show file tree
Hide file tree
Showing 41 changed files with 471 additions and 305 deletions.
4 changes: 3 additions & 1 deletion cc/input/input_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class Vector2d;
class Vector2dF;
}

namespace ui { struct LatencyInfo; }
namespace ui {
class LatencyInfo;
}

namespace cc {

Expand Down
4 changes: 2 additions & 2 deletions cc/output/latency_info_swap_promise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ LatencyInfoSwapPromise::~LatencyInfoSwapPromise() {
}

void LatencyInfoSwapPromise::DidSwap(CompositorFrameMetadata* metadata) {
DCHECK(!latency_.terminated);
DCHECK(!latency_.terminated());
metadata->latency_info.push_back(latency_);
}

Expand All @@ -47,7 +47,7 @@ void LatencyInfoSwapPromise::DidNotSwap(DidNotSwapReason reason) {
}

int64 LatencyInfoSwapPromise::TraceId() const {
return latency_.trace_id;
return latency_.trace_id();
}

// Trace the original LatencyInfo of a LatencyInfoSwapPromise
Expand Down
4 changes: 3 additions & 1 deletion cc/output/output_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

namespace base { class SingleThreadTaskRunner; }

namespace ui { struct LatencyInfo; }
namespace ui {
class LatencyInfo;
}

namespace gfx {
class Rect;
Expand Down
8 changes: 3 additions & 5 deletions cc/surfaces/display.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,9 @@ bool Display::DrawAndSwap() {
if (should_swap) {
swapped_since_resize_ = true;
for (auto& latency : frame->metadata.latency_info) {
TRACE_EVENT_FLOW_STEP0(
"input,benchmark",
"LatencyInfo.Flow",
TRACE_ID_DONT_MANGLE(latency.trace_id),
"Display::DrawAndSwap");
TRACE_EVENT_FLOW_STEP0("input,benchmark", "LatencyInfo.Flow",
TRACE_ID_DONT_MANGLE(latency.trace_id()),
"Display::DrawAndSwap");
}
benchmark_instrumentation::IssueDisplayRenderingStatsEvent();
renderer_->SwapBuffers(frame->metadata);
Expand Down
2 changes: 1 addition & 1 deletion cc/surfaces/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "ui/gfx/geometry/size.h"

namespace ui {
struct LatencyInfo;
class LatencyInfo;
}

namespace cc {
Expand Down
6 changes: 3 additions & 3 deletions cc/trees/latency_info_swap_promise_monitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool AddForwardingScrollUpdateToMainComponent(ui::LatencyInfo* latency_info) {
return false;
latency_info->AddLatencyNumber(
ui::INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT, 0,
latency_info->trace_id);
latency_info->trace_id());
return true;
}

Expand Down Expand Up @@ -67,8 +67,8 @@ void LatencyInfoSwapPromiseMonitor::OnForwardScrollUpdateToMainThreadOnImpl() {
if (AddForwardingScrollUpdateToMainComponent(latency_)) {
int64 new_sequence_number = 0;
for (ui::LatencyInfo::LatencyMap::const_iterator it =
latency_->latency_components.begin();
it != latency_->latency_components.end(); ++it) {
latency_->latency_components().begin();
it != latency_->latency_components().end(); ++it) {
if (it->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT) {
new_sequence_number =
((static_cast<int64>(base::PlatformThread::CurrentId()) << 32) ^
Expand Down
2 changes: 1 addition & 1 deletion cc/trees/latency_info_swap_promise_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define CC_TREES_LATENCY_INFO_SWAP_PROMISE_MONITOR_H_

namespace ui {
struct LatencyInfo;
class LatencyInfo;
} // namespace ui

namespace cc {
Expand Down
8 changes: 3 additions & 5 deletions cc/trees/layer_tree_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1742,11 +1742,9 @@ bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) {
CompositorFrameMetadata metadata = MakeCompositorFrameMetadata();
active_tree()->FinishSwapPromises(&metadata);
for (auto& latency : metadata.latency_info) {
TRACE_EVENT_FLOW_STEP0(
"input,benchmark",
"LatencyInfo.Flow",
TRACE_ID_DONT_MANGLE(latency.trace_id),
"SwapBuffers");
TRACE_EVENT_FLOW_STEP0("input,benchmark", "LatencyInfo.Flow",
TRACE_ID_DONT_MANGLE(latency.trace_id()),
"SwapBuffers");
// Only add the latency component once for renderer swap, not the browser
// swap.
if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT,
Expand Down
5 changes: 3 additions & 2 deletions cc/trees/layer_tree_host_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,8 @@ TEST_F(LayerTreeHostImplTest, ImplPinchZoomWheelBubbleBetweenViewports) {

TEST_F(LayerTreeHostImplTest, ScrollWithSwapPromises) {
ui::LatencyInfo latency_info;
latency_info.trace_id = 1234;
latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 0,
1234);
scoped_ptr<SwapPromise> swap_promise(
new LatencyInfoSwapPromise(latency_info));

Expand All @@ -1382,7 +1383,7 @@ TEST_F(LayerTreeHostImplTest, ScrollWithSwapPromises) {

scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas();
EXPECT_EQ(1u, scroll_info->swap_promises.size());
EXPECT_EQ(latency_info.trace_id, scroll_info->swap_promises[0]->TraceId());
EXPECT_EQ(latency_info.trace_id(), scroll_info->swap_promises[0]->TraceId());
}

// Test that scrolls targeting a layer with a non-null scroll_parent() bubble
Expand Down
2 changes: 1 addition & 1 deletion content/browser/gpu/gpu_process_host_ui_shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params;
#endif

namespace ui {
struct LatencyInfo;
class LatencyInfo;
}

namespace gfx {
Expand Down
5 changes: 3 additions & 2 deletions content/browser/renderer_host/event_with_latency_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class EventWithLatencyInfo {
// When coalescing two input events, we keep the oldest LatencyInfo
// for Telemetry latency test since it will represent the longest
// latency.
if (other.latency.trace_id >= 0 &&
(latency.trace_id < 0 || other.latency.trace_id < latency.trace_id))
if (other.latency.trace_id() >= 0 &&
(latency.trace_id() < 0 ||
other.latency.trace_id() < latency.trace_id()))
latency = other.latency;
}
};
Expand Down
6 changes: 3 additions & 3 deletions content/browser/renderer_host/input/gesture_event_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void GestureEventQueue::QueueScrollOrPinchAndForwardIfNecessary(
scroll_event.event.sourceDevice = gesture_event.event.sourceDevice;
scroll_event.event.timeStampSeconds = gesture_event.event.timeStampSeconds;
// Keep the oldest LatencyInfo.
DCHECK_LE(last_event->latency.trace_id, gesture_event.latency.trace_id);
DCHECK_LE(last_event->latency.trace_id(), gesture_event.latency.trace_id());
scroll_event.latency = last_event->latency;
pinch_event = scroll_event;
scroll_event.event.type = WebInputEvent::GestureScrollUpdate;
Expand All @@ -355,8 +355,8 @@ void GestureEventQueue::QueueScrollOrPinchAndForwardIfNecessary(
coalesced_gesture_events_[coalesced_gesture_events_.size() - 2];
if (IsCompatibleScrollorPinch(gesture_event, second_last_event)) {
// Keep the oldest LatencyInfo.
DCHECK_LE(second_last_event.latency.trace_id,
scroll_event.latency.trace_id);
DCHECK_LE(second_last_event.latency.trace_id(),
scroll_event.latency.trace_id());
scroll_event.latency = second_last_event.latency;
pinch_event.latency = second_last_event.latency;
combined_scroll_pinch.PreconcatTransform(
Expand Down
2 changes: 1 addition & 1 deletion content/browser/renderer_host/input/input_router_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "third_party/WebKit/public/web/WebInputEvent.h"

namespace ui {
struct LatencyInfo;
class LatencyInfo;
}

namespace content {
Expand Down
2 changes: 1 addition & 1 deletion content/browser/renderer_host/input/input_router_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Sender;
}

namespace ui {
struct LatencyInfo;
class LatencyInfo;
}

namespace content {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,60 +18,57 @@ using ui::LatencyInfo;
namespace content {
namespace {

const uint32 kMaxInputCoordinates = LatencyInfo::kMaxInputCoordinates;

void UpdateLatencyCoordinatesImpl(const blink::WebTouchEvent& touch,
LatencyInfo* latency) {
latency->input_coordinates_size =
std::min(kMaxInputCoordinates, touch.touchesLength);
for (uint32 i = 0; i < latency->input_coordinates_size; ++i) {
latency->input_coordinates[i] = LatencyInfo::InputCoordinate(
touch.touches[i].position.x, touch.touches[i].position.y);
LatencyInfo* latency,
float device_scale_factor) {
for (uint32 i = 0; i < touch.touchesLength; ++i) {
LatencyInfo::InputCoordinate coordinate(
touch.touches[i].position.x * device_scale_factor,
touch.touches[i].position.y * device_scale_factor);
if (!latency->AddInputCoordinate(coordinate))
break;
}
}

void UpdateLatencyCoordinatesImpl(const WebGestureEvent& gesture,
LatencyInfo* latency) {
latency->input_coordinates_size = 1;
latency->input_coordinates[0] =
LatencyInfo::InputCoordinate(gesture.x, gesture.y);
LatencyInfo* latency,
float device_scale_factor) {
latency->AddInputCoordinate(
LatencyInfo::InputCoordinate(gesture.x * device_scale_factor,
gesture.y * device_scale_factor));
}

void UpdateLatencyCoordinatesImpl(const WebMouseEvent& mouse,
LatencyInfo* latency) {
latency->input_coordinates_size = 1;
latency->input_coordinates[0] =
LatencyInfo::InputCoordinate(mouse.x, mouse.y);
LatencyInfo* latency,
float device_scale_factor) {
latency->AddInputCoordinate(
LatencyInfo::InputCoordinate(mouse.x * device_scale_factor,
mouse.y * device_scale_factor));
}

void UpdateLatencyCoordinatesImpl(const WebMouseWheelEvent& wheel,
LatencyInfo* latency) {
latency->input_coordinates_size = 1;
latency->input_coordinates[0] =
LatencyInfo::InputCoordinate(wheel.x, wheel.y);
LatencyInfo* latency,
float device_scale_factor) {
latency->AddInputCoordinate(
LatencyInfo::InputCoordinate(wheel.x * device_scale_factor,
wheel.y * device_scale_factor));
}

void UpdateLatencyCoordinates(const WebInputEvent& event,
float device_scale_factor,
LatencyInfo* latency) {
if (WebInputEvent::isMouseEventType(event.type)) {
UpdateLatencyCoordinatesImpl(static_cast<const WebMouseEvent&>(event),
latency);
latency, device_scale_factor);
} else if (WebInputEvent::isGestureEventType(event.type)) {
UpdateLatencyCoordinatesImpl(static_cast<const WebGestureEvent&>(event),
latency);
latency, device_scale_factor);
} else if (WebInputEvent::isTouchEventType(event.type)) {
UpdateLatencyCoordinatesImpl(static_cast<const WebTouchEvent&>(event),
latency);
latency, device_scale_factor);
} else if (event.type == WebInputEvent::MouseWheel) {
UpdateLatencyCoordinatesImpl(static_cast<const WebMouseWheelEvent&>(event),
latency);
}
if (device_scale_factor == 1)
return;
for (uint32 i = 0; i < latency->input_coordinates_size; ++i) {
latency->input_coordinates[i].x *= device_scale_factor;
latency->input_coordinates[i].y *= device_scale_factor;
latency, device_scale_factor);
}
}

Expand Down Expand Up @@ -260,25 +257,29 @@ void ComputeScrollLatencyHistograms(
// component ID where necessary.
void AddLatencyInfoComponentIds(LatencyInfo* latency,
int64 latency_component_id) {
LatencyInfo::LatencyMap new_components;
auto lc = latency->latency_components.begin();
while (lc != latency->latency_components.end()) {
ui::LatencyComponentType component_type = lc->first.first;
std::vector<std::pair<ui::LatencyComponentType, int64>> new_components_key;
std::vector<LatencyInfo::LatencyComponent> new_components_value;
for (const auto& lc : latency->latency_components()) {
ui::LatencyComponentType component_type = lc.first.first;
if (component_type == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT) {
// Generate a new component entry with the correct component ID
auto key = std::make_pair(component_type, latency_component_id);
new_components[key] = lc->second;

// Remove the old entry
latency->latency_components.erase(lc++);
} else {
++lc;
new_components_key.push_back(std::make_pair(component_type,
latency_component_id));
new_components_value.push_back(lc.second);
}
}

// Remove the entries with invalid component IDs.
latency->RemoveLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT);

// Add newly generated components into the latency info
for (lc = new_components.begin(); lc != new_components.end(); ++lc) {
latency->latency_components[lc->first] = lc->second;
for (size_t i = 0; i < new_components_key.size(); i++) {
latency->AddLatencyNumberWithTimestamp(
new_components_key[i].first,
new_components_key[i].second,
new_components_value[i].sequence_number,
new_components_value[i].event_time,
new_components_value[i].event_count);
}
}

Expand Down
Loading

0 comments on commit 45effdc

Please sign in to comment.