1 #ifndef DALI_DEVEL_TEXTURE_UPLOAD_MANAGER_H
2 #define DALI_DEVEL_TEXTURE_UPLOAD_MANAGER_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
28 #include <dali/public-api/dali-adaptor-common.h>
32 namespace Internal DALI_INTERNAL
34 namespace Adaptor DALI_INTERNAL
36 class TextureUploadManager;
37 } // namespace DALI_INTERNAL
38 } // namespace DALI_INTERNAL
43 * The manager that make we can upload resource into texture from the worker thread.
46 * someAsyncTask.mUploadManager = TextureUploadManager::Get();
47 * someAsyncTask.mTexture = someAsyncTask.mUploadManager.GenerateTexture2D();
48 * someAsyncTask.mResourceId = Integration::GetTextureResourceId(someAsyncTask.mTexture);
49 * AsyncTaskManager::Get().AddTask(someAsyncTask);
52 * SomeAsyncTask::Process()
54 * PixelData pixelData = LoadImage();
56 * mUploadManager.RequestUpload(mResourceId, pixelData); // Upload to Graphics::Texture paired by UploadResourceId.
62 class DALI_ADAPTOR_API TextureUploadManager : public BaseHandle
65 using ResourceId = uint32_t;
66 constexpr static ResourceId INVALID_RESOURCE_ID = 0u;
68 public: // Callbed by main thread.
73 TextureUploadManager();
79 ~TextureUploadManager();
82 * @brief Gets the singleton of TextureUploadManager object.
85 * @return A handle to the TextureUploadManager
87 static TextureUploadManager Get();
90 * @brief Generate the texture 2d that hold unique id for upload resources, called by main thread.
93 * @return The texture that hold unique id of upload resource.
95 Dali::Texture GenerateTexture2D();
97 public: // Called by update thread.
99 * @brief Upload all requested resources by RequestUpload.
102 * @return True if there was at least 1 resources uploaded.
104 bool ResourceUpload();
106 public: // Can be callbed by worker thread.
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.
113 * @param[in] resourceId The id of resource.
114 * @param[in] pixelData The buffer of resource.
116 void RequestUpload(ResourceId resourceId, PixelData pixelData);
121 * @brief Allows the creation of a TextureUploadManager handle from an internal pointer.
123 * @note Not intended for application developers
125 * @param[in] impl A pointer to the object
127 explicit DALI_INTERNAL TextureUploadManager(Internal::Adaptor::TextureUploadManager* impl);