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

Side by Side 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 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 2333 matching lines...) Expand 10 before | Expand all | Expand 10 after
2344 is_running_navigation_hint_task); 2344 is_running_navigation_hint_task);
2345 } 2345 }
2346 2346
2347 void RenderWidgetHostImpl::DidReceiveRendererFrame() { 2347 void RenderWidgetHostImpl::DidReceiveRendererFrame() {
2348 view_->DidReceiveRendererFrame(); 2348 view_->DidReceiveRendererFrame();
2349 } 2349 }
2350 2350
2351 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { 2351 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) {
2352 DCHECK(base::MessageLoopForUI::IsCurrent()); 2352 DCHECK(base::MessageLoopForUI::IsCurrent());
2353 2353
2354 gfx::Rect view_bounds = GetView()->GetViewBounds(); 2354 GetView()->CopyFromCompositingSurface(
2355 gfx::Rect snapshot_bounds(view_bounds.size()); 2355 gfx::Rect(), gfx::Size(),
2356 base::Bind(&RenderWidgetHostImpl::OnSnapshotReceived,
2357 weak_factory_.GetWeakPtr(), snapshot_id, 0),
2358 kN32_SkColorType);
2359 }
2356 2360
2357 std::vector<unsigned char> png; 2361 void RenderWidgetHostImpl::OnSnapshotReceived(int snapshot_id,
2358 if (ui::GrabViewSnapshot( 2362 int retry_count,
pfeldman 2016/12/22 18:07:41 The idea behind this grab method is that we test t
2359 GetView()->GetNativeView(), &png, snapshot_bounds)) { 2363 const SkBitmap& bitmap,
2360 OnSnapshotDataReceived(snapshot_id, &png.front(), png.size()); 2364 ReadbackResponse response) {
2365 static const int kMaxRetries = 5;
2366 if (response != READBACK_SUCCESS && retry_count < kMaxRetries) {
2367 GetView()->CopyFromCompositingSurface(
2368 gfx::Rect(), gfx::Size(),
2369 base::Bind(&RenderWidgetHostImpl::OnSnapshotReceived,
2370 weak_factory_.GetWeakPtr(), snapshot_id, retry_count + 1),
2371 kN32_SkColorType);
2361 return; 2372 return;
2362 } 2373 }
2363 2374
2364 ui::GrabViewSnapshotAsync(
2365 GetView()->GetNativeView(),
2366 snapshot_bounds,
2367 base::ThreadTaskRunnerHandle::Get(),
2368 base::Bind(&RenderWidgetHostImpl::OnSnapshotDataReceivedAsync,
2369 weak_factory_.GetWeakPtr(),
2370 snapshot_id));
2371 }
2372
2373 void RenderWidgetHostImpl::OnSnapshotDataReceived(int snapshot_id,
2374 const unsigned char* data,
2375 size_t size) {
2376 // Any pending snapshots with a lower ID than the one received are considered 2375 // Any pending snapshots with a lower ID than the one received are considered
2377 // to be implicitly complete, and returned the same snapshot data. 2376 // to be implicitly complete, and returned the same snapshot data.
2378 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin(); 2377 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin();
2379 while (it != pending_browser_snapshots_.end()) { 2378 while (it != pending_browser_snapshots_.end()) {
2380 if (it->first <= snapshot_id) { 2379 if (it->first <= snapshot_id) {
2381 it->second.Run(data, size); 2380 it->second.Run(bitmap);
2382 pending_browser_snapshots_.erase(it++); 2381 pending_browser_snapshots_.erase(it++);
2383 } else { 2382 } else {
2384 ++it; 2383 ++it;
2385 } 2384 }
2386 } 2385 }
2387 #if defined(OS_MACOSX) 2386 #if defined(OS_MACOSX)
2388 if (pending_browser_snapshots_.empty()) 2387 if (pending_browser_snapshots_.empty())
2389 power_save_blocker_.reset(); 2388 power_save_blocker_.reset();
2390 #endif 2389 #endif
2391 } 2390 }
2392 2391
2393 void RenderWidgetHostImpl::OnSnapshotDataReceivedAsync(
2394 int snapshot_id,
2395 scoped_refptr<base::RefCountedBytes> png_data) {
2396 if (png_data.get())
2397 OnSnapshotDataReceived(snapshot_id, png_data->front(), png_data->size());
2398 else
2399 OnSnapshotDataReceived(snapshot_id, NULL, 0);
2400 }
2401
2402 // static 2392 // static
2403 void RenderWidgetHostImpl::CompositorFrameDrawn( 2393 void RenderWidgetHostImpl::CompositorFrameDrawn(
2404 const std::vector<ui::LatencyInfo>& latency_info) { 2394 const std::vector<ui::LatencyInfo>& latency_info) {
2405 for (size_t i = 0; i < latency_info.size(); i++) { 2395 for (size_t i = 0; i < latency_info.size(); i++) {
2406 std::set<RenderWidgetHostImpl*> rwhi_set; 2396 std::set<RenderWidgetHostImpl*> rwhi_set;
2407 for (const auto& lc : latency_info[i].latency_components()) { 2397 for (const auto& lc : latency_info[i].latency_components()) {
2408 if (lc.first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || 2398 if (lc.first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT ||
2409 lc.first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT || 2399 lc.first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT ||
2410 lc.first.first == ui::TAB_SHOW_COMPONENT) { 2400 lc.first.first == ui::TAB_SHOW_COMPONENT) {
2411 // Matches with GetLatencyComponentId 2401 // Matches with GetLatencyComponentId
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2512 // different from the receiver's. 2502 // different from the receiver's.
2513 file_system_file.url = 2503 file_system_file.url =
2514 GURL(storage::GetIsolatedFileSystemRootURIString( 2504 GURL(storage::GetIsolatedFileSystemRootURIString(
2515 file_system_url.origin(), filesystem_id, std::string()) 2505 file_system_url.origin(), filesystem_id, std::string())
2516 .append(register_name)); 2506 .append(register_name));
2517 file_system_file.filesystem_id = filesystem_id; 2507 file_system_file.filesystem_id = filesystem_id;
2518 } 2508 }
2519 } 2509 }
2520 2510
2521 } // namespace content 2511 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698