mirror of
https://github.com/rive-app/rive-ios.git
synced 2026-01-18 17:11:28 +01:00
Add RenderPath::addRawPath
Addresses this issue: https://2dimensions.slack.com/archives/C07VD44ASE5/p1739456802968219 Rive's RenderPath steals the memory for the RawPath the runtime builds, which is usually fine apart from cases where we expect to use the RawPath after drawing with it. For example, with inner feather we want to be able to compute the bounds of the RawPath after it has been drawn. If during animation a user turns on inner feathering on a path which has not changed recently, which need to be able to compute its bounds, we can't if the RawPath is now gone. This also can happen with trim paths and dash paths which are re-trimmed/dashed after having being rendered a few frames. Right now we force rebuild the whole path to re-trim it because we lose the RawPath. This PR allows the ShapePaintPath to hold on to its RawPath by adding RenderPath::addRawPath. This is optimized memory usage but not having the runtime need to re-alloc the RawPath whenever it animates, but it means we're further from making RenderPaths immutable. For the future: It'd be good to chat about a long term solution that can accommodate all goals of allocating less memory (prior to this change we were re-allocating RawPath memory every frame when animating), not rebuilding paths as often, and still allow for immutability. Diffs= 9058a3fdad Add RenderPath::addRawPath (#9038) Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
This commit is contained in:
@@ -1 +1 @@
|
||||
7a6019fb974ed415d8531980b0b1516ff9f095c8
|
||||
9058a3fdad2444ca9eab3ef06bc49376eadba9de
|
||||
|
||||
@@ -188,6 +188,47 @@ void CoreGraphicsRenderPath::rewind()
|
||||
path = CGPathCreateMutable();
|
||||
}
|
||||
|
||||
void CoreGraphicsRenderPath::addRawPath(const RawPath& rawPath)
|
||||
{
|
||||
auto pts = rawPath.points();
|
||||
auto vbs = rawPath.verbs();
|
||||
auto p = pts.data();
|
||||
for (auto v : vbs)
|
||||
{
|
||||
switch ((PathVerb)v)
|
||||
{
|
||||
case PathVerb::move:
|
||||
CGPathMoveToPoint(path, nullptr, p[0].x, p[0].y);
|
||||
p += 1;
|
||||
break;
|
||||
case PathVerb::line:
|
||||
CGPathAddLineToPoint(path, nullptr, p[0].x, p[0].y);
|
||||
p += 1;
|
||||
break;
|
||||
case PathVerb::quad:
|
||||
CGPathAddQuadCurveToPoint(
|
||||
path, nullptr, p[0].x, p[0].y, p[1].x, p[1].y);
|
||||
p += 2;
|
||||
break;
|
||||
case PathVerb::cubic:
|
||||
CGPathAddCurveToPoint(path,
|
||||
nullptr,
|
||||
p[0].x,
|
||||
p[0].y,
|
||||
p[1].x,
|
||||
p[1].y,
|
||||
p[2].x,
|
||||
p[2].y);
|
||||
p += 3;
|
||||
break;
|
||||
case PathVerb::close:
|
||||
CGPathCloseSubpath(path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(p == pts.end());
|
||||
}
|
||||
|
||||
void CoreGraphicsRenderPath::addRenderPath(RenderPath* path,
|
||||
const Mat2D& transform)
|
||||
{
|
||||
|
||||
@@ -140,6 +140,7 @@ public:
|
||||
FillRule getFillRule() { return m_FillRule; }
|
||||
|
||||
void rewind() override;
|
||||
void addRawPath(const RawPath& path) override;
|
||||
void addRenderPath(RenderPath* path, const Mat2D& transform) override;
|
||||
void fillRule(FillRule value) override;
|
||||
void moveTo(float x, float y) override;
|
||||
|
||||
Submodule submodules/rive-runtime updated: e5ede9c6a3...7f971fba3c
Reference in New Issue
Block a user