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>
This commit is contained in:
Hal Canary 2017-02-12 20:29:12 -05:00 committed by Skia Commit-Bot
parent 5cdc9dda33
commit c8f918004a
2 changed files with 47 additions and 41 deletions

View File

@ -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;
}
}
}

View File

@ -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;