#define DALI_TOOLKIT_ASYNC_IMAGE_LOADER_IMPL_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.
#include <dali/public-api/object/base-object.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/image-loader/async-image-loader.h>
#include <dali-toolkit/devel-api/image-loader/async-image-loader-devel.h>
-#include <dali-toolkit/internal/image-loader/image-load-thread.h>
+#include <dali-toolkit/internal/image-loader/loading-task.h>
+#include <dali-toolkit/public-api/image-loader/async-image-loader.h>
namespace Dali
{
-
namespace Toolkit
{
-
namespace Internal
{
+using LoadingTaskPtr = IntrusivePtr<LoadingTask>;
-class AsyncImageLoader : public BaseObject
+struct AsyncImageLoadingInfo
{
-public:
+ AsyncImageLoadingInfo(LoadingTaskPtr loadingTask, std::uint32_t loadId)
+ : loadingTask(loadingTask),
+ loadId(loadId)
+ {
+ }
+
+ LoadingTaskPtr loadingTask;
+ std::uint32_t loadId;
+};
+class AsyncImageLoader : public BaseObject, public ConnectionTracker
+{
+public:
/**
* Constructor
*/
static IntrusivePtr<AsyncImageLoader> New();
/**
- * @copydoc Toolkit::AsyncImageLoader::Load( const std::string&, ImageDimensions, FittingMode::Type, SamplingMode::Type, bool , DevelAsyncImageLoader::PreMultiplyOnLoad )
+ * @copydoc Toolkit::AsyncImageLoader::LoadAnimatedImage( Dali::AnimatedImageLoading animatedImageLoading, uint32_t frameIndex, DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
*/
- uint32_t Load( const VisualUrl& url,
- ImageDimensions dimensions,
- FittingMode::Type fittingMode,
- SamplingMode::Type samplingMode,
- bool orientationCorrection,
- DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad );
+ uint32_t LoadAnimatedImage(Dali::AnimatedImageLoading animatedImageLoading,
+ uint32_t frameIndex,
+ DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
+
+ /**
+ * @brief Starts an animated image loading task.
+ * @param[in] asyncImageLoader The ayncImageLoader
+ * @param[in] animatedImageLoading The AnimatedImageLoading to load animated image
+ * @param[in] frameIndex The frame index of a frame to be loaded frame
+ * @param[in] dimensions The width and height to fit the loaded image to
+ * @param[in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter
+ * @param[in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size
+ * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha or if the image need to be applied alpha mask.
+ * @return The loading task id
+ */
+ uint32_t LoadAnimatedImage(Dali::AnimatedImageLoading animatedImageLoading,
+ uint32_t frameIndex,
+ Dali::ImageDimensions desiredSize,
+ Dali::FittingMode::Type fittingMode,
+ Dali::SamplingMode::Type samplingMode,
+ DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
+
+ /**
+ * @brief Starts an image loading task.
+ * @param[in] url The URL of the image file to load
+ * @param[in] dimensions The width and height to fit the loaded image to
+ * @param[in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter
+ * @param[in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size
+ * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header
+ * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha or if the image need to be applied alpha mask.
+ * @param[in] loadPlanes true to load image planes or false to load bitmap image.
+ * @return The loading task id
+ */
+ uint32_t Load(const VisualUrl& url,
+ ImageDimensions dimensions,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection,
+ DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
+ bool loadPlanes);
+
+ /**
+ * @brief Starts an image loading task by encoded image buffer.
+ * @param[in] encodedImageBuffer The encoded buffer of the image to load
+ * @param[in] dimensions The width and height to fit the loaded image to
+ * @param[in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter
+ * @param[in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size
+ * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header
+ * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha.
+ * @return The loading task id
+ */
+ uint32_t LoadEncodedImageBuffer(const EncodedImageBuffer& encodedImageBuffer,
+ ImageDimensions dimensions,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection,
+ DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
/**
* @brief Starts an mask applying task.
* @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha.
* @return The loading task id
*/
- uint32_t ApplyMask( Devel::PixelBuffer pixelBuffer,
- Devel::PixelBuffer maskPixelBuffer,
- float contentScale,
- bool cropToMask,
- DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad );
+ uint32_t ApplyMask(Devel::PixelBuffer pixelBuffer,
+ Devel::PixelBuffer maskPixelBuffer,
+ float contentScale,
+ bool cropToMask,
+ DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
/**
* @copydoc Toolkit::AsyncImageLoader::ImageLoadedSignal
/**
* @copydoc Toolkit::AsyncImageLoader::Cancel
*/
- bool Cancel( uint32_t loadingTaskId );
+ bool Cancel(uint32_t loadingTaskId);
/**
* @copydoc Toolkit::AsyncImageLoader::CancelAll
/**
* Process the completed loading task from the worker thread.
*/
- void ProcessLoadedImage();
+ void ProcessLoadedImage(LoadingTaskPtr task);
protected:
-
/**
* Destructor
*/
- ~AsyncImageLoader();
+ ~AsyncImageLoader() override;
private:
- Toolkit::AsyncImageLoader::ImageLoadedSignalType mLoadedSignal;
- Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType mPixelBufferLoadedSignal;
+ /**
+ * Remove already completed tasks
+ */
+ void RemoveCompletedTask();
- ImageLoadThread mLoadThread;
- uint32_t mLoadTaskId;
- bool mIsLoadThreadStarted;
+private:
+ Toolkit::AsyncImageLoader::ImageLoadedSignalType mLoadedSignal;
+ Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType mPixelBufferLoadedSignal;
+ std::vector<AsyncImageLoadingInfo> mLoadingTasks;
+ std::vector<uint32_t> mCompletedTaskIds;
+ uint32_t mLoadTaskId;
};
} // namespace Internal
-inline const Internal::AsyncImageLoader& GetImplementation( const Toolkit::AsyncImageLoader& handle )
+inline const Internal::AsyncImageLoader& GetImplementation(const Toolkit::AsyncImageLoader& handle)
{
- DALI_ASSERT_ALWAYS( handle && "AsyncImageLoader handle is empty" );
+ DALI_ASSERT_ALWAYS(handle && "AsyncImageLoader handle is empty");
const BaseObject& object = handle.GetBaseObject();
- return static_cast<const Internal::AsyncImageLoader&>( object );
+ return static_cast<const Internal::AsyncImageLoader&>(object);
}
-inline Internal::AsyncImageLoader& GetImplementation( Toolkit::AsyncImageLoader& handle )
+inline Internal::AsyncImageLoader& GetImplementation(Toolkit::AsyncImageLoader& handle)
{
- DALI_ASSERT_ALWAYS( handle && "AsyncImageLoader handle is empty" );
+ DALI_ASSERT_ALWAYS(handle && "AsyncImageLoader handle is empty");
BaseObject& object = handle.GetBaseObject();
- return static_cast<Internal::AsyncImageLoader&>( object );
+ return static_cast<Internal::AsyncImageLoader&>(object);
}
} // namespace Toolkit