Commit cb73241c authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Always return PatternData in LayoutSVGResourcePattern::BuildPatternData

This means that patterns that are in error are cached rather than being
attempted to be rebuilt. This is consistent with how gradients are
handled.

Bug: 109212
Change-Id: I72d418c78cc3314021d21977a53e93b3f7686757
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2062971
Commit-Queue: Stephen Chenney <schenney@chromium.org>
Auto-Submit: Fredrik Söderquist <fs@opera.com>
Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742610}
parent e7a9443d
...@@ -72,6 +72,8 @@ bool LayoutSVGResourcePattern::RemoveClientFromCache( ...@@ -72,6 +72,8 @@ bool LayoutSVGResourcePattern::RemoveClientFromCache(
std::unique_ptr<PatternData> LayoutSVGResourcePattern::BuildPatternData( std::unique_ptr<PatternData> LayoutSVGResourcePattern::BuildPatternData(
const FloatRect& object_bounding_box) { const FloatRect& object_bounding_box) {
auto pattern_data = std::make_unique<PatternData>();
DCHECK(GetElement()); DCHECK(GetElement());
// Validate pattern DOM state before building the actual pattern. This should // Validate pattern DOM state before building the actual pattern. This should
// avoid tearing down the pattern we're currently working on. Preferably the // avoid tearing down the pattern we're currently working on. Preferably the
...@@ -91,11 +93,11 @@ std::unique_ptr<PatternData> LayoutSVGResourcePattern::BuildPatternData( ...@@ -91,11 +93,11 @@ std::unique_ptr<PatternData> LayoutSVGResourcePattern::BuildPatternData(
if (attributes.PatternUnits() == if (attributes.PatternUnits() ==
SVGUnitTypes::kSvgUnitTypeObjectboundingbox && SVGUnitTypes::kSvgUnitTypeObjectboundingbox &&
object_bounding_box.IsEmpty()) object_bounding_box.IsEmpty())
return nullptr; return pattern_data;
// If there's no content disable rendering of the pattern. // If there's no content disable rendering of the pattern.
if (!attributes.PatternContentElement()) if (!attributes.PatternContentElement())
return nullptr; return pattern_data;
// Compute tile metrics. // Compute tile metrics.
FloatRect tile_bounds = SVGLengthContext::ResolveRectangle( FloatRect tile_bounds = SVGLengthContext::ResolveRectangle(
...@@ -103,13 +105,13 @@ std::unique_ptr<PatternData> LayoutSVGResourcePattern::BuildPatternData( ...@@ -103,13 +105,13 @@ std::unique_ptr<PatternData> LayoutSVGResourcePattern::BuildPatternData(
*attributes.X(), *attributes.Y(), *attributes.Width(), *attributes.X(), *attributes.Y(), *attributes.Width(),
*attributes.Height()); *attributes.Height());
if (tile_bounds.IsEmpty()) if (tile_bounds.IsEmpty())
return nullptr; return pattern_data;
AffineTransform tile_transform; AffineTransform tile_transform;
if (attributes.HasViewBox()) { if (attributes.HasViewBox()) {
// An empty viewBox disables rendering of the pattern. // An empty viewBox disables rendering of the pattern.
if (attributes.ViewBox().IsEmpty()) if (attributes.ViewBox().IsEmpty())
return nullptr; return pattern_data;
tile_transform = SVGFitToViewBox::ViewBoxToViewTransform( tile_transform = SVGFitToViewBox::ViewBoxToViewTransform(
attributes.ViewBox(), attributes.PreserveAspectRatio(), attributes.ViewBox(), attributes.PreserveAspectRatio(),
tile_bounds.Width(), tile_bounds.Height()); tile_bounds.Width(), tile_bounds.Height());
...@@ -122,7 +124,6 @@ std::unique_ptr<PatternData> LayoutSVGResourcePattern::BuildPatternData( ...@@ -122,7 +124,6 @@ std::unique_ptr<PatternData> LayoutSVGResourcePattern::BuildPatternData(
} }
} }
auto pattern_data = std::make_unique<PatternData>();
pattern_data->pattern = Pattern::CreatePaintRecordPattern( pattern_data->pattern = Pattern::CreatePaintRecordPattern(
AsPaintRecord(tile_bounds.Size(), tile_transform), AsPaintRecord(tile_bounds.Size(), tile_transform),
FloatRect(FloatPoint(), tile_bounds.Size())); FloatRect(FloatPoint(), tile_bounds.Size()));
...@@ -144,9 +145,7 @@ SVGPaintServer LayoutSVGResourcePattern::PreparePaintServer( ...@@ -144,9 +145,7 @@ SVGPaintServer LayoutSVGResourcePattern::PreparePaintServer(
if (!pattern_data) if (!pattern_data)
pattern_data = BuildPatternData(object_bounding_box); pattern_data = BuildPatternData(object_bounding_box);
// TODO(fs): Always allocate a PatternData, and let PatternData::pattern if (!pattern_data->pattern)
// being nullptr indicate that the pattern is in error/disabled.
if (!pattern_data || !pattern_data->pattern)
return SVGPaintServer::Invalid(); return SVGPaintServer::Invalid();
return SVGPaintServer(pattern_data->pattern, pattern_data->transform); return SVGPaintServer(pattern_data->pattern, pattern_data->transform);
......
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