OLD | NEW |
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 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 ignore_input_events_(false), | 202 ignore_input_events_(false), |
203 input_method_active_(false), | 203 input_method_active_(false), |
204 text_direction_updated_(false), | 204 text_direction_updated_(false), |
205 text_direction_(blink::WebTextDirectionLeftToRight), | 205 text_direction_(blink::WebTextDirectionLeftToRight), |
206 text_direction_canceled_(false), | 206 text_direction_canceled_(false), |
207 suppress_next_char_events_(false), | 207 suppress_next_char_events_(false), |
208 pending_mouse_lock_request_(false), | 208 pending_mouse_lock_request_(false), |
209 allow_privileged_mouse_lock_(false), | 209 allow_privileged_mouse_lock_(false), |
210 has_touch_handler_(false), | 210 has_touch_handler_(false), |
211 weak_factory_(this), | 211 weak_factory_(this), |
212 last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32) { | 212 last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32), |
| 213 next_window_snapshot_id_(0) { |
213 CHECK(delegate_); | 214 CHECK(delegate_); |
214 if (routing_id_ == MSG_ROUTING_NONE) { | 215 if (routing_id_ == MSG_ROUTING_NONE) { |
215 routing_id_ = process_->GetNextRoutingID(); | 216 routing_id_ = process_->GetNextRoutingID(); |
216 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( | 217 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( |
217 process_->GetID(), | 218 process_->GetID(), |
218 routing_id_); | 219 routing_id_); |
219 } else { | 220 } else { |
220 // TODO(piman): This is a O(N) lookup, where we could forward the | 221 // TODO(piman): This is a O(N) lookup, where we could forward the |
221 // information from the RenderWidgetHelper. The problem is that doing so | 222 // information from the RenderWidgetHelper. The problem is that doing so |
222 // currently leaks outside of content all the way to chrome classes, and | 223 // currently leaks outside of content all the way to chrome classes, and |
(...skipping 2172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2395 1000000, | 2396 1000000, |
2396 100); | 2397 100); |
2397 } | 2398 } |
2398 } | 2399 } |
2399 | 2400 |
2400 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { | 2401 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { |
2401 ui::LatencyInfo::LatencyComponent window_snapshot_component; | 2402 ui::LatencyInfo::LatencyComponent window_snapshot_component; |
2402 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, | 2403 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, |
2403 GetLatencyComponentId(), | 2404 GetLatencyComponentId(), |
2404 &window_snapshot_component)) { | 2405 &window_snapshot_component)) { |
2405 WindowSnapshotReachedScreen( | 2406 // While GpuBenchmarking V8 extension coexists with Page.captureScreenshot |
2406 static_cast<int>(window_snapshot_component.sequence_number)); | 2407 // they share the same LatencyComponentType. To avoid confusion only one |
| 2408 // of the two methods should be used when testing a specific renderer. |
| 2409 // TODO(kaznacheev): Remove this method when GpuBenchmarking V8 extension is |
| 2410 // retired. |
| 2411 int id = static_cast<int>(window_snapshot_component.sequence_number); |
| 2412 if (pending_window_snapshots_.count(id)) |
| 2413 WindowSnapshotReachedScreen(id); |
| 2414 else |
| 2415 WindowSnapshotReachedScreenUnsafe(id); |
2407 } | 2416 } |
2408 | 2417 |
2409 ui::LatencyInfo::LatencyComponent rwh_component; | 2418 ui::LatencyInfo::LatencyComponent rwh_component; |
2410 ui::LatencyInfo::LatencyComponent swap_component; | 2419 ui::LatencyInfo::LatencyComponent swap_component; |
2411 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | 2420 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
2412 GetLatencyComponentId(), | 2421 GetLatencyComponentId(), |
2413 &rwh_component) || | 2422 &rwh_component) || |
2414 !latency_info.FindLatency( | 2423 !latency_info.FindLatency( |
2415 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, | 2424 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, |
2416 0, &swap_component)) { | 2425 0, &swap_component)) { |
(...skipping 18 matching lines...) Expand all Loading... |
2435 1000000, | 2444 1000000, |
2436 100); | 2445 100); |
2437 } | 2446 } |
2438 } | 2447 } |
2439 } | 2448 } |
2440 | 2449 |
2441 void RenderWidgetHostImpl::DidReceiveRendererFrame() { | 2450 void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
2442 view_->DidReceiveRendererFrame(); | 2451 view_->DidReceiveRendererFrame(); |
2443 } | 2452 } |
2444 | 2453 |
| 2454 void RenderWidgetHostImpl::RequestWindowSnapshot( |
| 2455 const WindowSnapshotCallback& callback) { |
| 2456 int id = next_window_snapshot_id_++; |
| 2457 pending_window_snapshots_.insert(std::make_pair(id, callback)); |
| 2458 Send(new ViewMsg_ForceRedraw(GetRoutingID(), id)); |
| 2459 } |
| 2460 |
2445 void RenderWidgetHostImpl::WindowSnapshotAsyncCallback( | 2461 void RenderWidgetHostImpl::WindowSnapshotAsyncCallback( |
2446 int routing_id, | 2462 int routing_id, |
2447 int snapshot_id, | 2463 int snapshot_id, |
2448 gfx::Size snapshot_size, | 2464 gfx::Size snapshot_size, |
2449 scoped_refptr<base::RefCountedBytes> png_data) { | 2465 scoped_refptr<base::RefCountedBytes> png_data) { |
2450 if (!png_data) { | 2466 if (!png_data) { |
2451 std::vector<unsigned char> png_vector; | 2467 std::vector<unsigned char> png_vector; |
2452 Send(new ViewMsg_WindowSnapshotCompleted( | 2468 Send(new ViewMsg_WindowSnapshotCompleted( |
2453 routing_id, snapshot_id, gfx::Size(), png_vector)); | 2469 routing_id, snapshot_id, gfx::Size(), png_vector)); |
2454 return; | 2470 return; |
2455 } | 2471 } |
2456 | 2472 |
2457 Send(new ViewMsg_WindowSnapshotCompleted( | 2473 Send(new ViewMsg_WindowSnapshotCompleted( |
2458 routing_id, snapshot_id, snapshot_size, png_data->data())); | 2474 routing_id, snapshot_id, snapshot_size, png_data->data())); |
2459 } | 2475 } |
2460 | 2476 |
2461 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { | 2477 void RenderWidgetHostImpl::WindowSnapshotReachedScreenUnsafe(int snapshot_id) { |
2462 DCHECK(base::MessageLoopForUI::IsCurrent()); | 2478 DCHECK(base::MessageLoopForUI::IsCurrent()); |
2463 | 2479 |
2464 std::vector<unsigned char> png; | 2480 std::vector<unsigned char> png; |
2465 | 2481 |
2466 // This feature is behind the kEnableGpuBenchmarking command line switch | 2482 // This feature is behind the kEnableGpuBenchmarking command line switch |
2467 // because it poses security concerns and should only be used for testing. | 2483 // because it poses security concerns and should only be used for testing. |
2468 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 2484 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
2469 if (!command_line.HasSwitch(cc::switches::kEnableGpuBenchmarking)) { | 2485 if (!command_line.HasSwitch(cc::switches::kEnableGpuBenchmarking)) { |
2470 Send(new ViewMsg_WindowSnapshotCompleted( | 2486 Send(new ViewMsg_WindowSnapshotCompleted( |
2471 GetRoutingID(), snapshot_id, gfx::Size(), png)); | 2487 GetRoutingID(), snapshot_id, gfx::Size(), png)); |
(...skipping 15 matching lines...) Expand all Loading... |
2487 GetView()->GetNativeView(), | 2503 GetView()->GetNativeView(), |
2488 snapshot_bounds, | 2504 snapshot_bounds, |
2489 base::ThreadTaskRunnerHandle::Get(), | 2505 base::ThreadTaskRunnerHandle::Get(), |
2490 base::Bind(&RenderWidgetHostImpl::WindowSnapshotAsyncCallback, | 2506 base::Bind(&RenderWidgetHostImpl::WindowSnapshotAsyncCallback, |
2491 weak_factory_.GetWeakPtr(), | 2507 weak_factory_.GetWeakPtr(), |
2492 GetRoutingID(), | 2508 GetRoutingID(), |
2493 snapshot_id, | 2509 snapshot_id, |
2494 snapshot_size)); | 2510 snapshot_size)); |
2495 } | 2511 } |
2496 | 2512 |
| 2513 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { |
| 2514 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 2515 |
| 2516 gfx::Rect view_bounds = GetView()->GetViewBounds(); |
| 2517 gfx::Rect snapshot_bounds(view_bounds.size()); |
| 2518 |
| 2519 std::vector<unsigned char> png; |
| 2520 if (ui::GrabViewSnapshot( |
| 2521 GetView()->GetNativeView(), &png, snapshot_bounds)) { |
| 2522 OnSnapshotDataReceived(snapshot_id, &png.front(), png.size()); |
| 2523 return; |
| 2524 } |
| 2525 |
| 2526 ui::GrabViewSnapshotAsync( |
| 2527 GetView()->GetNativeView(), |
| 2528 snapshot_bounds, |
| 2529 base::ThreadTaskRunnerHandle::Get(), |
| 2530 base::Bind(&RenderWidgetHostImpl::OnSnapshotDataReceivedAsync, |
| 2531 weak_factory_.GetWeakPtr(), |
| 2532 snapshot_id)); |
| 2533 } |
| 2534 |
| 2535 void RenderWidgetHostImpl::OnSnapshotDataReceived(int snapshot_id, |
| 2536 const unsigned char* data, |
| 2537 size_t size) { |
| 2538 // Any pending snapshots with a lower ID than the one received are considered |
| 2539 // to be implicitly complete, and returned the same snapshot data. |
| 2540 PendingSnapshotMap::iterator it = pending_window_snapshots_.begin(); |
| 2541 while(it != pending_window_snapshots_.end()) { |
| 2542 if (it->first <= snapshot_id) { |
| 2543 it->second.Run(data, size); |
| 2544 pending_window_snapshots_.erase(it++); |
| 2545 } else { |
| 2546 ++it; |
| 2547 } |
| 2548 } |
| 2549 } |
| 2550 |
| 2551 void RenderWidgetHostImpl::OnSnapshotDataReceivedAsync( |
| 2552 int snapshot_id, |
| 2553 scoped_refptr<base::RefCountedBytes> png_data) { |
| 2554 if (png_data) |
| 2555 OnSnapshotDataReceived(snapshot_id, png_data->front(), png_data->size()); |
| 2556 else |
| 2557 OnSnapshotDataReceived(snapshot_id, NULL, 0); |
| 2558 } |
| 2559 |
2497 // static | 2560 // static |
2498 void RenderWidgetHostImpl::CompositorFrameDrawn( | 2561 void RenderWidgetHostImpl::CompositorFrameDrawn( |
2499 const std::vector<ui::LatencyInfo>& latency_info) { | 2562 const std::vector<ui::LatencyInfo>& latency_info) { |
2500 for (size_t i = 0; i < latency_info.size(); i++) { | 2563 for (size_t i = 0; i < latency_info.size(); i++) { |
2501 std::set<RenderWidgetHostImpl*> rwhi_set; | 2564 std::set<RenderWidgetHostImpl*> rwhi_set; |
2502 for (ui::LatencyInfo::LatencyMap::const_iterator b = | 2565 for (ui::LatencyInfo::LatencyMap::const_iterator b = |
2503 latency_info[i].latency_components.begin(); | 2566 latency_info[i].latency_components.begin(); |
2504 b != latency_info[i].latency_components.end(); | 2567 b != latency_info[i].latency_components.end(); |
2505 ++b) { | 2568 ++b) { |
2506 if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || | 2569 if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2541 } | 2604 } |
2542 } | 2605 } |
2543 | 2606 |
2544 // Add newly generated components into the latency info | 2607 // Add newly generated components into the latency info |
2545 for (lc = new_components.begin(); lc != new_components.end(); ++lc) { | 2608 for (lc = new_components.begin(); lc != new_components.end(); ++lc) { |
2546 latency_info->latency_components[lc->first] = lc->second; | 2609 latency_info->latency_components[lc->first] = lc->second; |
2547 } | 2610 } |
2548 } | 2611 } |
2549 | 2612 |
2550 } // namespace content | 2613 } // namespace content |
OLD | NEW |