add helper makeShader for the common Clamp case
Bug: skia:
Change-Id: I22cac56f35fed16daede0cf1b3e34dfa6f5ae3ea
Reviewed-on: https://skia-review.googlesource.com/14625
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/gm/composeshader.cpp b/gm/composeshader.cpp
index ff525f4..90fcedc 100644
--- a/gm/composeshader.cpp
+++ b/gm/composeshader.cpp
@@ -247,13 +247,10 @@
SkColorType::kAlpha_8_SkColorType, kPremul_SkAlphaType);
skMask.installPixels(imageInfo, dst8Storage.begin(), width, nullptr, nullptr, nullptr);
sk_sp<SkImage> skSrc = SkImage::MakeFromBitmap(skBitmap);
- sk_sp<SkShader> skSrcShader =
- skSrc->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
sk_sp<SkImage> skMaskImage = SkImage::MakeFromBitmap(skMask);
- sk_sp<SkShader> skMaskShader = skMaskImage->makeShader(
- SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
paint.setShader(
- SkShader::MakeComposeShader(skMaskShader, skSrcShader, SkBlendMode::kSrcIn));
+ SkShader::MakeComposeShader(skMaskImage->makeShader(), skSrc->makeShader(),
+ SkBlendMode::kSrcIn));
canvas->drawRect(r, paint);
}
diff --git a/gm/croppedrects.cpp b/gm/croppedrects.cpp
index 0ea265c..006e3d3 100644
--- a/gm/croppedrects.cpp
+++ b/gm/croppedrects.cpp
@@ -47,8 +47,7 @@
srcCanvas->drawRect(kSrcImageClip.makeInset(kStrokeWidth / 2, kStrokeWidth / 2), stroke);
fSrcImage = srcSurface->makeImageSnapshot();
- fSrcImageShader = fSrcImage->makeShader(SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode);
+ fSrcImageShader = fSrcImage->makeShader();
}
void onDraw(SkCanvas* canvas) override {
diff --git a/gm/drawatlas.cpp b/gm/drawatlas.cpp
index d0609b5..de44b6d 100644
--- a/gm/drawatlas.cpp
+++ b/gm/drawatlas.cpp
@@ -220,8 +220,7 @@
canvas->drawAtlas(image, &xform, &tex, &color, 1,
mode, &tex, &paint);
canvas->translate(128, 0);
- paint.setShader(image->makeShader(SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode));
+ paint.setShader(image->makeShader());
canvas->drawVertices(verts, mode, paint);
paint.setShader(nullptr);
canvas->translate(145, 0);
diff --git a/gm/localmatriximageshader.cpp b/gm/localmatriximageshader.cpp
index 2c9fcd2..f63497d 100644
--- a/gm/localmatriximageshader.cpp
+++ b/gm/localmatriximageshader.cpp
@@ -28,8 +28,7 @@
SkMatrix translate = SkMatrix::MakeTrans(100.0f, 0.0f);
SkMatrix rotate;
rotate.setRotate(45.0f);
- sk_sp<SkShader> redImageShader = redImage->makeShader(SkShader::TileMode::kClamp_TileMode,
- SkShader::TileMode::kClamp_TileMode, &translate);
+ sk_sp<SkShader> redImageShader = redImage->makeShader(&translate);
sk_sp<SkShader> redLocalMatrixShader = redImageShader->makeWithLocalMatrix(rotate);
// Rotate about the origin will happen first.
@@ -38,8 +37,7 @@
canvas->drawIRect(SkIRect::MakeWH(250, 250), paint);
sk_sp<SkImage> blueImage = make_image(canvas, SK_ColorBLUE);
- sk_sp<SkShader> blueImageShader = blueImage->makeShader(SkShader::TileMode::kClamp_TileMode,
- SkShader::TileMode::kClamp_TileMode, &rotate);
+ sk_sp<SkShader> blueImageShader = blueImage->makeShader(&rotate);
sk_sp<SkShader> blueLocalMatrixShader = blueImageShader->makeWithLocalMatrix(translate);
// Translate will happen first.
diff --git a/gm/rectangletexture.cpp b/gm/rectangletexture.cpp
index d4f4552..67ffa9a 100644
--- a/gm/rectangletexture.cpp
+++ b/gm/rectangletexture.cpp
@@ -163,8 +163,7 @@
SkPaint clampPaint;
clampPaint.setFilterQuality(q);
- clampPaint.setShader(rectImg->makeShader(SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode));
+ clampPaint.setShader(rectImg->makeShader());
canvas->drawRect(SkRect::MakeWH(1.5f * kWidth, 1.5f * kHeight), clampPaint);
canvas->translate(kWidth * 1.5f + kPad, 0);
diff --git a/include/core/SkImage.h b/include/core/SkImage.h
index c52ad3d..1e5df0b 100644
--- a/include/core/SkImage.h
+++ b/include/core/SkImage.h
@@ -252,6 +252,12 @@
sk_sp<SkShader> makeShader(SkShader::TileMode, SkShader::TileMode,
const SkMatrix* localMatrix = nullptr) const;
+ /**
+ * Helper version of makeShader() that specifies Clamp tilemode.
+ */
+ sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const {
+ return this->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, localMatrix);
+ }
/**
* If the image has direct access to its pixels (i.e. they are in local RAM)
diff --git a/samplecode/SampleFilterQuality.cpp b/samplecode/SampleFilterQuality.cpp
index 2c3eb4c..78aa20e 100644
--- a/samplecode/SampleFilterQuality.cpp
+++ b/samplecode/SampleFilterQuality.cpp
@@ -29,10 +29,7 @@
static sk_sp<SkShader> make_shader(const SkRect& bounds) {
sk_sp<SkImage> image(GetResourceAsImage("mandrill_128.png"));
- if (!image) {
- return nullptr;
- }
- return image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
+ return image ? image->makeShader() : nullptr;
}
#define N 128
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 76b4a52..dc5f68f 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -2907,10 +2907,8 @@
diffuseMap = surf->makeImageSnapshot();
}
- sk_sp<SkShader> povDepthShader = povDepthMap->makeShader(SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode);
- sk_sp<SkShader> diffuseShader = diffuseMap->makeShader(SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode);
+ sk_sp<SkShader> povDepthShader = povDepthMap->makeShader();
+ sk_sp<SkShader> diffuseShader = diffuseMap->makeShader();
// TODO: pass the depth to the shader in vertices, or uniforms
// so we don't have to render depth and color separately
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index 99a7a0c..9d38e16 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -250,9 +250,7 @@
localM.preTranslate(-tex[i].left(), -tex[i].top());
SkPaint pnt(paint);
- sk_sp<SkShader> shader = atlas->makeShader(SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode,
- &localM);
+ sk_sp<SkShader> shader = atlas->makeShader(&localM);
if (!shader) {
break;
}
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 7a0585e..5d996c8 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1676,7 +1676,7 @@
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawText", fContext.get());
SkPaint p(paint);
- p.setShader(atlas->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode));
+ p.setShader(atlas->makeShader());
GrPaint grPaint;
if (colors) {
diff --git a/tests/FlattenableFactoryToName.cpp b/tests/FlattenableFactoryToName.cpp
index 35ec984..fc47dfc 100644
--- a/tests/FlattenableFactoryToName.cpp
+++ b/tests/FlattenableFactoryToName.cpp
@@ -37,6 +37,5 @@
bm.allocN32Pixels(8, 8);
bm.eraseColor(SK_ColorCYAN);
sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm));
- auto shader = image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
- test_flattenable(r, shader.get(), "SkImage::newShader()");
+ test_flattenable(r, image->makeShader().get(), "SkImage::newShader()");
}
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index de4c6e0..e53bd1a 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -426,8 +426,7 @@
SkPixmap pmap(info, pixels, info.minRowBytes());
SkMatrix localMatrix = SkMatrix::MakeScale(1.0f / w, 1.0f / h);
auto fontImage = SkImage::MakeFromRaster(pmap, nullptr, nullptr);
- auto fontShader = fontImage->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode,
- &localMatrix);
+ auto fontShader = fontImage->makeShader(&localMatrix);
fImGuiFontPaint.setShader(fontShader);
fImGuiFontPaint.setColor(SK_ColorWHITE);
fImGuiFontPaint.setFilterQuality(kLow_SkFilterQuality);
@@ -435,9 +434,7 @@
auto gamutImage = GetResourceAsImage("gamut.png");
if (gamutImage) {
- auto gamutShader = gamutImage->makeShader(SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode);
- fImGuiGamutPaint.setShader(gamutShader);
+ fImGuiGamutPaint.setShader(gamutImage->makeShader());
}
fImGuiGamutPaint.setColor(SK_ColorWHITE);
fImGuiGamutPaint.setFilterQuality(kLow_SkFilterQuality);
@@ -1152,8 +1149,7 @@
static int zoomFactor = 4;
ImGui::SliderInt("Scale", &zoomFactor, 1, 16);
- zoomImagePaint.setShader(fLastImage->makeShader(SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode));
+ zoomImagePaint.setShader(fLastImage->makeShader());
zoomImagePaint.setColor(SK_ColorWHITE);
// Zoom by shrinking the corner UVs towards the mouse cursor