X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fsvg%2Fsvg-rasterize-thread.h;h=c9c305b1da4411ae3dd6edff717a6080e55d03f6;hp=13d284b2e9f470d1b6c7f338e878f8199b3da3c3;hb=35a7fe4e9b45558b58e365c637e704e2a51a5212;hpb=b160bfa1f94722346e59a732961ee5f253a75b8d;ds=sidebyside diff --git a/dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h b/dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h index 13d284b..c9c305b 100644 --- a/dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h +++ b/dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h @@ -32,6 +32,7 @@ #include // INTERNAL INCLUDES +#include #include namespace Dali @@ -44,6 +45,7 @@ class SvgVisual; typedef IntrusivePtr SvgVisualPtr; class SvgTask; typedef IntrusivePtr SvgTaskPtr; +class SvgRasterizeManager; /** * The svg rasterizing tasks to be processed in the worker thread. @@ -75,6 +77,15 @@ public: virtual void Process() = 0; /** + * Whether the task is ready to process. + * @return True if the task is ready to process. + */ + virtual bool IsReady() + { + return true; + } + + /** * Whether the task has succeeded. * @return True if the task has succeeded. */ @@ -161,6 +172,12 @@ public: void Process() override; /** + * Whether the task is ready to process. + * @return True if the task is ready to process. + */ + bool IsReady() override; + + /** * Get the rasterization result. * @return The pixel data with the rasterized pixels. */ @@ -182,7 +199,52 @@ private: /** * The worker thread for SVG rasterization. */ -class SvgRasterizeThread : public Thread, Integration::Processor +class SvgRasterizeThread : public Thread +{ +public: + /** + * Constructor. + */ + SvgRasterizeThread(SvgRasterizeManager& svgRasterizeManager); + + /** + * Destructor. + */ + ~SvgRasterizeThread() override; + + /** + * @brief Request the thread to rasterizes the task. + * @return True if the request succeeds, otherwise false. + */ + bool RequestRasterize(); + +protected: + /** + * The entry function of the worker thread. + * It rasterizes the image. + */ + void Run() override; + +private: + // Undefined + SvgRasterizeThread(const SvgRasterizeThread& thread) = delete; + + // Undefined + SvgRasterizeThread& operator=(const SvgRasterizeThread& thread) = delete; + +private: + ConditionalWait mConditionalWait; + const Dali::LogFactoryInterface& mLogFactory; + SvgRasterizeManager& mSvgRasterizeManager; + bool mDestroyThread; + bool mIsThreadStarted; + bool mIsThreadIdle; +}; + +/** + * The manager for SVG rasterization. + */ +class SvgRasterizeManager : Integration::Processor { public: /** @@ -190,12 +252,12 @@ public: * * @param[in] trigger The trigger to wake up the main thread. */ - SvgRasterizeThread(); + SvgRasterizeManager(); /** - * Terminate the svg rasterize thread, join and delete. + * Destructor. */ - static void TerminateThread(SvgRasterizeThread*& thread); + ~SvgRasterizeManager() override; /** * Add a rasterization task into the waiting queue, called by main thread. @@ -225,7 +287,6 @@ public: */ void Process(bool postProcessor) override; -private: /** * Pop the next task out from the queue. * @@ -240,6 +301,7 @@ private: */ void AddCompletedTask(SvgTaskPtr task); +private: /** * Applies the rasterized image to material */ @@ -251,34 +313,59 @@ private: */ void UnregisterProcessor(); -protected: - /** - * Destructor. - */ - ~SvgRasterizeThread() override; - +private: /** - * The entry function of the worker thread. - * It fetches task from the Queue, rasterizes the image and apply to the renderer. + * @brief Helper class to keep the relation between SvgRasterizeThread and corresponding container */ - void Run() override; + class RasterizeHelper + { + public: + /** + * @brief Create an RasterizeHelper. + * + * @param[in] svgRasterizeManager Reference to the SvgRasterizeManager + */ + RasterizeHelper(SvgRasterizeManager& svgRasterizeManager); + + /** + * @brief Request the thread to rasterizes the task. + * @return True if the request succeeds, otherwise false. + */ + bool RequestRasterize(); + + public: + RasterizeHelper(const RasterizeHelper&) = delete; + RasterizeHelper& operator=(const RasterizeHelper&) = delete; + + RasterizeHelper(RasterizeHelper&& rhs); + RasterizeHelper& operator=(RasterizeHelper&& rhs) = delete; + + private: + /** + * @brief Main constructor that used by all other constructors + */ + RasterizeHelper(std::unique_ptr rasterizer, SvgRasterizeManager& svgRasterizeManager); + + private: + std::unique_ptr mRasterizer; + SvgRasterizeManager& mSvgRasterizeManager; + }; private: // Undefined - SvgRasterizeThread(const SvgRasterizeThread& thread); + SvgRasterizeManager(const SvgRasterizeManager& thread); // Undefined - SvgRasterizeThread& operator=(const SvgRasterizeThread& thread); + SvgRasterizeManager& operator=(const SvgRasterizeManager& thread); private: std::vector mRasterizeTasks; //The queue of the tasks waiting to rasterize the SVG image std::vector mCompletedTasks; //The queue of the tasks with the SVG rasterization completed - ConditionalWait mConditionalWait; + RoundRobinContainerView mRasterizers; + Dali::Mutex mMutex; std::unique_ptr mTrigger; - const Dali::LogFactoryInterface& mLogFactory; - bool mIsThreadWaiting; bool mProcessorRegistered; };