Commit c24a7718 authored by pdr@chromium.org's avatar pdr@chromium.org

Change RenderSVGResourceClipper's ClipperContext class into an enum

RenderSVGResourceClipper needs a couple bits of state to determine
whether mask or path clipping was used. (The clipper doesn't maintain
this state because it can be applied to multiple renderers.) This patch
converts the ClipperContext class into a simple enum which is now
scoped to RenderSVGResourceClipper.

No new tests as there is no change in behavior.

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

git-svn-id: svn://svn.chromium.org/blink/trunk@181575 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 51acf0d0
...@@ -1720,7 +1720,7 @@ void RenderLayer::paintLayerContents(GraphicsContext* context, const LayerPainti ...@@ -1720,7 +1720,7 @@ void RenderLayer::paintLayerContents(GraphicsContext* context, const LayerPainti
GraphicsContextStateSaver clipStateSaver(*context, false); GraphicsContextStateSaver clipStateSaver(*context, false);
RenderStyle* style = renderer()->style(); RenderStyle* style = renderer()->style();
RenderSVGResourceClipper* resourceClipper = 0; RenderSVGResourceClipper* resourceClipper = 0;
ClipperContext clipperContext; RenderSVGResourceClipper::ClipperState clipperState = RenderSVGResourceClipper::ClipperNotApplied;
// Clip-path, like border radius, must not be applied to the contents of a composited-scrolling container. // Clip-path, like border radius, must not be applied to the contents of a composited-scrolling container.
// It must, however, still be applied to the mask layer, so that the compositor can properly mask the // It must, however, still be applied to the mask layer, so that the compositor can properly mask the
...@@ -1755,7 +1755,7 @@ void RenderLayer::paintLayerContents(GraphicsContext* context, const LayerPainti ...@@ -1755,7 +1755,7 @@ void RenderLayer::paintLayerContents(GraphicsContext* context, const LayerPainti
resourceClipper = toRenderSVGResourceClipper(toRenderSVGResourceContainer(element->renderer())); resourceClipper = toRenderSVGResourceClipper(toRenderSVGResourceContainer(element->renderer()));
if (!resourceClipper->applyClippingToContext(renderer(), rootRelativeBounds, if (!resourceClipper->applyClippingToContext(renderer(), rootRelativeBounds,
paintingInfo.paintDirtyRect, context, clipperContext)) { paintingInfo.paintDirtyRect, context, clipperState)) {
// No need to post-apply the clipper if this failed. // No need to post-apply the clipper if this failed.
resourceClipper = 0; resourceClipper = 0;
} }
...@@ -1908,7 +1908,7 @@ void RenderLayer::paintLayerContents(GraphicsContext* context, const LayerPainti ...@@ -1908,7 +1908,7 @@ void RenderLayer::paintLayerContents(GraphicsContext* context, const LayerPainti
} }
if (resourceClipper) if (resourceClipper)
resourceClipper->postApplyStatefulResource(renderer(), context, clipperContext); resourceClipper->postApplyStatefulResource(renderer(), context, clipperState);
} }
void RenderLayer::paintLayerByApplyingTransform(GraphicsContext* context, const LayerPaintingInfo& paintingInfo, PaintLayerFlags paintFlags, const LayoutPoint& translationOffset) void RenderLayer::paintLayerByApplyingTransform(GraphicsContext* context, const LayerPaintingInfo& paintingInfo, PaintLayerFlags paintFlags, const LayoutPoint& translationOffset)
......
...@@ -73,14 +73,14 @@ bool RenderSVGResourceClipper::applyResource(RenderObject*, RenderStyle*, Graphi ...@@ -73,14 +73,14 @@ bool RenderSVGResourceClipper::applyResource(RenderObject*, RenderStyle*, Graphi
return false; return false;
} }
bool RenderSVGResourceClipper::applyStatefulResource(RenderObject* object, GraphicsContext*& context, ClipperContext& clipperContext) bool RenderSVGResourceClipper::applyStatefulResource(RenderObject* object, GraphicsContext*& context, ClipperState& clipperState)
{ {
ASSERT(object); ASSERT(object);
ASSERT(context); ASSERT(context);
clearInvalidationMask(); clearInvalidationMask();
return applyClippingToContext(object, object->objectBoundingBox(), object->paintInvalidationRectInLocalCoordinates(), context, clipperContext); return applyClippingToContext(object, object->objectBoundingBox(), object->paintInvalidationRectInLocalCoordinates(), context, clipperState);
} }
bool RenderSVGResourceClipper::tryPathOnlyClipping(GraphicsContext* context, bool RenderSVGResourceClipper::tryPathOnlyClipping(GraphicsContext* context,
...@@ -147,11 +147,11 @@ bool RenderSVGResourceClipper::tryPathOnlyClipping(GraphicsContext* context, ...@@ -147,11 +147,11 @@ bool RenderSVGResourceClipper::tryPathOnlyClipping(GraphicsContext* context,
} }
bool RenderSVGResourceClipper::applyClippingToContext(RenderObject* target, const FloatRect& targetBoundingBox, bool RenderSVGResourceClipper::applyClippingToContext(RenderObject* target, const FloatRect& targetBoundingBox,
const FloatRect& paintInvalidationRect, GraphicsContext* context, ClipperContext& clipperContext) const FloatRect& paintInvalidationRect, GraphicsContext* context, ClipperState& clipperState)
{ {
ASSERT(target); ASSERT(target);
ASSERT(context); ASSERT(context);
ASSERT(clipperContext.state == ClipperContext::NotAppliedState); ASSERT(clipperState == ClipperNotApplied);
ASSERT_WITH_SECURITY_IMPLICATION(!needsLayout()); ASSERT_WITH_SECURITY_IMPLICATION(!needsLayout());
if (paintInvalidationRect.isEmpty() || m_inClipExpansion) if (paintInvalidationRect.isEmpty() || m_inClipExpansion)
...@@ -170,12 +170,12 @@ bool RenderSVGResourceClipper::applyClippingToContext(RenderObject* target, cons ...@@ -170,12 +170,12 @@ bool RenderSVGResourceClipper::applyClippingToContext(RenderObject* target, cons
// First, try to apply the clip as a clipPath. // First, try to apply the clip as a clipPath.
if (tryPathOnlyClipping(context, animatedLocalTransform, targetBoundingBox)) { if (tryPathOnlyClipping(context, animatedLocalTransform, targetBoundingBox)) {
clipperContext.state = ClipperContext::AppliedPathState; clipperState = ClipperAppliedPath;
return true; return true;
} }
// Fall back to masking. // Fall back to masking.
clipperContext.state = ClipperContext::AppliedMaskState; clipperState = ClipperAppliedMask;
// Mask layer start // Mask layer start
context->beginTransparencyLayer(1, &paintInvalidationRect); context->beginTransparencyLayer(1, &paintInvalidationRect);
...@@ -186,8 +186,8 @@ bool RenderSVGResourceClipper::applyClippingToContext(RenderObject* target, cons ...@@ -186,8 +186,8 @@ bool RenderSVGResourceClipper::applyClippingToContext(RenderObject* target, cons
// clipPath can also be clipped by another clipPath. // clipPath can also be clipped by another clipPath.
SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(this); SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(this);
RenderSVGResourceClipper* clipPathClipper = resources ? resources->clipper() : 0; RenderSVGResourceClipper* clipPathClipper = resources ? resources->clipper() : 0;
ClipperContext clipPathClipperContext; ClipperState clipPathClipperState = ClipperNotApplied;
if (clipPathClipper && !clipPathClipper->applyClippingToContext(this, targetBoundingBox, paintInvalidationRect, context, clipPathClipperContext)) { if (clipPathClipper && !clipPathClipper->applyClippingToContext(this, targetBoundingBox, paintInvalidationRect, context, clipPathClipperState)) {
// FIXME: Awkward state micro-management. Ideally, GraphicsContextStateSaver should // FIXME: Awkward state micro-management. Ideally, GraphicsContextStateSaver should
// a) pop saveLayers also // a) pop saveLayers also
// b) pop multiple states if needed (similarly to SkCanvas::restoreToCount()) // b) pop multiple states if needed (similarly to SkCanvas::restoreToCount())
...@@ -200,7 +200,7 @@ bool RenderSVGResourceClipper::applyClippingToContext(RenderObject* target, cons ...@@ -200,7 +200,7 @@ bool RenderSVGResourceClipper::applyClippingToContext(RenderObject* target, cons
drawClipMaskContent(context, targetBoundingBox); drawClipMaskContent(context, targetBoundingBox);
if (clipPathClipper) if (clipPathClipper)
clipPathClipper->postApplyStatefulResource(this, context, clipPathClipperContext); clipPathClipper->postApplyStatefulResource(this, context, clipPathClipperState);
} }
// Masked content layer start. // Masked content layer start.
...@@ -215,13 +215,13 @@ void RenderSVGResourceClipper::postApplyResource(RenderObject*, GraphicsContext* ...@@ -215,13 +215,13 @@ void RenderSVGResourceClipper::postApplyResource(RenderObject*, GraphicsContext*
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }
void RenderSVGResourceClipper::postApplyStatefulResource(RenderObject*, GraphicsContext*& context, ClipperContext& clipperContext) void RenderSVGResourceClipper::postApplyStatefulResource(RenderObject*, GraphicsContext*& context, ClipperState& clipperState)
{ {
switch (clipperContext.state) { switch (clipperState) {
case ClipperContext::AppliedPathState: case ClipperAppliedPath:
// Path-only clipping, no layers to restore. // Path-only clipping, no layers to restore.
break; break;
case ClipperContext::AppliedMaskState: case ClipperAppliedMask:
// Transfer content layer -> mask layer (SrcIn) // Transfer content layer -> mask layer (SrcIn)
context->endLayer(); context->endLayer();
// Transfer mask layer -> bg layer (SrcOver) // Transfer mask layer -> bg layer (SrcOver)
......
...@@ -27,21 +27,14 @@ namespace blink { ...@@ -27,21 +27,14 @@ namespace blink {
class DisplayList; class DisplayList;
struct ClipperContext {
WTF_MAKE_FAST_ALLOCATED;
public:
enum ClipperState { NotAppliedState, AppliedPathState, AppliedMaskState };
ClipperContext()
: state(NotAppliedState)
{
}
ClipperState state;
};
class RenderSVGResourceClipper FINAL : public RenderSVGResourceContainer { class RenderSVGResourceClipper FINAL : public RenderSVGResourceContainer {
public: public:
enum ClipperState {
ClipperNotApplied,
ClipperAppliedPath,
ClipperAppliedMask
};
explicit RenderSVGResourceClipper(SVGClipPathElement*); explicit RenderSVGResourceClipper(SVGClipPathElement*);
virtual ~RenderSVGResourceClipper(); virtual ~RenderSVGResourceClipper();
...@@ -56,13 +49,13 @@ public: ...@@ -56,13 +49,13 @@ public:
// FIXME: Filters are also stateful resources that could benefit from having their state managed // FIXME: Filters are also stateful resources that could benefit from having their state managed
// on the caller stack instead of the current hashmap. We should look at refactoring these // on the caller stack instead of the current hashmap. We should look at refactoring these
// into a general interface that can be shared. // into a general interface that can be shared.
bool applyStatefulResource(RenderObject*, GraphicsContext*&, ClipperContext&); bool applyStatefulResource(RenderObject*, GraphicsContext*&, ClipperState&);
void postApplyStatefulResource(RenderObject*, GraphicsContext*&, ClipperContext&); void postApplyStatefulResource(RenderObject*, GraphicsContext*&, ClipperState&);
// clipPath can be clipped too, but don't have a boundingBox or paintInvalidationRect. So we can't call // clipPath can be clipped too, but don't have a boundingBox or paintInvalidationRect. So we can't call
// applyResource directly and use the rects from the object, since they are empty for RenderSVGResources // applyResource directly and use the rects from the object, since they are empty for RenderSVGResources
// FIXME: We made applyClippingToContext public because we cannot call applyResource on HTML elements (it asserts on RenderObject::objectBoundingBox) // FIXME: We made applyClippingToContext public because we cannot call applyResource on HTML elements (it asserts on RenderObject::objectBoundingBox)
bool applyClippingToContext(RenderObject*, const FloatRect&, const FloatRect&, GraphicsContext*, ClipperContext&); bool applyClippingToContext(RenderObject*, const FloatRect&, const FloatRect&, GraphicsContext*, ClipperState&);
FloatRect resourceBoundingBox(const RenderObject*); FloatRect resourceBoundingBox(const RenderObject*);
......
...@@ -70,7 +70,7 @@ SVGRenderingContext::~SVGRenderingContext() ...@@ -70,7 +70,7 @@ SVGRenderingContext::~SVGRenderingContext()
if (m_clipper) { if (m_clipper) {
ASSERT(SVGResourcesCache::cachedResourcesForRenderObject(m_object)->clipper() == m_clipper); ASSERT(SVGResourcesCache::cachedResourcesForRenderObject(m_object)->clipper() == m_clipper);
m_clipper->postApplyStatefulResource(m_object, m_paintInfo->context, m_clipperContext); m_clipper->postApplyStatefulResource(m_object, m_paintInfo->context, m_clipperState);
} }
if (m_masker) { if (m_masker) {
...@@ -163,7 +163,7 @@ void SVGRenderingContext::prepareToRenderSVGContent(RenderObject* object, PaintI ...@@ -163,7 +163,7 @@ void SVGRenderingContext::prepareToRenderSVGContent(RenderObject* object, PaintI
RenderSVGResourceClipper* clipper = resources->clipper(); RenderSVGResourceClipper* clipper = resources->clipper();
if (!clipPathOperation && clipper) { if (!clipPathOperation && clipper) {
if (!clipper->applyStatefulResource(m_object, m_paintInfo->context, m_clipperContext)) if (!clipper->applyStatefulResource(m_object, m_paintInfo->context, m_clipperState))
return; return;
m_clipper = clipper; m_clipper = clipper;
m_renderingFlags |= PostApplyResources; m_renderingFlags |= PostApplyResources;
......
...@@ -53,6 +53,7 @@ public: ...@@ -53,6 +53,7 @@ public:
, m_savedContext(0) , m_savedContext(0)
, m_filter(0) , m_filter(0)
, m_clipper(0) , m_clipper(0)
, m_clipperState(RenderSVGResourceClipper::ClipperNotApplied)
, m_masker(0) , m_masker(0)
{ {
} }
...@@ -64,6 +65,7 @@ public: ...@@ -64,6 +65,7 @@ public:
, m_savedContext(0) , m_savedContext(0)
, m_filter(0) , m_filter(0)
, m_clipper(0) , m_clipper(0)
, m_clipperState(RenderSVGResourceClipper::ClipperNotApplied)
, m_masker(0) , m_masker(0)
{ {
prepareToRenderSVGContent(object, paintinfo, needsGraphicsContextSave); prepareToRenderSVGContent(object, paintinfo, needsGraphicsContextSave);
...@@ -111,7 +113,7 @@ private: ...@@ -111,7 +113,7 @@ private:
IntRect m_savedPaintRect; IntRect m_savedPaintRect;
RenderSVGResourceFilter* m_filter; RenderSVGResourceFilter* m_filter;
RenderSVGResourceClipper* m_clipper; RenderSVGResourceClipper* m_clipper;
ClipperContext m_clipperContext; RenderSVGResourceClipper::ClipperState m_clipperState;
RenderSVGResourceMasker* m_masker; RenderSVGResourceMasker* m_masker;
}; };
......
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