blob: 5adb4895f70a04136407c622995ce248e9c85e78 [file] [log] [blame]
senorblanco@chromium.org14e21272013-12-12 22:00:34 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9
10#include "SkPictureImageFilter.h"
11
12// This GM exercises the SkPictureImageFilter ImageFilter class.
13
14class PictureImageFilterGM : public skiagm::GM {
15public:
16 PictureImageFilterGM() {
17 }
18
19protected:
20 virtual SkString onShortName() SK_OVERRIDE {
21 return SkString("pictureimagefilter");
22 }
23
24 void makePicture() {
25 SkCanvas* canvas = fPicture.beginRecording(100, 100);
26 canvas->clear(0x00000000);
27 SkPaint paint;
28 paint.setAntiAlias(true);
29 paint.setColor(0xFFFFFFFF);
30 paint.setTextSize(SkIntToScalar(96));
31 const char* str = "e";
32 canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint);
33 }
34
35 virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(500, 150); }
36
37 virtual void onOnceBeforeDraw() SK_OVERRIDE {
38 this->makePicture();
39 }
40
41 static void fillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkImageFilter* filter) {
42 SkPaint paint;
43 paint.setImageFilter(filter);
44 canvas->save();
45 canvas->clipRect(clipRect);
46 canvas->drawPaint(paint);
47 canvas->restore();
48 }
49
50 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
51 canvas->clear(0x00000000);
52 {
53 SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30);
54 SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0);
55 SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100);
56 SkAutoTUnref<SkImageFilter> pictureSource(new SkPictureImageFilter(&fPicture));
57 SkAutoTUnref<SkImageFilter> pictureSourceSrcRect(new SkPictureImageFilter(&fPicture, srcRect));
58 SkAutoTUnref<SkImageFilter> pictureSourceEmptyRect(new SkPictureImageFilter(&fPicture, emptyRect));
59
60 // Draw the picture unscaled.
61 fillRectFiltered(canvas, bounds, pictureSource);
62 canvas->translate(SkIntToScalar(100), 0);
63
64 // Draw an unscaled subset of the source picture.
65 fillRectFiltered(canvas, bounds, pictureSourceSrcRect);
66 canvas->translate(SkIntToScalar(100), 0);
67
68 // Draw the picture to an empty rect (should draw nothing).
69 fillRectFiltered(canvas, bounds, pictureSourceEmptyRect);
70 canvas->translate(SkIntToScalar(100), 0);
71 }
72 }
73
74private:
75 SkPicture fPicture;
76 typedef GM INHERITED;
77};
78
79///////////////////////////////////////////////////////////////////////////////
80
81DEF_GM( return new PictureImageFilterGM; )