Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: gm/bleed.cpp

Issue 1426253002: Add bleed GM variants for bmp backed by an oversized texture (Closed) Base URL: https://skia.googlesource.com/skia.git@maxtile
Patch Set: comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14
15 #if SK_SUPPORT_GPU 15 #if SK_SUPPORT_GPU
16 #include "GrContext.h" 16 #include "GrContext.h"
17 #include "GrContextOptions.h" 17 #include "GrContextOptions.h"
18 #include "SkGr.h"
18 #endif 19 #endif
19 20
20 static void draw_bitmap_rect(SkCanvas* canvas, const SkBitmap& bitmap, const SkI mage*, 21 static void draw_bitmap_rect(SkCanvas* canvas, const SkBitmap& bitmap, const SkI mage*,
21 const SkRect& src, const SkRect& dst, 22 const SkRect& src, const SkRect& dst,
22 const SkPaint* paint, SkCanvas::SrcRectConstraint c onstraint) { 23 const SkPaint* paint, SkCanvas::SrcRectConstraint c onstraint) {
23 canvas->drawBitmapRect(bitmap, src, dst, paint, constraint); 24 canvas->drawBitmapRect(bitmap, src, dst, paint, constraint);
24 } 25 }
25 26
26 static void draw_image_rect(SkCanvas* canvas, const SkBitmap&, const SkImage* im age, 27 static void draw_image_rect(SkCanvas* canvas, const SkBitmap&, const SkImage* im age,
27 const SkRect& src, const SkRect& dst, 28 const SkRect& src, const SkRect& dst,
28 const SkPaint* paint, SkCanvas::SrcRectConstraint co nstraint) { 29 const SkPaint* paint, SkCanvas::SrcRectConstraint co nstraint) {
29 canvas->drawImageRect(image, src, dst, paint, constraint); 30 canvas->drawImageRect(image, src, dst, paint, constraint);
30 } 31 }
31 32
robertphillips 2015/11/02 19:37:59 // Upload the tight-fitting sw-backed bitmap to a
bsalomon 2015/11/02 20:17:30 Done.
33 static void draw_texture_bitmap_rect(SkCanvas* canvas, const SkBitmap& bitmap, c onst SkImage*,
34 const SkRect& src, const SkRect& dst,
35 const SkPaint* paint,
36 SkCanvas::SrcRectConstraint constraint) {
37 GrContext* context = canvas->getGrContext();
38 if (!context) {
39 // For non-GPU canvases fallback to drawing the bitmap directly.
40 canvas->drawBitmapRect(bitmap, src, dst, paint, constraint);
41 return;
42 }
robertphillips 2015/11/02 19:37:59 mv textureBmp to right before the GrWrapTextureInB
bsalomon 2015/11/02 20:17:30 Done.
43 SkBitmap textureBmp;
44 GrSurfaceDesc desc;
45 desc.fConfig = kAlpha_8_SkColorType == bitmap.colorType() ? kAlpha_8_GrPixel Config :
46 kSkia8888_GrPixe lConfig;
47 // Add some padding to the right and beneath the bitmap contents to exercise the case where
48 // the texture is larger than the bitmap.
49 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.
50 desc.fHeight = bitmap.height() + 22;
51 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de sc, true));
52 if (!texture) {
53 return;
54 }
55 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.
56 texture->writePixels(0, 0, bitmap.width(), bitmap.height(), desc.fConfig, bi tmap.getPixels(),
57 bitmap.rowBytes());
58 GrWrapTextureInBitmap(texture, bitmap.width(), bitmap.height(), true, &textu reBmp);
59 canvas->drawBitmapRect(textureBmp, src, dst, paint, constraint);
60 }
61
32 // Create a black&white checked texture with 2 1-pixel rings 62 // Create a black&white checked texture with 2 1-pixel rings
33 // around the outside edge. The inner ring is red and the outer ring is blue. 63 // around the outside edge. The inner ring is red and the outer ring is blue.
34 static void make_ringed_color_bitmap(SkBitmap* result, int width, int height) { 64 static void make_ringed_color_bitmap(SkBitmap* result, int width, int height) {
35 SkASSERT(0 == width % 2 && 0 == height % 2); 65 SkASSERT(0 == width % 2 && 0 == height % 2);
36 66
37 static const SkPMColor kRed = SkPreMultiplyColor(SK_ColorRED); 67 static const SkPMColor kRed = SkPreMultiplyColor(SK_ColorRED);
38 static const SkPMColor kBlue = SkPreMultiplyColor(SK_ColorBLUE); 68 static const SkPMColor kBlue = SkPreMultiplyColor(SK_ColorBLUE);
39 static const SkPMColor kBlack = SkPreMultiplyColor(SK_ColorBLACK); 69 static const SkPMColor kBlack = SkPreMultiplyColor(SK_ColorBLACK);
40 static const SkPMColor kWhite = SkPreMultiplyColor(SK_ColorWHITE); 70 static const SkPMColor kWhite = SkPreMultiplyColor(SK_ColorWHITE);
41 71
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 static SkShader* make_shader() { 195 static SkShader* make_shader() {
166 static const SkPoint pts[] = { {0, 0}, {20, 20} }; 196 static const SkPoint pts[] = { {0, 0}, {20, 20} };
167 static const SkColor colors[] = { SK_ColorGREEN, SK_ColorYELLOW }; 197 static const SkColor colors[] = { SK_ColorGREEN, SK_ColorYELLOW };
168 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kMi rror_TileMode); 198 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kMi rror_TileMode);
169 } 199 }
170 200
171 static SkShader* make_null_shader() { return nullptr; } 201 static SkShader* make_null_shader() { return nullptr; }
172 202
173 enum BleedTest { 203 enum BleedTest {
174 kUseBitmap_BleedTest, 204 kUseBitmap_BleedTest,
205 kUseTextureBitmap_BleedTest,
175 kUseImage_BleedTest, 206 kUseImage_BleedTest,
176 kUseAlphaBitmap_BleedTest, 207 kUseAlphaBitmap_BleedTest,
208 kUseAlphaTextureBitmap_BleedTest,
177 kUseAlphaImage_BleedTest, 209 kUseAlphaImage_BleedTest,
178 kUseAlphaBitmapShader_BleedTest, 210 kUseAlphaBitmapShader_BleedTest,
211 kUseAlphaTextureBitmapShader_BleedTest,
179 kUseAlphaImageShader_BleedTest, 212 kUseAlphaImageShader_BleedTest,
180 }; 213 };
181 214
182 const struct { 215 const struct {
183 const char* fName; 216 const char* fName;
184 void(*fBmpMaker)(SkBitmap* result, int width, int height); 217 void(*fBmpMaker)(SkBitmap* result, int width, int height);
185 SkShader*(*fShaderMaker)(); 218 SkShader*(*fShaderMaker)();
186 void(*fDraw)(SkCanvas*, const SkBitmap&, const SkImage*, const SkRect&, cons t SkRect&, 219 void(*fDraw)(SkCanvas*, const SkBitmap&, const SkImage*, const SkRect&, cons t SkRect&,
187 const SkPaint*, SkCanvas::SrcRectConstraint); 220 const SkPaint*, SkCanvas::SrcRectConstraint);
188 } gBleedRec[] = { 221 } gBleedRec[] = {
189 { "bleed", make_ringed_color_bitmap, make_null_shader, draw_bitmap_rect }, 222 { "bleed", make_ringed_color_bitmap, make_null_shad er, draw_bitmap_rect },
190 { "bleed_image", make_ringed_color_bitmap, make_null_shader, draw_image_rect }, 223 { "bleed_texture_bmp", make_ringed_color_bitmap, make_null_shad er, draw_texture_bitmap_rect },
191 { "bleed_alpha_bmp", make_ringed_alpha_bitmap, make_null_shader, draw_bitmap_rect }, 224 { "bleed_image", make_ringed_color_bitmap, make_null_shad er, draw_image_rect },
192 { "bleed_alpha_image", make_ringed_alpha_bitmap, make_null_shader, draw_image_rect }, 225 { "bleed_alpha_bmp", make_ringed_alpha_bitmap, make_null_shad er, draw_bitmap_rect },
193 { "bleed_alpha_bmp_shader", make_ringed_alpha_bitmap, make_shader, draw_bitmap_rect }, 226 { "bleed_alpha_texture_bmp", make_ringed_alpha_bitmap, make_null_shad er, draw_texture_bitmap_rect },
194 { "bleed_alpha_image_shader", make_ringed_alpha_bitmap, make_shader, draw_image_rect }, 227 { "bleed_alpha_image", make_ringed_alpha_bitmap, make_null_shad er, draw_image_rect },
228 { "bleed_alpha_bmp_shader", make_ringed_alpha_bitmap, make_shader, draw_bitmap_rect },
229 { "bleed_alpha_texture_bmp_shader", make_ringed_alpha_bitmap, make_shader, draw_texture_bitmap_rect },
230 { "bleed_alpha_image_shader", make_ringed_alpha_bitmap, make_shader, draw_image_rect },
195 }; 231 };
196 232
197 // This GM exercises the drawBitmapRect constraints 233 // This GM exercises the drawBitmapRect constraints
198 class BleedGM : public skiagm::GM { 234 class BleedGM : public skiagm::GM {
199 public: 235 public:
200 BleedGM(BleedTest bt) : fBT(bt) {} 236 BleedGM(BleedTest bt) : fBT(bt) {}
201 237
202 protected: 238 protected:
203 239
204 SkString onShortName() override { 240 SkString onShortName() override {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 SkAutoTUnref<SkImage> fImageSmall; 443 SkAutoTUnref<SkImage> fImageSmall;
408 SkAutoTUnref<SkImage> fImageBig; 444 SkAutoTUnref<SkImage> fImageBig;
409 445
410 SkAutoTUnref<SkShader> fShader; 446 SkAutoTUnref<SkShader> fShader;
411 447
412 const BleedTest fBT; 448 const BleedTest fBT;
413 449
414 typedef GM INHERITED; 450 typedef GM INHERITED;
415 }; 451 };
416 452
453
417 DEF_GM( return new BleedGM(kUseBitmap_BleedTest); ) 454 DEF_GM( return new BleedGM(kUseBitmap_BleedTest); )
455 DEF_GM( return new BleedGM(kUseTextureBitmap_BleedTest); )
418 DEF_GM( return new BleedGM(kUseImage_BleedTest); ) 456 DEF_GM( return new BleedGM(kUseImage_BleedTest); )
419 DEF_GM( return new BleedGM(kUseAlphaBitmap_BleedTest); ) 457 DEF_GM( return new BleedGM(kUseAlphaBitmap_BleedTest); )
458 DEF_GM( return new BleedGM(kUseAlphaTextureBitmap_BleedTest); )
420 DEF_GM( return new BleedGM(kUseAlphaImage_BleedTest); ) 459 DEF_GM( return new BleedGM(kUseAlphaImage_BleedTest); )
421 DEF_GM(return new BleedGM(kUseAlphaBitmapShader_BleedTest); ) 460 DEF_GM( return new BleedGM(kUseAlphaBitmapShader_BleedTest); )
422 DEF_GM(return new BleedGM(kUseAlphaImageShader_BleedTest); ) 461 DEF_GM( return new BleedGM(kUseAlphaTextureBitmapShader_BleedTest); )
462 DEF_GM( return new BleedGM(kUseAlphaImageShader_BleedTest); )
OLDNEW
« no previous file with comments | « no previous file | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698