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 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.
22 #include <dali/public-api/common/map-wrapper.h>
23 #include <dali/public-api/common/set-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>
43 * Responsible for managing the resources used by a GlyphAtlas.
45 * - Texture for holding the atlas
46 * - GlyphSets for uploading glyphs to a Texture.
48 * It implements the GlyphLoadObserver interface, so that resource-client
49 * can inform it when glyphs are loaded.
51 class GlyphResourceManager : public GlyphLoadObserver
58 * @param[in] fontLookup font lookup interface
60 GlyphResourceManager( const FontLookupInterface& fontLookup );
65 virtual ~GlyphResourceManager();
68 * Create a texture which can be used to upload character bitmaps to.
69 * @param[in] size the width and height of the square texture
70 * @return texture resource id
72 unsigned int CreateTexture(unsigned int size );
75 * Add a glyph resource observer
76 * @param[in] observer The observer to add.
78 void AddObserver( GlyphResourceObserver& observer);
81 * Remove a glyph resource observer.
82 * @param[in] observer The observer to remove.
84 void RemoveObserver( GlyphResourceObserver& observer);
87 * Adds a text observer.
88 * The observer will get a call back whenever new text is loaded.
89 * The observer is responsible for calling RemoveObserver() when
90 * all it's text is loaded or before destruction
91 * @param[in] observer The observer to add.
93 void AddTextObserver( TextObserver& observer );
96 * Removes a text observer.
97 * @param[in] observer The observer to remove.
99 void RemoveTextObserver( TextObserver& observer );
102 * Adds a texture observer, to detect atlas resize / split changes
103 * @param[in] observer The observer to add.
105 void AddTextureObserver( GlyphTextureObserver& observer);
108 * Removes a texture observer
109 * @param[in] observer The texture observer to remove.
111 void RemoveTextureObserver( GlyphTextureObserver& observer);
114 * Add a list of requests to load glyphs
115 * @param[in] request list glyph request list
116 * @param[in] observer the observer that sent the request
117 * @param[in] atlasTextureId the texture ID of the atlas
119 void AddRequests( const GlyphRequestList& requestList, GlyphResourceObserver& observer,
120 Integration::ResourceId atlasTextureId );
122 public: // for GlyphLoadObserver
125 * @copydoc GlyphLoadObserver::GlyphsLoaded()
127 virtual void GlyphsLoaded( Integration::ResourceId id, const Integration::GlyphSet& glyphSet, Integration::LoadStatus loadStatus );
132 * Send resource requests to load glyphs.
133 * @param[in]request glyph resource request
134 * @param[in] observer glyph resource observer
135 * @param[in] atlasTextureId the texture ID of the atlas
137 void SendRequests( const GlyphResourceRequest& request, GlyphResourceObserver& observer,
138 Integration::ResourceId atlasTextureId );
140 * Upload a glyphset to a texture
141 * @param[in] observer glyph resource observer
142 * @param[in] fontId font id
143 * @param[in] glyphSet glyph set (contains the bitmaps to upload)
145 void UploadGlyphsToTexture( GlyphResourceObserver* observer,
147 const Integration::GlyphSet& glyphSet );
150 * Notify text observers that some characters have been loaded
152 void NotifyTextObservers();
155 * notify texture observers, that a texture has been replaced
156 * @param[in] oldTextureIds list of old texture id's that have been replaced by the new texture id
157 * @paran[in] newTextureId new texture id
159 void NotifyTextureReplaced( TextureIdList& oldTextureIds, unsigned int newTextureId);
162 * New atlas texture has been updated - delete old textures.
163 * @param[in] observer glyph resource observer
165 void DeleteOldTextures( GlyphResourceObserver* observer );
172 GLYPH_LOADED_FROM_FILE, ///< loaded from file
173 GLYPH_UPLOADED_TO_GL, ///< uploaded to gl
177 * update a glyph observer to say whether either the glyphs have been
178 * loaded from file, or have been uploaded to gl.
179 * @param[in] observer glyph resource observer
180 * @param[in] fontId font id
181 * @param[in] glyphSet glyph set
182 * @param[in] updateType glyph update type
184 void UpdateObserver( GlyphResourceObserver* observer,
186 const Integration::GlyphSet& glyphSet,
187 GlyphUpdateType updateType);
191 * Given a resource id, return the observer watching that resource
192 * @param[in] id resource id
193 * @return glyph resource observer
195 GlyphResourceObserver* GetObserver( Integration::ResourceId id );
198 * Delete a texture ticket
199 * @param[in] id texture id
201 void DeleteTextureTicket(unsigned int id );
204 * Convert between GlyphQuality enum and integration TextQuality
205 * @param[in] quality GlyphQuality
206 * @return integration TextQuality
208 Integration::TextResourceType::TextQuality GetQuality( GlyphResourceRequest::GlyphQuality quality );
211 // Undefined copy constructor.
212 GlyphResourceManager( const GlyphResourceManager& );
214 // Undefined assignment operator.
215 GlyphResourceManager& operator=( const GlyphResourceManager& );
218 typedef std::pair< ResourceTicketPtr, GlyphResourceObserver* > ObserverTicketPair; ///< ticket & observer pair
219 typedef std::map< Integration::ResourceId, ObserverTicketPair > TicketList; ///< key = resource id = key, data = ticket+observer
220 typedef std::list< ResourceTicketPtr > TextureTickets; ///< list of texture tickets
221 typedef std::set<GlyphResourceObserver*> ObserverList; ///< Observer list typedef
222 typedef std::set<TextObserver*> TextObserverList;
224 ObserverList mObservers; ///< unique set of glyph observers
225 TextObserverList mTextObservers; ///< unique set of text observers
226 TicketList mGlyphLoadTickets; ///< list of tickets for glyphset load requests
227 TextureTickets mTextureTickets; ///< list of tickets for texture requests
228 const FontLookupInterface& mFontLookup; ///< font lookup
229 ResourceClient& mResourceClient; ///< resource client
232 } // namespace Internal
236 #endif // __DALI_INTERNAL_GLYPH_RESOURCE_MANAGER_H__