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