FastUIDraw
glyph_atlas.hpp
Go to the documentation of this file.
1 /*!
2  * \file glyph_atlas.hpp
3  * \brief file glyph_atlas.hpp
4  *
5  * Copyright 2016 by Intel.
6  *
7  * Contact: kevin.rogovin@gmail.com
8  *
9  * This Source Code Form is subject to the
10  * terms of the Mozilla Public License, v. 2.0.
11  * If a copy of the MPL was not distributed with
12  * this file, You can obtain one at
13  * http://mozilla.org/MPL/2.0/.
14  *
15  * \author Kevin Rogovin <kevin.rogovin@gmail.com>
16  *
17  */
18 
19 
20 #ifndef FASTUIDRAW_GLYPH_ATLAS_HPP
21 #define FASTUIDRAW_GLYPH_ATLAS_HPP
22 
24 #include <fastuidraw/util/util.hpp>
25 #include <fastuidraw/util/vecN.hpp>
27 
28 namespace fastuidraw
29 {
30 /*!\addtogroup PainterBackend
31  * @{
32  */
33  /*!
34  * \brief
35  * GlyphAtlasStoreBase represents an interface to an aray of
36  * uint32_t values.
37  *
38  * An example implementation in GL would be a buffer object that backs
39  * a single usamplerBuffer. An implementation of the class does NOT need to be
40  * thread safe because the user of the backing store, \ref GlyphAtlas performs
41  * calls to the backing store behind its own mutex.
42  */
44  public reference_counted<GlyphAtlasBackingStoreBase>::concurrent
45  {
46  public:
47  virtual
49 
50  /*!
51  * Returns the number of uint32_t backed by the store.
52  */
53  unsigned int
54  size(void);
55 
56  /*!
57  * To be implemented by a derived class to load
58  * data into the store.
59  * \param location to load data
60  * \param pdata data to load
61  */
62  virtual
63  void
64  set_values(unsigned int location, c_array<const uint32_t> pdata) = 0;
65 
66  /*!
67  * To be implemented by a derived class to flush contents
68  * to the backing store.
69  */
70  virtual
71  void
72  flush(void) = 0;
73 
74  /*!
75  * Resize the object to a larger size.
76  * \param new_size new number of uint32_t for the store to back
77  */
78  void
79  resize(unsigned int new_size);
80 
81  protected:
82  /*!
83  * Ctor.
84  * \param psize number of uint32_t elements that the
85  GlyphAtlasBackingStoreBase backs
86  */
87  explicit
88  GlyphAtlasBackingStoreBase(unsigned int psize);
89 
90  /*!
91  * To be implemented by a derived class to resize the
92  * object. When called, the return value of size() is
93  * the size before the resize completes.
94  * \param new_size new number of int32_t for the store to back
95  */
96  virtual
97  void
98  resize_implement(unsigned int new_size) = 0;
99 
100  private:
101  void *m_d;
102  };
103 
104  /*!
105  * \brief
106  * A GlyphAtlas is a common location to place glyph data of
107  * an application. Ideally, all glyph data is placed into a
108  * single GlyphAtlas. Methods of GlyphAtlas are thread safe,
109  * protected behind atomics and a mutex within the GlyphAtlas.
110  */
111  class GlyphAtlas:
112  public reference_counted<GlyphAtlas>::concurrent
113  {
114  public:
115  /*!
116  * Ctor.
117  * \param pstore GlyphAtlasBackingStoreBase to which to store data
118  */
119  explicit
121 
122  virtual
123  ~GlyphAtlas();
124 
125  /*!
126  * Negative return value indicates failure.
127  */
128  int
129  allocate_data(c_array<const uint32_t> pdata);
130 
131  /*!
132  * Deallocate data
133  */
134  void
135  deallocate_data(int location, int count);
136 
137  /*!
138  * Returns how much data has been allocated
139  */
140  unsigned int
141  data_allocated(void);
142 
143  /*!
144  * Frees all allocated regions of this GlyphAtlas;
145  */
146  void
147  clear(void);
148 
149  /*!
150  * Returns the number of times that clear() has been called.
151  */
152  unsigned int
153  number_times_cleared(void) const;
154 
155  /*!
156  * Calls GlyphAtlasBackingStoreBase::flush() on
157  * the backing store (see store()).
158  */
159  void
160  flush(void) const;
161 
162  /*!
163  * Returns the store for this GlyphAtlas.
164  */
166  store(void) const;
167 
168  /*!
169  * Increments an internal counter. If this internal
170  * counter is greater than zero, then clear() and
171  * deallocate_data() are -delayed- until the counter
172  * reaches zero again (see unlock_resources()). The
173  * use case is for buffered painting where the GPU
174  * calls are delayed for later (to batch commands)
175  * and a clear() or deallocate_data() was issued
176  * during painting.
177  */
178  void
179  lock_resources(void);
180 
181  /*!
182  * Decrements an internal counter. If this internal
183  * counter reaches zero then any deallocate_data()
184  * and clear() calls are issued.
185  */
186  void
187  unlock_resources(void);
188 
189  private:
190  void *m_d;
191  };
192 /*! @} */
193 } //namespace fastuidraw
194 
195 #endif
A GlyphAtlas is a common location to place glyph data of an application. Ideally, all glyph data is p...
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
A wrapper over a pointer to implement reference counting.
virtual void set_values(unsigned int location, c_array< const uint32_t > pdata)=0
void resize(unsigned int new_size)
file c_array.hpp
GlyphAtlasStoreBase represents an interface to an aray of uint32_t values.
Definition: glyph_atlas.hpp:43
file util.hpp
file vecN.hpp
Defines default reference counting base classes.
GlyphAtlasBackingStoreBase(unsigned int psize)
virtual void resize_implement(unsigned int new_size)=0
file reference_counted.hpp