#include "SkCanvas.h"
#include "SkMatrix.h"
+#include "SkPathOps.h"
#include "SkSVGNode.h"
#include "SkSVGRenderContext.h"
#include "SkSVGValue.h"
SkPath SkSVGNode::asPath(const SkSVGRenderContext& ctx) const {
SkSVGRenderContext localContext(ctx);
- return this->onPrepareToRender(&localContext) ? this->onAsPath(localContext) : SkPath();
+ if (!this->onPrepareToRender(&localContext)) {
+ return SkPath();
+ }
+
+ SkPath path = this->onAsPath(localContext);
+
+ if (const auto* clipPath = localContext.clipPath()) {
+ // There is a clip-path present on the current node.
+ Op(path, *clipPath, kIntersect_SkPathOp, &path);
+ }
+
+ return path;
}
bool SkSVGNode::onPrepareToRender(SkSVGRenderContext* ctx) const {
const SkPath clipPath = clipNode->asPath(*this);
+ // We use the computed clip path in two ways:
+ //
+ // - apply to the current canvas, for drawing
+ // - track in the presentation context, for asPath() composition
+ //
+ // TODO: the two uses are exclusive, avoid canvas churn when non needed.
+
// Only save if needed
if (fCanvas->getSaveCount() == fCanvasSaveCount) {
fCanvas->save();
}
fCanvas->clipPath(clipPath, true);
+ fClipPath.set(clipPath);
}
const SkPaint* SkSVGRenderContext::fillPaint() const {
#define SkSVGRenderContext_DEFINED
#include "SkPaint.h"
+#include "SkPath.h"
#include "SkRect.h"
#include "SkSize.h"
#include "SkSVGAttribute.h"
const SkPaint* fillPaint() const;
const SkPaint* strokePaint() const;
+ // The local computed clip path (not inherited).
+ const SkPath* clipPath() const { return fClipPath.getMaybeNull(); }
+
private:
// Stack-only
void* operator new(size_t) = delete;
// The save count on 'fCanvas' at construction time.
// A restoreToCount() will be issued on destruction.
int fCanvasSaveCount;
+
+ // clipPath, if present for the current context (not inherited).
+ SkTLazy<SkPath> fClipPath;
};
#endif // SkSVGRenderContext_DEFINED