1 #ifndef __DALI_SLP_PLATFORM_RESOURCE_LOADER_H__
2 #define __DALI_SLP_PLATFORM_RESOURCE_LOADER_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.
21 #include <dali/integration-api/platform-abstraction.h>
22 #include <dali/integration-api/glyph-set.h>
23 #include <dali/integration-api/resource-cache.h>
24 #include <dali/public-api/common/dali-vector.h>
28 #include FT_FREETYPE_H
51 * Contains information about a successfully loaded resource
57 * @param[in] loadedId The ID of the resource
58 * @param[in] loadedType The resource type
59 * @param[in] loadedResource A pointer to the loaded resource data
61 LoadedResource(Integration::ResourceId loadedId,
62 Integration::ResourceTypeId loadedType,
63 Integration::ResourcePointer loadedResource)
66 resource(loadedResource)
71 LoadedResource(const LoadedResource& loaded)
74 resource(loaded.resource)
78 /// Assignment operator
79 LoadedResource& operator=(const LoadedResource& rhs)
85 resource = rhs.resource;
90 Integration::ResourceId id; ///< Integer ID
91 Integration::ResourceTypeId type; ///< Type enum (bitmap, shader, ...)
92 Integration::ResourcePointer resource; ///< Reference counting pointer to the loaded / decoded representation of the resource.
96 * Contains information about a successfully saved resource
102 * @param[in] savedId The ID of the resource
103 * @param[in] savedType The resource type
105 SavedResource(Integration::ResourceId savedId,
106 Integration::ResourceTypeId savedType)
113 SavedResource(const LoadedResource& loaded)
119 /// Assignment operator
120 SavedResource& operator=(const SavedResource& rhs)
130 Integration::ResourceId id;
131 Integration::ResourceTypeId type;
135 * Contains information about a failed resource load/save request
137 struct FailedResource
139 FailedResource(Integration::ResourceId resourceId, Integration::ResourceFailure failure):
146 FailedResource(const FailedResource& failed)
148 failureType(failed.failureType)
152 /// Assignment operator
153 FailedResource& operator=(const FailedResource& rhs)
158 failureType = rhs.failureType;
163 Integration::ResourceId id;
164 Integration::ResourceFailure failureType;
168 * This implements the resource loading part of the PlatformAbstraction API.
169 * The requests for a specific resource type are farmed-out to a resource
170 * requester for that type which handles them in their own dedicated loading
178 * Create a resource loader.
179 * There should exactly one of these objects per Dali Core.
184 * Non-virtual destructor.
185 * ResourceLoader is NOT intended as a base class.
190 * Pause processing of already-queued resource requests.
195 * Continue processing resource requests.
200 * Check if the ResourceLoader is terminating
201 * @return true if terminating else false
203 bool IsTerminating();
206 * Add a partially loaded resource to the PartiallyLoadedResource queue
207 * @param[in] resource The resource's information and data
209 void AddPartiallyLoadedResource(LoadedResource& resource);
212 * Add a completely loaded resource to the LoadedResource queue
213 * @param[in] resource The resource's information and data
215 void AddLoadedResource(LoadedResource& resource);
218 * Add a successfully saved resource to the SavedResource queue
219 * @param[in] resource The resource's information
221 void AddSavedResource(SavedResource& resource);
224 * Add information about a failed resource load to the FailedLoads queue
225 * @param[in] resource The failed resource's information
227 void AddFailedLoad(FailedResource& resource);
230 * Add information about a failed resource save to the FailedSaves queue
231 * @param[in] resource The failed resource's information
233 void AddFailedSave(FailedResource& resource);
236 // From PlatformAbstraction
239 * @copydoc PlatformAbstraction::LoadResource()
241 void LoadResource(const Integration::ResourceRequest& request);
244 * @copydoc PlatformAbstraction::SaveResource()
246 void SaveResource(const Integration::ResourceRequest& request);
249 * @copydoc PlatformAbstraction::CancelLoad()
251 void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
254 * @copydoc PlatformAbstraction::IsLoading()
259 * @copydoc PlatformAbstraction::GetResources()
261 void GetResources(Integration::ResourceCache& cache);
264 * Called by Font objects to synchronously query glyph data.
265 * @param[in] textRequest resource request
266 * @param[in] freeType handle to the FreeType library
267 * @param[in] fontFamily name of the font's family
268 * @param[in] getBitmap whether to load bitmaps for the symbols as well
269 * @return A GlyphSet pointer with a list of the requested glyph metrics.
271 Integration::GlyphSet* GetGlyphData ( const Integration::TextResourceType& textRequest,
273 const std::string& fontFamily,
277 * Called by Font objects to synchronously load glyph data.
278 * @param[in] textRequest resource request
279 * @param[in] fontFamily name of the font's family
280 * @return A GlyphSet pointer containing the requested glyph bitmaps.
282 Integration::GlyphSet* GetCachedGlyphData( const Integration::TextResourceType& textRequest,
283 const std::string& fontFamily );
286 * Called by Font objects to synchronously query global font metrics.
287 * @param[in] freeType handle to the FreeType library
288 * @param[in] fontFamily name of the font's family
289 * @param[in] fontStyle name of the font's style
290 * @param[out] globalMetrics font requested global metrics.
292 void GetGlobalMetrics( FT_Library freeType,
293 const std::string& fontFamily,
294 const std::string& fontStyle,
295 Integration::GlobalMetrics& globalMetrics );
298 * @copydoc PlatformAbstraction::SetDpi()
300 void SetDpi(unsigned int dpiHor, unsigned int dpiVer);
303 * @copydoc PlatformAbstraction::GetFontFamilyForChars()
305 const std::string& GetFontFamilyForChars(const Integration::TextArray& charsRequested);
308 * @copydoc PlatformAbstraction::AllGlyphsSupported()
310 bool AllGlyphsSupported(const std::string& fontFamily, const std::string& fontStyle, const Integration::TextArray& charsRequested);
313 * @copydoc PlatformAbstraction::ValidateFontFamilyName()
315 bool ValidateFontFamilyName( const std::string& fontFamily,
316 const std::string& fontStyle,
317 bool& isDefaultSystemFontFamily,
318 bool& isDefaultSystemFontStyle,
319 std::string& closestFontFamilyMatch,
320 std::string& closestFontStyleMatch );
323 * @copydoc SlpPlatformAbstraction::GetFontLineHeightFromCapsHeight
325 PixelSize GetFontLineHeightFromCapsHeight(const std::string& fontFamily, const std::string& fontStyle, CapsHeight capsHeight, FT_Library freeType);
328 * @copydoc SlpPlatformAbstraction::GetFontList
330 void GetFontList( Dali::Integration::PlatformAbstraction::FontListMode mode, std::vector<std::string>& fontList );
333 * @copydoc SlpPlatformAbstraction::LoadFile()
335 bool LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const;
338 * @copydoc SlpPlatformAbstraction::LoadFile()
340 std::string LoadFile(const std::string& filename) const;
343 * @copydoc SlpPlatformAbstraction::SaveFile()
345 static bool SaveFile(const std::string& filename, std::vector< unsigned char >& buffer);
348 * Sets the default font family that should be used by the font resources.
349 * @param[in] fontFamily The default font family.
350 * @param[in] fontStyle The default font style.
352 void SetDefaultFontFamily( const std::string& fontFamily, const std::string& fontStyle );
355 * Retrieves the glyp's image representing the given character.
357 * @param[in] freeType Handle to the FreeType library.
358 * @param[in] fontFamily The font's family name.
359 * @param[in] fontStyle The font's style.
360 * @param[in] fontSize The font's size.
361 * @param[in] character The given character.
363 * @return The bitmap image.
365 Integration::BitmapPtr GetGlyphImage( FT_Library freeType, const std::string& fontFamily, const std::string& fontStyle, float fontSize, uint32_t character );
370 * Find the path of a platform-specific font resource.
371 * Multi-threading note: this method will be called from the main thread only i.e. not
372 * from within the Core::Render() method.
373 * @note Italics and boldness are applied by transforming the outline.
374 * @param[in] fontFamily The font family e.g. Arial, Courier.
375 * @param[in] fontStyle The font's style.
376 * @return The path to a font resource; the closest available match for the family parameter.
378 const std::string& GetFontPath(const std::string& fontFamily, const std::string& fontStyle); // not const because of mutex
381 struct ResourceLoaderImpl;
382 ResourceLoaderImpl* mImpl;
384 volatile int mTerminateThread; ///< Set to <> 0 in destructor, signals threads to exit their controlling loops
388 } // namespace SlpPlatform
392 #endif // __DALI_SLPPLATFORM_RESOURCE_LOADER_H_