remove sneaked inserting unicodes, zero-width no-break space.
[platform/core/uifw/lottie-player.git] / src / vector / vraster.cpp
index 1c72f78..ff5133b 100644 (file)
@@ -1,4 +1,20 @@
-#include "vraster.h"
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "vraster.h"
 #include <cstring>
 #include <thread>
 #include "v_ft_raster.h"
@@ -237,19 +253,23 @@ static void rleGenerationCb(int count, const SW_FT_Span *spans, void *user)
     rle->addSpan(rleSpan, count);
 }
 
+static void bboxCb(int x, int y, int w, int h, void *user)
+{
+    VRle *      rle = (VRle *)user;
+    rle->setBoundingRect({x, y, w, h});
+}
+
 struct RleTask {
-    RleTask() { receiver = sender.get_future(); }
-    std::promise<VRle> sender;
-    std::future<VRle>  receiver;
-    bool               stroke;
+    RleShare           mRlePromise;
     VPath              path;
     VRle               rle;
-    FillRule           fillRule;
-    CapStyle           cap;
-    JoinStyle          join;
     float              width;
     float              meterLimit;
     VRect              clip;
+    FillRule           fillRule;
+    CapStyle           cap;
+    JoinStyle          join;
+    bool               stroke;
     VRle               operator()(FTOutline &outRef, SW_FT_Stroker &stroker);
     void               render(FTOutline &outRef);
 };
@@ -260,6 +280,7 @@ void RleTask::render(FTOutline &outRef)
 
     params.flags = SW_FT_RASTER_FLAG_DIRECT | SW_FT_RASTER_FLAG_AA;
     params.gray_spans = &rleGenerationCb;
+    params.bbox_cb = &bboxCb;
     params.user = &rle;
     params.source = &outRef.ft;
 
@@ -273,8 +294,6 @@ void RleTask::render(FTOutline &outRef)
     }
     // compute rle
     sw_ft_grays_raster.raster_render(nullptr, &params);
-    // update bounding box.
-    rle.boundingRect();
 }
 
 VRle RleTask::operator()(FTOutline &outRef, SW_FT_Stroker &stroker)
@@ -311,6 +330,8 @@ VRle RleTask::operator()(FTOutline &outRef, SW_FT_Stroker &stroker)
 
     render(outRef);
 
+    path = VPath();
+
     return std::move(rle);
 }
 
@@ -330,29 +351,38 @@ class RleTaskScheduler {
         SW_FT_Stroker_New(&stroker);
 
         // Task Loop
+        RleTask task;
         while (true) {
-            RleTask *task = nullptr;
+            bool success = false;
 
             for (unsigned n = 0; n != _count * 32; ++n) {
-                if (_q[(i + n) % _count].try_pop(task)) break;
+                if (_q[(i + n) % _count].try_pop(task)) {
+                    success = true;
+                    break;
+                }
             }
-            if (!task && !_q[i].pop(task)) break;
 
-            task->sender.set_value((*task)(outlineRef, stroker));
-            delete task;
+            if (!success && !_q[i].pop(task)) break;
+
+            task.mRlePromise->set_value((task)(outlineRef, stroker));
         }
 
         // cleanup
         SW_FT_Stroker_Done(stroker);
     }
 
-public:
     RleTaskScheduler()
     {
         for (unsigned n = 0; n != _count; ++n) {
             _threads.emplace_back([&, n] { run(n); });
         }
     }
+public:
+    static RleTaskScheduler& instance()
+    {
+         static RleTaskScheduler singleton;
+         return singleton;
+    }
 
     ~RleTaskScheduler()
     {
@@ -361,70 +391,67 @@ public:
         for (auto &e : _threads) e.join();
     }
 
-    std::future<VRle> async(RleTask *task)
+    void async(RleTask &&task)
     {
-        auto receiver = std::move(task->receiver);
         auto i = _index++;
 
         for (unsigned n = 0; n != _count; ++n) {
-            if (_q[(i + n) % _count].try_push(task)) return receiver;
+            if (_q[(i + n) % _count].try_push(std::move(task))) return;
         }
 
-        _q[i % _count].push(task);
-
-        return receiver;
+        _q[i % _count].push(std::move(task));
     }
 
-    std::future<VRle> strokeRle(VPath &&path, VRle &&rle, CapStyle cap, JoinStyle join,
+    void strokeRle(RleShare &promise, VPath &&path, VRle &&rle, CapStyle cap, JoinStyle join,
                                 float width, float meterLimit, const VRect &clip)
     {
-        RleTask *task = new RleTask();
-        task->stroke = true;
-        task->path = std::move(path);
-        task->rle = std::move(rle);
-        task->cap = cap;
-        task->join = join;
-        task->width = width;
-        task->meterLimit = meterLimit;
-        task->clip = clip;
-        return async(task);
+        RleTask task;
+        task.stroke = true;
+        task.path = std::move(path);
+        task.rle = std::move(rle);
+        task.cap = cap;
+        task.join = join;
+        task.width = width;
+        task.meterLimit = meterLimit;
+        task.clip = clip;
+        task.mRlePromise = promise;
+
+        async(std::move(task));
     }
 
-    std::future<VRle> fillRle(VPath &&path, VRle &&rle, FillRule fillRule, const VRect &clip)
+    void fillRle(RleShare &promise, VPath &&path, VRle &&rle, FillRule fillRule, const VRect &clip)
     {
-        RleTask *task = new RleTask();
-        task->path = std::move(path);
-        task->rle = std::move(rle);
-        task->fillRule = fillRule;
-        task->clip = clip;
-        task->stroke = false;
-        return async(task);
+        RleTask task;
+        task.path = std::move(path);
+        task.rle = std::move(rle);
+        task.fillRule = fillRule;
+        task.clip = clip;
+        task.stroke = false;
+        task.mRlePromise = promise;
+
+        async(std::move(task));
     }
 };
 
-static RleTaskScheduler raster_scheduler;
-
-std::future<VRle> VRaster::generateFillInfo(VPath &&path, VRle &&rle,
-                                            FillRule     fillRule, const VRect &clip)
+void VRaster::generateFillInfo(RleShare &promise, VPath &&path, VRle &&rle,
+                                            FillRule fillRule, const VRect &clip)
 {
     if (path.empty()) {
-        std::promise<VRle> promise;
-        promise.set_value(VRle());
-        return promise.get_future();
+        promise->set_value(VRle());
+        return;
     }
-    return raster_scheduler.fillRle(std::move(path), std::move(rle), fillRule, clip);
+    return RleTaskScheduler::instance().fillRle(promise, std::move(path), std::move(rle), fillRule, clip);
 }
 
-std::future<VRle> VRaster::generateStrokeInfo(VPath &&path, VRle &&rle, CapStyle cap,
-                                              JoinStyle join, float width,
-                                              float meterLimit, const VRect &clip)
+void VRaster::generateStrokeInfo(RleShare &promise, VPath &&path, VRle &&rle, CapStyle cap,
+                                 JoinStyle join, float width,
+                                 float meterLimit, const VRect &clip)
 {
     if (path.empty()) {
-        std::promise<VRle> promise;
-        promise.set_value(VRle());
-        return promise.get_future();
+        promise->set_value(VRle());
+        return;
     }
-    return raster_scheduler.strokeRle(std::move(path), std::move(rle), cap, join, width, meterLimit, clip);
+    return RleTaskScheduler::instance().strokeRle(promise, std::move(path), std::move(rle), cap, join, width, meterLimit, clip);
 }
 
 V_END_NAMESPACE