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
diff --git a/expectations/gm/ignored-tests.txt b/expectations/gm/ignored-tests.txt
index 607f218..c20ebb2 100644
--- a/expectations/gm/ignored-tests.txt
+++ b/expectations/gm/ignored-tests.txt
@@ -59,3 +59,7 @@
 # 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
diff --git a/gm/bitmapshader.cpp b/gm/bitmapshader.cpp
index fb56307..99262bb 100644
--- a/gm/bitmapshader.cpp
+++ b/gm/bitmapshader.cpp
@@ -35,7 +35,8 @@
     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 @@
     }
 
     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: