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

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 2732923002: Add fromSurface optional parameter to devtools Page.CaptureScreenshot (Closed)
Patch Set: added from_surface parameter to GetSnapshotFromBrowser Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/render_widget_host_impl.h" 5 #include "content/browser/renderer_host/render_widget_host_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <set> 9 #include <set>
10 #include <tuple> 10 #include <tuple>
(...skipping 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 // factor). 1412 // factor).
1413 WasResized(); 1413 WasResized();
1414 1414
1415 if (touch_emulator_) { 1415 if (touch_emulator_) {
1416 touch_emulator_->SetDeviceScaleFactor( 1416 touch_emulator_->SetDeviceScaleFactor(
1417 view_.get() ? content::GetScaleFactorForView(view_.get()) : 1.0f); 1417 view_.get() ? content::GetScaleFactorForView(view_.get()) : 1.0f);
1418 } 1418 }
1419 } 1419 }
1420 1420
1421 void RenderWidgetHostImpl::GetSnapshotFromBrowser( 1421 void RenderWidgetHostImpl::GetSnapshotFromBrowser(
1422 const GetSnapshotFromBrowserCallback& callback) { 1422 const GetSnapshotFromBrowserCallback& callback,
1423 bool from_surface) {
1423 int id = next_browser_snapshot_id_++; 1424 int id = next_browser_snapshot_id_++;
1425 if (from_surface) {
1426 pending_surface_browser_snapshots_.insert(std::make_pair(id, callback));
1427 ui::LatencyInfo latency_info;
1428 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 0,
1429 id);
1430 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info));
1431 return;
1432 }
1424 1433
1425 #if defined(OS_MACOSX) 1434 #if defined(OS_MACOSX)
1426 // MacOS version of underlying GrabViewSnapshot() blocks while 1435 // MacOS version of underlying GrabViewSnapshot() blocks while
1427 // display/GPU are in a power-saving mode, so make sure display 1436 // display/GPU are in a power-saving mode, so make sure display
1428 // does not go to sleep for the duration of reading a snapshot. 1437 // does not go to sleep for the duration of reading a snapshot.
1429 if (pending_browser_snapshots_.empty()) { 1438 if (pending_browser_snapshots_.empty()) {
1430 DCHECK(!power_save_blocker_); 1439 DCHECK(!power_save_blocker_);
1431 power_save_blocker_.reset(new device::PowerSaveBlocker( 1440 power_save_blocker_.reset(new device::PowerSaveBlocker(
1432 device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, 1441 device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
1433 device::PowerSaveBlocker::kReasonOther, "GetSnapshot", 1442 device::PowerSaveBlocker::kReasonOther, "GetSnapshot",
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after
2336 is_running_navigation_hint_task); 2345 is_running_navigation_hint_task);
2337 } 2346 }
2338 2347
2339 void RenderWidgetHostImpl::DidReceiveRendererFrame() { 2348 void RenderWidgetHostImpl::DidReceiveRendererFrame() {
2340 view_->DidReceiveRendererFrame(); 2349 view_->DidReceiveRendererFrame();
2341 } 2350 }
2342 2351
2343 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { 2352 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) {
2344 DCHECK(base::MessageLoopForUI::IsCurrent()); 2353 DCHECK(base::MessageLoopForUI::IsCurrent());
2345 2354
2355 if (!pending_surface_browser_snapshots_.empty()) {
2356 GetView()->CopyFromSurface(
2357 gfx::Rect(), gfx::Size(),
2358 base::Bind(&RenderWidgetHostImpl::OnSnapshotFromSurfaceReceived,
2359 weak_factory_.GetWeakPtr(), snapshot_id, 0),
2360 kN32_SkColorType);
2361 }
2362
2363 if (!pending_browser_snapshots_.empty()) {
2346 #if defined(OS_ANDROID) 2364 #if defined(OS_ANDROID)
2347 // On Android, call sites should pass in the bounds with correct offset 2365 // On Android, call sites should pass in the bounds with correct offset
2348 // to capture the intended content area. 2366 // to capture the intended content area.
2349 gfx::Rect snapshot_bounds(GetView()->GetViewBounds()); 2367 gfx::Rect snapshot_bounds(GetView()->GetViewBounds());
2350 snapshot_bounds.Offset(0, GetView()->GetNativeView()->content_offset().y()); 2368 snapshot_bounds.Offset(0, GetView()->GetNativeView()->content_offset().y());
2351 #else 2369 #else
2352 gfx::Rect snapshot_bounds(GetView()->GetViewBounds().size()); 2370 gfx::Rect snapshot_bounds(GetView()->GetViewBounds().size());
2353 #endif 2371 #endif
2354 2372
2355 gfx::Image image; 2373 gfx::Image image;
2356 if (ui::GrabViewSnapshot(GetView()->GetNativeView(), snapshot_bounds, 2374 if (ui::GrabViewSnapshot(GetView()->GetNativeView(), snapshot_bounds,
2357 &image)) { 2375 &image)) {
2358 OnSnapshotReceived(snapshot_id, image); 2376 OnSnapshotReceived(snapshot_id, image);
2377 return;
2378 }
2379
2380 ui::GrabViewSnapshotAsync(
2381 GetView()->GetNativeView(), snapshot_bounds,
2382 base::Bind(&RenderWidgetHostImpl::OnSnapshotReceived,
2383 weak_factory_.GetWeakPtr(), snapshot_id));
2384 }
2385 }
2386
2387 void RenderWidgetHostImpl::OnSnapshotFromSurfaceReceived(
2388 int snapshot_id,
2389 int retry_count,
2390 const SkBitmap& bitmap,
2391 ReadbackResponse response) {
2392 static const int kMaxRetries = 5;
2393 if (response != READBACK_SUCCESS && retry_count < kMaxRetries) {
2394 GetView()->CopyFromSurface(
2395 gfx::Rect(), gfx::Size(),
2396 base::Bind(&RenderWidgetHostImpl::OnSnapshotFromSurfaceReceived,
2397 weak_factory_.GetWeakPtr(), snapshot_id, retry_count + 1),
2398 kN32_SkColorType);
2359 return; 2399 return;
2360 } 2400 }
2361 2401 // If all retries have failed, we return an empty image.
2362 ui::GrabViewSnapshotAsync( 2402 gfx::Image image = gfx::Image();
dgozman 2017/03/10 21:28:17 nit: it's unnecessary to call default constructor:
dvallet 2017/03/12 22:35:34 Done
2363 GetView()->GetNativeView(), snapshot_bounds, 2403 if (response == READBACK_SUCCESS)
2364 base::Bind(&RenderWidgetHostImpl::OnSnapshotReceived, 2404 image = gfx::Image::CreateFrom1xBitmap(bitmap);
2365 weak_factory_.GetWeakPtr(), snapshot_id)); 2405 // Any pending snapshots with a lower ID than the one received are considered
2406 // to be implicitly complete, and returned the same snapshot data.
2407 PendingSnapshotMap::iterator it = pending_surface_browser_snapshots_.begin();
2408 while (it != pending_surface_browser_snapshots_.end()) {
2409 if (it->first <= snapshot_id) {
2410 it->second.Run(image);
2411 pending_surface_browser_snapshots_.erase(it++);
2412 } else {
2413 ++it;
2414 }
2415 }
2366 } 2416 }
2367 2417
2368 void RenderWidgetHostImpl::OnSnapshotReceived(int snapshot_id, 2418 void RenderWidgetHostImpl::OnSnapshotReceived(int snapshot_id,
2369 const gfx::Image& image) { 2419 const gfx::Image& image) {
2370 // Any pending snapshots with a lower ID than the one received are considered 2420 // Any pending snapshots with a lower ID than the one received are considered
2371 // to be implicitly complete, and returned the same snapshot data. 2421 // to be implicitly complete, and returned the same snapshot data.
2372 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin(); 2422 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin();
2373 while (it != pending_browser_snapshots_.end()) { 2423 while (it != pending_browser_snapshots_.end()) {
2374 if (it->first <= snapshot_id) { 2424 if (it->first <= snapshot_id) {
2375 it->second.Run(image); 2425 it->second.Run(image);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2497 // different from the receiver's. 2547 // different from the receiver's.
2498 file_system_file.url = 2548 file_system_file.url =
2499 GURL(storage::GetIsolatedFileSystemRootURIString( 2549 GURL(storage::GetIsolatedFileSystemRootURIString(
2500 file_system_url.origin(), filesystem_id, std::string()) 2550 file_system_url.origin(), filesystem_id, std::string())
2501 .append(register_name)); 2551 .append(register_name));
2502 file_system_file.filesystem_id = filesystem_id; 2552 file_system_file.filesystem_id = filesystem_id;
2503 } 2553 }
2504 } 2554 }
2505 2555
2506 } // namespace content 2556 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698