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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 layer_brightness_(0.0f), | 68 layer_brightness_(0.0f), |
69 layer_grayscale_(0.0f), | 69 layer_grayscale_(0.0f), |
70 layer_inverted_(false), | 70 layer_inverted_(false), |
71 layer_mask_(NULL), | 71 layer_mask_(NULL), |
72 layer_mask_back_link_(NULL), | 72 layer_mask_back_link_(NULL), |
73 zoom_(1), | 73 zoom_(1), |
74 zoom_inset_(0), | 74 zoom_inset_(0), |
75 delegate_(NULL), | 75 delegate_(NULL), |
76 owner_(NULL), | 76 owner_(NULL), |
77 cc_layer_(NULL), | 77 cc_layer_(NULL), |
78 device_scale_factor_(1.0f) { | 78 device_scale_factor_(1.0f), |
| 79 cached_cc_layer_opacity_(1.0f) { |
79 CreateCcLayer(); | 80 CreateCcLayer(); |
80 } | 81 } |
81 | 82 |
82 Layer::Layer(LayerType type) | 83 Layer::Layer(LayerType type) |
83 : type_(type), | 84 : type_(type), |
84 compositor_(NULL), | 85 compositor_(NULL), |
85 parent_(NULL), | 86 parent_(NULL), |
86 visible_(true), | 87 visible_(true), |
87 force_render_surface_(false), | 88 force_render_surface_(false), |
88 fills_bounds_opaquely_(true), | 89 fills_bounds_opaquely_(true), |
89 fills_bounds_completely_(false), | 90 fills_bounds_completely_(false), |
90 background_blur_radius_(0), | 91 background_blur_radius_(0), |
91 layer_saturation_(0.0f), | 92 layer_saturation_(0.0f), |
92 layer_brightness_(0.0f), | 93 layer_brightness_(0.0f), |
93 layer_grayscale_(0.0f), | 94 layer_grayscale_(0.0f), |
94 layer_inverted_(false), | 95 layer_inverted_(false), |
95 layer_mask_(NULL), | 96 layer_mask_(NULL), |
96 layer_mask_back_link_(NULL), | 97 layer_mask_back_link_(NULL), |
97 zoom_(1), | 98 zoom_(1), |
98 zoom_inset_(0), | 99 zoom_inset_(0), |
99 delegate_(NULL), | 100 delegate_(NULL), |
100 owner_(NULL), | 101 owner_(NULL), |
101 cc_layer_(NULL), | 102 cc_layer_(NULL), |
102 device_scale_factor_(1.0f) { | 103 device_scale_factor_(1.0f), |
| 104 cached_cc_layer_opacity_(1.0f) { |
103 CreateCcLayer(); | 105 CreateCcLayer(); |
104 } | 106 } |
105 | 107 |
106 Layer::~Layer() { | 108 Layer::~Layer() { |
107 // Destroying the animator may cause observers to use the layer (and | 109 // Destroying the animator may cause observers to use the layer (and |
108 // indirectly the WebLayer). Destroy the animator first so that the WebLayer | 110 // indirectly the WebLayer). Destroy the animator first so that the WebLayer |
109 // is still around. | 111 // is still around. |
110 if (animator_.get()) | 112 if (animator_.get()) |
111 animator_->SetDelegate(NULL); | 113 animator_->SetDelegate(NULL); |
112 animator_ = NULL; | 114 animator_ = NULL; |
(...skipping 22 matching lines...) Expand all Loading... |
135 g_ui_layer_settings.Get().use_compositor_animation_timelines = | 137 g_ui_layer_settings.Get().use_compositor_animation_timelines = |
136 !command_line->HasSwitch( | 138 !command_line->HasSwitch( |
137 switches::kUIDisableCompositorAnimationTimelines); | 139 switches::kUIDisableCompositorAnimationTimelines); |
138 } | 140 } |
139 | 141 |
140 const Compositor* Layer::GetCompositor() const { | 142 const Compositor* Layer::GetCompositor() const { |
141 return GetRoot(this)->compositor_; | 143 return GetRoot(this)->compositor_; |
142 } | 144 } |
143 | 145 |
144 float Layer::opacity() const { | 146 float Layer::opacity() const { |
145 return cc_layer_->opacity(); | 147 return !visible_ ? cached_cc_layer_opacity_ : cc_layer_->opacity(); |
146 } | 148 } |
147 | 149 |
148 void Layer::SetCompositor(Compositor* compositor, | 150 void Layer::SetCompositor(Compositor* compositor, |
149 scoped_refptr<cc::Layer> root_layer) { | 151 scoped_refptr<cc::Layer> root_layer) { |
150 // This function must only be called to set the compositor on the root ui | 152 // This function must only be called to set the compositor on the root ui |
151 // layer. | 153 // layer. |
152 DCHECK(compositor); | 154 DCHECK(compositor); |
153 DCHECK(!compositor_); | 155 DCHECK(!compositor_); |
154 DCHECK(compositor->root_layer() == this); | 156 DCHECK(compositor->root_layer() == this); |
155 DCHECK(!parent_); | 157 DCHECK(!parent_); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 277 |
276 void Layer::SetMasksToBounds(bool masks_to_bounds) { | 278 void Layer::SetMasksToBounds(bool masks_to_bounds) { |
277 cc_layer_->SetMasksToBounds(masks_to_bounds); | 279 cc_layer_->SetMasksToBounds(masks_to_bounds); |
278 } | 280 } |
279 | 281 |
280 bool Layer::GetMasksToBounds() const { | 282 bool Layer::GetMasksToBounds() const { |
281 return cc_layer_->masks_to_bounds(); | 283 return cc_layer_->masks_to_bounds(); |
282 } | 284 } |
283 | 285 |
284 void Layer::SetOpacity(float opacity) { | 286 void Layer::SetOpacity(float opacity) { |
285 GetAnimator()->SetOpacity(opacity); | 287 if (visible_) |
| 288 GetAnimator()->SetOpacity(opacity); |
| 289 else |
| 290 cached_cc_layer_opacity_ = opacity; |
286 } | 291 } |
287 | 292 |
288 float Layer::GetCombinedOpacity() const { | 293 float Layer::GetCombinedOpacity() const { |
289 float opacity = this->opacity(); | 294 float opacity = this->opacity(); |
290 Layer* current = this->parent_; | 295 Layer* current = this->parent_; |
291 while (current) { | 296 while (current) { |
292 opacity *= current->opacity(); | 297 opacity *= current->opacity(); |
293 current = current->parent_; | 298 current = current->parent_; |
294 } | 299 } |
295 return opacity; | 300 return opacity; |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 | 521 |
517 for (size_t i = 0; i < children_.size(); ++i) { | 522 for (size_t i = 0; i < children_.size(); ++i) { |
518 DCHECK(children_[i]->cc_layer_); | 523 DCHECK(children_[i]->cc_layer_); |
519 cc_layer_->AddChild(children_[i]->cc_layer_); | 524 cc_layer_->AddChild(children_[i]->cc_layer_); |
520 } | 525 } |
521 cc_layer_->SetLayerClient(this); | 526 cc_layer_->SetLayerClient(this); |
522 cc_layer_->SetTransformOrigin(gfx::Point3F()); | 527 cc_layer_->SetTransformOrigin(gfx::Point3F()); |
523 cc_layer_->SetContentsOpaque(fills_bounds_opaquely_); | 528 cc_layer_->SetContentsOpaque(fills_bounds_opaquely_); |
524 cc_layer_->SetForceRenderSurface(force_render_surface_); | 529 cc_layer_->SetForceRenderSurface(force_render_surface_); |
525 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); | 530 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); |
526 cc_layer_->SetHideLayerAndSubtree(!visible_); | |
527 | 531 |
528 SetLayerFilters(); | 532 SetLayerFilters(); |
529 SetLayerBackgroundFilters(); | 533 SetLayerBackgroundFilters(); |
530 } | 534 } |
531 | 535 |
532 void Layer::SwitchCCLayerForTest() { | 536 void Layer::SwitchCCLayerForTest() { |
533 scoped_refptr<cc::Layer> new_layer = | 537 scoped_refptr<cc::Layer> new_layer = |
534 cc::PictureLayer::Create(UILayerSettings(), this); | 538 cc::PictureLayer::Create(UILayerSettings(), this); |
535 SwitchToLayer(new_layer); | 539 SwitchToLayer(new_layer); |
536 content_layer_ = new_layer; | 540 content_layer_ = new_layer; |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 void Layer::SetOpacityFromAnimation(float opacity) { | 909 void Layer::SetOpacityFromAnimation(float opacity) { |
906 cc_layer_->SetOpacity(opacity); | 910 cc_layer_->SetOpacity(opacity); |
907 ScheduleDraw(); | 911 ScheduleDraw(); |
908 } | 912 } |
909 | 913 |
910 void Layer::SetVisibilityFromAnimation(bool visible) { | 914 void Layer::SetVisibilityFromAnimation(bool visible) { |
911 if (visible_ == visible) | 915 if (visible_ == visible) |
912 return; | 916 return; |
913 | 917 |
914 visible_ = visible; | 918 visible_ = visible; |
915 cc_layer_->SetHideLayerAndSubtree(!visible_); | 919 if (visible) { |
| 920 cc_layer_->SetOpacity(cached_cc_layer_opacity_); |
| 921 } else { |
| 922 cached_cc_layer_opacity_ = cc_layer_->opacity(); |
| 923 cc_layer_->SetOpacity(0.f); |
| 924 } |
916 } | 925 } |
917 | 926 |
918 void Layer::SetBrightnessFromAnimation(float brightness) { | 927 void Layer::SetBrightnessFromAnimation(float brightness) { |
919 layer_brightness_ = brightness; | 928 layer_brightness_ = brightness; |
920 SetLayerFilters(); | 929 SetLayerFilters(); |
921 } | 930 } |
922 | 931 |
923 void Layer::SetGrayscaleFromAnimation(float grayscale) { | 932 void Layer::SetGrayscaleFromAnimation(float grayscale) { |
924 layer_grayscale_ = grayscale; | 933 layer_grayscale_ = grayscale; |
925 SetLayerFilters(); | 934 SetLayerFilters(); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 animator_->ResetCompositor(compositor); | 1107 animator_->ResetCompositor(compositor); |
1099 if (animator_->is_animating()) | 1108 if (animator_->is_animating()) |
1100 animator_->RemoveFromCollection(collection); | 1109 animator_->RemoveFromCollection(collection); |
1101 } | 1110 } |
1102 | 1111 |
1103 for (auto* child : children_) | 1112 for (auto* child : children_) |
1104 child->ResetCompositorForAnimatorsInTree(compositor); | 1113 child->ResetCompositorForAnimatorsInTree(compositor); |
1105 } | 1114 } |
1106 | 1115 |
1107 } // namespace ui | 1116 } // namespace ui |
OLD | NEW |