Index: gm/displacement.cpp |
diff --git a/gm/displacement.cpp b/gm/displacement.cpp |
index 353d14ecd8d90bc5ac8cf0163bf656b523274647..4746ef7118e85799384152ff4802c9c58704907d 100644 |
--- a/gm/displacement.cpp |
+++ b/gm/displacement.cpp |
@@ -14,49 +14,33 @@ namespace skiagm { |
class DisplacementMapGM : public GM { |
public: |
- DisplacementMapGM() : fInitialized(false) { |
+ DisplacementMapGM() { |
this->setBGColor(0xFF000000); |
} |
protected: |
- virtual SkString onShortName() { |
+ SkString onShortName() override { |
return SkString("displacement"); |
} |
- void make_bitmaps() { |
- make_bitmap(); |
- make_checkerboard(&fCheckerboard, 80, 80); |
- make_checkerboard(&fSmall, 64, 64); |
- make_checkerboard(&fLarge, 96, 96); |
- make_checkerboard(&fLargeW, 96, 64); |
- make_checkerboard(&fLargeH, 64, 96); |
- } |
+ void onOnceBeforeDraw() override { |
+ fBitmap = sk_tool_utils::create_string_bitmap(80, 80, 0xFF884422, 15, 55, 96, "g"); |
- void make_bitmap() { |
- fBitmap.allocN32Pixels(80, 80); |
- SkCanvas canvas(fBitmap); |
- canvas.clear(0x00000000); |
- SkPaint paint; |
- paint.setAntiAlias(true); |
- sk_tool_utils::set_portable_typeface(&paint); |
- paint.setColor(sk_tool_utils::color_to_565(0xFF884422)); |
- paint.setTextSize(SkIntToScalar(96)); |
- const char* str = "g"; |
- canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55), paint); |
- } |
+ SkColor c1 = sk_tool_utils::color_to_565(0xFF244484); |
+ SkColor c2 = sk_tool_utils::color_to_565(0xFF804020); |
- void make_checkerboard(SkBitmap* bitmap, int w, int h) { |
- bitmap->allocN32Pixels(w, h); |
- SkCanvas canvas(*bitmap); |
- sk_tool_utils::draw_checkerboard(&canvas, sk_tool_utils::color_to_565(0xFF244484), |
- sk_tool_utils::color_to_565(0xFF804020), 8); |
+ fCheckerboard = sk_tool_utils::create_checkerboard_bitmap(80, 80, c1, c2, 8); |
+ fSmall = sk_tool_utils::create_checkerboard_bitmap(64, 64, c1, c2, 8); |
+ fLarge = sk_tool_utils::create_checkerboard_bitmap(96, 96, c1, c2, 8); |
+ fLargeW = sk_tool_utils::create_checkerboard_bitmap(96, 64, c1, c2, 8); |
+ fLargeH = sk_tool_utils::create_checkerboard_bitmap(64, 96, c1, c2, 8); |
} |
- virtual SkISize onISize() { |
+ SkISize onISize() override { |
return SkISize::Make(500, 500); |
} |
- void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) { |
+ void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) const { |
canvas->save(); |
canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
canvas->clipRect(SkRect::MakeWH(SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()))); |
@@ -64,11 +48,7 @@ protected: |
canvas->restore(); |
} |
- virtual void onDraw(SkCanvas* canvas) { |
- if (!fInitialized) { |
- make_bitmaps(); |
- fInitialized = true; |
- } |
+ void onDraw(SkCanvas* canvas) override { |
canvas->clear(SK_ColorBLACK); |
SkPaint paint; |
SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard)); |
@@ -204,14 +184,12 @@ protected: |
} |
private: |
- typedef GM INHERITED; |
SkBitmap fBitmap, fCheckerboard, fSmall, fLarge, fLargeW, fLargeH; |
- bool fInitialized; |
+ |
+ typedef GM INHERITED; |
}; |
////////////////////////////////////////////////////////////////////////////// |
-static GM* MyFactory(void*) { return new DisplacementMapGM; } |
-static GMRegistry reg(MyFactory); |
- |
+DEF_GM(return new DisplacementMapGM;) |
} |