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 "SkGradientShader.h" |
13 #include "SkImage.h" | 13 #include "SkImage.h" |
14 #include "SkUtils.h" | 14 #include "SkUtils.h" |
15 | 15 |
16 #if SK_SUPPORT_GPU | 16 #if SK_SUPPORT_GPU |
17 #include "GrContext.h" | 17 #include "GrContext.h" |
18 #include "GrContextOptions.h" | 18 #include "GrContextOptions.h" |
19 #include "SkGr.h" | 19 #include "SkGr.h" |
20 #endif | 20 #endif |
21 | 21 |
22 /** Holds either a bitmap or image to be rendered and a rect that indicates what
part of the bitmap | 22 /** Holds either a bitmap or image to be rendered and a rect that indicates what
part of the bitmap |
23 or image should be tested by the GM. The area outside of the rect is present
to check | 23 or image should be tested by the GM. The area outside of the rect is present
to check |
24 for bleed due to filtering/blurring. */ | 24 for bleed due to filtering/blurring. */ |
25 struct TestPixels { | 25 struct TestPixels { |
26 enum Type { | 26 enum Type { |
27 kBitmap, | 27 kBitmap, |
28 kImage | 28 kImage |
29 }; | 29 }; |
30 Type fType; | 30 Type fType; |
31 SkBitmap fBitmap; | 31 SkBitmap fBitmap; |
32 SkAutoTUnref<SkImage> fImage; | 32 sk_sp<SkImage> fImage; |
33 SkIRect fRect; // The region of the bitmap/image that should
be rendered. | 33 SkIRect fRect; // The region of the bitmap/image that should be ren
dered. |
34 }; | 34 }; |
35 | 35 |
36 /** Creates a bitmap with two one-pixel rings around a checkerboard. The checker
board is 2x2 | 36 /** Creates a bitmap with two one-pixel rings around a checkerboard. The checker
board is 2x2 |
37 logically where each check has as many pixels as is necessary to fill the in
terior. The rect | 37 logically where each check has as many pixels as is necessary to fill the in
terior. The rect |
38 to draw is set to the checkerboard portion. */ | 38 to draw is set to the checkerboard portion. */ |
39 template<typename PIXEL_TYPE> | 39 template<typename PIXEL_TYPE> |
40 bool make_ringed_bitmap(GrContext*, TestPixels* result, int width, int height, | 40 bool make_ringed_bitmap(GrContext*, TestPixels* result, int width, int height, |
41 SkColorType ct, SkAlphaType at, | 41 SkColorType ct, SkAlphaType at, |
42 PIXEL_TYPE outerRingColor, PIXEL_TYPE innerRingColor, | 42 PIXEL_TYPE outerRingColor, PIXEL_TYPE innerRingColor, |
43 PIXEL_TYPE checkColor1, PIXEL_TYPE checkColor2) { | 43 PIXEL_TYPE checkColor1, PIXEL_TYPE checkColor2) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 static const uint8_t kHalf = 0x80; | 123 static const uint8_t kHalf = 0x80; |
124 static const uint8_t k3Q = 0xC0; | 124 static const uint8_t k3Q = 0xC0; |
125 static const uint8_t kOne = 0xFF; | 125 static const uint8_t kOne = 0xFF; |
126 return make_ringed_bitmap<uint8_t>(ctx, result, width, height, kAlpha_8_SkCo
lorType, | 126 return make_ringed_bitmap<uint8_t>(ctx, result, width, height, kAlpha_8_SkCo
lorType, |
127 kPremul_SkAlphaType, kZero, kOne, k3Q, kH
alf); | 127 kPremul_SkAlphaType, kZero, kOne, k3Q, kH
alf); |
128 } | 128 } |
129 | 129 |
130 /** Helper to reuse above functions to produce images rather than bmps */ | 130 /** Helper to reuse above functions to produce images rather than bmps */ |
131 static void bmp_to_image(TestPixels* result) { | 131 static void bmp_to_image(TestPixels* result) { |
132 SkASSERT(TestPixels::kBitmap == result->fType); | 132 SkASSERT(TestPixels::kBitmap == result->fType); |
133 result->fImage.reset(SkImage::NewFromBitmap(result->fBitmap)); | 133 result->fImage = SkImage::MakeFromBitmap(result->fBitmap); |
134 SkASSERT(result->fImage); | 134 SkASSERT(result->fImage); |
135 result->fType = TestPixels::kImage; | 135 result->fType = TestPixels::kImage; |
136 result->fBitmap.reset(); | 136 result->fBitmap.reset(); |
137 } | 137 } |
138 | 138 |
139 /** Color image case. */ | 139 /** Color image case. */ |
140 bool make_ringed_color_image(GrContext* ctx, TestPixels* result, int width, int
height) { | 140 bool make_ringed_color_image(GrContext* ctx, TestPixels* result, int width, int
height) { |
141 if (make_ringed_color_bitmap(ctx, result, width, height)) { | 141 if (make_ringed_color_bitmap(ctx, result, width, height)) { |
142 bmp_to_image(result); | 142 bmp_to_image(result); |
143 return true; | 143 return true; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 SkISize onISize() override { | 338 SkISize onISize() override { |
339 return SkISize::Make(1200, 1080); | 339 return SkISize::Make(1200, 1080); |
340 } | 340 } |
341 | 341 |
342 void drawPixels(SkCanvas* canvas, const TestPixels& pixels, const SkRect& sr
c, | 342 void drawPixels(SkCanvas* canvas, const TestPixels& pixels, const SkRect& sr
c, |
343 const SkRect& dst, const SkPaint* paint, | 343 const SkRect& dst, const SkPaint* paint, |
344 SkCanvas::SrcRectConstraint constraint) { | 344 SkCanvas::SrcRectConstraint constraint) { |
345 if (TestPixels::kBitmap == pixels.fType) { | 345 if (TestPixels::kBitmap == pixels.fType) { |
346 canvas->drawBitmapRect(pixels.fBitmap, src, dst, paint, constraint); | 346 canvas->drawBitmapRect(pixels.fBitmap, src, dst, paint, constraint); |
347 } else { | 347 } else { |
348 canvas->drawImageRect(pixels.fImage, src, dst, paint, constraint); | 348 canvas->drawImageRect(pixels.fImage.get(), src, dst, paint, constrai
nt); |
349 } | 349 } |
350 } | 350 } |
351 | 351 |
352 // Draw the area of interest of the small image | 352 // Draw the area of interest of the small image |
353 void drawCase1(SkCanvas* canvas, int transX, int transY, bool aa, | 353 void drawCase1(SkCanvas* canvas, int transX, int transY, bool aa, |
354 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte
r) { | 354 SkCanvas::SrcRectConstraint constraint, SkFilterQuality filte
r) { |
355 | 355 |
356 SkRect src = SkRect::Make(fSmallTestPixels.fRect); | 356 SkRect src = SkRect::Make(fSmallTestPixels.fRect); |
357 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans
Y), | 357 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(trans
Y), |
358 SkIntToScalar(kBlockSize), SkIntToScalar(k
BlockSize)); | 358 SkIntToScalar(kBlockSize), SkIntToScalar(k
BlockSize)); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 | 596 |
597 DEF_GM( return new BleedGM(kUseBitmap_BleedTest); ) | 597 DEF_GM( return new BleedGM(kUseBitmap_BleedTest); ) |
598 DEF_GM( return new BleedGM(kUseTextureBitmap_BleedTest); ) | 598 DEF_GM( return new BleedGM(kUseTextureBitmap_BleedTest); ) |
599 DEF_GM( return new BleedGM(kUseImage_BleedTest); ) | 599 DEF_GM( return new BleedGM(kUseImage_BleedTest); ) |
600 DEF_GM( return new BleedGM(kUseAlphaBitmap_BleedTest); ) | 600 DEF_GM( return new BleedGM(kUseAlphaBitmap_BleedTest); ) |
601 DEF_GM( return new BleedGM(kUseAlphaTextureBitmap_BleedTest); ) | 601 DEF_GM( return new BleedGM(kUseAlphaTextureBitmap_BleedTest); ) |
602 DEF_GM( return new BleedGM(kUseAlphaImage_BleedTest); ) | 602 DEF_GM( return new BleedGM(kUseAlphaImage_BleedTest); ) |
603 DEF_GM( return new BleedGM(kUseAlphaBitmapShader_BleedTest); ) | 603 DEF_GM( return new BleedGM(kUseAlphaBitmapShader_BleedTest); ) |
604 DEF_GM( return new BleedGM(kUseAlphaTextureBitmapShader_BleedTest); ) | 604 DEF_GM( return new BleedGM(kUseAlphaTextureBitmapShader_BleedTest); ) |
605 DEF_GM( return new BleedGM(kUseAlphaImageShader_BleedTest); ) | 605 DEF_GM( return new BleedGM(kUseAlphaImageShader_BleedTest); ) |
OLD | NEW |