renderer: implements trimpath and artboard rendering
authorTaehyub Kim <taehyub.kim@samsung.com>
Tue, 30 Mar 2021 05:28:50 +0000 (14:28 +0900)
committerTaehyub Kim <taehyub.kim@samsung.com>
Wed, 31 Mar 2021 08:20:30 +0000 (17:20 +0900)
 - make trimpath and artboard render, trimpath and artboard is not initialized in addRenderPath.
   so implements buildShape function for initializing trimpath and artboard shape in the function.

src/renderer/tvg_renderer.cpp
src/renderer/tvg_renderer.hpp

index 0aab2c1748d56e39d9ffac64ea6f17e58da372ac..15fb08c2796cc47161f30dd43248a0d7dd1c834c 100644 (file)
@@ -47,6 +47,46 @@ void TvgRenderPath::reset()
    m_PathPoints.clear();
 }
 
+void TvgRenderPath::buildShape()
+{
+   int index = 0;
+   for (size_t i = 0; i < m_PathType.size(); i++)
+   {
+      switch(m_PathType[i])
+      {
+         case PathCommand::MoveTo:
+         {
+            m_Shape->moveTo(m_PathPoints[index][0], m_PathPoints[index][1]);
+            index += 1;
+            break;
+         }
+         case PathCommand::LineTo:
+         {
+            m_Shape->lineTo(m_PathPoints[index][0], m_PathPoints[index][1]);
+            index += 1;
+            break;
+         }
+         case PathCommand::CubicTo:
+         {
+            m_Shape->cubicTo(m_PathPoints[index][0], m_PathPoints[index][1],
+                             m_PathPoints[index + 1][0], m_PathPoints[index + 1][1],
+                             m_PathPoints[index + 2][0], m_PathPoints[index + 2][1]);
+            index += 3;
+            break;
+         }
+         case PathCommand::Close:
+         {
+            m_Shape->close();
+            index += 1;
+            break;
+         }
+      }
+   }
+
+   m_PathType.clear();
+   m_PathPoints.clear();
+}
+
 void TvgRenderPath::addRenderPath(RenderPath* path, const Mat2D& transform)
 {
    m_PathType = static_cast<TvgRenderPath*>(path)->m_PathType;
@@ -57,6 +97,10 @@ void TvgRenderPath::addRenderPath(RenderPath* path, const Mat2D& transform)
 
    /* OPTIMIZE ME: Should avoid data copy in loop... */
    int index = 0;
+
+   if (m_PathType.size() != 0)
+     shapeAdded = true;
+
    for (size_t i = 0; i < m_PathType.size(); i++)
    {
       /* OPTIMIZE ME: apply transform only when it's not identity */
@@ -276,6 +320,8 @@ void TvgRenderer::drawPath(RenderPath* path, RenderPaint* paint)
 
    /* OPTIMIZE ME: Stroke / Fill Paints required to draw separately.
       thorvg doesn't need to handle both, we can avoid one of them rendering... */
+   if (!renderPath->isShapeAdded())
+     renderPath->buildShape();
 
    if (tvgPaint->style == RenderPaintStyle::fill)
    {
index d3f8101d9172bf53ebc85fd787f9342538e4033c..a877b166a47017ee08a958bcba5430218f02c4ca 100644 (file)
@@ -30,6 +30,7 @@ namespace rive
       vector<PathCommand> m_PathType;
       vector<Vec2D> m_PathPoints;
       bool active = false;
+      bool shapeAdded = false;
 
    public:
       TvgRenderPath();
@@ -37,6 +38,8 @@ namespace rive
       Shape* shape() { return m_Shape; }
       bool onCanvas() { return active; }
       void onCanvas(bool active) { this->active = active; }
+      bool isShapeAdded() { return this->shapeAdded; }
+      void buildShape();
       void reset() override;
       void addRenderPath(RenderPath* path, const Mat2D& transform) override;
       void fillRule(FillRule value) override;