1 #ifndef DALI_SCENE3D_MODEL_CACHE_MANAGER_H
2 #define DALI_SCENE3D_MODEL_CACHE_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.
22 #include <dali/public-api/object/base-handle.h>
25 #include <dali-scene3d/public-api/loader/load-result.h>
33 class ModelCacheManager;
36 * A singleton class to manage the cache of 3D models so that the resources of the same model
37 * are only loaded once and kept in the cache. The cached resources will be reused when the
38 * same model is loaded multiple times.
40 class ModelCacheManager : public Dali::BaseHandle
44 * @brief Creates a ModelCacheManager handle.
46 * Calling member functions with an uninitialised handle is not allowed.
53 * This is non-virtual since derived Handle types must not contain data or virtual methods.
58 * @brief Create or retrieve the ModelCacheManager singleton.
60 * @return A handle to the ModelCacheManager.
62 static ModelCacheManager Get();
65 * @brief Retrieves the load result for the model with the given URI.
66 * If there is no existing load result for the given model, a new one will be created.
67 * @param[in] modelUri The unique model URI with its absolute path.
68 * @return A reference to the model's load result.
70 Dali::Scene3D::Loader::LoadResult GetModelLoadResult(std::string modelUri);
73 * @brief Lock the mutex object to synchronize the scene loading of the model
74 * with the given URI between multiple threads.
75 * It will be used when we need to avoid multiple threads access to same cache.
77 * @param[in] modelUri The unique model RUI with its absolute path.
78 * @post UnlockModelLoadScene() should be called before call this API.
80 void LockModelLoadScene(std::string modelUri);
83 * @brief Unlock the mutex object to synchronize the scene loading of the model
84 * with the given URI between multiple threads.
85 * It will be used when we need to avoid multiple threads access to same cache.
87 * @param[in] modelUri The unique model URI with its absolute path.
88 * @pre LockModelLoadScene() should be called before call this API.
90 void UnlockModelLoadScene(std::string modelUri);
93 * @brief Retrieves the reference count of the cache for the model with the given URI.
94 * @param[in] modelUri The unique model URI with its absolute path.
95 * @return The reference count of the cache.
97 uint32_t GetModelCacheRefCount(std::string modelUri);
100 * @brief Reference the cache of the model with the given URI.
101 * This will increment the reference count of the load result by 1.
102 * @param[in] modelUri The model URI.
104 void ReferenceModelCache(std::string modelUri);
107 * @brief Unreference the cache of the model with the given URI.
108 * This will decrement the reference count of the load result by 1.
109 * When the reference count becomes zero, the model will be removed from the cache and all
110 * its resources will be deleted.
111 * @param[in] modelUri The model URI.
113 void UnreferenceModelCache(std::string modelUri);
116 * @brief Retrieves whether the scene of the model with the given URI has been loaded.
117 * @param[in] modelUri The unique model URI with its absolute path.
118 * @return whether the scene of the model has been loaded. This will be true if the scene
119 * has been loaded for once.
121 bool IsSceneLoaded(std::string modelUri);
124 * @brief Sets whether the scene of the model with the given URI has been loaded.
125 * @param[in] modelUri The unique model URI with its absolute path.
126 * @param[in] isSceneLoaded Whether the scene of the model has been loaded.
128 void SetSceneLoaded(std::string modelUri, bool isSceneLoaded);
131 * @brief Retrieves whether the scene loading of the model with the given URI is in progress.
132 * @param[in] modelUri The unique model URI with its absolute path.
133 * @return whether the scene loading of the model is in progress.
135 bool IsSceneLoading(std::string modelUri);
138 * @brief Sets whether the scene loading of the model with the given URI is in progress.
139 * @param[in] modelUri The unique model URI with its absolute path.
140 * @param[in] isSceneLoading Whether the scene loading of the model is in progress.
142 void SetSceneLoading(std::string modelUri, bool isSceneLoading);
145 // Default copy and move operator
146 ModelCacheManager(const ModelCacheManager& rhs) = default;
147 ModelCacheManager(ModelCacheManager&& rhs) = default;
148 ModelCacheManager& operator=(const ModelCacheManager& rhs) = default;
149 ModelCacheManager& operator=(ModelCacheManager&& rhs) noexcept = default;
153 explicit DALI_INTERNAL ModelCacheManager(ModelCacheManager::Impl* impl);
156 } // namespace Internal
158 } // namespace Scene3D
162 #endif // DALI_SCENE3D_MODEL_CACHE_MANAGER_H