| 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 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 namespace ui { | 43 namespace ui { |
| 44 | 44 |
| 45 Layer::Layer() | 45 Layer::Layer() |
| 46 : type_(LAYER_TEXTURED), | 46 : type_(LAYER_TEXTURED), |
| 47 compositor_(NULL), | 47 compositor_(NULL), |
| 48 parent_(NULL), | 48 parent_(NULL), |
| 49 visible_(true), | 49 visible_(true), |
| 50 is_drawn_(true), | |
| 51 force_render_surface_(false), | 50 force_render_surface_(false), |
| 52 fills_bounds_opaquely_(true), | 51 fills_bounds_opaquely_(true), |
| 53 layer_updated_externally_(false), | 52 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 is_drawn_(true), | |
| 76 force_render_surface_(false), | 74 force_render_surface_(false), |
| 77 fills_bounds_opaquely_(true), | 75 fills_bounds_opaquely_(true), |
| 78 layer_updated_externally_(false), | 76 layer_updated_externally_(false), |
| 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), |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 133 } |
| 136 | 134 |
| 137 void Layer::Add(Layer* child) { | 135 void Layer::Add(Layer* child) { |
| 138 DCHECK(!child->compositor_); | 136 DCHECK(!child->compositor_); |
| 139 if (child->parent_) | 137 if (child->parent_) |
| 140 child->parent_->Remove(child); | 138 child->parent_->Remove(child); |
| 141 child->parent_ = this; | 139 child->parent_ = this; |
| 142 children_.push_back(child); | 140 children_.push_back(child); |
| 143 cc_layer_->AddChild(child->cc_layer_); | 141 cc_layer_->AddChild(child->cc_layer_); |
| 144 child->OnDeviceScaleFactorChanged(device_scale_factor_); | 142 child->OnDeviceScaleFactorChanged(device_scale_factor_); |
| 145 child->UpdateIsDrawn(); | |
| 146 if (GetCompositor()) | 143 if (GetCompositor()) |
| 147 child->SendPendingThreadedAnimations(); | 144 child->SendPendingThreadedAnimations(); |
| 148 } | 145 } |
| 149 | 146 |
| 150 void Layer::Remove(Layer* child) { | 147 void Layer::Remove(Layer* child) { |
| 151 std::vector<Layer*>::iterator i = | 148 std::vector<Layer*>::iterator i = |
| 152 std::find(children_.begin(), children_.end(), child); | 149 std::find(children_.begin(), children_.end(), child); |
| 153 DCHECK(i != children_.end()); | 150 DCHECK(i != children_.end()); |
| 154 children_.erase(i); | 151 children_.erase(i); |
| 155 child->parent_ = NULL; | 152 child->parent_ = NULL; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 } | 360 } |
| 364 | 361 |
| 365 bool Layer::GetTargetVisibility() const { | 362 bool Layer::GetTargetVisibility() const { |
| 366 if (animator_.get() && animator_->IsAnimatingProperty( | 363 if (animator_.get() && animator_->IsAnimatingProperty( |
| 367 LayerAnimationElement::VISIBILITY)) | 364 LayerAnimationElement::VISIBILITY)) |
| 368 return animator_->GetTargetVisibility(); | 365 return animator_->GetTargetVisibility(); |
| 369 return visible_; | 366 return visible_; |
| 370 } | 367 } |
| 371 | 368 |
| 372 bool Layer::IsDrawn() const { | 369 bool Layer::IsDrawn() const { |
| 373 return is_drawn_; | 370 const Layer* layer = this; |
| 374 } | 371 while (layer && layer->visible_) |
| 375 | 372 layer = layer->parent_; |
| 376 void Layer::UpdateIsDrawn() { | 373 return layer == NULL; |
| 377 bool updated_is_drawn = visible_ && (!parent_ || parent_->IsDrawn()); | |
| 378 | |
| 379 if (updated_is_drawn == is_drawn_) | |
| 380 return; | |
| 381 | |
| 382 is_drawn_ = updated_is_drawn; | |
| 383 cc_layer_->SetIsDrawable(is_drawn_ && type_ != LAYER_NOT_DRAWN); | |
| 384 | |
| 385 for (size_t i = 0; i < children_.size(); ++i) { | |
| 386 children_[i]->UpdateIsDrawn(); | |
| 387 } | |
| 388 } | 374 } |
| 389 | 375 |
| 390 bool Layer::ShouldDraw() const { | 376 bool Layer::ShouldDraw() const { |
| 391 return type_ != LAYER_NOT_DRAWN && GetCombinedOpacity() > 0.0f; | 377 return type_ != LAYER_NOT_DRAWN && GetCombinedOpacity() > 0.0f; |
| 392 } | 378 } |
| 393 | 379 |
| 394 // static | 380 // static |
| 395 void Layer::ConvertPointToLayer(const Layer* source, | 381 void Layer::ConvertPointToLayer(const Layer* source, |
| 396 const Layer* target, | 382 const Layer* target, |
| 397 gfx::Point* point) { | 383 gfx::Point* point) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 delegated_renderer_layer_ = NULL; | 457 delegated_renderer_layer_ = NULL; |
| 472 | 458 |
| 473 cc_layer_->AddLayerAnimationEventObserver(this); | 459 cc_layer_->AddLayerAnimationEventObserver(this); |
| 474 for (size_t i = 0; i < children_.size(); ++i) { | 460 for (size_t i = 0; i < children_.size(); ++i) { |
| 475 DCHECK(children_[i]->cc_layer_); | 461 DCHECK(children_[i]->cc_layer_); |
| 476 cc_layer_->AddChild(children_[i]->cc_layer_); | 462 cc_layer_->AddChild(children_[i]->cc_layer_); |
| 477 } | 463 } |
| 478 cc_layer_->SetAnchorPoint(gfx::PointF()); | 464 cc_layer_->SetAnchorPoint(gfx::PointF()); |
| 479 cc_layer_->SetContentsOpaque(fills_bounds_opaquely_); | 465 cc_layer_->SetContentsOpaque(fills_bounds_opaquely_); |
| 480 cc_layer_->SetForceRenderSurface(force_render_surface_); | 466 cc_layer_->SetForceRenderSurface(force_render_surface_); |
| 481 cc_layer_->SetIsDrawable(IsDrawn()); | 467 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); |
| 468 cc_layer_->SetHideLayerAndSubtree(!visible_); |
| 482 } | 469 } |
| 483 | 470 |
| 484 void Layer::SwitchCCLayerForTest() { | 471 void Layer::SwitchCCLayerForTest() { |
| 485 scoped_refptr<cc::ContentLayer> new_layer = cc::ContentLayer::Create(this); | 472 scoped_refptr<cc::ContentLayer> new_layer = cc::ContentLayer::Create(this); |
| 486 SwitchToLayer(new_layer); | 473 SwitchToLayer(new_layer); |
| 487 content_layer_ = new_layer; | 474 content_layer_ = new_layer; |
| 488 } | 475 } |
| 489 | 476 |
| 490 void Layer::SetExternalTexture(Texture* texture) { | 477 void Layer::SetExternalTexture(Texture* texture) { |
| 491 // Hold a ref to the old |Texture| until we have updated all | 478 // Hold a ref to the old |Texture| until we have updated all |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 void Layer::SetOpacityImmediately(float opacity) { | 753 void Layer::SetOpacityImmediately(float opacity) { |
| 767 cc_layer_->SetOpacity(opacity); | 754 cc_layer_->SetOpacity(opacity); |
| 768 ScheduleDraw(); | 755 ScheduleDraw(); |
| 769 } | 756 } |
| 770 | 757 |
| 771 void Layer::SetVisibilityImmediately(bool visible) { | 758 void Layer::SetVisibilityImmediately(bool visible) { |
| 772 if (visible_ == visible) | 759 if (visible_ == visible) |
| 773 return; | 760 return; |
| 774 | 761 |
| 775 visible_ = visible; | 762 visible_ = visible; |
| 776 UpdateIsDrawn(); | 763 cc_layer_->SetHideLayerAndSubtree(!visible_); |
| 777 } | 764 } |
| 778 | 765 |
| 779 void Layer::SetBrightnessImmediately(float brightness) { | 766 void Layer::SetBrightnessImmediately(float brightness) { |
| 780 layer_brightness_ = brightness; | 767 layer_brightness_ = brightness; |
| 781 SetLayerFilters(); | 768 SetLayerFilters(); |
| 782 } | 769 } |
| 783 | 770 |
| 784 void Layer::SetGrayscaleImmediately(float grayscale) { | 771 void Layer::SetGrayscaleImmediately(float grayscale) { |
| 785 layer_grayscale_ = grayscale; | 772 layer_grayscale_ = grayscale; |
| 786 SetLayerFilters(); | 773 SetLayerFilters(); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 cc_layer_->SetBounds(ConvertSizeToPixel(this, size)); | 960 cc_layer_->SetBounds(ConvertSizeToPixel(this, size)); |
| 974 } | 961 } |
| 975 | 962 |
| 976 void Layer::RecomputePosition() { | 963 void Layer::RecomputePosition() { |
| 977 cc_layer_->SetPosition(gfx::ScalePoint( | 964 cc_layer_->SetPosition(gfx::ScalePoint( |
| 978 gfx::PointF(bounds_.x(), bounds_.y()), | 965 gfx::PointF(bounds_.x(), bounds_.y()), |
| 979 device_scale_factor_)); | 966 device_scale_factor_)); |
| 980 } | 967 } |
| 981 | 968 |
| 982 } // namespace ui | 969 } // namespace ui |
| OLD | NEW |