diff options
-rw-r--r-- | gm/spritebitmap.cpp | 96 | ||||
-rw-r--r-- | gyp/gmslides.gypi | 1 |
2 files changed, 97 insertions, 0 deletions
diff --git a/gm/spritebitmap.cpp b/gm/spritebitmap.cpp new file mode 100644 index 0000000000..d55d71315e --- /dev/null +++ b/gm/spritebitmap.cpp @@ -0,0 +1,96 @@ +/* + * Copyright 2013 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" +#include "SkCanvas.h" +#include "SkBlurImageFilter.h" + +static void make_bm(SkBitmap* bm) { + bm->setConfig(SkBitmap::kARGB_8888_Config, 100, 100); + bm->allocPixels(); + bm->eraseColor(SK_ColorBLUE); + + SkCanvas canvas(*bm); + SkPaint paint; + paint.setAntiAlias(true); + paint.setColor(SK_ColorRED); + canvas.drawCircle(50, 50, 50, paint); +} + +static void draw_2_bitmaps(SkCanvas* canvas, const SkBitmap& bm, bool doClip, + int dx, int dy, SkImageFilter* filter = NULL) { + SkAutoCanvasRestore acr(canvas, true); + SkPaint paint; + + SkRect clipR = SkRect::MakeXYWH(dx, dy, bm.width(), bm.height()); + + paint.setImageFilter(filter); + clipR.inset(5, 5); + + if (doClip) { + canvas->save(); + canvas->clipRect(clipR); + } + canvas->drawSprite(bm, dx, dy, &paint); + if (doClip) { + canvas->restore(); + } + + canvas->translate(bm.width() + 20, 0); + + if (doClip) { + canvas->save(); + canvas->clipRect(clipR); + } + canvas->drawBitmap(bm, dx, dy, &paint); + if (doClip) { + canvas->restore(); + } +} + +/** + * Compare output of drawSprite and drawBitmap (esp. clipping and imagefilters) + */ +class SpriteBitmapGM : public skiagm::GM { +public: + SpriteBitmapGM() {} + +protected: + virtual SkString onShortName() { + return SkString("spritebitmap"); + } + + virtual SkISize onISize() { + return SkISize::Make(640, 480); + } + + virtual void onDraw(SkCanvas* canvas) { + SkBitmap bm; + make_bm(&bm); + + int dx = 10; + int dy = 10; + + SkScalar sigma = 8; + SkAutoTUnref<SkImageFilter> filter(new SkBlurImageFilter(sigma, sigma)); + + draw_2_bitmaps(canvas, bm, false, dx, dy); + dy += bm.height() + 20; + draw_2_bitmaps(canvas, bm, false, dx, dy, filter); + dy += bm.height() + 20; + draw_2_bitmaps(canvas, bm, true, dx, dy); + dy += bm.height() + 20; + draw_2_bitmaps(canvas, bm, true, dx, dy, filter); + } + +private: + typedef GM INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + +DEF_GM( return new SpriteBitmapGM; ) diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi index 5aa75f6aa3..a50d084b1e 100644 --- a/gyp/gmslides.gypi +++ b/gyp/gmslides.gypi @@ -72,6 +72,7 @@ '../gm/shadertext3.cpp', '../gm/shadows.cpp', '../gm/simpleaaclip.cpp', + '../gm/spritebitmap.cpp', '../gm/srcmode.cpp', '../gm/strokefill.cpp', '../gm/strokerect.cpp', |