[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / texture-upload-manager.h
1 #ifndef DALI_DEVEL_TEXTURE_UPLOAD_MANAGER_H
2 #define DALI_DEVEL_TEXTURE_UPLOAD_MANAGER_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/common/intrusive-ptr.h>
22 #include <dali/public-api/images/pixel-data.h>
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/public-api/rendering/texture.h>
25 #include <stdint.h> ///< For uint32_t
26
27 // INTERNAL INCLUDES
28 #include <dali/public-api/dali-adaptor-common.h>
29
30 namespace Dali
31 {
32 namespace Internal DALI_INTERNAL
33 {
34 namespace Adaptor DALI_INTERNAL
35 {
36 class TextureUploadManager;
37 } // namespace DALI_INTERNAL
38 } // namespace DALI_INTERNAL
39
40 namespace Devel
41 {
42 /**
43  * The manager that make we can upload resource into texture from the worker thread.
44  * @code
45  * (Event Thread)
46  * someAsyncTask.mUploadManager = TextureUploadManager::Get();
47  * someAsyncTask.mTexture = someAsyncTask.mUploadManager.GenerateTexture2D();
48  * someAsyncTask.mResourceId = Integration::GetTextureResourceId(someAsyncTask.mTexture);
49  * AsyncTaskManager::Get().AddTask(someAsyncTask);
50  *
51  * (Worker Thread)
52  * SomeAsyncTask::Process()
53  * {
54  *   PixelData pixelData = LoadImage();
55  *   ...
56  *   mUploadManager.RequestUpload(mResourceId, pixelData); // Upload to Graphics::Texture paired by UploadResourceId.
57  * }
58  * @endcode
59  *
60  * @SINCE_2_2.38
61  */
62 class DALI_ADAPTOR_API TextureUploadManager : public BaseHandle
63 {
64 public:
65   using ResourceId                                = uint32_t;
66   constexpr static ResourceId INVALID_RESOURCE_ID = 0u;
67
68 public: // Callbed by main thread.
69   /**
70    * Constructor.
71    * @SINCE_2_2.38
72    */
73   TextureUploadManager();
74
75   /**
76    * Destructor.
77    * @SINCE_2_2.38
78    */
79   ~TextureUploadManager();
80
81   /**
82    * @brief Gets the singleton of TextureUploadManager object.
83    *
84    * @SINCE_2_2.38
85    * @return A handle to the TextureUploadManager
86    */
87   static TextureUploadManager Get();
88
89   /**
90    * @brief Generate the texture 2d that hold unique id for upload resources, called by main thread.
91    *
92    * @SINCE_2_2.38
93    * @return The texture that hold unique id of upload resource.
94    */
95   Dali::Texture GenerateTexture2D();
96
97 public: // Called by update thread.
98   /**
99    * @brief Upload all requested resources by RequestUpload.
100    *
101    * @SINCE_2_2.38
102    * @return True if there was at least 1 resources uploaded.
103    */
104   bool ResourceUpload();
105
106 public: // Can be callbed by worker thread.
107   /**
108    * @brief Request upload PixelData to given ResourceId.
109    * @note We should not request invalid resouceId.
110    * @note We should not request mutiple times into same resourceId.
111    *
112    * @SINCE_2_2.38
113    * @param[in] resourceId The id of resource.
114    * @param[in] pixelData The buffer of resource.
115    */
116   void RequestUpload(ResourceId resourceId, PixelData pixelData);
117
118 public:
119   /// @cond internal
120   /**
121    * @brief Allows the creation of a TextureUploadManager handle from an internal pointer.
122    *
123    * @note Not intended for application developers
124    * @SINCE_2_2.38
125    * @param[in] impl A pointer to the object
126    */
127   explicit DALI_INTERNAL TextureUploadManager(Internal::Adaptor::TextureUploadManager* impl);
128   /// @endcond
129 };
130 } // namespace Devel
131
132 } // namespace Dali
133
134 #endif