| 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 #if SK_SUPPORT_GPU |
| 485 static void run_gpu_test(skiatest::Reporter* reporter, |
| 486 GrContext* context, |
| 487 int widthHeight, |
| 488 PFTest test) { |
| 489 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
| 490 |
| 491 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
| 492 SkBudgeted::kNo, |
| 493 SkImageInfo::MakeN32Pre
mul(widthHeight, |
| 494
widthHeight), |
| 495 0, |
| 496 &props, |
| 497 SkGpuDevice::kUninit_In
itContents)); |
| 498 SkImageFilter::DeviceProxy proxy(device); |
| 499 |
| 500 (*test)(&proxy, reporter, context); |
| 501 } |
| 502 #endif |
| 503 |
| 504 DEF_TEST(TestNegativeBlurSigma, reporter) { |
| 505 run_raster_test(reporter, 100, test_negative_blur_sigma); |
| 506 } |
| 507 |
| 508 #if SK_SUPPORT_GPU |
| 509 DEF_GPUTEST_FOR_NATIVE_CONTEXT(TestNegativeBlurSigma_Gpu, reporter, context) { |
| 510 run_gpu_test(reporter, context, 100, test_negative_blur_sigma); |
| 511 } |
| 512 #endif |
| 513 |
| 419 DEF_TEST(ImageFilterDrawTiled, reporter) { | 514 DEF_TEST(ImageFilterDrawTiled, reporter) { |
| 420 // Check that all filters when drawn tiled (with subsequent clip rects) exac
tly | 515 // 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. | 516 // match the same filters drawn with a single full-canvas bitmap draw. |
| 422 // Tests pass by not asserting. | 517 // Tests pass by not asserting. |
| 423 | 518 |
| 424 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
SkXfermode::kSrcIn_Mode)); | 519 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
SkXfermode::kSrcIn_Mode)); |
| 425 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); | 520 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); |
| 426 SkScalar kernel[9] = { | 521 SkScalar kernel[9] = { |
| 427 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | 522 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
| 428 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), | 523 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 | 742 |
| 648 SkRect boundsSrc = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); | 743 SkRect boundsSrc = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); |
| 649 SkRect expectedBounds = SkRect::MakeXYWH( | 744 SkRect expectedBounds = SkRect::MakeXYWH( |
| 650 SkIntToScalar(-6), SkIntToScalar(-6), SkIntToScalar(112), SkIntToScalar(
112)); | 745 SkIntToScalar(-6), SkIntToScalar(-6), SkIntToScalar(112), SkIntToScalar(
112)); |
| 651 SkRect boundsDst = SkRect::MakeEmpty(); | 746 SkRect boundsDst = SkRect::MakeEmpty(); |
| 652 composedFilter->computeFastBounds(boundsSrc, &boundsDst); | 747 composedFilter->computeFastBounds(boundsSrc, &boundsDst); |
| 653 | 748 |
| 654 REPORTER_ASSERT(reporter, boundsDst == expectedBounds); | 749 REPORTER_ASSERT(reporter, boundsDst == expectedBounds); |
| 655 } | 750 } |
| 656 | 751 |
| 657 DEF_TEST(ImageFilterMergeResultSize, reporter) { | 752 static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy, |
| 753 skiatest::Reporter* reporter, |
| 754 GrContext* context) { |
| 658 SkBitmap greenBM; | 755 SkBitmap greenBM; |
| 659 greenBM.allocN32Pixels(20, 20); | 756 greenBM.allocN32Pixels(20, 20); |
| 660 greenBM.eraseColor(SK_ColorGREEN); | 757 greenBM.eraseColor(SK_ColorGREEN); |
| 661 SkAutoTUnref<SkImage> greenImage(SkImage::NewFromBitmap(greenBM)); | 758 SkAutoTUnref<SkImage> greenImage(SkImage::NewFromBitmap(greenBM)); |
| 662 SkAutoTUnref<SkImageFilter> source(SkImageSource::Create(greenImage.get())); | 759 SkAutoTUnref<SkImageFilter> source(SkImageSource::Create(greenImage.get())); |
| 663 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(source.get(), s
ource.get())); | 760 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(source.get(), s
ource.get())); |
| 664 | 761 |
| 665 SkBitmap bitmap; | 762 SkAutoTUnref<SkSpecialImage> srcImg(create_empty_special_image(context, prox
y, 1)); |
| 666 bitmap.allocN32Pixels(1, 1); | 763 |
| 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); | 764 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100),
nullptr); |
| 673 SkBitmap result; | |
| 674 SkIPoint offset; | 765 SkIPoint offset; |
| 675 REPORTER_ASSERT(reporter, merge->filterImageDeprecated(&proxy, bitmap, ctx,
&result, &offset)); | 766 |
| 676 REPORTER_ASSERT(reporter, result.width() == 20 && result.height() == 20); | 767 SkAutoTUnref<SkSpecialImage> resultImg(merge->filterImage(srcImg, ctx, &offs
et)); |
| 768 REPORTER_ASSERT(reporter, resultImg); |
| 769 |
| 770 REPORTER_ASSERT(reporter, resultImg->width() == 20 && resultImg->height() ==
20); |
| 677 } | 771 } |
| 678 | 772 |
| 773 DEF_TEST(ImageFilterMergeResultSize, reporter) { |
| 774 run_raster_test(reporter, 100, test_imagefilter_merge_result_size); |
| 775 } |
| 776 |
| 777 #if SK_SUPPORT_GPU |
| 778 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ImageFilterMergeResultSize_Gpu, reporter, context
) { |
| 779 run_gpu_test(reporter, context, 100, test_imagefilter_merge_result_size); |
| 780 } |
| 781 #endif |
| 782 |
| 679 static void draw_blurred_rect(SkCanvas* canvas) { | 783 static void draw_blurred_rect(SkCanvas* canvas) { |
| 680 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8
), 0)); | 784 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8
), 0)); |
| 681 SkPaint filterPaint; | 785 SkPaint filterPaint; |
| 682 filterPaint.setColor(SK_ColorWHITE); | 786 filterPaint.setColor(SK_ColorWHITE); |
| 683 filterPaint.setImageFilter(filter); | 787 filterPaint.setImageFilter(filter); |
| 684 canvas->saveLayer(nullptr, &filterPaint); | 788 canvas->saveLayer(nullptr, &filterPaint); |
| 685 SkPaint whitePaint; | 789 SkPaint whitePaint; |
| 686 whitePaint.setColor(SK_ColorWHITE); | 790 whitePaint.setColor(SK_ColorWHITE); |
| 687 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); | 791 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); |
| 688 canvas->restore(); | 792 canvas->restore(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 filterPaint.setImageFilter(filter); | 900 filterPaint.setImageFilter(filter); |
| 797 SkRect bounds = SkRect::MakeWH(1, 10); | 901 SkRect bounds = SkRect::MakeWH(1, 10); |
| 798 SkRect rect = SkRect::Make(SkIRect::MakeWH(width, height)); | 902 SkRect rect = SkRect::Make(SkIRect::MakeWH(width, height)); |
| 799 SkPaint rectPaint; | 903 SkPaint rectPaint; |
| 800 canvas.saveLayer(&bounds, &filterPaint); | 904 canvas.saveLayer(&bounds, &filterPaint); |
| 801 canvas.drawRect(rect, rectPaint); | 905 canvas.drawRect(rect, rectPaint); |
| 802 canvas.restore(); | 906 canvas.restore(); |
| 803 } | 907 } |
| 804 | 908 |
| 805 DEF_TEST(ImageFilterCropRect, reporter) { | 909 DEF_TEST(ImageFilterCropRect, reporter) { |
| 806 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 910 run_raster_test(reporter, 100, test_crop_rects); |
| 807 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 911 } |
| 808 | 912 |
| 809 SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props)); | 913 #if SK_SUPPORT_GPU |
| 810 SkImageFilter::DeviceProxy proxy(device); | 914 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ImageFilterCropRect_Gpu, reporter, context) { |
| 811 | 915 run_gpu_test(reporter, context, 100, test_crop_rects); |
| 812 test_crop_rects(&proxy, reporter); | |
| 813 } | 916 } |
| 917 #endif |
| 814 | 918 |
| 815 DEF_TEST(ImageFilterMatrix, reporter) { | 919 DEF_TEST(ImageFilterMatrix, reporter) { |
| 816 SkBitmap temp; | 920 SkBitmap temp; |
| 817 temp.allocN32Pixels(100, 100); | 921 temp.allocN32Pixels(100, 100); |
| 818 SkCanvas canvas(temp); | 922 SkCanvas canvas(temp); |
| 819 canvas.scale(SkIntToScalar(2), SkIntToScalar(2)); | 923 canvas.scale(SkIntToScalar(2), SkIntToScalar(2)); |
| 820 | 924 |
| 821 SkMatrix expectedMatrix = canvas.getTotalMatrix(); | 925 SkMatrix expectedMatrix = canvas.getTotalMatrix(); |
| 822 | 926 |
| 823 SkRTreeFactory factory; | 927 SkRTreeFactory factory; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 | 998 |
| 895 canvas.clear(0x0); | 999 canvas.clear(0x0); |
| 896 canvas.drawPicture(crossProcessPicture); | 1000 canvas.drawPicture(crossProcessPicture); |
| 897 pixel = *bitmap.getAddr32(0, 0); | 1001 pixel = *bitmap.getAddr32(0, 0); |
| 898 // If the security precautions are enabled, the result here should not be gr
een, since the | 1002 // If the security precautions are enabled, the result here should not be gr
een, since the |
| 899 // filter draws nothing. | 1003 // filter draws nothing. |
| 900 REPORTER_ASSERT(reporter, SkPicture::PictureIOSecurityPrecautionsEnabled() | 1004 REPORTER_ASSERT(reporter, SkPicture::PictureIOSecurityPrecautionsEnabled() |
| 901 ? pixel != SK_ColorGREEN : pixel == SK_ColorGREEN); | 1005 ? pixel != SK_ColorGREEN : pixel == SK_ColorGREEN); |
| 902 } | 1006 } |
| 903 | 1007 |
| 904 DEF_TEST(ImageFilterClippedPictureImageFilter, reporter) { | 1008 static void test_clipped_picture_imagefilter(SkImageFilter::Proxy* proxy, |
| 905 SkRTreeFactory factory; | 1009 skiatest::Reporter* reporter, |
| 906 SkPictureRecorder recorder; | 1010 GrContext* context) { |
| 907 SkCanvas* recordingCanvas = recorder.beginRecording(1, 1, &factory, 0); | 1011 SkAutoTUnref<SkPicture> picture; |
| 908 | 1012 |
| 909 // Create an SkPicture which simply draws a green 1x1 rectangle. | 1013 { |
| 910 SkPaint greenPaint; | 1014 SkRTreeFactory factory; |
| 911 greenPaint.setColor(SK_ColorGREEN); | 1015 SkPictureRecorder recorder; |
| 912 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint); | 1016 SkCanvas* recordingCanvas = recorder.beginRecording(1, 1, &factory, 0); |
| 913 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1017 |
| 1018 // Create an SkPicture which simply draws a green 1x1 rectangle. |
| 1019 SkPaint greenPaint; |
| 1020 greenPaint.setColor(SK_ColorGREEN); |
| 1021 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPain
t); |
| 1022 picture.reset(recorder.endRecording()); |
| 1023 } |
| 1024 |
| 1025 SkAutoTUnref<SkSpecialImage> srcImg(create_empty_special_image(context, prox
y, 2)); |
| 914 | 1026 |
| 915 SkAutoTUnref<SkImageFilter> imageFilter(SkPictureImageFilter::Create(picture
.get())); | 1027 SkAutoTUnref<SkImageFilter> imageFilter(SkPictureImageFilter::Create(picture
.get())); |
| 916 | 1028 |
| 917 SkBitmap result; | |
| 918 SkIPoint offset; | 1029 SkIPoint offset; |
| 919 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nul
lptr); | 1030 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nul
lptr); |
| 920 SkBitmap bitmap; | 1031 |
| 921 bitmap.allocN32Pixels(2, 2); | 1032 SkAutoTUnref<SkSpecialImage> resultImage(imageFilter->filterImage(srcImg, ct
x, &offset)); |
| 922 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 1033 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 } | 1034 } |
| 928 | 1035 |
| 1036 DEF_TEST(ImageFilterClippedPictureImageFilter, reporter) { |
| 1037 run_raster_test(reporter, 2, test_clipped_picture_imagefilter); |
| 1038 } |
| 1039 |
| 1040 #if SK_SUPPORT_GPU |
| 1041 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ImageFilterClippedPictureImageFilter_Gpu, reporte
r, context) { |
| 1042 run_gpu_test(reporter, context, 2, test_clipped_picture_imagefilter); |
| 1043 } |
| 1044 #endif |
| 1045 |
| 929 DEF_TEST(ImageFilterEmptySaveLayer, reporter) { | 1046 DEF_TEST(ImageFilterEmptySaveLayer, reporter) { |
| 930 // Even when there's an empty saveLayer()/restore(), ensure that an image | 1047 // Even when there's an empty saveLayer()/restore(), ensure that an image |
| 931 // filter or color filter which affects transparent black still draws. | 1048 // filter or color filter which affects transparent black still draws. |
| 932 | 1049 |
| 933 SkBitmap bitmap; | 1050 SkBitmap bitmap; |
| 934 bitmap.allocN32Pixels(10, 10); | 1051 bitmap.allocN32Pixels(10, 10); |
| 935 SkCanvas canvas(bitmap); | 1052 SkCanvas canvas(bitmap); |
| 936 | 1053 |
| 937 SkRTreeFactory factory; | 1054 SkRTreeFactory factory; |
| 938 SkPictureRecorder recorder; | 1055 SkPictureRecorder recorder; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); | 1264 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 1148 } | 1265 } |
| 1149 | 1266 |
| 1150 DEF_TEST(XfermodeImageFilterCroppedInput, reporter) { | 1267 DEF_TEST(XfermodeImageFilterCroppedInput, reporter) { |
| 1151 SkBitmap temp; | 1268 SkBitmap temp; |
| 1152 temp.allocN32Pixels(100, 100); | 1269 temp.allocN32Pixels(100, 100); |
| 1153 SkCanvas canvas(temp); | 1270 SkCanvas canvas(temp); |
| 1154 test_xfermode_cropped_input(&canvas, reporter); | 1271 test_xfermode_cropped_input(&canvas, reporter); |
| 1155 } | 1272 } |
| 1156 | 1273 |
| 1157 DEF_TEST(ComposedImageFilterOffset, reporter) { | 1274 static void test_composed_imagefilter_offset(SkImageFilter::Proxy* proxy, |
| 1158 SkBitmap bitmap; | 1275 skiatest::Reporter* reporter, |
| 1159 bitmap.allocN32Pixels(100, 100); | 1276 GrContext* context) { |
| 1160 bitmap.eraseARGB(0, 0, 0, 0); | 1277 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 | 1278 |
| 1165 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); | 1279 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); |
| 1166 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, n
ullptr, &cropRect)); | 1280 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, n
ullptr, &cropRect)); |
| 1167 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(SK_Scalar1,
SK_Scalar1, | 1281 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(SK_Scalar1,
SK_Scalar1, |
| 1168 nullptr, &c
ropRect)); | 1282 nullptr, &c
ropRect)); |
| 1169 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur
Filter, | 1283 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur
Filter, |
| 1170 offs
etFilter.get())); | 1284 offs
etFilter.get())); |
| 1171 SkBitmap result; | |
| 1172 SkIPoint offset; | 1285 SkIPoint offset; |
| 1173 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
); | 1286 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
); |
| 1174 REPORTER_ASSERT(reporter, | 1287 |
| 1175 composedFilter->filterImageDeprecated(&proxy, bitmap, ctx, &
result, &offset)); | 1288 SkAutoTUnref<SkSpecialImage> resultImg(composedFilter->filterImage(srcImg, c
tx, &offset)); |
| 1289 REPORTER_ASSERT(reporter, resultImg); |
| 1176 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); | 1290 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); |
| 1177 } | 1291 } |
| 1178 | 1292 |
| 1179 DEF_TEST(PartialCropRect, reporter) { | 1293 DEF_TEST(ComposedImageFilterOffset, reporter) { |
| 1180 SkBitmap bitmap; | 1294 run_raster_test(reporter, 100, test_composed_imagefilter_offset); |
| 1181 bitmap.allocN32Pixels(100, 100); | 1295 } |
| 1182 bitmap.eraseARGB(0, 0, 0, 0); | 1296 |
| 1183 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 1297 #if SK_SUPPORT_GPU |
| 1184 SkBitmapDevice device(bitmap, props); | 1298 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ComposedImageFilterOffset_Gpu, reporter, context)
{ |
| 1185 SkImageFilter::DeviceProxy proxy(&device); | 1299 run_gpu_test(reporter, context, 100, test_composed_imagefilter_offset); |
| 1300 } |
| 1301 #endif |
| 1302 |
| 1303 static void test_partial_crop_rect(SkImageFilter::Proxy* proxy, |
| 1304 skiatest::Reporter* reporter, |
| 1305 GrContext* context) { |
| 1306 SkAutoTUnref<SkSpecialImage> srcImg(create_empty_special_image(context, prox
y, 100)); |
| 1186 | 1307 |
| 1187 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), | 1308 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), |
| 1188 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k
HasHeight_CropEdge); | 1309 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k
HasHeight_CropEdge); |
| 1189 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); | 1310 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); |
| 1190 SkBitmap result; | |
| 1191 SkIPoint offset; | 1311 SkIPoint offset; |
| 1192 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
); | 1312 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
); |
| 1193 REPORTER_ASSERT(reporter, | 1313 |
| 1194 filter->filterImageDeprecated(&proxy, bitmap, ctx, &result,
&offset)); | 1314 SkAutoTUnref<SkSpecialImage> resultImg(filter->filterImage(srcImg, ctx, &off
set)); |
| 1315 REPORTER_ASSERT(reporter, resultImg); |
| 1316 |
| 1195 REPORTER_ASSERT(reporter, offset.fX == 0); | 1317 REPORTER_ASSERT(reporter, offset.fX == 0); |
| 1196 REPORTER_ASSERT(reporter, offset.fY == 0); | 1318 REPORTER_ASSERT(reporter, offset.fY == 0); |
| 1197 REPORTER_ASSERT(reporter, result.width() == 20); | 1319 REPORTER_ASSERT(reporter, resultImg->width() == 20); |
| 1198 REPORTER_ASSERT(reporter, result.height() == 30); | 1320 REPORTER_ASSERT(reporter, resultImg->height() == 30); |
| 1199 } | 1321 } |
| 1200 | 1322 |
| 1323 DEF_TEST(PartialCropRect, reporter) { |
| 1324 run_raster_test(reporter, 100, test_partial_crop_rect); |
| 1325 } |
| 1326 |
| 1327 #if SK_SUPPORT_GPU |
| 1328 DEF_GPUTEST_FOR_NATIVE_CONTEXT(PartialCropRect_Gpu, reporter, context) { |
| 1329 run_gpu_test(reporter, context, 100, test_partial_crop_rect); |
| 1330 } |
| 1331 #endif |
| 1332 |
| 1201 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { | 1333 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { |
| 1202 | 1334 |
| 1203 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); | 1335 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); |
| 1204 SkAutoTUnref<SkImageFilter> lighting(SkLightingImageFilter::CreatePointLitDi
ffuse( | 1336 SkAutoTUnref<SkImageFilter> lighting(SkLightingImageFilter::CreatePointLitDi
ffuse( |
| 1205 location, SK_ColorGREEN, 0, 0)); | 1337 location, SK_ColorGREEN, 0, 0)); |
| 1206 REPORTER_ASSERT(reporter, !lighting->canComputeFastBounds()); | 1338 REPORTER_ASSERT(reporter, !lighting->canComputeFastBounds()); |
| 1207 | 1339 |
| 1208 SkAutoTUnref<SkImageFilter> gray(make_grayscale(nullptr, nullptr)); | 1340 SkAutoTUnref<SkImageFilter> gray(make_grayscale(nullptr, nullptr)); |
| 1209 REPORTER_ASSERT(reporter, gray->canComputeFastBounds()); | 1341 REPORTER_ASSERT(reporter, gray->canComputeFastBounds()); |
| 1210 { | 1342 { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 canvas->drawRect(SkRect::MakeIWH(largeW, largeH), paint); | 1450 canvas->drawRect(SkRect::MakeIWH(largeW, largeH), paint); |
| 1319 } | 1451 } |
| 1320 | 1452 |
| 1321 DEF_TEST(BlurLargeImage, reporter) { | 1453 DEF_TEST(BlurLargeImage, reporter) { |
| 1322 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(SkImageInfo::MakeN32Pre
mul(100, 100))); | 1454 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(SkImageInfo::MakeN32Pre
mul(100, 100))); |
| 1323 test_large_blur_input(reporter, surface->getCanvas()); | 1455 test_large_blur_input(reporter, surface->getCanvas()); |
| 1324 } | 1456 } |
| 1325 | 1457 |
| 1326 #if SK_SUPPORT_GPU | 1458 #if SK_SUPPORT_GPU |
| 1327 | 1459 |
| 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) { | 1460 DEF_GPUTEST_FOR_NATIVE_CONTEXT(HugeBlurImageFilter_Gpu, reporter, context) { |
| 1343 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 1461 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
| 1344 | 1462 |
| 1345 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 1463 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
| 1346 SkBudgeted::kNo, | 1464 SkBudgeted::kNo, |
| 1347 SkImageInfo::MakeN32Pre
mul(100, 100), | 1465 SkImageInfo::MakeN32Pre
mul(100, 100), |
| 1348 0, | 1466 0, |
| 1349 &props, | 1467 &props, |
| 1350 SkGpuDevice::kUninit_In
itContents)); | 1468 SkGpuDevice::kUninit_In
itContents)); |
| 1351 SkCanvas canvas(device); | 1469 SkCanvas canvas(device); |
| 1352 | 1470 |
| 1353 test_huge_blur(&canvas, reporter); | 1471 test_huge_blur(&canvas, reporter); |
| 1354 } | 1472 } |
| 1355 | 1473 |
| 1356 DEF_GPUTEST_FOR_NATIVE_CONTEXT(XfermodeImageFilterCroppedInput_Gpu, reporter, co
ntext) { | 1474 DEF_GPUTEST_FOR_NATIVE_CONTEXT(XfermodeImageFilterCroppedInput_Gpu, reporter, co
ntext) { |
| 1357 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 1475 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
| 1358 | 1476 |
| 1359 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 1477 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
| 1360 SkBudgeted::kNo, | 1478 SkBudgeted::kNo, |
| 1361 SkImageInfo::MakeN32Pre
mul(1, 1), | 1479 SkImageInfo::MakeN32Pre
mul(1, 1), |
| 1362 0, | 1480 0, |
| 1363 &props, | 1481 &props, |
| 1364 SkGpuDevice::kUninit_In
itContents)); | 1482 SkGpuDevice::kUninit_In
itContents)); |
| 1365 SkCanvas canvas(device); | 1483 SkCanvas canvas(device); |
| 1366 | 1484 |
| 1367 test_xfermode_cropped_input(&canvas, reporter); | 1485 test_xfermode_cropped_input(&canvas, reporter); |
| 1368 } | 1486 } |
| 1369 | 1487 |
| 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) { | 1488 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { |
| 1385 SkAutoTUnref<SkSurface> surface( | 1489 SkAutoTUnref<SkSurface> surface( |
| 1386 SkSurface::NewRenderTarget(context, SkBudgeted::kYes, | 1490 SkSurface::NewRenderTarget(context, SkBudgeted::kYes, |
| 1387 SkImageInfo::MakeN32Premul(100, 100))); | 1491 SkImageInfo::MakeN32Premul(100, 100))); |
| 1388 test_large_blur_input(reporter, surface->getCanvas()); | 1492 test_large_blur_input(reporter, surface->getCanvas()); |
| 1389 } | 1493 } |
| 1390 #endif | 1494 #endif |
| OLD | NEW |