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
56 * The abstract base class for resource types.
62 * @param[in] typeId resource type id
64 ResourceType(ResourceTypeId typeId)
70 virtual ~ResourceType() {}
73 * Create a copy of the resource type with the same attributes.
74 * @return pointer to the new ResourceType.
76 virtual ResourceType* Clone() const = 0;
78 const ResourceTypeId id;
82 // Undefined copy constructor.
83 ResourceType(const ResourceType& typePath);
85 // Undefined assignment operator.
86 ResourceType& operator=(const ResourceType& rhs);
90 * BitmapResourceType describes a bitmap resource, which can be requested
91 * from ResourceLoader::LoadResource() or AllocateBitmapImage.
93 struct BitmapResourceType : public ResourceType
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
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.
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) {}
115 virtual ~BitmapResourceType() {}
118 * @copydoc ResourceType::Clone
120 virtual ResourceType* Clone() const
122 return new BitmapResourceType( size, scalingMode, samplingMode, orientationCorrection );
126 * Attributes are copied from the request.
128 ImageDimensions size;
129 FittingMode::Type scalingMode;
130 SamplingMode::Type samplingMode;
131 bool orientationCorrection;
135 // Undefined copy constructor.
136 BitmapResourceType(const BitmapResourceType& typePath);
138 // Undefined assignment operator.
139 BitmapResourceType& operator=(const BitmapResourceType& rhs);
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.
147 struct NativeImageResourceType : public ResourceType
152 NativeImageResourceType()
153 : ResourceType(ResourceNativeImage) {}
157 * @param[in] dimensions Width and Height to allocate for image.
159 NativeImageResourceType( ImageDimensions dimensions )
160 : ResourceType(ResourceNativeImage),
161 imageDimensions(dimensions) {}
166 virtual ~NativeImageResourceType() {}
169 * @copydoc ResourceType::Clone
171 virtual ResourceType* Clone() const
173 return new NativeImageResourceType(imageDimensions);
177 * Attributes are copied from the request (if supplied).
179 ImageDimensions imageDimensions;
183 // Undefined copy constructor.
184 NativeImageResourceType(const NativeImageResourceType& typePath);
186 // Undefined assignment operator.
187 NativeImageResourceType& operator=(const NativeImageResourceType& rhs);
191 * RenderTargetResourceType describes a bitmap resource, which can injected
192 * through ResourceManager::AddTargetImage()
194 struct RenderTargetResourceType : public ResourceType
199 RenderTargetResourceType()
200 : ResourceType(ResourceTargetImage) {}
204 * @param[in] dims Width and Height to allocate for image.
206 RenderTargetResourceType( ImageDimensions dims )
207 : ResourceType(ResourceTargetImage),
208 imageDimensions(dims) {}
213 virtual ~RenderTargetResourceType() {}
216 * @copydoc ResourceType::Clone
218 virtual ResourceType* Clone() const
220 return new RenderTargetResourceType(imageDimensions);
224 * Image size is copied from the request.
226 ImageDimensions imageDimensions;
230 // Undefined copy constructor.
231 RenderTargetResourceType(const RenderTargetResourceType& typePath);
233 // Undefined assignment operator.
234 RenderTargetResourceType& operator=(const RenderTargetResourceType& rhs);
238 * ShaderResourceType describes a shader program resource, which can be requested
239 * from PlatformAbstraction::LoadResource()
241 struct ShaderResourceType : public ResourceType
246 ShaderResourceType(size_t shaderHash, const std::string& vertexSource, const std::string& fragmentSource)
247 : ResourceType(ResourceShader),
249 vertexShader(vertexSource),
250 fragmentShader(fragmentSource)
257 virtual ~ShaderResourceType()
262 * @copydoc ResourceType::Clone
264 virtual ResourceType* Clone() const
266 return new ShaderResourceType(hash, vertexShader, fragmentShader);
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
276 // Undefined copy constructor.
277 ShaderResourceType(const ShaderResourceType& typePath);
279 // Undefined assignment operator.
280 ShaderResourceType& operator=(const ShaderResourceType& rhs);
284 * MeshResourceType describes a mesh program resource, which can be created
285 * using ResourceManager::AllocateMesh.
287 struct MeshResourceType : public ResourceType
293 : ResourceType(ResourceMesh) {}
298 virtual ~MeshResourceType() {}
301 * @copydoc ResourceType::Clone
303 virtual ResourceType* Clone() const
305 return new MeshResourceType();
310 // Undefined copy constructor.
311 MeshResourceType(const MeshResourceType& typePath);
313 // Undefined assignment operator.
314 MeshResourceType& operator=(const MeshResourceType& rhs);
317 } // namespace Integration
321 #endif // __DALI_INTEGRATION_RESOURCE_TYPES_H__