| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix)); | 151 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix)); |
| 152 return SkColorFilterImageFilter::Create(filter, input, cropRect); | 152 return SkColorFilterImageFilter::Create(filter, input, cropRect); |
| 153 } | 153 } |
| 154 | 154 |
| 155 static SkImageFilter* make_blue(SkImageFilter* input, const SkImageFilter::CropR
ect* cropRect) { | 155 static SkImageFilter* make_blue(SkImageFilter* input, const SkImageFilter::CropR
ect* cropRect) { |
| 156 SkAutoTUnref<SkColorFilter> filter(SkColorFilter::CreateModeFilter(SK_ColorB
LUE, | 156 SkAutoTUnref<SkColorFilter> filter(SkColorFilter::CreateModeFilter(SK_ColorB
LUE, |
| 157 SkXfermod
e::kSrcIn_Mode)); | 157 SkXfermod
e::kSrcIn_Mode)); |
| 158 return SkColorFilterImageFilter::Create(filter, input, cropRect); | 158 return SkColorFilterImageFilter::Create(filter, input, cropRect); |
| 159 } | 159 } |
| 160 | 160 |
| 161 static SkSpecialImage* create_empty_special_image(GrContext* context, | 161 static SkSpecialSurface* create_empty_special_surface(GrContext* context, |
| 162 SkImageFilter::Proxy* proxy, | 162 SkImageFilter::Proxy* prox
y, |
| 163 int widthHeight) { | 163 int widthHeight) { |
| 164 SkAutoTUnref<SkSpecialSurface> surf; | |
| 165 | |
| 166 if (context) { | 164 if (context) { |
| 167 GrSurfaceDesc desc; | 165 GrSurfaceDesc desc; |
| 168 desc.fConfig = kSkia8888_GrPixelConfig; | 166 desc.fConfig = kSkia8888_GrPixelConfig; |
| 169 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 167 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 170 desc.fWidth = widthHeight; | 168 desc.fWidth = widthHeight; |
| 171 desc.fHeight = widthHeight; | 169 desc.fHeight = widthHeight; |
| 172 surf.reset(SkSpecialSurface::NewRenderTarget(proxy, context, desc)); | 170 return SkSpecialSurface::NewRenderTarget(proxy, context, desc); |
| 173 } else { | 171 } else { |
| 174 const SkImageInfo info = SkImageInfo::MakeN32(widthHeight, widthHeight, | 172 const SkImageInfo info = SkImageInfo::MakeN32(widthHeight, widthHeight, |
| 175 kOpaque_SkAlphaType); | 173 kOpaque_SkAlphaType); |
| 176 surf.reset(SkSpecialSurface::NewRaster(proxy, info)); | 174 return SkSpecialSurface::NewRaster(proxy, info); |
| 177 } | 175 } |
| 176 } |
| 177 |
| 178 static SkSpecialImage* create_empty_special_image(GrContext* context, |
| 179 SkImageFilter::Proxy* proxy, |
| 180 int widthHeight) { |
| 181 SkAutoTUnref<SkSpecialSurface> surf(create_empty_special_surface(context, pr
oxy, widthHeight)); |
| 178 | 182 |
| 179 SkASSERT(surf); | 183 SkASSERT(surf); |
| 180 | 184 |
| 181 SkCanvas* canvas = surf->getCanvas(); | 185 SkCanvas* canvas = surf->getCanvas(); |
| 182 SkASSERT(canvas); | 186 SkASSERT(canvas); |
| 183 | 187 |
| 184 canvas->clear(0x0); | 188 canvas->clear(0x0); |
| 185 | 189 |
| 186 return surf->newImageSnapshot(); | 190 return surf->newImageSnapshot(); |
| 187 } | 191 } |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 DEF_TEST(TestNegativeBlurSigma, reporter) { | 505 DEF_TEST(TestNegativeBlurSigma, reporter) { |
| 502 run_raster_test(reporter, 100, test_negative_blur_sigma); | 506 run_raster_test(reporter, 100, test_negative_blur_sigma); |
| 503 } | 507 } |
| 504 | 508 |
| 505 #if SK_SUPPORT_GPU | 509 #if SK_SUPPORT_GPU |
| 506 DEF_GPUTEST_FOR_NATIVE_CONTEXT(TestNegativeBlurSigma_Gpu, reporter, context) { | 510 DEF_GPUTEST_FOR_NATIVE_CONTEXT(TestNegativeBlurSigma_Gpu, reporter, context) { |
| 507 run_gpu_test(reporter, context, 100, test_negative_blur_sigma); | 511 run_gpu_test(reporter, context, 100, test_negative_blur_sigma); |
| 508 } | 512 } |
| 509 #endif | 513 #endif |
| 510 | 514 |
| 515 static void test_zero_blur_sigma(SkImageFilter::Proxy* proxy, |
| 516 skiatest::Reporter* reporter, |
| 517 GrContext* context) { |
| 518 // Check that SkBlurImageFilter with a zero sigma and a non-zero srcOffset w
orks correctly. |
| 519 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(5, 0, 5, 10)
)); |
| 520 SkAutoTUnref<SkImageFilter> input(SkOffsetImageFilter::Create(0, 0, nullptr,
&cropRect)); |
| 521 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(0, 0, input, &c
ropRect)); |
| 522 |
| 523 SkAutoTUnref<SkSpecialSurface> surf(create_empty_special_surface(context, pr
oxy, 10)); |
| 524 surf->getCanvas()->clear(SK_ColorGREEN); |
| 525 SkAutoTUnref<SkSpecialImage> image(surf->newImageSnapshot()); |
| 526 |
| 527 SkIPoint offset; |
| 528 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr); |
| 529 |
| 530 SkAutoTUnref<SkSpecialImage> result(filter->filterImage(image, ctx, &offset)
); |
| 531 REPORTER_ASSERT(reporter, offset.fX == 5 && offset.fY == 0); |
| 532 REPORTER_ASSERT(reporter, result); |
| 533 REPORTER_ASSERT(reporter, result->width() == 5 && result->height() == 10); |
| 534 |
| 535 SkBitmap resultBM; |
| 536 |
| 537 TestingSpecialImageAccess::GetROPixels(result, &resultBM); |
| 538 |
| 539 SkAutoLockPixels lock(resultBM); |
| 540 for (int y = 0; y < resultBM.height(); y++) { |
| 541 for (int x = 0; x < resultBM.width(); x++) { |
| 542 bool diff = *resultBM.getAddr32(x, y) != SK_ColorGREEN; |
| 543 REPORTER_ASSERT(reporter, !diff); |
| 544 if (diff) { |
| 545 break; |
| 546 } |
| 547 } |
| 548 } |
| 549 } |
| 550 |
| 551 DEF_TEST(TestZeroBlurSigma, reporter) { |
| 552 run_raster_test(reporter, 100, test_zero_blur_sigma); |
| 553 } |
| 554 |
| 555 #if SK_SUPPORT_GPU |
| 556 DEF_GPUTEST_FOR_NATIVE_CONTEXT(TestZeroBlurSigma_Gpu, reporter, context) { |
| 557 run_gpu_test(reporter, context, 100, test_zero_blur_sigma); |
| 558 } |
| 559 #endif |
| 560 |
| 511 DEF_TEST(ImageFilterDrawTiled, reporter) { | 561 DEF_TEST(ImageFilterDrawTiled, reporter) { |
| 512 // Check that all filters when drawn tiled (with subsequent clip rects) exac
tly | 562 // Check that all filters when drawn tiled (with subsequent clip rects) exac
tly |
| 513 // match the same filters drawn with a single full-canvas bitmap draw. | 563 // match the same filters drawn with a single full-canvas bitmap draw. |
| 514 // Tests pass by not asserting. | 564 // Tests pass by not asserting. |
| 515 | 565 |
| 516 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
SkXfermode::kSrcIn_Mode)); | 566 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
SkXfermode::kSrcIn_Mode)); |
| 517 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); | 567 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); |
| 518 SkScalar kernel[9] = { | 568 SkScalar kernel[9] = { |
| 519 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | 569 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
| 520 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), | 570 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), |
| (...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1482 test_xfermode_cropped_input(&canvas, reporter); | 1532 test_xfermode_cropped_input(&canvas, reporter); |
| 1483 } | 1533 } |
| 1484 | 1534 |
| 1485 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { | 1535 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { |
| 1486 SkAutoTUnref<SkSurface> surface( | 1536 SkAutoTUnref<SkSurface> surface( |
| 1487 SkSurface::NewRenderTarget(context, SkBudgeted::kYes, | 1537 SkSurface::NewRenderTarget(context, SkBudgeted::kYes, |
| 1488 SkImageInfo::MakeN32Premul(100, 100))); | 1538 SkImageInfo::MakeN32Premul(100, 100))); |
| 1489 test_large_blur_input(reporter, surface->getCanvas()); | 1539 test_large_blur_input(reporter, surface->getCanvas()); |
| 1490 } | 1540 } |
| 1491 #endif | 1541 #endif |
| OLD | NEW |