Rename reset to rewind. In profiling Joel we saw that RawPath::reset was causing a lot of re-allocation. We realized the intention of reset in most of Rive code is to actually call rewind, so we renamed it and made other adjustments (like calling RawPath::rewind). Diffs= f4046e60b Rename reset to rewind. (#5004)
diff --git a/.rive_head b/.rive_head index 2250c19..418b068 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -c6caafc244be24e6f5472297dd6775b46c757e53 +f4046e60b12215a1627ce66fd7d367c0e8c1cdcc
diff --git a/include/rive/command_path.hpp b/include/rive/command_path.hpp index 3f77b15..324946e 100644 --- a/include/rive/command_path.hpp +++ b/include/rive/command_path.hpp
@@ -13,7 +13,7 @@ { public: virtual ~CommandPath() {} - virtual void reset() = 0; + virtual void rewind() = 0; virtual void fillRule(FillRule value) = 0; virtual void addPath(CommandPath* path, const Mat2D& transform) = 0;
diff --git a/include/rive/hittest_command_path.hpp b/include/rive/hittest_command_path.hpp index 4b9ca17..ea2b6d8 100644 --- a/include/rive/hittest_command_path.hpp +++ b/include/rive/hittest_command_path.hpp
@@ -28,7 +28,7 @@ bool wasHit(); // These 4 are not a good for the hit-tester - void reset() override; + void rewind() override; void fillRule(FillRule value) override; void addPath(CommandPath* path, const Mat2D& transform) override; RenderPath* renderPath() override;
diff --git a/include/rive/math/contour_measure.hpp b/include/rive/math/contour_measure.hpp index d7b00f6..67b27ef 100644 --- a/include/rive/math/contour_measure.hpp +++ b/include/rive/math/contour_measure.hpp
@@ -97,10 +97,10 @@ ContourMeasureIter(const RawPath& path, float tol = kDefaultTolerance) { - this->reset(path, tol); + this->rewind(path, tol); } - void reset(const RawPath&, float = kDefaultTolerance); + void rewind(const RawPath&, float = kDefaultTolerance); // Returns a measure object for each contour in the path // (contours with zero-length are skipped over)
diff --git a/include/rive/shapes/metrics_path.hpp b/include/rive/shapes/metrics_path.hpp index c8b8e16..b6798e8 100644 --- a/include/rive/shapes/metrics_path.hpp +++ b/include/rive/shapes/metrics_path.hpp
@@ -23,7 +23,7 @@ const std::vector<MetricsPath*>& paths() const { return m_Paths; } void addPath(CommandPath* path, const Mat2D& transform) override; - void reset() override; + void rewind() override; void moveTo(float x, float y) override; void lineTo(float x, float y) override; void cubicTo(float ox, float oy, float ix, float iy, float x, float y) override; @@ -64,7 +64,7 @@ void addPath(CommandPath* path, const Mat2D& transform) override; void fillRule(FillRule value) override; - void reset() override; + void rewind() override; void moveTo(float x, float y) override; void lineTo(float x, float y) override; void cubicTo(float ox, float oy, float ix, float iy, float x, float y) override;
diff --git a/include/rive/shapes/path_composer.hpp b/include/rive/shapes/path_composer.hpp index eac77cc..4475198 100644 --- a/include/rive/shapes/path_composer.hpp +++ b/include/rive/shapes/path_composer.hpp
@@ -12,11 +12,13 @@ Shape* m_Shape; std::unique_ptr<CommandPath> m_LocalPath; std::unique_ptr<CommandPath> m_WorldPath; + bool m_deferredPathDirt; public: PathComposer(Shape* shape); Shape* shape() const { return m_Shape; } void buildDependencies() override; + void onDirty(ComponentDirt dirt) override; void update(ComponentDirt value) override; CommandPath* localPath() const { return m_LocalPath.get(); }
diff --git a/include/rive/text/text_style.hpp b/include/rive/text/text_style.hpp index 20521c8..05f950b 100644 --- a/include/rive/text/text_style.hpp +++ b/include/rive/text/text_style.hpp
@@ -27,7 +27,7 @@ StatusCode import(ImportStack& importStack) override; bool addPath(const RawPath& rawPath); - void resetPath(); + void rewindPath(); void draw(Renderer* renderer); Core* clone() const override;
diff --git a/skia/renderer/src/cg_factory.cpp b/skia/renderer/src/cg_factory.cpp index f776e4f..cefbf3b 100644 --- a/skia/renderer/src/cg_factory.cpp +++ b/skia/renderer/src/cg_factory.cpp
@@ -144,7 +144,7 @@ return isStroke ? CGPathDrawingMode::kCGPathStroke : m_fillMode; } - void reset() override { m_path.reset(CGPathCreateMutable()); } + void rewind() override { m_path.reset(CGPathCreateMutable()); } void addRenderPath(RenderPath* path, const Mat2D& mx) override { auto transform = convert(mx);
diff --git a/skia/renderer/src/skia_factory.cpp b/skia/renderer/src/skia_factory.cpp index 8dd3f04..74a4970 100644 --- a/skia/renderer/src/skia_factory.cpp +++ b/skia/renderer/src/skia_factory.cpp
@@ -35,7 +35,7 @@ const SkPath& path() const { return m_Path; } - void reset() override; + void rewind() override; void addRenderPath(RenderPath* path, const Mat2D& transform) override; void fillRule(FillRule value) override; void moveTo(float x, float y) override; @@ -85,7 +85,7 @@ void SkiaRenderPath::fillRule(FillRule value) { m_Path.setFillType(ToSkia::convert(value)); } -void SkiaRenderPath::reset() { m_Path.reset(); } +void SkiaRenderPath::rewind() { m_Path.rewind(); } void SkiaRenderPath::addRenderPath(RenderPath* path, const Mat2D& transform) { m_Path.addPath(static_cast<SkiaRenderPath*>(path)->m_Path, ToSkia::convert(transform));
diff --git a/src/hittest_command_path.cpp b/src/hittest_command_path.cpp index 94fe025..27c42bf 100644 --- a/src/hittest_command_path.cpp +++ b/src/hittest_command_path.cpp
@@ -10,7 +10,7 @@ bool HitTestCommandPath::wasHit() { return m_Tester.test(m_FillRule); } -void HitTestCommandPath::reset() { m_Tester.reset(m_Area); } +void HitTestCommandPath::rewind() { m_Tester.reset(m_Area); } void HitTestCommandPath::fillRule(FillRule value) {
diff --git a/src/math/contour_measure.cpp b/src/math/contour_measure.cpp index 44968c4..3196356 100644 --- a/src/math/contour_measure.cpp +++ b/src/math/contour_measure.cpp
@@ -368,7 +368,7 @@ return distance; } -void ContourMeasureIter::reset(const RawPath& path, float tolerance) +void ContourMeasureIter::rewind(const RawPath& path, float tolerance) { m_iter = path.begin(); m_end = path.end();
diff --git a/src/shapes/clipping_shape.cpp b/src/shapes/clipping_shape.cpp index 558e322..5451b92 100644 --- a/src/shapes/clipping_shape.cpp +++ b/src/shapes/clipping_shape.cpp
@@ -98,7 +98,7 @@ { if (m_RenderPath) { - m_RenderPath->reset(); + m_RenderPath->rewind(); m_RenderPath->fillRule((FillRule)fillRule()); m_ClipRenderPath = nullptr;
diff --git a/src/shapes/metrics_path.cpp b/src/shapes/metrics_path.cpp index f93796b..8031a6d 100644 --- a/src/shapes/metrics_path.cpp +++ b/src/shapes/metrics_path.cpp
@@ -7,11 +7,11 @@ using namespace rive; -void MetricsPath::reset() +void MetricsPath::rewind() { m_Paths.clear(); m_Contour.reset(nullptr); - m_RawPath = RawPath(); + m_RawPath.rewind(); m_ComputedLengthTransform = Mat2D(); m_ComputedLength = 0; } @@ -84,10 +84,10 @@ m_RenderPath->addPath(path->renderPath(), transform); } -void RenderMetricsPath::reset() +void RenderMetricsPath::rewind() { - MetricsPath::reset(); - m_RenderPath->reset(); + MetricsPath::rewind(); + m_RenderPath->rewind(); } void RenderMetricsPath::moveTo(float x, float y)
diff --git a/src/shapes/paint/trim_path.cpp b/src/shapes/paint/trim_path.cpp index 32c5d01..d099330 100644 --- a/src/shapes/paint/trim_path.cpp +++ b/src/shapes/paint/trim_path.cpp
@@ -33,7 +33,7 @@ } else { - m_TrimmedPath->reset(); + m_TrimmedPath->rewind(); } auto renderOffset = std::fmod(std::fmod(offset(), 1.0f) + 1.0f, 1.0f);
diff --git a/src/shapes/path.cpp b/src/shapes/path.cpp index 902980a..3732d07 100644 --- a/src/shapes/path.cpp +++ b/src/shapes/path.cpp
@@ -241,10 +241,10 @@ assert(m_CommandPath != nullptr); if (hasDirt(value, ComponentDirt::Path)) { - // Build path doesn't explicitly reset because we use it to concatenate + // Build path doesn't explicitly rewind because we use it to concatenate // multiple built paths into a single command path (like the hit // tester). - m_CommandPath->reset(); + m_CommandPath->rewind(); buildPath(*m_CommandPath); } // if (hasDirt(value, ComponentDirt::WorldTransform) && m_Shape != nullptr)
diff --git a/src/shapes/path_composer.cpp b/src/shapes/path_composer.cpp index e10373e..a9c93d0 100644 --- a/src/shapes/path_composer.cpp +++ b/src/shapes/path_composer.cpp
@@ -8,7 +8,7 @@ static Mat2D identity; -PathComposer::PathComposer(Shape* shape) : m_Shape(shape) {} +PathComposer::PathComposer(Shape* shape) : m_Shape(shape), m_deferredPathDirt(false) {} void PathComposer::buildDependencies() { @@ -20,11 +20,26 @@ } } +void PathComposer::onDirty(ComponentDirt dirt) +{ + if (m_deferredPathDirt) + { + addDirt(ComponentDirt::Path); + } +} + void PathComposer::update(ComponentDirt value) { if (hasDirt(value, ComponentDirt::Path)) { auto space = m_Shape->pathSpace(); + if (m_Shape->renderOpacity() == 0 && (space & PathSpace::Clipping) != PathSpace::Clipping) + { + m_deferredPathDirt = true; + return; + } + m_deferredPathDirt = false; + if ((space & PathSpace::Local) == PathSpace::Local) { if (m_LocalPath == nullptr) @@ -33,7 +48,7 @@ } else { - m_LocalPath->reset(); + m_LocalPath->rewind(); } auto world = m_Shape->worldTransform(); Mat2D inverseWorld = world.invertOrIdentity(); @@ -52,7 +67,7 @@ } else { - m_WorldPath->reset(); + m_WorldPath->rewind(); } for (auto path : m_Shape->paths()) {
diff --git a/src/text/text.cpp b/src/text/text.cpp index bd8532d..af87a78 100644 --- a/src/text/text.cpp +++ b/src/text/text.cpp
@@ -72,7 +72,7 @@ { for (TextStyle* style : m_renderStyles) { - style->resetPath(); + style->rewindPath(); } m_renderStyles.clear();
diff --git a/src/text/text_style.cpp b/src/text/text_style.cpp index 860b5bb..bb0b90b 100644 --- a/src/text/text_style.cpp +++ b/src/text/text_style.cpp
@@ -19,9 +19,9 @@ m_path = factory->makeEmptyRenderPath(); } -void TextStyle::resetPath() +void TextStyle::rewindPath() { - m_path->reset(); + m_path->rewind(); m_hasContents = false; }
diff --git a/tess/include/rive/tess/tess_render_path.hpp b/tess/include/rive/tess/tess_render_path.hpp index 426e7f2..3e97bad 100644 --- a/tess/include/rive/tess/tess_render_path.hpp +++ b/tess/include/rive/tess/tess_render_path.hpp
@@ -43,7 +43,7 @@ TessRenderPath(); TessRenderPath(RawPath&, FillRule); ~TessRenderPath(); - void reset() override; + void rewind() override; void fillRule(FillRule value) override; bool empty() const;
diff --git a/tess/src/sokol/sokol_factory.cpp b/tess/src/sokol/sokol_factory.cpp index 0b990dc..51b0192 100644 --- a/tess/src/sokol/sokol_factory.cpp +++ b/tess/src/sokol/sokol_factory.cpp
@@ -18,7 +18,7 @@ class NoOpRenderPath : public RenderPath { public: - void reset() override {} + void rewind() override {} void fillRule(FillRule value) override {} void addPath(CommandPath* path, const Mat2D& transform) override {}
diff --git a/tess/src/sokol/sokol_tess_renderer.cpp b/tess/src/sokol/sokol_tess_renderer.cpp index 5078ec1..cb8305a 100644 --- a/tess/src/sokol/sokol_tess_renderer.cpp +++ b/tess/src/sokol/sokol_tess_renderer.cpp
@@ -53,9 +53,9 @@ } public: - void reset() override + void rewind() override { - TessRenderPath::reset(); + TessRenderPath::rewind(); m_vertices.clear(); m_indices.clear(); }
diff --git a/tess/src/tess_render_path.cpp b/tess/src/tess_render_path.cpp index 60d2fe6..2252b5e 100644 --- a/tess/src/tess_render_path.cpp +++ b/tess/src/tess_render_path.cpp
@@ -14,7 +14,7 @@ TessRenderPath::~TessRenderPath() {} -void TessRenderPath::reset() +void TessRenderPath::rewind() { m_rawPath.rewind(); m_subPaths.clear();
diff --git a/test/clip_test.cpp b/test/clip_test.cpp index 9185294..79e7fcc 100644 --- a/test/clip_test.cpp +++ b/test/clip_test.cpp
@@ -33,7 +33,7 @@ rive::RawPath rawPath; ClipTestRenderPath(rive::RawPath& path) : rawPath(path) {} - void reset() override {} + void rewind() override {} void fillRule(rive::FillRule value) override {} void addPath(rive::CommandPath* path, const rive::Mat2D& transform) override {}
diff --git a/test/contour_measure_test.cpp b/test/contour_measure_test.cpp index e42f760..a52f1b6 100644 --- a/test/contour_measure_test.cpp +++ b/test/contour_measure_test.cpp
@@ -43,11 +43,11 @@ REQUIRE(iter.next() == nullptr); path.moveTo(1, 2); - iter.reset(path, false); + iter.rewind(path, false); REQUIRE(iter.next() == nullptr); path.lineTo(4, 6); - iter.reset(path, false); + iter.rewind(path, false); auto cm = iter.next(); REQUIRE(cm); REQUIRE(nearly_eq(cm->length(), 5, tol)); @@ -58,7 +58,7 @@ path = RawPath(); const float w = 4, h = 6; path.addRect({0, 0, w, h}, PathDirection::cw); - iter.reset(path, false); + iter.rewind(path, false); cm = iter.next(); REQUIRE(cm); REQUIRE(nearly_eq(cm->length(), 2 * (w + h), tol));
diff --git a/test/path_test.cpp b/test/path_test.cpp index bfc6a33..38bbf20 100644 --- a/test/path_test.cpp +++ b/test/path_test.cpp
@@ -39,7 +39,7 @@ { public: std::vector<TestPathCommand> commands; - void reset() override + void rewind() override { commands.emplace_back( TestPathCommand{TestPathCommandType::Reset, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}); @@ -143,7 +143,7 @@ auto path = static_cast<TestRenderPath*>(rectangle->commandPath()); - // reset + // rewind // moveTo // cubic - for 1st corner @@ -204,7 +204,7 @@ auto path = static_cast<TestRenderPath*>(ellipse->commandPath()); - // reset + // rewind // moveTo // cubic - for 1st corner
diff --git a/utils/no_op_factory.cpp b/utils/no_op_factory.cpp index 2178aba..b0cb285 100644 --- a/utils/no_op_factory.cpp +++ b/utils/no_op_factory.cpp
@@ -26,7 +26,7 @@ class NoOpRenderPath : public RenderPath { public: - void reset() override {} + void rewind() override {} void fillRule(FillRule value) override {} void addPath(CommandPath* path, const Mat2D& transform) override {}