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

Side by Side Diff: gm/bitmapshader.cpp

Issue 203203005: update comment on setShader to clarify alpha-bitmap behavior in bitmapshaders (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | include/core/SkPaint.h » ('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 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "gm.h" 8 #include "gm.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 17 matching lines...) Expand all
28 SkPaint circlePaint; 28 SkPaint circlePaint;
29 circlePaint.setColor(SK_ColorBLACK); 29 circlePaint.setColor(SK_ColorBLACK);
30 30
31 bm->allocPixels(SkImageInfo::MakeA8(20, 20)); 31 bm->allocPixels(SkImageInfo::MakeA8(20, 20));
32 bm->eraseColor(SK_ColorTRANSPARENT); 32 bm->eraseColor(SK_ColorTRANSPARENT);
33 33
34 SkCanvas canvas(*bm); 34 SkCanvas canvas(*bm);
35 canvas.drawCircle(10, 10, 10, circlePaint); 35 canvas.drawCircle(10, 10, 10, circlePaint);
36 } 36 }
37 37
38 static void adopt_shader(SkPaint* paint, SkShader* shader) {
39 paint->setShader(shader);
yunchao 2014/03/18 14:38:36 I suggest that the shader set its own matrix. like
40 SkSafeUnref(shader);
41 }
42
38 class BitmapShaderGM : public GM { 43 class BitmapShaderGM : public GM {
39 public: 44 public:
40 45
41 BitmapShaderGM() { 46 BitmapShaderGM() {
42 this->setBGColor(SK_ColorGRAY); 47 this->setBGColor(SK_ColorGRAY);
43 draw_bm(&fBitmap); 48 draw_bm(&fBitmap);
44 draw_mask(&fMask); 49 draw_mask(&fMask);
45 } 50 }
46 51
47 protected: 52 protected:
48 virtual SkString onShortName() { 53 virtual SkString onShortName() {
49 return SkString("bitmapshaders"); 54 return SkString("bitmapshaders");
50 } 55 }
51 56
52 virtual SkISize onISize() { 57 virtual SkISize onISize() {
53 return make_isize(75, 100); 58 return SkISize::Make(75, 100);
54 } 59 }
55 60
56 virtual void onDraw(SkCanvas* canvas) { 61 virtual void onDraw(SkCanvas* canvas) {
57 SkShader* shader = SkShader::CreateBitmapShader(fBitmap,
58 SkShader::kClamp_TileMod e,
59 SkShader::kClamp_TileMod e);
60 SkPaint paint; 62 SkPaint paint;
61 paint.setShader(shader); 63
62 // release the shader ref as the paint now holds a reference 64 adopt_shader(&paint, SkShader::CreateBitmapShader(fBitmap, SkShader::kCl amp_TileMode,
63 shader->unref(); 65 SkShader::kClamp_TileM ode));
64 66
65 // draw the shader with a bitmap mask 67 // draw the shader with a bitmap mask
66 canvas->drawBitmap(fMask, 0, 0, &paint); 68 canvas->drawBitmap(fMask, 0, 0, &paint);
67 canvas->drawBitmap(fMask, 30, 0, &paint); 69 canvas->drawBitmap(fMask, 30, 0, &paint);
68 70
69 canvas->translate(0, 25); 71 canvas->translate(0, 25);
70 72
71 // draw the shader with standard geometry 73 canvas->drawCircle(10, 10, 10, paint);
72 canvas->drawCircle(10, 10, 10, paint); 74 canvas->drawCircle(40, 10, 10, paint); // no blue circle expected
73 canvas->drawCircle(40, 10, 10, paint); // no blue circle expected
74 75
75 canvas->translate(0, 25); 76 canvas->translate(0, 25);
76 77
77 shader = SkShader::CreateBitmapShader(fMask, 78 adopt_shader(&paint, SkShader::CreateBitmapShader(fMask, SkShader::kRepe at_TileMode,
78 SkShader::kRepeat_TileMode, 79 SkShader::kRepeat_Tile Mode));
79 SkShader::kRepeat_TileMode);
80 paint.setShader(shader);
81 paint.setColor(SK_ColorRED); 80 paint.setColor(SK_ColorRED);
82 shader->unref();
83 81
84 // draw the mask using the shader and a color 82 // draw the mask using the shader and a color
85 canvas->drawRect(SkRect::MakeXYWH(0, 0, 20, 20), paint); 83 canvas->drawRect(SkRect::MakeXYWH(0, 0, 20, 20), paint);
86 canvas->drawRect(SkRect::MakeXYWH(30, 0, 20, 20), paint); 84 canvas->drawRect(SkRect::MakeXYWH(30, 0, 20, 20), paint);
87 } 85 }
88 86
89 private: 87 private:
90 SkBitmap fBitmap; 88 SkBitmap fBitmap;
91 SkBitmap fMask; 89 SkBitmap fMask;
92 90
93 typedef GM INHERITED; 91 typedef GM INHERITED;
94 }; 92 };
95 93
96 ////////////////////////////////////////////////////////////////////////////// 94 //////////////////////////////////////////////////////////////////////////////
97 95
98 static GM* MyFactory(void*) { return new BitmapShaderGM; } 96 static GM* MyFactory(void*) { return new BitmapShaderGM; }
99 static GMRegistry reg(MyFactory); 97 static GMRegistry reg(MyFactory);
100 98
101 } 99 }
OLDNEW
« no previous file with comments | « no previous file | include/core/SkPaint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698