diff options
author | Hal Canary <halcanary@google.com> | 2017-02-12 20:29:12 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-13 18:59:17 +0000 |
commit | c8f918004a86a11ac8518b56c6ce77f434205987 (patch) | |
tree | 858cba6f99d1425ab5c0bec6b3172dbb8349277e | |
parent | 5cdc9dda330db41d34e452a91b6b0995b5a57626 (diff) |
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>
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 77 | ||||
-rw-r--r-- | src/pdf/SkPDFShader.cpp | 11 |
2 files changed, 47 insertions, 41 deletions
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 48c8a9dd53..4d945517f5 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -2011,49 +2011,48 @@ void SkPDFDevice::populateGraphicStateEntryFromPaint( 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 82b5b3475e..0d5439e7e8 100644 --- a/src/pdf/SkPDFShader.cpp +++ b/src/pdf/SkPDFShader.cpp @@ -1214,8 +1214,15 @@ bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const { 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; |