Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1348)

Unified Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 190693002: Migrate Telemetry from beginWindowSnapshotPNG to Page.captureScreenshot (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Aligned with the existing API Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 73c306d28292d3d19feb1d8aec5d5d9ba7fa3633..d4c2c7bb516d06c42f24217e59c2769009b139c3 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_browser_snapshot_id_(0) {
CHECK(delegate_);
if (routing_id_ == MSG_ROUTING_NONE) {
routing_id_ = process_->GetNextRoutingID();
@@ -1225,6 +1226,13 @@ void RenderWidgetHostImpl::GetSnapshotFromRenderer(
Send(new ViewMsg_Snapshot(GetRoutingID(), copy_rect_in_pixel));
}
+void RenderWidgetHostImpl::GetSnapshotFromBrowser(
+ const base::Callback<void(const unsigned char*,size_t)> callback) {
+ int id = next_browser_snapshot_id_++;
+ pending_browser_snapshots_.insert(std::make_pair(id, callback));
+ Send(new ViewMsg_ForceRedraw(GetRoutingID(), id));
+}
+
void RenderWidgetHostImpl::OnSnapshot(bool success,
const SkBitmap& bitmap) {
if (pending_snapshots_.size() == 0) {
@@ -2387,8 +2395,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.
Ken Russell (switch to Gerrit) 2014/03/11 18:22:29 That's a non-intuitive restriction that leaves the
Vladislav Kaznacheev 2014/03/12 09:24:24 Fair enough. I will try and remove the old GPU ben
+ // TODO(kaznacheev): Remove this method when GpuBenchmarking V8 extension is
+ // retired.
+ int id = static_cast<int>(window_snapshot_component.sequence_number);
+ if (pending_browser_snapshots_.count(id))
+ WindowSnapshotReachedScreen(id);
+ else
+ WindowSnapshotReachedScreenUnsafe(id);
}
ui::LatencyInfo::LatencyComponent rwh_component;
@@ -2443,7 +2459,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;
@@ -2479,6 +2495,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_browser_snapshots_.begin();
+ while(it != pending_browser_snapshots_.end()) {
+ if (it->first <= snapshot_id) {
+ it->second.Run(data, size);
+ pending_browser_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) {

Powered by Google App Engine
This is Rietveld 408576698