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 Flora License, Version 1.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://floralicense.org/license/
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.
25 #include <dali/public-api/images/image-attributes.h>
26 #include <dali/integration-api/resource-declarations.h>
37 * Extendable set of resource type identifiers used by ResourceType subclasses.
41 ResourceImageData, ///< A buffer of image data with dimension and type metadata.
48 ResourceTexture, ///< Used to pass through a request for a GLES texture to be allocated on the render thread.
49 ResourceAppBitmap ///< Used in Core to tag Bitmaps that belong to BitmapImages.
53 * @brief A ResourceType-derived class is just a data bucket.
55 * Each ResourceType derived class carries a bundle of data specific to one or
56 * more resource request types that are unambiguously specified by the
57 * <code>id</code> member of this base class.
58 * Dispatch on that ResourceTypeId to know exactly which kind of resource
59 * request is associated with a particular instance.
61 struct DALI_IMPORT_API ResourceType
65 * @param[in] typeId resource type id
67 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& type );
85 // Undefined assignment operator.
86 ResourceType& operator=( const ResourceType& rhs );
90 * ImageResourceType can be used to identify a a request as pertaining
91 * to images and carries some image attributes to modify the request.
92 * @todo Replace all uses of other image-related ResourceTypes with
93 * this one as they are duplicates.
95 struct DALI_IMPORT_API ImageResourceType : public ResourceType
99 * @param[in] typeId One of the image ResourceTypeIds.
100 * @param[in] attribs parameters for image loading request
102 ImageResourceType(const ResourceTypeId typeId, const ImageAttributes& attribs)
103 : ResourceType(typeId),
104 imageAttributes(attribs)
106 DALI_ASSERT_DEBUG( typeId == ResourceTexture || typeId == ResourceImageData || typeId == ResourceNativeImage || typeId == ResourceTargetImage || typeId == ResourceAppBitmap );
110 * @copydoc ResourceType::Clone
112 virtual ResourceType* Clone() const
114 return new ImageResourceType( id, imageAttributes );
118 * Attributes are copied from the request.
120 ImageAttributes imageAttributes;
124 * NativeImageResourceType describes a native image resource, which can be injected
125 * through ResourceManager::AddNativeImage() or requested through ResourceLoader::LoadResource().
126 * If the adaptor does not support NativeImages, it can fall back to Bitmap type.
128 struct DALI_IMPORT_API NativeImageResourceType : public ResourceType
131 * Default constructor initialises the base class with the correct ResourceTypeId.
133 NativeImageResourceType()
134 : ResourceType(ResourceNativeImage) {}
138 * @param[in] attribs parameters for image loading request
140 NativeImageResourceType(const ImageAttributes& attribs)
141 : ResourceType(ResourceNativeImage),
142 imageAttributes(attribs) {}
145 * @copydoc ResourceType::Clone
147 virtual ResourceType* Clone() const
149 return new NativeImageResourceType(imageAttributes);
153 * Attributes are copied from the request (if supplied).
155 ImageAttributes imageAttributes;
159 * RenderTargetResourceType describes a bitmap resource, which can injected
160 * through ResourceManager::AddTargetImage()
162 struct DALI_IMPORT_API RenderTargetResourceType : public ResourceType
165 * Default constructor initialises the base class with the correct ResourceTypeId.
167 RenderTargetResourceType()
168 : ResourceType(ResourceTargetImage) {}
172 * @param[in] attribs parameters for image loading request
174 RenderTargetResourceType(const ImageAttributes& attribs)
175 : ResourceType(ResourceTargetImage),
176 imageAttributes(attribs) {}
179 * @copydoc ResourceType::Clone
181 virtual ResourceType* Clone() const
183 return new RenderTargetResourceType(imageAttributes);
187 * Attributes are copied from the request.
189 ImageAttributes imageAttributes;
193 * ShaderResourceType describes a shader program resource, which can be requested
194 * from PlatformAbstraction::LoadResource()
196 struct DALI_IMPORT_API ShaderResourceType : public ResourceType
198 ShaderResourceType(size_t shaderHash, const std::string& vertexSource, const std::string& fragmentSource)
199 : ResourceType(ResourceShader),
201 vertexShader(vertexSource),
202 fragmentShader(fragmentSource)
207 * @copydoc ResourceType::Clone
209 virtual ResourceType* Clone() const
211 return new ShaderResourceType(hash, vertexShader, fragmentShader);
214 public: // Attributes
215 size_t hash; ///< Hash of the vertex/fragment sources
216 const std::string vertexShader; ///< source code for vertex program
217 const std::string fragmentShader; ///< source code for fragment program
221 * TextResourceType describes a font resource, which can be requested.
222 * from PlatformAbstraction::LoadResource() No font atlas is created.
224 struct DALI_IMPORT_API TextResourceType : public ResourceType
231 TextQualityLow, ///< Request lower quality text
232 TextQualityHigh ///< Request higher quality text
236 * Structure for requesting character to be loaded from file with atlas position
237 * for automatic texture upload
241 GlyphPosition(unsigned int chr, unsigned int xPos, unsigned int yPos)
250 /** \addtogroup GlyphPositionPackedWord
251 * We have 32 bits available for this data because of the alignment restrictions
252 * on the 32 bit words that follow so rather than using the minimum number of
253 * bits for each, we give "loaded" a whole 8 bits and push it to a byte-aligned
254 * address to make access possible via a plain byte load instead of a load,
255 * mask, shift sequence. The naive bitwidths before this modification are as follows:<code>
261 uint32_t character:21; ///< character code (UTF-32), max value of 0x10ffff (21 bits)
262 uint32_t quality:3; ///< Loaded quality 0 = low quality, 1 = high quality
263 uint32_t loaded:8; ///< true if Loaded
266 uint32_t xPosition; ///< X Position in atlas
267 uint32_t yPosition; ///< Y Position in atlas
270 * Used by ResourceTypeCompare
272 friend bool operator==(const GlyphPosition& lhs, const GlyphPosition& rhs);
275 typedef std::vector< GlyphPosition > CharacterList; ///< List of glyphs requested
279 GLYPH_CACHE_READ, ///< Doesn't cache glyphs.
280 GLYPH_CACHE_WRITE, ///< Caches glyphs.
284 * Text resource type constructor
285 * @param [in] hash The resourceHash for the FontAtlas and FontMetrics
286 * @param [in] style The font style
287 * @param [in] characterList The requested text as a vector or UTF-32 codes
288 * @param [in] textureAtlasId The resource ID of the texture atlas
289 * @param [in] quality A boolean, set to true to request high quality glyph bitmaps.
290 * @param [in] maxGlyphSize The size of the largest glyph in the font.
291 * @param [in] cache Whether text glyph should be cached or not.
293 TextResourceType( const size_t hash,
294 const std::string& style,
295 const CharacterList& characterList,
296 ResourceId textureAtlasId,
297 TextQuality quality = TextQualityLow,
298 Vector2 maxGlyphSize = Vector2::ONE,
299 GlyphCacheMode cache = GLYPH_CACHE_READ )
300 : ResourceType(ResourceText),
303 mCharacterList(characterList),
304 mTextureAtlasId(textureAtlasId),
306 mMaxGlyphSize(maxGlyphSize),
312 * @copydoc ResourceType::Clone
314 virtual ResourceType* Clone() const
316 return new TextResourceType(mFontHash, mStyle, mCharacterList, mTextureAtlasId, mQuality, mMaxGlyphSize, mCache);
320 * Font resource hash.
322 const size_t mFontHash;
327 const std::string mStyle;
330 * Displayed text (UTF-32 codes)
333 CharacterList mCharacterList; ///< List of characters
335 ResourceId mTextureAtlasId; ///< Resource ID of the texture atlas this request is for
337 TextQuality mQuality; ///< Text quality setting
339 Vector2 mMaxGlyphSize; ///< Max glyph size for font
341 GlyphCacheMode mCache; ///< Whether text glyphs should be cached.
345 * ModelResourceType describes a model resource, which can be requested
346 * from PlatformAbstraction::LoadResource()
348 struct DALI_IMPORT_API ModelResourceType : public ResourceType
351 * Default constructor initialises the base class with the correct ResourceTypeId.
354 : ResourceType(ResourceModel)
359 * @copydoc ResourceType::Clone
361 virtual ResourceType* Clone() const
363 return new ModelResourceType();
369 * MeshResourceType describes a mesh program resource, which can be created
370 * using ResourceManager::AllocateMesh.
372 struct DALI_IMPORT_API MeshResourceType : public ResourceType
375 * Default constructor initialises the base class with the correct ResourceTypeId.
378 : ResourceType(ResourceMesh) {}
381 * @copydoc ResourceType::Clone
383 virtual ResourceType* Clone() const
385 return new MeshResourceType();
389 inline bool operator==(const TextResourceType::GlyphPosition& lhs, const TextResourceType::GlyphPosition& rhs)
391 return lhs.character == rhs.character && lhs.xPosition == rhs.xPosition && lhs.yPosition == rhs.yPosition && lhs.quality == rhs.quality;
394 } // namespace Integration
398 #endif // __DALI_INTEGRATION_RESOURCE_TYPES_H__