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

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

Issue 23694031: Fix race conditions in window snapshot code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added screenshot sync test to telemetry unittests, updated cc unittest Created 7 years, 2 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
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 <utility> 9 #include <utility>
9 10
10 #include "base/auto_reset.h" 11 #include "base/auto_reset.h"
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/containers/hash_tables.h" 14 #include "base/containers/hash_tables.h"
14 #include "base/debug/trace_event.h" 15 #include "base/debug/trace_event.h"
15 #include "base/i18n/rtl.h" 16 #include "base/i18n/rtl.h"
16 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
17 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "content/public/common/content_switches.h" 52 #include "content/public/common/content_switches.h"
52 #include "content/public/common/result_codes.h" 53 #include "content/public/common/result_codes.h"
53 #include "skia/ext/image_operations.h" 54 #include "skia/ext/image_operations.h"
54 #include "skia/ext/platform_canvas.h" 55 #include "skia/ext/platform_canvas.h"
55 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" 56 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
56 #include "ui/events/event.h" 57 #include "ui/events/event.h"
57 #include "ui/events/keycodes/keyboard_codes.h" 58 #include "ui/events/keycodes/keyboard_codes.h"
58 #include "ui/gfx/size_conversions.h" 59 #include "ui/gfx/size_conversions.h"
59 #include "ui/gfx/skbitmap_operations.h" 60 #include "ui/gfx/skbitmap_operations.h"
60 #include "ui/gfx/vector2d_conversions.h" 61 #include "ui/gfx/vector2d_conversions.h"
62 #include "ui/snapshot/snapshot.h"
61 #include "webkit/common/cursors/webcursor.h" 63 #include "webkit/common/cursors/webcursor.h"
62 #include "webkit/common/webpreferences.h" 64 #include "webkit/common/webpreferences.h"
63 65
64 #if defined(TOOLKIT_GTK) 66 #if defined(TOOLKIT_GTK)
65 #include "content/browser/renderer_host/backing_store_gtk.h" 67 #include "content/browser/renderer_host/backing_store_gtk.h"
66 #elif defined(OS_MACOSX) 68 #elif defined(OS_MACOSX)
67 #include "content/browser/renderer_host/backing_store_mac.h" 69 #include "content/browser/renderer_host/backing_store_mac.h"
68 #elif defined(OS_WIN) 70 #elif defined(OS_WIN)
69 #include "content/common/plugin_constants_win.h" 71 #include "content/common/plugin_constants_win.h"
70 #endif 72 #endif
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 // problem, for example by tracking in the RenderWidgetHelper the routing id 206 // problem, for example by tracking in the RenderWidgetHelper the routing id
205 // (and surface id) that have been created, but whose RWH haven't yet. 207 // (and surface id) that have been created, but whose RWH haven't yet.
206 surface_id_ = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer( 208 surface_id_ = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer(
207 process_->GetID(), 209 process_->GetID(),
208 routing_id_); 210 routing_id_);
209 DCHECK(surface_id_); 211 DCHECK(surface_id_);
210 } 212 }
211 213
212 is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled(); 214 is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled();
213 215
216
214 g_routing_id_widget_map.Get().insert(std::make_pair( 217 g_routing_id_widget_map.Get().insert(std::make_pair(
215 RenderWidgetHostID(process->GetID(), routing_id_), this)); 218 RenderWidgetHostID(process->GetID(), routing_id_), this));
216 process_->AddRoute(routing_id_, this); 219 process_->AddRoute(routing_id_, this);
217 220
218 // If we're initially visible, tell the process host that we're alive. 221 // If we're initially visible, tell the process host that we're alive.
219 // Otherwise we'll notify the process host when we are first shown. 222 // Otherwise we'll notify the process host when we are first shown.
220 if (!hidden) 223 if (!hidden)
221 process_->WidgetRestored(); 224 process_->WidgetRestored();
222 225
223 accessibility_mode_ = 226 accessibility_mode_ =
(...skipping 2304 matching lines...) Expand 10 before | Expand all | Expand 10 after
2528 1000000, 2531 1000000,
2529 100); 2532 100);
2530 } 2533 }
2531 2534
2532 if (CommandLine::ForCurrentProcess()->HasSwitch( 2535 if (CommandLine::ForCurrentProcess()->HasSwitch(
2533 switches::kEnableGpuBenchmarking)) 2536 switches::kEnableGpuBenchmarking))
2534 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); 2537 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_));
2535 } 2538 }
2536 2539
2537 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { 2540 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) {
2541 ui::LatencyInfo::LatencyComponent window_snapshot_component;
2542 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
2543 GetLatencyComponentId(),
2544 &window_snapshot_component)) {
2545 WindowSnapshotReachedScreen(
2546 static_cast<int>(window_snapshot_component.sequence_number));
2547 }
2548
2538 ui::LatencyInfo::LatencyComponent rwh_component; 2549 ui::LatencyInfo::LatencyComponent rwh_component;
2539 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, 2550 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT,
2540 GetLatencyComponentId(), 2551 GetLatencyComponentId(),
2541 &rwh_component)) 2552 &rwh_component))
2542 return; 2553 return;
2543 2554
2544 rendering_stats_.input_event_count += rwh_component.event_count; 2555 rendering_stats_.input_event_count += rwh_component.event_count;
2545 rendering_stats_.total_input_latency += 2556 rendering_stats_.total_input_latency +=
2546 rwh_component.event_count * 2557 rwh_component.event_count *
2547 (latency_info.swap_timestamp - rwh_component.event_time); 2558 (latency_info.swap_timestamp - rwh_component.event_time);
(...skipping 24 matching lines...) Expand all
2572 2583
2573 if (CommandLine::ForCurrentProcess()->HasSwitch( 2584 if (CommandLine::ForCurrentProcess()->HasSwitch(
2574 switches::kEnableGpuBenchmarking)) 2585 switches::kEnableGpuBenchmarking))
2575 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); 2586 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_));
2576 } 2587 }
2577 2588
2578 void RenderWidgetHostImpl::DidReceiveRendererFrame() { 2589 void RenderWidgetHostImpl::DidReceiveRendererFrame() {
2579 view_->DidReceiveRendererFrame(); 2590 view_->DidReceiveRendererFrame();
2580 } 2591 }
2581 2592
2593 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) {
2594 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_UI));
2595
2596 std::vector<unsigned char> png;
2597
2598 // This feature is behind the kEnableGpuBenchmarking command line switch
2599 // because it poses security concerns and should only be used for testing.
2600 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2601 if (command_line.HasSwitch(switches::kEnableGpuBenchmarking)) {
2602 gfx::Rect view_bounds = GetView()->GetViewBounds();
2603 gfx::Rect snapshot_bounds(view_bounds.size());
2604 gfx::Size snapshot_size = snapshot_bounds.size();
2605
2606 if (ui::GrabViewSnapshot(GetView()->GetNativeView(),
2607 &png, snapshot_bounds)) {
2608 Send(new ViewMsg_WindowSnapshotCompleted(
2609 GetRoutingID(), snapshot_id, snapshot_size, png));
2610 return;
2611 }
2612 }
2613
2614 Send(new ViewMsg_WindowSnapshotCompleted(
2615 GetRoutingID(), snapshot_id, gfx::Size(), png));
2616 }
2617
2582 // static 2618 // static
2583 void RenderWidgetHostImpl::CompositorFrameDrawn( 2619 void RenderWidgetHostImpl::CompositorFrameDrawn(
2584 const ui::LatencyInfo& latency_info) { 2620 const ui::LatencyInfo& latency_info) {
2621 std::set<RenderWidgetHostImpl*> rwhi_set;
2622
2585 for (ui::LatencyInfo::LatencyMap::const_iterator b = 2623 for (ui::LatencyInfo::LatencyMap::const_iterator b =
2586 latency_info.latency_components.begin(); 2624 latency_info.latency_components.begin();
2587 b != latency_info.latency_components.end(); 2625 b != latency_info.latency_components.end();
2588 ++b) { 2626 ++b) {
2589 if (b->first.first != ui::INPUT_EVENT_LATENCY_RWH_COMPONENT) 2627 if (b->first.first == ui::INPUT_EVENT_LATENCY_RWH_COMPONENT ||
2590 continue; 2628 b->first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT) {
2591 // Matches with GetLatencyComponentId 2629 // Matches with GetLatencyComponentId
2592 int routing_id = b->first.second & 0xffffffff; 2630 int routing_id = b->first.second & 0xffffffff;
2593 int process_id = (b->first.second >> 32) & 0xffffffff; 2631 int process_id = (b->first.second >> 32) & 0xffffffff;
2594 RenderWidgetHost* rwh = 2632 RenderWidgetHost* rwh =
2595 RenderWidgetHost::FromID(process_id, routing_id); 2633 RenderWidgetHost::FromID(process_id, routing_id);
2596 if (!rwh) 2634 if (!rwh) {
2597 continue; 2635 continue;
2598 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); 2636 }
2637 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
2638 if (rwhi_set.insert(rwhi).second)
2639 rwhi->FrameSwapped(latency_info);
2640 }
2599 } 2641 }
2600 } 2642 }
2601 2643
2602 } // namespace content 2644 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698