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

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: Enable framework for aura 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 "ui/gfx/compositor/layer_animator.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatPoint.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatPoint.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatRect.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatRect.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
14 #include "ui/base/animation/animation.h"
15 #include "ui/gfx/compositor/layer_animation_manager.h"
16 #include "ui/gfx/canvas_skia.h" 15 #include "ui/gfx/canvas_skia.h"
17 #include "ui/gfx/interpolated_transform.h" 16 #include "ui/gfx/interpolated_transform.h"
18 #include "ui/gfx/point3.h" 17 #include "ui/gfx/point3.h"
19 18
20 namespace { 19 namespace {
21 20
22 const float EPSILON = 1e-3f; 21 const float EPSILON = 1e-3f;
23 22
24 bool IsApproximateMultilpleOf(float value, float base) { 23 bool IsApproximateMultilpleOf(float value, float base) {
25 float remainder = fmod(fabs(value), base); 24 float remainder = fmod(fabs(value), base);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 120 }
122 121
123 bool Layer::Contains(const Layer* other) const { 122 bool Layer::Contains(const Layer* other) const {
124 for (const Layer* parent = other; parent; parent = parent->parent()) { 123 for (const Layer* parent = other; parent; parent = parent->parent()) {
125 if (parent == this) 124 if (parent == this)
126 return true; 125 return true;
127 } 126 }
128 return false; 127 return false;
129 } 128 }
130 129
131 void Layer::SetAnimation(Animation* animation) { 130 void Layer::SetAnimator(LayerAnimator* animator) {
132 if (animation) { 131 if (animator)
133 if (!animator_.get()) 132 animator->SetDelegate(this);
134 animator_.reset(new LayerAnimationManager(this)); 133 animator_.reset(animator);
135 animation->Start(); 134 }
136 animator_->SetAnimation(animation); 135
137 } else { 136 LayerAnimator* Layer::GetAnimator() {
138 animator_.reset(); 137 if (!animator_.get())
139 } 138 SetAnimator(LayerAnimator::CreateDefaultAnimator());
139 return animator_.get();
140 } 140 }
141 141
142 void Layer::SetTransform(const ui::Transform& transform) { 142 void Layer::SetTransform(const ui::Transform& transform) {
143 StopAnimatingIfNecessary(LayerAnimationManager::TRANSFORM); 143 GetAnimator()->SetTransform(transform);
144 if (animator_.get() && animator_->IsRunning()) { 144 }
145 animator_->AnimateTransform(transform); 145
146 return; 146 Transform Layer::GetTargetTransform() const {
147 } 147 if (animator_.get() && animator_->is_animating())
148 SetTransformImmediately(transform); 148 return animator_->GetTargetTransform();
149 return transform_;
149 } 150 }
150 151
151 void Layer::SetBounds(const gfx::Rect& bounds) { 152 void Layer::SetBounds(const gfx::Rect& bounds) {
152 StopAnimatingIfNecessary(LayerAnimationManager::LOCATION); 153 GetAnimator()->SetBounds(bounds);
153 if (animator_.get() && animator_->IsRunning() &&
154 bounds.size() == bounds_.size()) {
155 animator_->AnimateToPoint(bounds.origin());
156 return;
157 }
158 SetBoundsImmediately(bounds);
159 } 154 }
160 155
161 gfx::Rect Layer::GetTargetBounds() const { 156 gfx::Rect Layer::GetTargetBounds() const {
162 if (animator_.get() && animator_->IsRunning()) 157 if (animator_.get() && animator_->is_animating())
163 return gfx::Rect(animator_->GetTargetPoint(), bounds_.size()); 158 return animator_->GetTargetBounds();
164 return bounds_; 159 return bounds_;
165 } 160 }
166 161
167 void Layer::SetOpacity(float opacity) { 162 void Layer::SetOpacity(float opacity) {
168 StopAnimatingIfNecessary(LayerAnimationManager::OPACITY); 163 GetAnimator()->SetOpacity(opacity);
169 if (animator_.get() && animator_->IsRunning()) { 164 }
170 animator_->AnimateOpacity(opacity); 165
171 return; 166 float Layer::GetTargetOpacity() const {
172 } 167 if (animator_.get() && animator_->is_animating())
173 SetOpacityImmediately(opacity); 168 return animator_->GetTargetOpacity();
169 return opacity_;
174 } 170 }
175 171
176 void Layer::SetVisible(bool visible) { 172 void Layer::SetVisible(bool visible) {
177 if (visible_ == visible) 173 if (visible_ == visible)
178 return; 174 return;
179 175
180 bool was_drawn = IsDrawn(); 176 bool was_drawn = IsDrawn();
181 visible_ = visible; 177 visible_ = visible;
182 bool is_drawn = IsDrawn(); 178 bool is_drawn = IsDrawn();
183 if (was_drawn == is_drawn) 179 if (was_drawn == is_drawn)
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 const Layer* p = this; 503 const Layer* p = this;
508 for (; p && p != ancestor; p = p->parent()) { 504 for (; p && p != ancestor; p = p->parent()) {
509 if (p->transform().HasChange()) 505 if (p->transform().HasChange())
510 transform->ConcatTransform(p->transform()); 506 transform->ConcatTransform(p->transform());
511 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), 507 transform->ConcatTranslate(static_cast<float>(p->bounds().x()),
512 static_cast<float>(p->bounds().y())); 508 static_cast<float>(p->bounds().y()));
513 } 509 }
514 return p == ancestor; 510 return p == ancestor;
515 } 511 }
516 512
517 void Layer::StopAnimatingIfNecessary(
518 LayerAnimationManager::AnimationProperty property) {
519 if (!animator_.get() || !animator_->IsRunning() ||
520 !animator_->got_initial_tick()) {
521 return;
522 }
523
524 if (property != LayerAnimationManager::LOCATION &&
525 animator_->IsAnimating(LayerAnimationManager::LOCATION)) {
526 SetBoundsImmediately(
527 gfx::Rect(animator_->GetTargetPoint(), bounds_.size()));
528 }
529 if (property != LayerAnimationManager::OPACITY &&
530 animator_->IsAnimating(LayerAnimationManager::OPACITY)) {
531 SetOpacityImmediately(animator_->GetTargetOpacity());
532 }
533 if (property != LayerAnimationManager::TRANSFORM &&
534 animator_->IsAnimating(LayerAnimationManager::TRANSFORM)) {
535 SetTransformImmediately(animator_->GetTargetTransform());
536 }
537 animator_.reset();
538 }
539
540 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) { 513 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) {
541 bounds_ = bounds; 514 bounds_ = bounds;
542 515
543 if (parent()) 516 if (parent())
544 parent()->RecomputeHole(); 517 parent()->RecomputeHole();
545 #if defined(USE_WEBKIT_COMPOSITOR) 518 #if defined(USE_WEBKIT_COMPOSITOR)
546 web_layer_.setBounds(bounds.size()); 519 web_layer_.setBounds(bounds.size());
547 RecomputeTransform(); 520 RecomputeTransform();
548 RecomputeDrawsContent(); 521 RecomputeDrawsContent();
549 #endif 522 #endif
(...skipping 29 matching lines...) Expand all
579 to_process.push(current->children_.at(i)); 552 to_process.push(current->children_.at(i));
580 } 553 }
581 } 554 }
582 #if defined(USE_WEBKIT_COMPOSITOR) 555 #if defined(USE_WEBKIT_COMPOSITOR)
583 if (visible_) 556 if (visible_)
584 web_layer_.setOpacity(opacity); 557 web_layer_.setOpacity(opacity);
585 RecomputeDrawsContent(); 558 RecomputeDrawsContent();
586 #endif 559 #endif
587 } 560 }
588 561
589 void Layer::SetBoundsFromAnimator(const gfx::Rect& bounds) { 562 void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) {
590 SetBoundsImmediately(bounds); 563 SetBoundsImmediately(bounds);
591 } 564 }
592 565
593 void Layer::SetTransformFromAnimator(const Transform& transform) { 566 void Layer::SetTransformFromAnimation(const Transform& transform) {
594 SetTransformImmediately(transform); 567 SetTransformImmediately(transform);
595 } 568 }
596 569
597 void Layer::SetOpacityFromAnimator(float opacity) { 570 void Layer::SetOpacityFromAnimation(float opacity) {
598 SetOpacityImmediately(opacity); 571 SetOpacityImmediately(opacity);
599 } 572 }
600 573
574 void Layer::ScheduleDrawForAnimation() {
575 ScheduleDraw();
576 }
577
578 const gfx::Rect& Layer::GetBoundsForAnimation() const {
579 return bounds();
580 }
581
582 const Transform& Layer::GetTransformForAnimation() const {
583 return transform();
584 }
585
586 float Layer::GetOpacityForAnimation() const {
587 return opacity();
588 }
589
590 void Layer::OnLayerAnimationEnded(LayerAnimationSequence* sequence) {
591 if (delegate_)
592 delegate_->OnLayerAnimationEnded(sequence);
593 }
594
601 #if defined(USE_WEBKIT_COMPOSITOR) 595 #if defined(USE_WEBKIT_COMPOSITOR)
602 void Layer::CreateWebLayer() { 596 void Layer::CreateWebLayer() {
603 web_layer_ = WebKit::WebContentLayer::create(this, this); 597 web_layer_ = WebKit::WebContentLayer::create(this, this);
604 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); 598 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f));
605 web_layer_.setOpaque(true); 599 web_layer_.setOpaque(true);
606 RecomputeDrawsContent(); 600 RecomputeDrawsContent();
607 } 601 }
608 602
609 void Layer::RecomputeTransform() { 603 void Layer::RecomputeTransform() {
610 ui::Transform transform = transform_; 604 ui::Transform transform = transform_;
611 transform.ConcatTranslate(bounds_.x(), bounds_.y()); 605 transform.ConcatTranslate(bounds_.x(), bounds_.y());
612 web_layer_.setTransform(transform.matrix()); 606 web_layer_.setTransform(transform.matrix());
613 } 607 }
614 608
615 void Layer::RecomputeDrawsContent() { 609 void Layer::RecomputeDrawsContent() {
616 web_layer_.setDrawsContent(ShouldDraw()); 610 web_layer_.setDrawsContent(ShouldDraw());
617 } 611 }
618 #endif 612 #endif
619 613
620 } // namespace ui 614 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698