Fix code to not include std set directly
[platform/core/uifw/dali-core.git] / dali / internal / event / text / resource / glyph-resource-manager.h
1 #ifndef __DALI_INTERNAL_GLYPH_RESOURCE_MANAGER_H__
2 #define __DALI_INTERNAL_GLYPH_RESOURCE_MANAGER_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
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
10 //
11 //     http://floralicense.org/license/
12 //
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.
18 //
19
20 // INTERNAL INCLUDES
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>
32
33 namespace Dali
34 {
35
36 namespace Internal
37 {
38
39 class ResourceClient;
40
41 /**
42  * Responsible for managing the resources used by a GlyphAtlas.
43  * This includes
44  * - Texture for holding the atlas
45  * - GlyphSets for uploading glyphs to a Texture.
46  *
47  * It implements the GlyphLoadObserver interface, so that resource-client
48  * can inform it when glyphs are loaded.
49  */
50 class GlyphResourceManager : public GlyphLoadObserver
51 {
52
53 public:
54
55   /**
56    * Constructor
57    * @param[in] fontLookup font lookup interface
58    */
59   GlyphResourceManager( const FontLookupInterface& fontLookup );
60
61   /**
62    * Destructor
63    */
64   virtual ~GlyphResourceManager();
65
66   /**
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
70    */
71  unsigned int CreateTexture(unsigned int size );
72
73   /**
74    * Add a glyph resource observer
75    * @param[in] observer The observer to add.
76    */
77   void AddObserver( GlyphResourceObserver& observer);
78
79   /**
80    * Remove a glyph resource observer.
81    * @param[in] observer The observer to remove.
82    */
83   void RemoveObserver( GlyphResourceObserver& observer);
84
85   /**
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.
91    */
92   void AddTextObserver( TextObserver& observer );
93
94   /**
95    * Removes a text observer.
96    * @param[in] observer The observer to remove.
97    */
98   void RemoveTextObserver( TextObserver& observer );
99
100   /**
101    * Adds a texture observer, to detect atlas resize / split changes
102    * @param[in] observer The observer to add.
103    */
104   void AddTextureObserver( GlyphTextureObserver& observer);
105
106   /**
107    * Removes a texture observer
108    * @param[in] observer The texture observer to remove.
109    */
110   void RemoveTextureObserver( GlyphTextureObserver& observer);
111
112   /**
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
117    */
118   void AddRequests( const GlyphRequestList& requestList, GlyphResourceObserver& observer,
119                     Integration::ResourceId atlasTextureId );
120
121 public: // for GlyphLoadObserver
122
123   /**
124    * @copydoc GlyphLoadObserver::GlyphsLoaded()
125    */
126   virtual void GlyphsLoaded( Integration::ResourceId id, const Integration::GlyphSet& glyphSet, Integration::LoadStatus loadStatus  );
127
128 private:
129
130   /**
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
135    */
136   void SendRequests( const GlyphResourceRequest& request, GlyphResourceObserver& observer,
137                      Integration::ResourceId atlasTextureId );
138   /**
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)
143    */
144   void UploadGlyphsToTexture( GlyphResourceObserver* observer,
145                               FontId fontId,
146                               const Integration::GlyphSet& glyphSet  );
147
148   /**
149    * Notify text observers that some characters have been loaded
150    */
151   void NotifyTextObservers();
152
153   /**
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
157    */
158   void NotifyTextureReplaced( TextureIdList& oldTextureIds, unsigned int newTextureId);
159
160   /**
161    * New atlas texture has been updated - delete old textures.
162    * @param[in] observer glyph resource observer
163    */
164   void DeleteOldTextures( GlyphResourceObserver* observer );
165
166   /**
167    * glyph update type
168    */
169   enum GlyphUpdateType
170   {
171     GLYPH_LOADED_FROM_FILE, ///< loaded from file
172     GLYPH_UPLOADED_TO_GL,   ///< uploaded to gl
173   };
174
175   /**
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
182    */
183   void UpdateObserver( GlyphResourceObserver* observer,
184                        FontId fontId,
185                        const Integration::GlyphSet& glyphSet,
186                        GlyphUpdateType updateType);
187
188
189   /**
190    * Given a resource id, return the observer watching that resource
191    * @param[in] id resource id
192    * @return glyph resource observer
193    */
194   GlyphResourceObserver* GetObserver( Integration::ResourceId id );
195
196   /**
197    * Delete a texture ticket
198    * @param[in] id texture id
199    */
200   void DeleteTextureTicket(unsigned int id );
201
202   /**
203    * Convert between GlyphQuality enum and integration TextQuality
204    * @param[in] quality GlyphQuality
205    * @return integration TextQuality
206    */
207   Integration::TextResourceType::TextQuality GetQuality( GlyphResourceRequest::GlyphQuality quality );
208
209
210   // Undefined copy constructor.
211   GlyphResourceManager( const GlyphResourceManager& );
212
213   // Undefined assignment operator.
214   GlyphResourceManager& operator=( const GlyphResourceManager& );
215
216
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;
222
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
229 };
230
231 } // namespace Internal
232
233 } // namespace Dali
234
235 #endif // __DALI_INTERNAL_GLYPH_RESOURCE_MANAGER_H__