Merge "Updated patch coverage script." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-scene-loader / public-api / resource-bundle.h
1 #ifndef DALI_SCENE_LOADER_RESOURCE_BUNDLE_H_
2 #define DALI_SCENE_LOADER_RESOURCE_BUNDLE_H_
3 /*
4  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // INTERNAL
21 #include "dali-scene-loader/public-api/mesh-definition.h"
22 #include "dali-scene-loader/public-api/material-definition.h"
23 #include "dali-scene-loader/public-api/environment-definition.h"
24 #include "dali-scene-loader/public-api/shader-definition.h"
25 #include "dali-scene-loader/public-api/skeleton-definition.h"
26
27 // EXTERNAL
28 #include "dali/public-api/common/vector-wrapper.h"
29 #include "dali/public-api/rendering/shader.h"
30 #include "dali/public-api/rendering/texture-set.h"
31 #include <memory>
32 #include <functional>
33
34 namespace Dali
35 {
36 namespace SceneLoader
37 {
38
39 /*
40  * @brief The types of resources that .dli may define.
41  */
42 struct DALI_SCENE_LOADER_API ResourceType
43 {
44   enum Value
45   {
46     Environment,
47     Shader,
48     Mesh,
49     Material,
50   };
51
52   ResourceType() = delete;
53 };
54
55 /*
56  * @return The string value corresponding to the given resource @a type.
57  */
58 DALI_SCENE_LOADER_API const char* GetResourceTypeName(ResourceType::Value type);
59
60 using ResourceRefCounts = std::vector<Vector<uint32_t>>;
61
62 /*
63  * @brief Stores all resource definitions along with the DALi resources that
64  *  could be created from them, directly indexible into with values from a dli
65  *  document.
66  */
67 class DALI_SCENE_LOADER_API ResourceBundle
68 {
69 public:
70   struct Options
71   {
72     using Type = uint8_t;
73
74     enum Value : Type
75     {
76       None = 0,
77       ForceReload = NthBit(0),  ///< Load resources [again] even if they were already loaded.
78       KeepUnused = NthBit(1)  ///<s Don't reset handles to resources that had a 0 reference count.
79     };
80   };
81
82   using PathProvider = std::function<std::string(ResourceType::Value)>;
83
84   ResourceBundle() = default;
85
86   ResourceBundle(const ResourceBundle&) = delete;
87   ResourceBundle& operator=(const ResourceBundle&) = delete;
88
89   ResourceBundle(ResourceBundle&&) = default;
90   ResourceBundle& operator=(ResourceBundle&&) = default;
91
92   /*
93    * @return A ResourceRefCounts object with the correct number of entries for
94    *  all resource types (based on the various resource definition vectors),
95    *  with all reference counts set to 0.
96    */
97   ResourceRefCounts CreateRefCounter() const;
98
99   /*
100    * @brief Based on a ResourceRefCounts, and more specifically the reference
101    *  count of materials therein, it will calculate the reference count of
102    *  environment maps.
103    */
104   void CountEnvironmentReferences(ResourceRefCounts& refCounts) const;
105
106   /*
107    * @brief Performs the loading of all resources based on their respective
108    *  reference count in @a refCounts. Resources that had a non-zero ref count will be
109    *  loaded unless we already have a handle to them (OR the ForceReload option was specified).
110    *  Any handles we have to resources that come in with a zero ref count will be reset,
111    *  UNLESS the KeepUnused option was specified.
112    */
113   void LoadResources(const ResourceRefCounts& refCounts,
114     PathProvider pathProvider,
115     Options::Type options = Options::None);
116
117 public: // DATA
118   EnvironmentDefinition::Vector mEnvironmentMaps;
119   ShaderDefinition::Vector mShaders;
120   MeshDefinition::Vector mMeshes;
121   MaterialDefinition::Vector mMaterials;
122
123   SkeletonDefinition::Vector mSkeletons;
124 };
125
126 }
127 }
128
129 #endif //DALI_SCENE_LOADER_RESOURCE_BUNDLE_H_