Commit e1e7aedf authored by fmalita's avatar fmalita Committed by Commit bot

Handle shader construction failures gracefully

If we cannot instantiate a shader (due to e.g. a non-invertible local
matrix), the expectation is to not draw anything.  We're currently
filling with black.

This unblocks https://skia-review.googlesource.com/c/7885/, which
prevents creation of shaders with non-invertible matrices.

R=reed@google.com

Review-Url: https://codereview.chromium.org/2677633004
Cr-Commit-Position: refs/heads/master@{#448018}
parent cb6d69f2
......@@ -320,6 +320,12 @@ void SVGImage::drawPatternForContainer(GraphicsContext& context,
paint.setShader(MakePaintShaderRecord(tilePicture, SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode,
&patternTransform, nullptr));
// If the shader could not be instantiated (e.g. non-invertible matrix),
// draw transparent.
// Note: we can't simply bail, because of arbitrary blend mode.
if (!paint.getShader())
paint.setColor(SK_ColorTRANSPARENT);
paint.setBlendMode(compositeOp);
paint.setColorFilter(sk_ref_sp(context.getColorFilter()));
context.drawRect(dstRect, paint);
......
......@@ -303,20 +303,24 @@ void Image::drawPattern(GraphicsContext& context,
const auto tmy = computeTileMode(destRect.y(), destRect.maxY(), adjustedY,
adjustedY + tileSize.height());
{
PaintFlags paint = context.fillPaint();
paint.setColor(SK_ColorBLACK);
paint.setBlendMode(compositeOp);
paint.setFilterQuality(
context.computeFilterQuality(this, destRect, normSrcRect));
paint.setAntiAlias(context.shouldAntialias());
paint.setShader(
createPatternShader(image.get(), localMatrix, paint,
FloatSize(repeatSpacing.width() / scale.width(),
repeatSpacing.height() / scale.height()),
tmx, tmy));
context.drawRect(destRect, paint);
}
PaintFlags paint = context.fillPaint();
paint.setColor(SK_ColorBLACK);
paint.setBlendMode(compositeOp);
paint.setFilterQuality(
context.computeFilterQuality(this, destRect, normSrcRect));
paint.setAntiAlias(context.shouldAntialias());
paint.setShader(
createPatternShader(image.get(), localMatrix, paint,
FloatSize(repeatSpacing.width() / scale.width(),
repeatSpacing.height() / scale.height()),
tmx, tmy));
// If the shader could not be instantiated (e.g. non-invertible matrix),
// draw transparent.
// Note: we can't simply bail, because of arbitrary blend mode.
if (!paint.getShader())
paint.setColor(SK_ColorTRANSPARENT);
context.drawRect(destRect, paint);
if (currentFrameIsLazyDecoded())
PlatformInstrumentation::didDrawLazyPixelRef(imageID);
......@@ -339,6 +343,8 @@ bool Image::applyShader(SkPaint& paint,
paint.setShader(image->makeShader(SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode, &localMatrix));
if (!paint.getShader())
return false;
// Animation is normally refreshed in draw() impls, which we don't call when
// painting via shaders.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment