gm: simplify several onName

Change-Id: I9c470c2cf5d546626c279ce65626f767292a94e6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228354
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
Hal Canary 2019-07-18 13:35:49 -04:00 committed by Skia Commit-Bot
parent bbb3f646f8
commit 594fe855a3
10 changed files with 124 additions and 272 deletions

View File

@ -98,16 +98,14 @@ static sk_sp<SkShader> make_radial() {
typedef void (*PaintProc)(SkPaint*, SkScalar width);
class BlurRectGM : public skiagm::GM {
sk_sp<SkMaskFilter> fMaskFilters[kLastEnum_SkBlurStyle + 1];
SkString fName;
SkAlpha fAlpha;
public:
BlurRectGM(const char name[], U8CPU alpha)
: fName(name)
, fAlpha(SkToU8(alpha)) {
}
BlurRectGM(const char name[], U8CPU alpha) : fName(name), fAlpha(SkToU8(alpha)) {}
private:
sk_sp<SkMaskFilter> fMaskFilters[kLastEnum_SkBlurStyle + 1];
const char* fName;
SkAlpha fAlpha;
protected:
void onOnceBeforeDraw() override {
for (int i = 0; i <= kLastEnum_SkBlurStyle; ++i) {
fMaskFilters[i] = SkMaskFilter::MakeBlur((SkBlurStyle)i,
@ -115,13 +113,9 @@ protected:
}
}
SkString onShortName() override {
return fName;
}
SkString onShortName() override { return SkString(fName); }
SkISize onISize() override {
return SkISize::Make(860, 820);
}
SkISize onISize() override { return {860, 820}; }
void onDraw(SkCanvas* canvas) override {
canvas->translate(STROKE_WIDTH*3/2, STROKE_WIDTH*3/2);
@ -161,7 +155,6 @@ protected:
}
}
private:
void drawProcs(SkCanvas* canvas, const SkRect& r, const SkPaint& paint,
bool doClip, const Proc procs[], size_t procsCount) {
SkAutoCanvasRestore acr(canvas, true);
@ -179,8 +172,6 @@ private:
canvas->translate(0, r.height() * 4/3);
}
}
private:
typedef GM INHERITED;
};
DEF_SIMPLE_GM(blurrect_gallery, canvas, 1200, 1024) {

View File

@ -33,18 +33,14 @@
// This GM mimics a blurred RR seen in the wild.
class BlurRoundRectGM : public skiagm::GM {
public:
BlurRoundRectGM(int width, int height)
: fName("blurroundrect"), fWidth(width), fHeight(height) {
fName.appendf("-WH-%ix%i-unevenCorners", width, height);
}
BlurRoundRectGM(int w, int h) : fWidth(w), fHeight(h) {}
private:
SkString onShortName() override {
return fName;
return SkStringPrintf("blurroundrect-WH-%ix%i-unevenCorners", fWidth, fHeight);
}
SkISize onISize() override {
return SkISize::Make(fWidth, fHeight);
}
SkISize onISize() override { return {fWidth, fHeight}; }
void onOnceBeforeDraw() override {
SkVector radii[4];
@ -86,12 +82,8 @@ public:
canvas->drawRRect(fRRect, paint);
}
private:
SkString fName;
SkRRect fRRect;
int fWidth, fHeight;
typedef skiagm::GM INHERITED;
SkRRect fRRect;
int fWidth, fHeight;
};
// Rounded rect with two opposite corners with large radii, the other two
// small.
@ -125,20 +117,9 @@ static sk_sp<SkShader> MakeRadial() {
// Simpler blurred RR test cases where all the radii are the same.
class SimpleBlurRoundRectGM : public skiagm::GM {
public:
SimpleBlurRoundRectGM()
: fName("simpleblurroundrect") {
}
SkString onShortName() override { return SkString("simpleblurroundrect"); }
protected:
SkString onShortName() override {
return fName;
}
SkISize onISize() override {
return SkISize::Make(1000, 500);
}
SkISize onISize() override { return {1000, 500}; }
void onDraw(SkCanvas* canvas) override {
canvas->scale(1.5f, 1.5f);
@ -171,10 +152,6 @@ protected:
}
}
}
private:
const SkString fName;
typedef skiagm::GM INHERITED;
};
// Create one with dimensions/rounded corners based on the skp

View File

@ -54,6 +54,7 @@ static void draw_row(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat,
class FilterBitmapGM : public skiagm::GM {
void onOnceBeforeDraw() override {
this->setBGColor(0xFFDDDDDD);
this->makeBitmap();
@ -69,25 +70,11 @@ class FilterBitmapGM : public skiagm::GM {
fMatrix[2].setScale(0.7f, 1.05f);
}
public:
protected:
SkBitmap fBM;
SkMatrix fMatrix[3];
SkString fName;
FilterBitmapGM()
{
this->setBGColor(0xFFDDDDDD);
}
protected:
SkString onShortName() override {
return fName;
}
SkISize onISize() override {
return SkISize::Make(1024, 768);
}
SkISize onISize() override { return SkISize::Make(1024, 768); }
virtual void makeBitmap() = 0;
virtual SkScalar getScale() = 0;
@ -104,21 +91,17 @@ protected:
canvas->translate(0, size.fHeight);
}
}
private:
typedef skiagm::GM INHERITED;
};
class FilterBitmapTextGM: public FilterBitmapGM {
public:
FilterBitmapTextGM(float textSize)
: fTextSize(textSize)
{
fName.printf("filterbitmap_text_%.2fpt", fTextSize);
}
public:
FilterBitmapTextGM(float textSize) : fTextSize(textSize) {}
protected:
float fTextSize;
private:
SkString onShortName() override {
return SkStringPrintf("filterbitmap_text_%.2fpt", fTextSize);
}
const float fTextSize;
SkScalar getScale() override {
return 32.f/fTextSize;
@ -143,20 +126,18 @@ class FilterBitmapTextGM: public FilterBitmapGM {
setTypeface(&font, "serif", SkFontStyle::BoldItalic());
canvas.drawString("Hamburgefons", fTextSize/2, 4.8f*fTextSize, font, paint);
}
private:
typedef FilterBitmapGM INHERITED;
};
class FilterBitmapCheckerboardGM: public FilterBitmapGM {
SkString onShortName() override {
return SkStringPrintf("filterbitmap_checkerboard_%d_%d%s",
fSize, fNumChecks, fConvertToG8 ? "_g8" : "");
}
public:
FilterBitmapCheckerboardGM(int size, int num_checks, bool convertToG8 = false)
: fSize(size), fNumChecks(num_checks), fConvertToG8(convertToG8)
{
fName.printf("filterbitmap_checkerboard_%d_%d%s",
fSize, fNumChecks, convertToG8 ? "_g8" : "");
}
: fSize(size), fNumChecks(num_checks), fConvertToG8(convertToG8) {}
protected:
protected:
int fSize;
int fNumChecks;
@ -190,23 +171,24 @@ private:
};
class FilterBitmapImageGM: public FilterBitmapGM {
public:
FilterBitmapImageGM(const char filename[], bool convertToG8 = false)
: fFilename(filename), fConvertToG8(convertToG8)
{
fName.printf("filterbitmap_image_%s%s", filename, convertToG8 ? "_g8" : "");
const char* fFilename;
int fSize;
SkString onShortName() override {
return SkStringPrintf("filterbitmap_image_%s%s", fFilename, fConvertToG8 ? "_g8" : "");
}
protected:
SkString fFilename;
int fSize;
public:
FilterBitmapImageGM(const char filename[], bool convertToG8 = false)
: fFilename(filename), fConvertToG8(convertToG8) {}
protected:
SkScalar getScale() override {
return 192.f/fSize;
}
void makeBitmap() override {
SkString resource = SkStringPrintf("images/%s", fFilename.c_str());
SkString resource = SkStringPrintf("images/%s", fFilename);
if (!GetResourceAsBitmap(resource.c_str(), &fBM)) {
fBM.allocN32Pixels(1, 1);
fBM.eraseARGB(255, 255, 0 , 0); // red == bad

View File

@ -19,6 +19,7 @@
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
namespace {
static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) {
SkRect bounds = SkRect::MakeWH(SkIntToScalar(bm.width()),
SkIntToScalar(bm.height()));
@ -46,8 +47,15 @@ static void draw_row(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat,
}
class FilterIndiaBoxGM : public skiagm::GM {
SkBitmap fBM;
SkMatrix fMatrix[2];
void onOnceBeforeDraw() override {
this->makeBitmap();
constexpr char kResource[] = "images/box.gif";
if (!GetResourceAsBitmap(kResource, &fBM)) {
fBM.allocN32Pixels(1, 1);
fBM.eraseARGB(255, 255, 0 , 0); // red == bad
}
SkScalar cx = SkScalarHalf(fBM.width());
SkScalar cy = SkScalarHalf(fBM.height());
@ -59,25 +67,9 @@ class FilterIndiaBoxGM : public skiagm::GM {
fMatrix[1].setRotate(30, cx, cy); fMatrix[1].postScale(horizScale, vertScale);
}
public:
SkBitmap fBM;
SkMatrix fMatrix[2];
SkString fName;
SkString onShortName() override { return SkString("filterindiabox"); }
FilterIndiaBoxGM() { this->setBGColor(ToolUtils::color_to_565(0xFFDDDDDD)); }
FilterIndiaBoxGM(const char filename[]) : fFilename(filename) {
fName.printf("filterindiabox");
}
protected:
SkString onShortName() override {
return fName;
}
SkISize onISize() override {
return SkISize::Make(680, 130);
}
SkISize onISize() override { return {680, 130}; }
void onDraw(SkCanvas* canvas) override {
canvas->translate(10, 10);
@ -90,27 +82,7 @@ protected:
canvas->translate(0, size.fHeight);
}
}
protected:
SkString fFilename;
int fSize;
SkScalar getScale() {
return 192.f/fSize;
}
void makeBitmap() {
if (!GetResourceAsBitmap(fFilename.c_str(), &fBM)) {
fBM.allocN32Pixels(1, 1);
fBM.eraseARGB(255, 255, 0 , 0); // red == bad
}
fSize = fBM.height();
}
private:
typedef skiagm::GM INHERITED;
};
} // namespace
//////////////////////////////////////////////////////////////////////////////
DEF_GM( return new FilterIndiaBoxGM("images/box.gif"); )
DEF_GM( return new FilterIndiaBoxGM(); )

View File

@ -69,22 +69,16 @@ static const char* zh = "zh";
static const char* ja = "ja";
class FontMgrGM : public skiagm::GM {
public:
FontMgrGM() {
SkGraphics::SetFontCacheLimit(16 * 1024 * 1024);
sk_sp<SkFontMgr> fFM;
fName.set("fontmgr_iter");
void onOnceBeforeDraw() override {
SkGraphics::SetFontCacheLimit(16 * 1024 * 1024);
fFM = SkFontMgr::RefDefault();
}
protected:
SkString onShortName() override {
return fName;
}
SkString onShortName() override { return SkString("fontmgr_iter"); }
SkISize onISize() override {
return SkISize::Make(1536, 768);
}
SkISize onISize() override { return {1536, 768}; }
void onDraw(SkCanvas* canvas) override {
SkScalar y = 20;
@ -123,29 +117,19 @@ protected:
y += 24;
}
}
private:
sk_sp<SkFontMgr> fFM;
SkString fName;
typedef GM INHERITED;
};
class FontMgrMatchGM : public skiagm::GM {
sk_sp<SkFontMgr> fFM;
public:
FontMgrMatchGM() : fFM(SkFontMgr::RefDefault()) {
void onOnceBeforeDraw() override {
fFM = SkFontMgr::RefDefault();
SkGraphics::SetFontCacheLimit(16 * 1024 * 1024);
}
protected:
SkString onShortName() override {
return SkString("fontmgr_match");
}
SkString onShortName() override { return SkString("fontmgr_match"); }
SkISize onISize() override {
return SkISize::Make(640, 1024);
}
SkISize onISize() override { return {640, 1024}; }
void iterateFamily(SkCanvas* canvas, const SkFont& font, SkFontStyleSet* fset) {
SkFont f(font);
@ -211,23 +195,22 @@ protected:
this->iterateFamily(canvas, font, fset.get());
return DrawResult::kOk;
}
private:
typedef GM INHERITED;
};
class FontMgrBoundsGM : public skiagm::GM {
public:
FontMgrBoundsGM(double scale, double skew)
: fFM(SkFontMgr::RefDefault())
, fName("fontmgr_bounds")
, fScaleX(SkDoubleToScalar(scale))
, fSkewX(SkDoubleToScalar(skew))
, fLabelBounds(false)
{
if (scale != 1 || skew != 0) {
fName.appendf("_%g_%g", scale, skew);
FontMgrBoundsGM(float scale, float skew) : fScaleX(scale) , fSkewX(skew) {}
private:
SkString onShortName() override {
if (fScaleX != 1 || fSkewX != 0) {
return SkStringPrintf("fontmgr_bounds_%g_%g", fScaleX, fSkewX);
}
return SkString("fontmgr_bounds");
}
void onOnceBeforeDraw() override {
fFM = SkFontMgr::RefDefault();
}
bool onGetControls(SkMetaData* controls) override {
@ -318,17 +301,9 @@ public:
}
}
}
protected:
SkString onShortName() override {
return fName;
}
SkISize onISize() override {
return SkISize::Make(1024, 850);
}
SkISize onISize() override { return {1024, 850}; }
void onDraw(SkCanvas* canvas) override {
SkFont font;
@ -372,19 +347,16 @@ protected:
}
}
private:
const sk_sp<SkFontMgr> fFM;
SkString fName;
sk_sp<SkFontMgr> fFM;
const SkScalar fScaleX;
const SkScalar fSkewX;
bool fLabelBounds;
typedef GM INHERITED;
bool fLabelBounds = false;
};
//////////////////////////////////////////////////////////////////////////////
DEF_GM(return new FontMgrGM;)
DEF_GM(return new FontMgrMatchGM;)
DEF_GM(return new FontMgrBoundsGM(1.0, 0);)
DEF_GM(return new FontMgrBoundsGM(0.75, 0);)
DEF_GM(return new FontMgrBoundsGM(1.0, -0.25);)
DEF_GM(return new FontMgrBoundsGM(1, 0);)
DEF_GM(return new FontMgrBoundsGM(0.75f, 0);)
DEF_GM(return new FontMgrBoundsGM(1, -0.25f);)

View File

@ -35,21 +35,13 @@ const char* gProg = R"(
static sk_sp<SkShader> gShader;
class RuntimeShader : public skiagm::GM {
public:
RuntimeShader() {
fName.printf("runtime_shader");
}
sk_sp<SkData> fData;
protected:
bool runAsBench() const override { return true; }
SkString onShortName() override {
return fName;
}
SkString onShortName() override { return SkString("runtime_shader"); }
SkISize onISize() override {
return SkISize::Make(512, 256);
}
SkISize onISize() override { return {512, 256}; }
void onOnceBeforeDraw() override {
// use global to pass gl persistent cache test in dm
@ -69,10 +61,5 @@ protected:
p.setShader(gShader);
canvas->drawRect({0, 0, 256, 256}, p);
}
private:
SkString fName;
sk_sp<SkData> fData;
typedef skiagm::GM INHERITED;
};
DEF_GM(return new RuntimeShader;)

View File

@ -45,20 +45,18 @@ static sk_sp<SkShader> shader_sweep(const SkColor colors[], int count, const SkS
class ShallowGradientGM : public skiagm::GM {
public:
ShallowGradientGM(MakeShaderProc proc, const char name[], bool dither)
: fProc(proc)
, fDither(dither) {
fName.printf("shallow_gradient_%s", name);
}
: fProc(proc), fName(name), fDither(dither) {}
protected:
private:
MakeShaderProc fProc;
const char* fName;
bool fDither;
SkString onShortName() override {
return fName;
return SkStringPrintf("shallow_gradient_%s%s", fName, fDither ? "" : "_nodither");
}
SkISize onISize() override {
return SkISize::Make(800, 800);
}
SkISize onISize() override { return {800, 800}; }
void onDraw(SkCanvas* canvas) override {
const SkColor colors[] = { 0xFF555555, 0xFF444444 };
@ -72,23 +70,18 @@ protected:
paint.setDither(fDither);
canvas->drawRect(r, paint);
}
private:
MakeShaderProc fProc;
SkString fName;
bool fDither;
typedef skiagm::GM INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
DEF_GM( return new ShallowGradientGM(shader_linear, "linear", true); )
DEF_GM( return new ShallowGradientGM(shader_radial, "radial", true); )
DEF_GM( return new ShallowGradientGM(shader_conical, "conical", true); )
DEF_GM( return new ShallowGradientGM(shader_sweep, "sweep", true); )
#define M(PROC, DITHER) DEF_GM( return new ShallowGradientGM(shader_ ## PROC, #PROC, DITHER); )
M(linear, true)
M(radial, true)
M(conical, true)
M(sweep, true)
DEF_GM( return new ShallowGradientGM(shader_linear, "linear_nodither", false); )
DEF_GM( return new ShallowGradientGM(shader_radial, "radial_nodither", false); )
DEF_GM( return new ShallowGradientGM(shader_conical, "conical_nodither", false); )
DEF_GM( return new ShallowGradientGM(shader_sweep, "sweep_nodither", false); )
M(linear, false)
M(radial, false)
M(conical, false)
M(sweep, false)
#undef M

View File

@ -197,17 +197,13 @@ typedef sk_sp<SkShader> (*ShaderProc)(SkTileMode, SkTileMode);
class Tiling2GM : public skiagm::GM {
ShaderProc fProc;
SkString fName;
const char* fName;
public:
Tiling2GM(ShaderProc proc, const char name[]) : fProc(proc) {
fName.printf("tilemode_%s", name);
}
Tiling2GM(ShaderProc proc, const char name[]) : fProc(proc), fName(name) {}
protected:
SkString onShortName() override {
return fName;
}
private:
SkString onShortName() override { return SkString(fName); }
SkISize onISize() override { return SkISize::Make(650, 610); }
@ -261,12 +257,10 @@ protected:
y += r.height() * 4 / 3;
}
}
private:
typedef skiagm::GM INHERITED;
};
DEF_GM( return new Tiling2GM(make_bm, "bitmap"); )
DEF_GM( return new Tiling2GM(make_grad, "gradient"); )
DEF_GM( return new Tiling2GM(make_bm, "tilemode_bitmap"); )
DEF_GM( return new Tiling2GM(make_grad, "tilemode_gradient"); )
////////////////////

View File

@ -194,17 +194,12 @@ typedef sk_sp<SkShader> (*ShaderProc)(SkTileMode, SkTileMode);
class ScaledTiling2GM : public skiagm::GM {
ShaderProc fProc;
SkString fName;
const char* fName;
public:
ScaledTiling2GM(ShaderProc proc, const char name[]) : fProc(proc) {
fName.printf("scaled_tilemode_%s", name);
}
ScaledTiling2GM(ShaderProc proc, const char name[]) : fProc(proc), fName(name) {}
protected:
SkString onShortName() override {
return fName;
}
private:
SkString onShortName() override { return SkString(fName); }
SkISize onISize() override { return SkISize::Make(650, 610); }
@ -257,14 +252,11 @@ protected:
y += r.height() * 4 / 3;
}
}
private:
typedef skiagm::GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_GM( return new ScaledTilingGM(true); )
DEF_GM( return new ScaledTilingGM(false); )
DEF_GM( return new ScaledTiling2GM(make_bm, "bitmap"); )
DEF_GM( return new ScaledTiling2GM(make_grad, "gradient"); )
DEF_GM( return new ScaledTiling2GM(make_bm, "scaled_tilemode_bitmap"); )
DEF_GM( return new ScaledTiling2GM(make_grad, "scaled_tilemode_gradient"); )

View File

@ -45,7 +45,7 @@ static sk_sp<SkImage> make_picture_image(int width, int height, SkColor colors[2
SkPictureRecorder recorder;
draw(recorder.beginRecording(SkRect::MakeIWH(width, height)), width, height, colors);
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
SkISize::Make(width, height), nullptr, nullptr,
{width, height}, nullptr, nullptr,
SkImage::BitDepth::kU8,
SkColorSpace::MakeSRGB());
}
@ -82,21 +82,15 @@ static void show_image(SkCanvas* canvas, int width, int height, SkColor colors[2
class VeryLargeBitmapGM : public skiagm::GM {
ImageMakerProc fProc;
SkString fName;
const char* fName;
public:
VeryLargeBitmapGM(ImageMakerProc proc, const char suffix[]) : fProc(proc) {
fName.printf("verylarge%s", suffix);
}
VeryLargeBitmapGM(ImageMakerProc proc, const char name[]) : fProc(proc), fName(name) {}
protected:
SkString onShortName() override {
return fName;
}
private:
SkString onShortName() override { return SkString(fName); }
SkISize onISize() override {
return SkISize::Make(500, 600);
}
SkISize onISize() override { return {500, 600}; }
void onDraw(SkCanvas* canvas) override {
int veryBig = 65*1024; // 64K < size
@ -128,9 +122,7 @@ protected:
// This used to be big enough that we didn't draw on CPU, but now we do.
show_image(canvas, veryBig, small, colors, fProc);
}
private:
typedef skiagm::GM INHERITED;
};
DEF_GM( return new VeryLargeBitmapGM(make_raster_image, "bitmap"); )
DEF_GM( return new VeryLargeBitmapGM(make_picture_image, "_picture_image"); )
DEF_GM( return new VeryLargeBitmapGM(make_raster_image, "verylargebitmap"); )
DEF_GM( return new VeryLargeBitmapGM(make_picture_image, "verylarge_picture_image"); )