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" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 // When impl-side painting is enabled, this will ensure PictureLayers always | 87 // When impl-side painting is enabled, this will ensure PictureLayers always |
88 // can have LCD text, to match the previous behaviour with ContentLayers, | 88 // can have LCD text, to match the previous behaviour with ContentLayers, |
89 // where LCD-not-allowed notifications were ignored. | 89 // where LCD-not-allowed notifications were ignored. |
90 settings.layers_always_allowed_lcd_text = true; | 90 settings.layers_always_allowed_lcd_text = true; |
91 settings.renderer_settings.refresh_rate = | 91 settings.renderer_settings.refresh_rate = |
92 context_factory_->DoesCreateTestContexts() ? kTestRefreshRate | 92 context_factory_->DoesCreateTestContexts() ? kTestRefreshRate |
93 : kDefaultRefreshRate; | 93 : kDefaultRefreshRate; |
94 settings.main_frame_before_activation_enabled = false; | 94 settings.main_frame_before_activation_enabled = false; |
95 settings.throttle_frame_production = | 95 settings.throttle_frame_production = |
96 !command_line->HasSwitch(switches::kDisableGpuVsync); | 96 !command_line->HasSwitch(switches::kDisableGpuVsync); |
97 settings.forward_begin_frames_to_children = | |
98 command_line->HasSwitch(cc::switches::kEnableBeginFrameScheduling); | |
97 #if !defined(OS_MACOSX) | 99 #if !defined(OS_MACOSX) |
98 settings.renderer_settings.partial_swap_enabled = | 100 settings.renderer_settings.partial_swap_enabled = |
99 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap); | 101 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap); |
100 #endif | 102 #endif |
101 #if defined(OS_CHROMEOS) | 103 #if defined(OS_CHROMEOS) |
102 settings.per_tile_painting_enabled = true; | 104 settings.per_tile_painting_enabled = true; |
103 #endif | 105 #endif |
104 #if defined(OS_WIN) | 106 #if defined(OS_WIN) |
105 settings.disable_hi_res_timer_tasks_on_battery = | 107 settings.disable_hi_res_timer_tasks_on_battery = |
106 !context_factory_->DoesCreateTestContexts(); | 108 !context_factory_->DoesCreateTestContexts(); |
(...skipping 23 matching lines...) Expand all Loading... | |
130 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects); | 132 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects); |
131 | 133 |
132 settings.initial_debug_state.SetRecordRenderingStats( | 134 settings.initial_debug_state.SetRecordRenderingStats( |
133 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); | 135 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); |
134 | 136 |
135 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); | 137 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); |
136 settings.use_zero_copy = IsUIZeroCopyEnabled(); | 138 settings.use_zero_copy = IsUIZeroCopyEnabled(); |
137 | 139 |
138 base::TimeTicks before_create = base::TimeTicks::Now(); | 140 base::TimeTicks before_create = base::TimeTicks::Now(); |
139 if (compositor_thread_loop_.get()) { | 141 if (compositor_thread_loop_.get()) { |
142 // Unified BeginFrame scheduling shouldn't be enabled with threaded | |
143 // compositing. | |
144 DCHECK(!settings.forward_begin_frames_to_children); | |
140 host_ = cc::LayerTreeHost::CreateThreaded( | 145 host_ = cc::LayerTreeHost::CreateThreaded( |
141 this, | 146 this, |
142 context_factory_->GetSharedBitmapManager(), | 147 context_factory_->GetSharedBitmapManager(), |
143 context_factory_->GetGpuMemoryBufferManager(), | 148 context_factory_->GetGpuMemoryBufferManager(), |
144 settings, | 149 settings, |
145 task_runner_, | 150 task_runner_, |
146 compositor_thread_loop_, | 151 compositor_thread_loop_, |
147 nullptr); | 152 nullptr); |
148 } else { | 153 } else { |
149 host_ = cc::LayerTreeHost::CreateSingleThreaded( | 154 host_ = cc::LayerTreeHost::CreateSingleThreaded( |
(...skipping 11 matching lines...) Expand all Loading... | |
161 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); | 166 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); |
162 host_->SetLayerTreeHostClientReady(); | 167 host_->SetLayerTreeHostClientReady(); |
163 } | 168 } |
164 | 169 |
165 Compositor::~Compositor() { | 170 Compositor::~Compositor() { |
166 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 171 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
167 | 172 |
168 CancelCompositorLock(); | 173 CancelCompositorLock(); |
169 DCHECK(!compositor_lock_); | 174 DCHECK(!compositor_lock_); |
170 | 175 |
176 DCHECK(!begin_frame_observer_list_.might_have_observers()); | |
177 | |
171 if (root_layer_) | 178 if (root_layer_) |
172 root_layer_->SetCompositor(NULL); | 179 root_layer_->SetCompositor(NULL); |
173 | 180 |
174 // Stop all outstanding draws before telling the ContextFactory to tear | 181 // Stop all outstanding draws before telling the ContextFactory to tear |
175 // down any contexts that the |host_| may rely upon. | 182 // down any contexts that the |host_| may rely upon. |
176 host_.reset(); | 183 host_.reset(); |
177 | 184 |
178 context_factory_->RemoveCompositor(this); | 185 context_factory_->RemoveCompositor(this); |
179 } | 186 } |
180 | 187 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 void Compositor::RemoveAnimationObserver( | 302 void Compositor::RemoveAnimationObserver( |
296 CompositorAnimationObserver* observer) { | 303 CompositorAnimationObserver* observer) { |
297 animation_observer_list_.RemoveObserver(observer); | 304 animation_observer_list_.RemoveObserver(observer); |
298 } | 305 } |
299 | 306 |
300 bool Compositor::HasAnimationObserver( | 307 bool Compositor::HasAnimationObserver( |
301 const CompositorAnimationObserver* observer) const { | 308 const CompositorAnimationObserver* observer) const { |
302 return animation_observer_list_.HasObserver(observer); | 309 return animation_observer_list_.HasObserver(observer); |
303 } | 310 } |
304 | 311 |
312 void Compositor::AddBeginFrameObserver( | |
313 CompositorBeginFrameObserver* observer, | |
314 const cc::BeginFrameArgs& last_begin_frame_args_sent_to_observer) { | |
315 // If |last_begin_frame_args_| is still effective, send it to the new | |
316 // |observer| immediately. | |
317 if (!last_begin_frame_args_sent_to_observer.deadline.is_null() && | |
318 last_begin_frame_args_sent_to_observer != last_begin_frame_args_) { | |
319 last_begin_frame_args_.type = cc::BeginFrameArgs::MISSED; | |
brianderson
2014/12/09 21:56:32
What about calling last_begin_frame_args_ missed_b
simonhong
2014/12/11 17:45:48
Done.
brianderson
2014/12/12 01:17:02
Thanks. I realize now that the if statement above
| |
320 observer->OnSendBeginFrame(last_begin_frame_args_); | |
321 } | |
322 | |
323 if (!begin_frame_observer_list_.might_have_observers()) | |
324 SetChildrenNeedBeginFrames(true); | |
325 begin_frame_observer_list_.AddObserver(observer); | |
326 } | |
327 | |
328 void Compositor::RemoveBeginFrameObserver( | |
329 CompositorBeginFrameObserver* observer) { | |
330 DCHECK(begin_frame_observer_list_.might_have_observers()); | |
331 begin_frame_observer_list_.RemoveObserver(observer); | |
332 | |
333 if (!begin_frame_observer_list_.might_have_observers()) | |
334 SetChildrenNeedBeginFrames(false); | |
335 } | |
336 | |
337 bool Compositor::HasBeginFrameObserver(CompositorBeginFrameObserver* observer) { | |
338 return begin_frame_observer_list_.HasObserver(observer); | |
339 } | |
340 | |
305 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { | 341 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { |
306 FOR_EACH_OBSERVER(CompositorAnimationObserver, | 342 FOR_EACH_OBSERVER(CompositorAnimationObserver, |
307 animation_observer_list_, | 343 animation_observer_list_, |
308 OnAnimationStep(args.frame_time)); | 344 OnAnimationStep(args.frame_time)); |
309 if (animation_observer_list_.might_have_observers()) | 345 if (animation_observer_list_.might_have_observers()) |
310 host_->SetNeedsAnimate(); | 346 host_->SetNeedsAnimate(); |
311 } | 347 } |
312 | 348 |
313 void Compositor::Layout() { | 349 void Compositor::Layout() { |
314 // We're sending damage that will be addressed during this composite | 350 // We're sending damage that will be addressed during this composite |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 388 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, |
353 OnCompositingStarted(this, start_time)); | 389 OnCompositingStarted(this, start_time)); |
354 } | 390 } |
355 | 391 |
356 void Compositor::DidAbortSwapBuffers() { | 392 void Compositor::DidAbortSwapBuffers() { |
357 FOR_EACH_OBSERVER(CompositorObserver, | 393 FOR_EACH_OBSERVER(CompositorObserver, |
358 observer_list_, | 394 observer_list_, |
359 OnCompositingAborted(this)); | 395 OnCompositingAborted(this)); |
360 } | 396 } |
361 | 397 |
398 void Compositor::SendBeginFramesToChildren(const cc::BeginFrameArgs& args) { | |
399 FOR_EACH_OBSERVER(CompositorBeginFrameObserver, | |
400 begin_frame_observer_list_, | |
401 OnSendBeginFrame(args)); | |
402 last_begin_frame_args_ = args; | |
403 } | |
404 | |
362 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { | 405 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { |
363 return host_->debug_state(); | 406 return host_->debug_state(); |
364 } | 407 } |
365 | 408 |
366 void Compositor::SetLayerTreeDebugState( | 409 void Compositor::SetLayerTreeDebugState( |
367 const cc::LayerTreeDebugState& debug_state) { | 410 const cc::LayerTreeDebugState& debug_state) { |
368 host_->SetDebugState(debug_state); | 411 host_->SetDebugState(debug_state); |
369 } | 412 } |
370 | 413 |
371 const cc::RendererSettings& Compositor::GetRendererSettings() const { | 414 const cc::RendererSettings& Compositor::GetRendererSettings() const { |
(...skipping 18 matching lines...) Expand all Loading... | |
390 FOR_EACH_OBSERVER(CompositorObserver, | 433 FOR_EACH_OBSERVER(CompositorObserver, |
391 observer_list_, | 434 observer_list_, |
392 OnCompositingLockStateChanged(this)); | 435 OnCompositingLockStateChanged(this)); |
393 } | 436 } |
394 | 437 |
395 void Compositor::CancelCompositorLock() { | 438 void Compositor::CancelCompositorLock() { |
396 if (compositor_lock_) | 439 if (compositor_lock_) |
397 compositor_lock_->CancelLock(); | 440 compositor_lock_->CancelLock(); |
398 } | 441 } |
399 | 442 |
443 void Compositor::SetChildrenNeedBeginFrames(bool need_begin_frames) { | |
444 host_->SetChildrenNeedBeginFrames(need_begin_frames); | |
445 } | |
446 | |
400 } // namespace ui | 447 } // namespace ui |
OLD | NEW |