Index: content/browser/renderer_host/render_widget_host_impl.cc |
diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc |
index c715fcac51e35b0b9e381cd686dd1453f7b7ecc8..d6dd169379c26c6012820530a080d9e1e0f9db13 100644 |
--- a/content/browser/renderer_host/render_widget_host_impl.cc |
+++ b/content/browser/renderer_host/render_widget_host_impl.cc |
@@ -209,7 +209,8 @@ RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, |
allow_privileged_mouse_lock_(false), |
has_touch_handler_(false), |
weak_factory_(this), |
- last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32) { |
+ last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32), |
+ next_window_snapshot_id_(0) { |
CHECK(delegate_); |
if (routing_id_ == MSG_ROUTING_NONE) { |
routing_id_ = process_->GetNextRoutingID(); |
@@ -2402,8 +2403,16 @@ void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { |
if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, |
GetLatencyComponentId(), |
&window_snapshot_component)) { |
- WindowSnapshotReachedScreen( |
- static_cast<int>(window_snapshot_component.sequence_number)); |
+ // While GpuBenchmarking V8 extension coexists with Page.captureScreenshot |
+ // they share the same LatencyComponentType. To avoid confusion only one |
+ // of the two methods should be used when testing a specific renderer. |
+ // TODO(kaznacheev): Remove this method when GpuBenchmarking V8 extension is |
+ // retired. |
+ int id = static_cast<int>(window_snapshot_component.sequence_number); |
+ if (pending_window_snapshots_.count(id)) |
+ WindowSnapshotReachedScreen(id); |
+ else |
+ WindowSnapshotReachedScreenUnsafe(id); |
} |
ui::LatencyInfo::LatencyComponent rwh_component; |
@@ -2442,6 +2451,13 @@ void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
view_->DidReceiveRendererFrame(); |
} |
+void RenderWidgetHostImpl::RequestWindowSnapshot( |
+ const WindowSnapshotCallback& callback) { |
+ int id = next_window_snapshot_id_++; |
+ pending_window_snapshots_.insert(std::make_pair(id, callback)); |
+ Send(new ViewMsg_ForceRedraw(GetRoutingID(), id)); |
+} |
+ |
void RenderWidgetHostImpl::WindowSnapshotAsyncCallback( |
int routing_id, |
int snapshot_id, |
@@ -2458,7 +2474,7 @@ void RenderWidgetHostImpl::WindowSnapshotAsyncCallback( |
routing_id, snapshot_id, snapshot_size, png_data->data())); |
} |
-void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { |
+void RenderWidgetHostImpl::WindowSnapshotReachedScreenUnsafe(int snapshot_id) { |
DCHECK(base::MessageLoopForUI::IsCurrent()); |
std::vector<unsigned char> png; |
@@ -2494,6 +2510,53 @@ void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { |
snapshot_size)); |
} |
+void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { |
+ DCHECK(base::MessageLoopForUI::IsCurrent()); |
+ |
+ gfx::Rect view_bounds = GetView()->GetViewBounds(); |
+ gfx::Rect snapshot_bounds(view_bounds.size()); |
+ |
+ std::vector<unsigned char> png; |
+ if (ui::GrabViewSnapshot( |
+ GetView()->GetNativeView(), &png, snapshot_bounds)) { |
+ OnSnapshotDataReceived(snapshot_id, &png.front(), png.size()); |
+ return; |
+ } |
+ |
+ ui::GrabViewSnapshotAsync( |
+ GetView()->GetNativeView(), |
+ snapshot_bounds, |
+ base::ThreadTaskRunnerHandle::Get(), |
+ base::Bind(&RenderWidgetHostImpl::OnSnapshotDataReceivedAsync, |
+ weak_factory_.GetWeakPtr(), |
+ snapshot_id)); |
+} |
+ |
+void RenderWidgetHostImpl::OnSnapshotDataReceived(int snapshot_id, |
+ const unsigned char* data, |
+ size_t size) { |
+ // Any pending snapshots with a lower ID than the one received are considered |
+ // to be implicitly complete, and returned the same snapshot data. |
+ PendingSnapshotMap::iterator it = pending_window_snapshots_.begin(); |
+ while(it != pending_window_snapshots_.end()) { |
+ if (it->first <= snapshot_id) { |
+ it->second.Run(data, size); |
+ pending_window_snapshots_.erase(it++); |
+ } else { |
+ ++it; |
+ } |
+ } |
+} |
+ |
+void RenderWidgetHostImpl::OnSnapshotDataReceivedAsync( |
+ int snapshot_id, |
+ scoped_refptr<base::RefCountedBytes> png_data) { |
+ if (png_data) |
+ OnSnapshotDataReceived(snapshot_id, png_data->front(), png_data->size()); |
+ else |
+ OnSnapshotDataReceived(snapshot_id, NULL, 0); |
+} |
+ |
// static |
void RenderWidgetHostImpl::CompositorFrameDrawn( |
const std::vector<ui::LatencyInfo>& latency_info) { |