Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(627)

Side by Side Diff: cc/output/filter_operation.cc

Issue 21154002: Add support for converting cc::FilterOperations into an SkImageFilter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/output/filter_operation.h ('k') | cc/output/filter_operations.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 memset(matrix_, 0, sizeof(matrix_));
85 }
86
87 FilterOperation::FilterOperation(const FilterOperation& other)
88 : type_(other.type_),
89 amount_(other.amount_),
90 drop_shadow_offset_(other.drop_shadow_offset_),
91 drop_shadow_color_(other.drop_shadow_color_),
92 image_filter_(other.image_filter_),
93 zoom_inset_(other.zoom_inset_) {
94 memcpy(matrix_, other.matrix_, sizeof(matrix_));
95 }
96
97 FilterOperation::~FilterOperation() {
98 }
99
71 // TODO(ajuma): Define a version of gfx::Tween::ValueBetween for floats, and use 100 // TODO(ajuma): Define a version of gfx::Tween::ValueBetween for floats, and use
72 // that instead. 101 // that instead.
73 static float BlendFloats(float from, float to, double progress) { 102 static float BlendFloats(float from, float to, double progress) {
74 return from * (1.0 - progress) + to * progress; 103 return from * (1.0 - progress) + to * progress;
75 } 104 }
76 105
77 static int BlendInts(int from, int to, double progress) { 106 static int BlendInts(int from, int to, double progress) {
78 return static_cast<int>( 107 return static_cast<int>(
79 MathUtil::Round(from * (1.0 - progress) + to * progress)); 108 MathUtil::Round(from * (1.0 - progress) + to * progress));
80 } 109 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 case FilterOperation::COLOR_MATRIX: { 169 case FilterOperation::COLOR_MATRIX: {
141 SkScalar matrix[20]; 170 SkScalar matrix[20];
142 memset(matrix, 0, 20 * sizeof(SkScalar)); 171 memset(matrix, 0, 20 * sizeof(SkScalar));
143 matrix[0] = matrix[6] = matrix[12] = matrix[18] = 1.f; 172 matrix[0] = matrix[6] = matrix[12] = matrix[18] = 1.f;
144 return FilterOperation::CreateColorMatrixFilter(matrix); 173 return FilterOperation::CreateColorMatrixFilter(matrix);
145 } 174 }
146 case FilterOperation::ZOOM: 175 case FilterOperation::ZOOM:
147 return FilterOperation::CreateZoomFilter(1.f, 0); 176 return FilterOperation::CreateZoomFilter(1.f, 0);
148 case FilterOperation::SATURATING_BRIGHTNESS: 177 case FilterOperation::SATURATING_BRIGHTNESS:
149 return FilterOperation::CreateSaturatingBrightnessFilter(0.f); 178 return FilterOperation::CreateSaturatingBrightnessFilter(0.f);
179 case FilterOperation::REFERENCE:
180 return FilterOperation::CreateReferenceFilter(
181 skia::RefPtr<SkImageFilter>());
150 } 182 }
151 NOTREACHED(); 183 NOTREACHED();
152 return FilterOperation::CreateEmptyFilter(); 184 return FilterOperation::CreateEmptyFilter();
153 } 185 }
154 186
155 static float ClampAmountForFilterType(float amount, 187 static float ClampAmountForFilterType(float amount,
156 FilterOperation::FilterType type) { 188 FilterOperation::FilterType type) {
157 switch (type) { 189 switch (type) {
158 case FilterOperation::GRAYSCALE: 190 case FilterOperation::GRAYSCALE:
159 case FilterOperation::SEPIA: 191 case FilterOperation::SEPIA:
160 case FilterOperation::INVERT: 192 case FilterOperation::INVERT:
161 case FilterOperation::OPACITY: 193 case FilterOperation::OPACITY:
162 return MathUtil::ClampToRange(amount, 0.f, 1.f); 194 return MathUtil::ClampToRange(amount, 0.f, 1.f);
163 case FilterOperation::SATURATE: 195 case FilterOperation::SATURATE:
164 case FilterOperation::BRIGHTNESS: 196 case FilterOperation::BRIGHTNESS:
165 case FilterOperation::CONTRAST: 197 case FilterOperation::CONTRAST:
166 case FilterOperation::BLUR: 198 case FilterOperation::BLUR:
167 case FilterOperation::DROP_SHADOW: 199 case FilterOperation::DROP_SHADOW:
168 return std::max(amount, 0.f); 200 return std::max(amount, 0.f);
169 case FilterOperation::ZOOM: 201 case FilterOperation::ZOOM:
170 return std::max(amount, 1.f); 202 return std::max(amount, 1.f);
171 case FilterOperation::HUE_ROTATE: 203 case FilterOperation::HUE_ROTATE:
172 case FilterOperation::SATURATING_BRIGHTNESS: 204 case FilterOperation::SATURATING_BRIGHTNESS:
173 return amount; 205 return amount;
174 case FilterOperation::COLOR_MATRIX: 206 case FilterOperation::COLOR_MATRIX:
207 case FilterOperation::REFERENCE:
175 NOTREACHED(); 208 NOTREACHED();
176 return amount; 209 return amount;
177 } 210 }
178 NOTREACHED(); 211 NOTREACHED();
179 return amount; 212 return amount;
180 } 213 }
181 214
182 // static 215 // static
183 FilterOperation FilterOperation::Blend(const FilterOperation* from, 216 FilterOperation FilterOperation::Blend(const FilterOperation* from,
184 const FilterOperation* to, 217 const FilterOperation* to,
185 double progress) { 218 double progress) {
186 FilterOperation blended_filter = FilterOperation::CreateEmptyFilter(); 219 FilterOperation blended_filter = FilterOperation::CreateEmptyFilter();
187 220
188 if (!from && !to) 221 if (!from && !to)
189 return blended_filter; 222 return blended_filter;
190 223
191 const FilterOperation& from_op = from ? *from : CreateNoOpFilter(to->type()); 224 const FilterOperation& from_op = from ? *from : CreateNoOpFilter(to->type());
192 const FilterOperation& to_op = to ? *to : CreateNoOpFilter(from->type()); 225 const FilterOperation& to_op = to ? *to : CreateNoOpFilter(from->type());
193 226
194 if (from_op.type() != to_op.type()) 227 if (from_op.type() != to_op.type())
195 return blended_filter; 228 return blended_filter;
196 229
197 DCHECK(to_op.type() != FilterOperation::COLOR_MATRIX); 230 DCHECK(to_op.type() != FilterOperation::COLOR_MATRIX);
198 blended_filter.set_type(to_op.type()); 231 blended_filter.set_type(to_op.type());
199 232
233 if (to_op.type() == FilterOperation::REFERENCE) {
234 if (progress > 0.5)
235 blended_filter.set_image_filter(to_op.image_filter());
236 else
237 blended_filter.set_image_filter(from_op.image_filter());
238 return blended_filter;
239 }
240
200 blended_filter.set_amount(ClampAmountForFilterType( 241 blended_filter.set_amount(ClampAmountForFilterType(
201 BlendFloats(from_op.amount(), to_op.amount(), progress), to_op.type())); 242 BlendFloats(from_op.amount(), to_op.amount(), progress), to_op.type()));
202 243
203 if (to_op.type() == FilterOperation::DROP_SHADOW) { 244 if (to_op.type() == FilterOperation::DROP_SHADOW) {
204 gfx::Point blended_offset(BlendInts(from_op.drop_shadow_offset().x(), 245 gfx::Point blended_offset(BlendInts(from_op.drop_shadow_offset().x(),
205 to_op.drop_shadow_offset().x(), 246 to_op.drop_shadow_offset().x(),
206 progress), 247 progress),
207 BlendInts(from_op.drop_shadow_offset().y(), 248 BlendInts(from_op.drop_shadow_offset().y(),
208 to_op.drop_shadow_offset().y(), 249 to_op.drop_shadow_offset().y(),
209 progress)); 250 progress));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 scoped_ptr<ListValue> matrix(new ListValue); 284 scoped_ptr<ListValue> matrix(new ListValue);
244 for (size_t i = 0; i < arraysize(matrix_); ++i) 285 for (size_t i = 0; i < arraysize(matrix_); ++i)
245 matrix->AppendDouble(matrix_[i]); 286 matrix->AppendDouble(matrix_[i]);
246 value->Set("matrix", matrix.release()); 287 value->Set("matrix", matrix.release());
247 break; 288 break;
248 } 289 }
249 case FilterOperation::ZOOM: 290 case FilterOperation::ZOOM:
250 value->SetDouble("amount", amount_); 291 value->SetDouble("amount", amount_);
251 value->SetDouble("inset", zoom_inset_); 292 value->SetDouble("inset", zoom_inset_);
252 break; 293 break;
294 case FilterOperation::REFERENCE: {
295 int count_inputs = 0;
296 bool can_filter_image_gpu = false;
297 if (image_filter_) {
298 count_inputs = image_filter_->countInputs();
299 can_filter_image_gpu = image_filter_->canFilterImageGPU();
300 }
301 value->SetBoolean("is_null", !image_filter_);
302 value->SetInteger("count_inputs", count_inputs);
303 value->SetBoolean("can_filter_image_gpu", can_filter_image_gpu);
304 break;
305 }
253 } 306 }
254 return value.PassAs<base::Value>(); 307 return value.PassAs<base::Value>();
255 } 308 }
256 309
257 } // namespace cc 310 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/filter_operation.h ('k') | cc/output/filter_operations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698