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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 void onOnceBeforeDraw() SK_OVERRIDE { | 97 void onOnceBeforeDraw() SK_OVERRIDE { |
98 make_ringed_bitmap(&fBitmapSmall, kSmallTextureSize, kSmallTextureSize); | 98 make_ringed_bitmap(&fBitmapSmall, kSmallTextureSize, kSmallTextureSize); |
99 | 99 |
100 // To exercise the GPU's tiling path we need a texture | 100 // To exercise the GPU's tiling path we need a texture |
101 // too big for the GPU to handle in one go | 101 // too big for the GPU to handle in one go |
102 make_ringed_bitmap(&fBitmapBig, 2*kMaxTextureSize, 2*kMaxTextureSize); | 102 make_ringed_bitmap(&fBitmapBig, 2*kMaxTextureSize, 2*kMaxTextureSize); |
103 } | 103 } |
104 | 104 |
105 // Draw only the center of the small bitmap | 105 // Draw only the center of the small bitmap |
106 void drawCase1(SkCanvas* canvas, int transX, int transY, | 106 void drawCase1(SkCanvas* canvas, int transX, int transY, |
107 SkCanvas::DrawBitmapRectFlags flags, SkPaint::FilterLevel fil
ter) { | 107 SkCanvas::DrawBitmapRectFlags flags, SkFilterQuality filter)
{ |
108 SkRect src = SkRect::MakeXYWH(2, 2, | 108 SkRect src = SkRect::MakeXYWH(2, 2, |
109 SkIntToScalar(kSmallTextureSize-4), | 109 SkIntToScalar(kSmallTextureSize-4), |
110 SkIntToScalar(kSmallTextureSize-4)); | 110 SkIntToScalar(kSmallTextureSize-4)); |
111 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc
alar(kBlockSize)); | 111 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc
alar(kBlockSize)); |
112 | 112 |
113 SkPaint paint; | 113 SkPaint paint; |
114 paint.setFilterLevel(filter); | 114 paint.setFilterQuality(filter); |
115 | 115 |
116 canvas->save(); | 116 canvas->save(); |
117 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY)); | 117 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY)); |
118 canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint, flags); | 118 canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint, flags); |
119 canvas->restore(); | 119 canvas->restore(); |
120 } | 120 } |
121 | 121 |
122 // Draw almost all of the large bitmap | 122 // Draw almost all of the large bitmap |
123 void drawCase2(SkCanvas* canvas, int transX, int transY, | 123 void drawCase2(SkCanvas* canvas, int transX, int transY, |
124 SkCanvas::DrawBitmapRectFlags flags, SkPaint::FilterLevel fil
ter) { | 124 SkCanvas::DrawBitmapRectFlags flags, SkFilterQuality filter)
{ |
125 SkRect src = SkRect::MakeXYWH(2, 2, | 125 SkRect src = SkRect::MakeXYWH(2, 2, |
126 SkIntToScalar(fBitmapBig.width()-4), | 126 SkIntToScalar(fBitmapBig.width()-4), |
127 SkIntToScalar(fBitmapBig.height()-4)); | 127 SkIntToScalar(fBitmapBig.height()-4)); |
128 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc
alar(kBlockSize)); | 128 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc
alar(kBlockSize)); |
129 | 129 |
130 SkPaint paint; | 130 SkPaint paint; |
131 paint.setFilterLevel(filter); | 131 paint.setFilterQuality(filter); |
132 | 132 |
133 canvas->save(); | 133 canvas->save(); |
134 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY)); | 134 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY)); |
135 canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint, flags); | 135 canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint, flags); |
136 canvas->restore(); | 136 canvas->restore(); |
137 } | 137 } |
138 | 138 |
139 // Draw ~1/4 of the large bitmap | 139 // Draw ~1/4 of the large bitmap |
140 void drawCase3(SkCanvas* canvas, int transX, int transY, | 140 void drawCase3(SkCanvas* canvas, int transX, int transY, |
141 SkCanvas::DrawBitmapRectFlags flags, SkPaint::FilterLevel fil
ter) { | 141 SkCanvas::DrawBitmapRectFlags flags, SkFilterQuality filter)
{ |
142 SkRect src = SkRect::MakeXYWH(2, 2, | 142 SkRect src = SkRect::MakeXYWH(2, 2, |
143 SkIntToScalar(fBitmapBig.width()/2-2), | 143 SkIntToScalar(fBitmapBig.width()/2-2), |
144 SkIntToScalar(fBitmapBig.height()/2-2)); | 144 SkIntToScalar(fBitmapBig.height()/2-2)); |
145 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc
alar(kBlockSize)); | 145 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc
alar(kBlockSize)); |
146 | 146 |
147 SkPaint paint; | 147 SkPaint paint; |
148 paint.setFilterLevel(filter); | 148 paint.setFilterQuality(filter); |
149 | 149 |
150 canvas->save(); | 150 canvas->save(); |
151 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY)); | 151 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY)); |
152 canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint, flags); | 152 canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint, flags); |
153 canvas->restore(); | 153 canvas->restore(); |
154 } | 154 } |
155 | 155 |
156 // Draw the center of the small bitmap with a mask filter | 156 // Draw the center of the small bitmap with a mask filter |
157 void drawCase4(SkCanvas* canvas, int transX, int transY, | 157 void drawCase4(SkCanvas* canvas, int transX, int transY, |
158 SkCanvas::DrawBitmapRectFlags flags, SkPaint::FilterLevel fil
ter) { | 158 SkCanvas::DrawBitmapRectFlags flags, SkFilterQuality filter)
{ |
159 SkRect src = SkRect::MakeXYWH(2, 2, | 159 SkRect src = SkRect::MakeXYWH(2, 2, |
160 SkIntToScalar(kSmallTextureSize-4), | 160 SkIntToScalar(kSmallTextureSize-4), |
161 SkIntToScalar(kSmallTextureSize-4)); | 161 SkIntToScalar(kSmallTextureSize-4)); |
162 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc
alar(kBlockSize)); | 162 SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToSc
alar(kBlockSize)); |
163 | 163 |
164 SkPaint paint; | 164 SkPaint paint; |
165 paint.setFilterLevel(filter); | 165 paint.setFilterQuality(filter); |
166 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, | 166 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, |
167 SkBlurMask::ConvertRadiusToSigma(SkIntT
oScalar(3))); | 167 SkBlurMask::ConvertRadiusToSigma(SkIntT
oScalar(3))); |
168 paint.setMaskFilter(mf)->unref(); | 168 paint.setMaskFilter(mf)->unref(); |
169 | 169 |
170 canvas->save(); | 170 canvas->save(); |
171 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY)); | 171 canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY)); |
172 canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint, flags); | 172 canvas->drawBitmapRectToRect(fBitmapSmall, &src, dst, &paint, flags); |
173 canvas->restore(); | 173 canvas->restore(); |
174 } | 174 } |
175 | 175 |
176 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 176 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
177 | 177 |
178 canvas->clear(SK_ColorGRAY); | 178 canvas->clear(SK_ColorGRAY); |
179 | 179 |
180 for (int m = 0; m < 2; ++m) { | 180 for (int m = 0; m < 2; ++m) { |
181 canvas->save(); | 181 canvas->save(); |
182 if (m) { | 182 if (m) { |
183 static const SkScalar kBottom = SkIntToScalar(kRow3Y + kBlockSiz
e + kBlockSpacing); | 183 static const SkScalar kBottom = SkIntToScalar(kRow3Y + kBlockSiz
e + kBlockSpacing); |
184 canvas->translate(0, kBottom); | 184 canvas->translate(0, kBottom); |
185 SkMatrix rotate; | 185 SkMatrix rotate; |
186 rotate.setRotate(15.f, 0, kBottom + kBlockSpacing); | 186 rotate.setRotate(15.f, 0, kBottom + kBlockSpacing); |
187 canvas->concat(rotate); | 187 canvas->concat(rotate); |
188 canvas->scale(0.71f, 1.22f); | 188 canvas->scale(0.71f, 1.22f); |
189 } | 189 } |
190 | 190 |
191 // First draw a column with no bleeding, tiling, or filtering | 191 // First draw a column with no bleeding, tiling, or filtering |
192 this->drawCase1(canvas, kCol0X, kRow0Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kNone_FilterLevel); | 192 this->drawCase1(canvas, kCol0X, kRow0Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kNone_SkFilterQuality); |
193 this->drawCase2(canvas, kCol0X, kRow1Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kNone_FilterLevel); | 193 this->drawCase2(canvas, kCol0X, kRow1Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kNone_SkFilterQuality); |
194 this->drawCase3(canvas, kCol0X, kRow2Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kNone_FilterLevel); | 194 this->drawCase3(canvas, kCol0X, kRow2Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kNone_SkFilterQuality); |
195 this->drawCase4(canvas, kCol0X, kRow3Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kNone_FilterLevel); | 195 this->drawCase4(canvas, kCol0X, kRow3Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kNone_SkFilterQuality); |
196 | 196 |
197 // Then draw a column with no bleeding or tiling but with low filter
ing | 197 // Then draw a column with no bleeding or tiling but with low filter
ing |
198 this->drawCase1(canvas, kCol1X, kRow0Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); | 198 this->drawCase1(canvas, kCol1X, kRow0Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kLow_SkFilterQuality); |
199 this->drawCase2(canvas, kCol1X, kRow1Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); | 199 this->drawCase2(canvas, kCol1X, kRow1Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kLow_SkFilterQuality); |
200 this->drawCase3(canvas, kCol1X, kRow2Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); | 200 this->drawCase3(canvas, kCol1X, kRow2Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kLow_SkFilterQuality); |
201 this->drawCase4(canvas, kCol1X, kRow3Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); | 201 this->drawCase4(canvas, kCol1X, kRow3Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kLow_SkFilterQuality); |
202 | 202 |
203 // Then draw a column with no bleeding or tiling but with high filte
ring | 203 // Then draw a column with no bleeding or tiling but with high filte
ring |
204 this->drawCase1(canvas, kCol2X, kRow0Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); | 204 this->drawCase1(canvas, kCol2X, kRow0Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kHigh_SkFilterQuality); |
205 this->drawCase2(canvas, kCol2X, kRow1Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); | 205 this->drawCase2(canvas, kCol2X, kRow1Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kHigh_SkFilterQuality); |
206 this->drawCase3(canvas, kCol2X, kRow2Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); | 206 this->drawCase3(canvas, kCol2X, kRow2Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kHigh_SkFilterQuality); |
207 this->drawCase4(canvas, kCol2X, kRow3Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); | 207 this->drawCase4(canvas, kCol2X, kRow3Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kHigh_SkFilterQuality); |
208 | 208 |
209 #if SK_SUPPORT_GPU | 209 #if SK_SUPPORT_GPU |
210 GrContext* ctx = canvas->getGrContext(); | 210 GrContext* ctx = canvas->getGrContext(); |
211 int oldMaxTextureSize = 0; | 211 int oldMaxTextureSize = 0; |
212 if (ctx) { | 212 if (ctx) { |
213 // shrink the max texture size so all our textures can be reason
ably sized | 213 // shrink the max texture size so all our textures can be reason
ably sized |
214 oldMaxTextureSize = ctx->getMaxTextureSize(); | 214 oldMaxTextureSize = ctx->getMaxTextureSize(); |
215 ctx->setMaxTextureSizeOverride(kMaxTextureSize); | 215 ctx->setMaxTextureSizeOverride(kMaxTextureSize); |
216 } | 216 } |
217 #endif | 217 #endif |
218 | 218 |
219 // Then draw a column with no bleeding but with tiling and low filte
ring | 219 // Then draw a column with no bleeding but with tiling and low filte
ring |
220 this->drawCase1(canvas, kCol3X, kRow0Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); | 220 this->drawCase1(canvas, kCol3X, kRow0Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kLow_SkFilterQuality); |
221 this->drawCase2(canvas, kCol3X, kRow1Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); | 221 this->drawCase2(canvas, kCol3X, kRow1Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kLow_SkFilterQuality); |
222 this->drawCase3(canvas, kCol3X, kRow2Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); | 222 this->drawCase3(canvas, kCol3X, kRow2Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kLow_SkFilterQuality); |
223 this->drawCase4(canvas, kCol3X, kRow3Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kLow_FilterLevel); | 223 this->drawCase4(canvas, kCol3X, kRow3Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kLow_SkFilterQuality); |
224 | 224 |
225 // Then draw a column with no bleeding but with tiling and high filt
ering | 225 // Then draw a column with no bleeding but with tiling and high filt
ering |
226 this->drawCase1(canvas, kCol4X, kRow0Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); | 226 this->drawCase1(canvas, kCol4X, kRow0Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kHigh_SkFilterQuality); |
227 this->drawCase2(canvas, kCol4X, kRow1Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); | 227 this->drawCase2(canvas, kCol4X, kRow1Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kHigh_SkFilterQuality); |
228 this->drawCase3(canvas, kCol4X, kRow2Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); | 228 this->drawCase3(canvas, kCol4X, kRow2Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kHigh_SkFilterQuality); |
229 this->drawCase4(canvas, kCol4X, kRow3Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, SkPaint::kHigh_FilterLevel); | 229 this->drawCase4(canvas, kCol4X, kRow3Y, SkCanvas::kNone_DrawBitmapRe
ctFlag, kHigh_SkFilterQuality); |
230 | 230 |
231 // Then draw a column with bleeding, tiling, and low filtering | 231 // Then draw a column with bleeding, tiling, and low filtering |
232 this->drawCase1(canvas, kCol5X, kRow0Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kLow_FilterLevel); | 232 this->drawCase1(canvas, kCol5X, kRow0Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, kLow_SkFilterQuality); |
233 this->drawCase2(canvas, kCol5X, kRow1Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kLow_FilterLevel); | 233 this->drawCase2(canvas, kCol5X, kRow1Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, kLow_SkFilterQuality); |
234 this->drawCase3(canvas, kCol5X, kRow2Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kLow_FilterLevel); | 234 this->drawCase3(canvas, kCol5X, kRow2Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, kLow_SkFilterQuality); |
235 this->drawCase4(canvas, kCol5X, kRow3Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kLow_FilterLevel); | 235 this->drawCase4(canvas, kCol5X, kRow3Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, kLow_SkFilterQuality); |
236 | 236 |
237 // Finally draw a column with bleeding, tiling, and high filtering | 237 // Finally draw a column with bleeding, tiling, and high filtering |
238 this->drawCase1(canvas, kCol6X, kRow0Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kHigh_FilterLevel); | 238 this->drawCase1(canvas, kCol6X, kRow0Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, kHigh_SkFilterQuality); |
239 this->drawCase2(canvas, kCol6X, kRow1Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kHigh_FilterLevel); | 239 this->drawCase2(canvas, kCol6X, kRow1Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, kHigh_SkFilterQuality); |
240 this->drawCase3(canvas, kCol6X, kRow2Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kHigh_FilterLevel); | 240 this->drawCase3(canvas, kCol6X, kRow2Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, kHigh_SkFilterQuality); |
241 this->drawCase4(canvas, kCol6X, kRow3Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, SkPaint::kHigh_FilterLevel); | 241 this->drawCase4(canvas, kCol6X, kRow3Y, SkCanvas::kBleed_DrawBitmapR
ectFlag, kHigh_SkFilterQuality); |
242 | 242 |
243 #if SK_SUPPORT_GPU | 243 #if SK_SUPPORT_GPU |
244 if (ctx) { | 244 if (ctx) { |
245 ctx->setMaxTextureSizeOverride(oldMaxTextureSize); | 245 ctx->setMaxTextureSizeOverride(oldMaxTextureSize); |
246 } | 246 } |
247 #endif | 247 #endif |
248 canvas->restore(); | 248 canvas->restore(); |
249 } | 249 } |
250 } | 250 } |
251 | 251 |
(...skipping 18 matching lines...) Expand all Loading... |
270 static const int kSmallTextureSize = 6; | 270 static const int kSmallTextureSize = 6; |
271 static const int kMaxTextureSize = 32; | 271 static const int kMaxTextureSize = 32; |
272 | 272 |
273 SkBitmap fBitmapSmall; | 273 SkBitmap fBitmapSmall; |
274 SkBitmap fBitmapBig; | 274 SkBitmap fBitmapBig; |
275 | 275 |
276 typedef GM INHERITED; | 276 typedef GM INHERITED; |
277 }; | 277 }; |
278 | 278 |
279 DEF_GM( return new BleedGM(); ) | 279 DEF_GM( return new BleedGM(); ) |
OLD | NEW |