X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fsvg%2Fsvg-rasterize-thread.h;h=13d284b2e9f470d1b6c7f338e878f8199b3da3c3;hb=6c0714272287978686a586369b1a909f27ab172d;hp=f30c45949e4a58a1b2855ea972b94faa1c6f51c0;hpb=072e6002280ed51a637ed54e0451bdbbe3c4ec79;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h b/dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h index f30c459..13d284b 100644 --- a/dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h +++ b/dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_SVG_RASTERIZE_THREAD_H /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,32 +19,31 @@ // EXTERNAL INCLUDES #include +#include #include #include #include -#include -#include +#include +#include #include #include +#include #include -#include +#include -struct NSVGimage; -struct NSVGrasterizer; +// INTERNAL INCLUDES +#include namespace Dali { - namespace Toolkit { - namespace Internal { - class SvgVisual; -typedef IntrusivePtr< SvgVisual > SvgVisualPtr; -class RasterizingTask; -typedef IntrusivePtr< RasterizingTask > RasterizingTaskPtr; +typedef IntrusivePtr SvgVisualPtr; +class SvgTask; +typedef IntrusivePtr SvgTaskPtr; /** * The svg rasterizing tasks to be processed in the worker thread. @@ -55,26 +54,31 @@ typedef IntrusivePtr< RasterizingTask > RasterizingTaskPtr; * 3. If this task gets its turn to do the rasterization, it triggers main thread to apply the rasterized image to material then been deleted in main thread call back * Or if this task is been removed ( new image/size set to the visual or actor off stage) before its turn to be processed, it then been deleted in the worker thread. */ -class RasterizingTask : public RefObject +class SvgTask : public RefObject { public: /** * Constructor - * - * @param[in] svgRenderer The renderer which the rasterized image to be applied. - * @param[in] parsedSvg The parsed svg for rasterizing. - * Note, after the task is added to the worker thread, the worker thread takes over the ownership. - * When the image is to be deleted, delete it in the worker thread by calling SvgRasterizeThread::DeleteImage( parsedSvg ). - * @param[in] width The rasterization width. - * @param[in] height The rasterization height. + * @param[in] svgVisual The visual which the rasterized image to be applied. + * @param[in] vectorRenderer The vector rasterizer. + */ + SvgTask(SvgVisual* svgVisual, VectorImageRenderer vectorRenderer); + + /** + * Destructor. + */ + virtual ~SvgTask() = default; + + /** + * Process the task */ - RasterizingTask( SvgVisual* svgRenderer, NSVGimage* parsedSvg, unsigned int width, unsigned int height ); + virtual void Process() = 0; /** - * Do the rasterization with the given rasterizer. - *@param[in] rasterizer The rasterizer that rasterize the SVG to a buffer image + * Whether the task has succeeded. + * @return True if the task has succeeded. */ - void Rasterize( NSVGrasterizer* rasterizer ); + bool HasSucceeded() const; /** * Get the svg visual @@ -85,57 +89,127 @@ public: * Get the rasterization result. * @return The pixel data with the rasterized pixels. */ - PixelData GetPixelData() const; + virtual PixelData GetPixelData() const; private: + // Undefined + SvgTask(const SvgTask& task) = delete; + + // Undefined + SvgTask& operator=(const SvgTask& task) = delete; + +protected: + SvgVisualPtr mSvgVisual; + VectorImageRenderer mVectorRenderer; + bool mHasSucceeded; +}; + +class SvgLoadingTask : public SvgTask +{ +public: + /** + * Constructor + * @param[in] svgVisual The visual which the rasterized image to be applied. + * @param[in] vectorRenderer The vector rasterizer. + * @param[in] url The URL to svg resource to use. + * @param[in] dpi The DPI of the screen. + */ + SvgLoadingTask(SvgVisual* svgVisual, VectorImageRenderer vectorRenderer, const VisualUrl& url, float dpi); + + /** + * Destructor. + */ + ~SvgLoadingTask() override; + /** + * Process the task + */ + void Process() override; + +private: // Undefined - RasterizingTask( const RasterizingTask& task ); + SvgLoadingTask(const SvgLoadingTask& task) = delete; // Undefined - RasterizingTask& operator=( const RasterizingTask& task ); + SvgLoadingTask& operator=(const SvgLoadingTask& task) = delete; private: - SvgVisualPtr mSvgVisual; - PixelData mPixelData; - NSVGimage* mParsedSvg; - unsigned int mWidth; - unsigned int mHeight; + VisualUrl mUrl; + float mDpi; }; +class SvgRasterizingTask : public SvgTask +{ +public: + /** + * Constructor + * @param[in] svgVisual The visual which the rasterized image to be applied. + * @param[in] vectorRenderer The vector rasterizer. + * @param[in] width The rasterization width. + * @param[in] height The rasterization height. + */ + SvgRasterizingTask(SvgVisual* svgVisual, VectorImageRenderer vectorRenderer, unsigned int width, unsigned int height); + + /** + * Destructor. + */ + ~SvgRasterizingTask() override; + + /** + * Process the task accodring to the type + */ + void Process() override; + + /** + * Get the rasterization result. + * @return The pixel data with the rasterized pixels. + */ + PixelData GetPixelData() const override; + +private: + // Undefined + SvgRasterizingTask(const SvgRasterizingTask& task) = delete; + + // Undefined + SvgRasterizingTask& operator=(const SvgRasterizingTask& task) = delete; + +private: + PixelData mPixelData; + uint32_t mWidth; + uint32_t mHeight; +}; /** * The worker thread for SVG rasterization. */ -class SvgRasterizeThread : public Thread +class SvgRasterizeThread : public Thread, Integration::Processor { public: - /** * Constructor. * * @param[in] trigger The trigger to wake up the main thread. */ - SvgRasterizeThread( EventThreadCallback* trigger ); + SvgRasterizeThread(); /** * Terminate the svg rasterize thread, join and delete. */ - static void TerminateThread( SvgRasterizeThread*& thread ); + static void TerminateThread(SvgRasterizeThread*& thread); /** * Add a rasterization task into the waiting queue, called by main thread. * * @param[in] task The task added to the queue. */ - void AddTask( RasterizingTaskPtr task ); + void AddTask(SvgTaskPtr task); /** * Pop the next task out from the completed queue, called by main thread. * * @return The next task in the completed queue. */ - RasterizingTaskPtr NextCompletedTask(); + SvgTaskPtr NextCompletedTask(); /** * Remove the task with the given visual from the waiting queue, called by main thread. @@ -144,40 +218,44 @@ public: * * @param[in] visual The visual pointer. */ - void RemoveTask( SvgVisual* visual ); + void RemoveTask(SvgVisual* visual); /** - * Delete the parsed SVG image, called by main thread. - * - * The parsed svg should be delelted in worker thread, as the main thread does not know whether a rasterization of this svg is ongoing. - * - * @param[in] parsedImage The image to be deleted + * @copydoc Dali::Integration::Processor::Process() */ - void DeleteImage( NSVGimage* parsedSvg ); + void Process(bool postProcessor) override; private: - /** * Pop the next task out from the queue. * * @return The next task to be processed. */ - RasterizingTaskPtr NextTaskToProcess(); + SvgTaskPtr NextTaskToProcess(); /** * Add a task in to the queue * * @param[in] task The task added to the queue. */ - void AddCompletedTask( RasterizingTaskPtr task ); + void AddCompletedTask(SvgTaskPtr task); -protected: + /** + * Applies the rasterized image to material + */ + void ApplyRasterizedSVGToSampler(); /** - * Destructor. + * @brief Unregister a previously registered processor + * */ - virtual ~SvgRasterizeThread(); + void UnregisterProcessor(); +protected: + /** + * Destructor. + */ + ~SvgRasterizeThread() override; /** * The entry function of the worker thread. @@ -186,25 +264,22 @@ protected: void Run() override; private: - // Undefined - SvgRasterizeThread( const SvgRasterizeThread& thread ); + SvgRasterizeThread(const SvgRasterizeThread& thread); // Undefined - SvgRasterizeThread& operator=( const SvgRasterizeThread& thread ); + SvgRasterizeThread& operator=(const SvgRasterizeThread& 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 - Vector mDeleteSvg; //The images that the event thread requested to delete - - ConditionalWait mConditionalWait; - Dali::Mutex mMutex; - EventThreadCallback* mTrigger; - - NSVGrasterizer* mRasterizer; - bool mIsThreadWaiting; + 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; + Dali::Mutex mMutex; + std::unique_ptr mTrigger; + const Dali::LogFactoryInterface& mLogFactory; + bool mIsThreadWaiting; + bool mProcessorRegistered; }; } // namespace Internal