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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 GetAnimator()->SetVisibility(visible); | 359 GetAnimator()->SetVisibility(visible); |
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 { | |
373 return is_drawn_; | |
374 } | |
375 | |
376 void Layer::UpdateIsDrawn() { | |
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 } | |
389 | |
390 bool Layer::ShouldDraw() const { | 369 bool Layer::ShouldDraw() const { |
391 return type_ != LAYER_NOT_DRAWN && GetCombinedOpacity() > 0.0f; | 370 return type_ != LAYER_NOT_DRAWN && GetCombinedOpacity() > 0.0f; |
392 } | 371 } |
393 | 372 |
394 // static | 373 // static |
395 void Layer::ConvertPointToLayer(const Layer* source, | 374 void Layer::ConvertPointToLayer(const Layer* source, |
396 const Layer* target, | 375 const Layer* target, |
397 gfx::Point* point) { | 376 gfx::Point* point) { |
398 if (source == target) | 377 if (source == target) |
399 return; | 378 return; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 delegated_renderer_layer_ = NULL; | 450 delegated_renderer_layer_ = NULL; |
472 | 451 |
473 cc_layer_->AddLayerAnimationEventObserver(this); | 452 cc_layer_->AddLayerAnimationEventObserver(this); |
474 for (size_t i = 0; i < children_.size(); ++i) { | 453 for (size_t i = 0; i < children_.size(); ++i) { |
475 DCHECK(children_[i]->cc_layer_); | 454 DCHECK(children_[i]->cc_layer_); |
476 cc_layer_->AddChild(children_[i]->cc_layer_); | 455 cc_layer_->AddChild(children_[i]->cc_layer_); |
477 } | 456 } |
478 cc_layer_->SetAnchorPoint(gfx::PointF()); | 457 cc_layer_->SetAnchorPoint(gfx::PointF()); |
479 cc_layer_->SetContentsOpaque(fills_bounds_opaquely_); | 458 cc_layer_->SetContentsOpaque(fills_bounds_opaquely_); |
480 cc_layer_->SetForceRenderSurface(force_render_surface_); | 459 cc_layer_->SetForceRenderSurface(force_render_surface_); |
481 cc_layer_->SetIsDrawable(IsDrawn()); | 460 cc_layer_->SetHideLayerAndSubtree(!visible_); |
482 } | 461 } |
483 | 462 |
484 void Layer::SwitchCCLayerForTest() { | 463 void Layer::SwitchCCLayerForTest() { |
485 scoped_refptr<cc::ContentLayer> new_layer = cc::ContentLayer::Create(this); | 464 scoped_refptr<cc::ContentLayer> new_layer = cc::ContentLayer::Create(this); |
486 SwitchToLayer(new_layer); | 465 SwitchToLayer(new_layer); |
487 content_layer_ = new_layer; | 466 content_layer_ = new_layer; |
488 } | 467 } |
489 | 468 |
490 void Layer::SetExternalTexture(Texture* texture) { | 469 void Layer::SetExternalTexture(Texture* texture) { |
491 // Hold a ref to the old |Texture| until we have updated all | 470 // Hold a ref to the old |Texture| until we have updated all |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 | 723 |
745 RecomputeDrawsContentAndUVRect(); | 724 RecomputeDrawsContentAndUVRect(); |
746 RecomputePosition(); | 725 RecomputePosition(); |
747 | 726 |
748 if (!closure.is_null()) | 727 if (!closure.is_null()) |
749 closure.Run(); | 728 closure.Run(); |
750 | 729 |
751 if (was_move) { | 730 if (was_move) { |
752 // Don't schedule a draw if we're invisible. We'll schedule one | 731 // Don't schedule a draw if we're invisible. We'll schedule one |
753 // automatically when we get visible. | 732 // automatically when we get visible. |
754 if (IsDrawn()) | 733 if (visible_) |
755 ScheduleDraw(); | 734 ScheduleDraw(); |
756 } else { | 735 } else { |
757 // Always schedule a paint, even if we're invisible. | 736 // Always schedule a paint, even if we're invisible. |
758 SchedulePaint(gfx::Rect(bounds.size())); | 737 SchedulePaint(gfx::Rect(bounds.size())); |
759 } | 738 } |
760 } | 739 } |
761 | 740 |
762 void Layer::SetTransformImmediately(const gfx::Transform& transform) { | 741 void Layer::SetTransformImmediately(const gfx::Transform& transform) { |
763 RecomputeCCTransformFromTransform(transform); | 742 RecomputeCCTransformFromTransform(transform); |
764 } | 743 } |
765 | 744 |
766 void Layer::SetOpacityImmediately(float opacity) { | 745 void Layer::SetOpacityImmediately(float opacity) { |
767 cc_layer_->SetOpacity(opacity); | 746 cc_layer_->SetOpacity(opacity); |
768 ScheduleDraw(); | 747 ScheduleDraw(); |
769 } | 748 } |
770 | 749 |
771 void Layer::SetVisibilityImmediately(bool visible) { | 750 void Layer::SetVisibilityImmediately(bool visible) { |
772 if (visible_ == visible) | 751 if (visible_ == visible) |
773 return; | 752 return; |
774 | 753 |
775 visible_ = visible; | 754 visible_ = visible; |
776 UpdateIsDrawn(); | 755 cc_layer_->SetHideLayerAndSubtree(!visible_); |
777 } | 756 } |
778 | 757 |
779 void Layer::SetBrightnessImmediately(float brightness) { | 758 void Layer::SetBrightnessImmediately(float brightness) { |
780 layer_brightness_ = brightness; | 759 layer_brightness_ = brightness; |
781 SetLayerFilters(); | 760 SetLayerFilters(); |
782 } | 761 } |
783 | 762 |
784 void Layer::SetGrayscaleImmediately(float grayscale) { | 763 void Layer::SetGrayscaleImmediately(float grayscale) { |
785 layer_grayscale_ = grayscale; | 764 layer_grayscale_ = grayscale; |
786 SetLayerFilters(); | 765 SetLayerFilters(); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 cc_layer_->SetBounds(ConvertSizeToPixel(this, size)); | 952 cc_layer_->SetBounds(ConvertSizeToPixel(this, size)); |
974 } | 953 } |
975 | 954 |
976 void Layer::RecomputePosition() { | 955 void Layer::RecomputePosition() { |
977 cc_layer_->SetPosition(gfx::ScalePoint( | 956 cc_layer_->SetPosition(gfx::ScalePoint( |
978 gfx::PointF(bounds_.x(), bounds_.y()), | 957 gfx::PointF(bounds_.x(), bounds_.y()), |
979 device_scale_factor_)); | 958 device_scale_factor_)); |
980 } | 959 } |
981 | 960 |
982 } // namespace ui | 961 } // namespace ui |
OLD | NEW |