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/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.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/begin_frame_args.h" | 21 #include "cc/output/begin_frame_args.h" |
22 #include "cc/output/context_provider.h" | 22 #include "cc/output/context_provider.h" |
23 #include "cc/scheduler/begin_frame_source.h" | 23 #include "cc/scheduler/begin_frame_source.h" |
24 #include "cc/surfaces/surface_id_allocator.h" | 24 #include "cc/surfaces/surface_id_allocator.h" |
25 #include "cc/trees/layer_tree_host.h" | 25 #include "cc/trees/layer_tree_host.h" |
26 #include "third_party/skia/include/core/SkBitmap.h" | 26 #include "third_party/skia/include/core/SkBitmap.h" |
27 #include "ui/compositor/compositor_observer.h" | 27 #include "ui/compositor/compositor_observer.h" |
28 #include "ui/compositor/compositor_switches.h" | 28 #include "ui/compositor/compositor_switches.h" |
29 #include "ui/compositor/compositor_vsync_manager.h" | |
30 #include "ui/compositor/dip_util.h" | 29 #include "ui/compositor/dip_util.h" |
31 #include "ui/compositor/layer.h" | 30 #include "ui/compositor/layer.h" |
32 #include "ui/compositor/layer_animator_collection.h" | 31 #include "ui/compositor/layer_animator_collection.h" |
33 #include "ui/gfx/frame_time.h" | 32 #include "ui/gfx/frame_time.h" |
34 #include "ui/gl/gl_context.h" | 33 #include "ui/gl/gl_context.h" |
35 #include "ui/gl/gl_switches.h" | 34 #include "ui/gl/gl_switches.h" |
36 | 35 |
37 namespace { | 36 namespace { |
38 | 37 |
39 const double kDefaultRefreshRate = 60.0; | 38 const double kDefaultRefreshRate = 60.0; |
(...skipping 25 matching lines...) Expand all Loading... | |
65 } | 64 } |
66 | 65 |
67 Compositor::Compositor(gfx::AcceleratedWidget widget, | 66 Compositor::Compositor(gfx::AcceleratedWidget widget, |
68 ui::ContextFactory* context_factory, | 67 ui::ContextFactory* context_factory, |
69 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 68 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
70 : context_factory_(context_factory), | 69 : context_factory_(context_factory), |
71 root_layer_(NULL), | 70 root_layer_(NULL), |
72 widget_(widget), | 71 widget_(widget), |
73 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()), | 72 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()), |
74 task_runner_(task_runner), | 73 task_runner_(task_runner), |
75 vsync_manager_(new CompositorVSyncManager()), | |
76 device_scale_factor_(0.0f), | 74 device_scale_factor_(0.0f), |
77 last_started_frame_(0), | 75 last_started_frame_(0), |
78 last_ended_frame_(0), | 76 last_ended_frame_(0), |
79 disable_schedule_composite_(false), | 77 disable_schedule_composite_(false), |
80 compositor_lock_(NULL), | 78 compositor_lock_(NULL), |
81 layer_animator_collection_(this), | 79 layer_animator_collection_(this), |
82 weak_ptr_factory_(this) { | 80 weak_ptr_factory_(this) { |
83 root_web_layer_ = cc::Layer::Create(); | 81 root_web_layer_ = cc::Layer::Create(); |
84 | 82 |
85 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 83 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
86 | 84 |
87 cc::LayerTreeSettings settings; | 85 cc::LayerTreeSettings settings; |
88 // When impl-side painting is enabled, this will ensure PictureLayers always | 86 // When impl-side painting is enabled, this will ensure PictureLayers always |
89 // can have LCD text, to match the previous behaviour with ContentLayers, | 87 // can have LCD text, to match the previous behaviour with ContentLayers, |
90 // where LCD-not-allowed notifications were ignored. | 88 // where LCD-not-allowed notifications were ignored. |
91 settings.layers_always_allowed_lcd_text = true; | 89 settings.layers_always_allowed_lcd_text = true; |
92 settings.renderer_settings.refresh_rate = | 90 settings.renderer_settings.refresh_rate = |
93 context_factory_->DoesCreateTestContexts() ? kTestRefreshRate | 91 context_factory_->DoesCreateTestContexts() ? kTestRefreshRate |
94 : kDefaultRefreshRate; | 92 : kDefaultRefreshRate; |
95 settings.main_frame_before_activation_enabled = false; | 93 settings.main_frame_before_activation_enabled = false; |
96 settings.throttle_frame_production = | 94 settings.throttle_frame_production = |
97 !command_line->HasSwitch(switches::kDisableGpuVsync); | 95 !command_line->HasSwitch(switches::kDisableGpuVsync); |
96 #if defined(USE_AURA) | |
97 settings.forward_begin_frames_to_children = true; | |
brianderson
2015/03/02 22:38:16
This flag doesn't seem useful like we thought it w
simonhong
2015/03/03 22:54:12
Yep, setting state_machine.SetChildrenNeedBeginFra
| |
98 #endif | |
98 #if !defined(OS_MACOSX) | 99 #if !defined(OS_MACOSX) |
99 settings.renderer_settings.partial_swap_enabled = | 100 settings.renderer_settings.partial_swap_enabled = |
100 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap); | 101 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap); |
101 #endif | 102 #endif |
102 #if defined(OS_CHROMEOS) | 103 #if defined(OS_CHROMEOS) |
103 settings.per_tile_painting_enabled = true; | 104 settings.per_tile_painting_enabled = true; |
104 #endif | 105 #endif |
105 #if defined(OS_WIN) | 106 #if defined(OS_WIN) |
106 settings.disable_hi_res_timer_tasks_on_battery = | 107 settings.disable_hi_res_timer_tasks_on_battery = |
107 !context_factory_->DoesCreateTestContexts(); | 108 !context_factory_->DoesCreateTestContexts(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 | 147 |
147 Compositor::~Compositor() { | 148 Compositor::~Compositor() { |
148 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 149 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
149 | 150 |
150 CancelCompositorLock(); | 151 CancelCompositorLock(); |
151 DCHECK(!compositor_lock_); | 152 DCHECK(!compositor_lock_); |
152 | 153 |
153 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 154 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, |
154 OnCompositingShuttingDown(this)); | 155 OnCompositingShuttingDown(this)); |
155 | 156 |
157 DCHECK(!begin_frame_observer_list_.might_have_observers()); | |
158 | |
156 if (root_layer_) | 159 if (root_layer_) |
157 root_layer_->SetCompositor(NULL); | 160 root_layer_->SetCompositor(NULL); |
158 | 161 |
159 // Stop all outstanding draws before telling the ContextFactory to tear | 162 // Stop all outstanding draws before telling the ContextFactory to tear |
160 // down any contexts that the |host_| may rely upon. | 163 // down any contexts that the |host_| may rely upon. |
161 host_.reset(); | 164 host_.reset(); |
162 | 165 |
163 context_factory_->RemoveCompositor(this); | 166 context_factory_->RemoveCompositor(this); |
164 } | 167 } |
165 | 168 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 } | 245 } |
243 | 246 |
244 void Compositor::SetVisible(bool visible) { | 247 void Compositor::SetVisible(bool visible) { |
245 host_->SetVisible(visible); | 248 host_->SetVisible(visible); |
246 } | 249 } |
247 | 250 |
248 bool Compositor::IsVisible() { | 251 bool Compositor::IsVisible() { |
249 return host_->visible(); | 252 return host_->visible(); |
250 } | 253 } |
251 | 254 |
252 scoped_refptr<CompositorVSyncManager> Compositor::vsync_manager() const { | 255 void Compositor::SetAuthoritativeVSyncInterval( |
253 return vsync_manager_; | 256 const base::TimeDelta& interval) { |
257 host_->SetAuthoritativeVSyncInterval(interval); | |
254 } | 258 } |
255 | 259 |
256 void Compositor::AddObserver(CompositorObserver* observer) { | 260 void Compositor::AddObserver(CompositorObserver* observer) { |
257 observer_list_.AddObserver(observer); | 261 observer_list_.AddObserver(observer); |
258 } | 262 } |
259 | 263 |
260 void Compositor::RemoveObserver(CompositorObserver* observer) { | 264 void Compositor::RemoveObserver(CompositorObserver* observer) { |
261 observer_list_.RemoveObserver(observer); | 265 observer_list_.RemoveObserver(observer); |
262 } | 266 } |
263 | 267 |
264 bool Compositor::HasObserver(const CompositorObserver* observer) const { | 268 bool Compositor::HasObserver(const CompositorObserver* observer) const { |
265 return observer_list_.HasObserver(observer); | 269 return observer_list_.HasObserver(observer); |
266 } | 270 } |
267 | 271 |
268 void Compositor::AddAnimationObserver(CompositorAnimationObserver* observer) { | 272 void Compositor::AddAnimationObserver(CompositorAnimationObserver* observer) { |
269 animation_observer_list_.AddObserver(observer); | 273 animation_observer_list_.AddObserver(observer); |
270 host_->SetNeedsAnimate(); | 274 host_->SetNeedsAnimate(); |
271 } | 275 } |
272 | 276 |
273 void Compositor::RemoveAnimationObserver( | 277 void Compositor::RemoveAnimationObserver( |
274 CompositorAnimationObserver* observer) { | 278 CompositorAnimationObserver* observer) { |
275 animation_observer_list_.RemoveObserver(observer); | 279 animation_observer_list_.RemoveObserver(observer); |
276 } | 280 } |
277 | 281 |
278 bool Compositor::HasAnimationObserver( | 282 bool Compositor::HasAnimationObserver( |
279 const CompositorAnimationObserver* observer) const { | 283 const CompositorAnimationObserver* observer) const { |
280 return animation_observer_list_.HasObserver(observer); | 284 return animation_observer_list_.HasObserver(observer); |
281 } | 285 } |
282 | 286 |
287 void Compositor::AddBeginFrameObserver( | |
brianderson
2015/03/02 22:38:17
Please add unit tests for this since the last_begi
| |
288 CompositorBeginFrameObserver* observer, | |
289 const cc::BeginFrameArgs& last_begin_frame_args_sent_to_observer) { | |
290 // If |last_begin_frame_args_| is still effective, send it to the new | |
291 // |observer| immediately. | |
292 if (!last_begin_frame_args_sent_to_observer.deadline.is_null() && | |
brianderson
2015/03/02 22:38:16
Is this check for a null deadline necessary?
simonhong
2015/03/03 22:54:12
I also can't remember why I added this a while ago
| |
293 last_begin_frame_args_sent_to_observer != missed_begin_frame_args_) { | |
brianderson
2015/03/02 22:38:16
It is possible that last_begin_frame_args_sent_to_
simonhong
2015/03/03 22:54:12
Done.
| |
294 missed_begin_frame_args_.type = cc::BeginFrameArgs::MISSED; | |
brianderson
2015/03/02 22:38:17
Can you move this line to the end of Compositor::S
simonhong
2015/03/03 22:54:12
Done.
| |
295 observer->OnSendBeginFrame(missed_begin_frame_args_); | |
296 } | |
297 | |
298 if (!begin_frame_observer_list_.might_have_observers()) | |
299 SetChildrenNeedBeginFrames(true); | |
300 begin_frame_observer_list_.AddObserver(observer); | |
301 } | |
302 | |
303 void Compositor::RemoveBeginFrameObserver( | |
304 CompositorBeginFrameObserver* observer) { | |
305 DCHECK(begin_frame_observer_list_.HasObserver(observer)); | |
306 begin_frame_observer_list_.RemoveObserver(observer); | |
307 | |
308 if (!begin_frame_observer_list_.might_have_observers()) | |
309 SetChildrenNeedBeginFrames(false); | |
310 } | |
311 | |
283 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { | 312 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { |
284 FOR_EACH_OBSERVER(CompositorAnimationObserver, | 313 FOR_EACH_OBSERVER(CompositorAnimationObserver, |
285 animation_observer_list_, | 314 animation_observer_list_, |
286 OnAnimationStep(args.frame_time)); | 315 OnAnimationStep(args.frame_time)); |
287 if (animation_observer_list_.might_have_observers()) | 316 if (animation_observer_list_.might_have_observers()) |
288 host_->SetNeedsAnimate(); | 317 host_->SetNeedsAnimate(); |
289 } | 318 } |
290 | 319 |
291 void Compositor::BeginMainFrameNotExpectedSoon() { | 320 void Compositor::BeginMainFrameNotExpectedSoon() { |
292 } | 321 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 362 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, |
334 OnCompositingStarted(this, start_time)); | 363 OnCompositingStarted(this, start_time)); |
335 } | 364 } |
336 | 365 |
337 void Compositor::DidAbortSwapBuffers() { | 366 void Compositor::DidAbortSwapBuffers() { |
338 FOR_EACH_OBSERVER(CompositorObserver, | 367 FOR_EACH_OBSERVER(CompositorObserver, |
339 observer_list_, | 368 observer_list_, |
340 OnCompositingAborted(this)); | 369 OnCompositingAborted(this)); |
341 } | 370 } |
342 | 371 |
372 void Compositor::SendBeginFramesToChildren(const cc::BeginFrameArgs& args) { | |
373 FOR_EACH_OBSERVER(CompositorBeginFrameObserver, | |
374 begin_frame_observer_list_, | |
375 OnSendBeginFrame(args)); | |
376 missed_begin_frame_args_ = args; | |
377 } | |
378 | |
343 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { | 379 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { |
344 return host_->debug_state(); | 380 return host_->debug_state(); |
345 } | 381 } |
346 | 382 |
347 void Compositor::SetLayerTreeDebugState( | 383 void Compositor::SetLayerTreeDebugState( |
348 const cc::LayerTreeDebugState& debug_state) { | 384 const cc::LayerTreeDebugState& debug_state) { |
349 host_->SetDebugState(debug_state); | 385 host_->SetDebugState(debug_state); |
350 } | 386 } |
351 | 387 |
352 const cc::RendererSettings& Compositor::GetRendererSettings() const { | 388 const cc::RendererSettings& Compositor::GetRendererSettings() const { |
(...skipping 18 matching lines...) Expand all Loading... | |
371 FOR_EACH_OBSERVER(CompositorObserver, | 407 FOR_EACH_OBSERVER(CompositorObserver, |
372 observer_list_, | 408 observer_list_, |
373 OnCompositingLockStateChanged(this)); | 409 OnCompositingLockStateChanged(this)); |
374 } | 410 } |
375 | 411 |
376 void Compositor::CancelCompositorLock() { | 412 void Compositor::CancelCompositorLock() { |
377 if (compositor_lock_) | 413 if (compositor_lock_) |
378 compositor_lock_->CancelLock(); | 414 compositor_lock_->CancelLock(); |
379 } | 415 } |
380 | 416 |
417 void Compositor::SetChildrenNeedBeginFrames(bool need_begin_frames) { | |
418 host_->SetChildrenNeedBeginFrames(need_begin_frames); | |
419 } | |
420 | |
381 } // namespace ui | 421 } // namespace ui |
OLD | NEW |