Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "cc/base/math_util.h" | 8 #include "cc/base/math_util.h" |
| 9 #include "cc/output/filter_operation.h" | 9 #include "cc/output/filter_operation.h" |
| 10 #include "third_party/skia/include/core/SkMath.h" | 10 #include "third_party/skia/include/core/SkMath.h" |
| 11 | 11 |
| 12 namespace cc { | 12 namespace cc { |
| 13 | 13 |
| 14 bool FilterOperation::operator==(const FilterOperation& other) const { | 14 bool FilterOperation::operator==(const FilterOperation& other) const { |
| 15 if (type_ != other.type_) | 15 if (type_ != other.type_) |
| 16 return false; | 16 return false; |
| 17 if (type_ == COLOR_MATRIX) | 17 if (type_ == COLOR_MATRIX) |
| 18 return !memcmp(matrix_, other.matrix_, sizeof(matrix_)); | 18 return !memcmp(matrix_, other.matrix_, sizeof(matrix_)); |
| 19 if (type_ == DROP_SHADOW) { | 19 if (type_ == DROP_SHADOW) { |
| 20 return amount_ == other.amount_ && | 20 return amount_ == other.amount_ && |
| 21 drop_shadow_offset_ == other.drop_shadow_offset_ && | 21 drop_shadow_offset_ == other.drop_shadow_offset_ && |
| 22 drop_shadow_color_ == other.drop_shadow_color_; | 22 drop_shadow_color_ == other.drop_shadow_color_; |
| 23 } | 23 } |
| 24 if (type_ == REFERENCE) | |
| 25 return image_filter_.get() == other.image_filter_.get(); | |
| 24 return amount_ == other.amount_; | 26 return amount_ == other.amount_; |
| 25 } | 27 } |
| 26 | 28 |
| 27 FilterOperation::FilterOperation(FilterType type, float amount) | 29 FilterOperation::FilterOperation(FilterType type, float amount) |
| 28 : type_(type), | 30 : type_(type), |
| 29 amount_(amount), | 31 amount_(amount), |
| 30 drop_shadow_offset_(0, 0), | 32 drop_shadow_offset_(0, 0), |
| 31 drop_shadow_color_(0), | 33 drop_shadow_color_(0), |
| 32 zoom_inset_(0) { | 34 zoom_inset_(0) { |
| 33 DCHECK_NE(type_, DROP_SHADOW); | 35 DCHECK_NE(type_, DROP_SHADOW); |
| 34 DCHECK_NE(type_, COLOR_MATRIX); | 36 DCHECK_NE(type_, COLOR_MATRIX); |
| 37 DCHECK_NE(type_, REFERENCE); | |
| 35 memset(matrix_, 0, sizeof(matrix_)); | 38 memset(matrix_, 0, sizeof(matrix_)); |
| 36 } | 39 } |
| 37 | 40 |
| 38 FilterOperation::FilterOperation(FilterType type, | 41 FilterOperation::FilterOperation(FilterType type, |
| 39 gfx::Point offset, | 42 gfx::Point offset, |
| 40 float stdDeviation, | 43 float stdDeviation, |
| 41 SkColor color) | 44 SkColor color) |
| 42 : type_(type), | 45 : type_(type), |
| 43 amount_(stdDeviation), | 46 amount_(stdDeviation), |
| 44 drop_shadow_offset_(offset), | 47 drop_shadow_offset_(offset), |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 61 FilterOperation::FilterOperation(FilterType type, float amount, int inset) | 64 FilterOperation::FilterOperation(FilterType type, float amount, int inset) |
| 62 : type_(type), | 65 : type_(type), |
| 63 amount_(amount), | 66 amount_(amount), |
| 64 drop_shadow_offset_(0, 0), | 67 drop_shadow_offset_(0, 0), |
| 65 drop_shadow_color_(0), | 68 drop_shadow_color_(0), |
| 66 zoom_inset_(inset) { | 69 zoom_inset_(inset) { |
| 67 DCHECK_EQ(type_, ZOOM); | 70 DCHECK_EQ(type_, ZOOM); |
| 68 memset(matrix_, 0, sizeof(matrix_)); | 71 memset(matrix_, 0, sizeof(matrix_)); |
| 69 } | 72 } |
| 70 | 73 |
| 74 FilterOperation::FilterOperation( | |
| 75 FilterType type, | |
| 76 const skia::RefPtr<SkImageFilter>& image_filter) | |
| 77 : type_(type), | |
| 78 amount_(0), | |
| 79 drop_shadow_offset_(0, 0), | |
| 80 drop_shadow_color_(0), | |
| 81 image_filter_(image_filter), | |
| 82 zoom_inset_(0) { | |
| 83 DCHECK_EQ(type_, REFERENCE); | |
| 84 DCHECK(image_filter.get()); | |
| 85 memset(matrix_, 0, sizeof(matrix_)); | |
| 86 } | |
| 87 | |
| 88 FilterOperation::FilterOperation(const FilterOperation& other) | |
| 89 : type_(other.type_), | |
| 90 amount_(other.amount_), | |
| 91 drop_shadow_offset_(other.drop_shadow_offset_), | |
| 92 drop_shadow_color_(other.drop_shadow_color_), | |
| 93 image_filter_(other.image_filter_), | |
| 94 zoom_inset_(other.zoom_inset_) { | |
| 95 memcpy(matrix_, other.matrix_, sizeof(matrix_)); | |
| 96 } | |
| 97 | |
| 98 FilterOperation::~FilterOperation() { | |
| 99 } | |
| 100 | |
| 71 // TODO(ajuma): Define a version of ui::Tween::ValueBetween for floats, and use | 101 // TODO(ajuma): Define a version of ui::Tween::ValueBetween for floats, and use |
| 72 // that instead. | 102 // that instead. |
| 73 static float BlendFloats(float from, float to, double progress) { | 103 static float BlendFloats(float from, float to, double progress) { |
| 74 return from * (1.0 - progress) + to * progress; | 104 return from * (1.0 - progress) + to * progress; |
| 75 } | 105 } |
| 76 | 106 |
| 77 static int BlendInts(int from, int to, double progress) { | 107 static int BlendInts(int from, int to, double progress) { |
| 78 return static_cast<int>( | 108 return static_cast<int>( |
| 79 MathUtil::Round(from * (1.0 - progress) + to * progress)); | 109 MathUtil::Round(from * (1.0 - progress) + to * progress)); |
| 80 } | 110 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 case FilterOperation::COLOR_MATRIX: { | 170 case FilterOperation::COLOR_MATRIX: { |
| 141 SkScalar matrix[20]; | 171 SkScalar matrix[20]; |
| 142 memset(matrix, 0, 20 * sizeof(SkScalar)); | 172 memset(matrix, 0, 20 * sizeof(SkScalar)); |
| 143 matrix[0] = matrix[6] = matrix[12] = matrix[18] = 1.f; | 173 matrix[0] = matrix[6] = matrix[12] = matrix[18] = 1.f; |
| 144 return FilterOperation::CreateColorMatrixFilter(matrix); | 174 return FilterOperation::CreateColorMatrixFilter(matrix); |
| 145 } | 175 } |
| 146 case FilterOperation::ZOOM: | 176 case FilterOperation::ZOOM: |
| 147 return FilterOperation::CreateZoomFilter(1.f, 0); | 177 return FilterOperation::CreateZoomFilter(1.f, 0); |
| 148 case FilterOperation::SATURATING_BRIGHTNESS: | 178 case FilterOperation::SATURATING_BRIGHTNESS: |
| 149 return FilterOperation::CreateSaturatingBrightnessFilter(0.f); | 179 return FilterOperation::CreateSaturatingBrightnessFilter(0.f); |
| 180 case FilterOperation::REFERENCE: | |
| 181 NOTREACHED(); | |
|
danakj
2013/09/09 22:04:50
Can't create an image filter that does nothing?
ajuma
2013/09/10 21:17:58
Done.
| |
| 182 return FilterOperation::CreateEmptyFilter(); | |
| 150 } | 183 } |
| 151 NOTREACHED(); | 184 NOTREACHED(); |
| 152 return FilterOperation::CreateEmptyFilter(); | 185 return FilterOperation::CreateEmptyFilter(); |
| 153 } | 186 } |
| 154 | 187 |
| 155 static float ClampAmountForFilterType(float amount, | 188 static float ClampAmountForFilterType(float amount, |
| 156 FilterOperation::FilterType type) { | 189 FilterOperation::FilterType type) { |
| 157 switch (type) { | 190 switch (type) { |
| 158 case FilterOperation::GRAYSCALE: | 191 case FilterOperation::GRAYSCALE: |
| 159 case FilterOperation::SEPIA: | 192 case FilterOperation::SEPIA: |
| 160 case FilterOperation::INVERT: | 193 case FilterOperation::INVERT: |
| 161 case FilterOperation::OPACITY: | 194 case FilterOperation::OPACITY: |
| 162 return MathUtil::ClampToRange(amount, 0.f, 1.f); | 195 return MathUtil::ClampToRange(amount, 0.f, 1.f); |
| 163 case FilterOperation::SATURATE: | 196 case FilterOperation::SATURATE: |
| 164 case FilterOperation::BRIGHTNESS: | 197 case FilterOperation::BRIGHTNESS: |
| 165 case FilterOperation::CONTRAST: | 198 case FilterOperation::CONTRAST: |
| 166 case FilterOperation::BLUR: | 199 case FilterOperation::BLUR: |
| 167 case FilterOperation::DROP_SHADOW: | 200 case FilterOperation::DROP_SHADOW: |
| 168 return std::max(amount, 0.f); | 201 return std::max(amount, 0.f); |
| 169 case FilterOperation::ZOOM: | 202 case FilterOperation::ZOOM: |
| 170 return std::max(amount, 1.f); | 203 return std::max(amount, 1.f); |
| 171 case FilterOperation::HUE_ROTATE: | 204 case FilterOperation::HUE_ROTATE: |
| 172 case FilterOperation::SATURATING_BRIGHTNESS: | 205 case FilterOperation::SATURATING_BRIGHTNESS: |
| 173 return amount; | 206 return amount; |
| 174 case FilterOperation::COLOR_MATRIX: | 207 case FilterOperation::COLOR_MATRIX: |
| 208 case FilterOperation::REFERENCE: | |
| 175 NOTREACHED(); | 209 NOTREACHED(); |
| 176 return amount; | 210 return amount; |
| 177 } | 211 } |
| 178 NOTREACHED(); | 212 NOTREACHED(); |
| 179 return amount; | 213 return amount; |
| 180 } | 214 } |
| 181 | 215 |
| 182 // static | 216 // static |
| 183 FilterOperation FilterOperation::Blend(const FilterOperation* from, | 217 FilterOperation FilterOperation::Blend(const FilterOperation* from, |
| 184 const FilterOperation* to, | 218 const FilterOperation* to, |
| 185 double progress) { | 219 double progress) { |
| 186 FilterOperation blended_filter = FilterOperation::CreateEmptyFilter(); | 220 FilterOperation blended_filter = FilterOperation::CreateEmptyFilter(); |
| 187 | 221 |
| 188 if (!from && !to) | 222 if (!from && !to) |
| 189 return blended_filter; | 223 return blended_filter; |
| 190 | 224 |
| 225 if ((from && from->type() == FilterOperation::REFERENCE) || | |
|
danakj
2013/09/09 22:04:50
If the two types differ, you might get the |to| or
ajuma
2013/09/10 21:17:58
Done.
| |
| 226 (to && to->type() == FilterOperation::REFERENCE)) { | |
| 227 if (progress > 0.5) | |
| 228 return to ? *to : blended_filter; | |
| 229 else | |
| 230 return from ? *from : blended_filter; | |
| 231 } | |
| 232 | |
| 191 const FilterOperation& from_op = from ? *from : CreateNoOpFilter(to->type()); | 233 const FilterOperation& from_op = from ? *from : CreateNoOpFilter(to->type()); |
| 192 const FilterOperation& to_op = to ? *to : CreateNoOpFilter(from->type()); | 234 const FilterOperation& to_op = to ? *to : CreateNoOpFilter(from->type()); |
| 193 | 235 |
| 194 if (from_op.type() != to_op.type()) | 236 if (from_op.type() != to_op.type()) |
| 195 return blended_filter; | 237 return blended_filter; |
| 196 | 238 |
| 197 DCHECK(to_op.type() != FilterOperation::COLOR_MATRIX); | 239 DCHECK(to_op.type() != FilterOperation::COLOR_MATRIX); |
| 198 blended_filter.set_type(to_op.type()); | 240 blended_filter.set_type(to_op.type()); |
| 199 | 241 |
| 200 blended_filter.set_amount(ClampAmountForFilterType( | 242 blended_filter.set_amount(ClampAmountForFilterType( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 scoped_ptr<ListValue> matrix(new ListValue); | 285 scoped_ptr<ListValue> matrix(new ListValue); |
| 244 for (size_t i = 0; i < arraysize(matrix_); ++i) | 286 for (size_t i = 0; i < arraysize(matrix_); ++i) |
| 245 matrix->AppendDouble(matrix_[i]); | 287 matrix->AppendDouble(matrix_[i]); |
| 246 value->Set("matrix", matrix.release()); | 288 value->Set("matrix", matrix.release()); |
| 247 break; | 289 break; |
| 248 } | 290 } |
| 249 case FilterOperation::ZOOM: | 291 case FilterOperation::ZOOM: |
| 250 value->SetDouble("amount", amount_); | 292 value->SetDouble("amount", amount_); |
| 251 value->SetDouble("inset", zoom_inset_); | 293 value->SetDouble("inset", zoom_inset_); |
| 252 break; | 294 break; |
| 295 case FilterOperation::REFERENCE: | |
| 296 break; | |
|
danakj
2013/09/09 22:04:50
Is there any data about the filter you can give he
ajuma
2013/09/10 21:17:58
Done.
| |
| 253 } | 297 } |
| 254 return value.PassAs<base::Value>(); | 298 return value.PassAs<base::Value>(); |
| 255 } | 299 } |
| 256 | 300 |
| 257 } // namespace cc | 301 } // namespace cc |
| OLD | NEW |