| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // ref on a GrTexture for non-atlased textures. In both cases, if this is | 83 // ref on a GrTexture for non-atlased textures. In both cases, if this is |
| 84 // non-NULL, that means that the texture is locked in the texture cache. | 84 // non-NULL, that means that the texture is locked in the texture cache. |
| 85 GrTexture* fTexture; | 85 GrTexture* fTexture; |
| 86 | 86 |
| 87 GrAtlasLocation fLocation; // only valid if the layer is atlased | 87 GrAtlasLocation fLocation; // only valid if the layer is atlased |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 // The GrLayerCache caches pre-computed saveLayers for later rendering. | 90 // The GrLayerCache caches pre-computed saveLayers for later rendering. |
| 91 // 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 |
| 92 // layers share a single GrTexture. | 92 // layers share a single GrTexture. |
| 93 // Unlike the GrFontCache, the GrTexture atlas only has one GrAtlasMgr (for 8888
) | 93 // Unlike the GrFontCache, the GrTexture atlas only has one GrAtlas (for 8888) |
| 94 // and one GrPlot (for the entire atlas). As such, the GrLayerCache | 94 // and one GrPlot (for the entire atlas). As such, the GrLayerCache |
| 95 // roughly combines the functionality of the GrFontCache and GrTextStrike | 95 // roughly combines the functionality of the GrFontCache and GrTextStrike |
| 96 // classes. | 96 // classes. |
| 97 class GrLayerCache { | 97 class GrLayerCache { |
| 98 public: | 98 public: |
| 99 GrLayerCache(GrContext*); | 99 GrLayerCache(GrContext*); |
| 100 ~GrLayerCache(); | 100 ~GrLayerCache(); |
| 101 | 101 |
| 102 // As a cache, the GrLayerCache can be ordered to free up all its cached | 102 // As a cache, the GrLayerCache can be ordered to free up all its cached |
| 103 // elements by the GrContext | 103 // elements by the GrContext |
| 104 void freeAll(); | 104 void freeAll(); |
| 105 | 105 |
| 106 GrCachedLayer* findLayer(const SkPicture* picture, int layerID); | 106 GrCachedLayer* findLayer(const SkPicture* picture, int layerID); |
| 107 GrCachedLayer* findLayerOrCreate(const SkPicture* picture, int layerID); | 107 GrCachedLayer* findLayerOrCreate(const SkPicture* picture, int layerID); |
| 108 | 108 |
| 109 // Inform the cache that layer's cached image is now required. Return true | 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. | 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 | 111 // If false is returned the caller should (re)render the layer into the |
| 112 // newly acquired texture. | 112 // newly acquired texture. |
| 113 bool lock(GrCachedLayer* layer, const GrTextureDesc& desc); | 113 bool lock(GrCachedLayer* layer, const GrTextureDesc& desc); |
| 114 | 114 |
| 115 // Inform the cache that layer's cached image is not currently required | 115 // Inform the cache that layer's cached image is not currently required |
| 116 void unlock(GrCachedLayer* layer); | 116 void unlock(GrCachedLayer* layer); |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 GrContext* fContext; // pointer back to owning context | 119 GrContext* fContext; // pointer back to owning context |
| 120 SkAutoTDelete<GrAtlasMgr> fAtlasMgr; // TODO: could lazily allocate | 120 SkAutoTDelete<GrAtlas> fAtlas; // TODO: could lazily allocate |
| 121 GrAtlas fPlotUsage; | 121 GrAtlas::ClientPlotUsage fPlotUsage; |
| 122 | 122 |
| 123 class PictureLayerKey; | 123 class PictureLayerKey; |
| 124 GrTHashTable<GrCachedLayer, PictureLayerKey, 7> fLayerHash; | 124 GrTHashTable<GrCachedLayer, PictureLayerKey, 7> fLayerHash; |
| 125 GrTAllocPool<GrCachedLayer> fLayerPool; | 125 GrTAllocPool<GrCachedLayer> fLayerPool; |
| 126 | 126 |
| 127 void init(); | 127 void init(); |
| 128 GrCachedLayer* createLayer(const SkPicture* picture, int layerID); | 128 GrCachedLayer* createLayer(const SkPicture* picture, int layerID); |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 #endif | 131 #endif |
| OLD | NEW |