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" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkGradientShader.h" | |
12 #include "SkImage.h" | 13 #include "SkImage.h" |
13 | 14 |
14 #if SK_SUPPORT_GPU | 15 #if SK_SUPPORT_GPU |
15 #include "GrContext.h" | 16 #include "GrContext.h" |
16 #include "GrContextOptions.h" | 17 #include "GrContextOptions.h" |
17 #endif | 18 #endif |
18 | 19 |
19 static void draw_bitmap_rect(SkCanvas* canvas, const SkBitmap& bitmap, const SkI mage*, | 20 static void draw_bitmap_rect(SkCanvas* canvas, const SkBitmap& bitmap, const SkI mage*, |
20 const SkRect& src, const SkRect& dst, | 21 const SkRect& src, const SkRect& dst, |
21 const SkPaint* paint, SkCanvas::SrcRectConstraint c onstraint) { | 22 const SkPaint* paint, SkCanvas::SrcRectConstraint c onstraint) { |
22 canvas->drawBitmapRect(bitmap, src, dst, paint, constraint); | 23 canvas->drawBitmapRect(bitmap, src, dst, paint, constraint); |
23 } | 24 } |
24 | 25 |
25 static void draw_image_rect(SkCanvas* canvas, const SkBitmap&, const SkImage* im age, | 26 static void draw_image_rect(SkCanvas* canvas, const SkBitmap&, const SkImage* im age, |
26 const SkRect& src, const SkRect& dst, | 27 const SkRect& src, const SkRect& dst, |
27 const SkPaint* paint, SkCanvas::SrcRectConstraint co nstraint) { | 28 const SkPaint* paint, SkCanvas::SrcRectConstraint co nstraint) { |
28 canvas->drawImageRect(image, src, dst, paint, constraint); | 29 canvas->drawImageRect(image, src, dst, paint, constraint); |
29 } | 30 } |
30 | 31 |
31 enum BleedTest { | |
32 kUseBitmap_BleedTest, | |
33 kUseImage_BleedTest, | |
34 }; | |
35 | |
36 const struct { | |
37 const char* fName; | |
38 void (*fDraw)(SkCanvas*, const SkBitmap&, const SkImage*, const SkRect&, con st SkRect&, | |
39 const SkPaint*, SkCanvas::SrcRectConstraint); | |
40 } gBleedRec[] = { | |
41 { "bleed", draw_bitmap_rect }, | |
42 { "bleed_image", draw_image_rect }, | |
43 }; | |
44 | |
45 // Create a black&white checked texture with 2 1-pixel rings | 32 // Create a black&white checked texture with 2 1-pixel rings |
46 // around the outside edge. The inner ring is red and the outer ring is blue. | 33 // around the outside edge. The inner ring is red and the outer ring is blue. |
47 static void make_ringed_bitmap(SkBitmap* result, int width, int height) { | 34 static void make_ringed_color_bitmap(SkBitmap* result, int width, int height) { |
48 SkASSERT(0 == width % 2 && 0 == height % 2); | 35 SkASSERT(0 == width % 2 && 0 == height % 2); |
49 | 36 |
50 static const SkPMColor kRed = SkPreMultiplyColor(SK_ColorRED); | 37 static const SkPMColor kRed = SkPreMultiplyColor(SK_ColorRED); |
51 static const SkPMColor kBlue = SkPreMultiplyColor(SK_ColorBLUE); | 38 static const SkPMColor kBlue = SkPreMultiplyColor(SK_ColorBLUE); |
52 static const SkPMColor kBlack = SkPreMultiplyColor(SK_ColorBLACK); | 39 static const SkPMColor kBlack = SkPreMultiplyColor(SK_ColorBLACK); |
53 static const SkPMColor kWhite = SkPreMultiplyColor(SK_ColorWHITE); | 40 static const SkPMColor kWhite = SkPreMultiplyColor(SK_ColorWHITE); |
54 | 41 |
55 result->allocN32Pixels(width, height, true); | 42 result->allocN32Pixels(width, height, true); |
56 | 43 |
57 SkPMColor* scanline = result->getAddr32(0, 0); | 44 SkPMColor* scanline = result->getAddr32(0, 0); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 scanline[x] = kRed; | 86 scanline[x] = kRed; |
100 } | 87 } |
101 scanline[width-1] = kBlue; | 88 scanline[width-1] = kBlue; |
102 | 89 |
103 scanline = result->getAddr32(0, height-1); | 90 scanline = result->getAddr32(0, height-1); |
104 for (int x = 0; x < width; ++x) { | 91 for (int x = 0; x < width; ++x) { |
105 scanline[x] = kBlue; | 92 scanline[x] = kBlue; |
106 } | 93 } |
107 result->setImmutable(); | 94 result->setImmutable(); |
108 } | 95 } |
109 | 96 |
robertphillips
2015/10/23 16:53:58
// Make the A8 texture:
//
// 1 1 1 ... 1 1 1
bsalomon
2015/10/23 17:57:10
Done.
| |
97 static void make_ringed_alpha_bitmap(SkBitmap* result, int width, int height) { | |
98 SkASSERT(0 == width % 2 && 0 == height % 2); | |
99 | |
100 static const SkPMColor kZero = 0x00; | |
101 static const SkPMColor kHalf = 0x80; | |
102 static const SkPMColor k3Q = 0xC0; | |
103 static const SkPMColor kOne = 0xFF; | |
104 SkImageInfo info = SkImageInfo::MakeA8(width, height); | |
105 // The 4 byte alignment seems to be necessary to allow this bmp to be conver ted | |
106 // to an image. | |
107 result->allocPixels(info, SkAlign4(width)); | |
108 | |
109 uint8_t* scanline = result->getAddr8(0, 0); | |
110 for (int x = 0; x < width; ++x) { | |
111 scanline[x] = kOne; | |
112 } | |
113 scanline = result->getAddr8(0, 1); | |
114 scanline[0] = kOne; | |
115 for (int x = 1; x < width - 1; ++x) { | |
116 scanline[x] = kZero; | |
117 } | |
118 scanline[width - 1] = kOne; | |
119 | |
120 for (int y = 2; y < height / 2; ++y) { | |
121 scanline = result->getAddr8(0, y); | |
122 scanline[0] = kOne; | |
123 scanline[1] = kZero; | |
124 for (int x = 2; x < width / 2; ++x) { | |
125 scanline[x] = k3Q; | |
126 } | |
127 for (int x = width / 2; x < width - 2; ++x) { | |
128 scanline[x] = kHalf; | |
129 } | |
130 scanline[width - 2] = kZero; | |
131 scanline[width - 1] = kOne; | |
132 } | |
133 | |
134 for (int y = height / 2; y < height - 2; ++y) { | |
135 scanline = result->getAddr8(0, y); | |
136 scanline[0] = kOne; | |
137 scanline[1] = kZero; | |
138 for (int x = 2; x < width / 2; ++x) { | |
139 scanline[x] = kHalf; | |
140 } | |
141 for (int x = width / 2; x < width - 2; ++x) { | |
142 scanline[x] = k3Q; | |
143 } | |
144 scanline[width - 2] = kZero; | |
145 scanline[width - 1] = kOne; | |
146 } | |
147 | |
148 scanline = result->getAddr8(0, height - 2); | |
149 scanline[0] = kOne; | |
150 for (int x = 1; x < width - 1; ++x) { | |
151 scanline[x] = kZero; | |
152 } | |
153 scanline[width - 1] = kOne; | |
154 | |
155 scanline = result->getAddr8(0, height - 1); | |
156 for (int x = 0; x < width; ++x) { | |
157 scanline[x] = kOne; | |
158 } | |
159 result->setImmutable(); | |
160 } | |
161 | |
162 static SkShader* make_shader() { | |
163 static const SkPoint pts[] = { {0, 0}, {20, 20} }; | |
164 static const SkColor colors[] = { SK_ColorGREEN, SK_ColorYELLOW }; | |
165 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kMi rror_TileMode); | |
166 } | |
167 | |
168 static SkShader* make_null_shader() { return nullptr; } | |
169 | |
170 enum BleedTest { | |
171 kUseBitmap_BleedTest, | |
172 kUseImage_BleedTest, | |
173 kUseAlphaBitmap_BleedTest, | |
174 kUseAlphaImage_BleedTest, | |
175 kUseAlphaBitmapShader_BleedTest, | |
176 kUseAlphaImageShader_BleedTest, | |
177 }; | |
178 | |
179 const struct { | |
180 const char* fName; | |
181 void(*fBmpMaker)(SkBitmap* result, int width, int height); | |
182 SkShader*(*fShaderMaker)(); | |
183 void(*fDraw)(SkCanvas*, const SkBitmap&, const SkImage*, const SkRect&, cons t SkRect&, | |
184 const SkPaint*, SkCanvas::SrcRectConstraint); | |
185 } gBleedRec[] = { | |
186 { "bleed", make_ringed_color_bitmap, make_null_shader, draw_bitmap_rect }, | |
187 { "bleed_image", make_ringed_color_bitmap, make_null_shader, draw_image_rect }, | |
188 { "bleed_alpha_bmp", make_ringed_alpha_bitmap, make_null_shader, draw_bitmap_rect }, | |
189 { "bleed_alpha_image", make_ringed_alpha_bitmap, make_null_shader, draw_image_rect }, | |
190 { "bleed_alpha_bmp_shader", make_ringed_alpha_bitmap, make_shader, draw_bitmap_rect }, | |
191 { "bleed_alpha_image_shader", make_ringed_alpha_bitmap, make_shader, draw_image_rect }, | |
192 }; | |
193 | |
110 // This GM exercises the drawBitmapRect constraints | 194 // This GM exercises the drawBitmapRect constraints |
111 class BleedGM : public skiagm::GM { | 195 class BleedGM : public skiagm::GM { |
112 public: | 196 public: |
113 BleedGM(BleedTest bt) : fBT(bt) {} | 197 BleedGM(BleedTest bt) : fBT(bt) {} |
114 | 198 |
115 protected: | 199 protected: |
116 | 200 |
117 SkString onShortName() override { | 201 SkString onShortName() override { |
118 return SkString(gBleedRec[fBT].fName); | 202 return SkString(gBleedRec[fBT].fName); |
119 } | 203 } |
120 | 204 |
121 SkISize onISize() override { | 205 SkISize onISize() override { |
122 return SkISize::Make(kWidth, 780); | 206 return SkISize::Make(1050, 780); |
123 } | 207 } |
124 | 208 |
125 void onOnceBeforeDraw() override { | 209 void onOnceBeforeDraw() override { |
126 make_ringed_bitmap(&fBitmapSmall, kSmallTextureSize, kSmallTextureSize); | 210 gBleedRec[fBT].fBmpMaker(&fBitmapSmall, kSmallTextureSize, kSmallTexture Size); |
127 fImageSmall.reset(SkImage::NewFromBitmap(fBitmapSmall)); | 211 fImageSmall.reset(SkImage::NewFromBitmap(fBitmapSmall)); |
128 | 212 |
129 // To exercise the GPU's tiling path we need a texture | 213 // To exercise the GPU's tiling path we need a texture |
130 // too big for the GPU to handle in one go | 214 // too big for the GPU to handle in one go |
131 make_ringed_bitmap(&fBitmapBig, 2*kMaxTextureSize, 2*kMaxTextureSize); | 215 gBleedRec[fBT].fBmpMaker(&fBitmapBig, 2*kMaxTextureSize, 2*kMaxTextureSi ze); |
132 fImageBig.reset(SkImage::NewFromBitmap(fBitmapBig)); | 216 fImageBig.reset(SkImage::NewFromBitmap(fBitmapBig)); |
217 | |
218 fShader.reset(gBleedRec[fBT].fShaderMaker()); | |
133 } | 219 } |
134 | 220 |
135 // Draw only the center of the small bitmap | 221 // Draw only the center of the small bitmap |
136 void drawCase1(SkCanvas* canvas, int transX, int transY, | 222 void drawCase1(SkCanvas* canvas, int transX, int transY, bool aa, |
137 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte r) { | 223 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte r) { |
138 SkRect src = SkRect::MakeXYWH(2, 2, | 224 SkRect src = SkRect::MakeXYWH(2, 2, |
139 SkIntToScalar(kSmallTextureSize-4), | 225 SkIntToScalar(kSmallTextureSize-4), |
140 SkIntToScalar(kSmallTextureSize-4)); | 226 SkIntToScalar(kSmallTextureSize-4)); |
141 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans Y), | 227 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans Y), |
142 SkIntToScalar(kBlockSize), SkIntToScalar(k BlockSize)); | 228 SkIntToScalar(kBlockSize), SkIntToScalar(k BlockSize)); |
143 | 229 |
144 SkPaint paint; | 230 SkPaint paint; |
145 paint.setFilterQuality(filter); | 231 paint.setFilterQuality(filter); |
232 paint.setShader(fShader); | |
233 paint.setColor(SK_ColorBLUE); | |
234 paint.setAntiAlias(aa); | |
146 | 235 |
147 gBleedRec[fBT].fDraw(canvas, fBitmapSmall, fImageSmall, src, dst, &paint , constraint); | 236 gBleedRec[fBT].fDraw(canvas, fBitmapSmall, fImageSmall, src, dst, &paint , constraint); |
148 } | 237 } |
149 | 238 |
150 // Draw almost all of the large bitmap | 239 // Draw almost all of the large bitmap |
151 void drawCase2(SkCanvas* canvas, int transX, int transY, | 240 void drawCase2(SkCanvas* canvas, int transX, int transY, bool aa, |
152 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte r) { | 241 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte r) { |
153 SkRect src = SkRect::MakeXYWH(2, 2, | 242 SkRect src = SkRect::MakeXYWH(2, 2, |
154 SkIntToScalar(fBitmapBig.width()-4), | 243 SkIntToScalar(fBitmapBig.width()-4), |
155 SkIntToScalar(fBitmapBig.height()-4)); | 244 SkIntToScalar(fBitmapBig.height()-4)); |
156 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans Y), | 245 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans Y), |
157 SkIntToScalar(kBlockSize), SkIntToScalar(k BlockSize)); | 246 SkIntToScalar(kBlockSize), SkIntToScalar(k BlockSize)); |
158 | 247 |
159 SkPaint paint; | 248 SkPaint paint; |
160 paint.setFilterQuality(filter); | 249 paint.setFilterQuality(filter); |
250 paint.setShader(fShader); | |
251 paint.setColor(SK_ColorBLUE); | |
252 paint.setAntiAlias(aa); | |
161 | 253 |
162 gBleedRec[fBT].fDraw(canvas, fBitmapBig, fImageBig, src, dst, &paint, co nstraint); | 254 gBleedRec[fBT].fDraw(canvas, fBitmapBig, fImageBig, src, dst, &paint, co nstraint); |
163 } | 255 } |
164 | 256 |
165 // Draw ~1/4 of the large bitmap | 257 // Draw ~1/4 of the large bitmap |
166 void drawCase3(SkCanvas* canvas, int transX, int transY, | 258 void drawCase3(SkCanvas* canvas, int transX, int transY, bool aa, |
167 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte r) { | 259 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte r) { |
168 SkRect src = SkRect::MakeXYWH(2, 2, | 260 SkRect src = SkRect::MakeXYWH(2, 2, |
169 SkIntToScalar(fBitmapBig.width()/2-2), | 261 SkIntToScalar(fBitmapBig.width()/2-2), |
170 SkIntToScalar(fBitmapBig.height()/2-2)); | 262 SkIntToScalar(fBitmapBig.height()/2-2)); |
171 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans Y), | 263 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans Y), |
172 SkIntToScalar(kBlockSize), SkIntToScalar(k BlockSize)); | 264 SkIntToScalar(kBlockSize), SkIntToScalar(k BlockSize)); |
173 | 265 |
174 SkPaint paint; | 266 SkPaint paint; |
175 paint.setFilterQuality(filter); | 267 paint.setFilterQuality(filter); |
268 paint.setShader(fShader); | |
269 paint.setColor(SK_ColorBLUE); | |
270 paint.setAntiAlias(aa); | |
176 | 271 |
177 gBleedRec[fBT].fDraw(canvas, fBitmapBig, fImageBig, src, dst, &paint, co nstraint); | 272 gBleedRec[fBT].fDraw(canvas, fBitmapBig, fImageBig, src, dst, &paint, co nstraint); |
178 } | 273 } |
179 | 274 |
180 // Draw the center of the small bitmap with a mask filter | 275 // Draw the center of the small bitmap with a mask filter |
181 void drawCase4(SkCanvas* canvas, int transX, int transY, | 276 void drawCase4(SkCanvas* canvas, int transX, int transY, bool aa, |
182 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte r) { | 277 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte r) { |
183 SkRect src = SkRect::MakeXYWH(2, 2, | 278 SkRect src = SkRect::MakeXYWH(2, 2, |
184 SkIntToScalar(kSmallTextureSize-4), | 279 SkIntToScalar(kSmallTextureSize-4), |
185 SkIntToScalar(kSmallTextureSize-4)); | 280 SkIntToScalar(kSmallTextureSize-4)); |
186 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans Y), | 281 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans Y), |
187 SkIntToScalar(kBlockSize), SkIntToScalar(k BlockSize)); | 282 SkIntToScalar(kBlockSize), SkIntToScalar(k BlockSize)); |
188 | 283 |
189 SkPaint paint; | 284 SkPaint paint; |
190 paint.setFilterQuality(filter); | 285 paint.setFilterQuality(filter); |
191 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, | 286 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, |
192 SkBlurMask::ConvertRadiusToSigma(3)); | 287 SkBlurMask::ConvertRadiusToSigma(3)); |
193 paint.setMaskFilter(mf)->unref(); | 288 paint.setMaskFilter(mf)->unref(); |
289 paint.setShader(fShader); | |
290 paint.setColor(SK_ColorBLUE); | |
291 paint.setAntiAlias(aa); | |
194 | 292 |
195 gBleedRec[fBT].fDraw(canvas, fBitmapSmall, fImageSmall, src, dst, &paint , constraint); | 293 gBleedRec[fBT].fDraw(canvas, fBitmapSmall, fImageSmall, src, dst, &paint , constraint); |
196 } | 294 } |
197 | 295 |
198 void onDraw(SkCanvas* canvas) override { | 296 void onDraw(SkCanvas* canvas) override { |
297 canvas->clear(SK_ColorGRAY); | |
298 SkTDArray<SkMatrix> matrices; | |
299 // Draw with identity | |
300 *matrices.append() = SkMatrix::I(); | |
199 | 301 |
200 canvas->clear(SK_ColorGRAY); | 302 // Draw with rotation and scale down in x, up in y. |
303 SkMatrix m; | |
304 static const SkScalar kBottom = SkIntToScalar(kRow3Y + kBlockSize + kBlo ckSpacing); | |
305 m.setTranslate(0, kBottom); | |
306 m.preRotate(15.f, 0, kBottom + kBlockSpacing); | |
307 m.preScale(0.71f, 1.22f); | |
308 *matrices.append() = m; | |
201 | 309 |
202 for (int m = 0; m < 2; ++m) { | 310 // Align the next set with the middle of the previous in y, translated t o the right in x. |
311 SkPoint corners[] = {{0, 0}, { 0, kBottom }, { kWidth, kBottom }, {kWidt h, 0} }; | |
312 matrices[matrices.count()-1].mapPoints(corners, 4); | |
313 SkScalar y = (corners[0].fY + corners[1].fY + corners[2].fY + corners[3] .fY) / 4; | |
314 SkScalar x = SkTMax(SkTMax(corners[0].fX, corners[1].fX), | |
315 SkTMax(corners[2].fX, corners[3].fX)); | |
316 m.setTranslate(x, y); | |
317 m.preScale(0.2f, 0.2f); | |
318 *matrices.append() = m; | |
319 | |
320 SkScalar maxX = 0; | |
321 for (int antiAlias = 0; antiAlias < 2; ++antiAlias) { | |
203 canvas->save(); | 322 canvas->save(); |
204 if (m) { | 323 canvas->translate(maxX, 0); |
205 static const SkScalar kBottom = SkIntToScalar(kRow3Y + kBlockSiz e + kBlockSpacing); | 324 for (int m = 0; m < matrices.count(); ++m) { |
206 canvas->translate(0, kBottom); | 325 canvas->save(); |
207 SkMatrix rotate; | 326 canvas->concat(matrices[m]); |
208 rotate.setRotate(15.f, 0, kBottom + kBlockSpacing); | 327 bool aa = SkToBool(antiAlias); |
209 canvas->concat(rotate); | 328 |
210 canvas->scale(0.71f, 1.22f); | 329 // First draw a column with no bleeding and no filtering |
330 this->drawCase1(canvas, kCol0X, kRow0Y, aa, SkCanvas::kStrict_Sr cRectConstraint, kNone_SkFilterQuality); | |
331 this->drawCase2(canvas, kCol0X, kRow1Y, aa, SkCanvas::kStrict_Sr cRectConstraint, kNone_SkFilterQuality); | |
332 this->drawCase3(canvas, kCol0X, kRow2Y, aa, SkCanvas::kStrict_Sr cRectConstraint, kNone_SkFilterQuality); | |
333 this->drawCase4(canvas, kCol0X, kRow3Y, aa, SkCanvas::kStrict_Sr cRectConstraint, kNone_SkFilterQuality); | |
334 | |
335 // Then draw a column with no bleeding and low filtering | |
336 this->drawCase1(canvas, kCol1X, kRow0Y, aa, SkCanvas::kStrict_Sr cRectConstraint, kLow_SkFilterQuality); | |
337 this->drawCase2(canvas, kCol1X, kRow1Y, aa, SkCanvas::kStrict_Sr cRectConstraint, kLow_SkFilterQuality); | |
338 this->drawCase3(canvas, kCol1X, kRow2Y, aa, SkCanvas::kStrict_Sr cRectConstraint, kLow_SkFilterQuality); | |
339 this->drawCase4(canvas, kCol1X, kRow3Y, aa, SkCanvas::kStrict_Sr cRectConstraint, kLow_SkFilterQuality); | |
340 | |
341 // Then draw a column with no bleeding and high filtering | |
342 this->drawCase1(canvas, kCol2X, kRow0Y, aa, SkCanvas::kStrict_Sr cRectConstraint, kHigh_SkFilterQuality); | |
343 this->drawCase2(canvas, kCol2X, kRow1Y, aa, SkCanvas::kStrict_Sr cRectConstraint, kHigh_SkFilterQuality); | |
344 this->drawCase3(canvas, kCol2X, kRow2Y, aa, SkCanvas::kStrict_Sr cRectConstraint, kHigh_SkFilterQuality); | |
345 this->drawCase4(canvas, kCol2X, kRow3Y, aa, SkCanvas::kStrict_Sr cRectConstraint, kHigh_SkFilterQuality); | |
346 | |
347 // Then draw a column with bleeding and no filtering (bleed shou ld have no effect w/out blur) | |
348 this->drawCase1(canvas, kCol3X, kRow0Y, aa, SkCanvas::kFast_SrcR ectConstraint, kNone_SkFilterQuality); | |
349 this->drawCase2(canvas, kCol3X, kRow1Y, aa, SkCanvas::kFast_SrcR ectConstraint, kNone_SkFilterQuality); | |
350 this->drawCase3(canvas, kCol3X, kRow2Y, aa, SkCanvas::kFast_SrcR ectConstraint, kNone_SkFilterQuality); | |
351 this->drawCase4(canvas, kCol3X, kRow3Y, aa, SkCanvas::kFast_SrcR ectConstraint, kNone_SkFilterQuality); | |
352 | |
353 // Then draw a column with bleeding and low filtering | |
354 this->drawCase1(canvas, kCol4X, kRow0Y, aa, SkCanvas::kFast_SrcR ectConstraint, kLow_SkFilterQuality); | |
355 this->drawCase2(canvas, kCol4X, kRow1Y, aa, SkCanvas::kFast_SrcR ectConstraint, kLow_SkFilterQuality); | |
356 this->drawCase3(canvas, kCol4X, kRow2Y, aa, SkCanvas::kFast_SrcR ectConstraint, kLow_SkFilterQuality); | |
357 this->drawCase4(canvas, kCol4X, kRow3Y, aa, SkCanvas::kFast_SrcR ectConstraint, kLow_SkFilterQuality); | |
358 | |
359 // Finally draw a column with bleeding and high filtering | |
360 this->drawCase1(canvas, kCol5X, kRow0Y, aa, SkCanvas::kFast_SrcR ectConstraint, kHigh_SkFilterQuality); | |
361 this->drawCase2(canvas, kCol5X, kRow1Y, aa, SkCanvas::kFast_SrcR ectConstraint, kHigh_SkFilterQuality); | |
362 this->drawCase3(canvas, kCol5X, kRow2Y, aa, SkCanvas::kFast_SrcR ectConstraint, kHigh_SkFilterQuality); | |
363 this->drawCase4(canvas, kCol5X, kRow3Y, aa, SkCanvas::kFast_SrcR ectConstraint, kHigh_SkFilterQuality); | |
364 | |
365 SkPoint corners[] = { { 0, 0 },{ 0, kBottom },{ kWidth, kBottom },{ kWidth, 0 } }; | |
366 matrices[m].mapPoints(corners, 4); | |
367 SkScalar x = kBlockSize + SkTMax(SkTMax(corners[0].fX, corners[1 ].fX), | |
368 SkTMax(corners[2].fX, corners[3 ].fX)); | |
369 maxX = SkTMax(maxX, x); | |
370 canvas->restore(); | |
211 } | 371 } |
212 | |
213 // First draw a column with no bleeding and no filtering | |
214 this->drawCase1(canvas, kCol0X, kRow0Y, SkCanvas::kStrict_SrcRectCon straint, kNone_SkFilterQuality); | |
215 this->drawCase2(canvas, kCol0X, kRow1Y, SkCanvas::kStrict_SrcRectCon straint, kNone_SkFilterQuality); | |
216 this->drawCase3(canvas, kCol0X, kRow2Y, SkCanvas::kStrict_SrcRectCon straint, kNone_SkFilterQuality); | |
217 this->drawCase4(canvas, kCol0X, kRow3Y, SkCanvas::kStrict_SrcRectCon straint, kNone_SkFilterQuality); | |
218 | |
219 // Then draw a column with no bleeding and low filtering | |
220 this->drawCase1(canvas, kCol1X, kRow0Y, SkCanvas::kStrict_SrcRectCon straint, kLow_SkFilterQuality); | |
221 this->drawCase2(canvas, kCol1X, kRow1Y, SkCanvas::kStrict_SrcRectCon straint, kLow_SkFilterQuality); | |
222 this->drawCase3(canvas, kCol1X, kRow2Y, SkCanvas::kStrict_SrcRectCon straint, kLow_SkFilterQuality); | |
223 this->drawCase4(canvas, kCol1X, kRow3Y, SkCanvas::kStrict_SrcRectCon straint, kLow_SkFilterQuality); | |
224 | |
225 // Then draw a column with no bleeding and high filtering | |
226 this->drawCase1(canvas, kCol2X, kRow0Y, SkCanvas::kStrict_SrcRectCon straint, kHigh_SkFilterQuality); | |
227 this->drawCase2(canvas, kCol2X, kRow1Y, SkCanvas::kStrict_SrcRectCon straint, kHigh_SkFilterQuality); | |
228 this->drawCase3(canvas, kCol2X, kRow2Y, SkCanvas::kStrict_SrcRectCon straint, kHigh_SkFilterQuality); | |
229 this->drawCase4(canvas, kCol2X, kRow3Y, SkCanvas::kStrict_SrcRectCon straint, kHigh_SkFilterQuality); | |
230 | |
231 // Then draw a column with bleeding and no filtering (bleed should h ave no effect w/out blur) | |
232 this->drawCase1(canvas, kCol3X, kRow0Y, SkCanvas::kFast_SrcRectConst raint, kNone_SkFilterQuality); | |
233 this->drawCase2(canvas, kCol3X, kRow1Y, SkCanvas::kFast_SrcRectConst raint, kNone_SkFilterQuality); | |
234 this->drawCase3(canvas, kCol3X, kRow2Y, SkCanvas::kFast_SrcRectConst raint, kNone_SkFilterQuality); | |
235 this->drawCase4(canvas, kCol3X, kRow3Y, SkCanvas::kFast_SrcRectConst raint, kNone_SkFilterQuality); | |
236 | |
237 // Then draw a column with bleeding and low filtering | |
238 this->drawCase1(canvas, kCol4X, kRow0Y, SkCanvas::kFast_SrcRectConst raint, kLow_SkFilterQuality); | |
239 this->drawCase2(canvas, kCol4X, kRow1Y, SkCanvas::kFast_SrcRectConst raint, kLow_SkFilterQuality); | |
240 this->drawCase3(canvas, kCol4X, kRow2Y, SkCanvas::kFast_SrcRectConst raint, kLow_SkFilterQuality); | |
241 this->drawCase4(canvas, kCol4X, kRow3Y, SkCanvas::kFast_SrcRectConst raint, kLow_SkFilterQuality); | |
242 | |
243 // Finally draw a column with bleeding and high filtering | |
244 this->drawCase1(canvas, kCol5X, kRow0Y, SkCanvas::kFast_SrcRectConst raint, kHigh_SkFilterQuality); | |
245 this->drawCase2(canvas, kCol5X, kRow1Y, SkCanvas::kFast_SrcRectConst raint, kHigh_SkFilterQuality); | |
246 this->drawCase3(canvas, kCol5X, kRow2Y, SkCanvas::kFast_SrcRectConst raint, kHigh_SkFilterQuality); | |
247 this->drawCase4(canvas, kCol5X, kRow3Y, SkCanvas::kFast_SrcRectConst raint, kHigh_SkFilterQuality); | |
248 | |
249 canvas->restore(); | 372 canvas->restore(); |
250 } | 373 } |
251 } | 374 } |
252 | 375 |
253 #if SK_SUPPORT_GPU | 376 #if SK_SUPPORT_GPU |
254 void modifyGrContextOptions(GrContextOptions* options) override { | 377 void modifyGrContextOptions(GrContextOptions* options) override { |
255 options->fMaxTextureSizeOverride = kMaxTextureSize; | 378 options->fMaxTextureSizeOverride = kMaxTextureSize; |
256 } | 379 } |
257 #endif | 380 #endif |
258 | 381 |
259 private: | 382 private: |
260 static const int kBlockSize = 70; | 383 static const int kBlockSize = 70; |
261 static const int kBlockSpacing = 5; | 384 static const int kBlockSpacing = 5; |
262 | 385 |
263 static const int kCol0X = kBlockSpacing; | 386 static const int kCol0X = kBlockSpacing; |
264 static const int kCol1X = 2*kBlockSpacing + kBlockSize; | 387 static const int kCol1X = 2*kBlockSpacing + kBlockSize; |
265 static const int kCol2X = 3*kBlockSpacing + 2*kBlockSize; | 388 static const int kCol2X = 3*kBlockSpacing + 2*kBlockSize; |
266 static const int kCol3X = 4*kBlockSpacing + 3*kBlockSize; | 389 static const int kCol3X = 4*kBlockSpacing + 3*kBlockSize; |
267 static const int kCol4X = 5*kBlockSpacing + 4*kBlockSize; | 390 static const int kCol4X = 5*kBlockSpacing + 4*kBlockSize; |
268 static const int kCol5X = 6*kBlockSpacing + 5*kBlockSize; | 391 static const int kCol5X = 6*kBlockSpacing + 5*kBlockSize; |
robertphillips
2015/10/23 16:53:58
Is kWidth used anywhere anymore ?
bsalomon
2015/10/23 17:57:10
Yep
| |
269 static const int kWidth = 7*kBlockSpacing + 6*kBlockSize; | 392 static const int kWidth = 7*kBlockSpacing + 6*kBlockSize; |
270 | 393 |
271 static const int kRow0Y = kBlockSpacing; | 394 static const int kRow0Y = kBlockSpacing; |
272 static const int kRow1Y = 2*kBlockSpacing + kBlockSize; | 395 static const int kRow1Y = 2*kBlockSpacing + kBlockSize; |
273 static const int kRow2Y = 3*kBlockSpacing + 2*kBlockSize; | 396 static const int kRow2Y = 3*kBlockSpacing + 2*kBlockSize; |
274 static const int kRow3Y = 4*kBlockSpacing + 3*kBlockSize; | 397 static const int kRow3Y = 4*kBlockSpacing + 3*kBlockSize; |
275 | 398 |
276 static const int kSmallTextureSize = 6; | 399 static const int kSmallTextureSize = 6; |
277 static const int kMaxTextureSize = 32; | 400 static const int kMaxTextureSize = 32; |
278 | 401 |
279 SkBitmap fBitmapSmall; | 402 SkBitmap fBitmapSmall; |
280 SkBitmap fBitmapBig; | 403 SkBitmap fBitmapBig; |
281 SkAutoTUnref<SkImage> fImageSmall; | 404 SkAutoTUnref<SkImage> fImageSmall; |
282 SkAutoTUnref<SkImage> fImageBig; | 405 SkAutoTUnref<SkImage> fImageBig; |
406 | |
407 SkAutoTUnref<SkShader> fShader; | |
408 | |
283 const BleedTest fBT; | 409 const BleedTest fBT; |
284 | 410 |
285 typedef GM INHERITED; | 411 typedef GM INHERITED; |
286 }; | 412 }; |
287 | 413 |
288 DEF_GM( return new BleedGM(kUseBitmap_BleedTest); ) | 414 DEF_GM( return new BleedGM(kUseBitmap_BleedTest); ) |
289 DEF_GM( return new BleedGM(kUseImage_BleedTest); ) | 415 DEF_GM( return new BleedGM(kUseImage_BleedTest); ) |
416 DEF_GM( return new BleedGM(kUseAlphaBitmap_BleedTest); ) | |
417 DEF_GM( return new BleedGM(kUseAlphaImage_BleedTest); ) | |
robertphillips
2015/10/23 16:53:58
Should we have a bug ?
bsalomon
2015/10/23 17:57:10
I'm looking into it now... if I don't have a quick
| |
418 #if 0 // Currently crashes GPU backend | |
419 DEF_GM(return new BleedGM(kUseAlphaBitmapShader_BleedTest); ) | |
420 DEF_GM(return new BleedGM(kUseAlphaImageShader_BleedTest); ) | |
421 #endif | |
OLD | NEW |