OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrLayerCache_DEFINED | 8 #ifndef GrLayerCache_DEFINED |
9 #define GrLayerCache_DEFINED | 9 #define GrLayerCache_DEFINED |
10 | 10 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // For atlased layers, 'fLocked' is true if the layer is in a plot and | 134 // For atlased layers, 'fLocked' is true if the layer is in a plot and |
135 // actively required for rendering. If the layer is in a plot but not | 135 // actively required for rendering. If the layer is in a plot but not |
136 // actively required for rendering, then 'fLocked' is false. If the | 136 // actively required for rendering, then 'fLocked' is false. If the |
137 // layer isn't in a plot then is can never be locked. | 137 // layer isn't in a plot then is can never be locked. |
138 bool fLocked; | 138 bool fLocked; |
139 }; | 139 }; |
140 | 140 |
141 // The GrLayerCache caches pre-computed saveLayers for later rendering. | 141 // The GrLayerCache caches pre-computed saveLayers for later rendering. |
142 // Non-atlased layers are stored in their own GrTexture while the atlased | 142 // Non-atlased layers are stored in their own GrTexture while the atlased |
143 // layers share a single GrTexture. | 143 // layers share a single GrTexture. |
144 // Unlike the GrFontCache, the GrTexture atlas only has one GrAtlas (for 8888) | 144 // |
145 // and one GrPlot (for the entire atlas). As such, the GrLayerCache | 145 // The Layer Cache uses four plots for atlasing. It attempts to devote a single
plot to |
146 // roughly combines the functionality of the GrFontCache and GrTextStrike | 146 // each picture but does allow sharing if a particular picture requires more |
147 // classes. | 147 // space. This is accomplished by: |
| 148 // If the picture already has plots |
| 149 // check its current plots for space - if they do return the new location |
| 150 // else (the picture is new or an existing picture which needs more space): |
| 151 // if there is an empty plot devote it to the picture |
| 152 // failing that find the emptiest plot and devote it to the picture |
| 153 // failing that (the atlas is full): |
| 154 // Loop through the plots that aren't currently used by the picture in
LRU order |
| 155 // If all the layers are unlocked: |
| 156 // delete them all, clear the rectanizer and devote the plot to the
picture |
| 157 // failing that - indicate that the atlas is full |
| 158 // |
| 159 // In order to purge a given picture: |
| 160 // Each plot used by the picture is considered. |
| 161 // If all the layers in the plot are unlocked then they are all removed and |
| 162 // the plot's rectanizer is reset. This can result in some layers owned |
| 163 // by other pictures being ejected! |
| 164 // If not all the layers are unlocked then just the purged picture's layers |
| 165 // are removed and the rectanizer isn't reset. This can lead to a lot |
| 166 // of wasted space in the plot! |
148 class GrLayerCache { | 167 class GrLayerCache { |
149 public: | 168 public: |
150 GrLayerCache(GrContext*); | 169 GrLayerCache(GrContext*); |
151 ~GrLayerCache(); | 170 ~GrLayerCache(); |
152 | 171 |
153 // As a cache, the GrLayerCache can be ordered to free up all its cached | 172 // As a cache, the GrLayerCache can be ordered to free up all its cached |
154 // elements by the GrContext | 173 // elements by the GrContext |
155 void freeAll(); | 174 void freeAll(); |
156 | 175 |
157 GrCachedLayer* findLayer(const SkPicture* picture, int layerID); | 176 GrCachedLayer* findLayer(const SkPicture* picture, int layerID); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 // Try to find a purgeable plot and clear it out. Return true if a plot | 240 // Try to find a purgeable plot and clear it out. Return true if a plot |
222 // was purged; false otherwise. | 241 // was purged; false otherwise. |
223 bool purgePlot(); | 242 bool purgePlot(); |
224 | 243 |
225 // for testing | 244 // for testing |
226 friend class TestingAccess; | 245 friend class TestingAccess; |
227 int numLayers() const { return fLayerHash.count(); } | 246 int numLayers() const { return fLayerHash.count(); } |
228 }; | 247 }; |
229 | 248 |
230 #endif | 249 #endif |
OLD | NEW |