canvas.drawCircle(10, 10, 10, circlePaint);
}
-static void adopt_shader(SkPaint* paint, SkShader* shader) {
+static void adopt_shader(SkPaint* paint, SkShader* shader, SkMatrix s) {
+ shader->setLocalMatrix(s);
paint->setShader(shader);
SkSafeUnref(shader);
}
}
virtual SkISize onISize() {
- return SkISize::Make(75, 100);
+ return SkISize::Make(150, 100);
}
virtual void onDraw(SkCanvas* canvas) {
SkPaint paint;
- adopt_shader(&paint, SkShader::CreateBitmapShader(fBitmap, SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode));
+ for (int i = 0; i < 2; i++) {
+ SkMatrix s;
+ s.reset();
+ if (1 == i) {
+ s.setScale(1.5, 1.5);
+ s.postTranslate(2, 2);
+ }
- // draw the shader with a bitmap mask
- canvas->drawBitmap(fMask, 0, 0, &paint);
- canvas->drawBitmap(fMask, 30, 0, &paint);
+ canvas->save();
+ adopt_shader(&paint, SkShader::CreateBitmapShader(fBitmap, SkShader::kClamp_TileMode,
+ SkShader::kClamp_TileMode), s);
- canvas->translate(0, 25);
+ // draw the shader with a bitmap mask
+ canvas->drawBitmap(fMask, 0, 0, &paint);
+ canvas->drawBitmap(fMask, 30, 0, &paint);
- canvas->drawCircle(10, 10, 10, paint);
- canvas->drawCircle(40, 10, 10, paint); // no blue circle expected
+ canvas->translate(0, 25);
- canvas->translate(0, 25);
+ canvas->drawCircle(10, 10, 10, paint);
+ canvas->drawCircle(40, 10, 10, paint); // no blue circle expected
- adopt_shader(&paint, SkShader::CreateBitmapShader(fMask, SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode));
- paint.setColor(SK_ColorRED);
+ canvas->translate(0, 25);
- // 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);
+ // clear the shader, colorized by a solid color with a bitmap mask
+ paint.setShader(NULL);
+ paint.setColor(SK_ColorGREEN);
+ canvas->drawBitmap(fMask, 0, 0, &paint);
+ canvas->drawBitmap(fMask, 30, 0, &paint);
+
+ canvas->translate(0, 25);
+
+ adopt_shader(&paint, SkShader::CreateBitmapShader(fMask, SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode), s);
+ paint.setColor(SK_ColorRED);
+
+ // 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);
+ canvas->restore();
+ canvas->translate(60, 0);
+ }
}
private: