Revert "[graphite] Update GMs to have graphite-backed gpu SkImages"

This reverts commit 932801c29e.

Reason for revert: unhappy bots

Original change's description:
> [graphite] Update GMs to have graphite-backed gpu SkImages
>
> This makes part of of our testing infrastructure (i.e., the GMs)
> compatible with Graphite's more stringent requirements.
>
> Bug: skia:12701
> Change-Id: I5d2bf44a1f044797971a1cf6874cf1819d715ca6
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/530539
> Reviewed-by: Jim Van Verth <jvanverth@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>

Bug: skia:12701
Change-Id: I1da473800efd2110c14883d63086a82af53effe2
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/531742
Auto-Submit: Robert Phillips <robertphillips@google.com>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
This commit is contained in:
Robert Phillips 2022-04-19 20:55:02 +00:00 committed by SkCQ
parent 932801c29e
commit 163a7eaf10
19 changed files with 124 additions and 203 deletions

View File

@ -1357,7 +1357,6 @@ generated_cc_atom(
"//include/core:SkTileMode_hdr",
"//include/core:SkTypes_hdr",
"//include/effects:SkGradientShader_hdr",
"//tools:ToolUtils_hdr",
],
)
@ -3150,7 +3149,6 @@ generated_cc_atom(
"//include/effects:SkImageFilters_hdr",
"//src/effects/imagefilters:SkCropImageFilter_hdr",
"//tools:Resources_hdr",
"//tools:ToolUtils_hdr",
],
)
@ -3172,7 +3170,6 @@ generated_cc_atom(
"//include/core:SkSize_hdr",
"//include/core:SkString_hdr",
"//include/core:SkSurface_hdr",
"//tools:ToolUtils_hdr",
],
)
@ -3506,7 +3503,6 @@ generated_cc_atom(
"//include/core:SkMatrix_hdr",
"//include/core:SkRect_hdr",
"//tools:Resources_hdr",
"//tools:ToolUtils_hdr",
],
)
@ -3713,7 +3709,6 @@ generated_cc_atom(
"//include/effects:SkGradientShader_hdr",
"//include/utils:SkRandom_hdr",
"//src/core:SkMathPriv_hdr",
"//tools:ToolUtils_hdr",
],
)
@ -6909,7 +6904,6 @@ generated_cc_atom(
"//include/private:SkTArray_hdr",
"//include/private:SkTDArray_hdr",
"//tools:Resources_hdr",
"//tools:ToolUtils_hdr",
],
)
@ -8647,7 +8641,6 @@ generated_cc_atom(
"//include/core:SkTypes_hdr",
"//include/private:SkTo_hdr",
"//include/utils:SkRandom_hdr",
"//tools:ToolUtils_hdr",
],
)
@ -9367,7 +9360,6 @@ generated_cc_atom(
"//include/core:SkSurface_hdr",
"//include/core:SkTileMode_hdr",
"//include/effects:SkGradientShader_hdr",
"//tools:ToolUtils_hdr",
],
)

View File

@ -20,21 +20,20 @@
#include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "tools/ToolUtils.h"
static sk_sp<SkImage> make_image(SkCanvas* destCanvas) {
static sk_sp<SkImage> make_image() {
auto surf = SkSurface::MakeRasterN32Premul(64, 64);
auto tmpCanvas = surf->getCanvas();
auto canvas = surf->getCanvas();
tmpCanvas->drawColor(SK_ColorRED);
canvas->drawColor(SK_ColorRED);
SkPaint paint;
paint.setAntiAlias(true);
const SkPoint pts[] = { { 0, 0 }, { 64, 64 } };
const SkColor colors[] = { SK_ColorWHITE, SK_ColorBLUE };
paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp));
tmpCanvas->drawCircle(32, 32, 32, paint);
canvas->drawCircle(32, 32, 32, paint);
return ToolUtils::MakeTextureImage(destCanvas, surf->makeImageSnapshot());
return surf->makeImageSnapshot();
}
class DrawBitmapRect2 : public skiagm::GM {
@ -68,7 +67,7 @@ protected:
paint.setStyle(SkPaint::kStroke_Style);
auto sampling = SkSamplingOptions();
auto image = make_image(canvas);
auto image = make_image();
SkRect dstR = { 0, 200, 128, 380 };
@ -153,8 +152,7 @@ protected:
SkRect srcR = { 0.5f, 0.5f, 2.5f, 2.5f };
SkRect dstR = { 100, 100, 300, 200 };
canvas->drawImageRect(ToolUtils::MakeTextureImage(canvas, bitmap.asImage()),
srcR, dstR, SkSamplingOptions(),
canvas->drawImageRect(bitmap.asImage(), srcR, dstR, SkSamplingOptions(),
nullptr, SkCanvas::kStrict_SrcRectConstraint);
}
@ -163,7 +161,7 @@ private:
};
//////////////////////////////////////////////////////////////////////////////
static sk_sp<SkImage> make_big_bitmap(SkCanvas* canvas) {
static sk_sp<SkImage> make_big_bitmap() {
constexpr int gXSize = 4096;
constexpr int gYSize = 4096;
@ -182,7 +180,7 @@ static sk_sp<SkImage> make_big_bitmap(SkCanvas* canvas) {
}
}
bitmap.setImmutable();
return ToolUtils::MakeTextureImage(canvas, bitmap.asImage());
return bitmap.asImage();
}
// This GM attempts to reveal any issues we may have when the GPU has to
@ -209,11 +207,11 @@ protected:
return SkISize::Make(640, 480);
}
void onDraw(SkCanvas* canvas) override {
if (!fBigImage) {
fBigImage = make_big_bitmap(canvas);
}
void onOnceBeforeDraw() override {
fBigImage = make_big_bitmap();
}
void onDraw(SkCanvas* canvas) override {
SkPaint paint;
paint.setAlpha(128);
paint.setBlendMode(SkBlendMode::kXor);

View File

@ -33,7 +33,7 @@
/** Creates an image with two one-pixel wide borders around a checkerboard. The checkerboard is 2x2
checks where each check has as many pixels as is necessary to fill the interior. It returns
the image and a src rect that bounds the checkerboard portion. */
std::tuple<sk_sp<SkImage>, SkRect> make_ringed_image(SkCanvas* canvas, int width, int height) {
std::tuple<sk_sp<SkImage>, SkRect> make_ringed_image(int width, int height) {
// These are kRGBA_8888_SkColorType values.
static constexpr uint32_t kOuterRingColor = 0xFFFF0000,
@ -101,8 +101,7 @@ std::tuple<sk_sp<SkImage>, SkRect> make_ringed_image(SkCanvas* canvas, int width
scanline[x] = kOuterRingColor;
}
bitmap.setImmutable();
return { ToolUtils::MakeTextureImage(canvas, bitmap.asImage()),
SkRect::Make({2, 2, width - 2, height - 2})};
return {bitmap.asImage(), SkRect::Make({2, 2, width - 2, height - 2})};
}
/**
@ -128,10 +127,6 @@ protected:
void drawImage(SkCanvas* canvas, sk_sp<SkImage> image, SkRect srcRect, SkRect dstRect,
const SkSamplingOptions& sampling, SkPaint* paint) {
if (fBatch) {
if (!image) {
return;
}
SkCanvas::ImageSetEntry imageSetEntry[1];
imageSetEntry[0].fImage = image;
imageSetEntry[0].fSrcRect = srcRect;
@ -157,7 +152,7 @@ protected:
paint.setColor(SK_ColorBLUE);
paint.setAntiAlias(aa);
this->drawImage(canvas, fSmallImage, fSmallSrcRect, dst, sampling, &paint);
drawImage(canvas, fSmallImage, fSmallSrcRect, dst, sampling, &paint);
}
// Draw the area of interest of the large image
@ -170,7 +165,7 @@ protected:
paint.setColor(SK_ColorBLUE);
paint.setAntiAlias(aa);
this->drawImage(canvas, fBigImage, fBigSrcRect, dst, sampling, &paint);
drawImage(canvas, fBigImage, fBigSrcRect, dst, sampling, &paint);
}
// Draw upper-left 1/4 of the area of interest of the large image
@ -187,7 +182,7 @@ protected:
paint.setColor(SK_ColorBLUE);
paint.setAntiAlias(aa);
this->drawImage(canvas, fBigImage, src, dst, sampling, &paint);
drawImage(canvas, fBigImage, src, dst, sampling, &paint);
}
// Draw the area of interest of the small image with a normal blur
@ -202,7 +197,7 @@ protected:
paint.setColor(SK_ColorBLUE);
paint.setAntiAlias(aa);
this->drawImage(canvas, fSmallImage, fSmallSrcRect, dst, sampling, &paint);
drawImage(canvas, fSmallImage, fSmallSrcRect, dst, sampling, &paint);
}
// Draw the area of interest of the small image with a outer blur
@ -217,18 +212,15 @@ protected:
paint.setColor(SK_ColorBLUE);
paint.setAntiAlias(aa);
this->drawImage(canvas, fSmallImage, fSmallSrcRect, dst, sampling, &paint);
drawImage(canvas, fSmallImage, fSmallSrcRect, dst, sampling, &paint);
}
void onOnceBeforeDraw() override {
std::tie(fBigImage, fBigSrcRect) = make_ringed_image(2*kMaxTextureSize, 2*kMaxTextureSize);
std::tie(fSmallImage, fSmallSrcRect) = make_ringed_image(kSmallSize, kSmallSize);
}
void onDraw(SkCanvas* canvas) override {
if (!fSmallImage) {
std::tie(fBigImage, fBigSrcRect) = make_ringed_image(canvas,
2*kMaxTextureSize,
2*kMaxTextureSize);
std::tie(fSmallImage, fSmallSrcRect) = make_ringed_image(canvas,
kSmallSize, kSmallSize);
}
canvas->clear(SK_ColorGRAY);
std::vector<SkMatrix> matrices;
// Draw with identity
@ -401,3 +393,5 @@ DEF_SIMPLE_GM(bleed_downscale, canvas, 360, 240) {
canvas->translate(0, 120);
}
}

View File

@ -68,12 +68,8 @@ DEF_SIMPLE_GM(colorwheel_alphatypes, canvas, 256, 128) {
sk_sp<SkData> imgData = GetResourceAsData("images/color_wheel.png");
auto pmImg = ToolUtils::MakeTextureImage(canvas,
SkImage::MakeFromEncoded(imgData,
kPremul_SkAlphaType));
auto upmImg = ToolUtils::MakeTextureImage(canvas,
SkImage::MakeFromEncoded(imgData,
kUnpremul_SkAlphaType));
auto pmImg = SkImage::MakeFromEncoded(imgData, kPremul_SkAlphaType);
auto upmImg = SkImage::MakeFromEncoded(imgData, kUnpremul_SkAlphaType);
SkSamplingOptions linear{SkFilterMode::kLinear};

View File

@ -19,7 +19,6 @@
#include "include/effects/SkImageFilters.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
// TODO(michaelludwig) - This will be made public within SkImageFilters.h at some point
#include "src/effects/imagefilters/SkCropImageFilter.h"
@ -180,19 +179,16 @@ void draw_example(
{
SkRect clippedContentBounds;
if (clippedContentBounds.intersect(contentBounds, kExampleBounds)) {
auto contentImage = ToolUtils::MakeTextureImage(
canvas, image->makeSubset(clippedContentBounds.roundOut()));
if (contentImage) {
SkPaint tiledPaint;
tiledPaint.setShader(contentImage->makeShader(
inputMode, inputMode, SkSamplingOptions(SkFilterMode::kLinear)));
tiledPaint.setAlphaf(0.15f);
auto contentImage = image->makeSubset(clippedContentBounds.roundOut());
SkPaint tiledPaint;
tiledPaint.setShader(contentImage->makeShader(
inputMode, inputMode, SkSamplingOptions(SkFilterMode::kLinear)));
tiledPaint.setAlphaf(0.15f);
canvas->save();
canvas->translate(clippedContentBounds.fLeft, clippedContentBounds.fTop);
canvas->drawPaint(tiledPaint);
canvas->restore();
}
canvas->save();
canvas->translate(clippedContentBounds.fLeft, clippedContentBounds.fTop);
canvas->drawPaint(tiledPaint);
canvas->restore();
}
}
@ -208,8 +204,7 @@ void draw_example(
canvas->clipRect(outputBounds);
canvas->saveLayer(hintContent ? &contentBounds : nullptr, &layerPaint);
auto tmp = ToolUtils::MakeTextureImage(canvas, image);
canvas->drawImageRect(tmp, contentBounds, contentBounds,
canvas->drawImageRect(image.get(), contentBounds, contentBounds,
SkSamplingOptions(SkFilterMode::kLinear), nullptr,
SkCanvas::kFast_SrcRectConstraint);
canvas->restore();

View File

@ -18,32 +18,11 @@
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "tools/ToolUtils.h"
namespace skiagm {
constexpr SkRect kSrcImageClip{75, 75, 275, 275};
static sk_sp<SkImage> create_image(SkCanvas* destCanvas) {
sk_sp<SkSurface> srcSurface = SkSurface::MakeRasterN32Premul(500, 500);
SkCanvas* srcCanvas = srcSurface->getCanvas();
srcCanvas->clear(SK_ColorRED);
SkPaint paint;
paint.setColor(0xff00ff00);
srcCanvas->drawRect(kSrcImageClip, paint);
constexpr SkScalar kStrokeWidth = 10;
SkPaint stroke;
stroke.setStyle(SkPaint::kStroke_Style);
stroke.setStrokeWidth(kStrokeWidth);
stroke.setColor(0xff008800);
srcCanvas->drawRect(kSrcImageClip.makeInset(kStrokeWidth / 2, kStrokeWidth / 2), stroke);
return ToolUtils::MakeTextureImage(destCanvas, srcSurface->makeImageSnapshot());
}
/*
* The purpose of this test is to exercise all three codepaths in skgpu::v1::SurfaceDrawContext
* (drawFilledRect, fillRectToRect, fillRectWithLocalMatrix) that pre-crop filled rects based on the
@ -58,12 +37,28 @@ private:
SkString onShortName() final { return SkString("croppedrects"); }
SkISize onISize() override { return SkISize::Make(500, 500); }
void onDraw(SkCanvas* canvas) override {
if (!fSrcImage) {
fSrcImage = create_image(canvas);
fSrcImageShader = fSrcImage->makeShader(SkSamplingOptions());
}
void onOnceBeforeDraw() override {
sk_sp<SkSurface> srcSurface = SkSurface::MakeRasterN32Premul(500, 500);
SkCanvas* srcCanvas = srcSurface->getCanvas();
srcCanvas->clear(SK_ColorRED);
SkPaint paint;
paint.setColor(0xff00ff00);
srcCanvas->drawRect(kSrcImageClip, paint);
constexpr SkScalar kStrokeWidth = 10;
SkPaint stroke;
stroke.setStyle(SkPaint::kStroke_Style);
stroke.setStrokeWidth(kStrokeWidth);
stroke.setColor(0xff008800);
srcCanvas->drawRect(kSrcImageClip.makeInset(kStrokeWidth / 2, kStrokeWidth / 2), stroke);
fSrcImage = srcSurface->makeImageSnapshot();
fSrcImageShader = fSrcImage->makeShader(SkSamplingOptions());
}
void onDraw(SkCanvas* canvas) override {
canvas->clear(SK_ColorWHITE);
{

View File

@ -11,12 +11,10 @@
#include "include/core/SkMatrix.h"
#include "include/core/SkRect.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
// https://bug.skia.org/4374
DEF_SIMPLE_GM(draw_bitmap_rect_skbug4734, canvas, 64, 64) {
auto img = ToolUtils::MakeTextureImage(canvas, GetResourceAsImage("images/randPixels.png"));
if (img) {
if (auto img = GetResourceAsImage("images/randPixels.png")) {
SkRect rect = SkRect::Make(img->bounds());
rect.inset(0.5, 1.5);
SkRect dst;

View File

@ -104,16 +104,14 @@ static sk_sp<SkImage> makebm(SkCanvas* origCanvas, SkBitmap* resultBM, int w, in
return image;
}
static void bitmapproc(SkCanvas* canvas, sk_sp<SkImage>, const SkBitmap& bm, const SkIRect& srcR,
static void bitmapproc(SkCanvas* canvas, SkImage*, const SkBitmap& bm, const SkIRect& srcR,
const SkRect& dstR, const SkSamplingOptions& sampling,
const SkPaint* paint) {
sk_sp<SkImage> img = ToolUtils::MakeTextureImage(canvas, bm.asImage());
canvas->drawImageRect(img, SkRect::Make(srcR), dstR, sampling, paint,
canvas->drawImageRect(bm.asImage(), SkRect::Make(srcR), dstR, sampling, paint,
SkCanvas::kStrict_SrcRectConstraint);
}
static void bitmapsubsetproc(SkCanvas* canvas, sk_sp<SkImage>,
const SkBitmap& bm, const SkIRect& srcR,
static void bitmapsubsetproc(SkCanvas* canvas, SkImage*, const SkBitmap& bm, const SkIRect& srcR,
const SkRect& dstR, const SkSamplingOptions& sampling,
const SkPaint* paint) {
if (!bm.bounds().contains(srcR)) {
@ -123,23 +121,21 @@ static void bitmapsubsetproc(SkCanvas* canvas, sk_sp<SkImage>,
SkBitmap subset;
if (bm.extractSubset(&subset, srcR)) {
sk_sp<SkImage> subsetImg = ToolUtils::MakeTextureImage(canvas, subset.asImage());
canvas->drawImageRect(subsetImg, dstR, sampling, paint);
canvas->drawImageRect(subset.asImage(), dstR, sampling, paint);
}
}
static void imageproc(SkCanvas* canvas, sk_sp<SkImage> image, const SkBitmap&, const SkIRect& srcR,
static void imageproc(SkCanvas* canvas, SkImage* image, const SkBitmap&, const SkIRect& srcR,
const SkRect& dstR, const SkSamplingOptions& sampling, const SkPaint* paint) {
sk_sp<SkImage> tmp = ToolUtils::MakeTextureImage(canvas, std::move(image));
canvas->drawImageRect(tmp, SkRect::Make(srcR), dstR, sampling, paint,
canvas->drawImageRect(image, SkRect::Make(srcR), dstR, sampling, paint,
SkCanvas::kStrict_SrcRectConstraint);
}
static void imagesubsetproc(SkCanvas* canvas, sk_sp<SkImage> image, const SkBitmap& bm,
static void imagesubsetproc(SkCanvas* canvas, SkImage* image, const SkBitmap& bm,
const SkIRect& srcR, const SkRect& dstR,
const SkSamplingOptions& sampling, const SkPaint* paint) {
if (!image->bounds().contains(srcR)) {
imageproc(canvas, std::move(image), bm, srcR, dstR, sampling, paint);
imageproc(canvas, image, bm, srcR, dstR, sampling, paint);
return;
}
@ -149,8 +145,7 @@ static void imagesubsetproc(SkCanvas* canvas, sk_sp<SkImage> image, const SkBitm
}
}
typedef void DrawRectRectProc(SkCanvas*, sk_sp<SkImage>, const SkBitmap&,
const SkIRect& srcR, const SkRect& dstR,
typedef void DrawRectRectProc(SkCanvas*, SkImage*, const SkBitmap&, const SkIRect&, const SkRect&,
const SkSamplingOptions&, const SkPaint*);
constexpr int gSize = 1024;
@ -176,8 +171,7 @@ protected:
SkISize onISize() override { return SkISize::Make(gSize, gSize); }
void setupImage(SkCanvas* canvas) {
fImage = ToolUtils::MakeTextureImage(canvas,
makebm(canvas, &fLargeBitmap, gBmpSize, gBmpSize));
fImage = makebm(canvas, &fLargeBitmap, gBmpSize, gBmpSize);
}
void onDraw(SkCanvas* canvas) override {
@ -214,7 +208,7 @@ protected:
for (int h = 1; h <= kMaxSrcRectSize; h *= 4) {
SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSize - h) / 2, w, h);
fProc(canvas, fImage, fLargeBitmap, srcRect, dstRect, SkSamplingOptions(),
fProc(canvas, fImage.get(), fLargeBitmap, srcRect, dstRect, SkSamplingOptions(),
nullptr);
SkString label;
@ -252,7 +246,7 @@ protected:
kNormal_SkBlurStyle,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5))));
fProc(canvas, bm.asImage(), bm, srcRect, dstRect,
fProc(canvas, bm.asImage().get(), bm, srcRect, dstRect,
SkSamplingOptions(SkFilterMode::kLinear), &maskPaint);
}
}

View File

@ -338,9 +338,7 @@ private:
int i = y * kM + x;
SkPaint entryPaint = paint;
entryPaint.setAlphaf(fSet[i].fAlpha * paint.getAlphaf());
sk_sp<SkImage> orig = sk_ref_sp(const_cast<SkImage*>(fSet[i].fImage.get()));
canvas->drawImageRect(ToolUtils::MakeTextureImage(canvas, std::move(orig)),
fSet[i].fSrcRect, fSet[i].fDstRect,
canvas->drawImageRect(fSet[i].fImage.get(), fSet[i].fSrcRect, fSet[i].fDstRect,
SkSamplingOptions(), &entryPaint,
SkCanvas::kFast_SrcRectConstraint);
}

View File

@ -25,7 +25,6 @@
#include "include/effects/SkGradientShader.h"
#include "include/utils/SkRandom.h"
#include "src/core/SkMathPriv.h"
#include "tools/ToolUtils.h"
static sk_sp<SkImage> makebm(int w, int h) {
SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
@ -91,7 +90,7 @@ protected:
void onDraw(SkCanvas* canvas) override {
if (nullptr == fImage) {
fImage = ToolUtils::MakeTextureImage(canvas, makebm(gSurfaceSize, gSurfaceSize));
fImage = makebm(gSurfaceSize, gSurfaceSize);
}
const SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)};

View File

@ -46,7 +46,7 @@ const SkSamplingOptions gSamplings[] = {
SkSamplingOptions(SkCubicResampler::Mitchell()),
};
static void draw_contents(SkSurface* surface, SkColor fillC) {
static void drawContents(SkSurface* surface, SkColor fillC) {
SkSize size = SkSize::Make(SkIntToScalar(surface->width()),
SkIntToScalar(surface->height()));
SkCanvas* canvas = surface->getCanvas();
@ -67,7 +67,7 @@ static void draw_contents(SkSurface* surface, SkColor fillC) {
}
static void test_surface(SkCanvas* canvas, SkSurface* surf, bool usePaint) {
draw_contents(surf, SK_ColorRED);
drawContents(surf, SK_ColorRED);
sk_sp<SkImage> imgR = surf->makeImageSnapshot();
if (true) {
@ -75,14 +75,13 @@ static void test_surface(SkCanvas* canvas, SkSurface* surf, bool usePaint) {
SkASSERT(imgR == imgR2);
}
imgR = ToolUtils::MakeTextureImage(canvas, std::move(imgR));
draw_contents(surf, SK_ColorGREEN);
sk_sp<SkImage> imgG = ToolUtils::MakeTextureImage(canvas, surf->makeImageSnapshot());
drawContents(surf, SK_ColorGREEN);
sk_sp<SkImage> imgG = surf->makeImageSnapshot();
// since we've drawn after we snapped imgR, imgG will be a different obj
SkASSERT(imgR != imgG);
draw_contents(surf, SK_ColorBLUE);
drawContents(surf, SK_ColorBLUE);
SkSamplingOptions sampling;
SkPaint paint;

View File

@ -268,16 +268,28 @@ protected:
{ 30, 30, 75, 75 }
};
auto rContext = canvas->recordingContext();
if (rContext && rContext->abandoned()) {
*errorMsg = "Direct context abandoned.";
return DrawResult::kSkip;
}
// These need to be GPU-backed when on the GPU to ensure that the image filters use the GPU
// code paths (otherwise they may choose to do CPU filtering then upload)
sk_sp<SkImage> mainImage = ToolUtils::MakeTextureImage(canvas, fMainImage);
sk_sp<SkImage> auxImage = ToolUtils::MakeTextureImage(canvas, fAuxImage);
sk_sp<SkImage> mainImage, auxImage;
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 (dContext->abandoned()) {
*errorMsg = "Direct context abandoned.";
return DrawResult::kSkip;
}
mainImage = fMainImage->makeTextureImage(dContext);
auxImage = fAuxImage->makeTextureImage(dContext);
} else {
mainImage = fMainImage;
auxImage = fAuxImage;
}
if (!mainImage || !auxImage) {
return DrawResult::kFail;
}
@ -370,10 +382,8 @@ private:
auto rContext = canvas->recordingContext();
result = mainImage->makeWithFilter(rContext, filter.get(), subset, clip,
&outSubset, &offset);
if (!result) {
return;
}
SkASSERT(result);
SkASSERT(mainImage->isTextureBacked() == result->isTextureBacked());
*dstRect = SkIRect::MakeXYWH(offset.x(), offset.y(),

View File

@ -80,7 +80,7 @@ DEF_SIMPLE_GM(imagemasksubset, canvas, 480, 480) {
const SkImageInfo info = SkImageInfo::MakeA8(kSize.width(), kSize.height());
for (size_t i = 0; i < SK_ARRAY_COUNT(makers); ++i) {
sk_sp<SkImage> image = ToolUtils::MakeTextureImage(canvas, makers[i](canvas, info));
sk_sp<SkImage> image = makers[i](canvas, info);
if (image) {
canvas->drawImageRect(image, SkRect::Make(kSubset), kDest, SkSamplingOptions(),
&paint, SkCanvas::kStrict_SrcRectConstraint);

View File

@ -17,7 +17,6 @@
#include "include/private/SkTArray.h"
#include "include/private/SkTDArray.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include <initializer_list>
@ -83,30 +82,27 @@ protected:
SkSamplingOptions(SkFilterMode::kLinear),
SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear),
SkSamplingOptions(SkCubicResampler::Mitchell())}) {
for (const auto& origImage : fImages) {
sk_sp<SkImage> img = ToolUtils::MakeTextureImage(canvas, origImage);
if (img) {
canvas->save();
canvas->concat(m);
SkRect src = { img->width() / 4.f, img->height() / 4.f,
3.f * img->width() / 4.f, 3.f * img->height() / 4 };
SkRect dst = { 0, 0,
3.f / 4.f * img->width(), 3.f / 4.f * img->height()};
switch (type) {
case DrawType::kDrawImage:
canvas->drawImage(img, 0, 0, sampling, &paint);
break;
case DrawType::kDrawImageRectStrict:
canvas->drawImageRect(img, src, dst, sampling, &paint,
SkCanvas::kStrict_SrcRectConstraint);
break;
case DrawType::kDrawImageRectFast:
canvas->drawImageRect(img, src, dst, sampling, &paint,
SkCanvas::kFast_SrcRectConstraint);
break;
}
canvas->restore();
for (const auto& img : fImages) {
canvas->save();
canvas->concat(m);
SkRect src = {img->width() / 4.f, img->height() / 4.f,
3.f * img->width() / 4.f, 3.f * img->height() / 4};
SkRect dst = {0, 0,
3.f / 4.f * img->width(), 3.f / 4.f * img->height()};
switch (type) {
case DrawType::kDrawImage:
canvas->drawImage(img, 0, 0, sampling, &paint);
break;
case DrawType::kDrawImageRectStrict:
canvas->drawImageRect(img, src, dst, sampling, &paint,
SkCanvas::kStrict_SrcRectConstraint);
break;
case DrawType::kDrawImageRectFast:
canvas->drawImageRect(img, src, dst, sampling, &paint,
SkCanvas::kFast_SrcRectConstraint);
break;
}
canvas->restore();
++n;
if (n < 8) {
canvas->translate(bounds.width() + 10.f, 0);

View File

@ -17,7 +17,6 @@
#include "include/core/SkTypes.h"
#include "include/private/SkTo.h"
#include "include/utils/SkRandom.h"
#include "tools/ToolUtils.h"
int make_bm(SkBitmap* bm, int height) {
constexpr int kRadius = 22;
@ -94,8 +93,7 @@ protected:
SkIRect subRect = SkIRect::MakeLTRB(0, startItem * itemHeight,
bmp.width(), bmp.height());
SkRect dstRect = SkRect::MakeWH(SkIntToScalar(bmp.width()), 10.f * itemHeight);
canvas->drawImageRect(ToolUtils::MakeTextureImage(canvas, bmp.asImage()),
SkRect::Make(subRect), dstRect,
canvas->drawImageRect(bmp.asImage(), SkRect::Make(subRect), dstRect,
SkSamplingOptions(SkFilterMode::kLinear), nullptr,
SkCanvas::kStrict_SrcRectConstraint);
canvas->translate(SkIntToScalar(bmp.width() + 10), 0);

View File

@ -24,7 +24,6 @@
#include "include/core/SkSurface.h"
#include "include/core/SkTileMode.h"
#include "include/effects/SkGradientShader.h"
#include "tools/ToolUtils.h"
static void draw(SkCanvas* canvas, int width, int height, SkColor colors[2]) {
const SkPoint center = { SkIntToScalar(width)/2, SkIntToScalar(height)/2 };
@ -55,10 +54,7 @@ typedef sk_sp<SkImage> (*ImageMakerProc)(int width, int height, SkColor colors[2
static void show_image(SkCanvas* canvas, int width, int height, SkColor colors[2],
ImageMakerProc proc) {
sk_sp<SkImage> image = ToolUtils::MakeTextureImage(canvas, proc(width, height, colors));
if (!image) {
return;
}
sk_sp<SkImage> image(proc(width, height, colors));
SkPaint borderPaint;

View File

@ -395,16 +395,12 @@ generated_cc_atom(
"//include/core:SkShader_hdr",
"//include/core:SkSurface_hdr",
"//include/core:SkTextBlob_hdr",
"//include/gpu:GrDirectContext_hdr",
"//include/gpu:GrRecordingContext_hdr",
"//include/ports:SkTypeface_win_hdr",
"//include/private:SkColorData_hdr",
"//include/private:SkFloatingPoint_hdr",
"//modules/svg/include:SkSVGDOM_hdr",
"//modules/svg/include:SkSVGNode_hdr",
"//src/core:SkFontPriv_hdr",
"//src/gpu/ganesh:GrCaps_hdr",
"//src/gpu/ganesh:GrDirectContextPriv_hdr",
"//src/xml:SkDOM_hdr",
],
)

View File

@ -21,14 +21,10 @@
#include "include/core/SkShader.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTextBlob.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/ports/SkTypeface_win.h"
#include "include/private/SkColorData.h"
#include "include/private/SkFloatingPoint.h"
#include "src/core/SkFontPriv.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "tools/ToolUtils.h"
#include <cmath>
@ -521,31 +517,4 @@ void sniff_paths(const char filepath[], std::function<PathSniffCallback> callbac
}
}
sk_sp<SkImage> MakeTextureImage(SkCanvas* canvas, sk_sp<SkImage> orig) {
if (!orig) {
return nullptr;
}
if (canvas->recordingContext() && canvas->recordingContext()->asDirectContext()) {
GrDirectContext* dContext = canvas->recordingContext()->asDirectContext();
const GrCaps* caps = dContext->priv().caps();
if (orig->width() >= caps->maxTextureSize() || orig->height() >= caps->maxTextureSize()) {
// Ganesh is able to tile large SkImage draws. Always forcing SkImages to be uploaded
// prevents this feature from being tested by our tools. For now, leave excessively
// large SkImages as bitmaps.
return orig;
}
return orig->makeTextureImage(dContext);
}
#if SK_GRAPHITE_ENABLED
else if (canvas->recorder()) {
return orig->makeTextureImage(canvas->recorder());
}
#endif
return orig;
}
} // namespace ToolUtils

View File

@ -300,8 +300,6 @@ using PathSniffCallback = void(const SkMatrix&, const SkPath&, const SkPaint&);
// Supported file formats are .svg and .skp.
void sniff_paths(const char filepath[], std::function<PathSniffCallback>);
sk_sp<SkImage> MakeTextureImage(SkCanvas* canvas, sk_sp<SkImage> orig);
} // namespace ToolUtils
#endif // ToolUtils_DEFINED