Import all GMs as Samples.
Review URL: http://codereview.appspot.com/5332043/
git-svn-id: http://skia.googlecode.com/svn/trunk@2564 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/aarectmodes.cpp b/gm/aarectmodes.cpp
index ffb267d..4ef1f60 100644
--- a/gm/aarectmodes.cpp
+++ b/gm/aarectmodes.cpp
@@ -107,7 +107,6 @@
virtual SkISize onISize() { return make_isize(640, 480); }
virtual void onDraw(SkCanvas* canvas) {
- canvas->drawColor(SK_ColorWHITE);
const SkRect bounds = SkRect::MakeWH(W, H);
static const SkAlpha gAlphaValue[] = { 0xFF, 0x88, 0x88 };
diff --git a/gm/bitmapfilters.cpp b/gm/bitmapfilters.cpp
index 9521cfd..cf98dcd 100644
--- a/gm/bitmapfilters.cpp
+++ b/gm/bitmapfilters.cpp
@@ -86,6 +86,7 @@
fBM8.copyTo(&fBM4444, SkBitmap::kARGB_4444_Config);
fBM8.copyTo(&fBM16, SkBitmap::kRGB_565_Config);
fBM8.copyTo(&fBM32, SkBitmap::kARGB_8888_Config);
+ this->setBGColor(0xFFDDDDDD);
}
protected:
@@ -98,7 +99,6 @@
}
virtual void onDraw(SkCanvas* canvas) {
- canvas->drawColor(0xFFDDDDDD);
SkScalar x = SkIntToScalar(10);
SkScalar y = SkIntToScalar(10);
diff --git a/gm/bitmapscroll.cpp b/gm/bitmapscroll.cpp
index c12dd05..70d1052 100644
--- a/gm/bitmapscroll.cpp
+++ b/gm/bitmapscroll.cpp
@@ -49,6 +49,7 @@
BitmapScrollGM() {
// Create the original bitmap.
make_bitmap(quarterWidth, quarterHeight, &origBitmap);
+ this->setBGColor(0xFFDDDDDD);
}
protected:
@@ -68,8 +69,7 @@
int xSpacing = quarterWidth * 20;
int ySpacing = quarterHeight * 16;
- // Draw background and left-hand text labels.
- canvas->drawColor(0xFFDDDDDD);
+ // Draw left-hand text labels.
drawLabel(canvas, "scroll entire bitmap",
x, y, x, y + ySpacing);
drawLabel(canvas, "scroll part of bitmap",
diff --git a/gm/blurs.cpp b/gm/blurs.cpp
index ac9432a..69504f7 100644
--- a/gm/blurs.cpp
+++ b/gm/blurs.cpp
@@ -12,7 +12,9 @@
class BlursGM : public GM {
public:
- BlursGM() {}
+ BlursGM() {
+ this->setBGColor(0xFFDDDDDD);
+ }
protected:
virtual SkString onShortName() {
@@ -23,13 +25,7 @@
return make_isize(700, 500);
}
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(0xFFDDDDDD);
- }
-
virtual void onDraw(SkCanvas* canvas) {
- drawBG(canvas);
-
SkBlurMaskFilter::BlurStyle NONE = SkBlurMaskFilter::BlurStyle(-999);
static const struct {
SkBlurMaskFilter::BlurStyle fStyle;
diff --git a/gm/complexclip.cpp b/gm/complexclip.cpp
index 0a4b6c2..204a378 100644
--- a/gm/complexclip.cpp
+++ b/gm/complexclip.cpp
@@ -16,6 +16,7 @@
class ComplexClipGM : public GM {
public:
ComplexClipGM() {
+ this->setBGColor(SkColorSetRGB(0xA0,0xDD,0xA0));
}
protected:
@@ -26,10 +27,6 @@
SkISize onISize() { return make_isize(550, 1000); }
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(SkColorSetRGB(0xA0,0xDD,0xA0));
- }
-
virtual void onDraw(SkCanvas* canvas) {
SkPath path;
path.moveTo(SkIntToScalar(0), SkIntToScalar(50));
@@ -70,7 +67,6 @@
clipB.close();
SkColor colorB = SK_ColorRED;
- drawBG(canvas);
SkPaint paint;
paint.setAntiAlias(true);
diff --git a/gm/complexclip2.cpp b/gm/complexclip2.cpp
index 44a8935..d6b653e 100644
--- a/gm/complexclip2.cpp
+++ b/gm/complexclip2.cpp
@@ -16,6 +16,8 @@
class ComplexClip2GM : public GM {
public:
ComplexClip2GM() {
+ this->setBGColor(SkColorSetRGB(0xDD,0xA0,0xDD));
+
SkScalar xA = 0 * SK_Scalar1;
SkScalar xB = 10 * SK_Scalar1;
SkScalar xC = 20 * SK_Scalar1;
@@ -86,12 +88,7 @@
SkScalarRoundToInt(fTotalHeight));
}
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(SkColorSetRGB(0xDD,0xA0,0xDD));
- }
-
virtual void onDraw(SkCanvas* canvas) {
- this->drawBG(canvas);
SkPaint rectPaint;
rectPaint.setStyle(SkPaint::kStroke_Style);
rectPaint.setStrokeWidth(-1);
diff --git a/gm/emptypath.cpp b/gm/emptypath.cpp
index ee9dd0c..c52932e 100644
--- a/gm/emptypath.cpp
+++ b/gm/emptypath.cpp
@@ -23,10 +23,6 @@
SkISize onISize() { return make_isize(600, 280); }
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(SK_ColorWHITE);
- }
-
void drawEmpty(SkCanvas* canvas,
SkColor color,
const SkRect& clip,
@@ -44,7 +40,6 @@
}
virtual void onDraw(SkCanvas* canvas) {
- this->drawBG(canvas);
struct FillAndName {
SkPath::FillType fFill;
const char* fName;
diff --git a/gm/filltypes.cpp b/gm/filltypes.cpp
index 0910f6c..73c718e 100644
--- a/gm/filltypes.cpp
+++ b/gm/filltypes.cpp
@@ -13,6 +13,7 @@
SkPath fPath;
public:
FillTypeGM() {
+ this->setBGColor(0xFFDDDDDD);
const SkScalar radius = SkIntToScalar(45);
fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius);
fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius);
@@ -56,8 +57,6 @@
}
virtual void onDraw(SkCanvas* canvas) {
- canvas->drawColor(0xFFDDDDDD);
-
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
SkPaint paint;
diff --git a/gm/gm.cpp b/gm/gm.cpp
new file mode 100644
index 0000000..cf4b640
--- /dev/null
+++ b/gm/gm.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+using namespace skiagm;
+
+GM::GM() {
+ fBGColor = SK_ColorWHITE;
+}
+GM::~GM() {}
+
+void GM::draw(SkCanvas* canvas) {
+ this->drawBackground(canvas);
+ this->drawContent(canvas);
+}
+
+void GM::drawContent(SkCanvas* canvas) {
+ this->onDraw(canvas);
+}
+
+void GM::drawBackground(SkCanvas* canvas) {
+ this->onDrawBackground(canvas);
+}
+
+const char* GM::shortName() {
+ if (fShortName.size() == 0) {
+ fShortName = this->onShortName();
+ }
+ return fShortName.c_str();
+}
+
+void GM::setBGColor(SkColor color) {
+ fBGColor = color;
+}
+
+void GM::onDrawBackground(SkCanvas* canvas) {
+ canvas->drawColor(fBGColor);
+}
+
+// need to explicitly declare this, or we get some weird infinite loop llist
+template GMRegistry* SkTRegistry<GM*, void*>::gHead;
diff --git a/gm/gm.h b/gm/gm.h
index 4035034..4259c39 100644
--- a/gm/gm.h
+++ b/gm/gm.h
@@ -35,27 +35,29 @@
kSkipPicture_Flag = 1 << 1
};
- void draw(SkCanvas*);
+ void draw(SkCanvas*);
+ void drawBackground(SkCanvas*);
+ void drawContent(SkCanvas*);
+
SkISize getISize() { return this->onISize(); }
- const char* shortName() {
- if (fShortName.size() == 0) {
- fShortName = this->onShortName();
- }
- return fShortName.c_str();
- }
+ const char* shortName();
uint32_t getFlags() const {
return this->onGetFlags();
}
+
+ void setBGColor(SkColor);
protected:
virtual void onDraw(SkCanvas*) = 0;
+ virtual void onDrawBackground(SkCanvas*);
virtual SkISize onISize() = 0;
virtual SkString onShortName() = 0;
virtual uint32_t onGetFlags() const { return 0; }
private:
SkString fShortName;
+ SkColor fBGColor;
};
typedef SkTRegistry<GM*, void*> GMRegistry;
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 35a14f4..4051fee 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -41,9 +41,6 @@
using namespace skiagm;
-// need to explicitly declare this, or we get some weird infinite loop llist
-template GMRegistry* SkTRegistry<GM*, void*>::gHead;
-
class Iter {
public:
Iter() {
@@ -707,14 +704,3 @@
}
return 0;
}
-
-///////////////////////////////////////////////////////////////////////////////
-
-using namespace skiagm;
-
-GM::GM() {}
-GM::~GM() {}
-
-void GM::draw(SkCanvas* canvas) {
- this->onDraw(canvas);
-}
diff --git a/gm/gradients.cpp b/gm/gradients.cpp
index ae715ce..aac8a96 100644
--- a/gm/gradients.cpp
+++ b/gm/gradients.cpp
@@ -80,7 +80,9 @@
class GradientsGM : public GM {
public:
- GradientsGM() {}
+ GradientsGM() {
+ this->setBGColor(0xFFDDDDDD);
+ }
protected:
SkString onShortName() {
@@ -88,13 +90,8 @@
}
virtual SkISize onISize() { return make_isize(640, 510); }
-
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(0xFFDDDDDD);
- }
-
+
virtual void onDraw(SkCanvas* canvas) {
- this->drawBG(canvas);
SkPoint pts[2] = {
{ 0, 0 },
diff --git a/gm/hairmodes.cpp b/gm/hairmodes.cpp
index cbbfe86..8bfa186 100644
--- a/gm/hairmodes.cpp
+++ b/gm/hairmodes.cpp
@@ -105,8 +105,6 @@
virtual SkISize onISize() { return make_isize(640, 480); }
virtual void onDraw(SkCanvas* canvas) {
- canvas->drawColor(SK_ColorWHITE);
-
const SkRect bounds = SkRect::MakeWH(W, H);
static const SkAlpha gAlphaValue[] = { 0xFF, 0x88, 0x88 };
diff --git a/gm/lcdtext.cpp b/gm/lcdtext.cpp
index e0e895c..ab8b8e4 100644
--- a/gm/lcdtext.cpp
+++ b/gm/lcdtext.cpp
@@ -30,13 +30,8 @@
SkISize onISize() { return make_isize(640, 480); }
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(SK_ColorWHITE);
- }
-
virtual void onDraw(SkCanvas* canvas) {
- this->drawBG(canvas);
-
+
y = textHeight;
drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderTrue"),
true, true);
diff --git a/gm/ninepatchstretch.cpp b/gm/ninepatchstretch.cpp
index f18e5fc..d1d4dda 100644
--- a/gm/ninepatchstretch.cpp
+++ b/gm/ninepatchstretch.cpp
@@ -66,8 +66,6 @@
}
virtual void onDraw(SkCanvas* canvas) {
- canvas->drawColor(SK_ColorWHITE);
-
SkBitmap bm;
SkIRect center;
make_bitmap(&bm, NULL /*SampleCode::GetGr()*/, ¢er);
diff --git a/gm/nocolorbleed.cpp b/gm/nocolorbleed.cpp
index d8e34bf..26b8184 100755
--- a/gm/nocolorbleed.cpp
+++ b/gm/nocolorbleed.cpp
@@ -11,7 +11,9 @@
class NoColorBleedGM : public GM {
public:
- NoColorBleedGM() {}
+ NoColorBleedGM() {
+ this->setBGColor(0xFFDDDDDD);
+ }
protected:
virtual SkString onShortName() {
@@ -22,13 +24,7 @@
return make_isize(200, 200);
}
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(0xFFDDDDDD);
- }
-
virtual void onDraw(SkCanvas* canvas) {
- drawBG(canvas);
-
SkBitmap sprite;
sprite.setConfig(SkBitmap::kARGB_8888_Config, 4, 4, 4*sizeof(SkColor));
const SkColor spriteData[16] = {
diff --git a/gm/pathfill.cpp b/gm/pathfill.cpp
index 71a45e4..9d4b3c8 100644
--- a/gm/pathfill.cpp
+++ b/gm/pathfill.cpp
@@ -125,13 +125,7 @@
return make_isize(640, 480);
}
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(SK_ColorWHITE);
- }
-
virtual void onDraw(SkCanvas* canvas) {
- this->drawBG(canvas);
-
SkPaint paint;
paint.setAntiAlias(true);
diff --git a/gm/points.cpp b/gm/points.cpp
index 8ac85b7..e4f3c2e 100644
--- a/gm/points.cpp
+++ b/gm/points.cpp
@@ -23,10 +23,6 @@
return make_isize(640, 490);
}
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(SK_ColorWHITE);
- }
-
static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) {
for (size_t i = 0; i < n; i++) {
// Compute these independently and store in variables, rather
@@ -39,8 +35,6 @@
}
virtual void onDraw(SkCanvas* canvas) {
- this->drawBG(canvas);
-
canvas->translate(SK_Scalar1, SK_Scalar1);
SkRandom rand;
diff --git a/gm/poly2poly.cpp b/gm/poly2poly.cpp
index 6a2df87..df824b5 100644
--- a/gm/poly2poly.cpp
+++ b/gm/poly2poly.cpp
@@ -21,10 +21,6 @@
virtual SkISize onISize() {
return make_isize(835, 840);
}
-
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(SK_ColorWHITE);
- }
static void doDraw(SkCanvas* canvas, SkPaint* paint, const int isrc[],
const int idst[], int count) {
@@ -60,9 +56,7 @@
canvas->restore();
}
- virtual void onDraw(SkCanvas* canvas) {
- this->drawBG(canvas);
-
+ virtual void onDraw(SkCanvas* canvas) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setStrokeWidth(SkIntToScalar(4));
diff --git a/gm/shadertext.cpp b/gm/shadertext.cpp
index 2df03cc..b574ab6 100644
--- a/gm/shadertext.cpp
+++ b/gm/shadertext.cpp
@@ -109,7 +109,9 @@
class ShaderTextGM : public GM {
public:
- ShaderTextGM() {}
+ ShaderTextGM() {
+ this->setBGColor(0xFFDDDDDD);
+ }
protected:
@@ -119,13 +121,7 @@
SkISize onISize() { return make_isize(1450, 500); }
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(0xFFDDDDDD);
- }
-
virtual void onDraw(SkCanvas* canvas) {
- this->drawBG(canvas);
-
const char text[] = "Shaded Text";
const int textLen = SK_ARRAY_COUNT(text) - 1;
const int pointSize = 36;
diff --git a/gm/shadows.cpp b/gm/shadows.cpp
index 454fa6a..d4dd72f 100644
--- a/gm/shadows.cpp
+++ b/gm/shadows.cpp
@@ -28,6 +28,7 @@
SkRect fRect;
ShadowsGM() {
+ this->setBGColor(0xFFDDDDDD);
fCirclePath.addCircle(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(10) );
fRect.set(SkIntToScalar(10), SkIntToScalar(10),
SkIntToScalar(30), SkIntToScalar(30));
@@ -42,13 +43,7 @@
return make_isize(200, 80);
}
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(0xFFDDDDDD);
- }
-
virtual void onDraw(SkCanvas* canvas) {
- this->drawBG(canvas);
-
SkBlurDrawLooper* shadowLoopers[5];
shadowLoopers[0] =
new SkBlurDrawLooper (SkIntToScalar(10), SkIntToScalar(5),
diff --git a/gm/shapes.cpp b/gm/shapes.cpp
index 09d90fd..0f46355 100644
--- a/gm/shapes.cpp
+++ b/gm/shapes.cpp
@@ -50,6 +50,8 @@
SkMatrixRef* fMatrixRefs[4];
public:
ShapesGM() {
+ this->setBGColor(0xFFDDDDDD);
+
SkMatrix m;
fGroup.appendShape(make_shape0(false))->unref();
m.setRotate(SkIntToScalar(30), SkIntToScalar(50), SkIntToScalar(50));
@@ -83,13 +85,7 @@
return make_isize(380, 480);
}
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(0xFFDDDDDD);
- }
-
virtual void onDraw(SkCanvas* canvas) {
- this->drawBG(canvas);
-
SkMatrix matrix;
SkGroupShape* gs = new SkGroupShape;
diff --git a/gm/strokerects.cpp b/gm/strokerects.cpp
index 44c0120..92f2a18 100644
--- a/gm/strokerects.cpp
+++ b/gm/strokerects.cpp
@@ -46,8 +46,6 @@
}
virtual void onDraw(SkCanvas* canvas) {
- canvas->drawColor(SK_ColorWHITE);
-
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
diff --git a/gm/strokes.cpp b/gm/strokes.cpp
index d8b21b2..ec265ad 100644
--- a/gm/strokes.cpp
+++ b/gm/strokes.cpp
@@ -49,9 +49,7 @@
return make_isize(W, H*2);
}
- virtual void onDraw(SkCanvas* canvas) {
- canvas->drawColor(SK_ColorWHITE);
-
+ virtual void onDraw(SkCanvas* canvas) {
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(SkIntToScalar(9)/2);
diff --git a/gm/texdata.cpp b/gm/texdata.cpp
index af0a122..e3547af 100644
--- a/gm/texdata.cpp
+++ b/gm/texdata.cpp
@@ -18,7 +18,9 @@
class TexDataGM : public GM {
public:
- TexDataGM() {}
+ TexDataGM() {
+ this->setBGColor(0xff000000);
+ }
protected:
virtual SkString onShortName() {
@@ -29,12 +31,7 @@
return make_isize(2*S, 2*S);
}
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(0xff000000);
- }
-
virtual void onDraw(SkCanvas* canvas) {
- drawBG(canvas);
SkDevice* device = canvas->getDevice();
GrRenderTarget* target = (GrRenderTarget*) device->accessRenderTarget();
GrContext* ctx = GetGr();
diff --git a/gm/tilemodes.cpp b/gm/tilemodes.cpp
index 12b1b09..289caae 100644
--- a/gm/tilemodes.cpp
+++ b/gm/tilemodes.cpp
@@ -80,12 +80,7 @@
SkISize onISize() { return make_isize(880, 560); }
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(SK_ColorWHITE);
- }
-
virtual void onDraw(SkCanvas* canvas) {
- this->drawBG(canvas);
SkRect r = { 0, 0, SkIntToScalar(gWidth*2), SkIntToScalar(gHeight*2) };
diff --git a/gm/tinybitmap.cpp b/gm/tinybitmap.cpp
index 2c45437..d532b5b 100644
--- a/gm/tinybitmap.cpp
+++ b/gm/tinybitmap.cpp
@@ -35,6 +35,7 @@
SkBitmap fBM;
public:
TinyBitmapGM() {
+ this->setBGColor(0xFFDDDDDD);
fBM = make_bitmap();
}
@@ -46,7 +47,6 @@
virtual SkISize onISize() { return make_isize(100, 100); }
virtual void onDraw(SkCanvas* canvas) {
- canvas->drawColor(0xFFDDDDDD);
SkShader* s =
SkShader::CreateBitmapShader(fBM, SkShader::kRepeat_TileMode,
SkShader::kMirror_TileMode);
diff --git a/gm/xfermodes.cpp b/gm/xfermodes.cpp
index 51a959e..4977062 100644
--- a/gm/xfermodes.cpp
+++ b/gm/xfermodes.cpp
@@ -78,15 +78,9 @@
return make_isize(790, 640);
}
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(SK_ColorWHITE);
- }
-
virtual void onDraw(SkCanvas* canvas) {
canvas->translate(SkIntToScalar(10), SkIntToScalar(20));
- this->drawBG(canvas);
-
const struct {
SkXfermode::Mode fMode;
const char* fLabel;