diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-11-15 15:56:38 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-11-15 15:56:38 +0000 |
commit | a4f8137e67e31390b0e7edc5e637a3a02495d1a2 (patch) | |
tree | df9890332f678cdfa5a4fd1ffd9b552f5be6a6c4 /gm/srcmode.cpp | |
parent | 2bde91dcb6f2840e01216054897fe98a930e9104 (diff) |
update srcmode GM to include aa/bw and gradients
add 'G' key to sampleapp, to toggle showing the GM's bounds as an overlay
git-svn-id: http://skia.googlecode.com/svn/trunk@6431 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/srcmode.cpp')
-rw-r--r-- | gm/srcmode.cpp | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/gm/srcmode.cpp b/gm/srcmode.cpp index 3aa1b5759c..5ac102e63e 100644 --- a/gm/srcmode.cpp +++ b/gm/srcmode.cpp @@ -7,10 +7,23 @@ #include "gm.h" #include "SkCanvas.h" +#include "SkGradientShader.h" -#define W SkIntToScalar(100) +#define W SkIntToScalar(80) #define H SkIntToScalar(60) +typedef void (*PaintProc)(SkPaint*); + +static void identity_paintproc(SkPaint* paint) {} +static void gradient_paintproc(SkPaint* paint) { + const SkColor colors[] = { SK_ColorGREEN, SK_ColorBLUE }; + const SkPoint pts[] = { { 0, 0 }, { W, H } }; + SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, + SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode); + paint->setShader(s)->unref(); +} + typedef void (*Proc)(SkCanvas*, const SkPaint&); static void draw_hair(SkCanvas* canvas, const SkPaint& paint) { @@ -36,7 +49,7 @@ static void draw_oval(SkCanvas* canvas, const SkPaint& paint) { static void draw_text(SkCanvas* canvas, const SkPaint& paint) { SkPaint p(paint); p.setTextSize(H/4); - canvas->drawText("Hamburgefons", 12, 0, H*2/3, p); + canvas->drawText("Hamburge", 8, 0, H*2/3, p); } class SrcModeGM : public skiagm::GM { @@ -52,14 +65,13 @@ protected: } virtual SkISize onISize() { - return SkISize::Make(640, 480); + return SkISize::Make(640, 760); } virtual void onDraw(SkCanvas* canvas) { canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); SkPaint paint; - paint.setAntiAlias(true); paint.setColor(0x80FF0000); const Proc procs[] = { @@ -70,15 +82,28 @@ protected: SkXfermode::kSrcOver_Mode, SkXfermode::kSrc_Mode, SkXfermode::kClear_Mode }; - for (size_t x = 0; x < SK_ARRAY_COUNT(modes); ++x) { - paint.setXfermodeMode(modes[x]); + const PaintProc paintProcs[] = { + identity_paintproc, gradient_paintproc + }; + + for (int aa = 0; aa <= 1; ++aa) { + paint.setAntiAlias(SkToBool(aa)); canvas->save(); - for (size_t y = 0; y < SK_ARRAY_COUNT(procs); ++y) { - procs[y](canvas, paint); - canvas->translate(0, H * 5 / 4); + for (size_t i = 0; i < SK_ARRAY_COUNT(paintProcs); ++i) { + paintProcs[i](&paint); + for (size_t x = 0; x < SK_ARRAY_COUNT(modes); ++x) { + paint.setXfermodeMode(modes[x]); + canvas->save(); + for (size_t y = 0; y < SK_ARRAY_COUNT(procs); ++y) { + procs[y](canvas, paint); + canvas->translate(0, H * 5 / 4); + } + canvas->restore(); + canvas->translate(W * 5 / 4, 0); + } } canvas->restore(); - canvas->translate(W * 5 / 4, 0); + canvas->translate(0, (H * 5 / 4) * SK_ARRAY_COUNT(procs)); } } |