Commit 9e33b03e authored by fs@opera.com's avatar fs@opera.com

Move painting code out of LayoutSVGResourceClipper

LayoutSVGResourceClipper::tryPathOnlyClipping contains the code to
emit the path - if one is successfully built. For the sake of layering,
push this out into the caller (SVGClipPainter) instead.

Also replace uses of clipperResource().isEmpty() with hasClipper(),
rename objectBoundingBox referenceBox (to better match the Masking spec
terminology) and rename the tryPathOnlyClipping to asPath.

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

git-svn-id: svn://svn.chromium.org/blink/trunk@201254 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent fc3b5f8e
......@@ -27,18 +27,10 @@
#include "core/dom/ElementTraversal.h"
#include "core/layout/HitTestResult.h"
#include "core/layout/svg/SVGLayoutSupport.h"
#include "core/layout/svg/SVGResources.h"
#include "core/layout/svg/SVGResourcesCache.h"
#include "core/paint/CompositingRecorder.h"
#include "core/paint/PaintInfo.h"
#include "core/paint/TransformRecorder.h"
#include "core/svg/SVGGeometryElement.h"
#include "core/svg/SVGUseElement.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "platform/graphics/paint/ClipPathDisplayItem.h"
#include "platform/graphics/paint/CompositingDisplayItem.h"
#include "platform/graphics/paint/DisplayItemList.h"
#include "platform/graphics/paint/DrawingDisplayItem.h"
#include "platform/graphics/paint/SkPictureBuilder.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/pathops/SkPathOps.h"
......@@ -68,13 +60,12 @@ void LayoutSVGResourceClipper::removeClientFromCache(LayoutObject* client, bool
markClientForInvalidation(client, markForInvalidation ? BoundariesInvalidation : ParentOnlyInvalidation);
}
bool LayoutSVGResourceClipper::tryPathOnlyClipping(const LayoutObject& layoutObject, GraphicsContext* context,
const AffineTransform& animatedLocalTransform, const FloatRect& objectBoundingBox) {
bool LayoutSVGResourceClipper::asPath(const AffineTransform& animatedLocalTransform,
const FloatRect& referenceBox, Path& clipPath) {
// If the current clip-path gets clipped itself, we have to fallback to masking.
if (!style()->svgStyle().clipperResource().isEmpty())
if (style()->svgStyle().hasClipper())
return false;
Path clipPath;
bool usingBuilder = false;
SkOpBuilder clipPathBuilder;
......@@ -93,7 +84,7 @@ bool LayoutSVGResourceClipper::tryPathOnlyClipping(const LayoutObject& layoutObj
continue;
const SVGComputedStyle& svgStyle = style->svgStyle();
// Current shape in clip-path gets clipped too. Fallback to masking.
if (!svgStyle.clipperResource().isEmpty())
if (svgStyle.hasClipper())
return false;
// First clip shape.
......@@ -135,22 +126,13 @@ bool LayoutSVGResourceClipper::tryPathOnlyClipping(const LayoutObject& layoutObj
// and transform the content to userspace if necessary.
if (clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
AffineTransform transform;
transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
transform.translate(referenceBox.x(), referenceBox.y());
transform.scaleNonUniform(referenceBox.width(), referenceBox.height());
clipPath.transform(transform);
}
// Transform path by animatedLocalTransform.
clipPath.transform(animatedLocalTransform);
if (RuntimeEnabledFeatures::slimmingPaintEnabled()) {
if (!context->displayItemList()->displayItemConstructionIsDisabled())
context->displayItemList()->createAndAppend<BeginClipPathDisplayItem>(layoutObject, clipPath);
} else {
BeginClipPathDisplayItem clipPathDisplayItem(layoutObject, clipPath);
clipPathDisplayItem.replay(*context);
}
return true;
}
......
......@@ -46,7 +46,7 @@ public:
SVGUnitTypes::SVGUnitType clipPathUnits() const { return toSVGClipPathElement(element())->clipPathUnits()->currentValue()->enumValue(); }
bool tryPathOnlyClipping(const LayoutObject&, GraphicsContext*, const AffineTransform&, const FloatRect&);
bool asPath(const AffineTransform&, const FloatRect& referenceBox, Path&);
PassRefPtr<const SkPicture> createContentPicture(AffineTransform&, const FloatRect&, GraphicsContext*);
bool hasCycle() { return m_inClipExpansion; }
......
......@@ -60,8 +60,16 @@ bool SVGClipPainter::applyClippingToContext(const LayoutObject& target, const Fl
}
// First, try to apply the clip as a clipPath.
if (m_clip.tryPathOnlyClipping(target, context, animatedLocalTransform, targetBoundingBox)) {
Path clipPath;
if (m_clip.asPath(animatedLocalTransform, targetBoundingBox, clipPath)) {
clipperState = ClipperAppliedPath;
if (RuntimeEnabledFeatures::slimmingPaintEnabled()) {
if (!context->displayItemList()->displayItemConstructionIsDisabled())
context->displayItemList()->createAndAppend<BeginClipPathDisplayItem>(target, clipPath);
} else {
BeginClipPathDisplayItem clipPathDisplayItem(target, clipPath);
clipPathDisplayItem.replay(*context);
}
return true;
}
......
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