| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 bool Layer::ConvertPointFromAncestor(const Layer* ancestor, | 713 bool Layer::ConvertPointFromAncestor(const Layer* ancestor, |
| 720 gfx::Point* point) const { | 714 gfx::Point* point) const { |
| 721 gfx::Transform transform; | 715 gfx::Transform transform; |
| 722 bool result = GetTargetTransformRelativeTo(ancestor, &transform); | 716 bool result = GetTargetTransformRelativeTo(ancestor, &transform); |
| 723 gfx::Point3F p(*point); | 717 gfx::Point3F p(*point); |
| 724 transform.TransformPointReverse(&p); | 718 transform.TransformPointReverse(&p); |
| 725 *point = gfx::ToFlooredPoint(p.AsPointF()); | 719 *point = gfx::ToFlooredPoint(p.AsPointF()); |
| 726 return result; | 720 return result; |
| 727 } | 721 } |
| 728 | 722 |
| 729 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) { | 723 void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) { |
| 730 if (bounds == bounds_) | 724 if (bounds == bounds_) |
| 731 return; | 725 return; |
| 732 | 726 |
| 733 base::Closure closure; | 727 base::Closure closure; |
| 734 if (delegate_) | 728 if (delegate_) |
| 735 closure = delegate_->PrepareForLayerBoundsChange(); | 729 closure = delegate_->PrepareForLayerBoundsChange(); |
| 736 bool was_move = bounds_.size() == bounds.size(); | 730 bool was_move = bounds_.size() == bounds.size(); |
| 737 bounds_ = bounds; | 731 bounds_ = bounds; |
| 738 | 732 |
| 739 RecomputeDrawsContentAndUVRect(); | 733 RecomputeDrawsContentAndUVRect(); |
| 740 RecomputePosition(); | 734 RecomputePosition(); |
| 741 | 735 |
| 742 if (!closure.is_null()) | 736 if (!closure.is_null()) |
| 743 closure.Run(); | 737 closure.Run(); |
| 744 | 738 |
| 745 if (was_move) { | 739 if (was_move) { |
| 746 // Don't schedule a draw if we're invisible. We'll schedule one | 740 // Don't schedule a draw if we're invisible. We'll schedule one |
| 747 // automatically when we get visible. | 741 // automatically when we get visible. |
| 748 if (IsDrawn()) | 742 if (IsDrawn()) |
| 749 ScheduleDraw(); | 743 ScheduleDraw(); |
| 750 } else { | 744 } else { |
| 751 // Always schedule a paint, even if we're invisible. | 745 // Always schedule a paint, even if we're invisible. |
| 752 SchedulePaint(gfx::Rect(bounds.size())); | 746 SchedulePaint(gfx::Rect(bounds.size())); |
| 753 } | 747 } |
| 754 } | 748 } |
| 755 | 749 |
| 756 void Layer::SetTransformImmediately(const gfx::Transform& transform) { | 750 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { |
| 757 RecomputeCCTransformFromTransform(transform); | 751 RecomputeCCTransformFromTransform(transform); |
| 758 } | 752 } |
| 759 | 753 |
| 760 void Layer::SetOpacityImmediately(float opacity) { | 754 void Layer::SetOpacityFromAnimation(float opacity) { |
| 761 cc_layer_->SetOpacity(opacity); | 755 cc_layer_->SetOpacity(opacity); |
| 762 ScheduleDraw(); | 756 ScheduleDraw(); |
| 763 } | 757 } |
| 764 | 758 |
| 765 void Layer::SetVisibilityImmediately(bool visible) { | 759 void Layer::SetVisibilityFromAnimation(bool visible) { |
| 766 if (visible_ == visible) | 760 if (visible_ == visible) |
| 767 return; | 761 return; |
| 768 | 762 |
| 769 visible_ = visible; | 763 visible_ = visible; |
| 770 cc_layer_->SetHideLayerAndSubtree(!visible_); | 764 cc_layer_->SetHideLayerAndSubtree(!visible_); |
| 771 } | 765 } |
| 772 | 766 |
| 773 void Layer::SetBrightnessImmediately(float brightness) { | 767 void Layer::SetBrightnessFromAnimation(float brightness) { |
| 774 layer_brightness_ = brightness; | 768 layer_brightness_ = brightness; |
| 775 SetLayerFilters(); | 769 SetLayerFilters(); |
| 776 } | 770 } |
| 777 | 771 |
| 778 void Layer::SetGrayscaleImmediately(float grayscale) { | 772 void Layer::SetGrayscaleFromAnimation(float grayscale) { |
| 779 layer_grayscale_ = grayscale; | 773 layer_grayscale_ = grayscale; |
| 780 SetLayerFilters(); | 774 SetLayerFilters(); |
| 781 } | 775 } |
| 782 | 776 |
| 783 void Layer::SetColorImmediately(SkColor color) { | 777 void Layer::SetColorFromAnimation(SkColor color) { |
| 784 DCHECK_EQ(type_, LAYER_SOLID_COLOR); | 778 DCHECK_EQ(type_, LAYER_SOLID_COLOR); |
| 785 solid_color_layer_->SetBackgroundColor(color); | 779 solid_color_layer_->SetBackgroundColor(color); |
| 786 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); | 780 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); |
| 787 } | 781 } |
| 788 | 782 |
| 789 void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) { | |
| 790 SetBoundsImmediately(bounds); | |
| 791 } | |
| 792 | |
| 793 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { | |
| 794 SetTransformImmediately(transform); | |
| 795 } | |
| 796 | |
| 797 void Layer::SetOpacityFromAnimation(float opacity) { | |
| 798 SetOpacityImmediately(opacity); | |
| 799 } | |
| 800 | |
| 801 void Layer::SetVisibilityFromAnimation(bool visibility) { | |
| 802 SetVisibilityImmediately(visibility); | |
| 803 } | |
| 804 | |
| 805 void Layer::SetBrightnessFromAnimation(float brightness) { | |
| 806 SetBrightnessImmediately(brightness); | |
| 807 } | |
| 808 | |
| 809 void Layer::SetGrayscaleFromAnimation(float grayscale) { | |
| 810 SetGrayscaleImmediately(grayscale); | |
| 811 } | |
| 812 | |
| 813 void Layer::SetColorFromAnimation(SkColor color) { | |
| 814 SetColorImmediately(color); | |
| 815 } | |
| 816 | |
| 817 void Layer::ScheduleDrawForAnimation() { | 783 void Layer::ScheduleDrawForAnimation() { |
| 818 ScheduleDraw(); | 784 ScheduleDraw(); |
| 819 } | 785 } |
| 820 | 786 |
| 821 const gfx::Rect& Layer::GetBoundsForAnimation() const { | 787 const gfx::Rect& Layer::GetBoundsForAnimation() const { |
| 822 return bounds(); | 788 return bounds(); |
| 823 } | 789 } |
| 824 | 790 |
| 825 gfx::Transform Layer::GetTransformForAnimation() const { | 791 gfx::Transform Layer::GetTransformForAnimation() const { |
| 826 return transform(); | 792 return transform(); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 cc_layer_->SetBounds(ConvertSizeToPixel(this, size)); | 934 cc_layer_->SetBounds(ConvertSizeToPixel(this, size)); |
| 969 } | 935 } |
| 970 | 936 |
| 971 void Layer::RecomputePosition() { | 937 void Layer::RecomputePosition() { |
| 972 cc_layer_->SetPosition(gfx::ScalePoint( | 938 cc_layer_->SetPosition(gfx::ScalePoint( |
| 973 gfx::PointF(bounds_.x(), bounds_.y()), | 939 gfx::PointF(bounds_.x(), bounds_.y()), |
| 974 device_scale_factor_)); | 940 device_scale_factor_)); |
| 975 } | 941 } |
| 976 | 942 |
| 977 } // namespace ui | 943 } // namespace ui |
| OLD | NEW |