OLD | NEW |
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/layer.h" | 5 #include "ui/compositor/layer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 animator->SetDelegate(this); | 179 animator->SetDelegate(this); |
180 animator_ = animator; | 180 animator_ = animator; |
181 } | 181 } |
182 | 182 |
183 LayerAnimator* Layer::GetAnimator() { | 183 LayerAnimator* Layer::GetAnimator() { |
184 if (!animator_.get()) | 184 if (!animator_.get()) |
185 SetAnimator(LayerAnimator::CreateDefaultAnimator()); | 185 SetAnimator(LayerAnimator::CreateDefaultAnimator()); |
186 return animator_.get(); | 186 return animator_.get(); |
187 } | 187 } |
188 | 188 |
189 void Layer::SetTransform(const ui::Transform& transform) { | 189 void Layer::SetTransform(const gfx::Transform& transform) { |
190 GetAnimator()->SetTransform(transform); | 190 GetAnimator()->SetTransform(transform); |
191 } | 191 } |
192 | 192 |
193 Transform Layer::GetTargetTransform() const { | 193 gfx::Transform Layer::GetTargetTransform() const { |
194 if (animator_.get() && animator_->IsAnimatingProperty( | 194 if (animator_.get() && animator_->IsAnimatingProperty( |
195 LayerAnimationElement::TRANSFORM)) { | 195 LayerAnimationElement::TRANSFORM)) { |
196 return animator_->GetTargetTransform(); | 196 return animator_->GetTargetTransform(); |
197 } | 197 } |
198 return transform_; | 198 return transform_; |
199 } | 199 } |
200 | 200 |
201 void Layer::SetBounds(const gfx::Rect& bounds) { | 201 void Layer::SetBounds(const gfx::Rect& bounds) { |
202 GetAnimator()->SetBounds(bounds); | 202 GetAnimator()->SetBounds(bounds); |
203 } | 203 } |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 (child_i < other_i ? other_i - 1 : other_i); | 553 (child_i < other_i ? other_i - 1 : other_i); |
554 children_.erase(children_.begin() + child_i); | 554 children_.erase(children_.begin() + child_i); |
555 children_.insert(children_.begin() + dest_i, child); | 555 children_.insert(children_.begin() + dest_i, child); |
556 | 556 |
557 child->web_layer_->removeFromParent(); | 557 child->web_layer_->removeFromParent(); |
558 web_layer_->insertChild(child->web_layer_, dest_i); | 558 web_layer_->insertChild(child->web_layer_, dest_i); |
559 } | 559 } |
560 | 560 |
561 bool Layer::ConvertPointForAncestor(const Layer* ancestor, | 561 bool Layer::ConvertPointForAncestor(const Layer* ancestor, |
562 gfx::Point* point) const { | 562 gfx::Point* point) const { |
563 ui::Transform transform; | 563 gfx::Transform transform; |
564 bool result = GetTransformRelativeTo(ancestor, &transform); | 564 bool result = GetTransformRelativeTo(ancestor, &transform); |
565 gfx::Point3f p(*point); | 565 gfx::Point3f p(*point); |
566 transform.TransformPoint(p); | 566 transform.TransformPoint(p); |
567 *point = p.AsPoint(); | 567 *point = p.AsPoint(); |
568 return result; | 568 return result; |
569 } | 569 } |
570 | 570 |
571 bool Layer::ConvertPointFromAncestor(const Layer* ancestor, | 571 bool Layer::ConvertPointFromAncestor(const Layer* ancestor, |
572 gfx::Point* point) const { | 572 gfx::Point* point) const { |
573 ui::Transform transform; | 573 gfx::Transform transform; |
574 bool result = GetTransformRelativeTo(ancestor, &transform); | 574 bool result = GetTransformRelativeTo(ancestor, &transform); |
575 gfx::Point3f p(*point); | 575 gfx::Point3f p(*point); |
576 transform.TransformPointReverse(p); | 576 transform.TransformPointReverse(p); |
577 *point = p.AsPoint(); | 577 *point = p.AsPoint(); |
578 return result; | 578 return result; |
579 } | 579 } |
580 | 580 |
581 bool Layer::GetTransformRelativeTo(const Layer* ancestor, | 581 bool Layer::GetTransformRelativeTo(const Layer* ancestor, |
582 ui::Transform* transform) const { | 582 gfx::Transform* transform) const { |
583 const Layer* p = this; | 583 const Layer* p = this; |
584 for (; p && p != ancestor; p = p->parent()) { | 584 for (; p && p != ancestor; p = p->parent()) { |
585 if (p->transform().HasChange()) | 585 if (p->transform().HasChange()) |
586 transform->ConcatTransform(p->transform()); | 586 transform->ConcatTransform(p->transform()); |
587 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), | 587 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), |
588 static_cast<float>(p->bounds().y())); | 588 static_cast<float>(p->bounds().y())); |
589 } | 589 } |
590 return p == ancestor; | 590 return p == ancestor; |
591 } | 591 } |
592 | 592 |
(...skipping 16 matching lines...) Expand all Loading... |
609 // Don't schedule a draw if we're invisible. We'll schedule one | 609 // Don't schedule a draw if we're invisible. We'll schedule one |
610 // automatically when we get visible. | 610 // automatically when we get visible. |
611 if (IsDrawn()) | 611 if (IsDrawn()) |
612 ScheduleDraw(); | 612 ScheduleDraw(); |
613 } else { | 613 } else { |
614 // Always schedule a paint, even if we're invisible. | 614 // Always schedule a paint, even if we're invisible. |
615 SchedulePaint(gfx::Rect(bounds.size())); | 615 SchedulePaint(gfx::Rect(bounds.size())); |
616 } | 616 } |
617 } | 617 } |
618 | 618 |
619 void Layer::SetTransformImmediately(const ui::Transform& transform) { | 619 void Layer::SetTransformImmediately(const gfx::Transform& transform) { |
620 transform_ = transform; | 620 transform_ = transform; |
621 | 621 |
622 RecomputeTransform(); | 622 RecomputeTransform(); |
623 } | 623 } |
624 | 624 |
625 void Layer::SetOpacityImmediately(float opacity) { | 625 void Layer::SetOpacityImmediately(float opacity) { |
626 bool schedule_draw = (opacity != opacity_ && IsDrawn()); | 626 bool schedule_draw = (opacity != opacity_ && IsDrawn()); |
627 opacity_ = opacity; | 627 opacity_ = opacity; |
628 | 628 |
629 if (visible_) | 629 if (visible_) |
(...skipping 26 matching lines...) Expand all Loading... |
656 DCHECK_EQ(type_, LAYER_SOLID_COLOR); | 656 DCHECK_EQ(type_, LAYER_SOLID_COLOR); |
657 // WebColor is equivalent to SkColor, per WebColor.h. | 657 // WebColor is equivalent to SkColor, per WebColor.h. |
658 solid_color_layer_->setBackgroundColor(static_cast<WebKit::WebColor>(color)); | 658 solid_color_layer_->setBackgroundColor(static_cast<WebKit::WebColor>(color)); |
659 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); | 659 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); |
660 } | 660 } |
661 | 661 |
662 void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) { | 662 void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) { |
663 SetBoundsImmediately(bounds); | 663 SetBoundsImmediately(bounds); |
664 } | 664 } |
665 | 665 |
666 void Layer::SetTransformFromAnimation(const Transform& transform) { | 666 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { |
667 SetTransformImmediately(transform); | 667 SetTransformImmediately(transform); |
668 } | 668 } |
669 | 669 |
670 void Layer::SetOpacityFromAnimation(float opacity) { | 670 void Layer::SetOpacityFromAnimation(float opacity) { |
671 SetOpacityImmediately(opacity); | 671 SetOpacityImmediately(opacity); |
672 } | 672 } |
673 | 673 |
674 void Layer::SetVisibilityFromAnimation(bool visibility) { | 674 void Layer::SetVisibilityFromAnimation(bool visibility) { |
675 SetVisibilityImmediately(visibility); | 675 SetVisibilityImmediately(visibility); |
676 } | 676 } |
(...skipping 11 matching lines...) Expand all Loading... |
688 } | 688 } |
689 | 689 |
690 void Layer::ScheduleDrawForAnimation() { | 690 void Layer::ScheduleDrawForAnimation() { |
691 ScheduleDraw(); | 691 ScheduleDraw(); |
692 } | 692 } |
693 | 693 |
694 const gfx::Rect& Layer::GetBoundsForAnimation() const { | 694 const gfx::Rect& Layer::GetBoundsForAnimation() const { |
695 return bounds(); | 695 return bounds(); |
696 } | 696 } |
697 | 697 |
698 const Transform& Layer::GetTransformForAnimation() const { | 698 const gfx::Transform& Layer::GetTransformForAnimation() const { |
699 return transform(); | 699 return transform(); |
700 } | 700 } |
701 | 701 |
702 float Layer::GetOpacityForAnimation() const { | 702 float Layer::GetOpacityForAnimation() const { |
703 return opacity(); | 703 return opacity(); |
704 } | 704 } |
705 | 705 |
706 bool Layer::GetVisibilityForAnimation() const { | 706 bool Layer::GetVisibilityForAnimation() const { |
707 return visible(); | 707 return visible(); |
708 } | 708 } |
(...skipping 26 matching lines...) Expand all Loading... |
735 } | 735 } |
736 web_layer_is_accelerated_ = false; | 736 web_layer_is_accelerated_ = false; |
737 show_debug_borders_ = CommandLine::ForCurrentProcess()->HasSwitch( | 737 show_debug_borders_ = CommandLine::ForCurrentProcess()->HasSwitch( |
738 switches::kUIShowLayerBorders); | 738 switches::kUIShowLayerBorders); |
739 web_layer_->setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | 739 web_layer_->setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
740 web_layer_->setOpaque(true); | 740 web_layer_->setOpaque(true); |
741 web_layer_->setDebugBorderWidth(show_debug_borders_ ? 2 : 0); | 741 web_layer_->setDebugBorderWidth(show_debug_borders_ ? 2 : 0); |
742 } | 742 } |
743 | 743 |
744 void Layer::RecomputeTransform() { | 744 void Layer::RecomputeTransform() { |
745 ui::Transform scale_translate; | 745 gfx::Transform scale_translate; |
746 scale_translate.matrix().set3x3(device_scale_factor_, 0, 0, | 746 scale_translate.matrix().set3x3(device_scale_factor_, 0, 0, |
747 0, device_scale_factor_, 0, | 747 0, device_scale_factor_, 0, |
748 0, 0, 1); | 748 0, 0, 1); |
749 // Start with the inverse matrix of above. | 749 // Start with the inverse matrix of above. |
750 Transform transform; | 750 gfx::Transform transform; |
751 transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0, | 751 transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0, |
752 0, 1.0f / device_scale_factor_, 0, | 752 0, 1.0f / device_scale_factor_, 0, |
753 0, 0, 1); | 753 0, 0, 1); |
754 transform.ConcatTransform(transform_); | 754 transform.ConcatTransform(transform_); |
755 transform.ConcatTranslate(bounds_.x(), bounds_.y()); | 755 transform.ConcatTranslate(bounds_.x(), bounds_.y()); |
756 transform.ConcatTransform(scale_translate); | 756 transform.ConcatTransform(scale_translate); |
757 web_layer_->setTransform(transform.matrix()); | 757 web_layer_->setTransform(transform.matrix()); |
758 } | 758 } |
759 | 759 |
760 void Layer::RecomputeDrawsContentAndUVRect() { | 760 void Layer::RecomputeDrawsContentAndUVRect() { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 return; | 795 return; |
796 unsigned int color = 0xFF000000; | 796 unsigned int color = 0xFF000000; |
797 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; | 797 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; |
798 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); | 798 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); |
799 if (!opaque) | 799 if (!opaque) |
800 color |= 0xFF; | 800 color |= 0xFF; |
801 web_layer_->setDebugBorderColor(color); | 801 web_layer_->setDebugBorderColor(color); |
802 } | 802 } |
803 | 803 |
804 } // namespace ui | 804 } // namespace ui |
OLD | NEW |