From: sub.mohanty@samsung.com Date: Wed, 19 Dec 2018 11:48:15 +0000 (+0900) Subject: lottie/render: Construct on first use of thread pool instance by moving into a single... X-Git-Tag: submit/tizen/20181226.015316~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d00a8fe714cf4fa30d76d907e47a49fc73cd3925;p=platform%2Fcore%2Fuifw%2Flottie-player.git lottie/render: Construct on first use of thread pool instance by moving into a singleton instance() api. Starting in C++11, scoped static initialization is now thread-safe Change-Id: Ia6933b439407e9dd635be67328eb750acf5b0367 --- diff --git a/src/lottie/lottieanimation.cpp b/src/lottie/lottieanimation.cpp index 5ba030b..1f09922 100644 --- a/src/lottie/lottieanimation.cpp +++ b/src/lottie/lottieanimation.cpp @@ -120,7 +120,6 @@ class RenderTaskScheduler { } } -public: RenderTaskScheduler() { for (unsigned n = 0; n != _count; ++n) { @@ -128,6 +127,13 @@ public: } } +public: + static RenderTaskScheduler& instance() + { + static RenderTaskScheduler singleton; + return singleton; + } + ~RenderTaskScheduler() { for (auto &e : _q) e.done(); @@ -159,7 +165,6 @@ public: return async(std::move(task)); } }; -static RenderTaskScheduler render_scheduler; /** * \breif Brief abput the Api. @@ -236,7 +241,7 @@ Animation::renderTree(size_t frameNo, size_t width, size_t height) const std::future Animation::render(size_t frameNo, Surface surface) { - return render_scheduler.render(d.get(), frameNo, std::move(surface)); + return RenderTaskScheduler::instance().render(d.get(), frameNo, std::move(surface)); } void Animation::renderSync(size_t frameNo, Surface surface) diff --git a/src/vector/vraster.cpp b/src/vector/vraster.cpp index 25185c3..91476d5 100644 --- a/src/vector/vraster.cpp +++ b/src/vector/vraster.cpp @@ -355,13 +355,18 @@ class RleTaskScheduler { 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() { @@ -412,8 +417,6 @@ public: } }; -static RleTaskScheduler raster_scheduler; - void VRaster::generateFillInfo(RleShare &promise, VPath &&path, VRle &&rle, FillRule fillRule, const VRect &clip) { @@ -421,7 +424,7 @@ void VRaster::generateFillInfo(RleShare &promise, VPath &&path, VRle &&rle, promise->set_value(VRle()); return; } - return raster_scheduler.fillRle(promise, std::move(path), std::move(rle), fillRule, clip); + return RleTaskScheduler::instance().fillRle(promise, std::move(path), std::move(rle), fillRule, clip); } void VRaster::generateStrokeInfo(RleShare &promise, VPath &&path, VRle &&rle, CapStyle cap, @@ -432,7 +435,7 @@ void VRaster::generateStrokeInfo(RleShare &promise, VPath &&path, VRle &&rle, Ca promise->set_value(VRle()); return; } - return raster_scheduler.strokeRle(promise, 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