From 247835b6c81a6165cda14f62fb094bcf4391b808 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Tue, 21 Jul 2020 16:50:06 -0400 Subject: [PATCH] Reland "Migrate SkImage::makeWithFilter to GrRecordingContext" This reverts commit d13b97f94c9f86081bb99dc505632f8e43ca610e. Reason for revert: Fixed chromium canary Original change's description: > Revert "Migrate SkImage::makeWithFilter to GrRecordingContext" > > This reverts commit 7f0129d424a45f87653f6d0d83141e10fa96cba3. > > Reason for revert: Broke Chrome roll > > Original change's description: > > Migrate SkImage::makeWithFilter to GrRecordingContext > > > > The staging flag landed in Chrome CL 2307531. > > > > Bug: skia:104662 > > Change-Id: I8a483bfb83e890bb0566cd252a464a6add89df4f > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304003 > > Reviewed-by: Robert Phillips > > Reviewed-by: Brian Salomon > > Commit-Queue: Adlai Holler > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I280dbffa26da71d53872266e62fa3bcaa3c00989 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304802 > Reviewed-by: Adlai Holler > Commit-Queue: Adlai Holler TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com Bug: skia:104662 Change-Id: I815677659f776966b1c7e362ce3df444834dd482 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304803 Reviewed-by: Robert Phillips Commit-Queue: Robert Phillips Auto-Submit: Adlai Holler --- bench/ImageFilterDAGBench.cpp | 8 +-- docs/examples/Image_makeWithFilter.cpp | 4 +- gm/imagemakewithfilter.cpp | 24 ++++--- include/core/SkImage.h | 12 ++-- src/image/SkImage.cpp | 38 +++++++---- tests/ImageFilterTest.cpp | 93 +++++++++++++++----------- tests/RepeatedClippedBlurTest.cpp | 16 ++--- 7 files changed, 112 insertions(+), 83 deletions(-) diff --git a/bench/ImageFilterDAGBench.cpp b/bench/ImageFilterDAGBench.cpp index 1f3a3b23d4f8..3f69c9d079d3 100644 --- a/bench/ImageFilterDAGBench.cpp +++ b/bench/ImageFilterDAGBench.cpp @@ -73,9 +73,9 @@ class ImageMakeWithFilterDAGBench : public Benchmark { SkIPoint offset = SkIPoint::Make(0, 0); SkIRect discardSubset; - auto direct = GrAsDirectContext(canvas->recordingContext()); + auto dContext = GrAsDirectContext(canvas->recordingContext()); // makeWithFilter will only use the GPU backend if the image is already a texture - sk_sp image = fImage->makeTextureImage(direct); + sk_sp image = fImage->makeTextureImage(dContext); if (!image) { image = fImage; } @@ -90,8 +90,8 @@ class ImageMakeWithFilterDAGBench : public Benchmark { // But measure makeWithFilter() per loop since that's the focus of this benchmark for (int j = 0; j < loops; j++) { - image = image->makeWithFilter(mergeFilter.get(), subset, subset, &discardSubset, - &offset); + image = image->makeWithFilter(dContext, mergeFilter.get(), subset, subset, + &discardSubset, &offset); SkASSERT(image && image->dimensions() == fImage->dimensions()); } } diff --git a/docs/examples/Image_makeWithFilter.cpp b/docs/examples/Image_makeWithFilter.cpp index 689b203a3158..9ccba4943ad5 100644 --- a/docs/examples/Image_makeWithFilter.cpp +++ b/docs/examples/Image_makeWithFilter.cpp @@ -12,8 +12,8 @@ void draw(SkCanvas* canvas) { clipBounds.outset(60, 60); SkIRect outSubset; SkIPoint offset; - sk_sp filtered(image->makeWithFilter(offsetFilter.get(), subset, clipBounds, - &outSubset, &offset)); + sk_sp filtered(image->makeWithFilter(canvas->recordingContext(), offsetFilter.get(), + subset, clipBounds, &outSubset, &offset)); SkPaint paint; paint.setAntiAlias(true); paint.setStyle(SkPaint::kStroke_Style); diff --git a/gm/imagemakewithfilter.cpp b/gm/imagemakewithfilter.cpp index 50046c4d748b..7108ac997db8 100644 --- a/gm/imagemakewithfilter.cpp +++ b/gm/imagemakewithfilter.cpp @@ -271,20 +271,20 @@ class ImageMakeWithFilterGM : public skiagm::GM { // code paths (otherwise they may choose to do CPU filtering then upload) sk_sp mainImage, auxImage; - auto recording = canvas->recordingContext(); - if (recording) { - // In a DDL context, we can't use the GPU code paths and we will drop the work – skip. - auto direct = GrAsDirectContext(recording); - if (!direct) { + auto rContext = canvas->recordingContext(); + // In a DDL context, we can't use the GPU code paths and we will drop the work – skip. + auto dContext = GrAsDirectContext(rContext); + if (rContext) { + if (!dContext) { *errorMsg = "Requires a direct context."; return DrawResult::kSkip; } - if (direct->abandoned()) { + if (dContext->abandoned()) { *errorMsg = "Direct context abandoned."; return DrawResult::kSkip; } - mainImage = fMainImage->makeTextureImage(direct); - auxImage = fAuxImage->makeTextureImage(direct); + mainImage = fMainImage->makeTextureImage(dContext); + auxImage = fAuxImage->makeTextureImage(dContext); } else { mainImage = fMainImage; auxImage = fAuxImage; @@ -292,8 +292,8 @@ class ImageMakeWithFilterGM : public skiagm::GM { if (!mainImage || !auxImage) { return DrawResult::kFail; } - SkASSERT(mainImage && (mainImage->isTextureBacked() || !recording)); - SkASSERT(auxImage && (auxImage->isTextureBacked() || !recording)); + SkASSERT(mainImage && (mainImage->isTextureBacked() || !rContext)); + SkASSERT(auxImage && (auxImage->isTextureBacked() || !rContext)); SkScalar MARGIN = SkIntToScalar(40); SkScalar DX = mainImage->width() + MARGIN; @@ -376,7 +376,9 @@ class ImageMakeWithFilterGM : public skiagm::GM { SkIRect outSubset; SkIPoint offset; - result = mainImage->makeWithFilter(filter.get(), subset, clip, &outSubset, &offset); + auto rContext = canvas->recordingContext(); + result = mainImage->makeWithFilter(rContext, filter.get(), subset, clip, + &outSubset, &offset); SkASSERT(result); SkASSERT(mainImage->isTextureBacked() == result->isTextureBacked()); diff --git a/include/core/SkImage.h b/include/core/SkImage.h index 2adf0c0664af..31cd5bd29013 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -35,7 +35,6 @@ class GrContext; class GrDirectContext; class GrRecordingContext; class GrContextThreadSafeProxy; -class GrRecordingContext; struct SkYUVAIndex; @@ -1253,7 +1252,8 @@ class SK_API SkImage : public SkRefCnt { is required storage for the actual bounds of the filtered SkImage. offset is required storage for translation of returned SkImage. - Returns nullptr if SkImage could not be created. If nullptr is returned, outSubset + Returns nullptr if SkImage could not be created or if the recording context provided doesn't + match the GPU context in which the image was created. If nullptr is returned, outSubset and offset are undefined. Useful for animation of SkImageFilter that varies size from frame to frame. @@ -1262,7 +1262,7 @@ class SK_API SkImage : public SkRefCnt { of GPU texture returned. offset translates the returned SkImage to keep subsequent animation frames aligned with respect to each other. - @param context the GrContext in play - if it exists + @param context the GrRecordingContext in play - if it exists @param filter how SkImage is sampled when transformed @param subset bounds of SkImage processed by filter @param clipBounds expected bounds of filtered SkImage @@ -1270,16 +1270,16 @@ class SK_API SkImage : public SkRefCnt { @param offset storage for returned SkImage translation @return filtered SkImage, or nullptr */ - sk_sp makeWithFilter(GrContext* context, + sk_sp makeWithFilter(GrRecordingContext* context, const SkImageFilter* filter, const SkIRect& subset, const SkIRect& clipBounds, SkIRect* outSubset, SkIPoint* offset) const; - /** To be deprecated. - */ +#ifdef SK_IMAGE_MAKE_WITH_FILTER_LEGACY_API sk_sp makeWithFilter(const SkImageFilter* filter, const SkIRect& subset, const SkIRect& clipBounds, SkIRect* outSubset, SkIPoint* offset) const; +#endif /** Defines a callback function, taking one parameter of type GrBackendTexture with no return value. Function is called when back-end texture is to be released. diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 6560a013367d..cb3b47dfe55f 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -348,26 +348,24 @@ sk_sp SkImage::MakeFromPicture(sk_sp picture, const SkISize& std::move(colorSpace))); } -sk_sp SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRect& subset, - const SkIRect& clipBounds, SkIRect* outSubset, - SkIPoint* offset) const { - GrContext* context = as_IB(this)->context(); - - return this->makeWithFilter(context, filter, subset, clipBounds, outSubset, offset); -} +sk_sp SkImage::makeWithFilter(GrRecordingContext* rContext, const SkImageFilter* filter, + const SkIRect& subset, const SkIRect& clipBounds, + SkIRect* outSubset, SkIPoint* offset) const { -sk_sp SkImage::makeWithFilter(GrContext* grContext, - const SkImageFilter* filter, const SkIRect& subset, - const SkIRect& clipBounds, SkIRect* outSubset, - SkIPoint* offset) const { if (!filter || !outSubset || !offset || !this->bounds().contains(subset)) { return nullptr; } - sk_sp srcSpecialImage = + sk_sp srcSpecialImage; #if SK_SUPPORT_GPU - SkSpecialImage::MakeFromImage(grContext, subset, sk_ref_sp(const_cast(this))); + auto myContext = as_IB(this)->context(); + if (myContext && !myContext->priv().matches(rContext)) { + return nullptr; + } + srcSpecialImage = SkSpecialImage::MakeFromImage(rContext, subset, + sk_ref_sp(const_cast(this))); #else - SkSpecialImage::MakeFromImage(nullptr, subset, sk_ref_sp(const_cast(this))); + srcSpecialImage = SkSpecialImage::MakeFromImage(nullptr, subset, + sk_ref_sp(const_cast(this))); #endif if (!srcSpecialImage) { return nullptr; @@ -412,6 +410,18 @@ sk_sp SkImage::makeWithFilter(GrContext* grContext, return result->asImage(); } +#ifdef SK_IMAGE_MAKE_WITH_FILTER_LEGACY_API +sk_sp SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRect& subset, + const SkIRect& clipBounds, SkIRect* outSubset, + SkIPoint* offset) const { + GrRecordingContext* rContext = nullptr; +#if SK_SUPPORT_GPU + rContext = as_IB(this)->context(); +#endif + return this->makeWithFilter(rContext, filter, subset, clipBounds, outSubset, offset); +} +#endif + bool SkImage::isLazyGenerated() const { return as_IB(this)->onIsLazyGenerated(); } diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index f8de5dcd3cfb..855604e450f1 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -329,9 +329,10 @@ static sk_sp make_blue(sk_sp input, const SkIRect* return SkImageFilters::ColorFilter(std::move(filter), std::move(input), cropRect); } -static sk_sp create_empty_special_surface(GrContext* context, int widthHeight) { - if (context) { - return SkSpecialSurface::MakeRenderTarget(context, widthHeight, widthHeight, +static sk_sp create_empty_special_surface(GrRecordingContext* rContext, + int widthHeight) { + if (rContext) { + return SkSpecialSurface::MakeRenderTarget(rContext, widthHeight, widthHeight, GrColorType::kRGBA_8888, nullptr); } else { const SkImageInfo info = SkImageInfo::MakeN32(widthHeight, widthHeight, @@ -340,17 +341,18 @@ static sk_sp create_empty_special_surface(GrContext* context, } } -static sk_sp create_surface(GrContext* context, int width, int height) { +static sk_sp create_surface(GrRecordingContext* rContext, int width, int height) { const SkImageInfo info = SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType); - if (context) { - return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info); + if (rContext) { + return SkSurface::MakeRenderTarget(rContext, SkBudgeted::kNo, info); } else { return SkSurface::MakeRaster(info); } } -static sk_sp create_empty_special_image(GrContext* context, int widthHeight) { - sk_sp surf(create_empty_special_surface(context, widthHeight)); +static sk_sp create_empty_special_image(GrRecordingContext* rContext, + int widthHeight) { + sk_sp surf(create_empty_special_surface(rContext, widthHeight)); SkASSERT(surf); @@ -467,11 +469,11 @@ DEF_TEST(ImageFilter, reporter) { } } -static void test_cropRects(skiatest::Reporter* reporter, GrContext* context) { +static void test_cropRects(skiatest::Reporter* reporter, GrRecordingContext* rContext) { // Check that all filters offset to their absolute crop rect, // unaffected by the input crop rect. // Tests pass by not asserting. - sk_sp srcImg(create_empty_special_image(context, 100)); + sk_sp srcImg(create_empty_special_image(rContext, 100)); SkASSERT(srcImg); SkIRect inputCropRect = SkIRect::MakeXYWH(8, 13, 80, 80); @@ -504,7 +506,8 @@ static bool special_image_to_bitmap(const SkSpecialImage* src, SkBitmap* dst) { return img->readPixels(dst->pixmap(), src->subset().fLeft, src->subset().fTop); } -static void test_negative_blur_sigma(skiatest::Reporter* reporter, GrContext* context) { +static void test_negative_blur_sigma(skiatest::Reporter* reporter, + GrRecordingContext* rContext) { // Check that SkBlurImageFilter will accept a negative sigma, either in // the given arguments or after CTM application. static const int kWidth = 32, kHeight = 32; @@ -515,7 +518,7 @@ static void test_negative_blur_sigma(skiatest::Reporter* reporter, GrContext* co sk_sp gradient = SkImage::MakeFromBitmap(make_gradient_circle(kWidth, kHeight)); sk_sp imgSrc( - SkSpecialImage::MakeFromImage(context, SkIRect::MakeWH(kWidth, kHeight), gradient)); + SkSpecialImage::MakeFromImage(rContext, SkIRect::MakeWH(kWidth, kHeight), gradient)); SkIPoint offset; SkImageFilter_Base::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr, @@ -664,13 +667,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(MorphologyFilterRadiusWithMirrorCTM_Gpu, repo test_morphology_radius_with_mirror_ctm(reporter, ctxInfo.directContext()); } -static void test_zero_blur_sigma(skiatest::Reporter* reporter, GrContext* context) { +static void test_zero_blur_sigma(skiatest::Reporter* reporter, GrRecordingContext* rContext) { // Check that SkBlurImageFilter with a zero sigma and a non-zero srcOffset works correctly. SkIRect cropRect = SkIRect::MakeXYWH(5, 0, 5, 10); sk_sp input(SkImageFilters::Offset(0, 0, nullptr, &cropRect)); sk_sp filter(SkImageFilters::Blur(0, 0, std::move(input), &cropRect)); - sk_sp surf(create_empty_special_surface(context, 10)); + sk_sp surf(create_empty_special_surface(rContext, 10)); surf->getCanvas()->clear(SK_ColorGREEN); sk_sp image(surf->makeImageSnapshot()); @@ -709,9 +712,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterZeroBlurSigma_Gpu, reporter, ctxIn // Tests that, even when an upstream filter has returned null (due to failure or clipping), a // downstream filter that affects transparent black still does so even with a nullptr input. -static void test_fail_affects_transparent_black(skiatest::Reporter* reporter, GrContext* context) { +static void test_fail_affects_transparent_black(skiatest::Reporter* reporter, + GrRecordingContext* rContext) { sk_sp failFilter(new FailImageFilter()); - sk_sp source(create_empty_special_image(context, 5)); + sk_sp source(create_empty_special_image(rContext, 5)); SkImageFilter_Base::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 1, 1), nullptr, kN32_SkColorType, nullptr, source.get()); sk_sp green(SkColorFilters::Blend(SK_ColorGREEN, SkBlendMode::kSrc)); @@ -986,7 +990,8 @@ DEF_TEST(ImageFilterUnionBounds, reporter) { } } -static void test_imagefilter_merge_result_size(skiatest::Reporter* reporter, GrContext* context) { +static void test_imagefilter_merge_result_size(skiatest::Reporter* reporter, + GrRecordingContext* rContext) { SkBitmap greenBM; greenBM.allocN32Pixels(20, 20); greenBM.eraseColor(SK_ColorGREEN); @@ -994,7 +999,7 @@ static void test_imagefilter_merge_result_size(skiatest::Reporter* reporter, GrC sk_sp source(SkImageFilters::Image(std::move(greenImage))); sk_sp merge(SkImageFilters::Merge(source, source)); - sk_sp srcImg(create_empty_special_image(context, 1)); + sk_sp srcImg(create_empty_special_image(rContext, 1)); SkImageFilter_Base::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr, kN32_SkColorType, nullptr, srcImg.get()); @@ -1132,7 +1137,7 @@ DEF_TEST(ImageFilterMatrixConvolutionBorder, reporter) { canvas.restore(); } -static void test_big_kernel(skiatest::Reporter* reporter, GrContext* context) { +static void test_big_kernel(skiatest::Reporter* reporter, GrRecordingContext* rContext) { // Check that a kernel that is too big for the GPU still works SkScalar identityKernel[49] = { 0, 0, 0, 0, 0, 0, 0, @@ -1151,7 +1156,7 @@ static void test_big_kernel(skiatest::Reporter* reporter, GrContext* context) { kernelSize, identityKernel, gain, bias, kernelOffset, SkTileMode::kClamp, true, nullptr)); - sk_sp srcImg(create_empty_special_image(context, 100)); + sk_sp srcImg(create_empty_special_image(rContext, 100)); SkASSERT(srcImg); SkIPoint offset; @@ -1159,7 +1164,7 @@ static void test_big_kernel(skiatest::Reporter* reporter, GrContext* context) { kN32_SkColorType, nullptr, srcImg.get()); sk_sp resultImg(as_IFB(filter)->filterImage(ctx).imageAndOffset(&offset)); REPORTER_ASSERT(reporter, resultImg); - REPORTER_ASSERT(reporter, SkToBool(context) == resultImg->isTextureBacked()); + REPORTER_ASSERT(reporter, SkToBool(rContext) == resultImg->isTextureBacked()); REPORTER_ASSERT(reporter, resultImg->width() == 100 && resultImg->height() == 100); REPORTER_ASSERT(reporter, offset.fX == 0 && offset.fY == 0); } @@ -1207,7 +1212,8 @@ DEF_TEST(ImageFilterMatrix, reporter) { canvas.drawPicture(recorder.finishRecordingAsPicture()); } -static void test_clipped_picture_imagefilter(skiatest::Reporter* reporter, GrContext* context) { +static void test_clipped_picture_imagefilter(skiatest::Reporter* reporter, + GrRecordingContext* rContext) { sk_sp picture; { @@ -1222,7 +1228,7 @@ static void test_clipped_picture_imagefilter(skiatest::Reporter* reporter, GrCon picture = recorder.finishRecordingAsPicture(); } - sk_sp srcImg(create_empty_special_image(context, 2)); + sk_sp srcImg(create_empty_special_image(rContext, 2)); sk_sp imageFilter(SkImageFilters::Picture(picture)); @@ -1443,8 +1449,9 @@ DEF_TEST(XfermodeImageFilterCroppedInput, reporter) { test_xfermode_cropped_input(SkSurface::MakeRasterN32Premul(100, 100).get(), reporter); } -static void test_composed_imagefilter_offset(skiatest::Reporter* reporter, GrContext* context) { - sk_sp srcImg(create_empty_special_image(context, 100)); +static void test_composed_imagefilter_offset(skiatest::Reporter* reporter, + GrRecordingContext* rContext) { + sk_sp srcImg(create_empty_special_image(rContext, 100)); SkIRect cropRect = SkIRect::MakeXYWH(1, 0, 20, 20); sk_sp offsetFilter(SkImageFilters::Offset(0, 0, nullptr, &cropRect)); @@ -1470,7 +1477,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ComposedImageFilterOffset_Gpu, reporter, ctxI test_composed_imagefilter_offset(reporter, ctxInfo.directContext()); } -static void test_composed_imagefilter_bounds(skiatest::Reporter* reporter, GrContext* context) { +static void test_composed_imagefilter_bounds(skiatest::Reporter* reporter, + GrRecordingContext* rContext) { // The bounds passed to the inner filter must be filtered by the outer // filter, so that the inner filter produces the pixels that the outer // filter requires as input. This matters if the outer filter moves pixels. @@ -1488,7 +1496,7 @@ static void test_composed_imagefilter_bounds(skiatest::Reporter* reporter, GrCon sk_sp composedFilter(SkImageFilters::Compose(std::move(offsetFilter), std::move(pictureFilter))); - sk_sp sourceImage(create_empty_special_image(context, 100)); + sk_sp sourceImage(create_empty_special_image(rContext, 100)); SkImageFilter_Base::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr, kN32_SkColorType, nullptr, sourceImage.get()); SkIPoint offset; @@ -1652,8 +1660,8 @@ DEF_TEST(ImageFilterBlurLargeImage, reporter) { test_large_blur_input(reporter, surface->getCanvas()); } -static void test_make_with_filter(skiatest::Reporter* reporter, GrContext* context) { - sk_sp surface(create_surface(context, 192, 128)); +static void test_make_with_filter(skiatest::Reporter* reporter, GrRecordingContext* rContext) { + sk_sp surface(create_surface(rContext, 192, 128)); surface->getCanvas()->clear(SK_ColorRED); SkPaint bluePaint; bluePaint.setColor(SK_ColorBLUE); @@ -1667,31 +1675,39 @@ static void test_make_with_filter(skiatest::Reporter* reporter, GrContext* conte SkIPoint offset; sk_sp result; - result = sourceImage->makeWithFilter(nullptr, subset, clipBounds, &outSubset, &offset); + result = sourceImage->makeWithFilter(rContext, nullptr, subset, clipBounds, + &outSubset, &offset); REPORTER_ASSERT(reporter, !result); - result = sourceImage->makeWithFilter(filter.get(), subset, clipBounds, nullptr, &offset); + result = sourceImage->makeWithFilter(rContext, filter.get(), subset, clipBounds, + nullptr, &offset); REPORTER_ASSERT(reporter, !result); - result = sourceImage->makeWithFilter(filter.get(), subset, clipBounds, &outSubset, nullptr); + result = sourceImage->makeWithFilter(rContext, filter.get(), subset, clipBounds, + &outSubset, nullptr); REPORTER_ASSERT(reporter, !result); SkIRect bigSubset = SkIRect::MakeXYWH(-10000, -10000, 20000, 20000); - result = sourceImage->makeWithFilter(filter.get(), bigSubset, clipBounds, &outSubset, &offset); + result = sourceImage->makeWithFilter(rContext, filter.get(), bigSubset, clipBounds, + &outSubset, &offset); REPORTER_ASSERT(reporter, !result); SkIRect empty = SkIRect::MakeEmpty(); - result = sourceImage->makeWithFilter(filter.get(), empty, clipBounds, &outSubset, &offset); + result = sourceImage->makeWithFilter(rContext, filter.get(), empty, clipBounds, + &outSubset, &offset); REPORTER_ASSERT(reporter, !result); - result = sourceImage->makeWithFilter(filter.get(), subset, empty, &outSubset, &offset); + result = sourceImage->makeWithFilter(rContext, filter.get(), subset, empty, + &outSubset, &offset); REPORTER_ASSERT(reporter, !result); SkIRect leftField = SkIRect::MakeXYWH(-1000, 0, 100, 100); - result = sourceImage->makeWithFilter(filter.get(), subset, leftField, &outSubset, &offset); + result = sourceImage->makeWithFilter(rContext, filter.get(), subset, leftField, + &outSubset, &offset); REPORTER_ASSERT(reporter, !result); - result = sourceImage->makeWithFilter(filter.get(), subset, clipBounds, &outSubset, &offset); + result = sourceImage->makeWithFilter(rContext, filter.get(), subset, clipBounds, + &outSubset, &offset); REPORTER_ASSERT(reporter, result); REPORTER_ASSERT(reporter, result->bounds().contains(outSubset)); @@ -1706,7 +1722,8 @@ static void test_make_with_filter(skiatest::Reporter* reporter, GrContext* conte subset.setXYWH(0, 0, 160, 90); filter = SkImageFilters::Xfermode(SkBlendMode::kSrc, nullptr); - result = sourceImage->makeWithFilter(filter.get(), subset, clipBounds, &outSubset, &offset); + result = sourceImage->makeWithFilter(rContext, filter.get(), subset, clipBounds, + &outSubset, &offset); REPORTER_ASSERT(reporter, result); } } diff --git a/tests/RepeatedClippedBlurTest.cpp b/tests/RepeatedClippedBlurTest.cpp index 1db63bebeaaf..1161ce77b55c 100644 --- a/tests/RepeatedClippedBlurTest.cpp +++ b/tests/RepeatedClippedBlurTest.cpp @@ -23,13 +23,13 @@ // 2D canvas and compositor image filtering. In this case Chrome doesn't regularly purge // the cache. This would result in Ganesh quickly running up to its max cache limit. DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RepeatedClippedBlurTest, reporter, ctxInfo) { - auto context = ctxInfo.directContext(); - GrResourceCache* cache = context->priv().getResourceCache(); + auto dContext = ctxInfo.directContext(); + GrResourceCache* cache = dContext->priv().getResourceCache(); const SkImageInfo ii = SkImageInfo::Make(1024, 600, kRGBA_8888_SkColorType, kPremul_SkAlphaType); - sk_sp dst(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii)); + sk_sp dst(SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, ii)); if (!dst) { ERRORF(reporter, "Could not create surfaces for repeated clipped blur test."); return; @@ -53,7 +53,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RepeatedClippedBlurTest, reporter, ctxInfo) { bm.eraseArea(SkIRect::MakeXYWH(1, 2, 1277, 1274), SK_ColorGREEN); sk_sp rasterImg = SkImage::MakeFromBitmap(bm); - bigImg = rasterImg->makeTextureImage(context); + bigImg = rasterImg->makeTextureImage(dContext); } sk_sp smImg; @@ -63,7 +63,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RepeatedClippedBlurTest, reporter, ctxInfo) { SkImageInfo screenII = SkImageInfo::Make(1024, 600, kRGBA_8888_SkColorType, kPremul_SkAlphaType); - sk_sp s = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, + sk_sp s = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kYes, screenII, 1, kTopLeft_GrSurfaceOrigin, nullptr); SkCanvas* c = s->getCanvas(); @@ -74,7 +74,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RepeatedClippedBlurTest, reporter, ctxInfo) { } // flush here just to clear the playing field - context->flushAndSubmit(); + dContext->flushAndSubmit(); size_t beforeBytes = cache->getResourceBytes(); @@ -93,7 +93,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RepeatedClippedBlurTest, reporter, ctxInfo) { SkIRect outSubset; SkIPoint offset; - sk_sp filteredImg = smImg->makeWithFilter(context, blur.get(), subset, clip, + sk_sp filteredImg = smImg->makeWithFilter(dContext, blur.get(), subset, clip, &outSubset, &offset); SkRect dstRect = SkRect::MakeXYWH(offset.fX, offset.fY, @@ -101,7 +101,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RepeatedClippedBlurTest, reporter, ctxInfo) { dstCanvas->drawImageRect(filteredImg, outSubset, dstRect, nullptr); // Flush here to mimic Chrome's SkiaHelper::ApplyImageFilter - context->flushAndSubmit(); + dContext->flushAndSubmit(); clip.fRight -= 16; }