-#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"
}
struct RleTask {
- std::promise<VRle> sender;
+ RleShare mRlePromise;
VPath path;
VRle rle;
float width;
if (!success && !_q[i].pop(task)) break;
- task.sender.set_value((task)(outlineRef, stroker));
+ 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()
{
for (auto &e : _threads) e.join();
}
- std::future<VRle> async(RleTask &&task)
+ void async(RleTask &&task)
{
- auto receiver = std::move(task.sender.get_future());
auto i = _index++;
for (unsigned n = 0; n != _count; ++n) {
- if (_q[(i + n) % _count].try_push(std::move(task))) return receiver;
+ if (_q[(i + n) % _count].try_push(std::move(task))) return;
}
_q[i % _count].push(std::move(task));
-
- return receiver;
}
- 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;
task.width = width;
task.meterLimit = meterLimit;
task.clip = clip;
- return async(std::move(task));
+ 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;
task.path = std::move(path);
task.fillRule = fillRule;
task.clip = clip;
task.stroke = false;
- return async(std::move(task));
+ 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