OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "SkPictureImageFilter.h" | 10 #include "SkPictureImageFilter.h" |
11 #include "SkPictureRecorder.h" | 11 #include "SkPictureRecorder.h" |
12 | 12 |
13 // This GM exercises the SkPictureImageFilter ImageFilter class. | 13 // This GM exercises the SkPictureImageFilter ImageFilter class. |
14 | 14 |
15 class PictureImageFilterGM : public skiagm::GM { | 15 class PictureImageFilterGM : public skiagm::GM { |
16 public: | 16 public: |
17 PictureImageFilterGM() { | 17 PictureImageFilterGM() { |
18 } | 18 } |
19 | 19 |
20 protected: | 20 protected: |
21 virtual SkString onShortName() SK_OVERRIDE { | 21 SkString onShortName() SK_OVERRIDE { |
22 return SkString("pictureimagefilter"); | 22 return SkString("pictureimagefilter"); |
23 } | 23 } |
24 | 24 |
25 void makePicture() { | 25 void makePicture() { |
26 SkPictureRecorder recorder; | 26 SkPictureRecorder recorder; |
27 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); | 27 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); |
28 canvas->clear(0x00000000); | 28 canvas->clear(0x00000000); |
29 SkPaint paint; | 29 SkPaint paint; |
30 paint.setAntiAlias(true); | 30 paint.setAntiAlias(true); |
31 sk_tool_utils::set_portable_typeface(&paint); | 31 sk_tool_utils::set_portable_typeface(&paint); |
32 paint.setColor(0xFFFFFFFF); | 32 paint.setColor(0xFFFFFFFF); |
33 paint.setTextSize(SkIntToScalar(96)); | 33 paint.setTextSize(SkIntToScalar(96)); |
34 const char* str = "e"; | 34 const char* str = "e"; |
35 canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); | 35 canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); |
36 fPicture.reset(recorder.endRecording()); | 36 fPicture.reset(recorder.endRecording()); |
37 } | 37 } |
38 | 38 |
39 virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(600, 300); } | 39 SkISize onISize() SK_OVERRIDE { return SkISize::Make(600, 300); } |
40 | 40 |
41 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 41 void onOnceBeforeDraw() SK_OVERRIDE { |
42 this->makePicture(); | 42 this->makePicture(); |
43 } | 43 } |
44 | 44 |
45 static void fillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkIma
geFilter* filter) { | 45 static void fillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkIma
geFilter* filter) { |
46 SkPaint paint; | 46 SkPaint paint; |
47 paint.setImageFilter(filter); | 47 paint.setImageFilter(filter); |
48 canvas->save(); | 48 canvas->save(); |
49 canvas->clipRect(clipRect); | 49 canvas->clipRect(clipRect); |
50 canvas->drawPaint(paint); | 50 canvas->drawPaint(paint); |
51 canvas->restore(); | 51 canvas->restore(); |
52 } | 52 } |
53 | 53 |
54 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 54 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
55 canvas->clear(0x00000000); | 55 canvas->clear(0x00000000); |
56 { | 56 { |
57 SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30); | 57 SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30); |
58 SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0); | 58 SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0); |
59 SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); | 59 SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); |
60 SkAutoTUnref<SkPictureImageFilter> pictureSource( | 60 SkAutoTUnref<SkPictureImageFilter> pictureSource( |
61 SkPictureImageFilter::Create(fPicture)); | 61 SkPictureImageFilter::Create(fPicture)); |
62 SkAutoTUnref<SkPictureImageFilter> pictureSourceSrcRect( | 62 SkAutoTUnref<SkPictureImageFilter> pictureSourceSrcRect( |
63 SkPictureImageFilter::Create(fPicture, srcRect)); | 63 SkPictureImageFilter::Create(fPicture, srcRect)); |
64 SkAutoTUnref<SkPictureImageFilter> pictureSourceEmptyRect( | 64 SkAutoTUnref<SkPictureImageFilter> pictureSourceEmptyRect( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } | 111 } |
112 | 112 |
113 private: | 113 private: |
114 SkAutoTUnref<SkPicture> fPicture; | 114 SkAutoTUnref<SkPicture> fPicture; |
115 typedef GM INHERITED; | 115 typedef GM INHERITED; |
116 }; | 116 }; |
117 | 117 |
118 /////////////////////////////////////////////////////////////////////////////// | 118 /////////////////////////////////////////////////////////////////////////////// |
119 | 119 |
120 DEF_GM( return new PictureImageFilterGM; ) | 120 DEF_GM( return new PictureImageFilterGM; ) |
OLD | NEW |