SkPDF: skip shader lookup for SkShader::kColor_GradientType

Also: SkPDFShader::State isi now zero-initilized.

No change in PDF tests.

BUG=chromium:690875
Change-Id: Ibc56cc9435362733adf50cbb51b11c9413572e7f
Reviewed-on: https://skia-review.googlesource.com/8355
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Hal Canary <halcanary@google.com>
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 48c8a9d..4d94551 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -2011,49 +2011,48 @@
     SkShader* shader = paint.getShader();
     SkColor color = paint.getColor();
     if (shader) {
-        // PDF positions patterns relative to the initial transform, so
-        // we need to apply the current transform to the shader parameters.
-        SkMatrix transform = matrix;
-        transform.postConcat(fInitialTransform);
-
-        // PDF doesn't support kClamp_TileMode, so we simulate it by making
-        // a pattern the size of the current clip.
-        SkIRect bounds = clipRegion.getBounds();
-
-        // We need to apply the initial transform to bounds in order to get
-        // bounds in a consistent coordinate system.
-        SkRect boundsTemp;
-        boundsTemp.set(bounds);
-        fInitialTransform.mapRect(&boundsTemp);
-        boundsTemp.roundOut(&bounds);
-
-        SkScalar rasterScale =
-                SkIntToScalar(fRasterDpi) / DPI_FOR_RASTER_SCALE_ONE;
-        pdfShader = SkPDFShader::GetPDFShader(
-                fDocument, fRasterDpi, shader, transform, bounds, rasterScale);
-
-        if (pdfShader.get()) {
-            // pdfShader has been canonicalized so we can directly compare
-            // pointers.
-            int resourceIndex = fShaderResources.find(pdfShader.get());
-            if (resourceIndex < 0) {
-                resourceIndex = fShaderResources.count();
-                fShaderResources.push(pdfShader.get());
-                pdfShader.get()->ref();
-            }
-            entry->fShaderIndex = resourceIndex;
-        } else {
-            // A color shader is treated as an invalid shader so we don't have
-            // to set a shader just for a color.
+        if (SkShader::kColor_GradientType == shader->asAGradient(nullptr)) {
+            // We don't have to set a shader just for a color.
             SkShader::GradientInfo gradientInfo;
-            SkColor gradientColor;
+            SkColor gradientColor = SK_ColorBLACK;
             gradientInfo.fColors = &gradientColor;
             gradientInfo.fColorOffsets = nullptr;
             gradientInfo.fColorCount = 1;
-            if (shader->asAGradient(&gradientInfo) ==
-                    SkShader::kColor_GradientType) {
-                entry->fColor = SkColorSetA(gradientColor, 0xFF);
-                color = gradientColor;
+            SkAssertResult(shader->asAGradient(&gradientInfo) == SkShader::kColor_GradientType);
+            entry->fColor = SkColorSetA(gradientColor, 0xFF);
+            color = gradientColor;
+        } else {
+            // PDF positions patterns relative to the initial transform, so
+            // we need to apply the current transform to the shader parameters.
+            SkMatrix transform = matrix;
+            transform.postConcat(fInitialTransform);
+
+            // PDF doesn't support kClamp_TileMode, so we simulate it by making
+            // a pattern the size of the current clip.
+            SkIRect bounds = clipRegion.getBounds();
+
+            // We need to apply the initial transform to bounds in order to get
+            // bounds in a consistent coordinate system.
+            SkRect boundsTemp;
+            boundsTemp.set(bounds);
+            fInitialTransform.mapRect(&boundsTemp);
+            boundsTemp.roundOut(&bounds);
+
+            SkScalar rasterScale =
+                    SkIntToScalar(fRasterDpi) / DPI_FOR_RASTER_SCALE_ONE;
+            pdfShader = SkPDFShader::GetPDFShader(
+                    fDocument, fRasterDpi, shader, transform, bounds, rasterScale);
+
+            if (pdfShader.get()) {
+                // pdfShader has been canonicalized so we can directly compare
+                // pointers.
+                int resourceIndex = fShaderResources.find(pdfShader.get());
+                if (resourceIndex < 0) {
+                    resourceIndex = fShaderResources.count();
+                    fShaderResources.push(pdfShader.get());
+                    pdfShader.get()->ref();
+                }
+                entry->fShaderIndex = resourceIndex;
             }
         }
     }
diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp
index 82b5b34..0d5439e 100644
--- a/src/pdf/SkPDFShader.cpp
+++ b/src/pdf/SkPDFShader.cpp
@@ -1214,8 +1214,15 @@
 SkPDFShader::State::State(SkShader* shader, const SkMatrix& canvasTransform,
                           const SkIRect& bbox, SkScalar rasterScale,
                           SkBitmap* imageDst)
-        : fCanvasTransform(canvasTransform),
-          fBBox(bbox) {
+        : fType(SkShader::kNone_GradientType)
+        , fInfo{0, nullptr, nullptr, {{0.0f, 0.0f}, {0.0f, 0.0f}},
+                {0.0f, 0.0f}, SkShader::kClamp_TileMode, 0}
+        , fCanvasTransform(canvasTransform)
+        , fShaderTransform{SkMatrix::I()}
+        , fBBox(bbox)
+        , fBitmapKey{{0, 0, 0, 0}, 0}
+        , fImageTileModes{SkShader::kClamp_TileMode,
+                          SkShader::kClamp_TileMode} {
     SkASSERT(imageDst);
     fInfo.fColorCount = 0;
     fInfo.fColors = nullptr;