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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | include/core/SkPaint.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/bitmapshader.cpp
diff --git a/gm/bitmapshader.cpp b/gm/bitmapshader.cpp
index 4649b7e95f16486c61bb1407a6ce2635af1fb369..fb563070d1d19abf01677dac68609eccfcdf2b82 100644
--- a/gm/bitmapshader.cpp
+++ b/gm/bitmapshader.cpp
@@ -35,6 +35,11 @@ static void draw_mask(SkBitmap* bm) {
canvas.drawCircle(10, 10, 10, circlePaint);
}
+static void adopt_shader(SkPaint* paint, SkShader* shader) {
+ paint->setShader(shader);
yunchao 2014/03/18 14:38:36 I suggest that the shader set its own matrix. like
+ SkSafeUnref(shader);
+}
+
class BitmapShaderGM : public GM {
public:
@@ -50,40 +55,33 @@ protected:
}
virtual SkISize onISize() {
- return make_isize(75, 100);
+ return SkISize::Make(75, 100);
}
virtual void onDraw(SkCanvas* canvas) {
- SkShader* shader = SkShader::CreateBitmapShader(fBitmap,
- SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode);
SkPaint paint;
- paint.setShader(shader);
- // release the shader ref as the paint now holds a reference
- shader->unref();
+
+ adopt_shader(&paint, SkShader::CreateBitmapShader(fBitmap, SkShader::kClamp_TileMode,
+ SkShader::kClamp_TileMode));
// draw the shader with a bitmap mask
canvas->drawBitmap(fMask, 0, 0, &paint);
canvas->drawBitmap(fMask, 30, 0, &paint);
- canvas->translate(0, 25);
+ canvas->translate(0, 25);
- // draw the shader with standard geometry
- canvas->drawCircle(10, 10, 10, paint);
- canvas->drawCircle(40, 10, 10, paint); // no blue circle expected
+ canvas->drawCircle(10, 10, 10, paint);
+ canvas->drawCircle(40, 10, 10, paint); // no blue circle expected
- canvas->translate(0, 25);
+ canvas->translate(0, 25);
- shader = SkShader::CreateBitmapShader(fMask,
- SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode);
- paint.setShader(shader);
+ adopt_shader(&paint, SkShader::CreateBitmapShader(fMask, SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode));
paint.setColor(SK_ColorRED);
- shader->unref();
- // draw the mask using the shader and a color
- canvas->drawRect(SkRect::MakeXYWH(0, 0, 20, 20), paint);
- canvas->drawRect(SkRect::MakeXYWH(30, 0, 20, 20), paint);
+ // draw the mask using the shader and a color
+ canvas->drawRect(SkRect::MakeXYWH(0, 0, 20, 20), paint);
+ canvas->drawRect(SkRect::MakeXYWH(30, 0, 20, 20), paint);
}
private:
« 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