Chromium Code Reviews| Index: content/renderer/render_view_impl.cc |
| diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc |
| index 6578cd88cc32fd13c51f6a9b28eb23dc2ec6a2cd..7bdf278df97fc50af28fc2877cb3b22982d8e7cd 100644 |
| --- a/content/renderer/render_view_impl.cc |
| +++ b/content/renderer/render_view_impl.cc |
| @@ -1116,6 +1116,7 @@ bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
| OnReleaseDisambiguationPopupDIB) |
| IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted, |
| OnWindowSnapshotCompleted) |
| + IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot) |
| // Have the super handle all other messages. |
| IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
| @@ -1899,6 +1900,55 @@ void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id, |
| pending_snapshots_.erase(it); |
| } |
| +namespace { |
| + |
| +bool CaptureSnapshot(WebView* view, |
| + const gfx::Rect& src_subrect, |
| + SkBitmap* snapshot) { |
| + base::TimeTicks beginning_time = base::TimeTicks::Now(); |
| + |
| + view->layout(); |
| + const WebSize& size = view->size(); |
|
jamesr
2013/03/18 22:41:18
I'm not sure about this - the size of a WebWidget
justinlin
2013/03/18 23:27:51
Done. Yea, this old stuff didn't really work with
|
| + gfx::Rect viewport_size = gfx::IntersectRects( |
| + src_subrect, gfx::Rect(size.width, size.height)); |
| + |
| + skia::RefPtr<SkCanvas> canvas = skia::AdoptRef( |
| + skia::CreatePlatformCanvas(viewport_size.width(), |
| + viewport_size.height(), |
| + true, |
| + NULL, |
| + skia::RETURN_NULL_ON_FAILURE)); |
| + if (!canvas) |
| + return false; |
| + |
| + view->paint(webkit_glue::ToWebCanvas(canvas.get()), viewport_size); |
| + |
| + 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; |
| +} |
| + |
| +} // namespace |
| + |
| +void RenderViewImpl::OnSnapshot(const gfx::Rect& src_subrect) { |
| + SkBitmap snapshot; |
| + bool error = false; |
| + |
| + if (!webview()->mainFrame() || !CaptureSnapshot(webview(), |
| + src_subrect, |
| + &snapshot)) |
| + error = true; |
| + |
| + DCHECK(error == snapshot.empty()) << |
| + "Snapshot should be empty on error, non-empty otherwise."; |
| + |
| + Send(new ViewHostMsg_Snapshot(routing_id_, !error, snapshot)); |
| +} |
| + |
| // WebKit::WebViewClient ------------------------------------------------------ |
| WebView* RenderViewImpl::createView( |