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

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: Addressed Nit 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "content/public/common/content_switches.h" 51 #include "content/public/common/content_switches.h"
51 #include "content/public/common/result_codes.h" 52 #include "content/public/common/result_codes.h"
52 #include "skia/ext/image_operations.h" 53 #include "skia/ext/image_operations.h"
53 #include "skia/ext/platform_canvas.h" 54 #include "skia/ext/platform_canvas.h"
54 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" 55 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
55 #include "ui/events/event.h" 56 #include "ui/events/event.h"
56 #include "ui/events/keycodes/keyboard_codes.h" 57 #include "ui/events/keycodes/keyboard_codes.h"
57 #include "ui/gfx/size_conversions.h" 58 #include "ui/gfx/size_conversions.h"
58 #include "ui/gfx/skbitmap_operations.h" 59 #include "ui/gfx/skbitmap_operations.h"
59 #include "ui/gfx/vector2d_conversions.h" 60 #include "ui/gfx/vector2d_conversions.h"
61 #include "ui/snapshot/snapshot.h"
60 #include "webkit/common/cursors/webcursor.h" 62 #include "webkit/common/cursors/webcursor.h"
61 #include "webkit/common/webpreferences.h" 63 #include "webkit/common/webpreferences.h"
62 64
63 #if defined(TOOLKIT_GTK) 65 #if defined(TOOLKIT_GTK)
64 #include "content/browser/renderer_host/backing_store_gtk.h" 66 #include "content/browser/renderer_host/backing_store_gtk.h"
65 #elif defined(OS_MACOSX) 67 #elif defined(OS_MACOSX)
66 #include "content/browser/renderer_host/backing_store_mac.h" 68 #include "content/browser/renderer_host/backing_store_mac.h"
67 #elif defined(OS_WIN) 69 #elif defined(OS_WIN)
68 #include "content/common/plugin_constants_win.h" 70 #include "content/common/plugin_constants_win.h"
69 #endif 71 #endif
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // problem, for example by tracking in the RenderWidgetHelper the routing id 205 // problem, for example by tracking in the RenderWidgetHelper the routing id
204 // (and surface id) that have been created, but whose RWH haven't yet. 206 // (and surface id) that have been created, but whose RWH haven't yet.
205 surface_id_ = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer( 207 surface_id_ = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer(
206 process_->GetID(), 208 process_->GetID(),
207 routing_id_); 209 routing_id_);
208 DCHECK(surface_id_); 210 DCHECK(surface_id_);
209 } 211 }
210 212
211 is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled(); 213 is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled();
212 214
215
213 g_routing_id_widget_map.Get().insert(std::make_pair( 216 g_routing_id_widget_map.Get().insert(std::make_pair(
214 RenderWidgetHostID(process->GetID(), routing_id_), this)); 217 RenderWidgetHostID(process->GetID(), routing_id_), this));
215 process_->AddRoute(routing_id_, this); 218 process_->AddRoute(routing_id_, this);
216 219
217 // If we're initially visible, tell the process host that we're alive. 220 // If we're initially visible, tell the process host that we're alive.
218 // Otherwise we'll notify the process host when we are first shown. 221 // Otherwise we'll notify the process host when we are first shown.
219 if (!hidden) 222 if (!hidden)
220 process_->WidgetRestored(); 223 process_->WidgetRestored();
221 224
222 accessibility_mode_ = 225 accessibility_mode_ =
(...skipping 2318 matching lines...) Expand 10 before | Expand all | Expand 10 after
2541 1000000, 2544 1000000,
2542 100); 2545 100);
2543 } 2546 }
2544 2547
2545 if (CommandLine::ForCurrentProcess()->HasSwitch( 2548 if (CommandLine::ForCurrentProcess()->HasSwitch(
2546 switches::kEnableGpuBenchmarking)) 2549 switches::kEnableGpuBenchmarking))
2547 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); 2550 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_));
2548 } 2551 }
2549 2552
2550 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { 2553 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) {
2554 ui::LatencyInfo::LatencyComponent window_snapshot_component;
2555 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
2556 GetLatencyComponentId(),
2557 &window_snapshot_component)) {
2558 WindowSnapshotReachedScreen(
2559 static_cast<int>(window_snapshot_component.sequence_number));
2560 }
2561
2551 ui::LatencyInfo::LatencyComponent rwh_component; 2562 ui::LatencyInfo::LatencyComponent rwh_component;
2552 ui::LatencyInfo::LatencyComponent swap_component; 2563 ui::LatencyInfo::LatencyComponent swap_component;
2553 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 2564 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
2554 GetLatencyComponentId(), 2565 GetLatencyComponentId(),
2555 &rwh_component) || 2566 &rwh_component) ||
2556 !latency_info.FindLatency( 2567 !latency_info.FindLatency(
2557 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 2568 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT,
2558 0, &swap_component)) { 2569 0, &swap_component)) {
2559 return; 2570 return;
2560 } 2571 }
(...skipping 29 matching lines...) Expand all
2590 2601
2591 if (CommandLine::ForCurrentProcess()->HasSwitch( 2602 if (CommandLine::ForCurrentProcess()->HasSwitch(
2592 switches::kEnableGpuBenchmarking)) 2603 switches::kEnableGpuBenchmarking))
2593 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); 2604 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_));
2594 } 2605 }
2595 2606
2596 void RenderWidgetHostImpl::DidReceiveRendererFrame() { 2607 void RenderWidgetHostImpl::DidReceiveRendererFrame() {
2597 view_->DidReceiveRendererFrame(); 2608 view_->DidReceiveRendererFrame();
2598 } 2609 }
2599 2610
2611 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) {
2612 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_UI));
2613
2614 std::vector<unsigned char> png;
2615
2616 // This feature is behind the kEnableGpuBenchmarking command line switch
2617 // because it poses security concerns and should only be used for testing.
2618 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2619 if (command_line.HasSwitch(switches::kEnableGpuBenchmarking)) {
2620 gfx::Rect view_bounds = GetView()->GetViewBounds();
2621 gfx::Rect snapshot_bounds(view_bounds.size());
2622 gfx::Size snapshot_size = snapshot_bounds.size();
2623
2624 if (ui::GrabViewSnapshot(GetView()->GetNativeView(),
2625 &png, snapshot_bounds)) {
2626 Send(new ViewMsg_WindowSnapshotCompleted(
2627 GetRoutingID(), snapshot_id, snapshot_size, png));
2628 return;
2629 }
2630 }
2631
2632 Send(new ViewMsg_WindowSnapshotCompleted(
2633 GetRoutingID(), snapshot_id, gfx::Size(), png));
2634 }
2635
2600 // static 2636 // static
2601 void RenderWidgetHostImpl::CompositorFrameDrawn( 2637 void RenderWidgetHostImpl::CompositorFrameDrawn(
2602 const ui::LatencyInfo& latency_info) { 2638 const ui::LatencyInfo& latency_info) {
2639 std::set<RenderWidgetHostImpl*> rwhi_set;
2640
2603 for (ui::LatencyInfo::LatencyMap::const_iterator b = 2641 for (ui::LatencyInfo::LatencyMap::const_iterator b =
2604 latency_info.latency_components.begin(); 2642 latency_info.latency_components.begin();
2605 b != latency_info.latency_components.end(); 2643 b != latency_info.latency_components.end();
2606 ++b) { 2644 ++b) {
2607 if (b->first.first != ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT) 2645 if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT ||
2608 continue; 2646 b->first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT) {
2609 // Matches with GetLatencyComponentId 2647 // Matches with GetLatencyComponentId
2610 int routing_id = b->first.second & 0xffffffff; 2648 int routing_id = b->first.second & 0xffffffff;
2611 int process_id = (b->first.second >> 32) & 0xffffffff; 2649 int process_id = (b->first.second >> 32) & 0xffffffff;
2612 RenderWidgetHost* rwh = 2650 RenderWidgetHost* rwh =
2613 RenderWidgetHost::FromID(process_id, routing_id); 2651 RenderWidgetHost::FromID(process_id, routing_id);
2614 if (!rwh) 2652 if (!rwh) {
2615 continue; 2653 continue;
2616 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); 2654 }
2655 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
2656 if (rwhi_set.insert(rwhi).second)
2657 rwhi->FrameSwapped(latency_info);
2658 }
2617 } 2659 }
2618 } 2660 }
2619 2661
2620 } // namespace content 2662 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | content/browser/renderer_host/render_widget_host_view_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698