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

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

Issue 127103002: Make WindowReachedScreen support async readback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mac /o\ Created 6 years, 11 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
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | ui/snapshot/snapshot.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 05bcf4822cf398541dda22725d2e737c9a62ffb5..22dac055215c143e2479a6f29c933a3ede9c89b1 100644
--- a/content/browser/renderer_host/render_widget_host_impl.cc
+++ b/content/browser/renderer_host/render_widget_host_impl.cc
@@ -20,6 +20,7 @@
#include "base/metrics/histogram.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/thread_task_runner_handle.h"
#include "cc/output/compositor_frame.h"
#include "cc/output/compositor_frame_ack.h"
#include "content/browser/accessibility/browser_accessibility_state_impl.h"
@@ -2423,6 +2424,22 @@ void RenderWidgetHostImpl::DidReceiveRendererFrame() {
view_->DidReceiveRendererFrame();
}
+void RenderWidgetHostImpl::WindowSnapshotAsyncCallback(
+ int routing_id,
+ int snapshot_id,
+ gfx::Size snapshot_size,
+ scoped_refptr<base::RefCountedBytes> png_data) {
+ if (!png_data) {
+ std::vector<unsigned char> png_vector;
+ Send(new ViewMsg_WindowSnapshotCompleted(
+ routing_id, snapshot_id, gfx::Size(), png_vector));
+ return;
+ }
+
+ Send(new ViewMsg_WindowSnapshotCompleted(
+ routing_id, snapshot_id, snapshot_size, png_data->data()));
+}
+
void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) {
DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_UI));
@@ -2431,21 +2448,32 @@ void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) {
// This feature is behind the kEnableGpuBenchmarking command line switch
// because it poses security concerns and should only be used for testing.
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
- if (command_line.HasSwitch(switches::kEnableGpuBenchmarking)) {
- gfx::Rect view_bounds = GetView()->GetViewBounds();
- gfx::Rect snapshot_bounds(view_bounds.size());
- gfx::Size snapshot_size = snapshot_bounds.size();
-
- if (ui::GrabViewSnapshot(GetView()->GetNativeView(),
- &png, snapshot_bounds)) {
- Send(new ViewMsg_WindowSnapshotCompleted(
- GetRoutingID(), snapshot_id, snapshot_size, png));
- return;
- }
+ if (!command_line.HasSwitch(switches::kEnableGpuBenchmarking)) {
+ Send(new ViewMsg_WindowSnapshotCompleted(
+ GetRoutingID(), snapshot_id, gfx::Size(), png));
+ return;
}
- Send(new ViewMsg_WindowSnapshotCompleted(
- GetRoutingID(), snapshot_id, gfx::Size(), png));
+ gfx::Rect view_bounds = GetView()->GetViewBounds();
+ gfx::Rect snapshot_bounds(view_bounds.size());
+ gfx::Size snapshot_size = snapshot_bounds.size();
+
+ if (ui::GrabViewSnapshot(
+ GetView()->GetNativeView(), &png, snapshot_bounds)) {
+ Send(new ViewMsg_WindowSnapshotCompleted(
+ GetRoutingID(), snapshot_id, snapshot_size, png));
+ return;
+ }
+
+ ui::GrabViewSnapshotAsync(
+ GetView()->GetNativeView(),
+ snapshot_bounds,
+ base::ThreadTaskRunnerHandle::Get(),
+ base::Bind(&RenderWidgetHostImpl::WindowSnapshotAsyncCallback,
+ weak_factory_.GetWeakPtr(),
+ GetRoutingID(),
+ snapshot_id,
+ snapshot_size));
}
// static
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | ui/snapshot/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698