[svg] Add current node to render context
A couple of render-time decisions require knowledge of object bounding
boxes, such as gradients (whose default coordinate space is
"objectBoundingBox". This CL adds the current node being rendered to the
render context so that it can be accessed down-stack (for example, when
gradients are being resolved and added to the paint as Skia shaders).
Each node will overload the bounds computation, for now it just returns
empty bounds for all nodes. TBD if we want to cache bounds somewhere,
either inside the node object or in a separate cache.
Bug: skia:10842
Change-Id: I40061ffedcb840e4dd28dba6351421f5b4fc904b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/329221
Commit-Queue: Tyler Denniston <tdenniston@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
diff --git a/modules/svg/src/SkSVGNode.cpp b/modules/svg/src/SkSVGNode.cpp
index ce05aa5..cf12945 100644
--- a/modules/svg/src/SkSVGNode.cpp
+++ b/modules/svg/src/SkSVGNode.cpp
@@ -19,7 +19,7 @@
SkSVGNode::~SkSVGNode() { }
void SkSVGNode::render(const SkSVGRenderContext& ctx) const {
- SkSVGRenderContext localContext(ctx);
+ SkSVGRenderContext localContext(ctx, this);
if (this->onPrepareToRender(&localContext)) {
this->onRender(localContext);
@@ -48,6 +48,10 @@
return path;
}
+SkRect SkSVGNode::objectBoundingBox(const SkSVGLengthContext& lctx) const {
+ return this->onObjectBoundingBox(lctx);
+}
+
bool SkSVGNode::onPrepareToRender(SkSVGRenderContext* ctx) const {
ctx->applyPresentationAttributes(fPresentationAttributes,
this->hasChildren() ? 0 : SkSVGRenderContext::kLeaf);