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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 namespace ui { | 44 namespace ui { |
45 | 45 |
46 Layer::Layer() | 46 Layer::Layer() |
47 : type_(LAYER_TEXTURED), | 47 : type_(LAYER_TEXTURED), |
48 compositor_(NULL), | 48 compositor_(NULL), |
49 parent_(NULL), | 49 parent_(NULL), |
50 visible_(true), | 50 visible_(true), |
51 force_render_surface_(false), | 51 force_render_surface_(false), |
52 fills_bounds_opaquely_(true), | 52 fills_bounds_opaquely_(true), |
53 layer_updated_externally_(false), | |
54 background_blur_radius_(0), | 53 background_blur_radius_(0), |
55 layer_saturation_(0.0f), | 54 layer_saturation_(0.0f), |
56 layer_brightness_(0.0f), | 55 layer_brightness_(0.0f), |
57 layer_grayscale_(0.0f), | 56 layer_grayscale_(0.0f), |
58 layer_inverted_(false), | 57 layer_inverted_(false), |
59 layer_mask_(NULL), | 58 layer_mask_(NULL), |
60 layer_mask_back_link_(NULL), | 59 layer_mask_back_link_(NULL), |
61 zoom_(1), | 60 zoom_(1), |
62 zoom_inset_(0), | 61 zoom_inset_(0), |
63 delegate_(NULL), | 62 delegate_(NULL), |
64 cc_layer_(NULL), | 63 cc_layer_(NULL), |
65 scale_content_(true), | 64 scale_content_(true), |
66 device_scale_factor_(1.0f) { | 65 device_scale_factor_(1.0f) { |
67 CreateWebLayer(); | 66 CreateWebLayer(); |
68 } | 67 } |
69 | 68 |
70 Layer::Layer(LayerType type) | 69 Layer::Layer(LayerType type) |
71 : type_(type), | 70 : type_(type), |
72 compositor_(NULL), | 71 compositor_(NULL), |
73 parent_(NULL), | 72 parent_(NULL), |
74 visible_(true), | 73 visible_(true), |
75 force_render_surface_(false), | 74 force_render_surface_(false), |
76 fills_bounds_opaquely_(true), | 75 fills_bounds_opaquely_(true), |
77 layer_updated_externally_(false), | |
78 background_blur_radius_(0), | 76 background_blur_radius_(0), |
79 layer_saturation_(0.0f), | 77 layer_saturation_(0.0f), |
80 layer_brightness_(0.0f), | 78 layer_brightness_(0.0f), |
81 layer_grayscale_(0.0f), | 79 layer_grayscale_(0.0f), |
82 layer_inverted_(false), | 80 layer_inverted_(false), |
83 layer_mask_(NULL), | 81 layer_mask_(NULL), |
84 layer_mask_back_link_(NULL), | 82 layer_mask_back_link_(NULL), |
85 zoom_(1), | 83 zoom_(1), |
86 zoom_inset_(0), | 84 zoom_inset_(0), |
87 delegate_(NULL), | 85 delegate_(NULL), |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 | 475 |
478 void Layer::SetExternalTexture(Texture* texture) { | 476 void Layer::SetExternalTexture(Texture* texture) { |
479 DCHECK(texture); | 477 DCHECK(texture); |
480 | 478 |
481 // Hold a ref to the old |Texture| until we have updated all | 479 // Hold a ref to the old |Texture| until we have updated all |
482 // compositor references to the texture id that it holds. | 480 // compositor references to the texture id that it holds. |
483 scoped_refptr<ui::Texture> old_texture = texture_; | 481 scoped_refptr<ui::Texture> old_texture = texture_; |
484 | 482 |
485 DCHECK_EQ(type_, LAYER_TEXTURED); | 483 DCHECK_EQ(type_, LAYER_TEXTURED); |
486 DCHECK(!solid_color_layer_.get()); | 484 DCHECK(!solid_color_layer_.get()); |
487 layer_updated_externally_ = true; | |
488 texture_ = texture; | 485 texture_ = texture; |
489 if (!texture_layer_.get()) { | 486 if (!texture_layer_.get()) { |
490 scoped_refptr<cc::TextureLayer> new_layer = cc::TextureLayer::Create(this); | 487 scoped_refptr<cc::TextureLayer> new_layer = cc::TextureLayer::Create(this); |
491 new_layer->SetFlipped(texture_->flipped()); | 488 new_layer->SetFlipped(texture_->flipped()); |
492 SwitchToLayer(new_layer); | 489 SwitchToLayer(new_layer); |
493 texture_layer_ = new_layer; | 490 texture_layer_ = new_layer; |
494 } | 491 } |
495 RecomputeDrawsContentAndUVRect(); | 492 RecomputeDrawsContentAndUVRect(); |
496 } | 493 } |
497 | 494 |
498 void Layer::SetTextureMailbox( | 495 void Layer::SetTextureMailbox( |
499 const cc::TextureMailbox& mailbox, | 496 const cc::TextureMailbox& mailbox, |
500 scoped_ptr<cc::SingleReleaseCallback> release_callback, | 497 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
501 float scale_factor) { | 498 float scale_factor) { |
502 DCHECK_EQ(type_, LAYER_TEXTURED); | 499 DCHECK_EQ(type_, LAYER_TEXTURED); |
503 DCHECK(!solid_color_layer_.get()); | 500 DCHECK(!solid_color_layer_.get()); |
504 layer_updated_externally_ = true; | |
505 texture_ = NULL; | 501 texture_ = NULL; |
506 if (!texture_layer_.get() || !texture_layer_->uses_mailbox()) { | 502 if (!texture_layer_.get() || !texture_layer_->uses_mailbox()) { |
507 scoped_refptr<cc::TextureLayer> new_layer = | 503 scoped_refptr<cc::TextureLayer> new_layer = |
508 cc::TextureLayer::CreateForMailbox(this); | 504 cc::TextureLayer::CreateForMailbox(this); |
509 new_layer->SetFlipped(false); | 505 new_layer->SetFlipped(false); |
510 SwitchToLayer(new_layer); | 506 SwitchToLayer(new_layer); |
511 texture_layer_ = new_layer; | 507 texture_layer_ = new_layer; |
512 } | 508 } |
513 texture_layer_->SetTextureMailbox(mailbox, release_callback.Pass()); | 509 texture_layer_->SetTextureMailbox(mailbox, release_callback.Pass()); |
514 mailbox_ = mailbox; | 510 mailbox_ = mailbox; |
515 mailbox_scale_factor_ = scale_factor; | 511 mailbox_scale_factor_ = scale_factor; |
516 RecomputeDrawsContentAndUVRect(); | 512 RecomputeDrawsContentAndUVRect(); |
517 } | 513 } |
518 | 514 |
519 cc::TextureMailbox Layer::GetTextureMailbox(float* scale_factor) { | 515 cc::TextureMailbox Layer::GetTextureMailbox(float* scale_factor) { |
520 if (scale_factor) | 516 if (scale_factor) |
521 *scale_factor = mailbox_scale_factor_; | 517 *scale_factor = mailbox_scale_factor_; |
522 return mailbox_; | 518 return mailbox_; |
523 } | 519 } |
524 | 520 |
525 void Layer::SetShowDelegatedContent(cc::DelegatedFrameProvider* frame_provider, | 521 void Layer::SetShowDelegatedContent(cc::DelegatedFrameProvider* frame_provider, |
526 gfx::Size frame_size_in_dip) { | 522 gfx::Size frame_size_in_dip) { |
527 DCHECK_EQ(type_, LAYER_TEXTURED); | 523 DCHECK_EQ(type_, LAYER_TEXTURED); |
528 | 524 |
529 scoped_refptr<cc::DelegatedRendererLayer> new_layer = | 525 scoped_refptr<cc::DelegatedRendererLayer> new_layer = |
530 cc::DelegatedRendererLayer::Create(frame_provider); | 526 cc::DelegatedRendererLayer::Create(frame_provider); |
531 SwitchToLayer(new_layer); | 527 SwitchToLayer(new_layer); |
532 delegated_renderer_layer_ = new_layer; | 528 delegated_renderer_layer_ = new_layer; |
533 layer_updated_externally_ = true; | |
534 | 529 |
535 delegated_frame_size_in_dip_ = frame_size_in_dip; | 530 delegated_frame_size_in_dip_ = frame_size_in_dip; |
536 RecomputeDrawsContentAndUVRect(); | 531 RecomputeDrawsContentAndUVRect(); |
537 } | 532 } |
538 | 533 |
539 void Layer::SetShowPaintedContent() { | 534 void Layer::SetShowPaintedContent() { |
540 if (content_layer_.get()) | 535 if (content_layer_.get()) |
541 return; | 536 return; |
542 | 537 |
543 scoped_refptr<cc::ContentLayer> new_layer = cc::ContentLayer::Create(this); | 538 scoped_refptr<cc::ContentLayer> new_layer = cc::ContentLayer::Create(this); |
544 SwitchToLayer(new_layer); | 539 SwitchToLayer(new_layer); |
545 content_layer_ = new_layer; | 540 content_layer_ = new_layer; |
546 | 541 |
547 layer_updated_externally_ = false; | |
548 mailbox_ = cc::TextureMailbox(); | 542 mailbox_ = cc::TextureMailbox(); |
549 texture_ = NULL; | 543 texture_ = NULL; |
550 | 544 |
551 RecomputeDrawsContentAndUVRect(); | 545 RecomputeDrawsContentAndUVRect(); |
552 } | 546 } |
553 | 547 |
554 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } | 548 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } |
555 | 549 |
556 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { | 550 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { |
557 if (type_ == LAYER_SOLID_COLOR || (!delegate_ && !texture_.get())) | 551 if (type_ == LAYER_SOLID_COLOR || (!delegate_ && !texture_.get())) |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 bool Layer::ConvertPointFromAncestor(const Layer* ancestor, | 706 bool Layer::ConvertPointFromAncestor(const Layer* ancestor, |
713 gfx::Point* point) const { | 707 gfx::Point* point) const { |
714 gfx::Transform transform; | 708 gfx::Transform transform; |
715 bool result = GetTargetTransformRelativeTo(ancestor, &transform); | 709 bool result = GetTargetTransformRelativeTo(ancestor, &transform); |
716 gfx::Point3F p(*point); | 710 gfx::Point3F p(*point); |
717 transform.TransformPointReverse(&p); | 711 transform.TransformPointReverse(&p); |
718 *point = gfx::ToFlooredPoint(p.AsPointF()); | 712 *point = gfx::ToFlooredPoint(p.AsPointF()); |
719 return result; | 713 return result; |
720 } | 714 } |
721 | 715 |
722 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) { | 716 void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) { |
723 if (bounds == bounds_) | 717 if (bounds == bounds_) |
724 return; | 718 return; |
725 | 719 |
726 base::Closure closure; | 720 base::Closure closure; |
727 if (delegate_) | 721 if (delegate_) |
728 closure = delegate_->PrepareForLayerBoundsChange(); | 722 closure = delegate_->PrepareForLayerBoundsChange(); |
729 bool was_move = bounds_.size() == bounds.size(); | 723 bool was_move = bounds_.size() == bounds.size(); |
730 bounds_ = bounds; | 724 bounds_ = bounds; |
731 | 725 |
732 RecomputeDrawsContentAndUVRect(); | 726 RecomputeDrawsContentAndUVRect(); |
733 RecomputePosition(); | 727 RecomputePosition(); |
734 | 728 |
735 if (!closure.is_null()) | 729 if (!closure.is_null()) |
736 closure.Run(); | 730 closure.Run(); |
737 | 731 |
738 if (was_move) { | 732 if (was_move) { |
739 // Don't schedule a draw if we're invisible. We'll schedule one | 733 // Don't schedule a draw if we're invisible. We'll schedule one |
740 // automatically when we get visible. | 734 // automatically when we get visible. |
741 if (IsDrawn()) | 735 if (IsDrawn()) |
742 ScheduleDraw(); | 736 ScheduleDraw(); |
743 } else { | 737 } else { |
744 // Always schedule a paint, even if we're invisible. | 738 // Always schedule a paint, even if we're invisible. |
745 SchedulePaint(gfx::Rect(bounds.size())); | 739 SchedulePaint(gfx::Rect(bounds.size())); |
746 } | 740 } |
747 } | 741 } |
748 | 742 |
749 void Layer::SetTransformImmediately(const gfx::Transform& transform) { | 743 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { |
750 RecomputeCCTransformFromTransform(transform); | 744 RecomputeCCTransformFromTransform(transform); |
751 } | 745 } |
752 | 746 |
753 void Layer::SetOpacityImmediately(float opacity) { | 747 void Layer::SetOpacityFromAnimation(float opacity) { |
754 cc_layer_->SetOpacity(opacity); | 748 cc_layer_->SetOpacity(opacity); |
755 ScheduleDraw(); | 749 ScheduleDraw(); |
756 } | 750 } |
757 | 751 |
758 void Layer::SetVisibilityImmediately(bool visible) { | 752 void Layer::SetVisibilityFromAnimation(bool visible) { |
759 if (visible_ == visible) | 753 if (visible_ == visible) |
760 return; | 754 return; |
761 | 755 |
762 visible_ = visible; | 756 visible_ = visible; |
763 cc_layer_->SetHideLayerAndSubtree(!visible_); | 757 cc_layer_->SetHideLayerAndSubtree(!visible_); |
764 } | 758 } |
765 | 759 |
766 void Layer::SetBrightnessImmediately(float brightness) { | 760 void Layer::SetBrightnessFromAnimation(float brightness) { |
767 layer_brightness_ = brightness; | 761 layer_brightness_ = brightness; |
768 SetLayerFilters(); | 762 SetLayerFilters(); |
769 } | 763 } |
770 | 764 |
771 void Layer::SetGrayscaleImmediately(float grayscale) { | 765 void Layer::SetGrayscaleFromAnimation(float grayscale) { |
772 layer_grayscale_ = grayscale; | 766 layer_grayscale_ = grayscale; |
773 SetLayerFilters(); | 767 SetLayerFilters(); |
774 } | 768 } |
775 | 769 |
776 void Layer::SetColorImmediately(SkColor color) { | 770 void Layer::SetColorFromAnimation(SkColor color) { |
777 DCHECK_EQ(type_, LAYER_SOLID_COLOR); | 771 DCHECK_EQ(type_, LAYER_SOLID_COLOR); |
778 solid_color_layer_->SetBackgroundColor(color); | 772 solid_color_layer_->SetBackgroundColor(color); |
779 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); | 773 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); |
780 } | 774 } |
781 | 775 |
782 void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) { | |
783 SetBoundsImmediately(bounds); | |
784 } | |
785 | |
786 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { | |
787 SetTransformImmediately(transform); | |
788 } | |
789 | |
790 void Layer::SetOpacityFromAnimation(float opacity) { | |
791 SetOpacityImmediately(opacity); | |
792 } | |
793 | |
794 void Layer::SetVisibilityFromAnimation(bool visibility) { | |
795 SetVisibilityImmediately(visibility); | |
796 } | |
797 | |
798 void Layer::SetBrightnessFromAnimation(float brightness) { | |
799 SetBrightnessImmediately(brightness); | |
800 } | |
801 | |
802 void Layer::SetGrayscaleFromAnimation(float grayscale) { | |
803 SetGrayscaleImmediately(grayscale); | |
804 } | |
805 | |
806 void Layer::SetColorFromAnimation(SkColor color) { | |
807 SetColorImmediately(color); | |
808 } | |
809 | |
810 void Layer::ScheduleDrawForAnimation() { | 776 void Layer::ScheduleDrawForAnimation() { |
811 ScheduleDraw(); | 777 ScheduleDraw(); |
812 } | 778 } |
813 | 779 |
814 const gfx::Rect& Layer::GetBoundsForAnimation() const { | 780 const gfx::Rect& Layer::GetBoundsForAnimation() const { |
815 return bounds(); | 781 return bounds(); |
816 } | 782 } |
817 | 783 |
818 gfx::Transform Layer::GetTransformForAnimation() const { | 784 gfx::Transform Layer::GetTransformForAnimation() const { |
819 return transform(); | 785 return transform(); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 cc_layer_->SetBounds(ConvertSizeToPixel(this, size)); | 927 cc_layer_->SetBounds(ConvertSizeToPixel(this, size)); |
962 } | 928 } |
963 | 929 |
964 void Layer::RecomputePosition() { | 930 void Layer::RecomputePosition() { |
965 cc_layer_->SetPosition(gfx::ScalePoint( | 931 cc_layer_->SetPosition(gfx::ScalePoint( |
966 gfx::PointF(bounds_.x(), bounds_.y()), | 932 gfx::PointF(bounds_.x(), bounds_.y()), |
967 device_scale_factor_)); | 933 device_scale_factor_)); |
968 } | 934 } |
969 | 935 |
970 } // namespace ui | 936 } // namespace ui |
OLD | NEW |