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