License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-core.git] / dali / internal / event / text / atlas / glyph-atlas-manager.h
1 #ifndef __DALI_INTERNAL_GLYPH_ATLAS_MANAGER_H__
2 #define __DALI_INTERNAL_GLYPH_ATLAS_MANAGER_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
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
21 // INTERNAL INCLUDES
22 #include <dali/internal/common/text-array.h>
23 #include <dali/internal/common/owner-container.h>
24 #include <dali/internal/event/text/font-metrics-interface.h>
25 #include <dali/internal/event/text/atlas/glyph-atlas.h>
26 #include <dali/internal/event/text/resource/glyph-texture-observer.h>
27 #include <dali/internal/event/text/resource/glyph-resource-manager.h>
28 #include <dali/internal/event/text/atlas/glyph-atlas-manager-interface.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 /**
37  *
38  * Glyph atlas manager does the following:
39  * - Creates Atlases
40  * - Resizes Atlases
41  * - Finds the best atlas given a string of text
42  *
43  * GlyphAtlasManagerInterface provides:
44  *
45  * - Text Vertex creation from a string of text
46  * - Allows observers to watch for text load events
47  * - Allows observers to watch for texture resize events.
48  */
49 class GlyphAtlasManager: public GlyphAtlasManagerInterface
50 {
51 public:
52
53   /**
54    * constructor
55    * @param[in] fontLookup font lookup interface
56    */
57   GlyphAtlasManager( const FontLookupInterface& fontLookup  );
58
59   /**
60    * destructor
61    */
62   virtual ~GlyphAtlasManager();
63
64
65 public: // for GlyphAtlasManagerInterface
66
67   /**
68    * @copydoc GlyphAtlasManagerInterface::TextRequired()
69    */
70   virtual TextVertexBuffer* TextRequired( const TextArray& text,
71                                           const TextFormat& format,
72                                           FontMetricsInterface& metrics );
73
74   /**
75    * @copydoc GlyphAtlasManagerInterface::TextNotRequired()
76    */
77   virtual void TextNotRequired( const TextArray& text,
78                                 const TextFormat& format,
79                                 FontId font,
80                                 unsigned int textureId );
81
82   /**
83    * @copydoc GlyphAtlasManagerInterface::IsTextLoaded()
84    */
85   virtual bool IsTextLoaded( const TextArray& text,
86                              const TextFormat& format,
87                              FontId fontId,
88                              unsigned int textureId) const;
89
90   /**
91    * @copydoc GlyphAtlasManagerInterface::AddTextObserver()
92    */
93   virtual void AddTextObserver( TextObserver& observer );
94
95   /**
96    * @copydoc GlyphAtlasManagerInterface::RemoveTextObserver()
97    */
98   virtual void RemoveTextObserver( TextObserver& observer );
99
100   /**
101    * @copydoc GlyphAtlasManagerInterface::AddObserver()
102    */
103   virtual void AddTextureObserver( GlyphTextureObserver& observer);
104
105   /**
106    * @copydoc GlyphAtlasManagerInterface::RemoveObserver()
107    */
108   virtual void RemoveTextureObserver( GlyphTextureObserver& observer);
109
110 public:
111
112   /**
113    * Send any pending glyph load requests held in each atlas to the resource manager.
114    */
115   void SendTextRequests();
116
117   /**
118    * @return glyph load observer interface
119    */
120   GlyphLoadObserver& GetLoadObserver();
121
122 private:
123
124   // Undefined copy constructor.
125   GlyphAtlasManager( const GlyphAtlasManager& );
126
127   // Undefined assignment operator.
128   GlyphAtlasManager& operator=( const GlyphAtlasManager& );
129
130   /**
131    * Creates a new atlas
132    * @param[in] size the atlas size in pixels (size = width = height)
133    * @return atlas
134    */
135   GlyphAtlas* CreateAtlas( unsigned int size );
136
137   /**
138    * Find the most suitable atlas for a string of text
139    * @param[in] text text array
140    * @param[in] format text format
141    * @param[in] font id
142    * @param[in,out] the ranking for the atlas that is found
143    * @return atlas
144    */
145   GlyphAtlas* FindAtlas( const TextArray& text ,
146                          const TextFormat& format,
147                          FontId fontId,
148                          AtlasRanking& bestRank);
149
150   /**
151    * Add an atlas
152    * @param[in] atlas to add
153    */
154   void AddAtlas( GlyphAtlas* atlas);
155
156   /**
157    * Remove an atlas
158    * @param[in] atlas the atlas to remove
159    */
160   void RemoveAtlas( GlyphAtlas* atlas  );
161
162   /**
163    * Get an atlas given a texture id
164    * @param[in] textureId
165    * @return atlas
166    */
167   GlyphAtlas& GetAtlas( unsigned int textureId ) const;
168
169   /**
170    * Takes an atlas and returns a bigger version.
171    * The old atlas is deleted.
172    * @param atlas the atlas to make bigger
173    * @returns a bigger atlas
174    */
175   GlyphAtlas* CreateLargerAtlas( GlyphAtlas* atlas );
176
177   /**
178    * Notify atlas observers that the texture has changed. Note, this no longer means
179    * that the glyphs are present.
180    */
181   void NotifyAtlasObservers();
182
183
184   typedef OwnerContainer< GlyphAtlas* >         AtlasList;  ///< atlas list typedef
185   typedef Dali::Vector< GlyphTextureObserver* > TextureObserverList; ///< list of observers that get informed when an atlas is resized / split
186
187   AtlasList                         mAtlasList;             ///< List of atlases
188   GlyphResourceManager              mGlyphResourceManager;  ///< glyph resource manager
189   TextureObserverList               mTextureObservers;      ///< unique set of observers that watch texture resize / split changes
190   bool                              mAtlasesChanged;        ///< Set to true if any atlas is resized, used to notify observers at end of event cycle
191 };
192
193 } // namespace Internal
194
195 } // namespace Dali
196
197 #endif // __DALI_INTERNAL_GLYPH_ATLAS_MANAGER_H__