| 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 "SkComposeImageFilter.h" | 15 #include "SkComposeImageFilter.h" |
| 16 #include "SkDeviceImageFilterProxy.h" | |
| 17 #include "SkDisplacementMapEffect.h" | 16 #include "SkDisplacementMapEffect.h" |
| 18 #include "SkDropShadowImageFilter.h" | 17 #include "SkDropShadowImageFilter.h" |
| 19 #include "SkFlattenableSerialization.h" | 18 #include "SkFlattenableSerialization.h" |
| 20 #include "SkGradientShader.h" | 19 #include "SkGradientShader.h" |
| 21 #include "SkLightingImageFilter.h" | 20 #include "SkLightingImageFilter.h" |
| 22 #include "SkMatrixConvolutionImageFilter.h" | 21 #include "SkMatrixConvolutionImageFilter.h" |
| 23 #include "SkMergeImageFilter.h" | 22 #include "SkMergeImageFilter.h" |
| 24 #include "SkMorphologyImageFilter.h" | 23 #include "SkMorphologyImageFilter.h" |
| 25 #include "SkOffsetImageFilter.h" | 24 #include "SkOffsetImageFilter.h" |
| 26 #include "SkPerlinNoiseShader.h" | 25 #include "SkPerlinNoiseShader.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 264 } |
| 266 } | 265 } |
| 267 | 266 |
| 268 static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter)
{ | 267 static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter)
{ |
| 269 // Check that all filters offset to their absolute crop rect, | 268 // Check that all filters offset to their absolute crop rect, |
| 270 // unaffected by the input crop rect. | 269 // unaffected by the input crop rect. |
| 271 // Tests pass by not asserting. | 270 // Tests pass by not asserting. |
| 272 SkBitmap bitmap; | 271 SkBitmap bitmap; |
| 273 bitmap.allocN32Pixels(100, 100); | 272 bitmap.allocN32Pixels(100, 100); |
| 274 bitmap.eraseARGB(0, 0, 0, 0); | 273 bitmap.eraseARGB(0, 0, 0, 0); |
| 275 SkDeviceImageFilterProxy proxy(device, SkSurfaceProps(SkSurfaceProps::kLegac
yFontHost_InitType)); | 274 SkImageFilter::Proxy proxy(device, SkSurfaceProps(SkSurfaceProps::kLegacyFon
tHost_InitType)); |
| 276 | 275 |
| 277 SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80)); | 276 SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80)); |
| 278 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60)); | 277 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60)); |
| 279 SkAutoTUnref<SkImageFilter> input(make_grayscale(NULL, &inputCropRect)); | 278 SkAutoTUnref<SkImageFilter> input(make_grayscale(NULL, &inputCropRect)); |
| 280 | 279 |
| 281 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
SkXfermode::kSrcIn_Mode)); | 280 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
SkXfermode::kSrcIn_Mode)); |
| 282 SkPoint3 location(0, 0, SK_Scalar1); | 281 SkPoint3 location(0, 0, SK_Scalar1); |
| 283 SkPoint3 target(SK_Scalar1, SK_Scalar1, SK_Scalar1); | 282 SkPoint3 target(SK_Scalar1, SK_Scalar1, SK_Scalar1); |
| 284 SkScalar kernel[9] = { | 283 SkScalar kernel[9] = { |
| 285 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | 284 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 SkPaint paint; | 344 SkPaint paint; |
| 346 paint.setShader(shader); | 345 paint.setShader(shader); |
| 347 canvas.drawCircle(x, y, radius, paint); | 346 canvas.drawCircle(x, y, radius, paint); |
| 348 return bitmap; | 347 return bitmap; |
| 349 } | 348 } |
| 350 | 349 |
| 351 static void test_negative_blur_sigma(SkBaseDevice* device, skiatest::Reporter* r
eporter) { | 350 static void test_negative_blur_sigma(SkBaseDevice* device, skiatest::Reporter* r
eporter) { |
| 352 // Check that SkBlurImageFilter will accept a negative sigma, either in | 351 // Check that SkBlurImageFilter will accept a negative sigma, either in |
| 353 // the given arguments or after CTM application. | 352 // the given arguments or after CTM application. |
| 354 int width = 32, height = 32; | 353 int width = 32, height = 32; |
| 355 SkDeviceImageFilterProxy proxy(device, SkSurfaceProps(SkSurfaceProps::kLegac
yFontHost_InitType)); | 354 SkImageFilter::Proxy proxy(device, SkSurfaceProps(SkSurfaceProps::kLegacyFon
tHost_InitType)); |
| 356 SkScalar five = SkIntToScalar(5); | 355 SkScalar five = SkIntToScalar(5); |
| 357 | 356 |
| 358 SkAutoTUnref<SkBlurImageFilter> positiveFilter( | 357 SkAutoTUnref<SkBlurImageFilter> positiveFilter( |
| 359 SkBlurImageFilter::Create(five, five) | 358 SkBlurImageFilter::Create(five, five) |
| 360 ); | 359 ); |
| 361 | 360 |
| 362 SkAutoTUnref<SkBlurImageFilter> negativeFilter( | 361 SkAutoTUnref<SkBlurImageFilter> negativeFilter( |
| 363 SkBlurImageFilter::Create(-five, five) | 362 SkBlurImageFilter::Create(-five, five) |
| 364 ); | 363 ); |
| 365 | 364 |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 | 880 |
| 882 SkAutoTUnref<SkImageFilter> imageFilter( | 881 SkAutoTUnref<SkImageFilter> imageFilter( |
| 883 SkPictureImageFilter::Create(picture.get())); | 882 SkPictureImageFilter::Create(picture.get())); |
| 884 | 883 |
| 885 SkBitmap result; | 884 SkBitmap result; |
| 886 SkIPoint offset; | 885 SkIPoint offset; |
| 887 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), NUL
L); | 886 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), NUL
L); |
| 888 SkBitmap bitmap; | 887 SkBitmap bitmap; |
| 889 bitmap.allocN32Pixels(2, 2); | 888 bitmap.allocN32Pixels(2, 2); |
| 890 SkBitmapDevice device(bitmap); | 889 SkBitmapDevice device(bitmap); |
| 891 SkDeviceImageFilterProxy proxy(&device, SkSurfaceProps(SkSurfaceProps::kLega
cyFontHost_InitType)); | 890 SkImageFilter::Proxy proxy(&device, SkSurfaceProps(SkSurfaceProps::kLegacyFo
ntHost_InitType)); |
| 892 REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, bitmap, ctx, &re
sult, &offset)); | 891 REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, bitmap, ctx, &re
sult, &offset)); |
| 893 } | 892 } |
| 894 | 893 |
| 895 DEF_TEST(ImageFilterEmptySaveLayer, reporter) { | 894 DEF_TEST(ImageFilterEmptySaveLayer, reporter) { |
| 896 // Even when there's an empty saveLayer()/restore(), ensure that an image | 895 // Even when there's an empty saveLayer()/restore(), ensure that an image |
| 897 // filter or color filter which affects transparent black still draws. | 896 // filter or color filter which affects transparent black still draws. |
| 898 | 897 |
| 899 SkBitmap bitmap; | 898 SkBitmap bitmap; |
| 900 bitmap.allocN32Pixels(10, 10); | 899 bitmap.allocN32Pixels(10, 10); |
| 901 SkBitmapDevice device(bitmap); | 900 SkBitmapDevice device(bitmap); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 temp.allocN32Pixels(100, 100); | 1123 temp.allocN32Pixels(100, 100); |
| 1125 SkBitmapDevice device(temp); | 1124 SkBitmapDevice device(temp); |
| 1126 test_xfermode_cropped_input(&device, reporter); | 1125 test_xfermode_cropped_input(&device, reporter); |
| 1127 } | 1126 } |
| 1128 | 1127 |
| 1129 DEF_TEST(ComposedImageFilterOffset, reporter) { | 1128 DEF_TEST(ComposedImageFilterOffset, reporter) { |
| 1130 SkBitmap bitmap; | 1129 SkBitmap bitmap; |
| 1131 bitmap.allocN32Pixels(100, 100); | 1130 bitmap.allocN32Pixels(100, 100); |
| 1132 bitmap.eraseARGB(0, 0, 0, 0); | 1131 bitmap.eraseARGB(0, 0, 0, 0); |
| 1133 SkBitmapDevice device(bitmap); | 1132 SkBitmapDevice device(bitmap); |
| 1134 SkDeviceImageFilterProxy proxy(&device, SkSurfaceProps(SkSurfaceProps::kLega
cyFontHost_InitType)); | 1133 SkImageFilter::Proxy proxy(&device, SkSurfaceProps(SkSurfaceProps::kLegacyFo
ntHost_InitType)); |
| 1135 | 1134 |
| 1136 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); | 1135 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); |
| 1137 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, N
ULL, &cropRect)); | 1136 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, N
ULL, &cropRect)); |
| 1138 SkAutoTUnref<SkImageFilter> blurFilter(makeBlur()); | 1137 SkAutoTUnref<SkImageFilter> blurFilter(makeBlur()); |
| 1139 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur
Filter, offsetFilter.get())); | 1138 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur
Filter, offsetFilter.get())); |
| 1140 SkBitmap result; | 1139 SkBitmap result; |
| 1141 SkIPoint offset; | 1140 SkIPoint offset; |
| 1142 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL); | 1141 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL); |
| 1143 REPORTER_ASSERT(reporter, composedFilter->filterImage(&proxy, bitmap, ctx, &
result, &offset)); | 1142 REPORTER_ASSERT(reporter, composedFilter->filterImage(&proxy, bitmap, ctx, &
result, &offset)); |
| 1144 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); | 1143 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 return; | 1191 return; |
| 1193 } | 1192 } |
| 1194 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 1193 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
| 1195 SkSurface::kNo_Budgeted
, | 1194 SkSurface::kNo_Budgeted
, |
| 1196 SkImageInfo::MakeN32Pre
mul(1, 1), | 1195 SkImageInfo::MakeN32Pre
mul(1, 1), |
| 1197 0, | 1196 0, |
| 1198 &gProps)); | 1197 &gProps)); |
| 1199 test_negative_blur_sigma(device, reporter); | 1198 test_negative_blur_sigma(device, reporter); |
| 1200 } | 1199 } |
| 1201 #endif | 1200 #endif |
| OLD | NEW |