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 | 11 |
12 // This GM exercises the SkPictureImageFilter ImageFilter class. | 12 // This GM exercises the SkPictureImageFilter ImageFilter class. |
13 | 13 |
14 class PictureImageFilterGM : public skiagm::GM { | 14 class PictureImageFilterGM : public skiagm::GM { |
15 public: | 15 public: |
16 PictureImageFilterGM() { | 16 PictureImageFilterGM() { |
17 } | 17 } |
18 | 18 |
19 protected: | 19 protected: |
20 virtual SkString onShortName() SK_OVERRIDE { | 20 virtual SkString onShortName() SK_OVERRIDE { |
21 return SkString("pictureimagefilter"); | 21 return SkString("pictureimagefilter"); |
22 } | 22 } |
23 | 23 |
24 void makePicture() { | 24 void makePicture() { |
25 SkCanvas* canvas = fPicture.beginRecording(100, 100); | 25 SkPictureRecorder recorder; |
| 26 SkCanvas* canvas = recorder.beginRecording(100, 100); |
26 canvas->clear(0x00000000); | 27 canvas->clear(0x00000000); |
27 SkPaint paint; | 28 SkPaint paint; |
28 paint.setAntiAlias(true); | 29 paint.setAntiAlias(true); |
29 paint.setColor(0xFFFFFFFF); | 30 paint.setColor(0xFFFFFFFF); |
30 paint.setTextSize(SkIntToScalar(96)); | 31 paint.setTextSize(SkIntToScalar(96)); |
31 const char* str = "e"; | 32 const char* str = "e"; |
32 canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); | 33 canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); |
33 fPicture.endRecording(); | 34 fPicture.reset(recorder.endRecording()); |
34 } | 35 } |
35 | 36 |
36 virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(500, 150); } | 37 virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(500, 150); } |
37 | 38 |
38 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 39 virtual void onOnceBeforeDraw() SK_OVERRIDE { |
39 this->makePicture(); | 40 this->makePicture(); |
40 } | 41 } |
41 | 42 |
42 static void fillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkIma
geFilter* filter) { | 43 static void fillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkIma
geFilter* filter) { |
43 SkPaint paint; | 44 SkPaint paint; |
44 paint.setImageFilter(filter); | 45 paint.setImageFilter(filter); |
45 canvas->save(); | 46 canvas->save(); |
46 canvas->clipRect(clipRect); | 47 canvas->clipRect(clipRect); |
47 canvas->drawPaint(paint); | 48 canvas->drawPaint(paint); |
48 canvas->restore(); | 49 canvas->restore(); |
49 } | 50 } |
50 | 51 |
51 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 52 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
52 canvas->clear(0x00000000); | 53 canvas->clear(0x00000000); |
53 { | 54 { |
54 SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30); | 55 SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30); |
55 SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0); | 56 SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0); |
56 SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); | 57 SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); |
57 SkAutoTUnref<SkImageFilter> pictureSource(SkPictureImageFilter::Crea
te(&fPicture)); | 58 SkAutoTUnref<SkImageFilter> pictureSource(SkPictureImageFilter::Crea
te(fPicture)); |
58 SkAutoTUnref<SkImageFilter> pictureSourceSrcRect(SkPictureImageFilte
r::Create(&fPicture, srcRect)); | 59 SkAutoTUnref<SkImageFilter> pictureSourceSrcRect(SkPictureImageFilte
r::Create(fPicture, srcRect)); |
59 SkAutoTUnref<SkImageFilter> pictureSourceEmptyRect(SkPictureImageFil
ter::Create(&fPicture, emptyRect)); | 60 SkAutoTUnref<SkImageFilter> pictureSourceEmptyRect(SkPictureImageFil
ter::Create(fPicture, emptyRect)); |
60 | 61 |
61 // Draw the picture unscaled. | 62 // Draw the picture unscaled. |
62 fillRectFiltered(canvas, bounds, pictureSource); | 63 fillRectFiltered(canvas, bounds, pictureSource); |
63 canvas->translate(SkIntToScalar(100), 0); | 64 canvas->translate(SkIntToScalar(100), 0); |
64 | 65 |
65 // Draw an unscaled subset of the source picture. | 66 // Draw an unscaled subset of the source picture. |
66 fillRectFiltered(canvas, bounds, pictureSourceSrcRect); | 67 fillRectFiltered(canvas, bounds, pictureSourceSrcRect); |
67 canvas->translate(SkIntToScalar(100), 0); | 68 canvas->translate(SkIntToScalar(100), 0); |
68 | 69 |
69 // Draw the picture to an empty rect (should draw nothing). | 70 // Draw the picture to an empty rect (should draw nothing). |
70 fillRectFiltered(canvas, bounds, pictureSourceEmptyRect); | 71 fillRectFiltered(canvas, bounds, pictureSourceEmptyRect); |
71 canvas->translate(SkIntToScalar(100), 0); | 72 canvas->translate(SkIntToScalar(100), 0); |
72 } | 73 } |
73 } | 74 } |
74 | 75 |
75 // SkPictureImageFilter doesn't support serialization yet. | 76 // SkPictureImageFilter doesn't support serialization yet. |
76 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 77 virtual uint32_t onGetFlags() const SK_OVERRIDE { |
77 return kSkipPicture_Flag | | 78 return kSkipPicture_Flag | |
78 kSkipPipe_Flag | | 79 kSkipPipe_Flag | |
79 kSkipPipeCrossProcess_Flag | | 80 kSkipPipeCrossProcess_Flag | |
80 kSkipTiled_Flag | | 81 kSkipTiled_Flag | |
81 kSkipScaledReplay_Flag; | 82 kSkipScaledReplay_Flag; |
82 } | 83 } |
83 | 84 |
84 private: | 85 private: |
85 SkPicture fPicture; | 86 SkAutoTUnref<SkPicture> fPicture; |
86 typedef GM INHERITED; | 87 typedef GM INHERITED; |
87 }; | 88 }; |
88 | 89 |
89 /////////////////////////////////////////////////////////////////////////////// | 90 /////////////////////////////////////////////////////////////////////////////// |
90 | 91 |
91 DEF_GM( return new PictureImageFilterGM; ) | 92 DEF_GM( return new PictureImageFilterGM; ) |
OLD | NEW |