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=d7eb16bd4cb62b4a3dcddf140d99ef56927a0c0b;hp=1f426cb3c55998177b73c21b438338fb1d6049c3;hb=8f568af864987ed3039737045db38ea3db4ac962;hpb=1972f043026a3e1bdcaad71c17859a8f324d1e6d diff --git a/dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h b/dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h index 1f426cb..d7eb16b 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) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -22,15 +22,17 @@ #include #include #include -#include #include #include #include #include #include +#include +#include +#include -struct NSVGimage; -struct NSVGrasterizer; +// INTERNAL INCLUDES +#include namespace Dali { @@ -53,31 +55,33 @@ typedef IntrusivePtr< RasterizingTask > RasterizingTaskPtr; * 1. Created by SvgVisual in the main thread * 2. Queued in the worked thread waiting to be processed. * 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 renderer or actor off stage) before its turn to be processed, it then been deleted in the worker thread. + * 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 { 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] url The URL to svg resource to use. * @param[in] width The rasterization width. * @param[in] height The rasterization height. + * @param[in] loaded The svg resource is loaded or not. + */ + RasterizingTask( SvgVisual* svgRenderer, VectorImageRenderer vectorRenderer, const VisualUrl& url, float dpi, unsigned int width, unsigned int height, bool loaded ); + + /** + * Destructor. */ - RasterizingTask( SvgVisual* svgRenderer, NSVGimage* parsedSvg, unsigned int width, unsigned int height ); + ~RasterizingTask() override; /** - * Do the rasterization with the given rasterizer. - *@param[in] rasterizer The rasterizer that rasterize the SVG to a buffer image + * Do the rasterization with the mRasterizer. */ - void Rasterize( NSVGrasterizer* rasterizer ); + void Rasterize(); /** - * Get the svg renderer + * Get the svg visual */ SvgVisual* GetSvgVisual() const; @@ -87,8 +91,23 @@ public: */ PixelData GetPixelData() const; -private: + /** + * Get the VectorRenderer. + * @return VectorRenderer. + */ + VectorImageRenderer GetVectorRenderer() const; + /** + * Whether the resource is loaded. + * @return True if the resource is loaded. + */ + bool IsLoaded() const; + + /** + * Load svg file + */ + void Load(); +private: // Undefined RasterizingTask( const RasterizingTask& task ); @@ -96,14 +115,16 @@ private: RasterizingTask& operator=( const RasterizingTask& task ); private: - SvgVisualPtr mSvgVisual; + SvgVisualPtr mSvgVisual; + VectorImageRenderer mVectorRenderer; + VisualUrl mUrl; PixelData mPixelData; - NSVGimage* mParsedSvg; + float mDpi; unsigned int mWidth; unsigned int mHeight; + bool mLoaded; }; - /** * The worker thread for SVG rasterization. */ @@ -138,22 +159,22 @@ public: RasterizingTaskPtr NextCompletedTask(); /** - * Remove the task with the given renderer from the waiting queue, called by main thread. + * Remove the task with the given visual from the waiting queue, called by main thread. * * Typically called when the actor is put off stage, so the renderer is not needed anymore. * - * @param[in] renderer The renderer pointer. + * @param[in] visual The visual pointer. */ - void RemoveTask( SvgVisual* renderer ); + 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. + * The parsed svg should be deleted 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 + * @param[in] VectorImage The image to be deleted */ - void DeleteImage( NSVGimage* parsedSvg ); + void DeleteImage( VectorImageRenderer vectorImage ); private: @@ -176,14 +197,14 @@ protected: /** * Destructor. */ - virtual ~SvgRasterizeThread(); + ~SvgRasterizeThread() override; /** * The entry function of the worker thread. * It fetches task from the Queue, rasterizes the image and apply to the renderer. */ - virtual void Run(); + void Run() override; private: @@ -197,13 +218,12 @@ 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 + Vector mDeleteSvg; //The images that the event thread requested to delete ConditionalWait mConditionalWait; Dali::Mutex mMutex; - EventThreadCallback* mTrigger; - - NSVGrasterizer* mRasterizer; + std::unique_ptr< EventThreadCallback > mTrigger; + const Dali::LogFactoryInterface& mLogFactory; bool mIsThreadWaiting; };