#define DALI_TOOLKIT_SVG_RASTERIZE_THREAD_H
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
// EXTERNAL INCLUDES
#include <dali/devel-api/adaptor-framework/event-thread-callback.h>
+#include <dali/devel-api/adaptor-framework/vector-image-renderer.h>
#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/pixel-data.h>
+#include <dali/integration-api/adaptor-framework/log-factory-interface.h>
+#include <dali/integration-api/processor-interface.h>
#include <dali/public-api/common/intrusive-ptr.h>
#include <dali/public-api/common/vector-wrapper.h>
+#include <dali/public-api/images/pixel-data.h>
#include <dali/public-api/object/ref-object.h>
#include <dali/public-api/rendering/texture-set.h>
-#include <dali/devel-api/adaptor-framework/vector-image-renderer.h>
-#include <dali/integration-api/adaptor-framework/log-factory-interface.h>
#include <memory>
// INTERNAL INCLUDES
namespace Dali
{
-
namespace Toolkit
{
-
namespace Internal
{
-
class SvgVisual;
-typedef IntrusivePtr< SvgVisual > SvgVisualPtr;
+typedef IntrusivePtr<SvgVisual> SvgVisualPtr;
class RasterizingTask;
-typedef IntrusivePtr< RasterizingTask > RasterizingTaskPtr;
+typedef IntrusivePtr<RasterizingTask> RasterizingTaskPtr;
/**
* The svg rasterizing tasks to be processed in the worker thread.
* @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 );
+ RasterizingTask(SvgVisual* svgRenderer, VectorImageRenderer vectorRenderer, const VisualUrl& url, float dpi, unsigned int width, unsigned int height);
/**
* Destructor.
private:
// Undefined
- RasterizingTask( const RasterizingTask& task );
+ RasterizingTask(const RasterizingTask& task);
// Undefined
- RasterizingTask& operator=( const RasterizingTask& task );
+ RasterizingTask& operator=(const RasterizingTask& task);
private:
- SvgVisualPtr mSvgVisual;
+ SvgVisualPtr mSvgVisual;
VectorImageRenderer mVectorRenderer;
- VisualUrl mUrl;
- PixelData mPixelData;
- float mDpi;
- unsigned int mWidth;
- unsigned int mHeight;
- bool mLoaded;
+ VisualUrl mUrl;
+ PixelData mPixelData;
+ float mDpi;
+ unsigned int mWidth;
+ unsigned int mHeight;
+ bool mLoadSuccess;
};
/**
* 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(RasterizingTaskPtr task);
/**
* Pop the next task out from the completed queue, called by main thread.
*
* @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 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
+ * @copydoc Dali::Integration::Processor::Process()
*/
- void DeleteImage( VectorImageRenderer vectorImage );
+ void Process(bool postProcessor) override;
private:
-
/**
* Pop the next task out from the queue.
*
*
* @param[in] task The task added to the queue.
*/
- void AddCompletedTask( RasterizingTaskPtr task );
+ void AddCompletedTask(RasterizingTaskPtr task);
-protected:
+ /**
+ * Applies the rasterized image to material
+ */
+ void ApplyRasterizedSVGToSampler();
+
+ /**
+ * @brief Unregister a previously registered processor
+ *
+ */
+ void UnregisterProcessor();
+protected:
/**
* Destructor.
*/
~SvgRasterizeThread() override;
-
/**
* The entry function of the worker thread.
* It fetches task from the Queue, rasterizes the image and apply to the renderer.
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<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
- Vector <VectorImageRenderer*> mDeleteSvg; //The images that the event thread requested to delete
-
- ConditionalWait mConditionalWait;
- Dali::Mutex mMutex;
- std::unique_ptr< EventThreadCallback > mTrigger;
- const Dali::LogFactoryInterface& mLogFactory;
- bool mIsThreadWaiting;
+ 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
+
+ ConditionalWait mConditionalWait;
+ Dali::Mutex mMutex;
+ std::unique_ptr<EventThreadCallback> mTrigger;
+ const Dali::LogFactoryInterface& mLogFactory;
+ bool mIsThreadWaiting;
+ bool mProcessorRegistered;
};
} // namespace Internal