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

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

Issue 427103002: compositor: Add rAF-like functionality for the UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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 "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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 device_scale_factor_(0.0f), 81 device_scale_factor_(0.0f),
82 last_started_frame_(0), 82 last_started_frame_(0),
83 last_ended_frame_(0), 83 last_ended_frame_(0),
84 disable_schedule_composite_(false), 84 disable_schedule_composite_(false),
85 compositor_lock_(NULL), 85 compositor_lock_(NULL),
86 defer_draw_scheduling_(false), 86 defer_draw_scheduling_(false),
87 waiting_on_compositing_end_(false), 87 waiting_on_compositing_end_(false),
88 draw_on_compositing_end_(false), 88 draw_on_compositing_end_(false),
89 swap_state_(SWAP_NONE), 89 swap_state_(SWAP_NONE),
90 layer_animator_collection_(this), 90 layer_animator_collection_(this),
91 schedule_draw_factory_(this) { 91 weak_ptr_factory_(this) {
92 root_web_layer_ = cc::Layer::Create(); 92 root_web_layer_ = cc::Layer::Create();
93 93
94 CommandLine* command_line = CommandLine::ForCurrentProcess(); 94 CommandLine* command_line = CommandLine::ForCurrentProcess();
95 95
96 cc::LayerTreeSettings settings; 96 cc::LayerTreeSettings settings;
97 settings.refresh_rate = 97 settings.refresh_rate =
98 context_factory_->DoesCreateTestContexts() 98 context_factory_->DoesCreateTestContexts()
99 ? kTestRefreshRate 99 ? kTestRefreshRate
100 : kDefaultRefreshRate; 100 : kDefaultRefreshRate;
101 settings.main_frame_before_draw_enabled = false; 101 settings.main_frame_before_draw_enabled = false;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 context_factory_->RemoveCompositor(this); 176 context_factory_->RemoveCompositor(this);
177 } 177 }
178 178
179 void Compositor::ScheduleDraw() { 179 void Compositor::ScheduleDraw() {
180 if (compositor_thread_loop_) { 180 if (compositor_thread_loop_) {
181 host_->SetNeedsCommit(); 181 host_->SetNeedsCommit();
182 } else if (!defer_draw_scheduling_) { 182 } else if (!defer_draw_scheduling_) {
183 defer_draw_scheduling_ = true; 183 defer_draw_scheduling_ = true;
184 task_runner_->PostTask( 184 task_runner_->PostTask(
185 FROM_HERE, 185 FROM_HERE,
186 base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr())); 186 base::Bind(&Compositor::Draw, weak_ptr_factory_.GetWeakPtr()));
187 } 187 }
188 } 188 }
189 189
190 void Compositor::SetRootLayer(Layer* root_layer) { 190 void Compositor::SetRootLayer(Layer* root_layer) {
191 if (root_layer_ == root_layer) 191 if (root_layer_ == root_layer)
192 return; 192 return;
193 if (root_layer_) 193 if (root_layer_)
194 root_layer_->SetCompositor(NULL); 194 root_layer_->SetCompositor(NULL);
195 root_layer_ = root_layer; 195 root_layer_ = root_layer;
196 if (root_layer_ && !root_layer_->GetCompositor()) 196 if (root_layer_ && !root_layer_->GetCompositor())
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 283
284 void Compositor::RemoveObserver(CompositorObserver* observer) { 284 void Compositor::RemoveObserver(CompositorObserver* observer) {
285 observer_list_.RemoveObserver(observer); 285 observer_list_.RemoveObserver(observer);
286 } 286 }
287 287
288 bool Compositor::HasObserver(CompositorObserver* observer) { 288 bool Compositor::HasObserver(CompositorObserver* observer) {
289 return observer_list_.HasObserver(observer); 289 return observer_list_.HasObserver(observer);
290 } 290 }
291 291
292 void Compositor::Animate(base::TimeTicks frame_begin_time) { 292 void Compositor::Animate(base::TimeTicks frame_begin_time) {
293 layer_animator_collection_.Progress(frame_begin_time); 293 bool should_animate = false;
294 if (layer_animator_collection_.HasActiveAnimators()) 294 std::set<AnimationFrameTask*> tasks = rafs_;
295 for (std::set<AnimationFrameTask*>::iterator i = tasks.begin();
296 i != tasks.end();
297 ++i) {
298 AnimationFrameTask* task = *i;
299 if (!rafs_.count(task))
300 continue;
301 if (task->Progress(frame_begin_time) == ANIMATION_FRAME_TASK_CONTINUE) {
302 CHECK(rafs_.count(task));
piman 2014/07/31 01:17:03 nit: DCHECK
303 should_animate = true;
304 } else {
305 DCHECK(!rafs_.count(task));
306 }
307 }
piman 2014/07/31 01:17:03 maybe it's naive, but why wouldn't the standard Ob
308
309 if (should_animate)
295 host_->SetNeedsAnimate(); 310 host_->SetNeedsAnimate();
296 } 311 }
297 312
298 void Compositor::Layout() { 313 void Compositor::Layout() {
299 // We're sending damage that will be addressed during this composite 314 // We're sending damage that will be addressed during this composite
300 // cycle, so we don't need to schedule another composite to address it. 315 // cycle, so we don't need to schedule another composite to address it.
301 disable_schedule_composite_ = true; 316 disable_schedule_composite_ = true;
302 if (root_layer_) 317 if (root_layer_)
303 root_layer_->SendDamagedRects(); 318 root_layer_->SendDamagedRects();
304 disable_schedule_composite_ = false; 319 disable_schedule_composite_ = false;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 NotifyEnd(); 368 NotifyEnd();
354 swap_state_ = SWAP_COMPLETED; 369 swap_state_ = SWAP_COMPLETED;
355 } 370 }
356 } 371 }
357 372
358 FOR_EACH_OBSERVER(CompositorObserver, 373 FOR_EACH_OBSERVER(CompositorObserver,
359 observer_list_, 374 observer_list_,
360 OnCompositingAborted(this)); 375 OnCompositingAborted(this));
361 } 376 }
362 377
363 void Compositor::ScheduleAnimationForLayerCollection() {
364 host_->SetNeedsAnimate();
365 }
366
367 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { 378 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const {
368 return host_->debug_state(); 379 return host_->debug_state();
369 } 380 }
370 381
371 void Compositor::SetLayerTreeDebugState( 382 void Compositor::SetLayerTreeDebugState(
372 const cc::LayerTreeDebugState& debug_state) { 383 const cc::LayerTreeDebugState& debug_state) {
373 host_->SetDebugState(debug_state); 384 host_->SetDebugState(debug_state);
374 } 385 }
375 386
376 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { 387 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 // Call ScheduleDraw() instead of Draw() in order to allow other 421 // Call ScheduleDraw() instead of Draw() in order to allow other
411 // CompositorObservers to be notified before starting another 422 // CompositorObservers to be notified before starting another
412 // draw cycle. 423 // draw cycle.
413 ScheduleDraw(); 424 ScheduleDraw();
414 } 425 }
415 FOR_EACH_OBSERVER(CompositorObserver, 426 FOR_EACH_OBSERVER(CompositorObserver,
416 observer_list_, 427 observer_list_,
417 OnCompositingEnded(this)); 428 OnCompositingEnded(this));
418 } 429 }
419 430
431 scoped_ptr<ScopedAnimationFrameTask> Compositor::RequestAnimationFrameTask(
432 AnimationFrameTask* task) {
433 CHECK(!rafs_.count(task));
434 rafs_.insert(task);
435 host_->SetNeedsAnimate();
436 return make_scoped_ptr(new ScopedAnimationFrameTask(
437 task,
438 base::Bind(&Compositor::RemoveAnimationFrameTask,
439 weak_ptr_factory_.GetWeakPtr(),
440 task)));
441 }
442
443 void Compositor::RemoveAnimationFrameTask(AnimationFrameTask* task) {
444 CHECK(rafs_.count(task));
445 rafs_.erase(task);
446 }
447
420 } // namespace ui 448 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698