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