diff options
author | 2014-03-24 02:49:48 +0000 | |
---|---|---|
committer | 2014-03-24 02:49:48 +0000 | |
commit | 08f6d86f8e6aa19f6f2702b106fcfaa89d760869 (patch) | |
tree | 59966db5a04dc684253bf929499f953915a506de /gm | |
parent | 7209f939c3ad99b86349046425191746398a1f6c (diff) |
update bitmapshader to avoid potential rendering error for kA8_Config
A local matrix is set to the shader, which will show the potential error for SkCanvas::drawBitmap when the bitmap is kA8_Config, as well as the potential error for drawing a geometry with a bitmapshader who's bitmap is kA8_Config.
A simple case is also added for SkCanvas::drawBitmap when the bitmap is kA8_Config, but there is not shader. Then the drawing area will be colorized by the solid color set in SkPaint.
BUG=skia:2278
BUG=skia:2293
R=reed@google.com, bsalomon@google.com
Author: yunchao.he@intel.com
Review URL: https://codereview.chromium.org/204143004
git-svn-id: http://skia.googlecode.com/svn/trunk@13904 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm')
-rw-r--r-- | gm/bitmapshader.cpp | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/gm/bitmapshader.cpp b/gm/bitmapshader.cpp index fb563070d1..99262bbf70 100644 --- a/gm/bitmapshader.cpp +++ b/gm/bitmapshader.cpp @@ -35,7 +35,8 @@ static void draw_mask(SkBitmap* bm) { 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); } @@ -55,33 +56,53 @@ protected: } 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: |