| 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 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 Layer::Layer() | 41 Layer::Layer() |
| 42 : type_(LAYER_TEXTURED), | 42 : type_(LAYER_TEXTURED), |
| 43 compositor_(NULL), | 43 compositor_(NULL), |
| 44 parent_(NULL), | 44 parent_(NULL), |
| 45 visible_(true), | 45 visible_(true), |
| 46 is_drawn_(true), | 46 is_drawn_(true), |
| 47 force_render_surface_(false), | 47 force_render_surface_(false), |
| 48 fills_bounds_opaquely_(true), | 48 fills_bounds_opaquely_(true), |
| 49 layer_updated_externally_(false), | 49 layer_updated_externally_(false), |
| 50 opacity_(1.0f), | |
| 51 background_blur_radius_(0), | 50 background_blur_radius_(0), |
| 52 layer_saturation_(0.0f), | 51 layer_saturation_(0.0f), |
| 53 layer_brightness_(0.0f), | 52 layer_brightness_(0.0f), |
| 54 layer_grayscale_(0.0f), | 53 layer_grayscale_(0.0f), |
| 55 layer_inverted_(false), | 54 layer_inverted_(false), |
| 56 layer_mask_(NULL), | 55 layer_mask_(NULL), |
| 57 layer_mask_back_link_(NULL), | 56 layer_mask_back_link_(NULL), |
| 58 zoom_x_offset_(0), | 57 zoom_x_offset_(0), |
| 59 zoom_y_offset_(0), | 58 zoom_y_offset_(0), |
| 60 zoom_(1), | 59 zoom_(1), |
| 61 zoom_inset_(0), | 60 zoom_inset_(0), |
| 62 delegate_(NULL), | 61 delegate_(NULL), |
| 63 cc_layer_(NULL), | 62 cc_layer_(NULL), |
| 64 scale_content_(true), | 63 scale_content_(true), |
| 65 device_scale_factor_(1.0f) { | 64 device_scale_factor_(1.0f) { |
| 66 CreateWebLayer(); | 65 CreateWebLayer(); |
| 67 } | 66 } |
| 68 | 67 |
| 69 Layer::Layer(LayerType type) | 68 Layer::Layer(LayerType type) |
| 70 : type_(type), | 69 : type_(type), |
| 71 compositor_(NULL), | 70 compositor_(NULL), |
| 72 parent_(NULL), | 71 parent_(NULL), |
| 73 visible_(true), | 72 visible_(true), |
| 74 is_drawn_(true), | 73 is_drawn_(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), | 76 layer_updated_externally_(false), |
| 78 opacity_(1.0f), | |
| 79 background_blur_radius_(0), | 77 background_blur_radius_(0), |
| 80 layer_saturation_(0.0f), | 78 layer_saturation_(0.0f), |
| 81 layer_brightness_(0.0f), | 79 layer_brightness_(0.0f), |
| 82 layer_grayscale_(0.0f), | 80 layer_grayscale_(0.0f), |
| 83 layer_inverted_(false), | 81 layer_inverted_(false), |
| 84 layer_mask_(NULL), | 82 layer_mask_(NULL), |
| 85 layer_mask_back_link_(NULL), | 83 layer_mask_back_link_(NULL), |
| 86 zoom_x_offset_(0), | 84 zoom_x_offset_(0), |
| 87 zoom_y_offset_(0), | 85 zoom_y_offset_(0), |
| 88 zoom_(1), | 86 zoom_(1), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 103 if (compositor_) | 101 if (compositor_) |
| 104 compositor_->SetRootLayer(NULL); | 102 compositor_->SetRootLayer(NULL); |
| 105 if (parent_) | 103 if (parent_) |
| 106 parent_->Remove(this); | 104 parent_->Remove(this); |
| 107 if (layer_mask_) | 105 if (layer_mask_) |
| 108 SetMaskLayer(NULL); | 106 SetMaskLayer(NULL); |
| 109 if (layer_mask_back_link_) | 107 if (layer_mask_back_link_) |
| 110 layer_mask_back_link_->SetMaskLayer(NULL); | 108 layer_mask_back_link_->SetMaskLayer(NULL); |
| 111 for (size_t i = 0; i < children_.size(); ++i) | 109 for (size_t i = 0; i < children_.size(); ++i) |
| 112 children_[i]->parent_ = NULL; | 110 children_[i]->parent_ = NULL; |
| 111 cc_layer_->removeLayerAnimationEventObserver(this); |
| 113 cc_layer_->removeFromParent(); | 112 cc_layer_->removeFromParent(); |
| 114 } | 113 } |
| 115 | 114 |
| 116 Compositor* Layer::GetCompositor() { | 115 Compositor* Layer::GetCompositor() { |
| 117 return GetRoot(this)->compositor_; | 116 return GetRoot(this)->compositor_; |
| 118 } | 117 } |
| 119 | 118 |
| 119 float Layer::opacity() const { |
| 120 return cc_layer_->opacity(); |
| 121 } |
| 122 |
| 120 void Layer::SetCompositor(Compositor* compositor) { | 123 void Layer::SetCompositor(Compositor* compositor) { |
| 121 // This function must only be called to set the compositor on the root layer, | 124 // This function must only be called to set the compositor on the root layer, |
| 122 // or to reset it. | 125 // or to reset it. |
| 123 DCHECK(!compositor || !compositor_); | 126 DCHECK(!compositor || !compositor_); |
| 124 DCHECK(!compositor || compositor->root_layer() == this); | 127 DCHECK(!compositor || compositor->root_layer() == this); |
| 125 DCHECK(!parent_); | 128 DCHECK(!parent_); |
| 126 compositor_ = compositor; | 129 compositor_ = compositor; |
| 127 if (compositor) | 130 if (compositor) |
| 128 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); | 131 OnDeviceScaleFactorChanged(compositor->device_scale_factor()); |
| 129 } | 132 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 221 |
| 219 bool Layer::GetMasksToBounds() const { | 222 bool Layer::GetMasksToBounds() const { |
| 220 return cc_layer_->masksToBounds(); | 223 return cc_layer_->masksToBounds(); |
| 221 } | 224 } |
| 222 | 225 |
| 223 void Layer::SetOpacity(float opacity) { | 226 void Layer::SetOpacity(float opacity) { |
| 224 GetAnimator()->SetOpacity(opacity); | 227 GetAnimator()->SetOpacity(opacity); |
| 225 } | 228 } |
| 226 | 229 |
| 227 float Layer::GetCombinedOpacity() const { | 230 float Layer::GetCombinedOpacity() const { |
| 228 float opacity = opacity_; | 231 float opacity = this->opacity(); |
| 229 Layer* current = this->parent_; | 232 Layer* current = this->parent_; |
| 230 while (current) { | 233 while (current) { |
| 231 opacity *= current->opacity_; | 234 opacity *= current->opacity(); |
| 232 current = current->parent_; | 235 current = current->parent_; |
| 233 } | 236 } |
| 234 return opacity; | 237 return opacity; |
| 235 } | 238 } |
| 236 | 239 |
| 237 void Layer::SetBackgroundBlur(int blur_radius) { | 240 void Layer::SetBackgroundBlur(int blur_radius) { |
| 238 background_blur_radius_ = blur_radius; | 241 background_blur_radius_ = blur_radius; |
| 239 | 242 |
| 240 SetLayerBackgroundFilters(); | 243 SetLayerBackgroundFilters(); |
| 241 } | 244 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 background_blur_radius_)); | 351 background_blur_radius_)); |
| 349 } | 352 } |
| 350 | 353 |
| 351 cc_layer_->setBackgroundFilters(filters); | 354 cc_layer_->setBackgroundFilters(filters); |
| 352 } | 355 } |
| 353 | 356 |
| 354 float Layer::GetTargetOpacity() const { | 357 float Layer::GetTargetOpacity() const { |
| 355 if (animator_.get() && animator_->IsAnimatingProperty( | 358 if (animator_.get() && animator_->IsAnimatingProperty( |
| 356 LayerAnimationElement::OPACITY)) | 359 LayerAnimationElement::OPACITY)) |
| 357 return animator_->GetTargetOpacity(); | 360 return animator_->GetTargetOpacity(); |
| 358 return opacity_; | 361 return opacity(); |
| 359 } | 362 } |
| 360 | 363 |
| 361 void Layer::SetVisible(bool visible) { | 364 void Layer::SetVisible(bool visible) { |
| 362 GetAnimator()->SetVisibility(visible); | 365 GetAnimator()->SetVisibility(visible); |
| 363 } | 366 } |
| 364 | 367 |
| 365 bool Layer::GetTargetVisibility() const { | 368 bool Layer::GetTargetVisibility() const { |
| 366 if (animator_.get() && animator_->IsAnimatingProperty( | 369 if (animator_.get() && animator_->IsAnimatingProperty( |
| 367 LayerAnimationElement::VISIBILITY)) | 370 LayerAnimationElement::VISIBILITY)) |
| 368 return animator_->GetTargetVisibility(); | 371 return animator_->GetTargetVisibility(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 new_layer = texture_layer_.get(); | 440 new_layer = texture_layer_.get(); |
| 438 } else { | 441 } else { |
| 439 old_texture_layer->willModifyTexture(); | 442 old_texture_layer->willModifyTexture(); |
| 440 content_layer_ = cc::ContentLayer::create(this); | 443 content_layer_ = cc::ContentLayer::create(this); |
| 441 new_layer = content_layer_.get(); | 444 new_layer = content_layer_.get(); |
| 442 } | 445 } |
| 443 if (parent_) { | 446 if (parent_) { |
| 444 DCHECK(parent_->cc_layer_); | 447 DCHECK(parent_->cc_layer_); |
| 445 parent_->cc_layer_->replaceChild(cc_layer_, new_layer); | 448 parent_->cc_layer_->replaceChild(cc_layer_, new_layer); |
| 446 } | 449 } |
| 450 cc_layer_->removeLayerAnimationEventObserver(this); |
| 451 new_layer->setOpacity(cc_layer_->opacity()); |
| 447 cc_layer_= new_layer; | 452 cc_layer_= new_layer; |
| 453 cc_layer_->addLayerAnimationEventObserver(this); |
| 448 cc_layer_is_accelerated_ = layer_updated_externally_; | 454 cc_layer_is_accelerated_ = layer_updated_externally_; |
| 449 for (size_t i = 0; i < children_.size(); ++i) { | 455 for (size_t i = 0; i < children_.size(); ++i) { |
| 450 DCHECK(children_[i]->cc_layer_); | 456 DCHECK(children_[i]->cc_layer_); |
| 451 cc_layer_->addChild(children_[i]->cc_layer_); | 457 cc_layer_->addChild(children_[i]->cc_layer_); |
| 452 } | 458 } |
| 453 cc_layer_->setAnchorPoint(gfx::PointF()); | 459 cc_layer_->setAnchorPoint(gfx::PointF()); |
| 454 cc_layer_->setContentsOpaque(fills_bounds_opaquely_); | 460 cc_layer_->setContentsOpaque(fills_bounds_opaquely_); |
| 455 cc_layer_->setOpacity(opacity_); | |
| 456 cc_layer_->setForceRenderSurface(force_render_surface_); | 461 cc_layer_->setForceRenderSurface(force_render_surface_); |
| 457 cc_layer_->setIsDrawable(IsDrawn()); | 462 cc_layer_->setIsDrawable(IsDrawn()); |
| 458 RecomputeTransform(); | 463 RecomputeTransform(); |
| 459 } | 464 } |
| 460 RecomputeDrawsContentAndUVRect(); | 465 RecomputeDrawsContentAndUVRect(); |
| 461 } | 466 } |
| 462 | 467 |
| 463 void Layer::SetColor(SkColor color) { | 468 void Layer::SetColor(SkColor color) { |
| 464 GetAnimator()->SetColor(color); | 469 GetAnimator()->SetColor(color); |
| 465 } | 470 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 } | 562 } |
| 558 | 563 |
| 559 void Layer::SetForceRenderSurface(bool force) { | 564 void Layer::SetForceRenderSurface(bool force) { |
| 560 if (force_render_surface_ == force) | 565 if (force_render_surface_ == force) |
| 561 return; | 566 return; |
| 562 | 567 |
| 563 force_render_surface_ = force; | 568 force_render_surface_ = force; |
| 564 cc_layer_->setForceRenderSurface(force_render_surface_); | 569 cc_layer_->setForceRenderSurface(force_render_surface_); |
| 565 } | 570 } |
| 566 | 571 |
| 572 void Layer::OnAnimationStarted(const cc::AnimationEvent& event) { |
| 573 if (animator_) |
| 574 animator_->OnThreadedAnimationStarted(event); |
| 575 } |
| 576 |
| 567 void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) { | 577 void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) { |
| 568 DCHECK_NE(child, other); | 578 DCHECK_NE(child, other); |
| 569 DCHECK_EQ(this, child->parent()); | 579 DCHECK_EQ(this, child->parent()); |
| 570 DCHECK_EQ(this, other->parent()); | 580 DCHECK_EQ(this, other->parent()); |
| 571 | 581 |
| 572 const size_t child_i = | 582 const size_t child_i = |
| 573 std::find(children_.begin(), children_.end(), child) - children_.begin(); | 583 std::find(children_.begin(), children_.end(), child) - children_.begin(); |
| 574 const size_t other_i = | 584 const size_t other_i = |
| 575 std::find(children_.begin(), children_.end(), other) - children_.begin(); | 585 std::find(children_.begin(), children_.end(), other) - children_.begin(); |
| 576 if ((above && child_i == other_i + 1) || (!above && child_i + 1 == other_i)) | 586 if ((above && child_i == other_i + 1) || (!above && child_i + 1 == other_i)) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 } | 659 } |
| 650 } | 660 } |
| 651 | 661 |
| 652 void Layer::SetTransformImmediately(const gfx::Transform& transform) { | 662 void Layer::SetTransformImmediately(const gfx::Transform& transform) { |
| 653 transform_ = transform; | 663 transform_ = transform; |
| 654 | 664 |
| 655 RecomputeTransform(); | 665 RecomputeTransform(); |
| 656 } | 666 } |
| 657 | 667 |
| 658 void Layer::SetOpacityImmediately(float opacity) { | 668 void Layer::SetOpacityImmediately(float opacity) { |
| 659 opacity_ = opacity; | |
| 660 | |
| 661 cc_layer_->setOpacity(opacity); | 669 cc_layer_->setOpacity(opacity); |
| 662 ScheduleDraw(); | 670 ScheduleDraw(); |
| 663 } | 671 } |
| 664 | 672 |
| 665 void Layer::SetVisibilityImmediately(bool visible) { | 673 void Layer::SetVisibilityImmediately(bool visible) { |
| 666 if (visible_ == visible) | 674 if (visible_ == visible) |
| 667 return; | 675 return; |
| 668 | 676 |
| 669 visible_ = visible; | 677 visible_ = visible; |
| 670 UpdateIsDrawn(); | 678 UpdateIsDrawn(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 } | 752 } |
| 745 | 753 |
| 746 SkColor Layer::GetColorForAnimation() const { | 754 SkColor Layer::GetColorForAnimation() const { |
| 747 // WebColor is equivalent to SkColor, per WebColor.h. | 755 // WebColor is equivalent to SkColor, per WebColor.h. |
| 748 // The NULL check is here since this is invoked regardless of whether we have | 756 // The NULL check is here since this is invoked regardless of whether we have |
| 749 // been configured as LAYER_SOLID_COLOR. | 757 // been configured as LAYER_SOLID_COLOR. |
| 750 return solid_color_layer_.get() ? | 758 return solid_color_layer_.get() ? |
| 751 solid_color_layer_->backgroundColor() : SK_ColorBLACK; | 759 solid_color_layer_->backgroundColor() : SK_ColorBLACK; |
| 752 } | 760 } |
| 753 | 761 |
| 762 void Layer::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) { |
| 763 DCHECK(cc_layer_); |
| 764 cc_layer_->addAnimation(animation.Pass()); |
| 765 } |
| 766 |
| 767 void Layer::RemoveThreadedAnimation(int animation_id) { |
| 768 DCHECK(cc_layer_); |
| 769 cc_layer_->removeAnimation(animation_id); |
| 770 } |
| 771 |
| 754 void Layer::CreateWebLayer() { | 772 void Layer::CreateWebLayer() { |
| 755 if (type_ == LAYER_SOLID_COLOR) { | 773 if (type_ == LAYER_SOLID_COLOR) { |
| 756 solid_color_layer_ = cc::SolidColorLayer::create(); | 774 solid_color_layer_ = cc::SolidColorLayer::create(); |
| 757 cc_layer_ = solid_color_layer_.get(); | 775 cc_layer_ = solid_color_layer_.get(); |
| 758 } else { | 776 } else { |
| 759 content_layer_ = cc::ContentLayer::create(this); | 777 content_layer_ = cc::ContentLayer::create(this); |
| 760 cc_layer_ = content_layer_.get(); | 778 cc_layer_ = content_layer_.get(); |
| 761 } | 779 } |
| 762 cc_layer_is_accelerated_ = false; | 780 cc_layer_is_accelerated_ = false; |
| 763 cc_layer_->setAnchorPoint(gfx::PointF()); | 781 cc_layer_->setAnchorPoint(gfx::PointF()); |
| 764 cc_layer_->setContentsOpaque(true); | 782 cc_layer_->setContentsOpaque(true); |
| 765 cc_layer_->setIsDrawable(type_ != LAYER_NOT_DRAWN); | 783 cc_layer_->setIsDrawable(type_ != LAYER_NOT_DRAWN); |
| 784 cc_layer_->addLayerAnimationEventObserver(this); |
| 766 } | 785 } |
| 767 | 786 |
| 768 void Layer::RecomputeTransform() { | 787 void Layer::RecomputeTransform() { |
| 769 gfx::Transform scale_translate; | 788 gfx::Transform scale_translate; |
| 770 scale_translate.matrix().set3x3(device_scale_factor_, 0, 0, | 789 scale_translate.matrix().set3x3(device_scale_factor_, 0, 0, |
| 771 0, device_scale_factor_, 0, | 790 0, device_scale_factor_, 0, |
| 772 0, 0, 1); | 791 0, 0, 1); |
| 773 // Start with the inverse matrix of above. | 792 // Start with the inverse matrix of above. |
| 774 gfx::Transform transform; | 793 gfx::Transform transform; |
| 775 transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0, | 794 transform.matrix().set3x3(1.0f / device_scale_factor_, 0, 0, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 800 gfx::PointF uv_bottom_right( | 819 gfx::PointF uv_bottom_right( |
| 801 static_cast<float>(size.width())/texture_size.width(), | 820 static_cast<float>(size.width())/texture_size.width(), |
| 802 static_cast<float>(size.height())/texture_size.height()); | 821 static_cast<float>(size.height())/texture_size.height()); |
| 803 texture_layer_->setUV(uv_top_left, uv_bottom_right); | 822 texture_layer_->setUV(uv_top_left, uv_bottom_right); |
| 804 | 823 |
| 805 cc_layer_->setBounds(ConvertSizeToPixel(this, size)); | 824 cc_layer_->setBounds(ConvertSizeToPixel(this, size)); |
| 806 } | 825 } |
| 807 } | 826 } |
| 808 | 827 |
| 809 } // namespace ui | 828 } // namespace ui |
| OLD | NEW |