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/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: Merge with master. Created 9 years, 1 month 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 "third_party/WebKit/Source/WebKit/chromium/public/WebExternalTextureLay er.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebExternalTextureLay er.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayer.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayer.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatPoint.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatPoint.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatRect.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatRect.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
16 #include "ui/base/animation/animation.h" 16 #include "ui/base/animation/animation.h"
17 #if defined(USE_WEBKIT_COMPOSITOR) 17 #if defined(USE_WEBKIT_COMPOSITOR)
18 #include "ui/gfx/compositor/compositor_cc.h" 18 #include "ui/gfx/compositor/compositor_cc.h"
19 #endif 19 #endif
20 #include "ui/gfx/compositor/layer_animation_manager.h" 20 #include "ui/gfx/compositor/layer_animator.h"
21 #include "ui/gfx/canvas_skia.h" 21 #include "ui/gfx/canvas_skia.h"
22 #include "ui/gfx/interpolated_transform.h" 22 #include "ui/gfx/interpolated_transform.h"
23 #include "ui/gfx/point3.h" 23 #include "ui/gfx/point3.h"
24 24
25 namespace { 25 namespace {
26 26
27 const float EPSILON = 1e-3f; 27 const float EPSILON = 1e-3f;
28 28
29 bool IsApproximateMultilpleOf(float value, float base) { 29 bool IsApproximateMultilpleOf(float value, float base) {
30 float remainder = fmod(fabs(value), base); 30 float remainder = fmod(fabs(value), base);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 126 }
127 127
128 bool Layer::Contains(const Layer* other) const { 128 bool Layer::Contains(const Layer* other) const {
129 for (const Layer* parent = other; parent; parent = parent->parent()) { 129 for (const Layer* parent = other; parent; parent = parent->parent()) {
130 if (parent == this) 130 if (parent == this)
131 return true; 131 return true;
132 } 132 }
133 return false; 133 return false;
134 } 134 }
135 135
136 void Layer::SetAnimation(Animation* animation) { 136 void Layer::SetAnimator(LayerAnimator* animator) {
137 if (animation) { 137 if (animator)
138 if (!animator_.get()) 138 animator->SetDelegate(this);
139 animator_.reset(new LayerAnimationManager(this)); 139 animator_.reset(animator);
140 animation->Start(); 140 }
141 animator_->SetAnimation(animation); 141
142 } else { 142 LayerAnimator* Layer::GetAnimator() {
143 animator_.reset(); 143 if (!animator_.get())
144 } 144 SetAnimator(LayerAnimator::CreateDefaultAnimator());
145 return animator_.get();
145 } 146 }
146 147
147 void Layer::SetTransform(const ui::Transform& transform) { 148 void Layer::SetTransform(const ui::Transform& transform) {
148 StopAnimatingIfNecessary(LayerAnimationManager::TRANSFORM); 149 GetAnimator()->SetTransform(transform);
149 if (animator_.get() && animator_->IsRunning()) { 150 }
150 animator_->AnimateTransform(transform); 151
151 return; 152 Transform Layer::GetTargetTransform() const {
152 } 153 if (animator_.get() && animator_->is_animating())
153 SetTransformImmediately(transform); 154 return animator_->GetTargetTransform();
155 return transform_;
154 } 156 }
155 157
156 void Layer::SetBounds(const gfx::Rect& bounds) { 158 void Layer::SetBounds(const gfx::Rect& bounds) {
157 StopAnimatingIfNecessary(LayerAnimationManager::LOCATION); 159 GetAnimator()->SetBounds(bounds);
158 if (animator_.get() && animator_->IsRunning() &&
159 bounds.size() == bounds_.size()) {
160 animator_->AnimateToPoint(bounds.origin());
161 return;
162 }
163 SetBoundsImmediately(bounds);
164 } 160 }
165 161
166 gfx::Rect Layer::GetTargetBounds() const { 162 gfx::Rect Layer::GetTargetBounds() const {
167 if (animator_.get() && animator_->IsRunning()) 163 if (animator_.get() && animator_->is_animating())
168 return gfx::Rect(animator_->GetTargetPoint(), bounds_.size()); 164 return animator_->GetTargetBounds();
169 return bounds_; 165 return bounds_;
170 } 166 }
171 167
172 void Layer::SetOpacity(float opacity) { 168 void Layer::SetOpacity(float opacity) {
173 StopAnimatingIfNecessary(LayerAnimationManager::OPACITY); 169 GetAnimator()->SetOpacity(opacity);
174 if (animator_.get() && animator_->IsRunning()) { 170 }
175 animator_->AnimateOpacity(opacity); 171
176 return; 172 float Layer::GetTargetOpacity() const {
177 } 173 if (animator_.get() && animator_->is_animating())
178 SetOpacityImmediately(opacity); 174 return animator_->GetTargetOpacity();
175 return opacity_;
179 } 176 }
180 177
181 void Layer::SetVisible(bool visible) { 178 void Layer::SetVisible(bool visible) {
182 if (visible_ == visible) 179 if (visible_ == visible)
183 return; 180 return;
184 181
185 bool was_drawn = IsDrawn(); 182 bool was_drawn = IsDrawn();
186 visible_ = visible; 183 visible_ = visible;
187 bool is_drawn = IsDrawn(); 184 bool is_drawn = IsDrawn();
188 if (was_drawn == is_drawn) 185 if (was_drawn == is_drawn)
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 const Layer* p = this; 537 const Layer* p = this;
541 for (; p && p != ancestor; p = p->parent()) { 538 for (; p && p != ancestor; p = p->parent()) {
542 if (p->transform().HasChange()) 539 if (p->transform().HasChange())
543 transform->ConcatTransform(p->transform()); 540 transform->ConcatTransform(p->transform());
544 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), 541 transform->ConcatTranslate(static_cast<float>(p->bounds().x()),
545 static_cast<float>(p->bounds().y())); 542 static_cast<float>(p->bounds().y()));
546 } 543 }
547 return p == ancestor; 544 return p == ancestor;
548 } 545 }
549 546
550 void Layer::StopAnimatingIfNecessary(
551 LayerAnimationManager::AnimationProperty property) {
552 if (!animator_.get() || !animator_->IsRunning() ||
553 !animator_->got_initial_tick()) {
554 return;
555 }
556
557 if (property != LayerAnimationManager::LOCATION &&
558 animator_->IsAnimating(LayerAnimationManager::LOCATION)) {
559 SetBoundsImmediately(
560 gfx::Rect(animator_->GetTargetPoint(), bounds_.size()));
561 }
562 if (property != LayerAnimationManager::OPACITY &&
563 animator_->IsAnimating(LayerAnimationManager::OPACITY)) {
564 SetOpacityImmediately(animator_->GetTargetOpacity());
565 }
566 if (property != LayerAnimationManager::TRANSFORM &&
567 animator_->IsAnimating(LayerAnimationManager::TRANSFORM)) {
568 SetTransformImmediately(animator_->GetTargetTransform());
569 }
570 animator_.reset();
571 }
572
573 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) { 547 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) {
574 bounds_ = bounds; 548 bounds_ = bounds;
575 549
576 if (parent()) 550 if (parent())
577 parent()->RecomputeHole(); 551 parent()->RecomputeHole();
578 #if defined(USE_WEBKIT_COMPOSITOR) 552 #if defined(USE_WEBKIT_COMPOSITOR)
579 web_layer_.setBounds(bounds.size()); 553 web_layer_.setBounds(bounds.size());
580 RecomputeTransform(); 554 RecomputeTransform();
581 RecomputeDrawsContent(); 555 RecomputeDrawsContent();
582 #endif 556 #endif
(...skipping 28 matching lines...) Expand all
611 for (size_t i = 0; i < current->children_.size(); ++i) 585 for (size_t i = 0; i < current->children_.size(); ++i)
612 to_process.push(current->children_.at(i)); 586 to_process.push(current->children_.at(i));
613 } 587 }
614 } 588 }
615 #if defined(USE_WEBKIT_COMPOSITOR) 589 #if defined(USE_WEBKIT_COMPOSITOR)
616 if (visible_) 590 if (visible_)
617 web_layer_.setOpacity(opacity); 591 web_layer_.setOpacity(opacity);
618 #endif 592 #endif
619 } 593 }
620 594
621 void Layer::SetBoundsFromAnimator(const gfx::Rect& bounds) { 595 void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) {
622 SetBoundsImmediately(bounds); 596 SetBoundsImmediately(bounds);
623 } 597 }
624 598
625 void Layer::SetTransformFromAnimator(const Transform& transform) { 599 void Layer::SetTransformFromAnimation(const Transform& transform) {
626 SetTransformImmediately(transform); 600 SetTransformImmediately(transform);
627 } 601 }
628 602
629 void Layer::SetOpacityFromAnimator(float opacity) { 603 void Layer::SetOpacityFromAnimation(float opacity) {
630 SetOpacityImmediately(opacity); 604 SetOpacityImmediately(opacity);
631 } 605 }
632 606
607 void Layer::ScheduleDrawForAnimation() {
608 ScheduleDraw();
609 }
610
611 const gfx::Rect& Layer::GetBoundsForAnimation() const {
612 return bounds();
613 }
614
615 const Transform& Layer::GetTransformForAnimation() const {
616 return transform();
617 }
618
619 float Layer::GetOpacityForAnimation() const {
620 return opacity();
621 }
622
623 void Layer::OnLayerAnimationEnded(LayerAnimationSequence* sequence) {
624 if (delegate_)
625 delegate_->OnLayerAnimationEnded(sequence);
626 }
627
633 #if defined(USE_WEBKIT_COMPOSITOR) 628 #if defined(USE_WEBKIT_COMPOSITOR)
634 void Layer::CreateWebLayer() { 629 void Layer::CreateWebLayer() {
635 web_layer_ = WebKit::WebContentLayer::create(this, this); 630 web_layer_ = WebKit::WebContentLayer::create(this, this);
636 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); 631 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f));
637 web_layer_.setOpaque(true); 632 web_layer_.setOpaque(true);
638 web_layer_is_accelerated_ = false; 633 web_layer_is_accelerated_ = false;
639 RecomputeDrawsContent(); 634 RecomputeDrawsContent();
640 } 635 }
641 636
642 void Layer::RecomputeTransform() { 637 void Layer::RecomputeTransform() {
(...skipping 16 matching lines...) Expand all
659 #else 654 #else
660 unsigned int texture_id = 0; 655 unsigned int texture_id = 0;
661 #endif 656 #endif
662 web_layer_.to<WebKit::WebExternalTextureLayer>().setTextureId( 657 web_layer_.to<WebKit::WebExternalTextureLayer>().setTextureId(
663 should_draw ? texture_id : 0); 658 should_draw ? texture_id : 0);
664 } 659 }
665 } 660 }
666 #endif 661 #endif
667 662
668 } // namespace ui 663 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698