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>
This commit is contained in:
Mike Reed 2017-04-28 11:12:19 -04:00 committed by Skia Commit-Bot
parent b6069dfba7
commit 0acd7954a9
12 changed files with 22 additions and 36 deletions

View File

@ -247,13 +247,10 @@ DEF_SIMPLE_GM(composeshader_bitmap2, canvas, 200, 200) {
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);
}

View File

@ -47,8 +47,7 @@ private:
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 {

View File

@ -220,8 +220,7 @@ DEF_SIMPLE_GM(compare_atlas_vertices, canvas, 560, 585) {
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);

View File

@ -28,8 +28,7 @@ DEF_SIMPLE_GM(localmatriximageshader, canvas, 250, 250) {
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 @@ DEF_SIMPLE_GM(localmatriximageshader, canvas, 250, 250) {
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.

View File

@ -163,8 +163,7 @@ protected:
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);

View File

@ -252,6 +252,12 @@ public:
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)

View File

@ -29,10 +29,7 @@ static sk_sp<SkSurface> make_surface(SkCanvas* canvas, const SkImageInfo& info)
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

View File

@ -2907,10 +2907,8 @@ void SkCanvas::onDrawShadowedPicture(const SkPicture* picture,
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

View File

@ -250,9 +250,7 @@ void SkBaseDevice::drawAtlas(const SkImage* atlas, const SkRSXform xform[],
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;
}

View File

@ -1676,7 +1676,7 @@ void SkGpuDevice::drawAtlas(const SkImage* atlas, const SkRSXform xform[],
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) {

View File

@ -37,6 +37,5 @@ DEF_TEST(FlattenableFactoryToName, r) {
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()");
}

View File

@ -426,8 +426,7 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
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 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
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 @@ void Viewer::drawImGui(SkCanvas* canvas) {
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