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 "ui/compositor/compositor.h" | 5 #include "ui/compositor/compositor.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
17 #include "cc/base/latency_info_swap_promise.h" | 17 #include "cc/base/latency_info_swap_promise.h" |
18 #include "cc/base/switches.h" | 18 #include "cc/base/switches.h" |
19 #include "cc/input/input_handler.h" | 19 #include "cc/input/input_handler.h" |
20 #include "cc/layers/layer.h" | 20 #include "cc/layers/layer.h" |
21 #include "cc/output/context_provider.h" | 21 #include "cc/output/context_provider.h" |
22 #include "cc/scheduler/begin_frame_manager.h" | |
22 #include "cc/trees/layer_tree_host.h" | 23 #include "cc/trees/layer_tree_host.h" |
23 #include "third_party/skia/include/core/SkBitmap.h" | 24 #include "third_party/skia/include/core/SkBitmap.h" |
24 #include "ui/compositor/compositor_observer.h" | 25 #include "ui/compositor/compositor_observer.h" |
25 #include "ui/compositor/compositor_switches.h" | 26 #include "ui/compositor/compositor_switches.h" |
26 #include "ui/compositor/compositor_vsync_manager.h" | |
27 #include "ui/compositor/dip_util.h" | 27 #include "ui/compositor/dip_util.h" |
28 #include "ui/compositor/layer.h" | 28 #include "ui/compositor/layer.h" |
29 #include "ui/compositor/layer_animator_collection.h" | 29 #include "ui/compositor/layer_animator_collection.h" |
30 #include "ui/gfx/frame_time.h" | 30 #include "ui/gfx/frame_time.h" |
31 #include "ui/gl/gl_context.h" | 31 #include "ui/gl/gl_context.h" |
32 #include "ui/gl/gl_switches.h" | 32 #include "ui/gl/gl_switches.h" |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 const double kDefaultRefreshRate = 60.0; | 36 const double kDefaultRefreshRate = 60.0; |
(...skipping 25 matching lines...) Expand all Loading... | |
62 } | 62 } |
63 | 63 |
64 Compositor::Compositor(gfx::AcceleratedWidget widget, | 64 Compositor::Compositor(gfx::AcceleratedWidget widget, |
65 ui::ContextFactory* context_factory, | 65 ui::ContextFactory* context_factory, |
66 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 66 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
67 : context_factory_(context_factory), | 67 : context_factory_(context_factory), |
68 root_layer_(NULL), | 68 root_layer_(NULL), |
69 widget_(widget), | 69 widget_(widget), |
70 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), | 70 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), |
71 task_runner_(task_runner), | 71 task_runner_(task_runner), |
72 vsync_manager_(new CompositorVSyncManager()), | 72 begin_frame_manager_(new cc::BeginFrameManager), |
73 device_scale_factor_(0.0f), | 73 device_scale_factor_(0.0f), |
74 disable_schedule_composite_(false), | 74 disable_schedule_composite_(false), |
75 compositor_lock_(NULL), | 75 compositor_lock_(NULL), |
76 layer_animator_collection_(this) { | 76 layer_animator_collection_(this) { |
77 root_web_layer_ = cc::Layer::Create(); | 77 root_web_layer_ = cc::Layer::Create(); |
78 | 78 |
79 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 79 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
80 | 80 |
81 cc::LayerTreeSettings settings; | 81 cc::LayerTreeSettings settings; |
82 settings.refresh_rate = | 82 settings.refresh_rate = |
83 context_factory_->DoesCreateTestContexts() | 83 context_factory_->DoesCreateTestContexts() |
84 ? kTestRefreshRate | 84 ? kTestRefreshRate |
85 : kDefaultRefreshRate; | 85 : kDefaultRefreshRate; |
86 settings.main_frame_before_draw_enabled = false; | 86 settings.main_frame_before_draw_enabled = false; |
87 settings.main_frame_before_activation_enabled = false; | 87 settings.main_frame_before_activation_enabled = false; |
88 settings.throttle_frame_production = | 88 settings.throttle_frame_production = |
89 !command_line->HasSwitch(switches::kDisableGpuVsync); | 89 !command_line->HasSwitch(switches::kDisableGpuVsync); |
90 #if !defined(OS_MACOSX) | 90 #if !defined(OS_MACOSX) |
91 settings.partial_swap_enabled = | 91 settings.partial_swap_enabled = |
92 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap); | 92 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap); |
93 #endif | 93 #endif |
94 #if defined(USE_AURA) | |
95 settings.begin_frame_publisher = | |
96 command_line->HasSwitch(cc::switches::kEnableBeginFrameScheduling); | |
97 #endif | |
94 #if defined(OS_CHROMEOS) | 98 #if defined(OS_CHROMEOS) |
95 settings.per_tile_painting_enabled = true; | 99 settings.per_tile_painting_enabled = true; |
96 #endif | 100 #endif |
97 | 101 |
98 // These flags should be mirrored by renderer versions in content/renderer/. | 102 // These flags should be mirrored by renderer versions in content/renderer/. |
99 settings.initial_debug_state.show_debug_borders = | 103 settings.initial_debug_state.show_debug_borders = |
100 command_line->HasSwitch(cc::switches::kUIShowCompositedLayerBorders); | 104 command_line->HasSwitch(cc::switches::kUIShowCompositedLayerBorders); |
101 settings.initial_debug_state.show_fps_counter = | 105 settings.initial_debug_state.show_fps_counter = |
102 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); | 106 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); |
103 settings.initial_debug_state.show_layer_animation_bounds_rects = | 107 settings.initial_debug_state.show_layer_animation_bounds_rects = |
(...skipping 14 matching lines...) Expand all Loading... | |
118 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects); | 122 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects); |
119 | 123 |
120 settings.initial_debug_state.SetRecordRenderingStats( | 124 settings.initial_debug_state.SetRecordRenderingStats( |
121 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); | 125 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); |
122 | 126 |
123 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); | 127 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); |
124 settings.use_zero_copy = IsUIZeroCopyEnabled(); | 128 settings.use_zero_copy = IsUIZeroCopyEnabled(); |
125 | 129 |
126 base::TimeTicks before_create = base::TimeTicks::Now(); | 130 base::TimeTicks before_create = base::TimeTicks::Now(); |
127 if (compositor_thread_loop_) { | 131 if (compositor_thread_loop_) { |
132 // --enable-begin-frame-scheduling is not used with threaded compositing. | |
133 DCHECK(!settings.begin_frame_publisher); | |
128 host_ = cc::LayerTreeHost::CreateThreaded( | 134 host_ = cc::LayerTreeHost::CreateThreaded( |
129 this, | 135 this, |
130 context_factory_->GetSharedBitmapManager(), | 136 context_factory_->GetSharedBitmapManager(), |
131 settings, | 137 settings, |
132 task_runner_, | 138 task_runner_, |
133 compositor_thread_loop_); | 139 compositor_thread_loop_); |
134 } else { | 140 } else { |
135 host_ = cc::LayerTreeHost::CreateSingleThreaded( | 141 host_ = cc::LayerTreeHost::CreateSingleThreaded( |
136 this, | 142 this, |
137 this, | 143 this, |
138 context_factory_->GetSharedBitmapManager(), | 144 context_factory_->GetSharedBitmapManager(), |
139 settings, | 145 settings, |
140 task_runner_); | 146 task_runner_, |
147 begin_frame_manager_.get()); | |
141 } | 148 } |
142 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", | 149 UMA_HISTOGRAM_TIMES("GPU.CreateBrowserCompositor", |
143 base::TimeTicks::Now() - before_create); | 150 base::TimeTicks::Now() - before_create); |
144 host_->SetRootLayer(root_web_layer_); | 151 host_->SetRootLayer(root_web_layer_); |
145 host_->SetLayerTreeHostClientReady(); | 152 host_->SetLayerTreeHostClientReady(); |
146 } | 153 } |
147 | 154 |
148 Compositor::~Compositor() { | 155 Compositor::~Compositor() { |
149 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 156 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
150 | 157 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 if (root_layer_) | 228 if (root_layer_) |
222 root_layer_->OnDeviceScaleFactorChanged(scale); | 229 root_layer_->OnDeviceScaleFactorChanged(scale); |
223 } | 230 } |
224 } | 231 } |
225 | 232 |
226 void Compositor::SetBackgroundColor(SkColor color) { | 233 void Compositor::SetBackgroundColor(SkColor color) { |
227 host_->set_background_color(color); | 234 host_->set_background_color(color); |
228 ScheduleDraw(); | 235 ScheduleDraw(); |
229 } | 236 } |
230 | 237 |
231 scoped_refptr<CompositorVSyncManager> Compositor::vsync_manager() const { | 238 void Compositor::SetAuthoritativeVSyncInterval( |
232 return vsync_manager_; | 239 base::TimeDelta interval) const { |
240 begin_frame_manager_->SetAuthoritativeVSyncInterval(interval); | |
brianderson
2014/08/28 02:48:07
I think it'll be better to have SetAuthoritativeVS
simonhong
2014/09/03 21:02:23
Done.
| |
233 } | 241 } |
234 | 242 |
235 void Compositor::AddObserver(CompositorObserver* observer) { | 243 void Compositor::AddObserver(CompositorObserver* observer) { |
236 observer_list_.AddObserver(observer); | 244 observer_list_.AddObserver(observer); |
237 } | 245 } |
238 | 246 |
239 void Compositor::RemoveObserver(CompositorObserver* observer) { | 247 void Compositor::RemoveObserver(CompositorObserver* observer) { |
240 observer_list_.RemoveObserver(observer); | 248 observer_list_.RemoveObserver(observer); |
241 } | 249 } |
242 | 250 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 observer_list_, | 352 observer_list_, |
345 OnCompositingLockStateChanged(this)); | 353 OnCompositingLockStateChanged(this)); |
346 } | 354 } |
347 | 355 |
348 void Compositor::CancelCompositorLock() { | 356 void Compositor::CancelCompositorLock() { |
349 if (compositor_lock_) | 357 if (compositor_lock_) |
350 compositor_lock_->CancelLock(); | 358 compositor_lock_->CancelLock(); |
351 } | 359 } |
352 | 360 |
353 } // namespace ui | 361 } // namespace ui |
OLD | NEW |