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

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

Issue 2748263002: Move cc::DisplayItemList and related classes into cc/paint/ (Closed)
Patch Set: Merge branch 'master' into ccpaint Created 3 years, 9 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
« no previous file with comments | « cc/base/filter_operation.h ('k') | cc/base/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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/trace_event/trace_event_argument.h" 9 #include "base/trace_event/trace_event_argument.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "cc/base/filter_operation.h"
11 #include "cc/base/math_util.h" 12 #include "cc/base/math_util.h"
12 #include "cc/output/filter_operation.h"
13 #include "ui/gfx/animation/tween.h" 13 #include "ui/gfx/animation/tween.h"
14 #include "ui/gfx/geometry/rect.h" 14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/geometry/rect_conversions.h" 15 #include "ui/gfx/geometry/rect_conversions.h"
16 #include "ui/gfx/skia_util.h" 16 #include "ui/gfx/skia_util.h"
17 17
18 namespace cc { 18 namespace cc {
19 19
20 bool FilterOperation::operator==(const FilterOperation& other) const { 20 bool FilterOperation::operator==(const FilterOperation& other) const {
21 if (type_ != other.type_) 21 if (type_ != other.type_)
22 return false; 22 return false;
23 if (type_ == COLOR_MATRIX) 23 if (type_ == COLOR_MATRIX)
24 return !memcmp(matrix_, other.matrix_, sizeof(matrix_)); 24 return !memcmp(matrix_, other.matrix_, sizeof(matrix_));
25 if (type_ == DROP_SHADOW) { 25 if (type_ == DROP_SHADOW) {
26 return amount_ == other.amount_ && 26 return amount_ == other.amount_ &&
27 drop_shadow_offset_ == other.drop_shadow_offset_ && 27 drop_shadow_offset_ == other.drop_shadow_offset_ &&
28 drop_shadow_color_ == other.drop_shadow_color_; 28 drop_shadow_color_ == other.drop_shadow_color_;
29 } 29 }
30 if (type_ == REFERENCE) { 30 if (type_ == REFERENCE) {
31 return image_filter_.get() == other.image_filter_.get(); 31 return image_filter_.get() == other.image_filter_.get();
32 } 32 }
33 if (type_ == ALPHA_THRESHOLD) { 33 if (type_ == ALPHA_THRESHOLD) {
34 return region_ == other.region_ && 34 return region_ == other.region_ && amount_ == other.amount_ &&
35 amount_ == other.amount_ && 35 outer_threshold_ == other.outer_threshold_;
36 outer_threshold_ == other.outer_threshold_;
37 } 36 }
38 return amount_ == other.amount_; 37 return amount_ == other.amount_;
39 } 38 }
40 39
41 FilterOperation::FilterOperation() : FilterOperation(GRAYSCALE, 0.f) {} 40 FilterOperation::FilterOperation() : FilterOperation(GRAYSCALE, 0.f) {}
42 41
43 FilterOperation::FilterOperation(FilterType type, float amount) 42 FilterOperation::FilterOperation(FilterType type, float amount)
44 : type_(type), 43 : type_(type),
45 amount_(amount), 44 amount_(amount),
46 outer_threshold_(0), 45 outer_threshold_(0),
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 amount_(other.amount_), 121 amount_(other.amount_),
123 outer_threshold_(other.outer_threshold_), 122 outer_threshold_(other.outer_threshold_),
124 drop_shadow_offset_(other.drop_shadow_offset_), 123 drop_shadow_offset_(other.drop_shadow_offset_),
125 drop_shadow_color_(other.drop_shadow_color_), 124 drop_shadow_color_(other.drop_shadow_color_),
126 image_filter_(other.image_filter_), 125 image_filter_(other.image_filter_),
127 zoom_inset_(other.zoom_inset_), 126 zoom_inset_(other.zoom_inset_),
128 region_(other.region_) { 127 region_(other.region_) {
129 memcpy(matrix_, other.matrix_, sizeof(matrix_)); 128 memcpy(matrix_, other.matrix_, sizeof(matrix_));
130 } 129 }
131 130
132 FilterOperation::~FilterOperation() { 131 FilterOperation::~FilterOperation() {}
133 }
134 132
135 static FilterOperation CreateNoOpFilter(FilterOperation::FilterType type) { 133 static FilterOperation CreateNoOpFilter(FilterOperation::FilterType type) {
136 switch (type) { 134 switch (type) {
137 case FilterOperation::GRAYSCALE: 135 case FilterOperation::GRAYSCALE:
138 return FilterOperation::CreateGrayscaleFilter(0.f); 136 return FilterOperation::CreateGrayscaleFilter(0.f);
139 case FilterOperation::SEPIA: 137 case FilterOperation::SEPIA:
140 return FilterOperation::CreateSepiaFilter(0.f); 138 return FilterOperation::CreateSepiaFilter(0.f);
141 case FilterOperation::SATURATE: 139 case FilterOperation::SATURATE:
142 return FilterOperation::CreateSaturateFilter(1.f); 140 return FilterOperation::CreateSaturateFilter(1.f);
143 case FilterOperation::HUE_ROTATE: 141 case FilterOperation::HUE_ROTATE:
144 return FilterOperation::CreateHueRotateFilter(0.f); 142 return FilterOperation::CreateHueRotateFilter(0.f);
145 case FilterOperation::INVERT: 143 case FilterOperation::INVERT:
146 return FilterOperation::CreateInvertFilter(0.f); 144 return FilterOperation::CreateInvertFilter(0.f);
147 case FilterOperation::BRIGHTNESS: 145 case FilterOperation::BRIGHTNESS:
148 return FilterOperation::CreateBrightnessFilter(1.f); 146 return FilterOperation::CreateBrightnessFilter(1.f);
149 case FilterOperation::CONTRAST: 147 case FilterOperation::CONTRAST:
150 return FilterOperation::CreateContrastFilter(1.f); 148 return FilterOperation::CreateContrastFilter(1.f);
151 case FilterOperation::OPACITY: 149 case FilterOperation::OPACITY:
152 return FilterOperation::CreateOpacityFilter(1.f); 150 return FilterOperation::CreateOpacityFilter(1.f);
153 case FilterOperation::BLUR: 151 case FilterOperation::BLUR:
154 return FilterOperation::CreateBlurFilter(0.f); 152 return FilterOperation::CreateBlurFilter(0.f);
155 case FilterOperation::DROP_SHADOW: 153 case FilterOperation::DROP_SHADOW:
156 return FilterOperation::CreateDropShadowFilter( 154 return FilterOperation::CreateDropShadowFilter(gfx::Point(0, 0), 0.f,
157 gfx::Point(0, 0), 0.f, SK_ColorTRANSPARENT); 155 SK_ColorTRANSPARENT);
158 case FilterOperation::COLOR_MATRIX: { 156 case FilterOperation::COLOR_MATRIX: {
159 SkScalar matrix[20]; 157 SkScalar matrix[20];
160 memset(matrix, 0, 20 * sizeof(SkScalar)); 158 memset(matrix, 0, 20 * sizeof(SkScalar));
161 matrix[0] = matrix[6] = matrix[12] = matrix[18] = 1.f; 159 matrix[0] = matrix[6] = matrix[12] = matrix[18] = 1.f;
162 return FilterOperation::CreateColorMatrixFilter(matrix); 160 return FilterOperation::CreateColorMatrixFilter(matrix);
163 } 161 }
164 case FilterOperation::ZOOM: 162 case FilterOperation::ZOOM:
165 return FilterOperation::CreateZoomFilter(1.f, 0); 163 return FilterOperation::CreateZoomFilter(1.f, 0);
166 case FilterOperation::SATURATING_BRIGHTNESS: 164 case FilterOperation::SATURATING_BRIGHTNESS:
167 return FilterOperation::CreateSaturatingBrightnessFilter(0.f); 165 return FilterOperation::CreateSaturatingBrightnessFilter(0.f);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 else 225 else
228 blended_filter.set_image_filter(from_op.image_filter()); 226 blended_filter.set_image_filter(from_op.image_filter());
229 return blended_filter; 227 return blended_filter;
230 } 228 }
231 229
232 blended_filter.set_amount(ClampAmountForFilterType( 230 blended_filter.set_amount(ClampAmountForFilterType(
233 gfx::Tween::FloatValueBetween(progress, from_op.amount(), to_op.amount()), 231 gfx::Tween::FloatValueBetween(progress, from_op.amount(), to_op.amount()),
234 to_op.type())); 232 to_op.type()));
235 233
236 if (to_op.type() == FilterOperation::DROP_SHADOW) { 234 if (to_op.type() == FilterOperation::DROP_SHADOW) {
237 gfx::Point blended_offset( 235 gfx::Point blended_offset(gfx::Tween::LinearIntValueBetween(
238 gfx::Tween::LinearIntValueBetween(progress, 236 progress, from_op.drop_shadow_offset().x(),
239 from_op.drop_shadow_offset().x(), 237 to_op.drop_shadow_offset().x()),
240 to_op.drop_shadow_offset().x()), 238 gfx::Tween::LinearIntValueBetween(
241 gfx::Tween::LinearIntValueBetween(progress, 239 progress, from_op.drop_shadow_offset().y(),
242 from_op.drop_shadow_offset().y(), 240 to_op.drop_shadow_offset().y()));
243 to_op.drop_shadow_offset().y()));
244 blended_filter.set_drop_shadow_offset(blended_offset); 241 blended_filter.set_drop_shadow_offset(blended_offset);
245 blended_filter.set_drop_shadow_color(gfx::Tween::ColorValueBetween( 242 blended_filter.set_drop_shadow_color(gfx::Tween::ColorValueBetween(
246 progress, from_op.drop_shadow_color(), to_op.drop_shadow_color())); 243 progress, from_op.drop_shadow_color(), to_op.drop_shadow_color()));
247 } else if (to_op.type() == FilterOperation::ZOOM) { 244 } else if (to_op.type() == FilterOperation::ZOOM) {
248 blended_filter.set_zoom_inset( 245 blended_filter.set_zoom_inset(
249 std::max(gfx::Tween::LinearIntValueBetween( 246 std::max(gfx::Tween::LinearIntValueBetween(
250 progress, from_op.zoom_inset(), to_op.zoom_inset()), 247 progress, from_op.zoom_inset(), to_op.zoom_inset()),
251 0)); 248 0));
252 } else if (to_op.type() == FilterOperation::ALPHA_THRESHOLD) { 249 } else if (to_op.type() == FilterOperation::ALPHA_THRESHOLD) {
253 blended_filter.set_outer_threshold(ClampAmountForFilterType( 250 blended_filter.set_outer_threshold(ClampAmountForFilterType(
254 gfx::Tween::FloatValueBetween(progress, 251 gfx::Tween::FloatValueBetween(progress, from_op.outer_threshold(),
255 from_op.outer_threshold(), 252 to_op.outer_threshold()),
256 to_op.outer_threshold()), 253 to_op.type()));
257 to_op.type()));
258 blended_filter.set_region(to_op.region()); 254 blended_filter.set_region(to_op.region());
259 } 255 }
260 256
261 return blended_filter; 257 return blended_filter;
262 } 258 }
263 259
264 void FilterOperation::AsValueInto(base::trace_event::TracedValue* value) const { 260 void FilterOperation::AsValueInto(base::trace_event::TracedValue* value) const {
265 value->SetInteger("type", type_); 261 value->SetInteger("type", type_);
266 switch (type_) { 262 switch (type_) {
267 case FilterOperation::GRAYSCALE: 263 case FilterOperation::GRAYSCALE:
(...skipping 27 matching lines...) Expand all
295 case FilterOperation::REFERENCE: { 291 case FilterOperation::REFERENCE: {
296 int count_inputs = 0; 292 int count_inputs = 0;
297 if (image_filter_) { 293 if (image_filter_) {
298 count_inputs = image_filter_->countInputs(); 294 count_inputs = image_filter_->countInputs();
299 } 295 }
300 value->SetBoolean("is_null", !image_filter_); 296 value->SetBoolean("is_null", !image_filter_);
301 value->SetInteger("count_inputs", count_inputs); 297 value->SetInteger("count_inputs", count_inputs);
302 break; 298 break;
303 } 299 }
304 case FilterOperation::ALPHA_THRESHOLD: { 300 case FilterOperation::ALPHA_THRESHOLD: {
305 value->SetDouble("inner_threshold", amount_); 301 value->SetDouble("inner_threshold", amount_);
306 value->SetDouble("outer_threshold", outer_threshold_); 302 value->SetDouble("outer_threshold", outer_threshold_);
307 std::unique_ptr<base::ListValue> region_value(new base::ListValue()); 303 std::unique_ptr<base::ListValue> region_value(new base::ListValue());
308 value->BeginArray("region"); 304 value->BeginArray("region");
309 for (SkRegion::Iterator it(region_); !it.done(); it.next()) { 305 for (SkRegion::Iterator it(region_); !it.done(); it.next()) {
310 value->AppendInteger(it.rect().x()); 306 value->AppendInteger(it.rect().x());
311 value->AppendInteger(it.rect().y()); 307 value->AppendInteger(it.rect().y());
312 value->AppendInteger(it.rect().width()); 308 value->AppendInteger(it.rect().width());
313 value->AppendInteger(it.rect().height()); 309 value->AppendInteger(it.rect().height());
314 }
315 value->EndArray();
316 } 310 }
317 break; 311 value->EndArray();
312 } break;
318 } 313 }
319 } 314 }
320 315
321 namespace { 316 namespace {
322 317
323 SkVector MapStdDeviation(float std_deviation, const SkMatrix& matrix) { 318 SkVector MapStdDeviation(float std_deviation, const SkMatrix& matrix) {
324 // Corresponds to SpreadForStdDeviation in filter_operations.cc. 319 // Corresponds to SpreadForStdDeviation in filter_operations.cc.
325 SkVector sigma = SkVector::Make(std_deviation, std_deviation); 320 SkVector sigma = SkVector::Make(std_deviation, std_deviation);
326 matrix.mapVectors(&sigma, 1); 321 matrix.mapVectors(&sigma, 1);
327 return sigma * SkIntToScalar(3); 322 return sigma * SkIntToScalar(3);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 SkImageFilter::kForward_MapDirection); 372 SkImageFilter::kForward_MapDirection);
378 } 373 }
379 374
380 gfx::Rect FilterOperation::MapRectReverse(const gfx::Rect& rect, 375 gfx::Rect FilterOperation::MapRectReverse(const gfx::Rect& rect,
381 const SkMatrix& matrix) const { 376 const SkMatrix& matrix) const {
382 return MapRectInternal(*this, rect, matrix, 377 return MapRectInternal(*this, rect, matrix,
383 SkImageFilter::kReverse_MapDirection); 378 SkImageFilter::kReverse_MapDirection);
384 } 379 }
385 380
386 } // namespace cc 381 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/filter_operation.h ('k') | cc/base/filter_operations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698