#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.
#include <dali/devel-api/threading/conditional-wait.h>
#include <dali/devel-api/threading/mutex.h>
#include <dali/devel-api/threading/thread.h>
-#include <dali/public-api/images/buffer-image.h>
#include <dali/public-api/images/pixel-data.h>
#include <dali/public-api/common/intrusive-ptr.h>
#include <dali/public-api/common/vector-wrapper.h>
#include <dali/public-api/object/ref-object.h>
#include <dali/public-api/rendering/texture-set.h>
+#include <dali-toolkit/internal/visuals/visual-url.h>
+#ifdef NO_THORVG
struct NSVGimage;
struct NSVGrasterizer;
+#else /* NO_THORVG */
+#include <string.h>
+#include <dali/devel-api/adaptor-framework/vector-image-renderer.h>
+#endif /* NO_THORVG */
namespace Dali
{
class RasterizingTask : public RefObject
{
public:
+#ifdef NO_THORVG
/**
* Constructor
*
* @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.
*/
- RasterizingTask( SvgVisual* svgRenderer, NSVGimage* parsedSvg, unsigned int width, unsigned int height );
+ RasterizingTask( SvgVisual* svgRenderer, NSVGimage* parsedSvg, const VisualUrl& url, float dpi, unsigned int width, unsigned int height );
+#else /* NO_THORVG */
+ /**
+ * Constructor
+ * @param[in] svgRenderer The renderer which the rasterized image to be applied.
+ * @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 );
+#endif /* NO_THORVG */
+
+ /**
+ * Destructor.
+ */
+ ~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 visual
*/
PixelData GetPixelData() const;
-private:
+#ifdef NO_THORVG
+ /**
+ * Get the parsed data.
+ * @return parsed image data.
+ */
+ NSVGimage* GetParsedImage() const;
+ /**
+ * Get default size of svg
+ *
+ * @param[out] width The default width of svg
+ * @param[out] height The default height of svg
+ */
+ void GetDefaultSize( uint32_t& width, uint32_t& height ) const;
+#else /* NO_THORVG */
+ /**
+ * Get the VectorRenderer.
+ * @return VectorRenderer.
+ */
+ VectorImageRenderer GetVectorRenderer() const;
+ /**
+ * Whether the resource is loaded.
+ * @return True if the resource is loaded.
+ */
+ bool IsLoaded() const;
+#endif /* NO_THORVG */
+ /**
+ * Load svg file
+ */
+ void Load();
+
+private:
// Undefined
RasterizingTask( const RasterizingTask& task );
RasterizingTask& operator=( const RasterizingTask& task );
private:
- SvgVisualPtr mSvgVisual;
- PixelData mPixelData;
+ SvgVisualPtr mSvgVisual;
+#ifdef NO_THORVG
NSVGimage* mParsedSvg;
+#else /* NO_THORVG */
+ VectorImageRenderer mVectorRenderer;
+#endif /* NO_THORVG */
+ VisualUrl mUrl;
+ PixelData mPixelData;
+ float mDpi;
unsigned int mWidth;
unsigned int mHeight;
+#ifdef NO_THORVG
+ NSVGrasterizer* mRasterizer;
+#else /* NO_THORVG */
+ bool mLoaded;
+#endif /* NO_THORVG */
};
-
/**
* The worker thread for SVG rasterization.
*/
*/
void RemoveTask( SvgVisual* visual );
+#ifdef NO_THORVG
/**
* 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
*/
void DeleteImage( NSVGimage* parsedSvg );
+#else /* NO_THORVG */
+ /**
+ * Delete the parsed SVG image, called by main thread.
+ *
+ * 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] VectorImage The image to be deleted
+ */
+ void DeleteImage( VectorImageRenderer vectorImage );
+#endif /* NO_THORVG */
private:
/**
* 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:
std::vector<RasterizingTaskPtr> mRasterizeTasks; //The queue of the tasks waiting to rasterize the SVG image
std::vector <RasterizingTaskPtr> mCompletedTasks; //The queue of the tasks with the SVG rasterization completed
+#ifdef NO_THORVG
Vector<NSVGimage*> mDeleteSvg; //The images that the event thread requested to delete
+#else /* NO_THORVG */
+ Vector <VectorImageRenderer*> mDeleteSvg; //The images that the event thread requested to delete
+#endif /* NO_THORVG */
ConditionalWait mConditionalWait;
Dali::Mutex mMutex;
EventThreadCallback* mTrigger;
- NSVGrasterizer* mRasterizer;
bool mIsThreadWaiting;
};