Add RenderWidgetHost::GetSnapshotFromRenderer method to content/ interface for snapshotting for cases where we might not be able to use CopyFromBackingStore because the browser side can't access the backing store or accelerated surface due to driver issues or WinXP.
Consolidate renderer-side snapshotting into that method and move clients (tabsApi, tabCapture and NTP) to the new method.
Let the Linux CopyFromCompositingSurface always use this since the current one is incorrect if the tab is in the background or is covered by a window.
Remove Linux-GTK snapshotting workarounds.
BUG=188867, 174957, 132301
Review URL: https://codereview.chromium.org/12881005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189969 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
index 425d943e8..60fbd38 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -321,6 +321,7 @@
IPC_MESSAGE_HANDLER(ViewMsg_ImeBatchStateChanged, OnImeBatchStateChanged)
IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
#endif
+ IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -1820,6 +1821,50 @@
Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
}
+void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) {
+ SkBitmap snapshot;
+
+ if (OnSnapshotHelper(src_subrect, &snapshot)) {
+ Send(new ViewHostMsg_Snapshot(routing_id(), true, snapshot));
+ } else {
+ Send(new ViewHostMsg_Snapshot(routing_id(), false, SkBitmap()));
+ }
+}
+
+bool RenderWidget::OnSnapshotHelper(const gfx::Rect& src_subrect,
+ SkBitmap* snapshot) {
+ base::TimeTicks beginning_time = base::TimeTicks::Now();
+
+ if (!webwidget_ || src_subrect.IsEmpty())
+ return false;
+
+ gfx::Rect viewport_size = gfx::IntersectRects(
+ src_subrect, gfx::Rect(physical_backing_size_));
+
+ skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(
+ skia::CreatePlatformCanvas(viewport_size.width(),
+ viewport_size.height(),
+ true,
+ NULL,
+ skia::RETURN_NULL_ON_FAILURE));
+ if (!canvas.get())
+ return false;
+
+ canvas->save();
+ webwidget_->layout();
+
+ PaintRect(viewport_size, viewport_size.origin(), canvas.get());
+ canvas->restore();
+
+ const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false);
+ if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
+ return false;
+
+ UMA_HISTOGRAM_TIMES("Renderer4.Snapshot",
+ base::TimeTicks::Now() - beginning_time);
+ return true;
+}
+
void RenderWidget::OnRepaint(const gfx::Size& size_to_paint) {
// During shutdown we can just ignore this message.
if (!webwidget_)