Chromium Code Reviews| Index: gm/bleed.cpp |
| diff --git a/gm/bleed.cpp b/gm/bleed.cpp |
| index 26dca803ef44cbd2b389dd21380b71dffedd8993..47096022c07c251ea3ba22e5f0e658b6da0bdcb2 100644 |
| --- a/gm/bleed.cpp |
| +++ b/gm/bleed.cpp |
| @@ -15,6 +15,7 @@ |
| #if SK_SUPPORT_GPU |
| #include "GrContext.h" |
| #include "GrContextOptions.h" |
| +#include "SkGr.h" |
| #endif |
| static void draw_bitmap_rect(SkCanvas* canvas, const SkBitmap& bitmap, const SkImage*, |
| @@ -29,6 +30,35 @@ static void draw_image_rect(SkCanvas* canvas, const SkBitmap&, const SkImage* im |
| canvas->drawImageRect(image, src, dst, paint, constraint); |
| } |
|
robertphillips
2015/11/02 19:37:59
// Upload the tight-fitting sw-backed bitmap to a
bsalomon
2015/11/02 20:17:30
Done.
|
| +static void draw_texture_bitmap_rect(SkCanvas* canvas, const SkBitmap& bitmap, const SkImage*, |
| + const SkRect& src, const SkRect& dst, |
| + const SkPaint* paint, |
| + SkCanvas::SrcRectConstraint constraint) { |
| + GrContext* context = canvas->getGrContext(); |
| + if (!context) { |
| + // For non-GPU canvases fallback to drawing the bitmap directly. |
| + canvas->drawBitmapRect(bitmap, src, dst, paint, constraint); |
| + return; |
| + } |
|
robertphillips
2015/11/02 19:37:59
mv textureBmp to right before the GrWrapTextureInB
bsalomon
2015/11/02 20:17:30
Done.
|
| + SkBitmap textureBmp; |
| + GrSurfaceDesc desc; |
| + desc.fConfig = kAlpha_8_SkColorType == bitmap.colorType() ? kAlpha_8_GrPixelConfig : |
| + kSkia8888_GrPixelConfig; |
| + // Add some padding to the right and beneath the bitmap contents to exercise the case where |
| + // the texture is larger than the bitmap. |
| + desc.fWidth = bitmap.width() + 16; |
|
robertphillips
2015/11/02 19:37:59
22 ?
bsalomon
2015/11/02 20:17:30
Just wanted a weird number... Added comment.
|
| + desc.fHeight = bitmap.height() + 22; |
| + SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(desc, true)); |
| + if (!texture) { |
| + return; |
| + } |
| + SkAutoLockPixels al(bitmap); |
|
robertphillips
2015/11/02 19:37:59
Can we clear the texture to green first ?
bsalomon
2015/11/02 20:17:30
Done.
|
| + texture->writePixels(0, 0, bitmap.width(), bitmap.height(), desc.fConfig, bitmap.getPixels(), |
| + bitmap.rowBytes()); |
| + GrWrapTextureInBitmap(texture, bitmap.width(), bitmap.height(), true, &textureBmp); |
| + canvas->drawBitmapRect(textureBmp, src, dst, paint, constraint); |
| +} |
| + |
| // Create a black&white checked texture with 2 1-pixel rings |
| // around the outside edge. The inner ring is red and the outer ring is blue. |
| static void make_ringed_color_bitmap(SkBitmap* result, int width, int height) { |
| @@ -172,10 +202,13 @@ static SkShader* make_null_shader() { return nullptr; } |
| enum BleedTest { |
| kUseBitmap_BleedTest, |
| + kUseTextureBitmap_BleedTest, |
| kUseImage_BleedTest, |
| kUseAlphaBitmap_BleedTest, |
| + kUseAlphaTextureBitmap_BleedTest, |
| kUseAlphaImage_BleedTest, |
| kUseAlphaBitmapShader_BleedTest, |
| + kUseAlphaTextureBitmapShader_BleedTest, |
| kUseAlphaImageShader_BleedTest, |
| }; |
| @@ -186,12 +219,15 @@ const struct { |
| void(*fDraw)(SkCanvas*, const SkBitmap&, const SkImage*, const SkRect&, const SkRect&, |
| const SkPaint*, SkCanvas::SrcRectConstraint); |
| } gBleedRec[] = { |
| - { "bleed", make_ringed_color_bitmap, make_null_shader, draw_bitmap_rect }, |
| - { "bleed_image", make_ringed_color_bitmap, make_null_shader, draw_image_rect }, |
| - { "bleed_alpha_bmp", make_ringed_alpha_bitmap, make_null_shader, draw_bitmap_rect }, |
| - { "bleed_alpha_image", make_ringed_alpha_bitmap, make_null_shader, draw_image_rect }, |
| - { "bleed_alpha_bmp_shader", make_ringed_alpha_bitmap, make_shader, draw_bitmap_rect }, |
| - { "bleed_alpha_image_shader", make_ringed_alpha_bitmap, make_shader, draw_image_rect }, |
| + { "bleed", make_ringed_color_bitmap, make_null_shader, draw_bitmap_rect }, |
| + { "bleed_texture_bmp", make_ringed_color_bitmap, make_null_shader, draw_texture_bitmap_rect }, |
| + { "bleed_image", make_ringed_color_bitmap, make_null_shader, draw_image_rect }, |
| + { "bleed_alpha_bmp", make_ringed_alpha_bitmap, make_null_shader, draw_bitmap_rect }, |
| + { "bleed_alpha_texture_bmp", make_ringed_alpha_bitmap, make_null_shader, draw_texture_bitmap_rect }, |
| + { "bleed_alpha_image", make_ringed_alpha_bitmap, make_null_shader, draw_image_rect }, |
| + { "bleed_alpha_bmp_shader", make_ringed_alpha_bitmap, make_shader, draw_bitmap_rect }, |
| + { "bleed_alpha_texture_bmp_shader", make_ringed_alpha_bitmap, make_shader, draw_texture_bitmap_rect }, |
| + { "bleed_alpha_image_shader", make_ringed_alpha_bitmap, make_shader, draw_image_rect }, |
| }; |
| // This GM exercises the drawBitmapRect constraints |
| @@ -414,9 +450,13 @@ private: |
| typedef GM INHERITED; |
| }; |
| + |
| DEF_GM( return new BleedGM(kUseBitmap_BleedTest); ) |
| +DEF_GM( return new BleedGM(kUseTextureBitmap_BleedTest); ) |
| DEF_GM( return new BleedGM(kUseImage_BleedTest); ) |
| DEF_GM( return new BleedGM(kUseAlphaBitmap_BleedTest); ) |
| +DEF_GM( return new BleedGM(kUseAlphaTextureBitmap_BleedTest); ) |
| DEF_GM( return new BleedGM(kUseAlphaImage_BleedTest); ) |
| -DEF_GM(return new BleedGM(kUseAlphaBitmapShader_BleedTest); ) |
| -DEF_GM(return new BleedGM(kUseAlphaImageShader_BleedTest); ) |
| +DEF_GM( return new BleedGM(kUseAlphaBitmapShader_BleedTest); ) |
| +DEF_GM( return new BleedGM(kUseAlphaTextureBitmapShader_BleedTest); ) |
| +DEF_GM( return new BleedGM(kUseAlphaImageShader_BleedTest); ) |