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 #include "SkBlurMask.h" | 9 #include "SkBlurMask.h" |
10 #include "SkBlurMaskFilter.h" | 10 #include "SkBlurMaskFilter.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 class BleedGM : public skiagm::GM { | 86 class BleedGM : public skiagm::GM { |
87 public: | 87 public: |
88 BleedGM() {} | 88 BleedGM() {} |
89 | 89 |
90 protected: | 90 protected: |
91 virtual SkString onShortName() SK_OVERRIDE { | 91 virtual SkString onShortName() SK_OVERRIDE { |
92 return SkString("bleed"); | 92 return SkString("bleed"); |
93 } | 93 } |
94 | 94 |
95 virtual SkISize onISize() SK_OVERRIDE { | 95 virtual SkISize onISize() SK_OVERRIDE { |
96 return SkISize::Make(kWidth, kHeight); | 96 return SkISize::Make(kWidth, 780); |
97 } | 97 } |
98 | 98 |
99 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 99 virtual void onOnceBeforeDraw() SK_OVERRIDE { |
100 make_ringed_bitmap(&fBitmapSmall, kSmallTextureSize, kSmallTextureSize); | 100 make_ringed_bitmap(&fBitmapSmall, kSmallTextureSize, kSmallTextureSize); |
101 | 101 |
102 // To exercise the GPU's tiling path we need a texture | 102 // To exercise the GPU's tiling path we need a texture |
103 // too big for the GPU to handle in one go | 103 // too big for the GPU to handle in one go |
104 make_ringed_bitmap(&fBitmapBig, 2*kMaxTextureSize, 2*kMaxTextureSize); | 104 make_ringed_bitmap(&fBitmapBig, 2*kMaxTextureSize, 2*kMaxTextureSize); |
105 } | 105 } |
106 | 106 |
107 // Draw only the center of the small bitmap | 107 // Draw only the center of the small bitmap |
108 void drawCase1(SkCanvas* canvas, int transX, int transY, | 108 void drawCase1(SkCanvas* canvas, int transX, int transY, |
109 SkCanvas::DrawBitmapRectFlags flags, SkPaint::FilterLevel fil
ter) { | 109 SkCanvas::DrawBitmapRectFlags flags, SkPaint::FilterLevel fil
ter) { |
110 SkRect src = SkRect::MakeXYWH(2, 2, | 110 SkRect src = SkRect::MakeXYWH(2, 2, |
111 kSmallTextureSize-4, | 111 SkIntToScalar(kSmallTextureSize-4), |
112 kSmallTextureSize-4); | 112 SkIntToScalar(kSmallTextureSize-4)); |
113 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc
alar(kBlockSize)); | 113 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc
alar(kBlockSize)); |
114 | 114 |
115 SkPaint paint; | 115 SkPaint paint; |
116 paint.setFilterLevel(filter); | 116 paint.setFilterLevel(filter); |
117 | 117 |
118 canvas->save(); | 118 canvas->save(); |
119 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY)); | 119 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY)); |
120 canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint, flags); | 120 canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint, flags); |
121 canvas->restore(); | 121 canvas->restore(); |
122 } | 122 } |
(...skipping 29 matching lines...) Expand all Loading... |
152 canvas->save(); | 152 canvas->save(); |
153 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY)); | 153 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY)); |
154 canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint, flags); | 154 canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint, flags); |
155 canvas->restore(); | 155 canvas->restore(); |
156 } | 156 } |
157 | 157 |
158 // Draw the center of the small bitmap with a mask filter | 158 // Draw the center of the small bitmap with a mask filter |
159 void drawCase4(SkCanvas* canvas, int transX, int transY, | 159 void drawCase4(SkCanvas* canvas, int transX, int transY, |
160 SkCanvas::DrawBitmapRectFlags flags, SkPaint::FilterLevel fil
ter) { | 160 SkCanvas::DrawBitmapRectFlags flags, SkPaint::FilterLevel fil
ter) { |
161 SkRect src = SkRect::MakeXYWH(2, 2, | 161 SkRect src = SkRect::MakeXYWH(2, 2, |
162 kSmallTextureSize-4, | 162 SkIntToScalar(kSmallTextureSize-4), |
163 kSmallTextureSize-4); | 163 SkIntToScalar(kSmallTextureSize-4)); |
164 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc
alar(kBlockSize)); | 164 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc
alar(kBlockSize)); |
165 | 165 |
166 SkPaint paint; | 166 SkPaint paint; |
167 paint.setFilterLevel(filter); | 167 paint.setFilterLevel(filter); |
168 SkMaskFilter* mf = SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_Bl
urStyle, | 168 SkMaskFilter* mf = SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_Bl
urStyle, |
169 SkBlurMask::ConvertRadiusToSigma(SkIntT
oScalar(3))); | 169 SkBlurMask::ConvertRadiusToSigma(SkIntT
oScalar(3))); |
170 paint.setMaskFilter(mf)->unref(); | 170 paint.setMaskFilter(mf)->unref(); |
171 | 171 |
172 canvas->save(); | 172 canvas->save(); |
173 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY)); | 173 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY)); |
174 canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint, flags); | 174 canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint, flags); |
175 canvas->restore(); | 175 canvas->restore(); |
176 } | 176 } |
177 | 177 |
178 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 178 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
179 | 179 |
180 canvas->clear(SK_ColorGRAY); | 180 canvas->clear(SK_ColorGRAY); |
181 | 181 |
182 // Currently there are no test cases with medium filtering since medium
uses mip-mapping and | 182 for (int m = 0; m < 2; ++m) { |
183 // these draws are always upscaling. | 183 canvas->save(); |
| 184 if (m) { |
| 185 static const SkScalar kBottom = SkIntToScalar(kRow3Y + kBlockSiz
e + kBlockSpacing); |
| 186 canvas->translate(0, kBottom); |
| 187 SkMatrix rotate; |
| 188 rotate.setRotate(15.f, 0, kBottom + kBlockSpacing); |
| 189 canvas->concat(rotate); |
| 190 canvas->scale(0.71f, 1.22f); |
| 191 } |
184 | 192 |
185 // First draw a column with no bleeding, tiling, or filtering | 193 // First draw a column with no bleeding, tiling, or filtering |
186 this->drawCase1(canvas, kCol0X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kNone_FilterLevel); | 194 this->drawCase1(canvas, kCol0X, kRow0Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kNone_FilterLevel); |
187 this->drawCase2(canvas, kCol0X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kNone_FilterLevel); | 195 this->drawCase2(canvas, kCol0X, kRow1Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kNone_FilterLevel); |
188 this->drawCase3(canvas, kCol0X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kNone_FilterLevel); | 196 this->drawCase3(canvas, kCol0X, kRow2Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kNone_FilterLevel); |
189 this->drawCase4(canvas, kCol0X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kNone_FilterLevel); | 197 this->drawCase4(canvas, kCol0X, kRow3Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kNone_FilterLevel); |
190 | 198 |
191 // Then draw a column with no bleeding or tiling but with low filtering | 199 // Then draw a column with no bleeding or tiling but with low filter
ing |
192 this->drawCase1(canvas, kCol1X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kLow_FilterLevel); | 200 this->drawCase1(canvas, kCol1X, kRow0Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); |
193 this->drawCase2(canvas, kCol1X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kLow_FilterLevel); | 201 this->drawCase2(canvas, kCol1X, kRow1Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); |
194 this->drawCase3(canvas, kCol1X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kLow_FilterLevel); | 202 this->drawCase3(canvas, kCol1X, kRow2Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); |
195 this->drawCase4(canvas, kCol1X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kLow_FilterLevel); | 203 this->drawCase4(canvas, kCol1X, kRow3Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); |
196 | 204 |
197 // Then draw a column with no bleeding or tiling but with high filtering | 205 // Then draw a column with no bleeding or tiling but with high filte
ring |
198 this->drawCase1(canvas, kCol2X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kHigh_FilterLevel); | 206 this->drawCase1(canvas, kCol2X, kRow0Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); |
199 this->drawCase2(canvas, kCol2X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kHigh_FilterLevel); | 207 this->drawCase2(canvas, kCol2X, kRow1Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); |
200 this->drawCase3(canvas, kCol2X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kHigh_FilterLevel); | 208 this->drawCase3(canvas, kCol2X, kRow2Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); |
201 this->drawCase4(canvas, kCol2X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kHigh_FilterLevel); | 209 this->drawCase4(canvas, kCol2X, kRow3Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); |
202 | 210 |
203 #if SK_SUPPORT_GPU | 211 #if SK_SUPPORT_GPU |
204 GrContext* ctx = canvas->getGrContext(); | 212 GrContext* ctx = canvas->getGrContext(); |
205 int oldMaxTextureSize = 0; | 213 int oldMaxTextureSize = 0; |
206 if (NULL != ctx) { | 214 if (NULL != ctx) { |
207 // shrink the max texture size so all our textures can be reasonably
sized | 215 // shrink the max texture size so all our textures can be reason
ably sized |
208 oldMaxTextureSize = ctx->getMaxTextureSize(); | 216 oldMaxTextureSize = ctx->getMaxTextureSize(); |
209 ctx->setMaxTextureSizeOverride(kMaxTextureSize); | 217 ctx->setMaxTextureSizeOverride(kMaxTextureSize); |
210 } | 218 } |
211 #endif | 219 #endif |
212 | 220 |
213 // Then draw a column with no bleeding but with tiling and low filtering | 221 // Then draw a column with no bleeding but with tiling and low filte
ring |
214 this->drawCase1(canvas, kCol3X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kLow_FilterLevel); | 222 this->drawCase1(canvas, kCol3X, kRow0Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); |
215 this->drawCase2(canvas, kCol3X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kLow_FilterLevel); | 223 this->drawCase2(canvas, kCol3X, kRow1Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); |
216 this->drawCase3(canvas, kCol3X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kLow_FilterLevel); | 224 this->drawCase3(canvas, kCol3X, kRow2Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); |
217 this->drawCase4(canvas, kCol3X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kLow_FilterLevel); | 225 this->drawCase4(canvas, kCol3X, kRow3Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); |
218 | 226 |
219 // Then draw a column with no bleeding but with tiling and high filterin
g | 227 // Then draw a column with no bleeding but with tiling and high filt
ering |
220 this->drawCase1(canvas, kCol4X, kRow0Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kHigh_FilterLevel); | 228 this->drawCase1(canvas, kCol4X, kRow0Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); |
221 this->drawCase2(canvas, kCol4X, kRow1Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kHigh_FilterLevel); | 229 this->drawCase2(canvas, kCol4X, kRow1Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); |
222 this->drawCase3(canvas, kCol4X, kRow2Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kHigh_FilterLevel); | 230 this->drawCase3(canvas, kCol4X, kRow2Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); |
223 this->drawCase4(canvas, kCol4X, kRow3Y, SkCanvas::kNone_DrawBitmapRectFl
ag, SkPaint::kHigh_FilterLevel); | 231 this->drawCase4(canvas, kCol4X, kRow3Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); |
224 | 232 |
225 // Then draw a column with bleeding, tiling, and low filtering | 233 // Then draw a column with bleeding, tiling, and low filtering |
226 this->drawCase1(canvas, kCol5X, kRow0Y, SkCanvas::kBleed_DrawBitmapRectF
lag, SkPaint::kLow_FilterLevel); | 234 this->drawCase1(canvas, kCol5X, kRow0Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kLow_FilterLevel); |
227 this->drawCase2(canvas, kCol5X, kRow1Y, SkCanvas::kBleed_DrawBitmapRectF
lag, SkPaint::kLow_FilterLevel); | 235 this->drawCase2(canvas, kCol5X, kRow1Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kLow_FilterLevel); |
228 this->drawCase3(canvas, kCol5X, kRow2Y, SkCanvas::kBleed_DrawBitmapRectF
lag, SkPaint::kLow_FilterLevel); | 236 this->drawCase3(canvas, kCol5X, kRow2Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kLow_FilterLevel); |
229 this->drawCase4(canvas, kCol5X, kRow3Y, SkCanvas::kBleed_DrawBitmapRectF
lag, SkPaint::kLow_FilterLevel); | 237 this->drawCase4(canvas, kCol5X, kRow3Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kLow_FilterLevel); |
230 | 238 |
231 // Finally draw a column with bleeding, tiling, and high filtering | 239 // Finally draw a column with bleeding, tiling, and high filtering |
232 this->drawCase1(canvas, kCol6X, kRow0Y, SkCanvas::kBleed_DrawBitmapRectF
lag, SkPaint::kHigh_FilterLevel); | 240 this->drawCase1(canvas, kCol6X, kRow0Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kHigh_FilterLevel); |
233 this->drawCase2(canvas, kCol6X, kRow1Y, SkCanvas::kBleed_DrawBitmapRectF
lag, SkPaint::kHigh_FilterLevel); | 241 this->drawCase2(canvas, kCol6X, kRow1Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kHigh_FilterLevel); |
234 this->drawCase3(canvas, kCol6X, kRow2Y, SkCanvas::kBleed_DrawBitmapRectF
lag, SkPaint::kHigh_FilterLevel); | 242 this->drawCase3(canvas, kCol6X, kRow2Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kHigh_FilterLevel); |
235 this->drawCase4(canvas, kCol6X, kRow3Y, SkCanvas::kBleed_DrawBitmapRectF
lag, SkPaint::kHigh_FilterLevel); | 243 this->drawCase4(canvas, kCol6X, kRow3Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kHigh_FilterLevel); |
236 | 244 |
237 #if SK_SUPPORT_GPU | 245 #if SK_SUPPORT_GPU |
238 if (NULL != ctx) { | 246 if (NULL != ctx) { |
239 ctx->setMaxTextureSizeOverride(oldMaxTextureSize); | 247 ctx->setMaxTextureSizeOverride(oldMaxTextureSize); |
| 248 } |
| 249 #endif |
| 250 canvas->restore(); |
240 } | 251 } |
241 #endif | |
242 } | 252 } |
243 | 253 |
244 private: | 254 private: |
245 static const int kBlockSize = 70; | 255 static const int kBlockSize = 70; |
246 static const int kBlockSpacing = 5; | 256 static const int kBlockSpacing = 5; |
247 | 257 |
248 static const int kCol0X = kBlockSpacing; | 258 static const int kCol0X = kBlockSpacing; |
249 static const int kCol1X = 2*kBlockSpacing + kBlockSize; | 259 static const int kCol1X = 2*kBlockSpacing + kBlockSize; |
250 static const int kCol2X = 3*kBlockSpacing + 2*kBlockSize; | 260 static const int kCol2X = 3*kBlockSpacing + 2*kBlockSize; |
251 static const int kCol3X = 4*kBlockSpacing + 3*kBlockSize; | 261 static const int kCol3X = 4*kBlockSpacing + 3*kBlockSize; |
252 static const int kCol4X = 5*kBlockSpacing + 4*kBlockSize; | 262 static const int kCol4X = 5*kBlockSpacing + 4*kBlockSize; |
253 static const int kCol5X = 6*kBlockSpacing + 5*kBlockSize; | 263 static const int kCol5X = 6*kBlockSpacing + 5*kBlockSize; |
254 static const int kCol6X = 7*kBlockSpacing + 6*kBlockSize; | 264 static const int kCol6X = 7*kBlockSpacing + 6*kBlockSize; |
255 static const int kWidth = 8*kBlockSpacing + 7*kBlockSize; | 265 static const int kWidth = 8*kBlockSpacing + 7*kBlockSize; |
256 | 266 |
257 static const int kRow0Y = kBlockSpacing; | 267 static const int kRow0Y = kBlockSpacing; |
258 static const int kRow1Y = 2*kBlockSpacing + kBlockSize; | 268 static const int kRow1Y = 2*kBlockSpacing + kBlockSize; |
259 static const int kRow2Y = 3*kBlockSpacing + 2*kBlockSize; | 269 static const int kRow2Y = 3*kBlockSpacing + 2*kBlockSize; |
260 static const int kRow3Y = 4*kBlockSpacing + 3*kBlockSize; | 270 static const int kRow3Y = 4*kBlockSpacing + 3*kBlockSize; |
261 static const int kHeight = 5*kBlockSpacing + 4*kBlockSize; | |
262 | 271 |
263 static const int kSmallTextureSize = 6; | 272 static const int kSmallTextureSize = 6; |
264 static const int kMaxTextureSize = 32; | 273 static const int kMaxTextureSize = 32; |
265 | 274 |
266 SkBitmap fBitmapSmall; | 275 SkBitmap fBitmapSmall; |
267 SkBitmap fBitmapBig; | 276 SkBitmap fBitmapBig; |
268 | 277 |
269 typedef GM INHERITED; | 278 typedef GM INHERITED; |
270 }; | 279 }; |
271 | 280 |
272 DEF_GM( return new BleedGM(); ) | 281 DEF_GM( return new BleedGM(); ) |
OLD | NEW |