OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/output/render_surface_filters.h" | 5 #include "cc/output/render_surface_filters.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "cc/output/filter_operation.h" | 11 #include "cc/output/filter_operation.h" |
12 #include "cc/output/filter_operations.h" | 12 #include "cc/output/filter_operations.h" |
13 #include "skia/ext/refptr.h" | |
14 #include "third_party/skia/include/core/SkImageFilter.h" | 13 #include "third_party/skia/include/core/SkImageFilter.h" |
15 #include "third_party/skia/include/effects/SkAlphaThresholdFilter.h" | 14 #include "third_party/skia/include/effects/SkAlphaThresholdFilter.h" |
16 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 15 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
17 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" | 16 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" |
18 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" | 17 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" |
19 #include "third_party/skia/include/effects/SkComposeImageFilter.h" | 18 #include "third_party/skia/include/effects/SkComposeImageFilter.h" |
20 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" | 19 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" |
21 #include "third_party/skia/include/effects/SkMagnifierImageFilter.h" | 20 #include "third_party/skia/include/effects/SkMagnifierImageFilter.h" |
22 #include "ui/gfx/geometry/size_f.h" | 21 #include "ui/gfx/geometry/size_f.h" |
23 | 22 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 | 137 |
139 matrix[10] = 0.272f - 0.272f * amount; | 138 matrix[10] = 0.272f - 0.272f * amount; |
140 matrix[11] = 0.534f - 0.534f * amount; | 139 matrix[11] = 0.534f - 0.534f * amount; |
141 matrix[12] = 0.131f + 0.869f * amount; | 140 matrix[12] = 0.131f + 0.869f * amount; |
142 matrix[13] = matrix[14] = 0.f; | 141 matrix[13] = matrix[14] = 0.f; |
143 | 142 |
144 matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0.f; | 143 matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0.f; |
145 matrix[18] = 1.f; | 144 matrix[18] = 1.f; |
146 } | 145 } |
147 | 146 |
148 skia::RefPtr<SkImageFilter> CreateMatrixImageFilter( | 147 sk_sp<SkImageFilter> CreateMatrixImageFilter( |
149 const SkScalar matrix[20], | 148 const SkScalar matrix[20], |
150 const skia::RefPtr<SkImageFilter>& input) { | 149 const sk_sp<SkImageFilter>& input) { |
danakj
2016/04/14 19:37:32
by value
tomhudson
2016/04/25 20:48:11
Done.
| |
151 sk_sp<SkColorFilter> color_filter = | 150 sk_sp<SkColorFilter> color_filter = |
152 SkColorFilter::MakeMatrixFilterRowMajor255(matrix); | 151 SkColorFilter::MakeMatrixFilterRowMajor255(matrix); |
153 return skia::AdoptRef( | 152 return sk_sp<SkImageFilter>( |
danakj
2016/04/14 19:37:32
call Make and you don't need to cast/wrap here
tomhudson
2016/04/25 20:48:11
Done.
(Some of those Make() calls on filters were
| |
154 SkColorFilterImageFilter::Create(color_filter.get(), input.get())); | 153 SkColorFilterImageFilter::Create(color_filter.get(), input.get())); |
155 } | 154 } |
156 | 155 |
157 } // namespace | 156 } // namespace |
158 | 157 |
159 skia::RefPtr<SkImageFilter> RenderSurfaceFilters::BuildImageFilter( | 158 sk_sp<SkImageFilter> RenderSurfaceFilters::BuildImageFilter( |
160 const FilterOperations& filters, | 159 const FilterOperations& filters, |
161 const gfx::SizeF& size) { | 160 const gfx::SizeF& size) { |
162 skia::RefPtr<SkImageFilter> image_filter; | 161 sk_sp<SkImageFilter> image_filter; |
163 SkScalar matrix[20]; | 162 SkScalar matrix[20]; |
164 for (size_t i = 0; i < filters.size(); ++i) { | 163 for (size_t i = 0; i < filters.size(); ++i) { |
165 const FilterOperation& op = filters.at(i); | 164 const FilterOperation& op = filters.at(i); |
166 switch (op.type()) { | 165 switch (op.type()) { |
167 case FilterOperation::GRAYSCALE: | 166 case FilterOperation::GRAYSCALE: |
168 GetGrayscaleMatrix(1.f - op.amount(), matrix); | 167 GetGrayscaleMatrix(1.f - op.amount(), matrix); |
169 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 168 image_filter = CreateMatrixImageFilter(matrix, image_filter); |
danakj
2016/04/14 19:37:32
should move image_filter on all these calls
tomhudson
2016/04/25 20:48:13
Done.
| |
170 break; | 169 break; |
171 case FilterOperation::SEPIA: | 170 case FilterOperation::SEPIA: |
172 GetSepiaMatrix(1.f - op.amount(), matrix); | 171 GetSepiaMatrix(1.f - op.amount(), matrix); |
173 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 172 image_filter = CreateMatrixImageFilter(matrix, image_filter); |
174 break; | 173 break; |
175 case FilterOperation::SATURATE: | 174 case FilterOperation::SATURATE: |
176 GetSaturateMatrix(op.amount(), matrix); | 175 GetSaturateMatrix(op.amount(), matrix); |
177 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 176 image_filter = CreateMatrixImageFilter(matrix, image_filter); |
178 break; | 177 break; |
179 case FilterOperation::HUE_ROTATE: | 178 case FilterOperation::HUE_ROTATE: |
(...skipping 10 matching lines...) Expand all Loading... | |
190 break; | 189 break; |
191 case FilterOperation::BRIGHTNESS: | 190 case FilterOperation::BRIGHTNESS: |
192 GetBrightnessMatrix(op.amount(), matrix); | 191 GetBrightnessMatrix(op.amount(), matrix); |
193 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 192 image_filter = CreateMatrixImageFilter(matrix, image_filter); |
194 break; | 193 break; |
195 case FilterOperation::CONTRAST: | 194 case FilterOperation::CONTRAST: |
196 GetContrastMatrix(op.amount(), matrix); | 195 GetContrastMatrix(op.amount(), matrix); |
197 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 196 image_filter = CreateMatrixImageFilter(matrix, image_filter); |
198 break; | 197 break; |
199 case FilterOperation::BLUR: | 198 case FilterOperation::BLUR: |
200 image_filter = skia::AdoptRef(SkBlurImageFilter::Create( | 199 image_filter = |
201 op.amount(), op.amount(), image_filter.get())); | 200 SkBlurImageFilter::Make(op.amount(), op.amount(), image_filter); |
202 break; | 201 break; |
203 case FilterOperation::DROP_SHADOW: | 202 case FilterOperation::DROP_SHADOW: |
204 image_filter = skia::AdoptRef(SkDropShadowImageFilter::Create( | 203 image_filter = sk_sp<SkImageFilter>(SkDropShadowImageFilter::Create( |
danakj
2016/04/14 19:37:31
call Make instead?
tomhudson
2016/04/25 20:48:11
Done.
| |
205 SkIntToScalar(op.drop_shadow_offset().x()), | 204 SkIntToScalar(op.drop_shadow_offset().x()), |
206 SkIntToScalar(op.drop_shadow_offset().y()), | 205 SkIntToScalar(op.drop_shadow_offset().y()), |
207 SkIntToScalar(op.amount()), | 206 SkIntToScalar(op.amount()), SkIntToScalar(op.amount()), |
208 SkIntToScalar(op.amount()), | |
209 op.drop_shadow_color(), | 207 op.drop_shadow_color(), |
210 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, | 208 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, |
211 image_filter.get())); | 209 image_filter.get())); |
212 break; | 210 break; |
213 case FilterOperation::COLOR_MATRIX: | 211 case FilterOperation::COLOR_MATRIX: |
214 image_filter = CreateMatrixImageFilter(op.matrix(), image_filter); | 212 image_filter = CreateMatrixImageFilter(op.matrix(), image_filter); |
215 break; | 213 break; |
216 case FilterOperation::ZOOM: { | 214 case FilterOperation::ZOOM: { |
217 skia::RefPtr<SkImageFilter> zoom_filter = | 215 sk_sp<SkImageFilter> zoom_filter(SkMagnifierImageFilter::Create( |
218 skia::AdoptRef(SkMagnifierImageFilter::Create( | 216 SkRect::MakeXYWH( |
219 SkRect::MakeXYWH( | 217 (size.width() - (size.width() / op.amount())) / 2.f, |
220 (size.width() - (size.width() / op.amount())) / 2.f, | 218 (size.height() - (size.height() / op.amount())) / 2.f, |
221 (size.height() - (size.height() / op.amount())) / 2.f, | 219 size.width() / op.amount(), size.height() / op.amount()), |
222 size.width() / op.amount(), | 220 op.zoom_inset())); |
223 size.height() / op.amount()), | |
224 op.zoom_inset())); | |
225 if (image_filter.get()) { | 221 if (image_filter.get()) { |
226 // TODO(ajuma): When there's a 1-input version of | 222 // TODO(ajuma): When there's a 1-input version of |
227 // SkMagnifierImageFilter, use that to handle the input filter | 223 // SkMagnifierImageFilter, use that to handle the input filter |
228 // instead of using an SkComposeImageFilter. | 224 // instead of using an SkComposeImageFilter. |
229 image_filter = skia::AdoptRef(SkComposeImageFilter::Create( | 225 image_filter = SkComposeImageFilter::Make(zoom_filter, image_filter); |
danakj
2016/04/14 19:37:32
move zoom_filter too
tomhudson
2016/04/25 20:48:11
Done.
| |
230 zoom_filter.get(), image_filter.get())); | |
231 } else { | 226 } else { |
232 image_filter = zoom_filter; | 227 image_filter = zoom_filter; |
233 } | 228 } |
234 break; | 229 break; |
235 } | 230 } |
236 case FilterOperation::SATURATING_BRIGHTNESS: | 231 case FilterOperation::SATURATING_BRIGHTNESS: |
237 GetSaturatingBrightnessMatrix(op.amount(), matrix); | 232 GetSaturatingBrightnessMatrix(op.amount(), matrix); |
238 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 233 image_filter = CreateMatrixImageFilter(matrix, image_filter); |
239 break; | 234 break; |
240 case FilterOperation::REFERENCE: { | 235 case FilterOperation::REFERENCE: { |
241 if (!op.image_filter()) | 236 if (!op.image_filter()) |
242 break; | 237 break; |
243 | 238 |
244 skia::RefPtr<SkColorFilter> cf; | 239 sk_sp<SkColorFilter> cf; |
245 | 240 |
246 { | 241 { |
247 SkColorFilter* colorfilter_rawptr = NULL; | 242 SkColorFilter* colorfilter_rawptr = NULL; |
248 op.image_filter()->asColorFilter(&colorfilter_rawptr); | 243 op.image_filter()->asColorFilter(&colorfilter_rawptr); |
249 cf = skia::AdoptRef(colorfilter_rawptr); | 244 cf = sk_sp<SkColorFilter>(colorfilter_rawptr); |
danakj
2016/04/14 19:37:32
cf.reset(
tomhudson
2016/04/25 20:48:11
Done.
| |
250 } | 245 } |
251 | 246 |
252 if (cf && cf->asColorMatrix(matrix) && | 247 if (cf && cf->asColorMatrix(matrix) && |
253 !op.image_filter()->getInput(0)) { | 248 !op.image_filter()->getInput(0)) { |
254 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 249 image_filter = CreateMatrixImageFilter(matrix, image_filter); |
danakj
2016/04/14 19:37:31
move image_filter
tomhudson
2016/04/25 20:48:11
Done.
| |
255 } else if (image_filter) { | 250 } else if (image_filter) { |
256 image_filter = skia::AdoptRef(SkComposeImageFilter::Create( | 251 image_filter = |
257 op.image_filter().get(), image_filter.get())); | 252 SkComposeImageFilter::Make(op.image_filter(), image_filter); |
danakj
2016/04/14 19:37:32
move image_filter
tomhudson
2016/04/25 20:48:11
Done.
| |
258 } else { | 253 } else { |
259 image_filter = op.image_filter(); | 254 image_filter = op.image_filter(); |
260 } | 255 } |
261 break; | 256 break; |
262 } | 257 } |
263 case FilterOperation::ALPHA_THRESHOLD: { | 258 case FilterOperation::ALPHA_THRESHOLD: { |
264 skia::RefPtr<SkImageFilter> alpha_filter = skia::AdoptRef( | 259 sk_sp<SkImageFilter> alpha_filter = SkAlphaThresholdFilter::Make( |
265 SkAlphaThresholdFilter::Create( | 260 op.region(), op.amount(), op.outer_threshold(), nullptr); |
266 op.region(), op.amount(), op.outer_threshold())); | |
267 if (image_filter.get()) { | 261 if (image_filter.get()) { |
268 image_filter = skia::AdoptRef(SkComposeImageFilter::Create( | 262 image_filter = SkComposeImageFilter::Make(alpha_filter, image_filter); |
danakj
2016/04/14 19:37:32
move alpha_filter
tomhudson
2016/04/25 20:48:13
Done.
| |
269 alpha_filter.get(), image_filter.get())); | |
270 } else { | 263 } else { |
271 image_filter = alpha_filter; | 264 image_filter = alpha_filter; |
danakj
2016/04/14 19:37:32
move
tomhudson
2016/04/25 20:48:11
Done.
| |
272 } | 265 } |
273 break; | 266 break; |
274 } | 267 } |
275 } | 268 } |
276 } | 269 } |
277 return image_filter; | 270 return image_filter; |
278 } | 271 } |
279 | 272 |
280 } // namespace cc | 273 } // namespace cc |
OLD | NEW |