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

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

Issue 317663005: Scale the ALPHA_THRESHOLD filter's region based on the device scale factor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove call to SetAlphaShape from this cl Created 6 years, 6 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
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 #include "ui/gfx/animation/tween.h" 11 #include "ui/gfx/animation/tween.h"
12 12
13 namespace cc { 13 namespace cc {
14 14
15 bool FilterOperation::operator==(const FilterOperation& other) const { 15 bool FilterOperation::operator==(const FilterOperation& other) const {
16 if (type_ != other.type_) 16 if (type_ != other.type_)
17 return false; 17 return false;
18 if (type_ == COLOR_MATRIX) 18 if (type_ == COLOR_MATRIX)
19 return !memcmp(matrix_, other.matrix_, sizeof(matrix_)); 19 return !memcmp(matrix_, other.matrix_, sizeof(matrix_));
20 if (type_ == DROP_SHADOW) { 20 if (type_ == DROP_SHADOW) {
21 return amount_ == other.amount_ && 21 return amount_ == other.amount_ &&
22 drop_shadow_offset_ == other.drop_shadow_offset_ && 22 drop_shadow_offset_ == other.drop_shadow_offset_ &&
23 drop_shadow_color_ == other.drop_shadow_color_; 23 drop_shadow_color_ == other.drop_shadow_color_;
24 } 24 }
25 if (type_ == REFERENCE) 25 if (type_ == REFERENCE)
26 return image_filter_.get() == other.image_filter_.get(); 26 return image_filter_.get() == other.image_filter_.get();
27 if (type_ == ALPHA_THRESHOLD) { 27 if (type_ == ALPHA_THRESHOLD) {
28 return region_ == other.region_ && 28 return region_ == other.region_ &&
29 amount_ == other.amount_ && 29 device_scale_factor_ == other.device_scale_factor_ &&
30 outer_threshold_ == other.outer_threshold_; 30 amount_ == other.amount_ &&
31 outer_threshold_ == other.outer_threshold_;
31 } 32 }
32 return amount_ == other.amount_; 33 return amount_ == other.amount_;
33 } 34 }
34 35
35 FilterOperation::FilterOperation(FilterType type, float amount) 36 FilterOperation::FilterOperation(FilterType type, float amount)
36 : type_(type), 37 : type_(type),
37 amount_(amount), 38 amount_(amount),
38 outer_threshold_(0), 39 outer_threshold_(0),
39 drop_shadow_offset_(0, 0), 40 drop_shadow_offset_(0, 0),
40 drop_shadow_color_(0), 41 drop_shadow_color_(0),
41 zoom_inset_(0) { 42 zoom_inset_(0),
43 device_scale_factor_(1.f) {
42 DCHECK_NE(type_, DROP_SHADOW); 44 DCHECK_NE(type_, DROP_SHADOW);
43 DCHECK_NE(type_, COLOR_MATRIX); 45 DCHECK_NE(type_, COLOR_MATRIX);
44 DCHECK_NE(type_, REFERENCE); 46 DCHECK_NE(type_, REFERENCE);
45 memset(matrix_, 0, sizeof(matrix_)); 47 memset(matrix_, 0, sizeof(matrix_));
46 } 48 }
47 49
48 FilterOperation::FilterOperation(FilterType type, 50 FilterOperation::FilterOperation(FilterType type,
49 const gfx::Point& offset, 51 const gfx::Point& offset,
50 float stdDeviation, 52 float stdDeviation,
51 SkColor color) 53 SkColor color)
52 : type_(type), 54 : type_(type),
53 amount_(stdDeviation), 55 amount_(stdDeviation),
54 outer_threshold_(0), 56 outer_threshold_(0),
55 drop_shadow_offset_(offset), 57 drop_shadow_offset_(offset),
56 drop_shadow_color_(color), 58 drop_shadow_color_(color),
57 zoom_inset_(0) { 59 zoom_inset_(0),
60 device_scale_factor_(1.f) {
58 DCHECK_EQ(type_, DROP_SHADOW); 61 DCHECK_EQ(type_, DROP_SHADOW);
59 memset(matrix_, 0, sizeof(matrix_)); 62 memset(matrix_, 0, sizeof(matrix_));
60 } 63 }
61 64
62 FilterOperation::FilterOperation(FilterType type, SkScalar matrix[20]) 65 FilterOperation::FilterOperation(FilterType type, SkScalar matrix[20])
63 : type_(type), 66 : type_(type),
64 amount_(0), 67 amount_(0),
65 outer_threshold_(0), 68 outer_threshold_(0),
66 drop_shadow_offset_(0, 0), 69 drop_shadow_offset_(0, 0),
67 drop_shadow_color_(0), 70 drop_shadow_color_(0),
68 zoom_inset_(0) { 71 zoom_inset_(0),
72 device_scale_factor_(1.f) {
69 DCHECK_EQ(type_, COLOR_MATRIX); 73 DCHECK_EQ(type_, COLOR_MATRIX);
70 memcpy(matrix_, matrix, sizeof(matrix_)); 74 memcpy(matrix_, matrix, sizeof(matrix_));
71 } 75 }
72 76
73 FilterOperation::FilterOperation(FilterType type, float amount, int inset) 77 FilterOperation::FilterOperation(FilterType type, float amount, int inset)
74 : type_(type), 78 : type_(type),
75 amount_(amount), 79 amount_(amount),
76 outer_threshold_(0), 80 outer_threshold_(0),
77 drop_shadow_offset_(0, 0), 81 drop_shadow_offset_(0, 0),
78 drop_shadow_color_(0), 82 drop_shadow_color_(0),
79 zoom_inset_(inset) { 83 zoom_inset_(inset),
84 device_scale_factor_(1.f) {
80 DCHECK_EQ(type_, ZOOM); 85 DCHECK_EQ(type_, ZOOM);
81 memset(matrix_, 0, sizeof(matrix_)); 86 memset(matrix_, 0, sizeof(matrix_));
82 } 87 }
83 88
84 FilterOperation::FilterOperation( 89 FilterOperation::FilterOperation(
85 FilterType type, 90 FilterType type,
86 const skia::RefPtr<SkImageFilter>& image_filter) 91 const skia::RefPtr<SkImageFilter>& image_filter)
87 : type_(type), 92 : type_(type),
88 amount_(0), 93 amount_(0),
89 outer_threshold_(0), 94 outer_threshold_(0),
90 drop_shadow_offset_(0, 0), 95 drop_shadow_offset_(0, 0),
91 drop_shadow_color_(0), 96 drop_shadow_color_(0),
92 image_filter_(image_filter), 97 image_filter_(image_filter),
93 zoom_inset_(0) { 98 zoom_inset_(0),
99 device_scale_factor_(1.f) {
94 DCHECK_EQ(type_, REFERENCE); 100 DCHECK_EQ(type_, REFERENCE);
95 memset(matrix_, 0, sizeof(matrix_)); 101 memset(matrix_, 0, sizeof(matrix_));
96 } 102 }
97 103
98 FilterOperation::FilterOperation(FilterType type, 104 FilterOperation::FilterOperation(FilterType type,
99 const SkRegion& region, 105 const SkRegion& region,
106 float device_scale_factor,
100 float inner_threshold, 107 float inner_threshold,
101 float outer_threshold) 108 float outer_threshold)
102 : type_(type), 109 : type_(type),
103 amount_(inner_threshold), 110 amount_(inner_threshold),
danakj 2014/06/17 21:35:28 how about putting the scale factor into amount_ an
garykac 2014/07/10 23:02:23 No longer necessary.
104 outer_threshold_(outer_threshold), 111 outer_threshold_(outer_threshold),
105 drop_shadow_offset_(0, 0), 112 drop_shadow_offset_(0, 0),
106 drop_shadow_color_(0), 113 drop_shadow_color_(0),
107 zoom_inset_(0), 114 zoom_inset_(0),
108 region_(region) { 115 region_(region),
116 device_scale_factor_(device_scale_factor) {
109 DCHECK_EQ(type_, ALPHA_THRESHOLD); 117 DCHECK_EQ(type_, ALPHA_THRESHOLD);
110 memset(matrix_, 0, sizeof(matrix_)); 118 memset(matrix_, 0, sizeof(matrix_));
111 } 119 }
112 120
113 FilterOperation::FilterOperation(const FilterOperation& other) 121 FilterOperation::FilterOperation(const FilterOperation& other)
114 : type_(other.type_), 122 : type_(other.type_),
115 amount_(other.amount_), 123 amount_(other.amount_),
116 outer_threshold_(other.outer_threshold_), 124 outer_threshold_(other.outer_threshold_),
117 drop_shadow_offset_(other.drop_shadow_offset_), 125 drop_shadow_offset_(other.drop_shadow_offset_),
118 drop_shadow_color_(other.drop_shadow_color_), 126 drop_shadow_color_(other.drop_shadow_color_),
119 image_filter_(other.image_filter_), 127 image_filter_(other.image_filter_),
120 zoom_inset_(other.zoom_inset_), 128 zoom_inset_(other.zoom_inset_),
121 region_(other.region_) { 129 region_(other.region_),
130 device_scale_factor_(other.device_scale_factor_) {
122 memcpy(matrix_, other.matrix_, sizeof(matrix_)); 131 memcpy(matrix_, other.matrix_, sizeof(matrix_));
123 } 132 }
124 133
125 FilterOperation::~FilterOperation() { 134 FilterOperation::~FilterOperation() {
126 } 135 }
127 136
128 static FilterOperation CreateNoOpFilter(FilterOperation::FilterType type) { 137 static FilterOperation CreateNoOpFilter(FilterOperation::FilterType type) {
129 switch (type) { 138 switch (type) {
130 case FilterOperation::GRAYSCALE: 139 case FilterOperation::GRAYSCALE:
131 return FilterOperation::CreateGrayscaleFilter(0.f); 140 return FilterOperation::CreateGrayscaleFilter(0.f);
(...skipping 23 matching lines...) Expand all
155 return FilterOperation::CreateColorMatrixFilter(matrix); 164 return FilterOperation::CreateColorMatrixFilter(matrix);
156 } 165 }
157 case FilterOperation::ZOOM: 166 case FilterOperation::ZOOM:
158 return FilterOperation::CreateZoomFilter(1.f, 0); 167 return FilterOperation::CreateZoomFilter(1.f, 0);
159 case FilterOperation::SATURATING_BRIGHTNESS: 168 case FilterOperation::SATURATING_BRIGHTNESS:
160 return FilterOperation::CreateSaturatingBrightnessFilter(0.f); 169 return FilterOperation::CreateSaturatingBrightnessFilter(0.f);
161 case FilterOperation::REFERENCE: 170 case FilterOperation::REFERENCE:
162 return FilterOperation::CreateReferenceFilter( 171 return FilterOperation::CreateReferenceFilter(
163 skia::RefPtr<SkImageFilter>()); 172 skia::RefPtr<SkImageFilter>());
164 case FilterOperation::ALPHA_THRESHOLD: 173 case FilterOperation::ALPHA_THRESHOLD:
165 return FilterOperation::CreateAlphaThresholdFilter(SkRegion(), 1.f, 0.f); 174 return FilterOperation::CreateAlphaThresholdFilter(
175 SkRegion(), 1.f, 1.f, 0.f);
166 } 176 }
167 NOTREACHED(); 177 NOTREACHED();
168 return FilterOperation::CreateEmptyFilter(); 178 return FilterOperation::CreateEmptyFilter();
169 } 179 }
170 180
171 static float ClampAmountForFilterType(float amount, 181 static float ClampAmountForFilterType(float amount,
172 FilterOperation::FilterType type) { 182 FilterOperation::FilterType type) {
173 switch (type) { 183 switch (type) {
174 case FilterOperation::GRAYSCALE: 184 case FilterOperation::GRAYSCALE:
175 case FilterOperation::SEPIA: 185 case FilterOperation::SEPIA:
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 blended_filter.set_zoom_inset( 252 blended_filter.set_zoom_inset(
243 std::max(gfx::Tween::LinearIntValueBetween( 253 std::max(gfx::Tween::LinearIntValueBetween(
244 from_op.zoom_inset(), to_op.zoom_inset(), progress), 254 from_op.zoom_inset(), to_op.zoom_inset(), progress),
245 0)); 255 0));
246 } else if (to_op.type() == FilterOperation::ALPHA_THRESHOLD) { 256 } else if (to_op.type() == FilterOperation::ALPHA_THRESHOLD) {
247 blended_filter.set_outer_threshold(ClampAmountForFilterType( 257 blended_filter.set_outer_threshold(ClampAmountForFilterType(
248 gfx::Tween::FloatValueBetween(progress, 258 gfx::Tween::FloatValueBetween(progress,
249 from_op.outer_threshold(), 259 from_op.outer_threshold(),
250 to_op.outer_threshold()), 260 to_op.outer_threshold()),
251 to_op.type())); 261 to_op.type()));
252 blended_filter.set_region(to_op.region()); 262 const FilterOperation& copy_op = progress > 0.5 ? to_op : from_op;
263 blended_filter.set_region(copy_op.region());
264 blended_filter.set_device_scale_factor(copy_op.device_scale_factor());
253 } 265 }
254 266
255 return blended_filter; 267 return blended_filter;
256 } 268 }
257 269
258 scoped_ptr<base::Value> FilterOperation::AsValue() const { 270 scoped_ptr<base::Value> FilterOperation::AsValue() const {
259 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); 271 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue);
260 value->SetInteger("type", type_); 272 value->SetInteger("type", type_);
261 switch (type_) { 273 switch (type_) {
262 case FilterOperation::GRAYSCALE: 274 case FilterOperation::GRAYSCALE:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 value->SetDouble("inner_threshold", amount_); 315 value->SetDouble("inner_threshold", amount_);
304 value->SetDouble("outer_threshold", outer_threshold_); 316 value->SetDouble("outer_threshold", outer_threshold_);
305 scoped_ptr<base::ListValue> region_value(new base::ListValue()); 317 scoped_ptr<base::ListValue> region_value(new base::ListValue());
306 for (SkRegion::Iterator it(region_); !it.done(); it.next()) { 318 for (SkRegion::Iterator it(region_); !it.done(); it.next()) {
307 region_value->AppendInteger(it.rect().x()); 319 region_value->AppendInteger(it.rect().x());
308 region_value->AppendInteger(it.rect().y()); 320 region_value->AppendInteger(it.rect().y());
309 region_value->AppendInteger(it.rect().width()); 321 region_value->AppendInteger(it.rect().width());
310 region_value->AppendInteger(it.rect().height()); 322 region_value->AppendInteger(it.rect().height());
311 } 323 }
312 value->Set("region", region_value.release()); 324 value->Set("region", region_value.release());
325 value->SetDouble("device_scale_factor", device_scale_factor_);
313 } 326 }
314 break; 327 break;
315 } 328 }
316 return value.PassAs<base::Value>(); 329 return value.PassAs<base::Value>();
317 } 330 }
318 331
319 } // namespace cc 332 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698