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 "SkImage.h" | 12 #include "SkImage.h" |
13 | 13 |
14 #if SK_SUPPORT_GPU | 14 #if SK_SUPPORT_GPU |
15 #include "GrContext.h" | 15 #include "GrContext.h" |
16 #include "GrContextOptions.h" | 16 #include "GrContextOptions.h" |
17 #endif | 17 #endif |
18 | 18 |
19 static void draw_bitmap_rect(SkCanvas* canvas, const SkBitmap& bitmap, const SkI
mage*, | 19 static void draw_bitmap_rect(SkCanvas* canvas, const SkBitmap& bitmap, const SkI
mage*, |
20 const SkRect* src, const SkRect& dst, | 20 const SkRect& src, const SkRect& dst, |
21 const SkPaint* paint, SkCanvas::SrcRectConstraint c
onstraint) { | 21 const SkPaint* paint, SkCanvas::SrcRectConstraint c
onstraint) { |
22 canvas->drawBitmapRect(bitmap, src, dst, paint, constraint); | 22 canvas->drawBitmapRect(bitmap, src, dst, paint, constraint); |
23 } | 23 } |
24 | 24 |
25 static void draw_image_rect(SkCanvas* canvas, const SkBitmap&, const SkImage* im
age, | 25 static void draw_image_rect(SkCanvas* canvas, const SkBitmap&, const SkImage* im
age, |
26 const SkRect* src, const SkRect& dst, | 26 const SkRect& src, const SkRect& dst, |
27 const SkPaint* paint, SkCanvas::SrcRectConstraint co
nstraint) { | 27 const SkPaint* paint, SkCanvas::SrcRectConstraint co
nstraint) { |
28 canvas->drawImageRect(image, src, dst, paint, constraint); | 28 canvas->drawImageRect(image, src, dst, paint, constraint); |
29 } | 29 } |
30 | 30 |
31 enum BleedTest { | 31 enum BleedTest { |
32 kUseBitmap_BleedTest, | 32 kUseBitmap_BleedTest, |
33 kUseImage_BleedTest, | 33 kUseImage_BleedTest, |
34 }; | 34 }; |
35 | 35 |
36 const struct { | 36 const struct { |
37 const char* fName; | 37 const char* fName; |
38 void (*fDraw)(SkCanvas*, const SkBitmap&, const SkImage*, const SkRect*, con
st SkRect&, | 38 void (*fDraw)(SkCanvas*, const SkBitmap&, const SkImage*, const SkRect&, con
st SkRect&, |
39 const SkPaint*, SkCanvas::SrcRectConstraint); | 39 const SkPaint*, SkCanvas::SrcRectConstraint); |
40 } gBleedRec[] = { | 40 } gBleedRec[] = { |
41 { "bleed", draw_bitmap_rect }, | 41 { "bleed", draw_bitmap_rect }, |
42 { "bleed_image", draw_image_rect }, | 42 { "bleed_image", draw_image_rect }, |
43 }; | 43 }; |
44 | 44 |
45 // Create a black&white checked texture with 2 1-pixel rings | 45 // 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. | 46 // 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) { | 47 static void make_ringed_bitmap(SkBitmap* result, int width, int height) { |
48 SkASSERT(0 == width % 2 && 0 == height % 2); | 48 SkASSERT(0 == width % 2 && 0 == height % 2); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte
r) { | 137 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte
r) { |
138 SkRect src = SkRect::MakeXYWH(2, 2, | 138 SkRect src = SkRect::MakeXYWH(2, 2, |
139 SkIntToScalar(kSmallTextureSize-4), | 139 SkIntToScalar(kSmallTextureSize-4), |
140 SkIntToScalar(kSmallTextureSize-4)); | 140 SkIntToScalar(kSmallTextureSize-4)); |
141 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans
Y), | 141 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans
Y), |
142 SkIntToScalar(kBlockSize), SkIntToScalar(k
BlockSize)); | 142 SkIntToScalar(kBlockSize), SkIntToScalar(k
BlockSize)); |
143 | 143 |
144 SkPaint paint; | 144 SkPaint paint; |
145 paint.setFilterQuality(filter); | 145 paint.setFilterQuality(filter); |
146 | 146 |
147 gBleedRec[fBT].fDraw(canvas, fBitmapSmall, fImageSmall, &src, dst, &pain
t, constraint); | 147 gBleedRec[fBT].fDraw(canvas, fBitmapSmall, fImageSmall, src, dst, &paint
, constraint); |
148 } | 148 } |
149 | 149 |
150 // Draw almost all of the large bitmap | 150 // Draw almost all of the large bitmap |
151 void drawCase2(SkCanvas* canvas, int transX, int transY, | 151 void drawCase2(SkCanvas* canvas, int transX, int transY, |
152 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte
r) { | 152 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte
r) { |
153 SkRect src = SkRect::MakeXYWH(2, 2, | 153 SkRect src = SkRect::MakeXYWH(2, 2, |
154 SkIntToScalar(fBitmapBig.width()-4), | 154 SkIntToScalar(fBitmapBig.width()-4), |
155 SkIntToScalar(fBitmapBig.height()-4)); | 155 SkIntToScalar(fBitmapBig.height()-4)); |
156 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans
Y), | 156 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans
Y), |
157 SkIntToScalar(kBlockSize), SkIntToScalar(k
BlockSize)); | 157 SkIntToScalar(kBlockSize), SkIntToScalar(k
BlockSize)); |
158 | 158 |
159 SkPaint paint; | 159 SkPaint paint; |
160 paint.setFilterQuality(filter); | 160 paint.setFilterQuality(filter); |
161 | 161 |
162 gBleedRec[fBT].fDraw(canvas, fBitmapBig, fImageBig, &src, dst, &paint, c
onstraint); | 162 gBleedRec[fBT].fDraw(canvas, fBitmapBig, fImageBig, src, dst, &paint, co
nstraint); |
163 } | 163 } |
164 | 164 |
165 // Draw ~1/4 of the large bitmap | 165 // Draw ~1/4 of the large bitmap |
166 void drawCase3(SkCanvas* canvas, int transX, int transY, | 166 void drawCase3(SkCanvas* canvas, int transX, int transY, |
167 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte
r) { | 167 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte
r) { |
168 SkRect src = SkRect::MakeXYWH(2, 2, | 168 SkRect src = SkRect::MakeXYWH(2, 2, |
169 SkIntToScalar(fBitmapBig.width()/2-2), | 169 SkIntToScalar(fBitmapBig.width()/2-2), |
170 SkIntToScalar(fBitmapBig.height()/2-2)); | 170 SkIntToScalar(fBitmapBig.height()/2-2)); |
171 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans
Y), | 171 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans
Y), |
172 SkIntToScalar(kBlockSize), SkIntToScalar(k
BlockSize)); | 172 SkIntToScalar(kBlockSize), SkIntToScalar(k
BlockSize)); |
173 | 173 |
174 SkPaint paint; | 174 SkPaint paint; |
175 paint.setFilterQuality(filter); | 175 paint.setFilterQuality(filter); |
176 | 176 |
177 gBleedRec[fBT].fDraw(canvas, fBitmapBig, fImageBig, &src, dst, &paint, c
onstraint); | 177 gBleedRec[fBT].fDraw(canvas, fBitmapBig, fImageBig, src, dst, &paint, co
nstraint); |
178 } | 178 } |
179 | 179 |
180 // Draw the center of the small bitmap with a mask filter | 180 // Draw the center of the small bitmap with a mask filter |
181 void drawCase4(SkCanvas* canvas, int transX, int transY, | 181 void drawCase4(SkCanvas* canvas, int transX, int transY, |
182 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte
r) { | 182 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte
r) { |
183 SkRect src = SkRect::MakeXYWH(2, 2, | 183 SkRect src = SkRect::MakeXYWH(2, 2, |
184 SkIntToScalar(kSmallTextureSize-4), | 184 SkIntToScalar(kSmallTextureSize-4), |
185 SkIntToScalar(kSmallTextureSize-4)); | 185 SkIntToScalar(kSmallTextureSize-4)); |
186 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans
Y), | 186 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans
Y), |
187 SkIntToScalar(kBlockSize), SkIntToScalar(k
BlockSize)); | 187 SkIntToScalar(kBlockSize), SkIntToScalar(k
BlockSize)); |
188 | 188 |
189 SkPaint paint; | 189 SkPaint paint; |
190 paint.setFilterQuality(filter); | 190 paint.setFilterQuality(filter); |
191 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, | 191 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, |
192 SkBlurMask::ConvertRadiusToSigma(3)); | 192 SkBlurMask::ConvertRadiusToSigma(3)); |
193 paint.setMaskFilter(mf)->unref(); | 193 paint.setMaskFilter(mf)->unref(); |
194 | 194 |
195 gBleedRec[fBT].fDraw(canvas, fBitmapSmall, fImageSmall, &src, dst, &pain
t, constraint); | 195 gBleedRec[fBT].fDraw(canvas, fBitmapSmall, fImageSmall, src, dst, &paint
, constraint); |
196 } | 196 } |
197 | 197 |
198 void onDraw(SkCanvas* canvas) override { | 198 void onDraw(SkCanvas* canvas) override { |
199 | 199 |
200 canvas->clear(SK_ColorGRAY); | 200 canvas->clear(SK_ColorGRAY); |
201 | 201 |
202 for (int m = 0; m < 2; ++m) { | 202 for (int m = 0; m < 2; ++m) { |
203 canvas->save(); | 203 canvas->save(); |
204 if (m) { | 204 if (m) { |
205 static const SkScalar kBottom = SkIntToScalar(kRow3Y + kBlockSiz
e + kBlockSpacing); | 205 static const SkScalar kBottom = SkIntToScalar(kRow3Y + kBlockSiz
e + kBlockSpacing); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 SkBitmap fBitmapBig; | 280 SkBitmap fBitmapBig; |
281 SkAutoTUnref<SkImage> fImageSmall; | 281 SkAutoTUnref<SkImage> fImageSmall; |
282 SkAutoTUnref<SkImage> fImageBig; | 282 SkAutoTUnref<SkImage> fImageBig; |
283 const BleedTest fBT; | 283 const BleedTest fBT; |
284 | 284 |
285 typedef GM INHERITED; | 285 typedef GM INHERITED; |
286 }; | 286 }; |
287 | 287 |
288 DEF_GM( return new BleedGM(kUseBitmap_BleedTest); ) | 288 DEF_GM( return new BleedGM(kUseBitmap_BleedTest); ) |
289 DEF_GM( return new BleedGM(kUseImage_BleedTest); ) | 289 DEF_GM( return new BleedGM(kUseImage_BleedTest); ) |
OLD | NEW |