update bitmapshader to avoid potential rendering error for kA8_Config
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 24 Mar 2014 02:49:48 +0000 (02:49 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 24 Mar 2014 02:49:48 +0000 (02:49 +0000)
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

expectations/gm/ignored-tests.txt
gm/bitmapshader.cpp

index 607f2184391d24ad3415ac36b1c8806b0c45c7a0..c20ebb2eff27bd236034a444330910f3ebbac55b 100644 (file)
@@ -59,3 +59,7 @@ canvas-layer-state
 # sugoi: https://codereview.chromium.org/208303002/
 # This path fixes a double offset with the resize filter and adds a gm case to test it
 resizeimagefilter
+
+# yunchao: https://codereview.chromium.org/204143004/
+# This change add some cases to bitmapshader to avoid potential drawing error for kA8_Config
+bitmapshaders
index fb563070d1d19abf01677dac68609eccfcdf2b82..99262bbf706d54bc21dcb5ae0205537da4f7bedd 100644 (file)
@@ -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: