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

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

Issue 291843012: compositor: Tick the UI animations from cc, instead of from timer callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 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"
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/trees/layer_tree_host.h" 22 #include "cc/trees/layer_tree_host.h"
23 #include "third_party/skia/include/core/SkBitmap.h" 23 #include "third_party/skia/include/core/SkBitmap.h"
24 #include "ui/compositor/compositor_observer.h" 24 #include "ui/compositor/compositor_observer.h"
25 #include "ui/compositor/compositor_switches.h" 25 #include "ui/compositor/compositor_switches.h"
26 #include "ui/compositor/compositor_vsync_manager.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/gfx/frame_time.h" 30 #include "ui/gfx/frame_time.h"
30 #include "ui/gl/gl_context.h" 31 #include "ui/gl/gl_context.h"
31 #include "ui/gl/gl_switches.h" 32 #include "ui/gl/gl_switches.h"
32 33
33 namespace { 34 namespace {
34 35
35 const double kDefaultRefreshRate = 60.0; 36 const double kDefaultRefreshRate = 60.0;
36 const double kTestRefreshRate = 200.0; 37 const double kTestRefreshRate = 200.0;
37 38
38 ui::ContextFactory* g_context_factory = NULL; 39 ui::ContextFactory* g_context_factory = NULL;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 vsync_manager_(new CompositorVSyncManager()), 91 vsync_manager_(new CompositorVSyncManager()),
91 device_scale_factor_(0.0f), 92 device_scale_factor_(0.0f),
92 last_started_frame_(0), 93 last_started_frame_(0),
93 last_ended_frame_(0), 94 last_ended_frame_(0),
94 disable_schedule_composite_(false), 95 disable_schedule_composite_(false),
95 compositor_lock_(NULL), 96 compositor_lock_(NULL),
96 defer_draw_scheduling_(false), 97 defer_draw_scheduling_(false),
97 waiting_on_compositing_end_(false), 98 waiting_on_compositing_end_(false),
98 draw_on_compositing_end_(false), 99 draw_on_compositing_end_(false),
99 swap_state_(SWAP_NONE), 100 swap_state_(SWAP_NONE),
101 layer_animator_collection_(this),
100 schedule_draw_factory_(this) { 102 schedule_draw_factory_(this) {
101 Init(); 103 Init();
102 } 104 }
103 105
104 Compositor::Compositor(gfx::AcceleratedWidget widget, 106 Compositor::Compositor(gfx::AcceleratedWidget widget,
105 ui::ContextFactory* context_factory) 107 ui::ContextFactory* context_factory)
106 : context_factory_(context_factory), 108 : context_factory_(context_factory),
107 root_layer_(NULL), 109 root_layer_(NULL),
108 widget_(widget), 110 widget_(widget),
109 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), 111 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()),
110 vsync_manager_(new CompositorVSyncManager()), 112 vsync_manager_(new CompositorVSyncManager()),
111 device_scale_factor_(0.0f), 113 device_scale_factor_(0.0f),
112 last_started_frame_(0), 114 last_started_frame_(0),
113 last_ended_frame_(0), 115 last_ended_frame_(0),
114 disable_schedule_composite_(false), 116 disable_schedule_composite_(false),
115 compositor_lock_(NULL), 117 compositor_lock_(NULL),
116 defer_draw_scheduling_(false), 118 defer_draw_scheduling_(false),
117 waiting_on_compositing_end_(false), 119 waiting_on_compositing_end_(false),
118 draw_on_compositing_end_(false), 120 draw_on_compositing_end_(false),
119 swap_state_(SWAP_NONE), 121 swap_state_(SWAP_NONE),
122 layer_animator_collection_(this),
120 schedule_draw_factory_(this) { 123 schedule_draw_factory_(this) {
121 Init(); 124 Init();
122 } 125 }
123 126
124 // Yes, this is the wrong place. I'm leaving here to minimize diffs since this 127 // Yes, this is the wrong place. I'm leaving here to minimize diffs since this
125 // function will be nuked soonish. 128 // function will be nuked soonish.
126 void Compositor::Init() { 129 void Compositor::Init() {
127 root_web_layer_ = cc::Layer::Create(); 130 root_web_layer_ = cc::Layer::Create();
128 root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f)); 131 root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f));
129 132
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 if (!root_layer_) 252 if (!root_layer_)
250 return; 253 return;
251 254
252 DCHECK_NE(swap_state_, SWAP_POSTED); 255 DCHECK_NE(swap_state_, SWAP_POSTED);
253 swap_state_ = SWAP_NONE; 256 swap_state_ = SWAP_NONE;
254 257
255 last_started_frame_++; 258 last_started_frame_++;
256 if (!IsLocked()) { 259 if (!IsLocked()) {
257 // TODO(nduca): Temporary while compositor calls 260 // TODO(nduca): Temporary while compositor calls
258 // compositeImmediately() directly. 261 // compositeImmediately() directly.
262 base::TimeTicks now = gfx::FrameTime::Now();
263 Animate(now);
259 Layout(); 264 Layout();
260 host_->Composite(gfx::FrameTime::Now()); 265 host_->Composite(now);
261 } 266 }
262 if (swap_state_ == SWAP_NONE) 267 if (swap_state_ == SWAP_NONE)
263 NotifyEnd(); 268 NotifyEnd();
264 } 269 }
265 270
266 void Compositor::ScheduleFullRedraw() { 271 void Compositor::ScheduleFullRedraw() {
267 host_->SetNeedsRedraw(); 272 host_->SetNeedsRedraw();
268 } 273 }
269 274
270 void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) { 275 void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 315 }
311 316
312 void Compositor::RemoveObserver(CompositorObserver* observer) { 317 void Compositor::RemoveObserver(CompositorObserver* observer) {
313 observer_list_.RemoveObserver(observer); 318 observer_list_.RemoveObserver(observer);
314 } 319 }
315 320
316 bool Compositor::HasObserver(CompositorObserver* observer) { 321 bool Compositor::HasObserver(CompositorObserver* observer) {
317 return observer_list_.HasObserver(observer); 322 return observer_list_.HasObserver(observer);
318 } 323 }
319 324
325 void Compositor::Animate(base::TimeTicks frame_begin_time) {
326 layer_animator_collection_.Progress(frame_begin_time);
327 if (layer_animator_collection_.HasActiveAnimators())
328 host_->SetNeedsAnimate();
329 }
330
320 void Compositor::Layout() { 331 void Compositor::Layout() {
321 // We're sending damage that will be addressed during this composite 332 // We're sending damage that will be addressed during this composite
322 // cycle, so we don't need to schedule another composite to address it. 333 // cycle, so we don't need to schedule another composite to address it.
323 disable_schedule_composite_ = true; 334 disable_schedule_composite_ = true;
324 if (root_layer_) 335 if (root_layer_)
325 root_layer_->SendDamagedRects(); 336 root_layer_->SendDamagedRects();
326 disable_schedule_composite_ = false; 337 disable_schedule_composite_ = false;
327 } 338 }
328 339
329 scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface(bool fallback) { 340 scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface(bool fallback) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 NotifyEnd(); 386 NotifyEnd();
376 swap_state_ = SWAP_COMPLETED; 387 swap_state_ = SWAP_COMPLETED;
377 } 388 }
378 } 389 }
379 390
380 FOR_EACH_OBSERVER(CompositorObserver, 391 FOR_EACH_OBSERVER(CompositorObserver,
381 observer_list_, 392 observer_list_,
382 OnCompositingAborted(this)); 393 OnCompositingAborted(this));
383 } 394 }
384 395
396 void Compositor::ScheduleAnimationForLayerCollection() {
397 ScheduleAnimation();
ajuma 2014/05/26 14:43:23 host_->SetNeedsAnimate()
sadrul 2014/05/28 21:41:22 Done (I assume you meant 'instead of' ScheduleAnim
398 }
399
385 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { 400 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const {
386 return host_->debug_state(); 401 return host_->debug_state();
387 } 402 }
388 403
389 void Compositor::SetLayerTreeDebugState( 404 void Compositor::SetLayerTreeDebugState(
390 const cc::LayerTreeDebugState& debug_state) { 405 const cc::LayerTreeDebugState& debug_state) {
391 host_->SetDebugState(debug_state); 406 host_->SetDebugState(debug_state);
392 } 407 }
393 408
394 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { 409 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 // CompositorObservers to be notified before starting another 444 // CompositorObservers to be notified before starting another
430 // draw cycle. 445 // draw cycle.
431 ScheduleDraw(); 446 ScheduleDraw();
432 } 447 }
433 FOR_EACH_OBSERVER(CompositorObserver, 448 FOR_EACH_OBSERVER(CompositorObserver,
434 observer_list_, 449 observer_list_,
435 OnCompositingEnded(this)); 450 OnCompositingEnded(this));
436 } 451 }
437 452
438 } // namespace ui 453 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698