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

Side by Side Diff: ui/compositor/compositor.cc

Issue 638653003: Make ui::Compositor use ui::Scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase with enable mode patch since that would probably go in before this Created 6 years 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
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 "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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 ui::ContextFactory* context_factory, 68 ui::ContextFactory* context_factory,
69 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 69 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
70 : context_factory_(context_factory), 70 : context_factory_(context_factory),
71 root_layer_(NULL), 71 root_layer_(NULL),
72 widget_(widget), 72 widget_(widget),
73 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()), 73 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()),
74 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), 74 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()),
75 task_runner_(task_runner), 75 task_runner_(task_runner),
76 vsync_manager_(new CompositorVSyncManager()), 76 vsync_manager_(new CompositorVSyncManager()),
77 device_scale_factor_(0.0f), 77 device_scale_factor_(0.0f),
78 last_started_frame_(0),
79 last_ended_frame_(0),
80 disable_schedule_composite_(false), 78 disable_schedule_composite_(false),
81 compositor_lock_(NULL), 79 compositor_lock_(NULL),
82 defer_draw_scheduling_(false),
83 waiting_on_compositing_end_(false),
84 draw_on_compositing_end_(false),
85 swap_state_(SWAP_NONE),
86 layer_animator_collection_(this), 80 layer_animator_collection_(this),
87 weak_ptr_factory_(this) { 81 weak_ptr_factory_(this) {
88 root_web_layer_ = cc::Layer::Create(); 82 root_web_layer_ = cc::Layer::Create();
89 83
90 CommandLine* command_line = CommandLine::ForCurrentProcess(); 84 CommandLine* command_line = CommandLine::ForCurrentProcess();
91 85
92 cc::LayerTreeSettings settings; 86 cc::LayerTreeSettings settings;
93 // When impl-side painting is enabled, this will ensure PictureLayers always 87 // When impl-side painting is enabled, this will ensure PictureLayers always
94 // can have LCD text, to match the previous behaviour with ContentLayers, 88 // can have LCD text, to match the previous behaviour with ContentLayers,
95 // where LCD-not-allowed notifications were ignored. 89 // where LCD-not-allowed notifications were ignored.
96 settings.layers_always_allowed_lcd_text = true; 90 settings.layers_always_allowed_lcd_text = true;
97 settings.renderer_settings.refresh_rate = 91 settings.renderer_settings.refresh_rate =
98 context_factory_->DoesCreateTestContexts() ? kTestRefreshRate 92 context_factory_->DoesCreateTestContexts() ? kTestRefreshRate
99 : kDefaultRefreshRate; 93 : kDefaultRefreshRate;
100 settings.main_frame_before_activation_enabled = false; 94 settings.main_frame_before_activation_enabled = false;
101 settings.throttle_frame_production = 95 settings.throttle_frame_production =
102 !command_line->HasSwitch(switches::kDisableGpuVsync); 96 !command_line->HasSwitch(switches::kDisableGpuVsync);
103 #if !defined(OS_MACOSX) 97 #if !defined(OS_MACOSX)
104 settings.renderer_settings.partial_swap_enabled = 98 settings.renderer_settings.partial_swap_enabled =
105 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap); 99 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap);
106 #endif 100 #endif
107 #if defined(OS_CHROMEOS) 101 #if defined(OS_CHROMEOS)
108 settings.per_tile_painting_enabled = true; 102 settings.per_tile_painting_enabled = true;
109 #endif 103 #endif
110 #if defined(OS_WIN) 104 #if defined(OS_WIN)
111 settings.disable_hi_res_timer_tasks_on_battery = true; 105 settings.disable_hi_res_timer_tasks_on_battery =
106 !context_factory_->DoesCreateTestContexts();
112 settings.renderer_settings.finish_rendering_on_resize = true; 107 settings.renderer_settings.finish_rendering_on_resize = true;
113 #endif 108 #endif
114 109
115 // These flags should be mirrored by renderer versions in content/renderer/. 110 // These flags should be mirrored by renderer versions in content/renderer/.
116 settings.initial_debug_state.show_debug_borders = 111 settings.initial_debug_state.show_debug_borders =
117 command_line->HasSwitch(cc::switches::kUIShowCompositedLayerBorders); 112 command_line->HasSwitch(cc::switches::kUIShowCompositedLayerBorders);
118 settings.initial_debug_state.show_fps_counter = 113 settings.initial_debug_state.show_fps_counter =
119 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); 114 command_line->HasSwitch(cc::switches::kUIShowFPSCounter);
120 settings.initial_debug_state.show_layer_animation_bounds_rects = 115 settings.initial_debug_state.show_layer_animation_bounds_rects =
121 command_line->HasSwitch(cc::switches::kUIShowLayerAnimationBounds); 116 command_line->HasSwitch(cc::switches::kUIShowLayerAnimationBounds);
(...skipping 10 matching lines...) Expand all
132 settings.initial_debug_state.show_occluding_rects = 127 settings.initial_debug_state.show_occluding_rects =
133 command_line->HasSwitch(cc::switches::kUIShowOccludingRects); 128 command_line->HasSwitch(cc::switches::kUIShowOccludingRects);
134 settings.initial_debug_state.show_non_occluding_rects = 129 settings.initial_debug_state.show_non_occluding_rects =
135 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects); 130 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects);
136 131
137 settings.initial_debug_state.SetRecordRenderingStats( 132 settings.initial_debug_state.SetRecordRenderingStats(
138 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); 133 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking));
139 134
140 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); 135 settings.impl_side_painting = IsUIImplSidePaintingEnabled();
141 settings.use_zero_copy = IsUIZeroCopyEnabled(); 136 settings.use_zero_copy = IsUIZeroCopyEnabled();
142 settings.single_thread_proxy_scheduler = false;
143 137
144 base::TimeTicks before_create = base::TimeTicks::Now(); 138 base::TimeTicks before_create = base::TimeTicks::Now();
145 if (compositor_thread_loop_.get()) { 139 if (compositor_thread_loop_.get()) {
146 host_ = cc::LayerTreeHost::CreateThreaded( 140 host_ = cc::LayerTreeHost::CreateThreaded(
147 this, 141 this,
148 context_factory_->GetSharedBitmapManager(), 142 context_factory_->GetSharedBitmapManager(),
149 context_factory_->GetGpuMemoryBufferManager(), 143 context_factory_->GetGpuMemoryBufferManager(),
150 settings, 144 settings,
151 task_runner_, 145 task_runner_,
152 compositor_thread_loop_, 146 compositor_thread_loop_,
(...skipping 30 matching lines...) Expand all
183 177
184 context_factory_->RemoveCompositor(this); 178 context_factory_->RemoveCompositor(this);
185 } 179 }
186 180
187 void Compositor::SetOutputSurface( 181 void Compositor::SetOutputSurface(
188 scoped_ptr<cc::OutputSurface> output_surface) { 182 scoped_ptr<cc::OutputSurface> output_surface) {
189 host_->SetOutputSurface(output_surface.Pass()); 183 host_->SetOutputSurface(output_surface.Pass());
190 } 184 }
191 185
192 void Compositor::ScheduleDraw() { 186 void Compositor::ScheduleDraw() {
193 if (compositor_thread_loop_.get()) { 187 host_->SetNeedsCommit();
194 host_->SetNeedsCommit();
195 } else if (!defer_draw_scheduling_) {
196 defer_draw_scheduling_ = true;
197 task_runner_->PostTask(
198 FROM_HERE,
199 base::Bind(&Compositor::Draw, weak_ptr_factory_.GetWeakPtr()));
200 }
201 } 188 }
202 189
203 void Compositor::SetRootLayer(Layer* root_layer) { 190 void Compositor::SetRootLayer(Layer* root_layer) {
204 if (root_layer_ == root_layer) 191 if (root_layer_ == root_layer)
205 return; 192 return;
206 if (root_layer_) 193 if (root_layer_)
207 root_layer_->SetCompositor(NULL); 194 root_layer_->SetCompositor(NULL);
208 root_layer_ = root_layer; 195 root_layer_ = root_layer;
209 if (root_layer_ && !root_layer_->GetCompositor()) 196 if (root_layer_ && !root_layer_->GetCompositor())
210 root_layer_->SetCompositor(this); 197 root_layer_->SetCompositor(this);
211 root_web_layer_->RemoveAllChildren(); 198 root_web_layer_->RemoveAllChildren();
212 if (root_layer_) 199 if (root_layer_)
213 root_web_layer_->AddChild(root_layer_->cc_layer()); 200 root_web_layer_->AddChild(root_layer_->cc_layer());
214 } 201 }
215 202
216 void Compositor::SetHostHasTransparentBackground( 203 void Compositor::SetHostHasTransparentBackground(
217 bool host_has_transparent_background) { 204 bool host_has_transparent_background) {
218 host_->set_has_transparent_background(host_has_transparent_background); 205 host_->set_has_transparent_background(host_has_transparent_background);
219 } 206 }
220 207
221 void Compositor::Draw() {
222 DCHECK(!compositor_thread_loop_.get());
223
224 defer_draw_scheduling_ = false;
225 if (waiting_on_compositing_end_) {
226 draw_on_compositing_end_ = true;
227 return;
228 }
229 if (!root_layer_)
230 return;
231
232 TRACE_EVENT_ASYNC_BEGIN0("ui", "Compositor::Draw", last_started_frame_ + 1);
233
234 DCHECK_NE(swap_state_, SWAP_POSTED);
235 swap_state_ = SWAP_NONE;
236
237 waiting_on_compositing_end_ = true;
238 last_started_frame_++;
239 if (!IsLocked()) {
240 // TODO(nduca): Temporary while compositor calls
241 // compositeImmediately() directly.
242 cc::BeginFrameArgs args = cc::BeginFrameArgs::Create(
243 BEGINFRAME_FROM_HERE, gfx::FrameTime::Now(), base::TimeTicks(),
244 cc::BeginFrameArgs::DefaultInterval(), cc::BeginFrameArgs::SYNCHRONOUS);
245 BeginMainFrame(args);
246 host_->Composite(args.frame_time);
247 }
248 if (swap_state_ == SWAP_NONE)
249 NotifyEnd();
250 }
251
252 void Compositor::ScheduleFullRedraw() { 208 void Compositor::ScheduleFullRedraw() {
209 // TODO(enne): Some callers (mac) call this function expecting that it
210 // will also commit. This should probably just redraw the screen
211 // from damage and not commit. ScheduleDraw/ScheduleRedraw need
212 // better names.
253 host_->SetNeedsRedraw(); 213 host_->SetNeedsRedraw();
214 host_->SetNeedsCommit();
254 } 215 }
255 216
256 void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) { 217 void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) {
218 // TODO(enne): Make this not commit. See ScheduleFullRedraw.
257 host_->SetNeedsRedrawRect(damage_rect); 219 host_->SetNeedsRedrawRect(damage_rect);
220 host_->SetNeedsCommit();
258 } 221 }
259 222
260 void Compositor::DisableSwapUntilResize() { 223 void Compositor::DisableSwapUntilResize() {
261 host_->FinishAllRendering(); 224 host_->FinishAllRendering();
262 context_factory_->ResizeDisplay(this, gfx::Size()); 225 context_factory_->ResizeDisplay(this, gfx::Size());
263 } 226 }
264 227
265 void Compositor::SetLatencyInfo(const ui::LatencyInfo& latency_info) { 228 void Compositor::SetLatencyInfo(const ui::LatencyInfo& latency_info) {
266 scoped_ptr<cc::SwapPromise> swap_promise( 229 scoped_ptr<cc::SwapPromise> swap_promise(
267 new cc::LatencyInfoSwapPromise(latency_info)); 230 new cc::LatencyInfoSwapPromise(latency_info));
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 } 325 }
363 326
364 void Compositor::DidCommit() { 327 void Compositor::DidCommit() {
365 DCHECK(!IsLocked()); 328 DCHECK(!IsLocked());
366 FOR_EACH_OBSERVER(CompositorObserver, 329 FOR_EACH_OBSERVER(CompositorObserver,
367 observer_list_, 330 observer_list_,
368 OnCompositingDidCommit(this)); 331 OnCompositingDidCommit(this));
369 } 332 }
370 333
371 void Compositor::DidCommitAndDrawFrame() { 334 void Compositor::DidCommitAndDrawFrame() {
335 }
336
337 void Compositor::DidCompleteSwapBuffers() {
338 // DidPostSwapBuffers is a SingleThreadProxy-only feature. Synthetically
339 // generate OnCompositingStarted messages for the threaded case so that
340 // OnCompositingStarted/OnCompositingEnded messages match.
341 if (compositor_thread_loop_.get()) {
342 base::TimeTicks start_time = gfx::FrameTime::Now();
343 FOR_EACH_OBSERVER(CompositorObserver, observer_list_,
344 OnCompositingStarted(this, start_time));
345 }
346 FOR_EACH_OBSERVER(CompositorObserver, observer_list_,
347 OnCompositingEnded(this));
348 }
349
350 void Compositor::DidPostSwapBuffers() {
372 base::TimeTicks start_time = gfx::FrameTime::Now(); 351 base::TimeTicks start_time = gfx::FrameTime::Now();
373 FOR_EACH_OBSERVER(CompositorObserver, 352 FOR_EACH_OBSERVER(CompositorObserver, observer_list_,
374 observer_list_,
375 OnCompositingStarted(this, start_time)); 353 OnCompositingStarted(this, start_time));
376 } 354 }
377 355
378 void Compositor::DidCompleteSwapBuffers() {
379 if (compositor_thread_loop_.get()) {
380 NotifyEnd();
381 } else {
382 DCHECK_EQ(swap_state_, SWAP_POSTED);
383 NotifyEnd();
384 swap_state_ = SWAP_COMPLETED;
385 }
386 }
387
388 void Compositor::ScheduleComposite() {
389 if (!disable_schedule_composite_)
390 ScheduleDraw();
391 }
392
393 void Compositor::ScheduleAnimation() {
394 ScheduleComposite();
395 }
396
397 void Compositor::DidPostSwapBuffers() {
398 DCHECK(!compositor_thread_loop_.get());
399 DCHECK_EQ(swap_state_, SWAP_NONE);
400 swap_state_ = SWAP_POSTED;
401 }
402
403 void Compositor::DidAbortSwapBuffers() { 356 void Compositor::DidAbortSwapBuffers() {
404 if (!compositor_thread_loop_.get()) {
405 if (swap_state_ == SWAP_POSTED) {
406 NotifyEnd();
407 swap_state_ = SWAP_COMPLETED;
408 }
409 }
410
411 FOR_EACH_OBSERVER(CompositorObserver, 357 FOR_EACH_OBSERVER(CompositorObserver,
412 observer_list_, 358 observer_list_,
413 OnCompositingAborted(this)); 359 OnCompositingAborted(this));
414 } 360 }
415 361
416 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { 362 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const {
417 return host_->debug_state(); 363 return host_->debug_state();
418 } 364 }
419 365
420 void Compositor::SetLayerTreeDebugState( 366 void Compositor::SetLayerTreeDebugState(
421 const cc::LayerTreeDebugState& debug_state) { 367 const cc::LayerTreeDebugState& debug_state) {
422 host_->SetDebugState(debug_state); 368 host_->SetDebugState(debug_state);
423 } 369 }
424 370
425 const cc::RendererSettings& Compositor::GetRendererSettings() const { 371 const cc::RendererSettings& Compositor::GetRendererSettings() const {
426 return host_->settings().renderer_settings; 372 return host_->settings().renderer_settings;
427 } 373 }
428 374
429 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { 375 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() {
430 if (!compositor_lock_) { 376 if (!compositor_lock_) {
431 compositor_lock_ = new CompositorLock(this); 377 compositor_lock_ = new CompositorLock(this);
432 if (compositor_thread_loop_.get()) 378 host_->SetDeferCommits(true);
433 host_->SetDeferCommits(true);
434 FOR_EACH_OBSERVER(CompositorObserver, 379 FOR_EACH_OBSERVER(CompositorObserver,
435 observer_list_, 380 observer_list_,
436 OnCompositingLockStateChanged(this)); 381 OnCompositingLockStateChanged(this));
437 } 382 }
438 return compositor_lock_; 383 return compositor_lock_;
439 } 384 }
440 385
441 void Compositor::UnlockCompositor() { 386 void Compositor::UnlockCompositor() {
442 DCHECK(compositor_lock_); 387 DCHECK(compositor_lock_);
443 compositor_lock_ = NULL; 388 compositor_lock_ = NULL;
444 if (compositor_thread_loop_.get()) 389 host_->SetDeferCommits(false);
445 host_->SetDeferCommits(false);
446 FOR_EACH_OBSERVER(CompositorObserver, 390 FOR_EACH_OBSERVER(CompositorObserver,
447 observer_list_, 391 observer_list_,
448 OnCompositingLockStateChanged(this)); 392 OnCompositingLockStateChanged(this));
449 } 393 }
450 394
451 void Compositor::CancelCompositorLock() { 395 void Compositor::CancelCompositorLock() {
452 if (compositor_lock_) 396 if (compositor_lock_)
453 compositor_lock_->CancelLock(); 397 compositor_lock_->CancelLock();
454 } 398 }
455 399
456 void Compositor::NotifyEnd() {
457 last_ended_frame_++;
458 TRACE_EVENT_ASYNC_END0("ui", "Compositor::Draw", last_ended_frame_);
459 waiting_on_compositing_end_ = false;
460 if (draw_on_compositing_end_) {
461 draw_on_compositing_end_ = false;
462
463 // Call ScheduleDraw() instead of Draw() in order to allow other
464 // CompositorObservers to be notified before starting another
465 // draw cycle.
466 ScheduleDraw();
467 }
468 FOR_EACH_OBSERVER(
469 CompositorObserver, observer_list_, OnCompositingEnded(this));
470 }
471
472 } // namespace ui 400 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698