vector/rle: added operator&=() api to VRle
authorsubhransu mohanty <sub.mohanty@samsung.com>
Thu, 19 Sep 2019 07:45:45 +0000 (16:45 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Sun, 22 Sep 2019 21:53:45 +0000 (06:53 +0900)
src/vector/vrle.cpp
src/vector/vrle.h

index d56710d..5f165df 100644 (file)
@@ -728,4 +728,26 @@ VRle VRle::toRle(const VRect &rect)
     return result;
 }
 
+/*
+ * this api makes use of thread_local temporary
+ * buffer to avoid creating intermediate temporary rle buffer
+ * the scratch buffer object will grow its size on demand
+ * so that future call won't need any more memory allocation.
+ * this function is thread safe as it uses thread_local variable
+ * which is unique per thread.
+ */
+static thread_local VRle::VRleData Scratch_Object;
+
+void VRle::operator&=(const VRle &o)
+{
+    if (empty()) return;
+    if (o.empty()) {
+        reset();
+        return;
+    }
+    Scratch_Object.reset();
+    Scratch_Object.opIntersect(d.read(), o.d.read());
+    d.write() = Scratch_Object;
+}
+
 V_END_NAMESPACE
index 6ba92d6..80cb300 100644 (file)
@@ -51,6 +51,7 @@ public:
     void intersect(const VRect &r, VRleSpanCb cb, void *userData) const;
     void intersect(const VRle &rle, VRleSpanCb cb, void *userData) const;
 
+    void operator&=(const VRle &o);
     VRle operator&(const VRle &o) const;
     VRle operator-(const VRle &o) const;
     VRle operator+(const VRle &o) const;
@@ -62,7 +63,7 @@ public:
     size_t refCount() const { return d.refCount();}
     void clone(const VRle &o);
 
-private:
+public:
     struct VRleData {
         enum class OpCode {
             Add,
@@ -88,6 +89,7 @@ private:
         mutable VRect           mBbox;
         mutable bool            mBboxDirty = true;
     };
+private:
     friend void opIntersectHelper(const VRle::VRleData &obj1,
                                   const VRle::VRleData &obj2,
                                   VRle::VRleSpanCb cb, void *userData);