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