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