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 |
11 #include "GrAllocPool.h" | 11 #include "GrAllocPool.h" |
| 12 #include "GrAtlas.h" |
12 #include "GrTHashTable.h" | 13 #include "GrTHashTable.h" |
13 #include "GrPictureUtils.h" | 14 #include "GrPictureUtils.h" |
14 #include "GrRect.h" | 15 #include "GrRect.h" |
15 | 16 |
16 class GrAtlasMgr; | |
17 class GrGpu; | 17 class GrGpu; |
18 class GrPlot; | |
19 class SkPicture; | 18 class SkPicture; |
20 | 19 |
21 // GrAtlasLocation captures an atlased item's position in the atlas. This | 20 // GrAtlasLocation captures an atlased item's position in the atlas. This |
22 // means the plot in which it resides and its bounds inside the plot. | 21 // means the plot in which it resides and its bounds inside the plot. |
23 // TODO: Make GrGlyph use one of these? | 22 // TODO: Make GrGlyph use one of these? |
24 class GrAtlasLocation { | 23 class GrAtlasLocation { |
25 public: | 24 public: |
26 GrAtlasLocation() : fPlot(NULL) {} | 25 GrAtlasLocation() : fPlot(NULL) {} |
27 | 26 |
28 void set(GrPlot* plot, const GrIRect16& bounds) { | 27 void set(GrPlot* plot, const GrIRect16& bounds) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 89 |
91 // The GrLayerCache caches pre-computed saveLayers for later rendering. | 90 // The GrLayerCache caches pre-computed saveLayers for later rendering. |
92 // Non-atlased layers are stored in their own GrTexture while the atlased | 91 // Non-atlased layers are stored in their own GrTexture while the atlased |
93 // layers share a single GrTexture. | 92 // layers share a single GrTexture. |
94 // Unlike the GrFontCache, the GrTexture atlas only has one GrAtlasMgr (for 8888
) | 93 // Unlike the GrFontCache, the GrTexture atlas only has one GrAtlasMgr (for 8888
) |
95 // and one GrPlot (for the entire atlas). As such, the GrLayerCache | 94 // and one GrPlot (for the entire atlas). As such, the GrLayerCache |
96 // roughly combines the functionality of the GrFontCache and GrTextStrike | 95 // roughly combines the functionality of the GrFontCache and GrTextStrike |
97 // classes. | 96 // classes. |
98 class GrLayerCache { | 97 class GrLayerCache { |
99 public: | 98 public: |
100 GrLayerCache(GrGpu*); | 99 GrLayerCache(GrContext*); |
101 ~GrLayerCache(); | 100 ~GrLayerCache(); |
102 | 101 |
| 102 // As a cache, the GrLayerCache can be ordered to free up all its cached |
| 103 // elements by the GrContext |
103 void freeAll(); | 104 void freeAll(); |
104 | 105 |
105 GrCachedLayer* findLayerOrCreate(const SkPicture* picture, int id); | 106 GrCachedLayer* findLayer(const SkPicture* picture, int layerID); |
| 107 GrCachedLayer* findLayerOrCreate(const SkPicture* picture, int layerID); |
| 108 |
| 109 // Inform the cache that layer's cached image is now required. Return true |
| 110 // if it was found in the ResourceCache and doesn't need to be regenerated. |
| 111 // If false is returned the caller should (re)render the layer into the |
| 112 // newly acquired texture. |
| 113 bool lock(GrCachedLayer* layer, const GrTextureDesc& desc); |
| 114 |
| 115 // Inform the cache that layer's cached image is not currently required |
| 116 void unlock(GrCachedLayer* layer); |
106 | 117 |
107 private: | 118 private: |
108 SkAutoTUnref<GrGpu> fGpu; | 119 GrContext* fContext; // pointer back to owning context |
109 SkAutoTDelete<GrAtlasMgr> fAtlasMgr; // TODO: could lazily allocate | 120 SkAutoTDelete<GrAtlasMgr> fAtlasMgr; // TODO: could lazily allocate |
| 121 GrAtlas fPlotUsage; |
110 | 122 |
111 class PictureLayerKey; | 123 class PictureLayerKey; |
112 GrTHashTable<GrCachedLayer, PictureLayerKey, 7> fLayerHash; | 124 GrTHashTable<GrCachedLayer, PictureLayerKey, 7> fLayerHash; |
113 GrTAllocPool<GrCachedLayer> fLayerPool; | 125 GrTAllocPool<GrCachedLayer> fLayerPool; |
114 | 126 |
115 void init(); | 127 void init(); |
116 GrCachedLayer* createLayer(const SkPicture* picture, int id); | 128 GrCachedLayer* createLayer(const SkPicture* picture, int layerID); |
117 | |
118 }; | 129 }; |
119 | 130 |
120 #endif | 131 #endif |
OLD | NEW |