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