OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 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 #include "SkCanvas.h" | |
10 #include "SkColorFilter.h" | 9 #include "SkColorFilter.h" |
11 #include "SkColorPriv.h" | |
12 #include "SkShader.h" | |
13 | 10 |
14 #include "SkBlurImageFilter.h" | |
15 #include "SkColorFilterImageFilter.h" | 11 #include "SkColorFilterImageFilter.h" |
16 #include "SkMergeImageFilter.h" | 12 #include "SkDropShadowImageFilter.h" |
17 #include "SkOffsetImageFilter.h" | |
18 #include "SkTestImageFilters.h" | |
19 | 13 |
20 /////////////////////////////////////////////////////////////////////////////// | 14 /////////////////////////////////////////////////////////////////////////////// |
21 | 15 |
22 static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { | 16 static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
23 SkPaint paint; | 17 SkPaint paint; |
24 paint.setImageFilter(imf); | 18 paint.setImageFilter(imf); |
25 paint.setColor(SK_ColorBLACK); | 19 paint.setColor(SK_ColorBLACK); |
26 canvas->save(); | 20 canvas->save(); |
27 canvas->clipRect(r); | 21 canvas->clipRect(r); |
28 canvas->drawPaint(paint); | 22 canvas->drawPaint(paint); |
29 canvas->restore(); | 23 canvas->restore(); |
30 } | 24 } |
31 | 25 |
32 static void draw_path(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { | 26 static void draw_path(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
33 SkPaint paint; | 27 SkPaint paint; |
34 paint.setColor(SK_ColorMAGENTA); | 28 paint.setColor(SK_ColorGREEN); |
35 paint.setImageFilter(imf); | 29 paint.setImageFilter(imf); |
36 paint.setAntiAlias(true); | 30 paint.setAntiAlias(true); |
37 canvas->save(); | 31 canvas->save(); |
38 canvas->clipRect(r); | 32 canvas->clipRect(r); |
39 canvas->drawCircle(r.centerX(), r.centerY(), r.width()*2/5, paint); | 33 canvas->drawCircle(r.centerX(), r.centerY(), r.width()/3, paint); |
40 canvas->restore(); | 34 canvas->restore(); |
41 } | 35 } |
42 | 36 |
43 static void draw_text(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { | 37 static void draw_text(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
44 SkPaint paint; | 38 SkPaint paint; |
45 paint.setImageFilter(imf); | 39 paint.setImageFilter(imf); |
46 paint.setColor(SK_ColorGREEN); | 40 paint.setColor(SK_ColorGREEN); |
47 paint.setAntiAlias(true); | 41 paint.setAntiAlias(true); |
48 paint.setTextSize(r.height()/2); | 42 paint.setTextSize(r.height()/2); |
49 paint.setTextAlign(SkPaint::kCenter_Align); | 43 paint.setTextAlign(SkPaint::kCenter_Align); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 paint.setImageFilter(imf); | 86 paint.setImageFilter(imf); |
93 SkPoint loc = { r.fLeft, r.fTop }; | 87 SkPoint loc = { r.fLeft, r.fTop }; |
94 canvas->getTotalMatrix().mapPoints(&loc, 1); | 88 canvas->getTotalMatrix().mapPoints(&loc, 1); |
95 canvas->drawSprite(bm, | 89 canvas->drawSprite(bm, |
96 SkScalarRoundToInt(loc.fX), SkScalarRoundToInt(loc.fY), | 90 SkScalarRoundToInt(loc.fX), SkScalarRoundToInt(loc.fY), |
97 &paint); | 91 &paint); |
98 } | 92 } |
99 | 93 |
100 /////////////////////////////////////////////////////////////////////////////// | 94 /////////////////////////////////////////////////////////////////////////////// |
101 | 95 |
102 class ImageFiltersCroppedGM : public skiagm::GM { | 96 class DropShadowImageFilterGM : public skiagm::GM { |
103 public: | 97 public: |
104 ImageFiltersCroppedGM () {} | 98 DropShadowImageFilterGM () {} |
105 | 99 |
106 protected: | 100 protected: |
107 | 101 |
108 virtual SkString onShortName() { | 102 virtual SkString onShortName() { |
109 return SkString("imagefilterscropped"); | 103 return SkString("dropshadowimagefilter"); |
110 } | 104 } |
111 | 105 |
112 virtual SkISize onISize() { return SkISize::Make(400, 640); } | 106 virtual SkISize onISize() { return SkISize::Make(400, 700); } |
113 | 107 |
114 void draw_frame(SkCanvas* canvas, const SkRect& r) { | 108 void draw_frame(SkCanvas* canvas, const SkRect& r) { |
115 SkPaint paint; | 109 SkPaint paint; |
116 paint.setStyle(SkPaint::kStroke_Style); | 110 paint.setStyle(SkPaint::kStroke_Style); |
117 paint.setColor(SK_ColorRED); | 111 paint.setColor(SK_ColorRED); |
118 canvas->drawRect(r, paint); | 112 canvas->drawRect(r, paint); |
119 } | 113 } |
120 | 114 |
121 virtual uint32_t onGetFlags() const { | 115 virtual uint32_t onGetFlags() const { |
122 // Because of the use of drawSprite, this test is excluded | 116 // Because of the use of drawSprite, this test is excluded |
123 // from scaled replay tests because drawSprite ignores the | 117 // from scaled replay tests because drawSprite ignores the |
124 // reciprocal scale that is applied at record time, which is | 118 // reciprocal scale that is applied at record time, which is |
125 // the intended behavior of drawSprite. | 119 // the intended behavior of drawSprite. |
126 return kSkipScaledReplay_Flag; | 120 return kSkipScaledReplay_Flag; |
127 } | 121 } |
128 | 122 |
129 virtual void onDraw(SkCanvas* canvas) { | 123 virtual void onDraw(SkCanvas* canvas) { |
130 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { | 124 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { |
131 draw_sprite, draw_bitmap, draw_path, draw_paint, draw_text | 125 draw_sprite, draw_bitmap, draw_path, draw_paint, draw_text |
132 }; | 126 }; |
133 | 127 |
134 SkAutoTUnref<SkColorFilter> cf( | 128 SkAutoTUnref<SkColorFilter> cf( |
135 SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mod
e)); | 129 SkColorFilter::CreateModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_
Mode)); |
136 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10,
44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge); | 130 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get
())); |
137 SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -
100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge); | 131 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10,
44, 44)), |
138 | 132 SkImageFilter::CropRect::kHasAll_CropEd
ge); |
139 SkAutoTUnref<SkImageFilter> offset(new SkOffsetImageFilter( | 133 SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -
100, 10, 10)), |
140 SkIntToScalar(-10), SkIntToScalar(-10))); | 134 SkImageFilter::CropRect::kHasAll_CropE
dge); |
141 | |
142 SkAutoTUnref<SkImageFilter> cfOffset(SkColorFilterImageFilter::Create(cf
.get(), offset.get())); | |
143 | 135 |
144 SkImageFilter* filters[] = { | 136 SkImageFilter* filters[] = { |
145 NULL, | 137 NULL, |
146 SkColorFilterImageFilter::Create(cf.get(), NULL, &cropRect), | 138 new SkDropShadowImageFilter(7.0f, 0.0f, 0.0f, 3.0f, SK_ColorBLUE), |
147 new SkBlurImageFilter(1.0f, 1.0f, NULL, &cropRect), | 139 new SkDropShadowImageFilter(0.0f, 7.0f, 3.0f, 0.0f, SK_ColorBLUE), |
148 new SkBlurImageFilter(8.0f, 0.0f, NULL, &cropRect), | 140 new SkDropShadowImageFilter(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE), |
149 new SkBlurImageFilter(0.0f, 8.0f, NULL, &cropRect), | 141 new SkDropShadowImageFilter(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, cf
if), |
150 new SkBlurImageFilter(8.0f, 8.0f, NULL, &cropRect), | 142 new SkDropShadowImageFilter(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, NU
LL, &cropRect), |
151 new SkMergeImageFilter(NULL, cfOffset.get(), SkXfermode::kSrcOver_Mo
de, &cropRect), | 143 new SkDropShadowImageFilter(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, NU
LL, &bogusRect), |
152 new SkBlurImageFilter(8.0f, 8.0f, NULL, &bogusRect), | |
153 SkColorFilterImageFilter::Create(cf.get(), NULL, &bogusRect), | |
154 }; | 144 }; |
155 | 145 |
156 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); | 146 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); |
157 SkScalar MARGIN = SkIntToScalar(16); | 147 SkScalar MARGIN = SkIntToScalar(16); |
158 SkScalar DX = r.width() + MARGIN; | 148 SkScalar DX = r.width() + MARGIN; |
159 SkScalar DY = r.height() + MARGIN; | 149 SkScalar DY = r.height() + MARGIN; |
160 | 150 |
161 canvas->translate(MARGIN, MARGIN); | 151 canvas->translate(MARGIN, MARGIN); |
162 for (size_t j = 0; j < SK_ARRAY_COUNT(drawProc); ++j) { | 152 for (size_t j = 0; j < SK_ARRAY_COUNT(drawProc); ++j) { |
163 canvas->save(); | 153 canvas->save(); |
164 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 154 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
165 drawProc[j](canvas, r, filters[i]); | 155 drawProc[j](canvas, r, filters[i]); |
166 canvas->translate(0, DY); | 156 canvas->translate(0, DY); |
167 } | 157 } |
168 canvas->restore(); | 158 canvas->restore(); |
169 canvas->translate(DX, 0); | 159 canvas->translate(DX, 0); |
170 } | 160 } |
171 | 161 |
172 for(size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) { | 162 for(size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) { |
173 SkSafeUnref(filters[j]); | 163 SkSafeUnref(filters[j]); |
174 } | 164 } |
175 } | 165 } |
176 | 166 |
177 private: | 167 private: |
178 typedef GM INHERITED; | 168 typedef GM INHERITED; |
179 }; | 169 }; |
180 | 170 |
181 /////////////////////////////////////////////////////////////////////////////// | 171 /////////////////////////////////////////////////////////////////////////////// |
182 | 172 |
183 static skiagm::GM* MyFactory(void*) { return new ImageFiltersCroppedGM; } | 173 static skiagm::GM* MyFactory(void*) { return new DropShadowImageFilterGM; } |
184 static skiagm::GMRegistry reg(MyFactory); | 174 static skiagm::GMRegistry reg(MyFactory); |
OLD | NEW |