1 #ifndef __DALI_INTERNAL_GLYPH_RESOURCE_MANAGER_H__
2 #define __DALI_INTERNAL_GLYPH_RESOURCE_MANAGER_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.
21 #include <dali/public-api/common/map-wrapper.h>
22 #include <dali/public-api/common/set-wrapper.h>
23 #include <dali/internal/event/text/glyph-status/glyph-status.h>
24 #include <dali/internal/event/text/resource/glyph-resource-observer.h>
25 #include <dali/internal/event/text/resource/glyph-resource-request.h>
26 #include <dali/internal/event/text/resource/glyph-load-observer.h>
27 #include <dali/internal/event/text/resource/font-lookup-interface.h>
28 #include <dali/internal/event/text/resource/glyph-texture-observer.h>
29 #include <dali/internal/event/text/text-observer.h>
30 #include <dali/internal/event/resources/resource-ticket.h>
31 #include <dali/integration-api/resource-cache.h>
42 * Responsible for managing the resources used by a GlyphAtlas.
44 * - Texture for holding the atlas
45 * - GlyphSets for uploading glyphs to a Texture.
47 * It implements the GlyphLoadObserver interface, so that resource-client
48 * can inform it when glyphs are loaded.
50 class GlyphResourceManager : public GlyphLoadObserver
57 * @param[in] fontLookup font lookup interface
59 GlyphResourceManager( const FontLookupInterface& fontLookup );
64 virtual ~GlyphResourceManager();
67 * Create a texture which can be used to upload character bitmaps to.
68 * @param[in] size the width and height of the square texture
69 * @return texture resource id
71 unsigned int CreateTexture(unsigned int size );
74 * Add a glyph resource observer
75 * @param[in] observer The observer to add.
77 void AddObserver( GlyphResourceObserver& observer);
80 * Remove a glyph resource observer.
81 * @param[in] observer The observer to remove.
83 void RemoveObserver( GlyphResourceObserver& observer);
86 * Adds a text observer.
87 * The observer will get a call back whenever new text is loaded.
88 * The observer is responsible for calling RemoveObserver() when
89 * all it's text is loaded or before destruction
90 * @param[in] observer The observer to add.
92 void AddTextObserver( TextObserver& observer );
95 * Removes a text observer.
96 * @param[in] observer The observer to remove.
98 void RemoveTextObserver( TextObserver& observer );
101 * Adds a texture observer, to detect atlas resize / split changes
102 * @param[in] observer The observer to add.
104 void AddTextureObserver( GlyphTextureObserver& observer);
107 * Removes a texture observer
108 * @param[in] observer The texture observer to remove.
110 void RemoveTextureObserver( GlyphTextureObserver& observer);
113 * Add a list of requests to load glyphs
114 * @param[in] request list glyph request list
115 * @param[in] observer the observer that sent the request
116 * @param[in] atlasTextureId the texture ID of the atlas
118 void AddRequests( const GlyphRequestList& requestList, GlyphResourceObserver& observer,
119 Integration::ResourceId atlasTextureId );
121 public: // for GlyphLoadObserver
124 * @copydoc GlyphLoadObserver::GlyphsLoaded()
126 virtual void GlyphsLoaded( Integration::ResourceId id, const Integration::GlyphSet& glyphSet, Integration::LoadStatus loadStatus );
131 * Send resource requests to load glyphs.
132 * @param[in]request glyph resource request
133 * @param[in] observer glyph resource observer
134 * @param[in] atlasTextureId the texture ID of the atlas
136 void SendRequests( const GlyphResourceRequest& request, GlyphResourceObserver& observer,
137 Integration::ResourceId atlasTextureId );
139 * Upload a glyphset to a texture
140 * @param[in] observer glyph resource observer
141 * @param[in] fontId font id
142 * @param[in] glyphSet glyph set (contains the bitmaps to upload)
144 void UploadGlyphsToTexture( GlyphResourceObserver* observer,
146 const Integration::GlyphSet& glyphSet );
149 * Notify text observers that some characters have been loaded
151 void NotifyTextObservers();
154 * notify texture observers, that a texture has been replaced
155 * @param[in] oldTextureIds list of old texture id's that have been replaced by the new texture id
156 * @paran[in] newTextureId new texture id
158 void NotifyTextureReplaced( TextureIdList& oldTextureIds, unsigned int newTextureId);
161 * New atlas texture has been updated - delete old textures.
162 * @param[in] observer glyph resource observer
164 void DeleteOldTextures( GlyphResourceObserver* observer );
171 GLYPH_LOADED_FROM_FILE, ///< loaded from file
172 GLYPH_UPLOADED_TO_GL, ///< uploaded to gl
176 * update a glyph observer to say whether either the glyphs have been
177 * loaded from file, or have been uploaded to gl.
178 * @param[in] observer glyph resource observer
179 * @param[in] fontId font id
180 * @param[in] glyphSet glyph set
181 * @param[in] updateType glyph update type
183 void UpdateObserver( GlyphResourceObserver* observer,
185 const Integration::GlyphSet& glyphSet,
186 GlyphUpdateType updateType);
190 * Given a resource id, return the observer watching that resource
191 * @param[in] id resource id
192 * @return glyph resource observer
194 GlyphResourceObserver* GetObserver( Integration::ResourceId id );
197 * Delete a texture ticket
198 * @param[in] id texture id
200 void DeleteTextureTicket(unsigned int id );
203 * Convert between GlyphQuality enum and integration TextQuality
204 * @param[in] quality GlyphQuality
205 * @return integration TextQuality
207 Integration::TextResourceType::TextQuality GetQuality( GlyphResourceRequest::GlyphQuality quality );
210 // Undefined copy constructor.
211 GlyphResourceManager( const GlyphResourceManager& );
213 // Undefined assignment operator.
214 GlyphResourceManager& operator=( const GlyphResourceManager& );
217 typedef std::pair< ResourceTicketPtr, GlyphResourceObserver* > ObserverTicketPair; ///< ticket & observer pair
218 typedef std::map< Integration::ResourceId, ObserverTicketPair > TicketList; ///< key = resource id = key, data = ticket+observer
219 typedef std::list< ResourceTicketPtr > TextureTickets; ///< list of texture tickets
220 typedef std::set<GlyphResourceObserver*> ObserverList; ///< Observer list typedef
221 typedef std::set<TextObserver*> TextObserverList;
223 ObserverList mObservers; ///< unique set of glyph observers
224 TextObserverList mTextObservers; ///< unique set of text observers
225 TicketList mGlyphLoadTickets; ///< list of tickets for glyphset load requests
226 TextureTickets mTextureTickets; ///< list of tickets for texture requests
227 const FontLookupInterface& mFontLookup; ///< font lookup
228 ResourceClient& mResourceClient; ///< resource client
231 } // namespace Internal
235 #endif // __DALI_INTERNAL_GLYPH_RESOURCE_MANAGER_H__