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

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

Issue 8362006: Reland r107720 - Enable the new layer animation framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address reviewer comments. Created 9 years, 2 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/gfx/compositor/layer.h" 5 #include "ui/gfx/compositor/layer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "ui/base/animation/animation.h" 11 #include "ui/gfx/compositor/layer_animator.h"
12 #include "ui/gfx/compositor/layer_animation_manager.h"
13 #include "ui/gfx/canvas_skia.h" 12 #include "ui/gfx/canvas_skia.h"
14 #include "ui/gfx/interpolated_transform.h" 13 #include "ui/gfx/interpolated_transform.h"
15 #include "ui/gfx/point3.h" 14 #include "ui/gfx/point3.h"
16 15
17 namespace { 16 namespace {
18 17
19 const float EPSILON = 1e-3f; 18 const float EPSILON = 1e-3f;
20 19
21 bool IsApproximateMultilpleOf(float value, float base) { 20 bool IsApproximateMultilpleOf(float value, float base) {
22 float remainder = fmod(fabs(value), base); 21 float remainder = fmod(fabs(value), base);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 98 }
100 99
101 bool Layer::Contains(const Layer* other) const { 100 bool Layer::Contains(const Layer* other) const {
102 for (const Layer* parent = other; parent; parent = parent->parent()) { 101 for (const Layer* parent = other; parent; parent = parent->parent()) {
103 if (parent == this) 102 if (parent == this)
104 return true; 103 return true;
105 } 104 }
106 return false; 105 return false;
107 } 106 }
108 107
109 void Layer::SetAnimation(Animation* animation) { 108 void Layer::SetAnimator(LayerAnimator* animator) {
110 if (animation) { 109 if (animator)
111 if (!animator_.get()) 110 animator->SetDelegate(this);
112 animator_.reset(new LayerAnimationManager(this)); 111 animator_.reset(animator);
113 animation->Start(); 112 }
114 animator_->SetAnimation(animation); 113
115 } else { 114 LayerAnimator* Layer::GetAnimator() {
116 animator_.reset(); 115 if (!animator_.get())
117 } 116 SetAnimator(LayerAnimator::CreateDefaultAnimator());
117 return animator_.get();
118 } 118 }
119 119
120 void Layer::SetTransform(const ui::Transform& transform) { 120 void Layer::SetTransform(const ui::Transform& transform) {
121 StopAnimatingIfNecessary(LayerAnimationManager::TRANSFORM); 121 GetAnimator()->SetTransform(transform);
122 if (animator_.get() && animator_->IsRunning()) { 122 }
123 animator_->AnimateTransform(transform); 123
124 return; 124 Transform Layer::GetTargetTransform() const {
125 } 125 if (animator_.get() && animator_->is_animating())
126 SetTransformImmediately(transform); 126 return animator_->GetTargetTransform();
127 return transform_;
127 } 128 }
128 129
129 void Layer::SetBounds(const gfx::Rect& bounds) { 130 void Layer::SetBounds(const gfx::Rect& bounds) {
130 StopAnimatingIfNecessary(LayerAnimationManager::LOCATION); 131 GetAnimator()->SetBounds(bounds);
131 if (animator_.get() && animator_->IsRunning() &&
132 bounds.size() == bounds_.size()) {
133 animator_->AnimateToPoint(bounds.origin());
134 return;
135 }
136 SetBoundsImmediately(bounds);
137 } 132 }
138 133
139 gfx::Rect Layer::GetTargetBounds() const { 134 gfx::Rect Layer::GetTargetBounds() const {
140 if (animator_.get() && animator_->IsRunning()) 135 if (animator_.get() && animator_->is_animating())
141 return gfx::Rect(animator_->GetTargetPoint(), bounds_.size()); 136 return animator_->GetTargetBounds();
142 return bounds_; 137 return bounds_;
143 } 138 }
144 139
145 void Layer::SetOpacity(float opacity) { 140 void Layer::SetOpacity(float opacity) {
146 StopAnimatingIfNecessary(LayerAnimationManager::OPACITY); 141 GetAnimator()->SetOpacity(opacity);
147 if (animator_.get() && animator_->IsRunning()) { 142 }
148 animator_->AnimateOpacity(opacity); 143
149 return; 144 float Layer::GetTargetOpacity() const {
150 } 145 if (animator_.get() && animator_->is_animating())
151 SetOpacityImmediately(opacity); 146 return animator_->GetTargetOpacity();
147 return opacity_;
152 } 148 }
153 149
154 void Layer::SetVisible(bool visible) { 150 void Layer::SetVisible(bool visible) {
155 if (visible_ == visible) 151 if (visible_ == visible)
156 return; 152 return;
157 153
158 bool was_drawn = IsDrawn(); 154 bool was_drawn = IsDrawn();
159 visible_ = visible; 155 visible_ = visible;
160 bool is_drawn = IsDrawn(); 156 bool is_drawn = IsDrawn();
161 if (was_drawn == is_drawn) 157 if (was_drawn == is_drawn)
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 const Layer* p = this; 427 const Layer* p = this;
432 for (; p && p != ancestor; p = p->parent()) { 428 for (; p && p != ancestor; p = p->parent()) {
433 if (p->transform().HasChange()) 429 if (p->transform().HasChange())
434 transform->ConcatTransform(p->transform()); 430 transform->ConcatTransform(p->transform());
435 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), 431 transform->ConcatTranslate(static_cast<float>(p->bounds().x()),
436 static_cast<float>(p->bounds().y())); 432 static_cast<float>(p->bounds().y()));
437 } 433 }
438 return p == ancestor; 434 return p == ancestor;
439 } 435 }
440 436
441 void Layer::StopAnimatingIfNecessary(
442 LayerAnimationManager::AnimationProperty property) {
443 if (!animator_.get() || !animator_->IsRunning() ||
444 !animator_->got_initial_tick()) {
445 return;
446 }
447
448 if (property != LayerAnimationManager::LOCATION &&
449 animator_->IsAnimating(LayerAnimationManager::LOCATION)) {
450 SetBoundsImmediately(
451 gfx::Rect(animator_->GetTargetPoint(), bounds_.size()));
452 }
453 if (property != LayerAnimationManager::OPACITY &&
454 animator_->IsAnimating(LayerAnimationManager::OPACITY)) {
455 SetOpacityImmediately(animator_->GetTargetOpacity());
456 }
457 if (property != LayerAnimationManager::TRANSFORM &&
458 animator_->IsAnimating(LayerAnimationManager::TRANSFORM)) {
459 SetTransformImmediately(animator_->GetTargetTransform());
460 }
461 animator_.reset();
462 }
463
464 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) { 437 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) {
465 bounds_ = bounds; 438 bounds_ = bounds;
466 439
467 if (parent()) 440 if (parent())
468 parent()->RecomputeHole(); 441 parent()->RecomputeHole();
469 } 442 }
470 443
471 void Layer::SetTransformImmediately(const ui::Transform& transform) { 444 void Layer::SetTransformImmediately(const ui::Transform& transform) {
472 transform_ = transform; 445 transform_ = transform;
473 446
(...skipping 16 matching lines...) Expand all
490 while (!to_process.empty()) { 463 while (!to_process.empty()) {
491 Layer* current = to_process.front(); 464 Layer* current = to_process.front();
492 to_process.pop(); 465 to_process.pop();
493 current->RecomputeHole(); 466 current->RecomputeHole();
494 for (size_t i = 0; i < current->children_.size(); ++i) 467 for (size_t i = 0; i < current->children_.size(); ++i)
495 to_process.push(current->children_.at(i)); 468 to_process.push(current->children_.at(i));
496 } 469 }
497 } 470 }
498 } 471 }
499 472
500 void Layer::SetBoundsFromAnimator(const gfx::Rect& bounds) { 473 void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) {
501 SetBoundsImmediately(bounds); 474 SetBoundsImmediately(bounds);
502 } 475 }
503 476
504 void Layer::SetTransformFromAnimator(const Transform& transform) { 477 void Layer::SetTransformFromAnimation(const Transform& transform) {
505 SetTransformImmediately(transform); 478 SetTransformImmediately(transform);
506 } 479 }
507 480
508 void Layer::SetOpacityFromAnimator(float opacity) { 481 void Layer::SetOpacityFromAnimation(float opacity) {
509 SetOpacityImmediately(opacity); 482 SetOpacityImmediately(opacity);
510 } 483 }
511 484
485 void Layer::ScheduleDrawForAnimation() {
486 ScheduleDraw();
487 }
488
489 const gfx::Rect& Layer::GetBoundsForAnimation() const {
490 return bounds();
491 }
492
493 const Transform& Layer::GetTransformForAnimation() const {
494 return transform();
495 }
496
497 float Layer::GetOpacityForAnimation() const {
498 return opacity();
499 }
500
512 } // namespace ui 501 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698