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.
23 #include <dali/public-api/common/map-wrapper.h>
24 #include <dali/internal/event/text/glyph-status/glyph-status.h>
25 #include <dali/internal/event/text/resource/glyph-resource-observer.h>
26 #include <dali/internal/event/text/resource/glyph-resource-request.h>
27 #include <dali/internal/event/text/resource/glyph-load-observer.h>
28 #include <dali/internal/event/text/resource/font-lookup-interface.h>
29 #include <dali/internal/event/text/resource/glyph-texture-observer.h>
30 #include <dali/internal/event/text/text-observer.h>
31 #include <dali/internal/event/resources/resource-ticket.h>
32 #include <dali/integration-api/resource-cache.h>
46 * Responsible for managing the resources used by a GlyphAtlas.
48 * - Texture for holding the atlas
49 * - GlyphSets for uploading glyphs to a Texture.
51 * It implements the GlyphLoadObserver interface, so that resource-client
52 * can inform it when glyphs are loaded.
54 class GlyphResourceManager : public GlyphLoadObserver
61 * @param[in] fontLookup font lookup interface
63 GlyphResourceManager( const FontLookupInterface& fontLookup );
68 virtual ~GlyphResourceManager();
71 * Create a texture which can be used to upload character bitmaps to.
72 * @param[in] size the width and height of the square texture
73 * @return texture resource id
75 unsigned int CreateTexture(unsigned int size );
78 * Add a glyph resource observer
79 * @param[in] observer The observer to add.
81 void AddObserver( GlyphResourceObserver& observer);
84 * Remove a glyph resource observer.
85 * @param[in] observer The observer to remove.
87 void RemoveObserver( GlyphResourceObserver& observer);
90 * Adds a text observer.
91 * The observer will get a call back whenever new text is loaded.
92 * The observer is responsible for calling RemoveObserver() when
93 * all it's text is loaded or before destruction
94 * @param[in] observer The observer to add.
96 void AddTextObserver( TextObserver& observer );
99 * Removes a text observer.
100 * @param[in] observer The observer to remove.
102 void RemoveTextObserver( TextObserver& observer );
105 * Adds a texture observer, to detect atlas resize / split changes
106 * @param[in] observer The observer to add.
108 void AddTextureObserver( GlyphTextureObserver& observer);
111 * Removes a texture observer
112 * @param[in] observer The texture observer to remove.
114 void RemoveTextureObserver( GlyphTextureObserver& observer);
117 * Add a list of requests to load glyphs
118 * @param[in] request list glyph request list
119 * @param[in] observer the observer that sent the request
120 * @param[in] atlasTextureId the texture ID of the atlas
122 void AddRequests( const GlyphRequestList& requestList, GlyphResourceObserver& observer,
123 Integration::ResourceId atlasTextureId );
125 public: // for GlyphLoadObserver
128 * @copydoc GlyphLoadObserver::GlyphsLoaded()
130 virtual void GlyphsLoaded( Integration::ResourceId id, const Integration::GlyphSet& glyphSet, Integration::LoadStatus loadStatus );
135 * Send resource requests to load glyphs.
136 * @param[in]request glyph resource request
137 * @param[in] observer glyph resource observer
138 * @param[in] atlasTextureId the texture ID of the atlas
140 void SendRequests( const GlyphResourceRequest& request, GlyphResourceObserver& observer,
141 Integration::ResourceId atlasTextureId );
143 * Upload a glyphset to a texture
144 * @param[in] observer glyph resource observer
145 * @param[in] fontId font id
146 * @param[in] glyphSet glyph set (contains the bitmaps to upload)
148 void UploadGlyphsToTexture( GlyphResourceObserver* observer,
150 const Integration::GlyphSet& glyphSet );
153 * Notify text observers that some characters have been loaded
155 void NotifyTextObservers();
158 * notify texture observers, that a texture has been replaced
159 * @param[in] oldTextureIds list of old texture id's that have been replaced by the new texture id
160 * @paran[in] newTextureId new texture id
162 void NotifyTextureReplaced( TextureIdList& oldTextureIds, unsigned int newTextureId);
165 * New atlas texture has been updated - delete old textures.
166 * @param[in] observer glyph resource observer
168 void DeleteOldTextures( GlyphResourceObserver* observer );
175 GLYPH_LOADED_FROM_FILE, ///< loaded from file
176 GLYPH_UPLOADED_TO_GL, ///< uploaded to gl
180 * update a glyph observer to say whether either the glyphs have been
181 * loaded from file, or have been uploaded to gl.
182 * @param[in] observer glyph resource observer
183 * @param[in] fontId font id
184 * @param[in] glyphSet glyph set
185 * @param[in] updateType glyph update type
187 void UpdateObserver( GlyphResourceObserver* observer,
189 const Integration::GlyphSet& glyphSet,
190 GlyphUpdateType updateType);
194 * Given a resource id, return the observer watching that resource
195 * @param[in] id resource id
196 * @return glyph resource observer
198 GlyphResourceObserver* GetObserver( Integration::ResourceId id );
201 * Delete a texture ticket
202 * @param[in] id texture id
204 void DeleteTextureTicket(unsigned int id );
207 * Convert between GlyphQuality enum and integration TextQuality
208 * @param[in] quality GlyphQuality
209 * @return integration TextQuality
211 Integration::TextResourceType::TextQuality GetQuality( GlyphResourceRequest::GlyphQuality quality );
214 // Undefined copy constructor.
215 GlyphResourceManager( const GlyphResourceManager& );
217 // Undefined assignment operator.
218 GlyphResourceManager& operator=( const GlyphResourceManager& );
221 typedef std::pair< ResourceTicketPtr, GlyphResourceObserver* > ObserverTicketPair; ///< ticket & observer pair
222 typedef std::map< Integration::ResourceId, ObserverTicketPair > TicketList; ///< key = resource id = key, data = ticket+observer
223 typedef std::list< ResourceTicketPtr > TextureTickets; ///< list of texture tickets
224 typedef std::set<GlyphResourceObserver*> ObserverList; ///< Observer list typedef
225 typedef std::set<TextObserver*> TextObserverList;
227 ObserverList mObservers; ///< unique set of glyph observers
228 TextObserverList mTextObservers; ///< unique set of text observers
229 TicketList mGlyphLoadTickets; ///< list of tickets for glyphset load requests
230 TextureTickets mTextureTickets; ///< list of tickets for texture requests
231 const FontLookupInterface& mFontLookup; ///< font lookup
232 ResourceClient& mResourceClient; ///< resource client
235 } // namespace Internal
239 #endif // __DALI_INTERNAL_GLYPH_RESOURCE_MANAGER_H__