Commit 11a2ddce authored by fs@opera.com's avatar fs@opera.com

Pass more const RenderObject& in the vicinity of paint-servers

BUG=420022

Review URL: https://codereview.chromium.org/661643005

git-svn-id: svn://svn.chromium.org/blink/trunk@183882 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent a62ddbe8
......@@ -84,17 +84,17 @@ void SVGPaintServer::prependTransform(const AffineTransform& transform)
m_gradient->setGradientSpaceTransform(transform * m_gradient->gradientSpaceTransform());
}
SVGPaintServer SVGPaintServer::requestForRenderer(RenderObject& renderer, RenderStyle* style, RenderSVGResourceMode resourceMode)
SVGPaintServer SVGPaintServer::requestForRenderer(const RenderObject& renderer, const RenderStyle* style, RenderSVGResourceMode resourceMode)
{
ASSERT(style);
ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode);
bool hasFallback = false;
RenderSVGResource* paintingResource = RenderSVGResource::requestPaintingResource(resourceMode, &renderer, style, hasFallback);
RenderSVGResource* paintingResource = RenderSVGResource::requestPaintingResource(resourceMode, renderer, style, hasFallback);
if (!paintingResource)
return invalid();
SVGPaintServer paintServer = paintingResource->preparePaintServer(&renderer);
SVGPaintServer paintServer = paintingResource->preparePaintServer(renderer);
if (paintServer.isValid())
return paintServer;
if (hasFallback)
......@@ -102,15 +102,14 @@ SVGPaintServer SVGPaintServer::requestForRenderer(RenderObject& renderer, Render
return invalid();
}
SVGPaintServer RenderSVGResource::preparePaintServer(RenderObject*)
SVGPaintServer RenderSVGResource::preparePaintServer(const RenderObject&)
{
ASSERT_NOT_REACHED();
return SVGPaintServer::invalid();
}
RenderSVGResource* RenderSVGResource::requestPaintingResource(RenderSVGResourceMode mode, RenderObject* object, const RenderStyle* style, bool& hasFallback)
RenderSVGResource* RenderSVGResource::requestPaintingResource(RenderSVGResourceMode mode, const RenderObject& object, const RenderStyle* style, bool& hasFallback)
{
ASSERT(object);
ASSERT(style);
hasFallback = false;
......@@ -166,7 +165,7 @@ RenderSVGResource* RenderSVGResource::requestPaintingResource(RenderSVGResourceM
}
RenderSVGResource* uriResource = 0;
if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(object))
if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(&object))
uriResource = applyToFill ? resources->fill() : resources->stroke();
// If the requested resource is not available, return the color resource or 'none'.
......
......@@ -54,7 +54,7 @@ public:
explicit SVGPaintServer(PassRefPtr<Gradient>);
explicit SVGPaintServer(PassRefPtr<Pattern>);
static SVGPaintServer requestForRenderer(RenderObject&, RenderStyle*, RenderSVGResourceMode);
static SVGPaintServer requestForRenderer(const RenderObject&, const RenderStyle*, RenderSVGResourceMode);
void apply(GraphicsContext&, RenderSVGResourceMode, GraphicsContextStateSaver* = 0);
......@@ -75,13 +75,13 @@ public:
RenderSVGResource() { }
virtual ~RenderSVGResource() { }
virtual SVGPaintServer preparePaintServer(RenderObject*);
virtual SVGPaintServer preparePaintServer(const RenderObject&);
virtual RenderSVGResourceType resourceType() const = 0;
// Helper utilities used in the render tree to access resources used for painting shapes/text (gradients & patterns & solid colors only)
// If hasFallback gets set to true, the sharedSolidPaintingResource is set to a fallback color.
static RenderSVGResource* requestPaintingResource(RenderSVGResourceMode, RenderObject*, const RenderStyle*, bool& hasFallback);
static RenderSVGResource* requestPaintingResource(RenderSVGResourceMode, const RenderObject&, const RenderStyle*, bool& hasFallback);
static RenderSVGResourceSolidColor* sharedSolidPaintingResource();
static void markForLayoutAndParentResourceInvalidation(RenderObject*, bool needsLayout = true);
......
......@@ -45,10 +45,8 @@ void RenderSVGResourceGradient::removeClientFromCache(RenderObject* client, bool
markClientForInvalidation(client, markForInvalidation ? PaintInvalidation : ParentOnlyInvalidation);
}
SVGPaintServer RenderSVGResourceGradient::preparePaintServer(RenderObject* object)
SVGPaintServer RenderSVGResourceGradient::preparePaintServer(const RenderObject& object)
{
ASSERT(object);
clearInvalidationMask();
// Be sure to synchronize all SVG properties on the gradientElement _before_ processing any further.
......@@ -69,11 +67,11 @@ SVGPaintServer RenderSVGResourceGradient::preparePaintServer(RenderObject* objec
// Spec: When the geometry of the applicable element has no width or height and objectBoundingBox is specified,
// then the given effect (e.g. a gradient or a filter) will be ignored.
FloatRect objectBoundingBox = object->objectBoundingBox();
FloatRect objectBoundingBox = object.objectBoundingBox();
if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && objectBoundingBox.isEmpty())
return SVGPaintServer::invalid();
OwnPtr<GradientData>& gradientData = m_gradientMap.add(object, nullptr).storedValue->value;
OwnPtr<GradientData>& gradientData = m_gradientMap.add(&object, nullptr).storedValue->value;
if (!gradientData)
gradientData = adoptPtr(new GradientData);
......
......@@ -47,7 +47,7 @@ public:
virtual void removeAllClientsFromCache(bool markForInvalidation = true) override final;
virtual void removeClientFromCache(RenderObject*, bool markForInvalidation = true) override final;
virtual SVGPaintServer preparePaintServer(RenderObject*) override final;
virtual SVGPaintServer preparePaintServer(const RenderObject&) override final;
virtual bool isChildAllowed(RenderObject* child, RenderStyle*) const override final;
......@@ -63,7 +63,7 @@ protected:
private:
bool m_shouldCollectGradientAttributes : 1;
HashMap<RenderObject*, OwnPtr<GradientData> > m_gradientMap;
HashMap<const RenderObject*, OwnPtr<GradientData> > m_gradientMap;
};
}
......
......@@ -50,10 +50,9 @@ void RenderSVGResourcePattern::removeClientFromCache(RenderObject* client, bool
markClientForInvalidation(client, markForInvalidation ? PaintInvalidation : ParentOnlyInvalidation);
}
PatternData* RenderSVGResourcePattern::buildPattern(RenderObject* object, const SVGPatternElement* patternElement)
PatternData* RenderSVGResourcePattern::buildPattern(const RenderObject& object, const SVGPatternElement* patternElement)
{
ASSERT(object);
PatternData* currentData = m_patternMap.get(object);
PatternData* currentData = m_patternMap.get(&object);
if (currentData && currentData->pattern)
return currentData;
......@@ -72,7 +71,7 @@ PatternData* RenderSVGResourcePattern::buildPattern(RenderObject* object, const
return 0;
AffineTransform absoluteTransformIgnoringRotation;
SVGRenderingContext::calculateDeviceSpaceTransformation(object, absoluteTransformIgnoringRotation);
SVGRenderingContext::calculateDeviceSpaceTransformation(&object, absoluteTransformIgnoringRotation);
// Ignore 2D rotation, as it doesn't affect the size of the tile.
SVGRenderingContext::clear2DRotation(absoluteTransformIgnoringRotation);
......@@ -107,13 +106,11 @@ PatternData* RenderSVGResourcePattern::buildPattern(RenderObject* object, const
// Various calls above may trigger invalidations in some fringe cases (ImageBuffer allocation
// failures in the SVG image cache for example). To avoid having our PatternData deleted by
// removeAllClientsFromCache(), we only make it visible in the cache at the very end.
return m_patternMap.set(object, patternData.release()).storedValue->value.get();
return m_patternMap.set(&object, patternData.release()).storedValue->value.get();
}
SVGPaintServer RenderSVGResourcePattern::preparePaintServer(RenderObject* object)
SVGPaintServer RenderSVGResourcePattern::preparePaintServer(const RenderObject& object)
{
ASSERT(object);
clearInvalidationMask();
SVGPatternElement* patternElement = toSVGPatternElement(element());
......@@ -130,7 +127,7 @@ SVGPaintServer RenderSVGResourcePattern::preparePaintServer(RenderObject* object
// Spec: When the geometry of the applicable element has no width or height and objectBoundingBox is specified,
// then the given effect (e.g. a gradient or a filter) will be ignored.
FloatRect objectBoundingBox = object->objectBoundingBox();
FloatRect objectBoundingBox = object.objectBoundingBox();
if (m_attributes.patternUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && objectBoundingBox.isEmpty())
return SVGPaintServer::invalid();
......@@ -151,16 +148,15 @@ static inline FloatRect calculatePatternBoundaries(const PatternAttributes& attr
return SVGLengthContext::resolveRectangle(patternElement, attributes.patternUnits(), objectBoundingBox, attributes.x(), attributes.y(), attributes.width(), attributes.height());
}
bool RenderSVGResourcePattern::buildTileImageTransform(RenderObject* renderer,
bool RenderSVGResourcePattern::buildTileImageTransform(const RenderObject& renderer,
const PatternAttributes& attributes,
const SVGPatternElement* patternElement,
FloatRect& patternBoundaries,
AffineTransform& tileImageTransform) const
{
ASSERT(renderer);
ASSERT(patternElement);
FloatRect objectBoundingBox = renderer->objectBoundingBox();
FloatRect objectBoundingBox = renderer.objectBoundingBox();
patternBoundaries = calculatePatternBoundaries(attributes, objectBoundingBox, patternElement);
if (patternBoundaries.width() <= 0 || patternBoundaries.height() <= 0)
return false;
......
......@@ -51,22 +51,22 @@ public:
virtual void removeAllClientsFromCache(bool markForInvalidation = true) override;
virtual void removeClientFromCache(RenderObject*, bool markForInvalidation = true) override;
virtual SVGPaintServer preparePaintServer(RenderObject*) override;
virtual SVGPaintServer preparePaintServer(const RenderObject&) override;
virtual RenderSVGResourceType resourceType() const override { return s_resourceType; }
static const RenderSVGResourceType s_resourceType;
private:
bool buildTileImageTransform(RenderObject*, const PatternAttributes&, const SVGPatternElement*, FloatRect& patternBoundaries, AffineTransform& tileImageTransform) const;
bool buildTileImageTransform(const RenderObject&, const PatternAttributes&, const SVGPatternElement*, FloatRect& patternBoundaries, AffineTransform& tileImageTransform) const;
PassOwnPtr<ImageBuffer> createTileImage(const PatternAttributes&, const FloatRect& tileBoundaries,
const FloatRect& absoluteTileBoundaries, const AffineTransform& tileImageTransform) const;
PatternData* buildPattern(RenderObject*, const SVGPatternElement*);
PatternData* buildPattern(const RenderObject&, const SVGPatternElement*);
bool m_shouldCollectPatternAttributes : 1;
PatternAttributes m_attributes;
HashMap<RenderObject*, OwnPtr<PatternData> > m_patternMap;
HashMap<const RenderObject*, OwnPtr<PatternData> > m_patternMap;
};
}
......
......@@ -32,10 +32,8 @@ RenderSVGResourceSolidColor::~RenderSVGResourceSolidColor()
{
}
SVGPaintServer RenderSVGResourceSolidColor::preparePaintServer(RenderObject* object)
SVGPaintServer RenderSVGResourceSolidColor::preparePaintServer(const RenderObject&)
{
ASSERT_UNUSED(object, object);
return SVGPaintServer(m_color);
}
......
......@@ -30,7 +30,7 @@ public:
RenderSVGResourceSolidColor();
virtual ~RenderSVGResourceSolidColor();
virtual SVGPaintServer preparePaintServer(RenderObject*) override;
virtual SVGPaintServer preparePaintServer(const RenderObject&) override;
virtual RenderSVGResourceType resourceType() const override { return s_resourceType; }
static const RenderSVGResourceType s_resourceType;
......
......@@ -112,7 +112,7 @@ bool RenderSVGShape::fillContains(const FloatPoint& point, bool requiresFill, co
return false;
bool hasFallback;
if (requiresFill && !RenderSVGResource::requestPaintingResource(ApplyToFillMode, this, style(), hasFallback))
if (requiresFill && !RenderSVGResource::requestPaintingResource(ApplyToFillMode, *this, style(), hasFallback))
return false;
return shapeDependentFillContains(point, fillRule);
......@@ -124,7 +124,7 @@ bool RenderSVGShape::strokeContains(const FloatPoint& point, bool requiresStroke
return false;
bool hasFallback;
if (requiresStroke && !RenderSVGResource::requestPaintingResource(ApplyToStrokeMode, this, style(), hasFallback))
if (requiresStroke && !RenderSVGResource::requestPaintingResource(ApplyToStrokeMode, *this, style(), hasFallback))
return false;
return shapeDependentStrokeContains(point);
......
......@@ -282,7 +282,7 @@ static void writeStyle(TextStream& ts, const RenderObject& object)
ASSERT(shape.element());
bool hasFallback;
if (RenderSVGResource* strokePaintingResource = RenderSVGResource::requestPaintingResource(ApplyToStrokeMode, const_cast<RenderSVGShape*>(&shape), shape.style(), hasFallback)) {
if (RenderSVGResource* strokePaintingResource = RenderSVGResource::requestPaintingResource(ApplyToStrokeMode, shape, shape.style(), hasFallback)) {
TextStreamSeparator s(" ");
ts << " [stroke={" << s;
writeSVGPaintingResource(ts, strokePaintingResource);
......@@ -310,7 +310,7 @@ static void writeStyle(TextStream& ts, const RenderObject& object)
ts << "}]";
}
if (RenderSVGResource* fillPaintingResource = RenderSVGResource::requestPaintingResource(ApplyToFillMode, const_cast<RenderSVGShape*>(&shape), shape.style(), hasFallback)) {
if (RenderSVGResource* fillPaintingResource = RenderSVGResource::requestPaintingResource(ApplyToFillMode, shape, shape.style(), hasFallback)) {
TextStreamSeparator s(" ");
ts << " [fill={" << s;
writeSVGPaintingResource(ts, fillPaintingResource);
......
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