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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 fills_bounds_opaquely_(true), | 56 fills_bounds_opaquely_(true), |
57 layer_updated_externally_(false), | 57 layer_updated_externally_(false), |
58 opacity_(1.0f), | 58 opacity_(1.0f), |
59 background_blur_radius_(0), | 59 background_blur_radius_(0), |
60 layer_saturation_(0.0f), | 60 layer_saturation_(0.0f), |
61 layer_brightness_(0.0f), | 61 layer_brightness_(0.0f), |
62 layer_grayscale_(0.0f), | 62 layer_grayscale_(0.0f), |
63 layer_inverted_(false), | 63 layer_inverted_(false), |
64 layer_mask_(NULL), | 64 layer_mask_(NULL), |
65 layer_mask_back_link_(NULL), | 65 layer_mask_back_link_(NULL), |
| 66 zoom_x_offset_(0), |
| 67 zoom_y_offset_(0), |
| 68 zoom_(1), |
| 69 zoom_inset_(0), |
66 delegate_(NULL), | 70 delegate_(NULL), |
67 web_layer_(NULL), | 71 web_layer_(NULL), |
68 scale_content_(true), | 72 scale_content_(true), |
69 device_scale_factor_(1.0f) { | 73 device_scale_factor_(1.0f) { |
70 CreateWebLayer(); | 74 CreateWebLayer(); |
71 } | 75 } |
72 | 76 |
73 Layer::Layer(LayerType type) | 77 Layer::Layer(LayerType type) |
74 : type_(type), | 78 : type_(type), |
75 compositor_(NULL), | 79 compositor_(NULL), |
76 parent_(NULL), | 80 parent_(NULL), |
77 visible_(true), | 81 visible_(true), |
78 force_render_surface_(false), | 82 force_render_surface_(false), |
79 fills_bounds_opaquely_(true), | 83 fills_bounds_opaquely_(true), |
80 layer_updated_externally_(false), | 84 layer_updated_externally_(false), |
81 opacity_(1.0f), | 85 opacity_(1.0f), |
82 background_blur_radius_(0), | 86 background_blur_radius_(0), |
83 layer_saturation_(0.0f), | 87 layer_saturation_(0.0f), |
84 layer_brightness_(0.0f), | 88 layer_brightness_(0.0f), |
85 layer_grayscale_(0.0f), | 89 layer_grayscale_(0.0f), |
86 layer_inverted_(false), | 90 layer_inverted_(false), |
87 layer_mask_(NULL), | 91 layer_mask_(NULL), |
88 layer_mask_back_link_(NULL), | 92 layer_mask_back_link_(NULL), |
| 93 zoom_x_offset_(0), |
| 94 zoom_y_offset_(0), |
| 95 zoom_(1), |
| 96 zoom_inset_(0), |
89 delegate_(NULL), | 97 delegate_(NULL), |
90 scale_content_(true), | 98 scale_content_(true), |
91 device_scale_factor_(1.0f) { | 99 device_scale_factor_(1.0f) { |
92 CreateWebLayer(); | 100 CreateWebLayer(); |
93 } | 101 } |
94 | 102 |
95 Layer::~Layer() { | 103 Layer::~Layer() { |
96 // Destroying the animator may cause observers to use the layer (and | 104 // Destroying the animator may cause observers to use the layer (and |
97 // indirectly the WebLayer). Destroy the animator first so that the WebLayer | 105 // indirectly the WebLayer). Destroy the animator first so that the WebLayer |
98 // is still around. | 106 // is still around. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 while (current) { | 236 while (current) { |
229 opacity *= current->opacity_; | 237 opacity *= current->opacity_; |
230 current = current->parent_; | 238 current = current->parent_; |
231 } | 239 } |
232 return opacity; | 240 return opacity; |
233 } | 241 } |
234 | 242 |
235 void Layer::SetBackgroundBlur(int blur_radius) { | 243 void Layer::SetBackgroundBlur(int blur_radius) { |
236 background_blur_radius_ = blur_radius; | 244 background_blur_radius_ = blur_radius; |
237 | 245 |
238 WebKit::WebFilterOperations filters; | 246 SetLayerBackgroundFilters(); |
239 if (background_blur_radius_) { | |
240 filters.append(WebKit::WebFilterOperation::createBlurFilter( | |
241 background_blur_radius_)); | |
242 } | |
243 web_layer_->setBackgroundFilters(filters); | |
244 } | 247 } |
245 | 248 |
246 void Layer::SetLayerSaturation(float saturation) { | 249 void Layer::SetLayerSaturation(float saturation) { |
247 layer_saturation_ = saturation; | 250 layer_saturation_ = saturation; |
248 SetLayerFilters(); | 251 SetLayerFilters(); |
249 } | 252 } |
250 | 253 |
251 void Layer::SetLayerBrightness(float brightness) { | 254 void Layer::SetLayerBrightness(float brightness) { |
252 GetAnimator()->SetBrightness(brightness); | 255 GetAnimator()->SetBrightness(brightness); |
253 } | 256 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 layer_mask_->layer_mask_back_link_ = NULL; | 295 layer_mask_->layer_mask_back_link_ = NULL; |
293 layer_mask_ = layer_mask; | 296 layer_mask_ = layer_mask; |
294 web_layer_->setMaskLayer( | 297 web_layer_->setMaskLayer( |
295 layer_mask ? layer_mask->web_layer() : NULL); | 298 layer_mask ? layer_mask->web_layer() : NULL); |
296 // We need to reference the linked object so that it can properly break the | 299 // We need to reference the linked object so that it can properly break the |
297 // link to us when it gets deleted. | 300 // link to us when it gets deleted. |
298 if (layer_mask) | 301 if (layer_mask) |
299 layer_mask->layer_mask_back_link_ = this; | 302 layer_mask->layer_mask_back_link_ = this; |
300 } | 303 } |
301 | 304 |
| 305 void Layer::SetBackgroundZoom(float x_offset, |
| 306 float y_offset, |
| 307 float zoom, |
| 308 int inset) { |
| 309 zoom_x_offset_ = x_offset; |
| 310 zoom_y_offset_ = y_offset; |
| 311 zoom_ = zoom; |
| 312 zoom_inset_ = inset; |
| 313 |
| 314 SetLayerBackgroundFilters(); |
| 315 } |
| 316 |
302 void Layer::SetLayerFilters() { | 317 void Layer::SetLayerFilters() { |
303 WebKit::WebFilterOperations filters; | 318 WebKit::WebFilterOperations filters; |
304 if (layer_saturation_) { | 319 if (layer_saturation_) { |
305 filters.append(WebKit::WebFilterOperation::createSaturateFilter( | 320 filters.append(WebKit::WebFilterOperation::createSaturateFilter( |
306 layer_saturation_)); | 321 layer_saturation_)); |
307 } | 322 } |
308 if (layer_grayscale_) { | 323 if (layer_grayscale_) { |
309 filters.append(WebKit::WebFilterOperation::createGrayscaleFilter( | 324 filters.append(WebKit::WebFilterOperation::createGrayscaleFilter( |
310 layer_grayscale_)); | 325 layer_grayscale_)); |
311 } | 326 } |
312 if (layer_inverted_) | 327 if (layer_inverted_) |
313 filters.append(WebKit::WebFilterOperation::createInvertFilter(1.0)); | 328 filters.append(WebKit::WebFilterOperation::createInvertFilter(1.0)); |
314 // Brightness goes last, because the resulting colors neeed clamping, which | 329 // Brightness goes last, because the resulting colors neeed clamping, which |
315 // cause further color matrix filters to be applied separately. In this order, | 330 // cause further color matrix filters to be applied separately. In this order, |
316 // they all can be combined in a single pass. | 331 // they all can be combined in a single pass. |
317 if (layer_brightness_) { | 332 if (layer_brightness_) { |
318 filters.append(WebKit::WebFilterOperation::createBrightnessFilter( | 333 filters.append(WebKit::WebFilterOperation::createBrightnessFilter( |
319 layer_brightness_)); | 334 layer_brightness_)); |
320 } | 335 } |
321 | 336 |
322 web_layer_->setFilters(filters); | 337 web_layer_->setFilters(filters); |
323 } | 338 } |
324 | 339 |
| 340 void Layer::SetLayerBackgroundFilters() { |
| 341 WebKit::WebFilterOperations filters; |
| 342 if (zoom_ != 1) { |
| 343 filters.append(WebKit::WebFilterOperation::createZoomFilter( |
| 344 WebKit::WebRect(zoom_x_offset_, zoom_y_offset_, |
| 345 (GetTargetBounds().width() / zoom_), |
| 346 (GetTargetBounds().height() / zoom_)), |
| 347 zoom_inset_)); |
| 348 } |
| 349 |
| 350 if (background_blur_radius_) { |
| 351 filters.append(WebKit::WebFilterOperation::createBlurFilter( |
| 352 background_blur_radius_)); |
| 353 } |
| 354 |
| 355 web_layer_->setBackgroundFilters(filters); |
| 356 } |
| 357 |
325 float Layer::GetTargetOpacity() const { | 358 float Layer::GetTargetOpacity() const { |
326 if (animator_.get() && animator_->IsAnimatingProperty( | 359 if (animator_.get() && animator_->IsAnimatingProperty( |
327 LayerAnimationElement::OPACITY)) | 360 LayerAnimationElement::OPACITY)) |
328 return animator_->GetTargetOpacity(); | 361 return animator_->GetTargetOpacity(); |
329 return opacity_; | 362 return opacity_; |
330 } | 363 } |
331 | 364 |
332 void Layer::SetVisible(bool visible) { | 365 void Layer::SetVisible(bool visible) { |
333 GetAnimator()->SetVisibility(visible); | 366 GetAnimator()->SetVisibility(visible); |
334 } | 367 } |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 return; | 823 return; |
791 unsigned int color = 0xFF000000; | 824 unsigned int color = 0xFF000000; |
792 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; | 825 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; |
793 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); | 826 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); |
794 if (!opaque) | 827 if (!opaque) |
795 color |= 0xFF; | 828 color |= 0xFF; |
796 web_layer_->setDebugBorderColor(color); | 829 web_layer_->setDebugBorderColor(color); |
797 } | 830 } |
798 | 831 |
799 } // namespace ui | 832 } // namespace ui |
OLD | NEW |