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

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
« no previous file with comments | « ui/compositor/compositor.h ('k') | ui/compositor/compositor.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 const int kCompositorLockTimeoutMs = 67; 39 const int kCompositorLockTimeoutMs = 67;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 vsync_manager_(new CompositorVSyncManager()), 78 vsync_manager_(new CompositorVSyncManager()),
78 device_scale_factor_(0.0f), 79 device_scale_factor_(0.0f),
79 last_started_frame_(0), 80 last_started_frame_(0),
80 last_ended_frame_(0), 81 last_ended_frame_(0),
81 disable_schedule_composite_(false), 82 disable_schedule_composite_(false),
82 compositor_lock_(NULL), 83 compositor_lock_(NULL),
83 defer_draw_scheduling_(false), 84 defer_draw_scheduling_(false),
84 waiting_on_compositing_end_(false), 85 waiting_on_compositing_end_(false),
85 draw_on_compositing_end_(false), 86 draw_on_compositing_end_(false),
86 swap_state_(SWAP_NONE), 87 swap_state_(SWAP_NONE),
88 layer_animator_collection_(this),
87 schedule_draw_factory_(this) { 89 schedule_draw_factory_(this) {
88 root_web_layer_ = cc::Layer::Create(); 90 root_web_layer_ = cc::Layer::Create();
89 root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f)); 91 root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f));
90 92
91 CommandLine* command_line = CommandLine::ForCurrentProcess(); 93 CommandLine* command_line = CommandLine::ForCurrentProcess();
92 94
93 cc::LayerTreeSettings settings; 95 cc::LayerTreeSettings settings;
94 settings.refresh_rate = 96 settings.refresh_rate =
95 context_factory_->DoesCreateTestContexts() 97 context_factory_->DoesCreateTestContexts()
96 ? kTestRefreshRate 98 ? kTestRefreshRate
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 if (!root_layer_) 212 if (!root_layer_)
211 return; 213 return;
212 214
213 DCHECK_NE(swap_state_, SWAP_POSTED); 215 DCHECK_NE(swap_state_, SWAP_POSTED);
214 swap_state_ = SWAP_NONE; 216 swap_state_ = SWAP_NONE;
215 217
216 last_started_frame_++; 218 last_started_frame_++;
217 if (!IsLocked()) { 219 if (!IsLocked()) {
218 // TODO(nduca): Temporary while compositor calls 220 // TODO(nduca): Temporary while compositor calls
219 // compositeImmediately() directly. 221 // compositeImmediately() directly.
222 base::TimeTicks now = gfx::FrameTime::Now();
223 Animate(now);
220 Layout(); 224 Layout();
221 host_->Composite(gfx::FrameTime::Now()); 225 host_->Composite(now);
222 } 226 }
223 if (swap_state_ == SWAP_NONE) 227 if (swap_state_ == SWAP_NONE)
224 NotifyEnd(); 228 NotifyEnd();
225 } 229 }
226 230
227 void Compositor::ScheduleFullRedraw() { 231 void Compositor::ScheduleFullRedraw() {
228 host_->SetNeedsRedraw(); 232 host_->SetNeedsRedraw();
229 } 233 }
230 234
231 void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) { 235 void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 275 }
272 276
273 void Compositor::RemoveObserver(CompositorObserver* observer) { 277 void Compositor::RemoveObserver(CompositorObserver* observer) {
274 observer_list_.RemoveObserver(observer); 278 observer_list_.RemoveObserver(observer);
275 } 279 }
276 280
277 bool Compositor::HasObserver(CompositorObserver* observer) { 281 bool Compositor::HasObserver(CompositorObserver* observer) {
278 return observer_list_.HasObserver(observer); 282 return observer_list_.HasObserver(observer);
279 } 283 }
280 284
285 void Compositor::Animate(base::TimeTicks frame_begin_time) {
286 layer_animator_collection_.Progress(frame_begin_time);
287 if (layer_animator_collection_.HasActiveAnimators())
288 host_->SetNeedsAnimate();
289 }
290
281 void Compositor::Layout() { 291 void Compositor::Layout() {
282 // We're sending damage that will be addressed during this composite 292 // We're sending damage that will be addressed during this composite
283 // cycle, so we don't need to schedule another composite to address it. 293 // cycle, so we don't need to schedule another composite to address it.
284 disable_schedule_composite_ = true; 294 disable_schedule_composite_ = true;
285 if (root_layer_) 295 if (root_layer_)
286 root_layer_->SendDamagedRects(); 296 root_layer_->SendDamagedRects();
287 disable_schedule_composite_ = false; 297 disable_schedule_composite_ = false;
288 } 298 }
289 299
290 scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface(bool fallback) { 300 scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface(bool fallback) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 NotifyEnd(); 346 NotifyEnd();
337 swap_state_ = SWAP_COMPLETED; 347 swap_state_ = SWAP_COMPLETED;
338 } 348 }
339 } 349 }
340 350
341 FOR_EACH_OBSERVER(CompositorObserver, 351 FOR_EACH_OBSERVER(CompositorObserver,
342 observer_list_, 352 observer_list_,
343 OnCompositingAborted(this)); 353 OnCompositingAborted(this));
344 } 354 }
345 355
356 void Compositor::ScheduleAnimationForLayerCollection() {
357 host_->SetNeedsAnimate();
358 }
359
346 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { 360 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const {
347 return host_->debug_state(); 361 return host_->debug_state();
348 } 362 }
349 363
350 void Compositor::SetLayerTreeDebugState( 364 void Compositor::SetLayerTreeDebugState(
351 const cc::LayerTreeDebugState& debug_state) { 365 const cc::LayerTreeDebugState& debug_state) {
352 host_->SetDebugState(debug_state); 366 host_->SetDebugState(debug_state);
353 } 367 }
354 368
355 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { 369 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 // CompositorObservers to be notified before starting another 404 // CompositorObservers to be notified before starting another
391 // draw cycle. 405 // draw cycle.
392 ScheduleDraw(); 406 ScheduleDraw();
393 } 407 }
394 FOR_EACH_OBSERVER(CompositorObserver, 408 FOR_EACH_OBSERVER(CompositorObserver,
395 observer_list_, 409 observer_list_,
396 OnCompositingEnded(this)); 410 OnCompositingEnded(this));
397 } 411 }
398 412
399 } // namespace ui 413 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/compositor.h ('k') | ui/compositor/compositor.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698