Dasher: Fixed crash when dash array contains ZERO length segments or ZERO gap segments
authorsubhransu mohanty <sub.mohanty@samsung.com>
Tue, 30 Jul 2019 00:44:35 +0000 (09:44 +0900)
committerHermet Park <hermetpark@gmail.com>
Fri, 9 Aug 2019 08:54:26 +0000 (17:54 +0900)
src/vector/vdasher.cpp
src/vector/vdasher.h
src/vector/vdrawable.cpp

index a6ca9ab..121a250 100644 (file)
@@ -33,6 +33,15 @@ VDasher::VDasher(const float *dashArray, size_t size)
     mIndex = 0;
     mCurrentLength = 0;
     mDiscard = false;
+    //if the dash array contains ZERO length
+    // segments or ZERO lengths gaps we could
+    // optimize those usecase.
+    for (size_t i = 0; i < mArraySize; i++) {
+        if (!vCompare(mDashArray->length, 0.0f))
+            mNoLength = false;
+        if (!vCompare(mDashArray->gap, 0.0f))
+            mNoGap = false;
+    }
 }
 
 void VDasher::moveTo(const VPointF &p)
@@ -178,7 +187,8 @@ void VDasher::cubicTo(const VPointF &cp1, const VPointF &cp2, const VPointF &e)
 
 VPath VDasher::dashed(const VPath &path)
 {
-    if (path.empty()) return VPath();
+    if (path.empty() || mNoLength) return VPath();
+    if (mNoGap) return path;
 
     mResult = {};
     mResult.reserve(path.points().size(), path.elements().size());
index 224a2a8..81ce197 100644 (file)
@@ -46,10 +46,12 @@ private:
     VPointF              mCurPt;
     size_t               mIndex{0}; /* index to the dash Array */
     float                mCurrentLength;
-    bool                 mDiscard;
     float                mDashOffset{0};
     VPath                mResult;
-    bool                 mStartNewSegment=true;
+    bool                 mDiscard{false};
+    bool                 mStartNewSegment{true};
+    bool                 mNoLength{true};
+    bool                 mNoGap{true};
 };
 
 V_END_NAMESPACE
index 946054f..af44032 100644 (file)
@@ -26,7 +26,7 @@ void VDrawable::preprocess(const VRect &clip)
         if (mStroke.enable) {
             if (mStroke.mDash.size()) {
                 VDasher dasher(mStroke.mDash.data(), mStroke.mDash.size());
-                mPath = dasher.dashed(mPath);
+                mPath.clone(dasher.dashed(mPath));
             }
             mRasterizer.rasterize(std::move(mPath), mStroke.cap, mStroke.join,
                                   mStroke.width, mStroke.meterLimit, clip);