Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include "SkMorphologyImageFilter.h" | 25 #include "SkMorphologyImageFilter.h" |
| 26 #include "SkOffsetImageFilter.h" | 26 #include "SkOffsetImageFilter.h" |
| 27 #include "SkPaintImageFilter.h" | 27 #include "SkPaintImageFilter.h" |
| 28 #include "SkPerlinNoiseShader.h" | 28 #include "SkPerlinNoiseShader.h" |
| 29 #include "SkPicture.h" | 29 #include "SkPicture.h" |
| 30 #include "SkPictureImageFilter.h" | 30 #include "SkPictureImageFilter.h" |
| 31 #include "SkPictureRecorder.h" | 31 #include "SkPictureRecorder.h" |
| 32 #include "SkPoint3.h" | 32 #include "SkPoint3.h" |
| 33 #include "SkReadBuffer.h" | 33 #include "SkReadBuffer.h" |
| 34 #include "SkRect.h" | 34 #include "SkRect.h" |
| 35 #include "SkSpecialImage.h" | |
| 36 #include "SkSpecialSurface.h" | |
| 35 #include "SkSurface.h" | 37 #include "SkSurface.h" |
| 36 #include "SkTableColorFilter.h" | 38 #include "SkTableColorFilter.h" |
| 37 #include "SkTileImageFilter.h" | 39 #include "SkTileImageFilter.h" |
| 38 #include "SkXfermodeImageFilter.h" | 40 #include "SkXfermodeImageFilter.h" |
| 39 #include "Test.h" | 41 #include "Test.h" |
| 42 #include "TestingSpecialImageAccess.h" | |
| 40 | 43 |
| 41 #if SK_SUPPORT_GPU | 44 #if SK_SUPPORT_GPU |
| 42 #include "GrContext.h" | 45 #include "GrContext.h" |
| 43 #include "SkGpuDevice.h" | 46 #include "SkGpuDevice.h" |
| 44 #endif | 47 #endif |
| 45 | 48 |
| 46 static const int kBitmapSize = 4; | 49 static const int kBitmapSize = 4; |
| 47 | 50 |
| 48 namespace { | 51 namespace { |
| 49 | 52 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix)); | 151 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix)); |
| 149 return SkColorFilterImageFilter::Create(filter, input, cropRect); | 152 return SkColorFilterImageFilter::Create(filter, input, cropRect); |
| 150 } | 153 } |
| 151 | 154 |
| 152 static SkImageFilter* make_blue(SkImageFilter* input, const SkImageFilter::CropR ect* cropRect) { | 155 static SkImageFilter* make_blue(SkImageFilter* input, const SkImageFilter::CropR ect* cropRect) { |
| 153 SkAutoTUnref<SkColorFilter> filter(SkColorFilter::CreateModeFilter(SK_ColorB LUE, | 156 SkAutoTUnref<SkColorFilter> filter(SkColorFilter::CreateModeFilter(SK_ColorB LUE, |
| 154 SkXfermod e::kSrcIn_Mode)); | 157 SkXfermod e::kSrcIn_Mode)); |
| 155 return SkColorFilterImageFilter::Create(filter, input, cropRect); | 158 return SkColorFilterImageFilter::Create(filter, input, cropRect); |
| 156 } | 159 } |
| 157 | 160 |
| 161 static SkSpecialImage* create_empty_special_image(GrContext* context, | |
| 162 SkImageFilter::Proxy* proxy, | |
| 163 int widthHeight) { | |
| 164 SkAutoTUnref<SkSpecialSurface> surf; | |
| 165 | |
| 166 if (context) { | |
| 167 GrSurfaceDesc desc; | |
| 168 desc.fConfig = kSkia8888_GrPixelConfig; | |
| 169 desc.fFlags = kRenderTarget_GrSurfaceFlag; | |
| 170 desc.fWidth = widthHeight; | |
| 171 desc.fHeight = widthHeight; | |
| 172 surf.reset(SkSpecialSurface::NewRenderTarget(proxy, context, desc)); | |
| 173 } else { | |
| 174 const SkImageInfo info = SkImageInfo::MakeN32(widthHeight, widthHeight, | |
| 175 kOpaque_SkAlphaType); | |
| 176 surf.reset(SkSpecialSurface::NewRaster(proxy, info)); | |
| 177 } | |
| 178 | |
| 179 SkASSERT(surf); | |
| 180 | |
| 181 SkCanvas* canvas = surf->getCanvas(); | |
| 182 SkASSERT(canvas); | |
| 183 | |
| 184 canvas->clear(0x0); | |
| 185 | |
| 186 return surf->newImageSnapshot(); | |
| 187 } | |
| 188 | |
| 189 | |
| 158 DEF_TEST(ImageFilter, reporter) { | 190 DEF_TEST(ImageFilter, reporter) { |
| 159 { | 191 { |
| 160 // Check that two non-clipping color-matrice-filters concatenate into a single filter. | 192 // Check that two non-clipping color-matrice-filters concatenate into a single filter. |
| 161 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f)); | 193 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f)); |
| 162 SkAutoTUnref<SkImageFilter> quarterBrightness(make_scale(0.5f, halfBrigh tness)); | 194 SkAutoTUnref<SkImageFilter> quarterBrightness(make_scale(0.5f, halfBrigh tness)); |
| 163 REPORTER_ASSERT(reporter, nullptr == quarterBrightness->getInput(0)); | 195 REPORTER_ASSERT(reporter, nullptr == quarterBrightness->getInput(0)); |
| 164 SkColorFilter* cf; | 196 SkColorFilter* cf; |
| 165 REPORTER_ASSERT(reporter, quarterBrightness->asColorFilter(&cf)); | 197 REPORTER_ASSERT(reporter, quarterBrightness->asColorFilter(&cf)); |
| 166 REPORTER_ASSERT(reporter, cf->asColorMatrix(nullptr)); | 198 REPORTER_ASSERT(reporter, cf->asColorMatrix(nullptr)); |
| 167 cf->unref(); | 199 cf->unref(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1, | 296 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1, |
| 265 bmSrc))->unref(); | 297 bmSrc))->unref(); |
| 266 SkCanvas canvas(result); | 298 SkCanvas canvas(result); |
| 267 SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize), | 299 SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize), |
| 268 SkIntToScalar(kBitmapSize)); | 300 SkIntToScalar(kBitmapSize)); |
| 269 canvas.drawRect(r, paint); | 301 canvas.drawRect(r, paint); |
| 270 } | 302 } |
| 271 } | 303 } |
| 272 } | 304 } |
| 273 | 305 |
| 274 static void test_crop_rects(SkImageFilter::Proxy* proxy, skiatest::Reporter* rep orter) { | 306 static void test_crop_rects(SkImageFilter::Proxy* proxy, |
| 307 skiatest::Reporter* reporter, | |
| 308 GrContext* context) { | |
| 275 // Check that all filters offset to their absolute crop rect, | 309 // Check that all filters offset to their absolute crop rect, |
| 276 // unaffected by the input crop rect. | 310 // unaffected by the input crop rect. |
| 277 // Tests pass by not asserting. | 311 // Tests pass by not asserting. |
| 278 SkBitmap bitmap; | 312 SkAutoTUnref<SkSpecialImage> srcImg(create_empty_special_image(context, prox y, 100)); |
| 279 bitmap.allocN32Pixels(100, 100); | 313 SkASSERT(srcImg); |
| 280 bitmap.eraseARGB(0, 0, 0, 0); | |
| 281 | 314 |
| 282 SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80)); | 315 SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80)); |
| 283 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60)); | 316 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60)); |
| 284 SkAutoTUnref<SkImageFilter> input(make_grayscale(nullptr, &inputCropRect)); | 317 SkAutoTUnref<SkImageFilter> input(make_grayscale(nullptr, &inputCropRect)); |
| 285 | 318 |
| 286 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode)); | 319 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode)); |
| 287 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); | 320 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); |
| 288 SkScalar kernel[9] = { | 321 SkScalar kernel[9] = { |
| 289 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | 322 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
| 290 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), | 323 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 309 SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, input.get(), &cropRe ct), | 342 SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, input.get(), &cropRe ct), |
| 310 SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, input.get(), &cropRe ct), | 343 SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, input.get(), &cropRe ct), |
| 311 SkDilateImageFilter::Create(3, 2, input.get(), &cropRect), | 344 SkDilateImageFilter::Create(3, 2, input.get(), &cropRect), |
| 312 SkErodeImageFilter::Create(2, 3, input.get(), &cropRect), | 345 SkErodeImageFilter::Create(2, 3, input.get(), &cropRect), |
| 313 SkTileImageFilter::Create(inputCropRect.rect(), cropRect.rect(), input.g et()), | 346 SkTileImageFilter::Create(inputCropRect.rect(), cropRect.rect(), input.g et()), |
| 314 SkXfermodeImageFilter::Create(SkXfermode::Create(SkXfermode::kSrcOver_Mo de), input.get(), input.get(), &cropRect), | 347 SkXfermodeImageFilter::Create(SkXfermode::Create(SkXfermode::kSrcOver_Mo de), input.get(), input.get(), &cropRect), |
| 315 }; | 348 }; |
| 316 | 349 |
| 317 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 350 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
| 318 SkImageFilter* filter = filters[i]; | 351 SkImageFilter* filter = filters[i]; |
| 319 SkBitmap result; | |
| 320 SkIPoint offset; | 352 SkIPoint offset; |
| 321 SkString str; | 353 SkString str; |
| 322 str.printf("filter %d", static_cast<int>(i)); | 354 str.printf("filter %d", static_cast<int>(i)); |
| 323 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nul lptr); | 355 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nul lptr); |
| 324 REPORTER_ASSERT_MESSAGE(reporter, | 356 SkAutoTUnref<SkSpecialImage> resultImg(filter->filterImage(srcImg, ctx, &offset)); |
| 325 filter->filterImageDeprecated(proxy, bitmap, ctx , | 357 REPORTER_ASSERT_MESSAGE(reporter, resultImg, str.c_str()); |
| 326 &result, &offset), | |
| 327 str.c_str()); | |
| 328 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st r.c_str()); | 358 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st r.c_str()); |
| 329 } | 359 } |
| 330 | 360 |
| 331 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 361 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
| 332 SkSafeUnref(filters[i]); | 362 SkSafeUnref(filters[i]); |
| 333 } | 363 } |
| 334 } | 364 } |
| 335 | 365 |
| 336 static SkBitmap make_gradient_circle(int width, int height) { | 366 static SkBitmap make_gradient_circle(int width, int height) { |
| 337 SkBitmap bitmap; | 367 SkBitmap bitmap; |
| 338 SkScalar x = SkIntToScalar(width / 2); | 368 SkScalar x = SkIntToScalar(width / 2); |
| 339 SkScalar y = SkIntToScalar(height / 2); | 369 SkScalar y = SkIntToScalar(height / 2); |
| 340 SkScalar radius = SkMinScalar(x, y) * 0.8f; | 370 SkScalar radius = SkMinScalar(x, y) * 0.8f; |
| 341 bitmap.allocN32Pixels(width, height); | 371 bitmap.allocN32Pixels(width, height); |
| 342 SkCanvas canvas(bitmap); | 372 SkCanvas canvas(bitmap); |
| 343 canvas.clear(0x00000000); | 373 canvas.clear(0x00000000); |
| 344 SkColor colors[2]; | 374 SkColor colors[2]; |
| 345 colors[0] = SK_ColorWHITE; | 375 colors[0] = SK_ColorWHITE; |
| 346 colors[1] = SK_ColorBLACK; | 376 colors[1] = SK_ColorBLACK; |
| 347 SkAutoTUnref<SkShader> shader( | 377 SkAutoTUnref<SkShader> shader( |
| 348 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, null ptr, 2, | 378 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, null ptr, 2, |
| 349 SkShader::kClamp_TileMode) | 379 SkShader::kClamp_TileMode) |
| 350 ); | 380 ); |
| 351 SkPaint paint; | 381 SkPaint paint; |
| 352 paint.setShader(shader); | 382 paint.setShader(shader); |
| 353 canvas.drawCircle(x, y, radius, paint); | 383 canvas.drawCircle(x, y, radius, paint); |
| 354 return bitmap; | 384 return bitmap; |
| 355 } | 385 } |
| 356 | 386 |
| 357 static void test_negative_blur_sigma(SkImageFilter::Proxy* proxy, skiatest::Repo rter* reporter) { | 387 |
| 388 | |
| 389 static void test_negative_blur_sigma(SkImageFilter::Proxy* proxy, | |
| 390 skiatest::Reporter* reporter, | |
| 391 GrContext* context) { | |
| 358 // Check that SkBlurImageFilter will accept a negative sigma, either in | 392 // Check that SkBlurImageFilter will accept a negative sigma, either in |
| 359 // the given arguments or after CTM application. | 393 // the given arguments or after CTM application. |
| 360 const int width = 32, height = 32; | 394 const int width = 32, height = 32; |
| 361 const SkScalar five = SkIntToScalar(5); | 395 const SkScalar five = SkIntToScalar(5); |
| 362 | 396 |
| 363 SkAutoTUnref<SkImageFilter> positiveFilter(SkBlurImageFilter::Create(five, f ive)); | 397 SkAutoTUnref<SkImageFilter> positiveFilter(SkBlurImageFilter::Create(five, f ive)); |
| 364 SkAutoTUnref<SkImageFilter> negativeFilter(SkBlurImageFilter::Create(-five, five)); | 398 SkAutoTUnref<SkImageFilter> negativeFilter(SkBlurImageFilter::Create(-five, five)); |
| 365 | 399 |
| 366 SkBitmap gradient = make_gradient_circle(width, height); | 400 SkBitmap gradient = make_gradient_circle(width, height); |
| 367 SkBitmap positiveResult1, negativeResult1; | 401 SkAutoTUnref<SkSpecialImage> imgSrc(SkSpecialImage::NewFromRaster(proxy, |
| 368 SkBitmap positiveResult2, negativeResult2; | 402 SkIRect::M akeWH(width, |
| 403 height), | |
| 404 gradient)) ; | |
| 405 | |
| 369 SkIPoint offset; | 406 SkIPoint offset; |
| 370 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr); | 407 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr); |
| 371 REPORTER_ASSERT(reporter, | 408 |
| 372 positiveFilter->filterImageDeprecated(proxy, gradient, ctx, | 409 SkAutoTUnref<SkSpecialImage> positiveResult1(positiveFilter->filterImage(img Src, ctx, &offset)); |
| 373 &positiveResult1, &off set)); | 410 REPORTER_ASSERT(reporter, positiveResult1); |
| 374 REPORTER_ASSERT(reporter, | 411 |
| 375 negativeFilter->filterImageDeprecated(proxy, gradient, ctx, | 412 SkAutoTUnref<SkSpecialImage> negativeResult1(negativeFilter->filterImage(img Src, ctx, &offset)); |
| 376 &negativeResult1, &off set)); | 413 REPORTER_ASSERT(reporter, negativeResult1); |
| 414 | |
| 377 SkMatrix negativeScale; | 415 SkMatrix negativeScale; |
| 378 negativeScale.setScale(-SK_Scalar1, SK_Scalar1); | 416 negativeScale.setScale(-SK_Scalar1, SK_Scalar1); |
| 379 SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeWH(32, 32), n ullptr); | 417 SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeWH(32, 32), n ullptr); |
| 380 REPORTER_ASSERT(reporter, | 418 |
| 381 positiveFilter->filterImageDeprecated(proxy, gradient, negat iveCTX, | 419 SkAutoTUnref<SkSpecialImage> negativeResult2(positiveFilter->filterImage(img Src, |
| 382 &negativeResult2, &off set)); | 420 neg ativeCTX, |
| 383 REPORTER_ASSERT(reporter, | 421 &of fset)); |
| 384 negativeFilter->filterImageDeprecated(proxy, gradient, negat iveCTX, | 422 REPORTER_ASSERT(reporter, negativeResult2); |
| 385 &positiveResult2, &off set)); | 423 |
| 386 SkAutoLockPixels lockP1(positiveResult1); | 424 SkAutoTUnref<SkSpecialImage> positiveResult2(negativeFilter->filterImage(img Src, |
| 387 SkAutoLockPixels lockP2(positiveResult2); | 425 neg ativeCTX, |
| 388 SkAutoLockPixels lockN1(negativeResult1); | 426 &of fset)); |
| 389 SkAutoLockPixels lockN2(negativeResult2); | 427 REPORTER_ASSERT(reporter, positiveResult2); |
| 428 | |
| 429 | |
| 430 SkBitmap positiveResultBM1, positiveResultBM2; | |
| 431 SkBitmap negativeResultBM1, negativeResultBM2; | |
| 432 | |
| 433 TestingSpecialImageAccess::GetROPixels(positiveResult1, &positiveResultBM1); | |
| 434 TestingSpecialImageAccess::GetROPixels(positiveResult2, &positiveResultBM2); | |
| 435 TestingSpecialImageAccess::GetROPixels(negativeResult1, &negativeResultBM1); | |
| 436 TestingSpecialImageAccess::GetROPixels(negativeResult2, &negativeResultBM2); | |
| 437 | |
| 438 SkAutoLockPixels lockP1(positiveResultBM1); | |
| 439 SkAutoLockPixels lockP2(positiveResultBM2); | |
| 440 SkAutoLockPixels lockN1(negativeResultBM1); | |
| 441 SkAutoLockPixels lockN2(negativeResultBM2); | |
| 390 for (int y = 0; y < height; y++) { | 442 for (int y = 0; y < height; y++) { |
| 391 int diffs = memcmp(positiveResult1.getAddr32(0, y), negativeResult1.getA ddr32(0, y), positiveResult1.rowBytes()); | 443 int diffs = memcmp(positiveResultBM1.getAddr32(0, y), |
| 444 negativeResultBM1.getAddr32(0, y), | |
| 445 positiveResultBM1.rowBytes()); | |
| 392 REPORTER_ASSERT(reporter, !diffs); | 446 REPORTER_ASSERT(reporter, !diffs); |
| 393 if (diffs) { | 447 if (diffs) { |
| 394 break; | 448 break; |
| 395 } | 449 } |
| 396 diffs = memcmp(positiveResult1.getAddr32(0, y), negativeResult2.getAddr3 2(0, y), positiveResult1.rowBytes()); | 450 diffs = memcmp(positiveResultBM1.getAddr32(0, y), |
| 451 negativeResultBM2.getAddr32(0, y), | |
| 452 positiveResultBM1.rowBytes()); | |
| 397 REPORTER_ASSERT(reporter, !diffs); | 453 REPORTER_ASSERT(reporter, !diffs); |
| 398 if (diffs) { | 454 if (diffs) { |
| 399 break; | 455 break; |
| 400 } | 456 } |
| 401 diffs = memcmp(positiveResult1.getAddr32(0, y), positiveResult2.getAddr3 2(0, y), positiveResult1.rowBytes()); | 457 diffs = memcmp(positiveResultBM1.getAddr32(0, y), |
| 458 positiveResultBM2.getAddr32(0, y), | |
| 459 positiveResultBM1.rowBytes()); | |
| 402 REPORTER_ASSERT(reporter, !diffs); | 460 REPORTER_ASSERT(reporter, !diffs); |
| 403 if (diffs) { | 461 if (diffs) { |
| 404 break; | 462 break; |
| 405 } | 463 } |
| 406 } | 464 } |
| 407 } | 465 } |
| 408 | 466 |
| 409 DEF_TEST(TestNegativeBlurSigma, reporter) { | 467 typedef void (*PFTest)(SkImageFilter::Proxy* proxy, |
| 410 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 468 skiatest::Reporter* reporter, |
| 469 GrContext* context); | |
| 470 | |
| 471 static void run_raster_test(skiatest::Reporter* reporter, | |
| 472 int widthHeight, | |
| 473 PFTest test) { | |
| 411 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 474 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
| 412 | 475 |
| 476 const SkImageInfo info = SkImageInfo::MakeN32Premul(widthHeight, widthHeight ); | |
| 477 | |
| 413 SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props)); | 478 SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props)); |
| 414 SkImageFilter::DeviceProxy proxy(device); | 479 SkImageFilter::DeviceProxy proxy(device); |
| 415 | 480 |
| 416 test_negative_blur_sigma(&proxy, reporter); | 481 (*test)(&proxy, reporter, nullptr); |
| 417 } | 482 } |
| 418 | 483 |
| 484 static void run_gpu_test(skiatest::Reporter* reporter, | |
| 485 GrContext* context, | |
| 486 int widthHeight, | |
| 487 PFTest test) { | |
| 488 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | |
| 489 | |
| 490 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | |
| 491 SkBudgeted::kNo, | |
| 492 SkImageInfo::MakeN32Pre mul(widthHeight, | |
| 493 widthHeight), | |
| 494 0, | |
| 495 &props, | |
| 496 SkGpuDevice::kUninit_In itContents)); | |
| 497 SkImageFilter::DeviceProxy proxy(device); | |
| 498 | |
| 499 (*test)(&proxy, reporter, context); | |
| 500 } | |
| 501 | |
| 502 DEF_TEST(TestNegativeBlurSigma, reporter) { | |
| 503 run_raster_test(reporter, 100, test_negative_blur_sigma); | |
| 504 } | |
| 505 | |
| 506 #if SK_SUPPORT_GPU | |
| 507 DEF_GPUTEST_FOR_NATIVE_CONTEXT(TestNegativeBlurSigma_Gpu, reporter, context) { | |
| 508 run_gpu_test(reporter, context, 100, test_negative_blur_sigma); | |
| 509 } | |
| 510 #endif | |
| 511 | |
| 419 DEF_TEST(ImageFilterDrawTiled, reporter) { | 512 DEF_TEST(ImageFilterDrawTiled, reporter) { |
| 420 // Check that all filters when drawn tiled (with subsequent clip rects) exac tly | 513 // Check that all filters when drawn tiled (with subsequent clip rects) exac tly |
| 421 // match the same filters drawn with a single full-canvas bitmap draw. | 514 // match the same filters drawn with a single full-canvas bitmap draw. |
| 422 // Tests pass by not asserting. | 515 // Tests pass by not asserting. |
| 423 | 516 |
| 424 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode)); | 517 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode)); |
| 425 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); | 518 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); |
| 426 SkScalar kernel[9] = { | 519 SkScalar kernel[9] = { |
| 427 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | 520 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
| 428 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), | 521 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 647 | 740 |
| 648 SkRect boundsSrc = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); | 741 SkRect boundsSrc = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); |
| 649 SkRect expectedBounds = SkRect::MakeXYWH( | 742 SkRect expectedBounds = SkRect::MakeXYWH( |
| 650 SkIntToScalar(-6), SkIntToScalar(-6), SkIntToScalar(112), SkIntToScalar( 112)); | 743 SkIntToScalar(-6), SkIntToScalar(-6), SkIntToScalar(112), SkIntToScalar( 112)); |
| 651 SkRect boundsDst = SkRect::MakeEmpty(); | 744 SkRect boundsDst = SkRect::MakeEmpty(); |
| 652 composedFilter->computeFastBounds(boundsSrc, &boundsDst); | 745 composedFilter->computeFastBounds(boundsSrc, &boundsDst); |
| 653 | 746 |
| 654 REPORTER_ASSERT(reporter, boundsDst == expectedBounds); | 747 REPORTER_ASSERT(reporter, boundsDst == expectedBounds); |
| 655 } | 748 } |
| 656 | 749 |
| 657 DEF_TEST(ImageFilterMergeResultSize, reporter) { | 750 static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy, |
| 751 skiatest::Reporter* reporter, | |
| 752 GrContext* context) { | |
| 658 SkBitmap greenBM; | 753 SkBitmap greenBM; |
| 659 greenBM.allocN32Pixels(20, 20); | 754 greenBM.allocN32Pixels(20, 20); |
| 660 greenBM.eraseColor(SK_ColorGREEN); | 755 greenBM.eraseColor(SK_ColorGREEN); |
| 661 SkAutoTUnref<SkImage> greenImage(SkImage::NewFromBitmap(greenBM)); | 756 SkAutoTUnref<SkImage> greenImage(SkImage::NewFromBitmap(greenBM)); |
| 662 SkAutoTUnref<SkImageFilter> source(SkImageSource::Create(greenImage.get())); | 757 SkAutoTUnref<SkImageFilter> source(SkImageSource::Create(greenImage.get())); |
| 663 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(source.get(), s ource.get())); | 758 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(source.get(), s ource.get())); |
| 664 | 759 |
| 665 SkBitmap bitmap; | 760 SkAutoTUnref<SkSpecialImage> srcImg(create_empty_special_image(context, prox y, 1)); |
| 666 bitmap.allocN32Pixels(1, 1); | 761 |
| 667 bitmap.eraseColor(0); | |
| 668 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | |
| 669 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | |
| 670 SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props)); | |
| 671 SkImageFilter::DeviceProxy proxy(device); | |
| 672 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr); | 762 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr); |
| 673 SkBitmap result; | |
| 674 SkIPoint offset; | 763 SkIPoint offset; |
| 675 REPORTER_ASSERT(reporter, merge->filterImageDeprecated(&proxy, bitmap, ctx, &result, &offset)); | 764 |
| 676 REPORTER_ASSERT(reporter, result.width() == 20 && result.height() == 20); | 765 SkAutoTUnref<SkSpecialImage> resultImg(merge->filterImage(srcImg, ctx, &offs et)); |
| 766 REPORTER_ASSERT(reporter, resultImg); | |
| 767 | |
| 768 REPORTER_ASSERT(reporter, resultImg->width() == 20 && resultImg->height() == 20); | |
| 677 } | 769 } |
| 678 | 770 |
| 771 DEF_TEST(ImageFilterMergeResultSize, reporter) { | |
| 772 run_raster_test(reporter, 100, test_imagefilter_merge_result_size); | |
| 773 } | |
| 774 | |
| 775 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ImageFilterMergeResultSize_Gpu, reporter, context ) { | |
| 776 run_gpu_test(reporter, context, 100, test_imagefilter_merge_result_size); | |
| 777 } | |
| 778 | |
| 779 | |
| 679 static void draw_blurred_rect(SkCanvas* canvas) { | 780 static void draw_blurred_rect(SkCanvas* canvas) { |
| 680 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8 ), 0)); | 781 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8 ), 0)); |
| 681 SkPaint filterPaint; | 782 SkPaint filterPaint; |
| 682 filterPaint.setColor(SK_ColorWHITE); | 783 filterPaint.setColor(SK_ColorWHITE); |
| 683 filterPaint.setImageFilter(filter); | 784 filterPaint.setImageFilter(filter); |
| 684 canvas->saveLayer(nullptr, &filterPaint); | 785 canvas->saveLayer(nullptr, &filterPaint); |
| 685 SkPaint whitePaint; | 786 SkPaint whitePaint; |
| 686 whitePaint.setColor(SK_ColorWHITE); | 787 whitePaint.setColor(SK_ColorWHITE); |
| 687 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); | 788 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); |
| 688 canvas->restore(); | 789 canvas->restore(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 filterPaint.setImageFilter(filter); | 897 filterPaint.setImageFilter(filter); |
| 797 SkRect bounds = SkRect::MakeWH(1, 10); | 898 SkRect bounds = SkRect::MakeWH(1, 10); |
| 798 SkRect rect = SkRect::Make(SkIRect::MakeWH(width, height)); | 899 SkRect rect = SkRect::Make(SkIRect::MakeWH(width, height)); |
| 799 SkPaint rectPaint; | 900 SkPaint rectPaint; |
| 800 canvas.saveLayer(&bounds, &filterPaint); | 901 canvas.saveLayer(&bounds, &filterPaint); |
| 801 canvas.drawRect(rect, rectPaint); | 902 canvas.drawRect(rect, rectPaint); |
| 802 canvas.restore(); | 903 canvas.restore(); |
| 803 } | 904 } |
| 804 | 905 |
| 805 DEF_TEST(ImageFilterCropRect, reporter) { | 906 DEF_TEST(ImageFilterCropRect, reporter) { |
| 806 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 907 run_raster_test(reporter, 100, test_crop_rects); |
| 807 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 908 } |
| 808 | 909 |
| 809 SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props)); | 910 #if SK_SUPPORT_GPU |
| 810 SkImageFilter::DeviceProxy proxy(device); | 911 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ImageFilterCropRect_Gpu, reporter, context) { |
| 811 | 912 run_gpu_test(reporter, context, 100, test_crop_rects); |
| 812 test_crop_rects(&proxy, reporter); | |
| 813 } | 913 } |
| 914 #endif | |
| 814 | 915 |
| 815 DEF_TEST(ImageFilterMatrix, reporter) { | 916 DEF_TEST(ImageFilterMatrix, reporter) { |
| 816 SkBitmap temp; | 917 SkBitmap temp; |
| 817 temp.allocN32Pixels(100, 100); | 918 temp.allocN32Pixels(100, 100); |
| 818 SkCanvas canvas(temp); | 919 SkCanvas canvas(temp); |
| 819 canvas.scale(SkIntToScalar(2), SkIntToScalar(2)); | 920 canvas.scale(SkIntToScalar(2), SkIntToScalar(2)); |
| 820 | 921 |
| 821 SkMatrix expectedMatrix = canvas.getTotalMatrix(); | 922 SkMatrix expectedMatrix = canvas.getTotalMatrix(); |
| 822 | 923 |
| 823 SkRTreeFactory factory; | 924 SkRTreeFactory factory; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 894 | 995 |
| 895 canvas.clear(0x0); | 996 canvas.clear(0x0); |
| 896 canvas.drawPicture(crossProcessPicture); | 997 canvas.drawPicture(crossProcessPicture); |
| 897 pixel = *bitmap.getAddr32(0, 0); | 998 pixel = *bitmap.getAddr32(0, 0); |
| 898 // If the security precautions are enabled, the result here should not be gr een, since the | 999 // If the security precautions are enabled, the result here should not be gr een, since the |
| 899 // filter draws nothing. | 1000 // filter draws nothing. |
| 900 REPORTER_ASSERT(reporter, SkPicture::PictureIOSecurityPrecautionsEnabled() | 1001 REPORTER_ASSERT(reporter, SkPicture::PictureIOSecurityPrecautionsEnabled() |
| 901 ? pixel != SK_ColorGREEN : pixel == SK_ColorGREEN); | 1002 ? pixel != SK_ColorGREEN : pixel == SK_ColorGREEN); |
| 902 } | 1003 } |
| 903 | 1004 |
| 904 DEF_TEST(ImageFilterClippedPictureImageFilter, reporter) { | 1005 static void test_clipped_picture_imagefilter(SkImageFilter::Proxy* proxy, |
| 905 SkRTreeFactory factory; | 1006 skiatest::Reporter* reporter, |
| 906 SkPictureRecorder recorder; | 1007 GrContext* context) { |
| 907 SkCanvas* recordingCanvas = recorder.beginRecording(1, 1, &factory, 0); | 1008 SkAutoTUnref<SkPicture> picture; |
| 908 | 1009 |
| 909 // Create an SkPicture which simply draws a green 1x1 rectangle. | 1010 { |
| 910 SkPaint greenPaint; | 1011 SkRTreeFactory factory; |
| 911 greenPaint.setColor(SK_ColorGREEN); | 1012 SkPictureRecorder recorder; |
| 912 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint); | 1013 SkCanvas* recordingCanvas = recorder.beginRecording(1, 1, &factory, 0); |
| 913 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1014 |
| 1015 // Create an SkPicture which simply draws a green 1x1 rectangle. | |
| 1016 SkPaint greenPaint; | |
| 1017 greenPaint.setColor(SK_ColorGREEN); | |
| 1018 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPain t); | |
| 1019 picture.reset(recorder.endRecording()); | |
| 1020 } | |
| 1021 | |
| 1022 SkAutoTUnref<SkSpecialImage> srcImg(create_empty_special_image(context, prox y, 2)); | |
| 914 | 1023 |
| 915 SkAutoTUnref<SkImageFilter> imageFilter(SkPictureImageFilter::Create(picture .get())); | 1024 SkAutoTUnref<SkImageFilter> imageFilter(SkPictureImageFilter::Create(picture .get())); |
| 916 | 1025 |
| 917 SkBitmap result; | |
| 918 SkIPoint offset; | 1026 SkIPoint offset; |
| 919 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nul lptr); | 1027 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nul lptr); |
| 920 SkBitmap bitmap; | 1028 |
| 921 bitmap.allocN32Pixels(2, 2); | 1029 SkAutoTUnref<SkSpecialImage> resultImage(imageFilter->filterImage(srcImg, ct x, &offset)); |
| 922 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 1030 REPORTER_ASSERT(reporter, !resultImage); |
| 923 SkBitmapDevice device(bitmap, props); | |
| 924 SkImageFilter::DeviceProxy proxy(&device); | |
| 925 REPORTER_ASSERT(reporter, | |
| 926 !imageFilter->filterImageDeprecated(&proxy, bitmap, ctx, &re sult, &offset)); | |
| 927 } | 1031 } |
| 928 | 1032 |
| 1033 DEF_TEST(ImageFilterClippedPictureImageFilter, reporter) { | |
| 1034 run_raster_test(reporter, 2, test_clipped_picture_imagefilter); | |
| 1035 } | |
| 1036 | |
| 1037 #if SK_SUPPORT_GPU | |
| 1038 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ImageFilterClippedPictureImageFilter_Gpu, reporte r, context) { | |
| 1039 run_gpu_test(reporter, context, 2, test_clipped_picture_imagefilter); | |
| 1040 } | |
| 1041 #endif | |
| 1042 | |
| 929 DEF_TEST(ImageFilterEmptySaveLayer, reporter) { | 1043 DEF_TEST(ImageFilterEmptySaveLayer, reporter) { |
| 930 // Even when there's an empty saveLayer()/restore(), ensure that an image | 1044 // Even when there's an empty saveLayer()/restore(), ensure that an image |
| 931 // filter or color filter which affects transparent black still draws. | 1045 // filter or color filter which affects transparent black still draws. |
| 932 | 1046 |
| 933 SkBitmap bitmap; | 1047 SkBitmap bitmap; |
| 934 bitmap.allocN32Pixels(10, 10); | 1048 bitmap.allocN32Pixels(10, 10); |
| 935 SkCanvas canvas(bitmap); | 1049 SkCanvas canvas(bitmap); |
| 936 | 1050 |
| 937 SkRTreeFactory factory; | 1051 SkRTreeFactory factory; |
| 938 SkPictureRecorder recorder; | 1052 SkPictureRecorder recorder; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1147 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); | 1261 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 1148 } | 1262 } |
| 1149 | 1263 |
| 1150 DEF_TEST(XfermodeImageFilterCroppedInput, reporter) { | 1264 DEF_TEST(XfermodeImageFilterCroppedInput, reporter) { |
| 1151 SkBitmap temp; | 1265 SkBitmap temp; |
| 1152 temp.allocN32Pixels(100, 100); | 1266 temp.allocN32Pixels(100, 100); |
| 1153 SkCanvas canvas(temp); | 1267 SkCanvas canvas(temp); |
| 1154 test_xfermode_cropped_input(&canvas, reporter); | 1268 test_xfermode_cropped_input(&canvas, reporter); |
| 1155 } | 1269 } |
| 1156 | 1270 |
| 1157 DEF_TEST(ComposedImageFilterOffset, reporter) { | 1271 static void test_composed_imagefilter_offset(SkImageFilter::Proxy* proxy, |
| 1158 SkBitmap bitmap; | 1272 skiatest::Reporter* reporter, |
| 1159 bitmap.allocN32Pixels(100, 100); | 1273 GrContext* context) { |
| 1160 bitmap.eraseARGB(0, 0, 0, 0); | 1274 SkAutoTUnref<SkSpecialImage> srcImg(create_empty_special_image(context, prox y, 100)); |
| 1161 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | |
| 1162 SkBitmapDevice device(bitmap, props); | |
| 1163 SkImageFilter::DeviceProxy proxy(&device); | |
| 1164 | 1275 |
| 1165 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); | 1276 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); |
| 1166 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, n ullptr, &cropRect)); | 1277 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, n ullptr, &cropRect)); |
| 1167 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1, | 1278 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1, |
| 1168 nullptr, &c ropRect)); | 1279 nullptr, &c ropRect)); |
| 1169 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur Filter, | 1280 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur Filter, |
| 1170 offs etFilter.get())); | 1281 offs etFilter.get())); |
| 1171 SkBitmap result; | |
| 1172 SkIPoint offset; | 1282 SkIPoint offset; |
| 1173 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr ); | 1283 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr ); |
| 1174 REPORTER_ASSERT(reporter, | 1284 |
| 1175 composedFilter->filterImageDeprecated(&proxy, bitmap, ctx, & result, &offset)); | 1285 SkAutoTUnref<SkSpecialImage> resultImg(composedFilter->filterImage(srcImg, c tx, &offset)); |
| 1286 REPORTER_ASSERT(reporter, resultImg); | |
| 1176 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); | 1287 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); |
| 1177 } | 1288 } |
| 1178 | 1289 |
| 1179 DEF_TEST(PartialCropRect, reporter) { | 1290 DEF_TEST(ComposedImageFilterOffset, reporter) { |
| 1180 SkBitmap bitmap; | 1291 run_raster_test(reporter, 100, test_composed_imagefilter_offset); |
|
Stephen White
2016/03/04 22:52:55
It looks like the widthHeight param is always the
robertphillips
2016/03/07 17:35:57
Unfortunately, the ImageFilterClippedPictureImageF
| |
| 1181 bitmap.allocN32Pixels(100, 100); | 1292 } |
| 1182 bitmap.eraseARGB(0, 0, 0, 0); | 1293 |
| 1183 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 1294 #if SK_SUPPORT_GPU |
| 1184 SkBitmapDevice device(bitmap, props); | 1295 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ComposedImageFilterOffset_Gpu, reporter, context) { |
|
Stephen White
2016/03/04 22:52:55
Some of these tests probably don't need to be run
robertphillips
2016/03/07 17:35:57
Right - hopefully they will all become generic but
| |
| 1185 SkImageFilter::DeviceProxy proxy(&device); | 1296 run_gpu_test(reporter, context, 100, test_composed_imagefilter_offset); |
| 1297 } | |
| 1298 #endif | |
| 1299 | |
| 1300 static void test_partial_crop_rect(SkImageFilter::Proxy* proxy, | |
| 1301 skiatest::Reporter* reporter, | |
| 1302 GrContext* context) { | |
| 1303 SkAutoTUnref<SkSpecialImage> srcImg(create_empty_special_image(context, prox y, 100)); | |
| 1186 | 1304 |
| 1187 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), | 1305 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), |
| 1188 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k HasHeight_CropEdge); | 1306 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k HasHeight_CropEdge); |
| 1189 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); | 1307 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); |
| 1190 SkBitmap result; | |
| 1191 SkIPoint offset; | 1308 SkIPoint offset; |
| 1192 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr ); | 1309 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr ); |
| 1193 REPORTER_ASSERT(reporter, | 1310 |
| 1194 filter->filterImageDeprecated(&proxy, bitmap, ctx, &result, &offset)); | 1311 SkAutoTUnref<SkSpecialImage> resultImg(filter->filterImage(srcImg, ctx, &off set)); |
| 1312 REPORTER_ASSERT(reporter, resultImg); | |
| 1313 | |
| 1195 REPORTER_ASSERT(reporter, offset.fX == 0); | 1314 REPORTER_ASSERT(reporter, offset.fX == 0); |
| 1196 REPORTER_ASSERT(reporter, offset.fY == 0); | 1315 REPORTER_ASSERT(reporter, offset.fY == 0); |
| 1197 REPORTER_ASSERT(reporter, result.width() == 20); | 1316 REPORTER_ASSERT(reporter, resultImg->width() == 20); |
| 1198 REPORTER_ASSERT(reporter, result.height() == 30); | 1317 REPORTER_ASSERT(reporter, resultImg->height() == 30); |
| 1199 } | 1318 } |
| 1200 | 1319 |
| 1320 DEF_TEST(PartialCropRect, reporter) { | |
| 1321 run_raster_test(reporter, 100, test_partial_crop_rect); | |
| 1322 } | |
| 1323 | |
| 1324 #if SK_SUPPORT_GPU | |
| 1325 DEF_GPUTEST_FOR_NATIVE_CONTEXT(PartialCropRect_Gpu, reporter, context) { | |
| 1326 run_gpu_test(reporter, context, 100, test_partial_crop_rect); | |
| 1327 } | |
| 1328 #endif | |
| 1329 | |
| 1201 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { | 1330 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { |
| 1202 | 1331 |
| 1203 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); | 1332 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); |
| 1204 SkAutoTUnref<SkImageFilter> lighting(SkLightingImageFilter::CreatePointLitDi ffuse( | 1333 SkAutoTUnref<SkImageFilter> lighting(SkLightingImageFilter::CreatePointLitDi ffuse( |
| 1205 location, SK_ColorGREEN, 0, 0)); | 1334 location, SK_ColorGREEN, 0, 0)); |
| 1206 REPORTER_ASSERT(reporter, !lighting->canComputeFastBounds()); | 1335 REPORTER_ASSERT(reporter, !lighting->canComputeFastBounds()); |
| 1207 | 1336 |
| 1208 SkAutoTUnref<SkImageFilter> gray(make_grayscale(nullptr, nullptr)); | 1337 SkAutoTUnref<SkImageFilter> gray(make_grayscale(nullptr, nullptr)); |
| 1209 REPORTER_ASSERT(reporter, gray->canComputeFastBounds()); | 1338 REPORTER_ASSERT(reporter, gray->canComputeFastBounds()); |
| 1210 { | 1339 { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1318 canvas->drawRect(SkRect::MakeIWH(largeW, largeH), paint); | 1447 canvas->drawRect(SkRect::MakeIWH(largeW, largeH), paint); |
| 1319 } | 1448 } |
| 1320 | 1449 |
| 1321 DEF_TEST(BlurLargeImage, reporter) { | 1450 DEF_TEST(BlurLargeImage, reporter) { |
| 1322 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(SkImageInfo::MakeN32Pre mul(100, 100))); | 1451 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(SkImageInfo::MakeN32Pre mul(100, 100))); |
| 1323 test_large_blur_input(reporter, surface->getCanvas()); | 1452 test_large_blur_input(reporter, surface->getCanvas()); |
| 1324 } | 1453 } |
| 1325 | 1454 |
| 1326 #if SK_SUPPORT_GPU | 1455 #if SK_SUPPORT_GPU |
| 1327 | 1456 |
| 1328 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ImageFilterCropRect_Gpu, reporter, context) { | |
| 1329 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | |
| 1330 | |
| 1331 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | |
| 1332 SkBudgeted::kNo, | |
| 1333 SkImageInfo::MakeN32Pre mul(100, 100), | |
| 1334 0, | |
| 1335 &props, | |
| 1336 SkGpuDevice::kUninit_In itContents)); | |
| 1337 SkImageFilter::DeviceProxy proxy(device); | |
| 1338 | |
| 1339 test_crop_rects(&proxy, reporter); | |
| 1340 } | |
| 1341 | |
| 1342 DEF_GPUTEST_FOR_NATIVE_CONTEXT(HugeBlurImageFilter_Gpu, reporter, context) { | 1457 DEF_GPUTEST_FOR_NATIVE_CONTEXT(HugeBlurImageFilter_Gpu, reporter, context) { |
| 1343 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 1458 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
| 1344 | 1459 |
| 1345 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 1460 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
| 1346 SkBudgeted::kNo, | 1461 SkBudgeted::kNo, |
| 1347 SkImageInfo::MakeN32Pre mul(100, 100), | 1462 SkImageInfo::MakeN32Pre mul(100, 100), |
| 1348 0, | 1463 0, |
| 1349 &props, | 1464 &props, |
| 1350 SkGpuDevice::kUninit_In itContents)); | 1465 SkGpuDevice::kUninit_In itContents)); |
| 1351 SkCanvas canvas(device); | 1466 SkCanvas canvas(device); |
| 1352 | 1467 |
| 1353 test_huge_blur(&canvas, reporter); | 1468 test_huge_blur(&canvas, reporter); |
| 1354 } | 1469 } |
| 1355 | 1470 |
| 1356 DEF_GPUTEST_FOR_NATIVE_CONTEXT(XfermodeImageFilterCroppedInput_Gpu, reporter, co ntext) { | 1471 DEF_GPUTEST_FOR_NATIVE_CONTEXT(XfermodeImageFilterCroppedInput_Gpu, reporter, co ntext) { |
| 1357 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 1472 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
| 1358 | 1473 |
| 1359 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 1474 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
| 1360 SkBudgeted::kNo, | 1475 SkBudgeted::kNo, |
| 1361 SkImageInfo::MakeN32Pre mul(1, 1), | 1476 SkImageInfo::MakeN32Pre mul(1, 1), |
| 1362 0, | 1477 0, |
| 1363 &props, | 1478 &props, |
| 1364 SkGpuDevice::kUninit_In itContents)); | 1479 SkGpuDevice::kUninit_In itContents)); |
| 1365 SkCanvas canvas(device); | 1480 SkCanvas canvas(device); |
| 1366 | 1481 |
| 1367 test_xfermode_cropped_input(&canvas, reporter); | 1482 test_xfermode_cropped_input(&canvas, reporter); |
| 1368 } | 1483 } |
| 1369 | 1484 |
| 1370 DEF_GPUTEST_FOR_NATIVE_CONTEXT(TestNegativeBlurSigma_Gpu, reporter, context) { | |
| 1371 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | |
| 1372 | |
| 1373 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | |
| 1374 SkBudgeted::kNo, | |
| 1375 SkImageInfo::MakeN32Pre mul(1, 1), | |
| 1376 0, | |
| 1377 &props, | |
| 1378 SkGpuDevice::kUninit_In itContents)); | |
| 1379 SkImageFilter::DeviceProxy proxy(device); | |
| 1380 | |
| 1381 test_negative_blur_sigma(&proxy, reporter); | |
| 1382 } | |
| 1383 | |
| 1384 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { | 1485 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { |
| 1385 SkAutoTUnref<SkSurface> surface( | 1486 SkAutoTUnref<SkSurface> surface( |
| 1386 SkSurface::NewRenderTarget(context, SkBudgeted::kYes, | 1487 SkSurface::NewRenderTarget(context, SkBudgeted::kYes, |
| 1387 SkImageInfo::MakeN32Premul(100, 100))); | 1488 SkImageInfo::MakeN32Premul(100, 100))); |
| 1388 test_large_blur_input(reporter, surface->getCanvas()); | 1489 test_large_blur_input(reporter, surface->getCanvas()); |
| 1389 } | 1490 } |
| 1390 #endif | 1491 #endif |
| OLD | NEW |