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(const SkScalar matrix[20], |
149 const SkScalar matrix[20], | 148 sk_sp<SkImageFilter> input) { |
150 const skia::RefPtr<SkImageFilter>& input) { | 149 return SkColorFilterImageFilter::Make( |
151 sk_sp<SkColorFilter> color_filter = | 150 SkColorFilter::MakeMatrixFilterRowMajor255(matrix), std::move(input)); |
152 SkColorFilter::MakeMatrixFilterRowMajor255(matrix); | |
153 return skia::AdoptRef( | |
154 SkColorFilterImageFilter::Create(color_filter.get(), input.get())); | |
155 } | 151 } |
156 | 152 |
157 } // namespace | 153 } // namespace |
158 | 154 |
159 skia::RefPtr<SkImageFilter> RenderSurfaceFilters::BuildImageFilter( | 155 sk_sp<SkImageFilter> RenderSurfaceFilters::BuildImageFilter( |
160 const FilterOperations& filters, | 156 const FilterOperations& filters, |
161 const gfx::SizeF& size) { | 157 const gfx::SizeF& size) { |
162 skia::RefPtr<SkImageFilter> image_filter; | 158 sk_sp<SkImageFilter> image_filter; |
163 SkScalar matrix[20]; | 159 SkScalar matrix[20]; |
164 for (size_t i = 0; i < filters.size(); ++i) { | 160 for (size_t i = 0; i < filters.size(); ++i) { |
165 const FilterOperation& op = filters.at(i); | 161 const FilterOperation& op = filters.at(i); |
166 switch (op.type()) { | 162 switch (op.type()) { |
167 case FilterOperation::GRAYSCALE: | 163 case FilterOperation::GRAYSCALE: |
168 GetGrayscaleMatrix(1.f - op.amount(), matrix); | 164 GetGrayscaleMatrix(1.f - op.amount(), matrix); |
169 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 165 image_filter = CreateMatrixImageFilter(matrix, std::move(image_filter)); |
170 break; | 166 break; |
171 case FilterOperation::SEPIA: | 167 case FilterOperation::SEPIA: |
172 GetSepiaMatrix(1.f - op.amount(), matrix); | 168 GetSepiaMatrix(1.f - op.amount(), matrix); |
173 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 169 image_filter = CreateMatrixImageFilter(matrix, std::move(image_filter)); |
174 break; | 170 break; |
175 case FilterOperation::SATURATE: | 171 case FilterOperation::SATURATE: |
176 GetSaturateMatrix(op.amount(), matrix); | 172 GetSaturateMatrix(op.amount(), matrix); |
177 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 173 image_filter = CreateMatrixImageFilter(matrix, std::move(image_filter)); |
178 break; | 174 break; |
179 case FilterOperation::HUE_ROTATE: | 175 case FilterOperation::HUE_ROTATE: |
180 GetHueRotateMatrix(op.amount(), matrix); | 176 GetHueRotateMatrix(op.amount(), matrix); |
181 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 177 image_filter = CreateMatrixImageFilter(matrix, std::move(image_filter)); |
182 break; | 178 break; |
183 case FilterOperation::INVERT: | 179 case FilterOperation::INVERT: |
184 GetInvertMatrix(op.amount(), matrix); | 180 GetInvertMatrix(op.amount(), matrix); |
185 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 181 image_filter = CreateMatrixImageFilter(matrix, std::move(image_filter)); |
186 break; | 182 break; |
187 case FilterOperation::OPACITY: | 183 case FilterOperation::OPACITY: |
188 GetOpacityMatrix(op.amount(), matrix); | 184 GetOpacityMatrix(op.amount(), matrix); |
189 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 185 image_filter = CreateMatrixImageFilter(matrix, std::move(image_filter)); |
190 break; | 186 break; |
191 case FilterOperation::BRIGHTNESS: | 187 case FilterOperation::BRIGHTNESS: |
192 GetBrightnessMatrix(op.amount(), matrix); | 188 GetBrightnessMatrix(op.amount(), matrix); |
193 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 189 image_filter = CreateMatrixImageFilter(matrix, std::move(image_filter)); |
194 break; | 190 break; |
195 case FilterOperation::CONTRAST: | 191 case FilterOperation::CONTRAST: |
196 GetContrastMatrix(op.amount(), matrix); | 192 GetContrastMatrix(op.amount(), matrix); |
197 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 193 image_filter = CreateMatrixImageFilter(matrix, std::move(image_filter)); |
198 break; | 194 break; |
199 case FilterOperation::BLUR: | 195 case FilterOperation::BLUR: |
200 image_filter = skia::AdoptRef(SkBlurImageFilter::Create( | 196 image_filter = SkBlurImageFilter::Make(op.amount(), op.amount(), |
201 op.amount(), op.amount(), image_filter.get())); | 197 std::move(image_filter)); |
202 break; | 198 break; |
203 case FilterOperation::DROP_SHADOW: | 199 case FilterOperation::DROP_SHADOW: |
204 image_filter = skia::AdoptRef(SkDropShadowImageFilter::Create( | 200 image_filter = SkDropShadowImageFilter::Make( |
205 SkIntToScalar(op.drop_shadow_offset().x()), | 201 SkIntToScalar(op.drop_shadow_offset().x()), |
206 SkIntToScalar(op.drop_shadow_offset().y()), | 202 SkIntToScalar(op.drop_shadow_offset().y()), |
207 SkIntToScalar(op.amount()), | 203 SkIntToScalar(op.amount()), SkIntToScalar(op.amount()), |
208 SkIntToScalar(op.amount()), | |
209 op.drop_shadow_color(), | 204 op.drop_shadow_color(), |
210 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, | 205 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, |
211 image_filter.get())); | 206 std::move(image_filter)); |
212 break; | 207 break; |
213 case FilterOperation::COLOR_MATRIX: | 208 case FilterOperation::COLOR_MATRIX: |
214 image_filter = CreateMatrixImageFilter(op.matrix(), image_filter); | 209 image_filter = |
| 210 CreateMatrixImageFilter(op.matrix(), std::move(image_filter)); |
215 break; | 211 break; |
216 case FilterOperation::ZOOM: { | 212 case FilterOperation::ZOOM: { |
217 skia::RefPtr<SkImageFilter> zoom_filter = | 213 sk_sp<SkImageFilter> zoom_filter(SkMagnifierImageFilter::Make( |
218 skia::AdoptRef(SkMagnifierImageFilter::Create( | 214 SkRect::MakeXYWH( |
219 SkRect::MakeXYWH( | 215 (size.width() - (size.width() / op.amount())) / 2.f, |
220 (size.width() - (size.width() / op.amount())) / 2.f, | 216 (size.height() - (size.height() / op.amount())) / 2.f, |
221 (size.height() - (size.height() / op.amount())) / 2.f, | 217 size.width() / op.amount(), size.height() / op.amount()), |
222 size.width() / op.amount(), | 218 op.zoom_inset(), nullptr)); |
223 size.height() / op.amount()), | 219 if (image_filter) { |
224 op.zoom_inset())); | |
225 if (image_filter.get()) { | |
226 // TODO(ajuma): When there's a 1-input version of | 220 // TODO(ajuma): When there's a 1-input version of |
227 // SkMagnifierImageFilter, use that to handle the input filter | 221 // SkMagnifierImageFilter, use that to handle the input filter |
228 // instead of using an SkComposeImageFilter. | 222 // instead of using an SkComposeImageFilter. |
229 image_filter = skia::AdoptRef(SkComposeImageFilter::Create( | 223 image_filter = SkComposeImageFilter::Make(std::move(zoom_filter), |
230 zoom_filter.get(), image_filter.get())); | 224 std::move(image_filter)); |
231 } else { | 225 } else { |
232 image_filter = zoom_filter; | 226 image_filter = std::move(zoom_filter); |
233 } | 227 } |
234 break; | 228 break; |
235 } | 229 } |
236 case FilterOperation::SATURATING_BRIGHTNESS: | 230 case FilterOperation::SATURATING_BRIGHTNESS: |
237 GetSaturatingBrightnessMatrix(op.amount(), matrix); | 231 GetSaturatingBrightnessMatrix(op.amount(), matrix); |
238 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 232 image_filter = CreateMatrixImageFilter(matrix, std::move(image_filter)); |
239 break; | 233 break; |
240 case FilterOperation::REFERENCE: { | 234 case FilterOperation::REFERENCE: { |
241 if (!op.image_filter()) | 235 if (!op.image_filter()) |
242 break; | 236 break; |
243 | 237 |
244 skia::RefPtr<SkColorFilter> cf; | 238 sk_sp<SkColorFilter> cf; |
245 | 239 |
246 { | 240 { |
247 SkColorFilter* colorfilter_rawptr = NULL; | 241 SkColorFilter* colorfilter_rawptr = NULL; |
248 op.image_filter()->asColorFilter(&colorfilter_rawptr); | 242 op.image_filter()->asColorFilter(&colorfilter_rawptr); |
249 cf = skia::AdoptRef(colorfilter_rawptr); | 243 cf.reset(colorfilter_rawptr); |
250 } | 244 } |
251 | 245 |
252 if (cf && cf->asColorMatrix(matrix) && | 246 if (cf && cf->asColorMatrix(matrix) && |
253 !op.image_filter()->getInput(0)) { | 247 !op.image_filter()->getInput(0)) { |
254 image_filter = CreateMatrixImageFilter(matrix, image_filter); | 248 image_filter = |
| 249 CreateMatrixImageFilter(matrix, std::move(image_filter)); |
255 } else if (image_filter) { | 250 } else if (image_filter) { |
256 image_filter = skia::AdoptRef(SkComposeImageFilter::Create( | 251 image_filter = SkComposeImageFilter::Make(op.image_filter(), |
257 op.image_filter().get(), image_filter.get())); | 252 std::move(image_filter)); |
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())); | 261 if (image_filter) { |
267 if (image_filter.get()) { | 262 image_filter = SkComposeImageFilter::Make(std::move(alpha_filter), |
268 image_filter = skia::AdoptRef(SkComposeImageFilter::Create( | 263 std::move(image_filter)); |
269 alpha_filter.get(), image_filter.get())); | |
270 } else { | 264 } else { |
271 image_filter = alpha_filter; | 265 image_filter = std::move(alpha_filter); |
272 } | 266 } |
273 break; | 267 break; |
274 } | 268 } |
275 } | 269 } |
276 } | 270 } |
277 return image_filter; | 271 return image_filter; |
278 } | 272 } |
279 | 273 |
280 } // namespace cc | 274 } // namespace cc |
OLD | NEW |