aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf/SkPDFShader.cpp
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2016-09-28 11:53:33 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-09-28 17:06:08 +0000
commit47bf4c0009f1f2c86e831447e69475e50cbfc958 (patch)
tree21076cd8a6f09e282babbf41c1d9ef455936b320 /src/pdf/SkPDFShader.cpp
parente3a4e993ef79788d5ee807b10ff588e9c46bac6d (diff)
SkPDF: use SkImage::isAImage
output size savings = ~0.4% with effected gms and skps. BUG=568816 BUG=skia:5592 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2760 Change-Id: Ifead46ea5789e18aa3ddea9ca3986717296a6391 Reviewed-on: https://skia-review.googlesource.com/2760 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'src/pdf/SkPDFShader.cpp')
-rw-r--r--src/pdf/SkPDFShader.cpp93
1 files changed, 49 insertions, 44 deletions
diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp
index 2fe01d9663..d44f10bf7a 100644
--- a/src/pdf/SkPDFShader.cpp
+++ b/src/pdf/SkPDFShader.cpp
@@ -1219,59 +1219,64 @@ SkPDFShader::State::State(SkShader* shader, const SkMatrix& canvasTransform,
fInfo.fColorCount = 0;
fInfo.fColors = nullptr;
fInfo.fColorOffsets = nullptr;
- fShaderTransform = shader->getLocalMatrix();
fImageTileModes[0] = fImageTileModes[1] = SkShader::kClamp_TileMode;
-
fType = shader->asAGradient(&fInfo);
- if (fType == SkShader::kNone_GradientType) {
- if (!shader->isABitmap(imageDst, nullptr, fImageTileModes)) {
- // Generic fallback for unsupported shaders:
- // * allocate a bbox-sized bitmap
- // * shade the whole area
- // * use the result as a bitmap shader
-
- // bbox is in device space. While that's exactly what we
- // want for sizing our bitmap, we need to map it into
- // shader space for adjustments (to match
- // MakeImageShader's behavior).
- SkRect shaderRect = SkRect::Make(bbox);
- if (!inverse_transform_bbox(canvasTransform, &shaderRect)) {
- imageDst->reset();
- return;
- }
+ if (fType != SkShader::kNone_GradientType) {
+ fShaderTransform = shader->getLocalMatrix();
+ this->allocateGradientInfoStorage();
+ shader->asAGradient(&fInfo);
+ return;
+ }
+ if (SkImage* skimg = shader->isAImage(&fShaderTransform, fImageTileModes)) {
+ // TODO(halcanary): delay converting to bitmap.
+ if (skimg->asLegacyBitmap(imageDst, SkImage::kRO_LegacyBitmapMode)) {
+ fBitmapKey = SkBitmapKey(*imageDst);
+ return;
+ }
+ }
+ fShaderTransform = shader->getLocalMatrix();
+ // Generic fallback for unsupported shaders:
+ // * allocate a bbox-sized bitmap
+ // * shade the whole area
+ // * use the result as a bitmap shader
+
+ // bbox is in device space. While that's exactly what we
+ // want for sizing our bitmap, we need to map it into
+ // shader space for adjustments (to match
+ // MakeImageShader's behavior).
+ SkRect shaderRect = SkRect::Make(bbox);
+ if (!inverse_transform_bbox(canvasTransform, &shaderRect)) {
+ imageDst->reset();
+ return;
+ }
- // Clamp the bitmap size to about 1M pixels
- static const SkScalar kMaxBitmapArea = 1024 * 1024;
- SkScalar bitmapArea = rasterScale * bbox.width() * rasterScale * bbox.height();
- if (bitmapArea > kMaxBitmapArea) {
- rasterScale *= SkScalarSqrt(kMaxBitmapArea / bitmapArea);
- }
+ // Clamp the bitmap size to about 1M pixels
+ static const SkScalar kMaxBitmapArea = 1024 * 1024;
+ SkScalar bitmapArea = rasterScale * bbox.width() * rasterScale * bbox.height();
+ if (bitmapArea > kMaxBitmapArea) {
+ rasterScale *= SkScalarSqrt(kMaxBitmapArea / bitmapArea);
+ }
- SkISize size = SkISize::Make(SkScalarRoundToInt(rasterScale * bbox.width()),
- SkScalarRoundToInt(rasterScale * bbox.height()));
- SkSize scale = SkSize::Make(SkIntToScalar(size.width()) / shaderRect.width(),
- SkIntToScalar(size.height()) / shaderRect.height());
+ SkISize size = SkISize::Make(SkScalarRoundToInt(rasterScale * bbox.width()),
+ SkScalarRoundToInt(rasterScale * bbox.height()));
+ SkSize scale = SkSize::Make(SkIntToScalar(size.width()) / shaderRect.width(),
+ SkIntToScalar(size.height()) / shaderRect.height());
- imageDst->allocN32Pixels(size.width(), size.height());
- imageDst->eraseColor(SK_ColorTRANSPARENT);
+ imageDst->allocN32Pixels(size.width(), size.height());
+ imageDst->eraseColor(SK_ColorTRANSPARENT);
- SkPaint p;
- p.setShader(sk_ref_sp(shader));
+ SkPaint p;
+ p.setShader(sk_ref_sp(shader));
- SkCanvas canvas(*imageDst);
- canvas.scale(scale.width(), scale.height());
- canvas.translate(-shaderRect.x(), -shaderRect.y());
- canvas.drawPaint(p);
+ SkCanvas canvas(*imageDst);
+ canvas.scale(scale.width(), scale.height());
+ canvas.translate(-shaderRect.x(), -shaderRect.y());
+ canvas.drawPaint(p);
- fShaderTransform.setTranslate(shaderRect.x(), shaderRect.y());
- fShaderTransform.preScale(1 / scale.width(), 1 / scale.height());
- }
- fBitmapKey = SkBitmapKey(*imageDst);
- } else {
- this->allocateGradientInfoStorage();
- shader->asAGradient(&fInfo);
- }
+ fShaderTransform.setTranslate(shaderRect.x(), shaderRect.y());
+ fShaderTransform.preScale(1 / scale.width(), 1 / scale.height());
+ fBitmapKey = SkBitmapKey(*imageDst);
}
SkPDFShader::State::State(const SkPDFShader::State& other)