| 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 <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 compositor_(NULL), | 90 compositor_(NULL), |
| 91 parent_(NULL), | 91 parent_(NULL), |
| 92 visible_(true), | 92 visible_(true), |
| 93 fills_bounds_opaquely_(true), | 93 fills_bounds_opaquely_(true), |
| 94 fills_bounds_completely_(false), | 94 fills_bounds_completely_(false), |
| 95 background_blur_radius_(0), | 95 background_blur_radius_(0), |
| 96 layer_saturation_(0.0f), | 96 layer_saturation_(0.0f), |
| 97 layer_brightness_(0.0f), | 97 layer_brightness_(0.0f), |
| 98 layer_grayscale_(0.0f), | 98 layer_grayscale_(0.0f), |
| 99 layer_inverted_(false), | 99 layer_inverted_(false), |
| 100 layer_temperature_(0.0f), |
| 101 layer_blue_scale_(1.0f), |
| 102 layer_green_scale_(1.0f), |
| 100 layer_mask_(NULL), | 103 layer_mask_(NULL), |
| 101 layer_mask_back_link_(NULL), | 104 layer_mask_back_link_(NULL), |
| 102 zoom_(1), | 105 zoom_(1), |
| 103 zoom_inset_(0), | 106 zoom_inset_(0), |
| 104 delegate_(NULL), | 107 delegate_(NULL), |
| 105 owner_(NULL), | 108 owner_(NULL), |
| 106 cc_layer_(NULL), | 109 cc_layer_(NULL), |
| 107 device_scale_factor_(1.0f) { | 110 device_scale_factor_(1.0f) { |
| 108 CreateCcLayer(); | 111 CreateCcLayer(); |
| 109 } | 112 } |
| 110 | 113 |
| 111 Layer::Layer(LayerType type) | 114 Layer::Layer(LayerType type) |
| 112 : type_(type), | 115 : type_(type), |
| 113 compositor_(NULL), | 116 compositor_(NULL), |
| 114 parent_(NULL), | 117 parent_(NULL), |
| 115 visible_(true), | 118 visible_(true), |
| 116 fills_bounds_opaquely_(true), | 119 fills_bounds_opaquely_(true), |
| 117 fills_bounds_completely_(false), | 120 fills_bounds_completely_(false), |
| 118 background_blur_radius_(0), | 121 background_blur_radius_(0), |
| 119 layer_saturation_(0.0f), | 122 layer_saturation_(0.0f), |
| 120 layer_brightness_(0.0f), | 123 layer_brightness_(0.0f), |
| 121 layer_grayscale_(0.0f), | 124 layer_grayscale_(0.0f), |
| 122 layer_inverted_(false), | 125 layer_inverted_(false), |
| 126 layer_temperature_(0.0f), |
| 127 layer_blue_scale_(1.0f), |
| 128 layer_green_scale_(1.0f), |
| 123 layer_mask_(NULL), | 129 layer_mask_(NULL), |
| 124 layer_mask_back_link_(NULL), | 130 layer_mask_back_link_(NULL), |
| 125 zoom_(1), | 131 zoom_(1), |
| 126 zoom_inset_(0), | 132 zoom_inset_(0), |
| 127 delegate_(NULL), | 133 delegate_(NULL), |
| 128 owner_(NULL), | 134 owner_(NULL), |
| 129 cc_layer_(NULL), | 135 cc_layer_(NULL), |
| 130 device_scale_factor_(1.0f) { | 136 device_scale_factor_(1.0f) { |
| 131 CreateCcLayer(); | 137 CreateCcLayer(); |
| 132 } | 138 } |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 float Layer::GetCombinedOpacity() const { | 371 float Layer::GetCombinedOpacity() const { |
| 366 float opacity = this->opacity(); | 372 float opacity = this->opacity(); |
| 367 Layer* current = this->parent_; | 373 Layer* current = this->parent_; |
| 368 while (current) { | 374 while (current) { |
| 369 opacity *= current->opacity(); | 375 opacity *= current->opacity(); |
| 370 current = current->parent_; | 376 current = current->parent_; |
| 371 } | 377 } |
| 372 return opacity; | 378 return opacity; |
| 373 } | 379 } |
| 374 | 380 |
| 381 void Layer::SetLayerTemperature(float value) { |
| 382 GetAnimator()->SetTemperature(value); |
| 383 } |
| 384 |
| 375 void Layer::SetBackgroundBlur(int blur_radius) { | 385 void Layer::SetBackgroundBlur(int blur_radius) { |
| 376 background_blur_radius_ = blur_radius; | 386 background_blur_radius_ = blur_radius; |
| 377 | 387 |
| 378 SetLayerBackgroundFilters(); | 388 SetLayerBackgroundFilters(); |
| 379 } | 389 } |
| 380 | 390 |
| 381 void Layer::SetLayerSaturation(float saturation) { | 391 void Layer::SetLayerSaturation(float saturation) { |
| 382 layer_saturation_ = saturation; | 392 layer_saturation_ = saturation; |
| 383 SetLayerFilters(); | 393 SetLayerFilters(); |
| 384 } | 394 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 void Layer::SetLayerFilters() { | 461 void Layer::SetLayerFilters() { |
| 452 cc::FilterOperations filters; | 462 cc::FilterOperations filters; |
| 453 if (layer_saturation_) { | 463 if (layer_saturation_) { |
| 454 filters.Append(cc::FilterOperation::CreateSaturateFilter( | 464 filters.Append(cc::FilterOperation::CreateSaturateFilter( |
| 455 layer_saturation_)); | 465 layer_saturation_)); |
| 456 } | 466 } |
| 457 if (layer_grayscale_) { | 467 if (layer_grayscale_) { |
| 458 filters.Append(cc::FilterOperation::CreateGrayscaleFilter( | 468 filters.Append(cc::FilterOperation::CreateGrayscaleFilter( |
| 459 layer_grayscale_)); | 469 layer_grayscale_)); |
| 460 } | 470 } |
| 471 if (layer_temperature_) { |
| 472 float color_matrix[] = { |
| 473 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, |
| 474 0.0f, layer_green_scale_, 0.0f, 0.0f, 0.0f, |
| 475 0.0f, 0.0f, layer_blue_scale_, 0.0f, 0.0f, |
| 476 0.0f, 0.0f, 0.0f, 1.0f, 0.0f |
| 477 }; |
| 478 filters.Append(cc::FilterOperation::CreateColorMatrixFilter(color_matrix)); |
| 479 } |
| 461 if (layer_inverted_) | 480 if (layer_inverted_) |
| 462 filters.Append(cc::FilterOperation::CreateInvertFilter(1.0)); | 481 filters.Append(cc::FilterOperation::CreateInvertFilter(1.0)); |
| 463 // Brightness goes last, because the resulting colors neeed clamping, which | 482 // Brightness goes last, because the resulting colors neeed clamping, which |
| 464 // cause further color matrix filters to be applied separately. In this order, | 483 // cause further color matrix filters to be applied separately. In this order, |
| 465 // they all can be combined in a single pass. | 484 // they all can be combined in a single pass. |
| 466 if (layer_brightness_) { | 485 if (layer_brightness_) { |
| 467 filters.Append(cc::FilterOperation::CreateSaturatingBrightnessFilter( | 486 filters.Append(cc::FilterOperation::CreateSaturatingBrightnessFilter( |
| 468 layer_brightness_)); | 487 layer_brightness_)); |
| 469 } | 488 } |
| 470 if (alpha_shape_) { | 489 if (alpha_shape_) { |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 layer_grayscale_ = grayscale; | 1066 layer_grayscale_ = grayscale; |
| 1048 SetLayerFilters(); | 1067 SetLayerFilters(); |
| 1049 } | 1068 } |
| 1050 | 1069 |
| 1051 void Layer::SetColorFromAnimation(SkColor color) { | 1070 void Layer::SetColorFromAnimation(SkColor color) { |
| 1052 DCHECK_EQ(type_, LAYER_SOLID_COLOR); | 1071 DCHECK_EQ(type_, LAYER_SOLID_COLOR); |
| 1053 cc_layer_->SetBackgroundColor(color); | 1072 cc_layer_->SetBackgroundColor(color); |
| 1054 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); | 1073 SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); |
| 1055 } | 1074 } |
| 1056 | 1075 |
| 1076 void Layer::SetTemperatureFromAnimation(float temperature) { |
| 1077 layer_temperature_ = temperature; |
| 1078 |
| 1079 // If we only tone down the blue scale, the screen will look very green so we |
| 1080 // also need to tone down the green, but with a less value compared to the |
| 1081 // blue scale to avoid making things look very red. |
| 1082 layer_blue_scale_ = 1.0f - temperature; |
| 1083 layer_green_scale_ = 1.0f - 0.3f * temperature; |
| 1084 SetLayerFilters(); |
| 1085 } |
| 1086 |
| 1057 void Layer::ScheduleDrawForAnimation() { | 1087 void Layer::ScheduleDrawForAnimation() { |
| 1058 ScheduleDraw(); | 1088 ScheduleDraw(); |
| 1059 } | 1089 } |
| 1060 | 1090 |
| 1061 const gfx::Rect& Layer::GetBoundsForAnimation() const { | 1091 const gfx::Rect& Layer::GetBoundsForAnimation() const { |
| 1062 return bounds(); | 1092 return bounds(); |
| 1063 } | 1093 } |
| 1064 | 1094 |
| 1065 gfx::Transform Layer::GetTransformForAnimation() const { | 1095 gfx::Transform Layer::GetTransformForAnimation() const { |
| 1066 return transform(); | 1096 return transform(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1083 } | 1113 } |
| 1084 | 1114 |
| 1085 SkColor Layer::GetColorForAnimation() const { | 1115 SkColor Layer::GetColorForAnimation() const { |
| 1086 // WebColor is equivalent to SkColor, per WebColor.h. | 1116 // WebColor is equivalent to SkColor, per WebColor.h. |
| 1087 // The NULL check is here since this is invoked regardless of whether we have | 1117 // The NULL check is here since this is invoked regardless of whether we have |
| 1088 // been configured as LAYER_SOLID_COLOR. | 1118 // been configured as LAYER_SOLID_COLOR. |
| 1089 return solid_color_layer_.get() ? | 1119 return solid_color_layer_.get() ? |
| 1090 solid_color_layer_->background_color() : SK_ColorBLACK; | 1120 solid_color_layer_->background_color() : SK_ColorBLACK; |
| 1091 } | 1121 } |
| 1092 | 1122 |
| 1123 float Layer::GetTemperatureFromAnimation() const { |
| 1124 return layer_temperature_; |
| 1125 } |
| 1126 |
| 1093 float Layer::GetDeviceScaleFactor() const { | 1127 float Layer::GetDeviceScaleFactor() const { |
| 1094 return device_scale_factor_; | 1128 return device_scale_factor_; |
| 1095 } | 1129 } |
| 1096 | 1130 |
| 1097 LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() { | 1131 LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() { |
| 1098 Compositor* compositor = GetCompositor(); | 1132 Compositor* compositor = GetCompositor(); |
| 1099 return compositor ? compositor->layer_animator_collection() : NULL; | 1133 return compositor ? compositor->layer_animator_collection() : NULL; |
| 1100 } | 1134 } |
| 1101 | 1135 |
| 1102 int Layer::GetFrameNumber() const { | 1136 int Layer::GetFrameNumber() const { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 const auto it = std::find_if(mirrors_.begin(), mirrors_.end(), | 1227 const auto it = std::find_if(mirrors_.begin(), mirrors_.end(), |
| 1194 [mirror](const std::unique_ptr<LayerMirror>& mirror_ptr) { | 1228 [mirror](const std::unique_ptr<LayerMirror>& mirror_ptr) { |
| 1195 return mirror_ptr.get() == mirror; | 1229 return mirror_ptr.get() == mirror; |
| 1196 }); | 1230 }); |
| 1197 | 1231 |
| 1198 DCHECK(it != mirrors_.end()); | 1232 DCHECK(it != mirrors_.end()); |
| 1199 mirrors_.erase(it); | 1233 mirrors_.erase(it); |
| 1200 } | 1234 } |
| 1201 | 1235 |
| 1202 } // namespace ui | 1236 } // namespace ui |
| OLD | NEW |