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-attributes.h>
29 #include <dali/integration-api/resource-declarations.h>
40 * Extendable set of resource types
53 * The abstract base class for resource types.
59 * @param[in] typeId resource type id
61 ResourceType(ResourceTypeId typeId)
67 virtual ~ResourceType() {}
70 * Create a copy of the resource type with the same attributes.
71 * @return pointer to the new ResourceType.
73 virtual ResourceType* Clone() const = 0;
75 const ResourceTypeId id;
79 // Undefined copy constructor.
80 ResourceType(const ResourceType& typePath);
82 // Undefined assignment operator.
83 ResourceType& operator=(const ResourceType& rhs);
87 * BitmapResourceType describes a bitmap resource, which can be requested
88 * from ResourceLoader::LoadResource() or AllocateBitmapImage.
90 struct BitmapResourceType : public ResourceType
94 * @param[in] attribs parameters for image loading request
96 BitmapResourceType(const ImageAttributes& attribs)
97 : ResourceType(ResourceBitmap),
98 imageAttributes(attribs) {}
103 virtual ~BitmapResourceType() {}
106 * @copydoc ResourceType::Clone
108 virtual ResourceType* Clone() const
110 return new BitmapResourceType(imageAttributes);
114 * Attributes are copied from the request.
116 ImageAttributes imageAttributes;
120 // Undefined copy constructor.
121 BitmapResourceType(const BitmapResourceType& typePath);
123 // Undefined assignment operator.
124 BitmapResourceType& operator=(const BitmapResourceType& rhs);
128 * NativeImageResourceType describes a native image resource, which can be injected
129 * through ResourceManager::AddNativeImage() or requested through ResourceLoader::LoadResource().
130 * If the adaptor does not support NativeImages, it can fall back to Bitmap type.
132 struct NativeImageResourceType : public ResourceType
137 NativeImageResourceType()
138 : ResourceType(ResourceNativeImage) {}
142 * @param[in] attribs parameters for image loading request
144 NativeImageResourceType(const ImageAttributes& attribs)
145 : ResourceType(ResourceNativeImage),
146 imageAttributes(attribs) {}
151 virtual ~NativeImageResourceType() {}
154 * @copydoc ResourceType::Clone
156 virtual ResourceType* Clone() const
158 return new NativeImageResourceType(imageAttributes);
162 * Attributes are copied from the request (if supplied).
164 ImageAttributes imageAttributes;
168 // Undefined copy constructor.
169 NativeImageResourceType(const NativeImageResourceType& typePath);
171 // Undefined assignment operator.
172 NativeImageResourceType& operator=(const NativeImageResourceType& rhs);
176 * RenderTargetResourceType describes a bitmap resource, which can injected
177 * through ResourceManager::AddTargetImage()
179 struct RenderTargetResourceType : public ResourceType
184 RenderTargetResourceType()
185 : ResourceType(ResourceTargetImage) {}
189 * @param[in] attribs parameters for image loading request
191 RenderTargetResourceType(const ImageAttributes& attribs)
192 : ResourceType(ResourceTargetImage),
193 imageAttributes(attribs) {}
198 virtual ~RenderTargetResourceType() {}
201 * @copydoc ResourceType::Clone
203 virtual ResourceType* Clone() const
205 return new RenderTargetResourceType(imageAttributes);
209 * Attributes are copied from the request.
211 ImageAttributes imageAttributes;
215 // Undefined copy constructor.
216 RenderTargetResourceType(const RenderTargetResourceType& typePath);
218 // Undefined assignment operator.
219 RenderTargetResourceType& operator=(const RenderTargetResourceType& rhs);
223 * ShaderResourceType describes a shader program resource, which can be requested
224 * from PlatformAbstraction::LoadResource()
226 struct ShaderResourceType : public ResourceType
231 ShaderResourceType(size_t shaderHash, const std::string& vertexSource, const std::string& fragmentSource)
232 : ResourceType(ResourceShader),
234 vertexShader(vertexSource),
235 fragmentShader(fragmentSource)
242 virtual ~ShaderResourceType()
247 * @copydoc ResourceType::Clone
249 virtual ResourceType* Clone() const
251 return new ShaderResourceType(hash, vertexShader, fragmentShader);
254 public: // Attributes
255 size_t hash; ///< Hash of the vertex/fragment sources
256 const std::string vertexShader; ///< source code for vertex program
257 const std::string fragmentShader; ///< source code for fragment program
261 // Undefined copy constructor.
262 ShaderResourceType(const ShaderResourceType& typePath);
264 // Undefined assignment operator.
265 ShaderResourceType& operator=(const ShaderResourceType& rhs);
269 * TextResourceType describes a font resource, which can be requested.
270 * from PlatformAbstraction::LoadResource() No font atlas is created.
272 struct TextResourceType : public ResourceType
279 TextQualityLow, ///< Request lower quality text
280 TextQualityHigh ///< Request higher quality text
284 * Structure for requesting character to be loaded from file with atlas position
285 * for automatic texture upload
289 GlyphPosition(unsigned int chr, unsigned int xPos, unsigned int yPos)
298 /** \addtogroup GlyphPositionPackedWord
299 * We have 32 bits available for this data because of the alignment restrictions
300 * on the 32 bit words that follow so rather than using the minimum number of
301 * bits for each, we give "loaded" a whole 8 bits and push it to a byte-aligned
302 * address to make access possible via a plain byte load instead of a load,
303 * mask, shift sequence. The naive bitwidths before this modification are as follows:
309 uint32_t character:21; ///< character code (UTF-32), max value of 0x10ffff (21 bits)
310 uint32_t quality:3; ///< Loaded quality 0 = low quality, 1 = high quality
311 uint32_t loaded:8; ///< true if Loaded
314 uint32_t xPosition; ///< X Position in atlas
315 uint32_t yPosition; ///< Y Position in atlas
318 * Used by ResourceTypeCompare
320 friend bool operator==(const GlyphPosition& lhs, const GlyphPosition& rhs);
323 typedef std::vector< GlyphPosition > CharacterList; ///< List of glyphs requested
327 GLYPH_CACHE_READ, ///< Doesn't cache glyphs.
328 GLYPH_CACHE_WRITE, ///< Caches glyphs.
332 * Text resource type constructor
333 * @param [in] hash The resourceHash for the FontAtlas and FontMetrics
334 * @param [in] style The font style
335 * @param [in] characterList The requested text as a vector or UTF-32 codes
336 * @param [in] textureAtlasId The resource ID of the texture atlas
337 * @param [in] quality A boolean, set to true to request high quality glyph bitmaps.
338 * @param [in] maxGlyphSize The size of the largest glyph in the font.
339 * @param [in] cache Whether text glyph should be cached or not.
341 TextResourceType( const size_t hash,
342 const std::string& style,
343 const CharacterList& characterList,
344 ResourceId textureAtlasId,
345 TextQuality quality = TextQualityLow,
346 Vector2 maxGlyphSize = Vector2::ONE,
347 GlyphCacheMode cache = GLYPH_CACHE_READ )
348 : ResourceType(ResourceText),
351 mCharacterList(characterList),
352 mTextureAtlasId(textureAtlasId),
354 mMaxGlyphSize(maxGlyphSize),
362 virtual ~TextResourceType()
367 * @copydoc ResourceType::Clone
369 virtual ResourceType* Clone() const
371 return new TextResourceType(mFontHash, mStyle, mCharacterList, mTextureAtlasId, mQuality, mMaxGlyphSize, mCache);
375 * Font resource hash.
377 const size_t mFontHash;
382 const std::string mStyle;
385 * Displayed text (UTF-32 codes)
388 CharacterList mCharacterList; ///< List of characters
390 ResourceId mTextureAtlasId; ///< Resource ID of the texture atlas this request is for
392 TextQuality mQuality; ///< Text quality setting
394 Vector2 mMaxGlyphSize; ///< Max glyph size for font
396 GlyphCacheMode mCache; ///< Whether text glyphs should be cached.
400 // Undefined copy constructor.
401 TextResourceType(const TextResourceType& typePath);
403 // Undefined copy constructor.
404 TextResourceType& operator=(const TextResourceType& rhs);
409 * MeshResourceType describes a mesh program resource, which can be created
410 * using ResourceManager::AllocateMesh.
412 struct MeshResourceType : public ResourceType
418 : ResourceType(ResourceMesh) {}
423 virtual ~MeshResourceType() {}
426 * @copydoc ResourceType::Clone
428 virtual ResourceType* Clone() const
430 return new MeshResourceType();
435 // Undefined copy constructor.
436 MeshResourceType(const MeshResourceType& typePath);
438 // Undefined assignment operator.
439 MeshResourceType& operator=(const MeshResourceType& rhs);
442 inline bool operator==(const TextResourceType::GlyphPosition& lhs, const TextResourceType::GlyphPosition& rhs)
444 return lhs.character == rhs.character && lhs.xPosition == rhs.xPosition && lhs.yPosition == rhs.yPosition && lhs.quality == rhs.quality;
447 } // namespace Integration
451 #endif // __DALI_INTEGRATION_RESOURCE_TYPES_H__