Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-core.git] / dali / integration-api / resource-types.h
1 #ifndef __DALI_INTEGRATION_RESOURCE_TYPES_H__
2 #define __DALI_INTEGRATION_RESOURCE_TYPES_H__
3
4 /*
5  * Copyright (c) 2014 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 <stdint.h>
23 #include <string>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/common/dali-common.h>
27 #include <dali/public-api/common/vector-wrapper.h>
28 #include <dali/public-api/images/image-attributes.h>
29 #include <dali/integration-api/resource-declarations.h>
30
31 namespace Dali
32 {
33
34 namespace Integration
35 {
36
37 // Resource Types
38
39 /**
40  * Extendable set of resource types
41  */
42 enum ResourceTypeId
43 {
44   ResourceBitmap,
45   ResourceNativeImage,
46   ResourceTargetImage,
47   ResourceShader,
48   ResourceMesh
49 };
50
51 /**
52  * The abstract base class for resource types.
53  */
54 struct ResourceType
55 {
56   /**
57    * Constructor.
58    * @param[in] typeId resource type id
59    */
60   ResourceType(ResourceTypeId typeId)
61   : id(typeId) {}
62
63   /**
64    * Destructor.
65    */
66   virtual ~ResourceType() {}
67
68   /**
69    * Create a copy of the resource type with the same attributes.
70    * @return pointer to the new ResourceType.
71    */
72   virtual ResourceType* Clone() const = 0;
73
74   const ResourceTypeId id;
75
76 private:
77
78   // Undefined copy constructor.
79   ResourceType(const ResourceType& typePath);
80
81   // Undefined assignment operator.
82   ResourceType& operator=(const ResourceType& rhs);
83 };
84
85 /**
86  * BitmapResourceType describes a bitmap resource, which can be requested
87  * from ResourceLoader::LoadResource() or AllocateBitmapImage.
88  */
89 struct BitmapResourceType : public ResourceType
90 {
91   /**
92    * Constructor.
93    * @param[in] attribs parameters for image loading request
94    */
95   BitmapResourceType(const ImageAttributes& attribs)
96   : ResourceType(ResourceBitmap),
97     imageAttributes(attribs) {}
98
99   /**
100    * Destructor.
101    */
102   virtual ~BitmapResourceType() {}
103
104   /**
105    * @copydoc ResourceType::Clone
106    */
107   virtual ResourceType* Clone() const
108   {
109     return new BitmapResourceType(imageAttributes);
110   }
111
112   /**
113    * Attributes are copied from the request.
114    */
115   ImageAttributes imageAttributes;
116
117 private:
118
119   // Undefined copy constructor.
120   BitmapResourceType(const BitmapResourceType& typePath);
121
122   // Undefined assignment operator.
123   BitmapResourceType& operator=(const BitmapResourceType& rhs);
124 };
125
126 /**
127  * NativeImageResourceType describes a native image resource, which can be injected
128  * through ResourceManager::AddNativeImage() or requested through ResourceLoader::LoadResource().
129  * If the adaptor does not support NativeImages, it can fall back to Bitmap type.
130  */
131 struct NativeImageResourceType : public ResourceType
132 {
133   /**
134    * Constructor.
135    */
136   NativeImageResourceType()
137   : ResourceType(ResourceNativeImage) {}
138
139   /**
140    * Constructor.
141    * @param[in] attribs parameters for image loading request
142    */
143   NativeImageResourceType(const ImageAttributes& attribs)
144   : ResourceType(ResourceNativeImage),
145     imageAttributes(attribs) {}
146
147   /**
148    * Destructor.
149    */
150   virtual ~NativeImageResourceType() {}
151
152  /**
153   * @copydoc ResourceType::Clone
154   */
155   virtual ResourceType* Clone() const
156   {
157     return new NativeImageResourceType(imageAttributes);
158   }
159
160   /**
161    * Attributes are copied from the request (if supplied).
162    */
163   ImageAttributes imageAttributes;
164
165 private:
166
167   // Undefined copy constructor.
168   NativeImageResourceType(const NativeImageResourceType& typePath);
169
170   // Undefined assignment operator.
171   NativeImageResourceType& operator=(const NativeImageResourceType& rhs);
172 };
173
174 /**
175  * RenderTargetResourceType describes a bitmap resource, which can injected
176  * through ResourceManager::AddTargetImage()
177  */
178 struct RenderTargetResourceType : public ResourceType
179 {
180   /**
181    * Constructor.
182    */
183   RenderTargetResourceType()
184   : ResourceType(ResourceTargetImage) {}
185
186   /**
187    * Constructor.
188    * @param[in] attribs parameters for image loading request
189    */
190   RenderTargetResourceType(const ImageAttributes& attribs)
191   : ResourceType(ResourceTargetImage),
192     imageAttributes(attribs) {}
193
194   /**
195    * Destructor.
196    */
197   virtual ~RenderTargetResourceType() {}
198
199   /**
200    * @copydoc ResourceType::Clone
201    */
202   virtual ResourceType* Clone() const
203   {
204     return new RenderTargetResourceType(imageAttributes);
205   }
206
207   /**
208    * Attributes are copied from the request.
209    */
210   ImageAttributes imageAttributes;
211
212 private:
213
214   // Undefined copy constructor.
215   RenderTargetResourceType(const RenderTargetResourceType& typePath);
216
217   // Undefined assignment operator.
218   RenderTargetResourceType& operator=(const RenderTargetResourceType& rhs);
219 };
220
221 /**
222  * ShaderResourceType describes a shader program resource, which can be requested
223  * from PlatformAbstraction::LoadResource()
224  */
225 struct ShaderResourceType : public ResourceType
226 {
227   /**
228    * Constructor.
229    */
230   ShaderResourceType(size_t shaderHash, const std::string& vertexSource, const std::string& fragmentSource)
231   : ResourceType(ResourceShader),
232     hash(shaderHash),
233     vertexShader(vertexSource),
234     fragmentShader(fragmentSource)
235   {
236   }
237
238   /**
239    * Destructor.
240    */
241   virtual ~ShaderResourceType()
242   {
243   }
244
245   /**
246    * @copydoc ResourceType::Clone
247    */
248   virtual ResourceType* Clone() const
249   {
250     return new ShaderResourceType(hash, vertexShader, fragmentShader);
251   }
252
253 public: // Attributes
254   size_t            hash;              ///< Hash of the vertex/fragment sources
255   const std::string vertexShader;      ///< source code for vertex program
256   const std::string fragmentShader;    ///< source code for fragment program
257
258 private:
259
260   // Undefined copy constructor.
261   ShaderResourceType(const ShaderResourceType& typePath);
262
263   // Undefined assignment operator.
264   ShaderResourceType& operator=(const ShaderResourceType& rhs);
265 };
266
267 /**
268  * MeshResourceType describes a mesh program resource, which can be created
269  * using ResourceManager::AllocateMesh.
270  */
271 struct MeshResourceType : public ResourceType
272 {
273   /**
274    * Constructor.
275    */
276   MeshResourceType()
277   : ResourceType(ResourceMesh) {}
278
279   /**
280    * Destructor.
281    */
282   virtual ~MeshResourceType() {}
283
284   /**
285    * @copydoc ResourceType::Clone
286    */
287   virtual ResourceType* Clone() const
288   {
289     return new MeshResourceType();
290   }
291
292 private:
293
294   // Undefined copy constructor.
295   MeshResourceType(const MeshResourceType& typePath);
296
297   // Undefined assignment operator.
298   MeshResourceType& operator=(const MeshResourceType& rhs);
299 };
300
301 } // namespace Integration
302
303 } // namespace Dali
304
305 #endif // __DALI_INTEGRATION_RESOURCE_TYPES_H__