Merge "Use c-style string when webview loads contents." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / common / model-cache-manager.h
1 #ifndef DALI_SCENE3D_MODEL_CACHE_MANAGER_H
2 #define DALI_SCENE3D_MODEL_CACHE_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
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/threading/conditional-wait.h>
23 #include <dali/public-api/object/base-handle.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-scene3d/public-api/loader/load-result.h>
27
28 namespace Dali
29 {
30 namespace Scene3D
31 {
32 namespace Internal
33 {
34 class ModelCacheManager;
35
36 /**
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.
40  */
41 class ModelCacheManager : public Dali::BaseHandle
42 {
43 public:
44   /**
45    * @brief Creates a ModelCacheManager handle.
46    *
47    * Calling member functions with an uninitialised handle is not allowed.
48    */
49   ModelCacheManager();
50
51   /**
52    * @brief Destructor
53    *
54    * This is non-virtual since derived Handle types must not contain data or virtual methods.
55    */
56   ~ModelCacheManager();
57
58   /**
59    * @brief Create or retrieve the ModelCacheManager singleton.
60    *
61    * @return A handle to the ModelCacheManager.
62    */
63   static ModelCacheManager Get();
64
65   /**
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.
70    */
71   Dali::Scene3D::Loader::LoadResult GetModelLoadResult(std::string modelUri);
72
73   /**
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.
77    */
78   uint32_t GetModelCacheRefCount(std::string modelUri);
79
80   /**
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.
85    */
86   Dali::ConditionalWait& GetLoadSceneConditionalWaitInstance(std::string modelUri);
87
88   /**
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.
92    */
93   void ReferenceModelCache(std::string modelUri);
94
95   /**
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.
101    */
102   void UnreferenceModelCache(std::string modelUri);
103
104   /**
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.
109    */
110   bool IsSceneLoaded(std::string modelUri);
111
112   /**
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.
116    */
117   void SetSceneLoaded(std::string modelUri, bool isSceneLoaded);
118
119   /**
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.
123    */
124   bool IsSceneLoading(std::string modelUri);
125
126   /**
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.
130    */
131   void SetSceneLoading(std::string modelUri, bool isSceneLoading);
132
133 public:
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;
139
140 private:
141   class Impl;
142   explicit DALI_INTERNAL ModelCacheManager(ModelCacheManager::Impl* impl);
143 };
144
145 } // namespace Internal
146
147 } // namespace Scene3D
148
149 } // namespace Dali
150
151 #endif // DALI_SCENE3D_MODEL_CACHE_MANAGER_H