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 <robertphillips@google.com>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Commit-Queue: Adlai Holler <adlai@google.com>
>
> 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 <adlai@google.com>
> Commit-Queue: Adlai Holler <adlai@google.com>

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 <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index f8de5dc..855604e 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -329,9 +329,10 @@
     return SkImageFilters::ColorFilter(std::move(filter), std::move(input), cropRect);
 }
 
-static sk_sp<SkSpecialSurface> create_empty_special_surface(GrContext* context, int widthHeight) {
-    if (context) {
-        return SkSpecialSurface::MakeRenderTarget(context, widthHeight, widthHeight,
+static sk_sp<SkSpecialSurface> 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<SkSurface> create_surface(GrContext* context, int width, int height) {
+static sk_sp<SkSurface> 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<SkSpecialImage> create_empty_special_image(GrContext* context, int widthHeight) {
-    sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, widthHeight));
+static sk_sp<SkSpecialImage> create_empty_special_image(GrRecordingContext* rContext,
+                                                        int widthHeight) {
+    sk_sp<SkSpecialSurface> surf(create_empty_special_surface(rContext, widthHeight));
 
     SkASSERT(surf);
 
@@ -467,11 +469,11 @@
     }
 }
 
-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<SkSpecialImage> srcImg(create_empty_special_image(context, 100));
+    sk_sp<SkSpecialImage> srcImg(create_empty_special_image(rContext, 100));
     SkASSERT(srcImg);
 
     SkIRect inputCropRect = SkIRect::MakeXYWH(8, 13, 80, 80);
@@ -504,7 +506,8 @@
     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 @@
 
     sk_sp<SkImage> gradient = SkImage::MakeFromBitmap(make_gradient_circle(kWidth, kHeight));
     sk_sp<SkSpecialImage> 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 @@
     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<SkImageFilter> input(SkImageFilters::Offset(0, 0, nullptr, &cropRect));
     sk_sp<SkImageFilter> filter(SkImageFilters::Blur(0, 0, std::move(input), &cropRect));
 
-    sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, 10));
+    sk_sp<SkSpecialSurface> surf(create_empty_special_surface(rContext, 10));
     surf->getCanvas()->clear(SK_ColorGREEN);
     sk_sp<SkSpecialImage> image(surf->makeImageSnapshot());
 
@@ -709,9 +712,10 @@
 
 // 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<FailImageFilter> failFilter(new FailImageFilter());
-    sk_sp<SkSpecialImage> source(create_empty_special_image(context, 5));
+    sk_sp<SkSpecialImage> 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<SkColorFilter> green(SkColorFilters::Blend(SK_ColorGREEN, SkBlendMode::kSrc));
@@ -986,7 +990,8 @@
     }
 }
 
-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 @@
     sk_sp<SkImageFilter> source(SkImageFilters::Image(std::move(greenImage)));
     sk_sp<SkImageFilter> merge(SkImageFilters::Merge(source, source));
 
-    sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 1));
+    sk_sp<SkSpecialImage> 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 @@
     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 @@
             kernelSize, identityKernel, gain, bias, kernelOffset,
             SkTileMode::kClamp, true, nullptr));
 
-    sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 100));
+    sk_sp<SkSpecialImage> srcImg(create_empty_special_image(rContext, 100));
     SkASSERT(srcImg);
 
     SkIPoint offset;
@@ -1159,7 +1164,7 @@
                                     kN32_SkColorType, nullptr, srcImg.get());
     sk_sp<SkSpecialImage> 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 @@
     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<SkPicture> picture;
 
     {
@@ -1222,7 +1228,7 @@
         picture = recorder.finishRecordingAsPicture();
     }
 
-    sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 2));
+    sk_sp<SkSpecialImage> srcImg(create_empty_special_image(rContext, 2));
 
     sk_sp<SkImageFilter> imageFilter(SkImageFilters::Picture(picture));
 
@@ -1443,8 +1449,9 @@
     test_xfermode_cropped_input(SkSurface::MakeRasterN32Premul(100, 100).get(), reporter);
 }
 
-static void test_composed_imagefilter_offset(skiatest::Reporter* reporter, GrContext* context) {
-    sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 100));
+static void test_composed_imagefilter_offset(skiatest::Reporter* reporter,
+                                             GrRecordingContext* rContext) {
+    sk_sp<SkSpecialImage> srcImg(create_empty_special_image(rContext, 100));
 
     SkIRect cropRect = SkIRect::MakeXYWH(1, 0, 20, 20);
     sk_sp<SkImageFilter> offsetFilter(SkImageFilters::Offset(0, 0, nullptr, &cropRect));
@@ -1470,7 +1477,8 @@
     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 @@
     sk_sp<SkImageFilter> composedFilter(SkImageFilters::Compose(std::move(offsetFilter),
                                                                 std::move(pictureFilter)));
 
-    sk_sp<SkSpecialImage> sourceImage(create_empty_special_image(context, 100));
+    sk_sp<SkSpecialImage> 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 @@
     test_large_blur_input(reporter, surface->getCanvas());
 }
 
-static void test_make_with_filter(skiatest::Reporter* reporter, GrContext* context) {
-    sk_sp<SkSurface> surface(create_surface(context, 192, 128));
+static void test_make_with_filter(skiatest::Reporter* reporter, GrRecordingContext* rContext) {
+    sk_sp<SkSurface> surface(create_surface(rContext, 192, 128));
     surface->getCanvas()->clear(SK_ColorRED);
     SkPaint bluePaint;
     bluePaint.setColor(SK_ColorBLUE);
@@ -1667,31 +1675,39 @@
     SkIPoint offset;
     sk_sp<SkImage> 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 @@
         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 1db63be..1161ce7 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<SkSurface> dst(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii));
+    sk_sp<SkSurface> 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 @@
         bm.eraseArea(SkIRect::MakeXYWH(1, 2, 1277, 1274), SK_ColorGREEN);
 
         sk_sp<SkImage> rasterImg = SkImage::MakeFromBitmap(bm);
-        bigImg = rasterImg->makeTextureImage(context);
+        bigImg = rasterImg->makeTextureImage(dContext);
     }
 
     sk_sp<SkImage> smImg;
@@ -63,7 +63,7 @@
         SkImageInfo screenII = SkImageInfo::Make(1024, 600, kRGBA_8888_SkColorType,
                                                  kPremul_SkAlphaType);
 
-        sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes,
+        sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kYes,
                                                          screenII, 1, kTopLeft_GrSurfaceOrigin,
                                                          nullptr);
         SkCanvas* c = s->getCanvas();
@@ -74,7 +74,7 @@
     }
 
     // flush here just to clear the playing field
-    context->flushAndSubmit();
+    dContext->flushAndSubmit();
 
     size_t beforeBytes = cache->getResourceBytes();
 
@@ -93,7 +93,7 @@
 
         SkIRect outSubset;
         SkIPoint offset;
-        sk_sp<SkImage> filteredImg = smImg->makeWithFilter(context, blur.get(), subset, clip,
+        sk_sp<SkImage> filteredImg = smImg->makeWithFilter(dContext, blur.get(), subset, clip,
                                                            &outSubset, &offset);
 
         SkRect dstRect = SkRect::MakeXYWH(offset.fX, offset.fY,
@@ -101,7 +101,7 @@
         dstCanvas->drawImageRect(filteredImg, outSubset, dstRect, nullptr);
 
         // Flush here to mimic Chrome's SkiaHelper::ApplyImageFilter
-        context->flushAndSubmit();
+        dContext->flushAndSubmit();
 
         clip.fRight -= 16;
     }