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

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

Issue 2592983002: [devtools] Support different encodings for Page.CaptureScreenshot. (Closed)
Patch Set: fix return value description + rebase Created 4 years 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 8860791b51b005f240538873bcf57ad775c73536..a631af8831e35fb94ff6cba6acd0880f09dfa23f 100644
--- a/content/browser/renderer_host/render_widget_host_impl.cc
+++ b/content/browser/renderer_host/render_widget_host_impl.cc
@@ -2351,38 +2351,37 @@ void RenderWidgetHostImpl::DidReceiveRendererFrame() {
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(
pfeldman 2016/12/22 18:07:41 The idea behind this grab method is that we test t
- GetView()->GetNativeView(), &png, snapshot_bounds)) {
- OnSnapshotDataReceived(snapshot_id, &png.front(), png.size());
+ GetView()->CopyFromCompositingSurface(
+ gfx::Rect(), gfx::Size(),
+ base::Bind(&RenderWidgetHostImpl::OnSnapshotReceived,
+ weak_factory_.GetWeakPtr(), snapshot_id, 0),
+ kN32_SkColorType);
+}
+
+void RenderWidgetHostImpl::OnSnapshotReceived(int snapshot_id,
+ int retry_count,
+ const SkBitmap& bitmap,
+ ReadbackResponse response) {
+ static const int kMaxRetries = 5;
+ if (response != READBACK_SUCCESS && retry_count < kMaxRetries) {
+ GetView()->CopyFromCompositingSurface(
+ gfx::Rect(), gfx::Size(),
+ base::Bind(&RenderWidgetHostImpl::OnSnapshotReceived,
+ weak_factory_.GetWeakPtr(), snapshot_id, retry_count + 1),
+ kN32_SkColorType);
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;
- }
+ if (it->first <= snapshot_id) {
+ it->second.Run(bitmap);
+ pending_browser_snapshots_.erase(it++);
+ } else {
+ ++it;
+ }
}
#if defined(OS_MACOSX)
if (pending_browser_snapshots_.empty())
@@ -2390,15 +2389,6 @@ void RenderWidgetHostImpl::OnSnapshotDataReceived(int snapshot_id,
#endif
}
-void RenderWidgetHostImpl::OnSnapshotDataReceivedAsync(
- int snapshot_id,
- scoped_refptr<base::RefCountedBytes> png_data) {
- if (png_data.get())
- 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