OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapDevice.h" | 9 #include "SkBitmapDevice.h" |
10 #include "SkBitmapSource.h" | 10 #include "SkBitmapSource.h" |
11 #include "SkBlurImageFilter.h" | 11 #include "SkBlurImageFilter.h" |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
13 #include "SkColorFilterImageFilter.h" | 13 #include "SkColorFilterImageFilter.h" |
14 #include "SkColorMatrixFilter.h" | 14 #include "SkColorMatrixFilter.h" |
15 #include "SkDeviceImageFilterProxy.h" | 15 #include "SkDeviceImageFilterProxy.h" |
16 #include "SkDisplacementMapEffect.h" | 16 #include "SkDisplacementMapEffect.h" |
17 #include "SkDropShadowImageFilter.h" | 17 #include "SkDropShadowImageFilter.h" |
18 #include "SkFlattenableSerialization.h" | 18 #include "SkFlattenableSerialization.h" |
19 #include "SkGradientShader.h" | 19 #include "SkGradientShader.h" |
| 20 #include "SkImagePriv.h" |
| 21 #include "SkImage_Base.h" |
20 #include "SkLightingImageFilter.h" | 22 #include "SkLightingImageFilter.h" |
21 #include "SkMatrixConvolutionImageFilter.h" | 23 #include "SkMatrixConvolutionImageFilter.h" |
22 #include "SkMatrixImageFilter.h" | 24 #include "SkMatrixImageFilter.h" |
23 #include "SkMergeImageFilter.h" | 25 #include "SkMergeImageFilter.h" |
24 #include "SkMorphologyImageFilter.h" | 26 #include "SkMorphologyImageFilter.h" |
25 #include "SkOffsetImageFilter.h" | 27 #include "SkOffsetImageFilter.h" |
26 #include "SkPerlinNoiseShader.h" | 28 #include "SkPerlinNoiseShader.h" |
27 #include "SkPicture.h" | 29 #include "SkPicture.h" |
28 #include "SkPictureImageFilter.h" | 30 #include "SkPictureImageFilter.h" |
29 #include "SkPictureRecorder.h" | 31 #include "SkPictureRecorder.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 SkIntToScalar(kBitmapSize)); | 228 SkIntToScalar(kBitmapSize)); |
227 canvas.drawRect(r, paint); | 229 canvas.drawRect(r, paint); |
228 } | 230 } |
229 } | 231 } |
230 } | 232 } |
231 | 233 |
232 static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter)
{ | 234 static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter)
{ |
233 // Check that all filters offset to their absolute crop rect, | 235 // Check that all filters offset to their absolute crop rect, |
234 // unaffected by the input crop rect. | 236 // unaffected by the input crop rect. |
235 // Tests pass by not asserting. | 237 // Tests pass by not asserting. |
236 SkBitmap bitmap; | 238 SkAutoTUnref<SkImage> image; |
237 bitmap.allocN32Pixels(100, 100); | 239 { |
238 bitmap.eraseARGB(0, 0, 0, 0); | 240 SkBitmap bitmap; |
| 241 bitmap.allocN32Pixels(100, 100); |
| 242 bitmap.eraseARGB(0, 0, 0, 0); |
| 243 image.reset(SkNewImageFromBitmap(bitmap, true, NULL)); |
| 244 REPORTER_ASSERT(reporter, image != NULL); |
| 245 } |
239 SkDeviceImageFilterProxy proxy(device, SkSurfaceProps(SkSurfaceProps::kLegac
yFontHost_InitType)); | 246 SkDeviceImageFilterProxy proxy(device, SkSurfaceProps(SkSurfaceProps::kLegac
yFontHost_InitType)); |
240 | 247 |
241 SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80)); | 248 SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80)); |
242 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60)); | 249 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60)); |
243 SkAutoTUnref<SkImageFilter> input(make_grayscale(NULL, &inputCropRect)); | 250 SkAutoTUnref<SkImageFilter> input(make_grayscale(NULL, &inputCropRect)); |
244 | 251 |
245 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
SkXfermode::kSrcIn_Mode)); | 252 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
SkXfermode::kSrcIn_Mode)); |
246 SkPoint3 location(0, 0, SK_Scalar1); | 253 SkPoint3 location(0, 0, SK_Scalar1); |
247 SkPoint3 target(SK_Scalar1, SK_Scalar1, SK_Scalar1); | 254 SkPoint3 target(SK_Scalar1, SK_Scalar1, SK_Scalar1); |
248 SkScalar kernel[9] = { | 255 SkScalar kernel[9] = { |
(...skipping 20 matching lines...) Expand all Loading... |
269 SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, input.get(), &cropRe
ct), | 276 SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, input.get(), &cropRe
ct), |
270 SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, input.get(), &cropRe
ct), | 277 SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, input.get(), &cropRe
ct), |
271 SkDilateImageFilter::Create(3, 2, input.get(), &cropRect), | 278 SkDilateImageFilter::Create(3, 2, input.get(), &cropRect), |
272 SkErodeImageFilter::Create(2, 3, input.get(), &cropRect), | 279 SkErodeImageFilter::Create(2, 3, input.get(), &cropRect), |
273 SkTileImageFilter::Create(inputCropRect.rect(), cropRect.rect(), input.g
et()), | 280 SkTileImageFilter::Create(inputCropRect.rect(), cropRect.rect(), input.g
et()), |
274 SkXfermodeImageFilter::Create(SkXfermode::Create(SkXfermode::kSrcOver_Mo
de), input.get(), input.get(), &cropRect), | 281 SkXfermodeImageFilter::Create(SkXfermode::Create(SkXfermode::kSrcOver_Mo
de), input.get(), input.get(), &cropRect), |
275 }; | 282 }; |
276 | 283 |
277 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 284 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
278 SkImageFilter* filter = filters[i]; | 285 SkImageFilter* filter = filters[i]; |
279 SkBitmap result; | 286 SkAutoTUnref<SkImage> result; |
280 SkIPoint offset; | 287 SkIPoint offset; |
281 SkString str; | 288 SkString str; |
282 str.printf("filter %d", static_cast<int>(i)); | 289 str.printf("filter %d", static_cast<int>(i)); |
283 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL); | 290 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL); |
284 REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(&proxy, bitmap, ct
x, | 291 REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(&proxy, *image, ct
x, |
285 &result, &offset), str.c_str()); | 292 result, &offset), str.c_str()); |
286 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st
r.c_str()); | 293 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st
r.c_str()); |
287 } | 294 } |
288 | 295 |
289 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 296 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
290 SkSafeUnref(filters[i]); | 297 SkSafeUnref(filters[i]); |
291 } | 298 } |
292 } | 299 } |
293 | 300 |
294 static SkBitmap make_gradient_circle(int width, int height) { | 301 static SkBitmap make_gradient_circle(int width, int height) { |
295 SkBitmap bitmap; | 302 SkBitmap bitmap; |
296 SkScalar x = SkIntToScalar(width / 2); | 303 SkScalar x = SkIntToScalar(width / 2); |
297 SkScalar y = SkIntToScalar(height / 2); | 304 SkScalar y = SkIntToScalar(height / 2); |
298 SkScalar radius = SkMinScalar(x, y) * 0.8f; | 305 SkScalar radius = SkMinScalar(x, y) * 0.8f; |
299 bitmap.allocN32Pixels(width, height); | 306 bitmap.allocN32Pixels(width, height); |
300 SkCanvas canvas(bitmap); | 307 SkCanvas canvas(bitmap); |
301 canvas.clear(0x00000000); | 308 canvas.clear(0x00000000); |
302 SkColor colors[2]; | 309 SkColor colors[2]; |
303 colors[0] = SK_ColorWHITE; | 310 colors[0] = SK_ColorWHITE; |
304 colors[1] = SK_ColorBLACK; | 311 colors[1] = SK_ColorBLACK; |
305 SkAutoTUnref<SkShader> shader( | 312 SkAutoTUnref<SkShader> shader( |
306 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, NULL
, 2, | 313 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, NULL
, 2, |
307 SkShader::kClamp_TileMode) | 314 SkShader::kClamp_TileMode) |
308 ); | 315 ); |
309 SkPaint paint; | 316 SkPaint paint; |
310 paint.setShader(shader); | 317 paint.setShader(shader); |
311 canvas.drawCircle(x, y, radius, paint); | 318 canvas.drawCircle(x, y, radius, paint); |
312 return bitmap; | 319 return bitmap; |
313 } | 320 } |
314 | 321 |
| 322 |
315 static void test_negative_blur_sigma(SkBaseDevice* device, skiatest::Reporter* r
eporter) { | 323 static void test_negative_blur_sigma(SkBaseDevice* device, skiatest::Reporter* r
eporter) { |
316 // Check that SkBlurImageFilter will accept a negative sigma, either in | 324 // Check that SkBlurImageFilter will accept a negative sigma, either in |
317 // the given arguments or after CTM application. | 325 // the given arguments or after CTM application. |
318 int width = 32, height = 32; | 326 int width = 32, height = 32; |
319 SkDeviceImageFilterProxy proxy(device, SkSurfaceProps(SkSurfaceProps::kLegac
yFontHost_InitType)); | 327 SkDeviceImageFilterProxy proxy(device, SkSurfaceProps(SkSurfaceProps::kLegac
yFontHost_InitType)); |
320 SkScalar five = SkIntToScalar(5); | 328 SkScalar five = SkIntToScalar(5); |
321 | 329 |
322 SkAutoTUnref<SkBlurImageFilter> positiveFilter( | 330 SkAutoTUnref<SkBlurImageFilter> positiveFilter( |
323 SkBlurImageFilter::Create(five, five) | 331 SkBlurImageFilter::Create(five, five) |
324 ); | 332 ); |
325 | 333 |
326 SkAutoTUnref<SkBlurImageFilter> negativeFilter( | 334 SkAutoTUnref<SkBlurImageFilter> negativeFilter( |
327 SkBlurImageFilter::Create(-five, five) | 335 SkBlurImageFilter::Create(-five, five) |
328 ); | 336 ); |
329 | 337 |
330 SkBitmap gradient = make_gradient_circle(width, height); | |
331 SkBitmap positiveResult1, negativeResult1; | 338 SkBitmap positiveResult1, negativeResult1; |
332 SkBitmap positiveResult2, negativeResult2; | 339 SkBitmap positiveResult2, negativeResult2; |
333 SkIPoint offset; | 340 { |
334 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL); | 341 SkAutoTUnref<SkImage> gradient( |
335 positiveFilter->filterImage(&proxy, gradient, ctx, &positiveResult1, &offset
); | 342 SkNewImageFromBitmap(make_gradient_circle(width, height), true, NULL
)); |
336 negativeFilter->filterImage(&proxy, gradient, ctx, &negativeResult1, &offset
); | 343 SkAutoTUnref<SkImage> positiveResult1i, negativeResult1i; |
337 SkMatrix negativeScale; | 344 SkAutoTUnref<SkImage> positiveResult2i, negativeResult2i; |
338 negativeScale.setScale(-SK_Scalar1, SK_Scalar1); | 345 SkIPoint offset; |
339 SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeLargest(), NU
LL); | 346 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL); |
340 positiveFilter->filterImage(&proxy, gradient, negativeCTX, &negativeResult2,
&offset); | 347 positiveFilter->filterImage(&proxy, *gradient, ctx, positiveResult1i, &o
ffset); |
341 negativeFilter->filterImage(&proxy, gradient, negativeCTX, &positiveResult2,
&offset); | 348 negativeFilter->filterImage(&proxy, *gradient, ctx, negativeResult1i, &o
ffset); |
| 349 SkMatrix negativeScale; |
| 350 negativeScale.setScale(-SK_Scalar1, SK_Scalar1); |
| 351 SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeLargest()
, NULL); |
| 352 positiveFilter->filterImage(&proxy, *gradient, negativeCTX, negativeResu
lt2i, &offset); |
| 353 negativeFilter->filterImage(&proxy, *gradient, negativeCTX, positiveResu
lt2i, &offset); |
| 354 REPORTER_ASSERT(reporter, as_IB(positiveResult1i)->getROPixels(&positive
Result1)); |
| 355 REPORTER_ASSERT(reporter, as_IB(positiveResult2i)->getROPixels(&positive
Result2)); |
| 356 REPORTER_ASSERT(reporter, as_IB(negativeResult1i)->getROPixels(&negative
Result1)); |
| 357 REPORTER_ASSERT(reporter, as_IB(negativeResult2i)->getROPixels(&negative
Result2)); |
| 358 } |
| 359 |
342 SkAutoLockPixels lockP1(positiveResult1); | 360 SkAutoLockPixels lockP1(positiveResult1); |
343 SkAutoLockPixels lockP2(positiveResult2); | 361 SkAutoLockPixels lockP2(positiveResult2); |
344 SkAutoLockPixels lockN1(negativeResult1); | 362 SkAutoLockPixels lockN1(negativeResult1); |
345 SkAutoLockPixels lockN2(negativeResult2); | 363 SkAutoLockPixels lockN2(negativeResult2); |
346 for (int y = 0; y < height; y++) { | 364 for (int y = 0; y < height; y++) { |
347 int diffs = memcmp(positiveResult1.getAddr32(0, y), negativeResult1.getA
ddr32(0, y), positiveResult1.rowBytes()); | 365 int diffs = memcmp(positiveResult1.getAddr32(0, y), negativeResult1.getA
ddr32(0, y), positiveResult1.rowBytes()); |
348 REPORTER_ASSERT(reporter, !diffs); | 366 REPORTER_ASSERT(reporter, !diffs); |
349 if (diffs) { | 367 if (diffs) { |
350 break; | 368 break; |
351 } | 369 } |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 | 835 |
818 // Create an SkPicture which simply draws a green 1x1 rectangle. | 836 // Create an SkPicture which simply draws a green 1x1 rectangle. |
819 SkPaint greenPaint; | 837 SkPaint greenPaint; |
820 greenPaint.setColor(SK_ColorGREEN); | 838 greenPaint.setColor(SK_ColorGREEN); |
821 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint); | 839 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint); |
822 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 840 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
823 | 841 |
824 SkAutoTUnref<SkImageFilter> imageFilter( | 842 SkAutoTUnref<SkImageFilter> imageFilter( |
825 SkPictureImageFilter::Create(picture.get())); | 843 SkPictureImageFilter::Create(picture.get())); |
826 | 844 |
827 SkBitmap result; | 845 SkAutoTUnref<SkImage> result; |
828 SkIPoint offset; | 846 SkIPoint offset; |
829 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), NUL
L); | 847 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), NUL
L); |
| 848 SkAutoTUnref<SkImage> image; |
830 SkBitmap bitmap; | 849 SkBitmap bitmap; |
831 bitmap.allocN32Pixels(2, 2); | 850 bitmap.allocN32Pixels(2, 2); |
| 851 image.reset(SkNewImageFromBitmap(bitmap, true, NULL)); |
832 SkBitmapDevice device(bitmap); | 852 SkBitmapDevice device(bitmap); |
833 SkDeviceImageFilterProxy proxy(&device, SkSurfaceProps(SkSurfaceProps::kLega
cyFontHost_InitType)); | 853 SkDeviceImageFilterProxy proxy(&device, SkSurfaceProps(SkSurfaceProps::kLega
cyFontHost_InitType)); |
834 REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, bitmap, ctx, &re
sult, &offset)); | 854 REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, *image, ctx, res
ult, &offset)); |
835 } | 855 } |
836 | 856 |
837 DEF_TEST(ImageFilterEmptySaveLayer, reporter) { | 857 DEF_TEST(ImageFilterEmptySaveLayer, reporter) { |
838 // Even when there's an empty saveLayer()/restore(), ensure that an image | 858 // Even when there's an empty saveLayer()/restore(), ensure that an image |
839 // filter or color filter which affects transparent black still draws. | 859 // filter or color filter which affects transparent black still draws. |
840 | 860 |
841 SkBitmap bitmap; | 861 SkBitmap bitmap; |
842 bitmap.allocN32Pixels(10, 10); | 862 bitmap.allocN32Pixels(10, 10); |
843 SkBitmapDevice device(bitmap); | 863 SkBitmapDevice device(bitmap); |
844 SkCanvas canvas(&device); | 864 SkCanvas canvas(&device); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) { | 1124 DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) { |
1105 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); | 1125 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
1106 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 1126 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
1107 SkSurface::kNo_Budgeted
, | 1127 SkSurface::kNo_Budgeted
, |
1108 SkImageInfo::MakeN32Pre
mul(1, 1), | 1128 SkImageInfo::MakeN32Pre
mul(1, 1), |
1109 0, | 1129 0, |
1110 &gProps)); | 1130 &gProps)); |
1111 test_negative_blur_sigma(device, reporter); | 1131 test_negative_blur_sigma(device, reporter); |
1112 } | 1132 } |
1113 #endif | 1133 #endif |
OLD | NEW |