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 25 matching lines...) Expand all Loading... |
36 | 36 |
37 const GrIRect16& bounds() const { | 37 const GrIRect16& bounds() const { |
38 return fBounds; | 38 return fBounds; |
39 } | 39 } |
40 | 40 |
41 private: | 41 private: |
42 GrPlot* fPlot; | 42 GrPlot* fPlot; |
43 GrIRect16 fBounds; // only valid is fPlot != NULL | 43 GrIRect16 fBounds; // only valid is fPlot != NULL |
44 }; | 44 }; |
45 | 45 |
46 // A GrAtlasedLayer encapsulates the atlasing information for a single saveLayer
. | 46 // GrCachedLayer encapsulates the caching information for a single saveLayer. |
47 // It is roughly equivalent to a GrGlyph in the font caching system | 47 // |
48 class GrAtlasedLayer { | 48 // Atlased layers get a ref to their atlas GrTexture and their GrAtlasLocation |
| 49 // is filled in. |
| 50 // In this case GrCachedLayer is roughly equivalent to a GrGlyph in the font |
| 51 // caching system. |
| 52 // |
| 53 // Non-atlased layers get a ref to the GrTexture in which they reside. |
| 54 // TODO: can we easily reuse the empty space in the non-atlased GrTexture's? |
| 55 struct GrCachedLayer { |
49 public: | 56 public: |
50 GrAtlasedLayer() : fPictureID(SK_InvalidGenID) { } | |
51 | |
52 uint32_t pictureID() const { return fPictureID; } | 57 uint32_t pictureID() const { return fPictureID; } |
53 int layerID() const { return fLayerID; } | 58 int layerID() const { return fLayerID; } |
54 | 59 |
55 void init(uint32_t pictureID, int layerID) { | 60 void init(uint32_t pictureID, int layerID) { |
56 fPictureID = pictureID; | 61 fPictureID = pictureID; |
57 fLayerID = layerID; | 62 fLayerID = layerID; |
| 63 fTexture = NULL; |
| 64 fLocation.set(NULL, GrIRect16::MakeEmpty()); |
58 } | 65 } |
59 | 66 |
| 67 // This call takes over the caller's ref |
| 68 void setTexture(GrTexture* texture) { |
| 69 if (NULL != fTexture) { |
| 70 fTexture->unref(); |
| 71 } |
| 72 |
| 73 fTexture = texture; // just take over caller's ref |
| 74 } |
| 75 GrTexture* getTexture() { return fTexture; } |
| 76 |
60 private: | 77 private: |
61 uint32_t fPictureID; | 78 uint32_t fPictureID; |
62 int fLayerID; // only valid if fPicture != kInvalidGenID | 79 // fLayerID is only valid when fPicture != kInvalidGenID in which case it |
63 GrAtlasLocation fLocation; | 80 // is the index of this layer in the picture (one of 0 .. #layers). |
| 81 int fLayerID; |
| 82 |
| 83 // fTexture is a ref on the atlasing texture for atlased layers and a |
| 84 // ref on a GrTexture for non-atlased textures. In both cases, if this is |
| 85 // non-NULL, that means that the texture is locked in the texture cache. |
| 86 GrTexture* fTexture; |
| 87 |
| 88 GrAtlasLocation fLocation; // only valid if the layer is atlased |
64 }; | 89 }; |
65 | 90 |
66 // The GrLayerCache caches pre-computed saveLayers for later rendering. | 91 // The GrLayerCache caches pre-computed saveLayers for later rendering. |
67 // Unlike the GrFontCache, this cache only has one GrAtlasMgr (for 8888) | 92 // Non-atlased layers are stored in their own GrTexture while the atlased |
| 93 // layers share a single GrTexture. |
| 94 // Unlike the GrFontCache, the GrTexture atlas only has one GrAtlasMgr (for 8888
) |
68 // and one GrPlot (for the entire atlas). As such, the GrLayerCache | 95 // and one GrPlot (for the entire atlas). As such, the GrLayerCache |
69 // roughly combines the functionality of the GrFontCache and GrTextStrike | 96 // roughly combines the functionality of the GrFontCache and GrTextStrike |
70 // classes. | 97 // classes. |
71 class GrLayerCache { | 98 class GrLayerCache { |
72 public: | 99 public: |
73 GrLayerCache(GrGpu*); | 100 GrLayerCache(GrGpu*); |
74 ~GrLayerCache(); | 101 ~GrLayerCache(); |
75 | 102 |
76 void freeAll(); | 103 void freeAll(); |
77 | 104 |
78 const GrAtlasedLayer* findLayerOrCreate(SkPicture* picture, int id); | 105 GrCachedLayer* findLayerOrCreate(SkPicture* picture, int id); |
79 | 106 |
80 private: | 107 private: |
81 SkAutoTUnref<GrGpu> fGpu; | 108 SkAutoTUnref<GrGpu> fGpu; |
82 SkAutoTDelete<GrAtlasMgr> fAtlasMgr; // TODO: could lazily allocate | 109 SkAutoTDelete<GrAtlasMgr> fAtlasMgr; // TODO: could lazily allocate |
83 | 110 |
84 class PictureLayerKey; | 111 class PictureLayerKey; |
85 GrTHashTable<GrAtlasedLayer, PictureLayerKey, 7> fLayerHash; | 112 GrTHashTable<GrCachedLayer, PictureLayerKey, 7> fLayerHash; |
86 GrTAllocPool<GrAtlasedLayer> fLayerPool; | 113 GrTAllocPool<GrCachedLayer> fLayerPool; |
87 | 114 |
88 void init(); | 115 void init(); |
89 GrAtlasedLayer* createLayer(SkPicture* picture, int id); | 116 GrCachedLayer* createLayer(SkPicture* picture, int id); |
90 | 117 |
91 }; | 118 }; |
92 | 119 |
93 #endif | 120 #endif |
OLD | NEW |