1 #ifndef __DALI_INTEGRATION_RESOURCE_TYPES_H__
2 #define __DALI_INTEGRATION_RESOURCE_TYPES_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
36 typedef Uint16Pair ImageDimensions;
44 * Extendable set of resource types
55 * The abstract base class for resource types.
61 * @param[in] typeId resource type id
63 ResourceType(ResourceTypeId typeId)
69 virtual ~ResourceType() {}
72 * Create a copy of the resource type with the same attributes.
73 * @return pointer to the new ResourceType.
75 virtual ResourceType* Clone() const = 0;
77 const ResourceTypeId id;
81 // Undefined copy constructor.
82 ResourceType(const ResourceType& typePath);
84 // Undefined assignment operator.
85 ResourceType& operator=(const ResourceType& rhs);
89 * BitmapResourceType describes a bitmap resource, which can be requested
90 * from ResourceLoader::LoadResource() or AllocateBitmapImage.
92 struct BitmapResourceType : public ResourceType
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
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.
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) {}
114 virtual ~BitmapResourceType() {}
117 * @copydoc ResourceType::Clone
119 virtual ResourceType* Clone() const
121 return new BitmapResourceType( size, scalingMode, samplingMode, orientationCorrection );
125 * Attributes are copied from the request.
127 ImageDimensions size;
128 FittingMode::Type scalingMode;
129 SamplingMode::Type samplingMode;
130 bool orientationCorrection;
134 // Undefined copy constructor.
135 BitmapResourceType(const BitmapResourceType& typePath);
137 // Undefined assignment operator.
138 BitmapResourceType& operator=(const BitmapResourceType& rhs);
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.
146 struct NativeImageResourceType : public ResourceType
151 NativeImageResourceType()
152 : ResourceType(ResourceNativeImage) {}
156 * @param[in] dimensions Width and Height to allocate for image.
158 NativeImageResourceType( ImageDimensions dimensions )
159 : ResourceType(ResourceNativeImage),
160 imageDimensions(dimensions) {}
165 virtual ~NativeImageResourceType() {}
168 * @copydoc ResourceType::Clone
170 virtual ResourceType* Clone() const
172 return new NativeImageResourceType(imageDimensions);
176 * Attributes are copied from the request (if supplied).
178 ImageDimensions imageDimensions;
182 // Undefined copy constructor.
183 NativeImageResourceType(const NativeImageResourceType& typePath);
185 // Undefined assignment operator.
186 NativeImageResourceType& operator=(const NativeImageResourceType& rhs);
190 * RenderTargetResourceType describes a bitmap resource, which can injected
191 * through ResourceManager::AddTargetImage()
193 struct RenderTargetResourceType : public ResourceType
198 RenderTargetResourceType()
199 : ResourceType(ResourceTargetImage) {}
203 * @param[in] dims Width and Height to allocate for image.
205 RenderTargetResourceType( ImageDimensions dims )
206 : ResourceType(ResourceTargetImage),
207 imageDimensions(dims) {}
212 virtual ~RenderTargetResourceType() {}
215 * @copydoc ResourceType::Clone
217 virtual ResourceType* Clone() const
219 return new RenderTargetResourceType(imageDimensions);
223 * Image size is copied from the request.
225 ImageDimensions imageDimensions;
229 // Undefined copy constructor.
230 RenderTargetResourceType(const RenderTargetResourceType& typePath);
232 // Undefined assignment operator.
233 RenderTargetResourceType& operator=(const RenderTargetResourceType& rhs);
237 * ShaderResourceType describes a shader program resource, which can be requested
238 * from PlatformAbstraction::LoadResource()
240 struct ShaderResourceType : public ResourceType
245 ShaderResourceType(size_t shaderHash, const std::string& vertexSource, const std::string& fragmentSource)
246 : ResourceType(ResourceShader),
248 vertexShader(vertexSource),
249 fragmentShader(fragmentSource)
256 virtual ~ShaderResourceType()
261 * @copydoc ResourceType::Clone
263 virtual ResourceType* Clone() const
265 return new ShaderResourceType(hash, vertexShader, fragmentShader);
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
275 // Undefined copy constructor.
276 ShaderResourceType(const ShaderResourceType& typePath);
278 // Undefined assignment operator.
279 ShaderResourceType& operator=(const ShaderResourceType& rhs);
282 } // namespace Integration
286 #endif // __DALI_INTEGRATION_RESOURCE_TYPES_H__