2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "SkBlurImageFilter.h"
12 static void make_bm(SkBitmap* bm) {
13 bm->allocN32Pixels(100, 100);
14 bm->eraseColor(SK_ColorBLUE);
18 paint.setAntiAlias(true);
19 paint.setColor(SK_ColorRED);
20 canvas.drawCircle(50, 50, 50, paint);
23 static void draw_2_bitmaps(SkCanvas* canvas, const SkBitmap& bm, bool doClip,
24 int dx, int dy, SkImageFilter* filter = NULL) {
25 SkAutoCanvasRestore acr(canvas, true);
28 SkRect clipR = SkRect::MakeXYWH(SkIntToScalar(dx),
30 SkIntToScalar(bm.width()),
31 SkIntToScalar(bm.height()));
33 paint.setImageFilter(filter);
38 canvas->clipRect(clipR);
40 canvas->drawSprite(bm, dx, dy, &paint);
45 canvas->translate(SkIntToScalar(bm.width() + 20), 0);
49 canvas->clipRect(clipR);
51 canvas->drawBitmap(bm, SkIntToScalar(dx), SkIntToScalar(dy), &paint);
58 * Compare output of drawSprite and drawBitmap (esp. clipping and imagefilters)
60 class SpriteBitmapGM : public skiagm::GM {
66 SkString onShortName() override {
67 return SkString("spritebitmap");
70 SkISize onISize() override {
71 return SkISize::Make(640, 480);
74 void onDraw(SkCanvas* canvas) override {
82 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(sigma, sigma));
84 draw_2_bitmaps(canvas, bm, false, dx, dy);
85 dy += bm.height() + 20;
86 draw_2_bitmaps(canvas, bm, false, dx, dy, filter);
87 dy += bm.height() + 20;
88 draw_2_bitmaps(canvas, bm, true, dx, dy);
89 dy += bm.height() + 20;
90 draw_2_bitmaps(canvas, bm, true, dx, dy, filter);
97 //////////////////////////////////////////////////////////////////////////////
99 DEF_GM( return new SpriteBitmapGM; )