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

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 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
« no previous file with comments | « ui/gfx/compositor/layer.h ('k') | ui/gfx/compositor/layer_animation_delegate.h » ('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) 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/WebContentLayer.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayer.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebExternalTextureLay er.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebExternalTextureLay er.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/canvas_skia.h" 20 #include "ui/gfx/canvas_skia.h"
21 #include "ui/gfx/compositor/layer_animation_manager.h" 21 #include "ui/gfx/compositor/layer_animator.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);
31 return remainder < EPSILON || base - remainder < EPSILON; 31 return remainder < EPSILON || base - remainder < EPSILON;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 128 }
129 129
130 bool Layer::Contains(const Layer* other) const { 130 bool Layer::Contains(const Layer* other) const {
131 for (const Layer* parent = other; parent; parent = parent->parent()) { 131 for (const Layer* parent = other; parent; parent = parent->parent()) {
132 if (parent == this) 132 if (parent == this)
133 return true; 133 return true;
134 } 134 }
135 return false; 135 return false;
136 } 136 }
137 137
138 void Layer::SetAnimation(Animation* animation) { 138 void Layer::SetAnimator(LayerAnimator* animator) {
139 if (animation) { 139 if (animator)
140 if (!animator_.get()) 140 animator->SetDelegate(this);
141 animator_.reset(new LayerAnimationManager(this)); 141 animator_.reset(animator);
142 animation->Start(); 142 }
143 animator_->SetAnimation(animation); 143
144 } else { 144 LayerAnimator* Layer::GetAnimator() {
145 animator_.reset(); 145 if (!animator_.get())
146 } 146 SetAnimator(LayerAnimator::CreateDefaultAnimator());
147 return animator_.get();
147 } 148 }
148 149
149 void Layer::SetTransform(const ui::Transform& transform) { 150 void Layer::SetTransform(const ui::Transform& transform) {
150 StopAnimatingIfNecessary(LayerAnimationManager::TRANSFORM); 151 GetAnimator()->SetTransform(transform);
151 if (animator_.get() && animator_->IsRunning()) { 152 }
152 animator_->AnimateTransform(transform); 153
153 return; 154 Transform Layer::GetTargetTransform() const {
154 } 155 if (animator_.get() && animator_->is_animating())
155 SetTransformImmediately(transform); 156 return animator_->GetTargetTransform();
157 return transform_;
156 } 158 }
157 159
158 void Layer::SetBounds(const gfx::Rect& bounds) { 160 void Layer::SetBounds(const gfx::Rect& bounds) {
159 StopAnimatingIfNecessary(LayerAnimationManager::LOCATION); 161 GetAnimator()->SetBounds(bounds);
160 if (animator_.get() && animator_->IsRunning() &&
161 bounds.size() == bounds_.size()) {
162 animator_->AnimateToPoint(bounds.origin());
163 return;
164 }
165 SetBoundsImmediately(bounds);
166 } 162 }
167 163
168 gfx::Rect Layer::GetTargetBounds() const { 164 gfx::Rect Layer::GetTargetBounds() const {
169 if (animator_.get() && animator_->IsRunning()) 165 if (animator_.get() && animator_->is_animating())
170 return gfx::Rect(animator_->GetTargetPoint(), bounds_.size()); 166 return animator_->GetTargetBounds();
171 return bounds_; 167 return bounds_;
172 } 168 }
173 169
174 void Layer::SetOpacity(float opacity) { 170 void Layer::SetOpacity(float opacity) {
175 StopAnimatingIfNecessary(LayerAnimationManager::OPACITY); 171 GetAnimator()->SetOpacity(opacity);
176 if (animator_.get() && animator_->IsRunning()) { 172 }
177 animator_->AnimateOpacity(opacity); 173
178 return; 174 float Layer::GetTargetOpacity() const {
179 } 175 if (animator_.get() && animator_->is_animating())
180 SetOpacityImmediately(opacity); 176 return animator_->GetTargetOpacity();
177 return opacity_;
181 } 178 }
182 179
183 void Layer::SetVisible(bool visible) { 180 void Layer::SetVisible(bool visible) {
184 if (visible_ == visible) 181 if (visible_ == visible)
185 return; 182 return;
186 183
187 bool was_drawn = IsDrawn(); 184 bool was_drawn = IsDrawn();
188 visible_ = visible; 185 visible_ = visible;
189 #if defined(USE_WEBKIT_COMPOSITOR) 186 #if defined(USE_WEBKIT_COMPOSITOR)
190 // TODO(piman): Expose a visibility flag on WebLayer. 187 // TODO(piman): Expose a visibility flag on WebLayer.
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 const Layer* p = this; 586 const Layer* p = this;
590 for (; p && p != ancestor; p = p->parent()) { 587 for (; p && p != ancestor; p = p->parent()) {
591 if (p->transform().HasChange()) 588 if (p->transform().HasChange())
592 transform->ConcatTransform(p->transform()); 589 transform->ConcatTransform(p->transform());
593 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), 590 transform->ConcatTranslate(static_cast<float>(p->bounds().x()),
594 static_cast<float>(p->bounds().y())); 591 static_cast<float>(p->bounds().y()));
595 } 592 }
596 return p == ancestor; 593 return p == ancestor;
597 } 594 }
598 595
599 void Layer::StopAnimatingIfNecessary(
600 LayerAnimationManager::AnimationProperty property) {
601 if (!animator_.get() || !animator_->IsRunning() ||
602 !animator_->got_initial_tick()) {
603 return;
604 }
605
606 if (property != LayerAnimationManager::LOCATION &&
607 animator_->IsAnimating(LayerAnimationManager::LOCATION)) {
608 SetBoundsImmediately(
609 gfx::Rect(animator_->GetTargetPoint(), bounds_.size()));
610 }
611 if (property != LayerAnimationManager::OPACITY &&
612 animator_->IsAnimating(LayerAnimationManager::OPACITY)) {
613 SetOpacityImmediately(animator_->GetTargetOpacity());
614 }
615 if (property != LayerAnimationManager::TRANSFORM &&
616 animator_->IsAnimating(LayerAnimationManager::TRANSFORM)) {
617 SetTransformImmediately(animator_->GetTargetTransform());
618 }
619 animator_.reset();
620 }
621
622 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) { 596 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) {
623 bounds_ = bounds; 597 bounds_ = bounds;
624 598
625 SetNeedsToRecomputeHole(); 599 SetNeedsToRecomputeHole();
626 #if defined(USE_WEBKIT_COMPOSITOR) 600 #if defined(USE_WEBKIT_COMPOSITOR)
627 web_layer_.setBounds(bounds.size()); 601 web_layer_.setBounds(bounds.size());
628 RecomputeTransform(); 602 RecomputeTransform();
629 RecomputeDrawsContent(); 603 RecomputeDrawsContent();
630 #endif 604 #endif
631 } 605 }
632 606
633 void Layer::SetTransformImmediately(const ui::Transform& transform) { 607 void Layer::SetTransformImmediately(const ui::Transform& transform) {
634 transform_ = transform; 608 transform_ = transform;
635 609
636 SetNeedsToRecomputeHole(); 610 SetNeedsToRecomputeHole();
637 #if defined(USE_WEBKIT_COMPOSITOR) 611 #if defined(USE_WEBKIT_COMPOSITOR)
638 RecomputeTransform(); 612 RecomputeTransform();
639 #endif 613 #endif
640 } 614 }
641 615
642 void Layer::SetOpacityImmediately(float opacity) { 616 void Layer::SetOpacityImmediately(float opacity) {
643 opacity_ = opacity; 617 opacity_ = opacity;
644 SetNeedsToRecomputeHole(); 618 SetNeedsToRecomputeHole();
645 #if defined(USE_WEBKIT_COMPOSITOR) 619 #if defined(USE_WEBKIT_COMPOSITOR)
646 if (visible_) 620 if (visible_)
647 web_layer_.setOpacity(opacity); 621 web_layer_.setOpacity(opacity);
648 #endif 622 #endif
649 } 623 }
650 624
651 void Layer::SetBoundsFromAnimator(const gfx::Rect& bounds) { 625 void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) {
652 SetBoundsImmediately(bounds); 626 SetBoundsImmediately(bounds);
653 } 627 }
654 628
655 void Layer::SetTransformFromAnimator(const Transform& transform) { 629 void Layer::SetTransformFromAnimation(const Transform& transform) {
656 SetTransformImmediately(transform); 630 SetTransformImmediately(transform);
657 } 631 }
658 632
659 void Layer::SetOpacityFromAnimator(float opacity) { 633 void Layer::SetOpacityFromAnimation(float opacity) {
660 SetOpacityImmediately(opacity); 634 SetOpacityImmediately(opacity);
661 } 635 }
662 636
637 void Layer::ScheduleDrawForAnimation() {
638 ScheduleDraw();
639 }
640
641 const gfx::Rect& Layer::GetBoundsForAnimation() const {
642 return bounds();
643 }
644
645 const Transform& Layer::GetTransformForAnimation() const {
646 return transform();
647 }
648
649 float Layer::GetOpacityForAnimation() const {
650 return opacity();
651 }
652
653 void Layer::OnLayerAnimationEnded(LayerAnimationSequence* sequence) {
654 if (delegate_)
655 delegate_->OnLayerAnimationEnded(sequence);
656 }
657
663 #if defined(USE_WEBKIT_COMPOSITOR) 658 #if defined(USE_WEBKIT_COMPOSITOR)
664 void Layer::CreateWebLayer() { 659 void Layer::CreateWebLayer() {
665 web_layer_ = WebKit::WebContentLayer::create(this, this); 660 web_layer_ = WebKit::WebContentLayer::create(this, this);
666 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); 661 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f));
667 web_layer_.setOpaque(true); 662 web_layer_.setOpaque(true);
668 web_layer_is_accelerated_ = false; 663 web_layer_is_accelerated_ = false;
669 RecomputeDrawsContent(); 664 RecomputeDrawsContent();
670 } 665 }
671 666
672 void Layer::RecomputeTransform() { 667 void Layer::RecomputeTransform() {
(...skipping 16 matching lines...) Expand all
689 #else 684 #else
690 unsigned int texture_id = 0; 685 unsigned int texture_id = 0;
691 #endif 686 #endif
692 web_layer_.to<WebKit::WebExternalTextureLayer>().setTextureId( 687 web_layer_.to<WebKit::WebExternalTextureLayer>().setTextureId(
693 should_draw ? texture_id : 0); 688 should_draw ? texture_id : 0);
694 } 689 }
695 } 690 }
696 #endif 691 #endif
697 692
698 } // namespace ui 693 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/layer.h ('k') | ui/gfx/compositor/layer_animation_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698