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

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

Issue 127103002: Make WindowReachedScreen support async readback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mac /o\ Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | ui/snapshot/snapshot.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/auto_reset.h" 11 #include "base/auto_reset.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/containers/hash_tables.h" 14 #include "base/containers/hash_tables.h"
15 #include "base/debug/trace_event.h" 15 #include "base/debug/trace_event.h"
16 #include "base/i18n/rtl.h" 16 #include "base/i18n/rtl.h"
17 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
18 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
19 #include "base/metrics/field_trial.h" 19 #include "base/metrics/field_trial.h"
20 #include "base/metrics/histogram.h" 20 #include "base/metrics/histogram.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "base/thread_task_runner_handle.h"
23 #include "cc/output/compositor_frame.h" 24 #include "cc/output/compositor_frame.h"
24 #include "cc/output/compositor_frame_ack.h" 25 #include "cc/output/compositor_frame_ack.h"
25 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 26 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
26 #include "content/browser/gpu/compositor_util.h" 27 #include "content/browser/gpu/compositor_util.h"
27 #include "content/browser/gpu/gpu_process_host.h" 28 #include "content/browser/gpu/gpu_process_host.h"
28 #include "content/browser/gpu/gpu_process_host_ui_shim.h" 29 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
29 #include "content/browser/gpu/gpu_surface_tracker.h" 30 #include "content/browser/gpu/gpu_surface_tracker.h"
30 #include "content/browser/renderer_host/backing_store.h" 31 #include "content/browser/renderer_host/backing_store.h"
31 #include "content/browser/renderer_host/backing_store_manager.h" 32 #include "content/browser/renderer_host/backing_store_manager.h"
32 #include "content/browser/renderer_host/dip_util.h" 33 #include "content/browser/renderer_host/dip_util.h"
(...skipping 2383 matching lines...) Expand 10 before | Expand all | Expand 10 after
2416 2417
2417 if (CommandLine::ForCurrentProcess()->HasSwitch( 2418 if (CommandLine::ForCurrentProcess()->HasSwitch(
2418 switches::kEnableGpuBenchmarking)) 2419 switches::kEnableGpuBenchmarking))
2419 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); 2420 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_));
2420 } 2421 }
2421 2422
2422 void RenderWidgetHostImpl::DidReceiveRendererFrame() { 2423 void RenderWidgetHostImpl::DidReceiveRendererFrame() {
2423 view_->DidReceiveRendererFrame(); 2424 view_->DidReceiveRendererFrame();
2424 } 2425 }
2425 2426
2427 void RenderWidgetHostImpl::WindowSnapshotAsyncCallback(
2428 int routing_id,
2429 int snapshot_id,
2430 gfx::Size snapshot_size,
2431 scoped_refptr<base::RefCountedBytes> png_data) {
2432 if (!png_data) {
2433 std::vector<unsigned char> png_vector;
2434 Send(new ViewMsg_WindowSnapshotCompleted(
2435 routing_id, snapshot_id, gfx::Size(), png_vector));
2436 return;
2437 }
2438
2439 Send(new ViewMsg_WindowSnapshotCompleted(
2440 routing_id, snapshot_id, snapshot_size, png_data->data()));
2441 }
2442
2426 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { 2443 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) {
2427 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_UI)); 2444 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_UI));
2428 2445
2429 std::vector<unsigned char> png; 2446 std::vector<unsigned char> png;
2430 2447
2431 // This feature is behind the kEnableGpuBenchmarking command line switch 2448 // This feature is behind the kEnableGpuBenchmarking command line switch
2432 // because it poses security concerns and should only be used for testing. 2449 // because it poses security concerns and should only be used for testing.
2433 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 2450 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2434 if (command_line.HasSwitch(switches::kEnableGpuBenchmarking)) { 2451 if (!command_line.HasSwitch(switches::kEnableGpuBenchmarking)) {
2435 gfx::Rect view_bounds = GetView()->GetViewBounds(); 2452 Send(new ViewMsg_WindowSnapshotCompleted(
2436 gfx::Rect snapshot_bounds(view_bounds.size()); 2453 GetRoutingID(), snapshot_id, gfx::Size(), png));
2437 gfx::Size snapshot_size = snapshot_bounds.size(); 2454 return;
2438
2439 if (ui::GrabViewSnapshot(GetView()->GetNativeView(),
2440 &png, snapshot_bounds)) {
2441 Send(new ViewMsg_WindowSnapshotCompleted(
2442 GetRoutingID(), snapshot_id, snapshot_size, png));
2443 return;
2444 }
2445 } 2455 }
2446 2456
2447 Send(new ViewMsg_WindowSnapshotCompleted( 2457 gfx::Rect view_bounds = GetView()->GetViewBounds();
2448 GetRoutingID(), snapshot_id, gfx::Size(), png)); 2458 gfx::Rect snapshot_bounds(view_bounds.size());
2459 gfx::Size snapshot_size = snapshot_bounds.size();
2460
2461 if (ui::GrabViewSnapshot(
2462 GetView()->GetNativeView(), &png, snapshot_bounds)) {
2463 Send(new ViewMsg_WindowSnapshotCompleted(
2464 GetRoutingID(), snapshot_id, snapshot_size, png));
2465 return;
2466 }
2467
2468 ui::GrabViewSnapshotAsync(
2469 GetView()->GetNativeView(),
2470 snapshot_bounds,
2471 base::ThreadTaskRunnerHandle::Get(),
2472 base::Bind(&RenderWidgetHostImpl::WindowSnapshotAsyncCallback,
2473 weak_factory_.GetWeakPtr(),
2474 GetRoutingID(),
2475 snapshot_id,
2476 snapshot_size));
2449 } 2477 }
2450 2478
2451 // static 2479 // static
2452 void RenderWidgetHostImpl::CompositorFrameDrawn( 2480 void RenderWidgetHostImpl::CompositorFrameDrawn(
2453 const ui::LatencyInfo& latency_info) { 2481 const ui::LatencyInfo& latency_info) {
2454 std::set<RenderWidgetHostImpl*> rwhi_set; 2482 std::set<RenderWidgetHostImpl*> rwhi_set;
2455 2483
2456 for (ui::LatencyInfo::LatencyMap::const_iterator b = 2484 for (ui::LatencyInfo::LatencyMap::const_iterator b =
2457 latency_info.latency_components.begin(); 2485 latency_info.latency_components.begin();
2458 b != latency_info.latency_components.end(); 2486 b != latency_info.latency_components.end();
2459 ++b) { 2487 ++b) {
2460 if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || 2488 if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT ||
2461 b->first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT) { 2489 b->first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT) {
2462 // Matches with GetLatencyComponentId 2490 // Matches with GetLatencyComponentId
2463 int routing_id = b->first.second & 0xffffffff; 2491 int routing_id = b->first.second & 0xffffffff;
2464 int process_id = (b->first.second >> 32) & 0xffffffff; 2492 int process_id = (b->first.second >> 32) & 0xffffffff;
2465 RenderWidgetHost* rwh = 2493 RenderWidgetHost* rwh =
2466 RenderWidgetHost::FromID(process_id, routing_id); 2494 RenderWidgetHost::FromID(process_id, routing_id);
2467 if (!rwh) { 2495 if (!rwh) {
2468 continue; 2496 continue;
2469 } 2497 }
2470 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); 2498 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
2471 if (rwhi_set.insert(rwhi).second) 2499 if (rwhi_set.insert(rwhi).second)
2472 rwhi->FrameSwapped(latency_info); 2500 rwhi->FrameSwapped(latency_info);
2473 } 2501 }
2474 } 2502 }
2475 } 2503 }
2476 2504
2477 } // namespace content 2505 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | ui/snapshot/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698