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/devel-api/threading/conditional-wait.h>
23 #include <dali/public-api/object/base-handle.h>
26 #include <dali-scene3d/public-api/loader/load-result.h>
34 class ModelCacheManager;
37 * A singleton class to manage the cache of 3D models so that the resources of the same model
38 * are only loaded once and kept in the cache. The cached resources will be reused when the
39 * same model is loaded multiple times.
41 class ModelCacheManager : public Dali::BaseHandle
45 * @brief Creates a ModelCacheManager handle.
47 * Calling member functions with an uninitialised handle is not allowed.
54 * This is non-virtual since derived Handle types must not contain data or virtual methods.
59 * @brief Create or retrieve the ModelCacheManager singleton.
61 * @return A handle to the ModelCacheManager.
63 static ModelCacheManager Get();
66 * @brief Retrieves the load result for the model with the given URI.
67 * If there is no existing load result for the given model, a new one will be created.
68 * @param[in] modelUri The unique model URI with its absolute path.
69 * @return A reference to the model's load result.
71 Dali::Scene3D::Loader::LoadResult GetModelLoadResult(std::string modelUri);
74 * @brief Retrieves the reference count of the cache for the model with the given URI.
75 * @param[in] modelUri The unique model URI with its absolute path.
76 * @return The reference count of the cache.
78 uint32_t GetModelCacheRefCount(std::string modelUri);
81 * @brief Retrieves the ConditionalWait object to synchronize the scene loading of the model
82 * with the given URI between multiple threads.
83 * @param[in] modelUri The unique model URI with its absolute path.
84 * @return The ConditionalWait object.
86 Dali::ConditionalWait& GetLoadSceneConditionalWaitInstance(std::string modelUri);
89 * @brief Reference the cache of the model with the given URI.
90 * This will increment the reference count of the load result by 1.
91 * @param[in] modelUri The model URI.
93 void ReferenceModelCache(std::string modelUri);
96 * @brief Unreference the cache of the model with the given URI.
97 * This will decrement the reference count of the load result by 1.
98 * When the reference count becomes zero, the model will be removed from the cache and all
99 * its resources will be deleted.
100 * @param[in] modelUri The model URI.
102 void UnreferenceModelCache(std::string modelUri);
105 * @brief Retrieves whether the scene of the model with the given URI has been loaded.
106 * @param[in] modelUri The unique model URI with its absolute path.
107 * @return whether the scene of the model has been loaded. This will be true if the scene
108 * has been loaded for once.
110 bool IsSceneLoaded(std::string modelUri);
113 * @brief Sets whether the scene of the model with the given URI has been loaded.
114 * @param[in] modelUri The unique model URI with its absolute path.
115 * @param[in] isSceneLoaded Whether the scene of the model has been loaded.
117 void SetSceneLoaded(std::string modelUri, bool isSceneLoaded);
120 * @brief Retrieves whether the scene loading of the model with the given URI is in progress.
121 * @param[in] modelUri The unique model URI with its absolute path.
122 * @return whether the scene loading of the model is in progress.
124 bool IsSceneLoading(std::string modelUri);
127 * @brief Sets whether the scene loading of the model with the given URI is in progress.
128 * @param[in] modelUri The unique model URI with its absolute path.
129 * @param[in] isSceneLoading Whether the scene loading of the model is in progress.
131 void SetSceneLoading(std::string modelUri, bool isSceneLoading);
134 // Default copy and move operator
135 ModelCacheManager(const ModelCacheManager& rhs) = default;
136 ModelCacheManager(ModelCacheManager&& rhs) = default;
137 ModelCacheManager& operator=(const ModelCacheManager& rhs) = default;
138 ModelCacheManager& operator=(ModelCacheManager&& rhs) noexcept = default;
142 explicit DALI_INTERNAL ModelCacheManager(ModelCacheManager::Impl* impl);
145 } // namespace Internal
147 } // namespace Scene3D
151 #endif // DALI_SCENE3D_MODEL_CACHE_MANAGER_H