Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: src/gpu/GrLayerCache.h

Issue 397873004: Make GrLayerCache use multiple plots in its atlas (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Try to pacify clang Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/gpu/GrLayerCache.cpp » ('j') | src/gpu/GrLayerCache.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #define USE_ATLAS 0 11 #define USE_ATLAS 0
12 12
13 #include "GrAllocPool.h" 13 #include "GrAllocPool.h"
14 #include "GrAtlas.h" 14 #include "GrAtlas.h"
15 #include "GrTHashTable.h" 15 #include "GrTHashTable.h"
16 #include "GrPictureUtils.h" 16 #include "GrPictureUtils.h"
17 #include "GrRect.h" 17 #include "GrRect.h"
18 18
19 class GrGpu;
20 class SkPicture; 19 class SkPicture;
21 20
21 // GrPictureInfo stores the atlas plots used by a single picture. A single
22 // plot may be used to store layers from multiple pictures.
23 struct GrPictureInfo {
24 public:
25 GrPictureInfo(uint32_t pictureID) : fPictureID(pictureID) { }
26
27 uint32_t fPictureID;
28
29 GrAtlas::ClientPlotUsage fPlotUsage;
30 };
31
22 // GrCachedLayer encapsulates the caching information for a single saveLayer. 32 // GrCachedLayer encapsulates the caching information for a single saveLayer.
23 // 33 //
24 // Atlased layers get a ref to the backing GrTexture while non-atlased layers 34 // Atlased layers get a ref to the backing GrTexture while non-atlased layers
25 // get a ref to the GrTexture in which they reside. In both cases 'fRect' 35 // get a ref to the GrTexture in which they reside. In both cases 'fRect'
26 // contains the layer's extent in its texture. 36 // contains the layer's extent in its texture.
27 // 37 // Atlased layers also get a pointer to the plot in which they reside.
28 // TODO: can we easily reuse the empty space in the non-atlased GrTexture's?
29 struct GrCachedLayer { 38 struct GrCachedLayer {
30 public: 39 public:
31 GrCachedLayer(uint32_t pictureID, int layerID) 40 GrCachedLayer(uint32_t pictureID, int layerID)
32 : fAtlased(false) { 41 : fPlot(NULL) {
33 fPictureID = pictureID; 42 fPictureID = pictureID;
34 fLayerID = layerID; 43 fLayerID = layerID;
35 fTexture = NULL; 44 fTexture = NULL;
36 fRect = GrIRect16::MakeEmpty(); 45 fRect = GrIRect16::MakeEmpty();
37 } 46 }
38 47
39 uint32_t pictureID() const { return fPictureID; } 48 uint32_t pictureID() const { return fPictureID; }
40 int layerID() const { return fLayerID; } 49 int layerID() const { return fLayerID; }
41 50
42 // This call takes over the caller's ref 51 // This call takes over the caller's ref
43 void setTexture(GrTexture* texture, const GrIRect16& rect) { 52 void setTexture(GrTexture* texture, const GrIRect16& rect) {
44 if (NULL != fTexture) { 53 if (NULL != fTexture) {
45 fTexture->unref(); 54 fTexture->unref();
46 } 55 }
47 56
48 fTexture = texture; // just take over caller's ref 57 fTexture = texture; // just take over caller's ref
49 fRect = rect; 58 fRect = rect;
50 } 59 }
51 GrTexture* texture() { return fTexture; } 60 GrTexture* texture() { return fTexture; }
52 const GrIRect16& rect() const { return fRect; } 61 const GrIRect16& rect() const { return fRect; }
53 62
54 void setAtlased(bool atlased) { fAtlased = atlased; } 63 void setPlot(GrPlot* plot) {
55 bool isAtlased() const { return fAtlased; } 64 SkASSERT(NULL == fPlot);
65 fPlot = plot;
66 }
67 GrPlot* plot() { return fPlot; }
56 68
57 SkDEBUGCODE(void validate(GrTexture* backingTexture) const;) 69 bool isAtlased() const { return NULL != fPlot; }
70
71 SkDEBUGCODE(void validate(const GrTexture* backingTexture) const;)
58 72
59 private: 73 private:
60 // ID of the picture of which this layer is a part 74 // ID of the picture of which this layer is a part
61 uint32_t fPictureID; 75 uint32_t fPictureID;
62 76
63 // fLayerID is only valid when fPicture != kInvalidGenID in which case it 77 // fLayerID is only valid when fPicture != kInvalidGenID in which case it
64 // is the index of this layer in the picture (one of 0 .. #layers). 78 // is the index of this layer in the picture (one of 0 .. #layers).
65 int fLayerID; 79 int fLayerID;
66 80
67 // fTexture is a ref on the atlasing texture for atlased layers and a 81 // fTexture is a ref on the atlasing texture for atlased layers and a
68 // ref on a GrTexture for non-atlased textures. In both cases, if this is 82 // ref on a GrTexture for non-atlased textures. In both cases, if this is
69 // non-NULL, that means that the texture is locked in the texture cache. 83 // non-NULL, that means that the texture is locked in the texture cache.
70 GrTexture* fTexture; 84 GrTexture* fTexture;
71 85
72 // True if this layer is in an atlas; false otherwise.
73 bool fAtlased;
74
75 // For both atlased and non-atlased layers 'fRect' contains the bound of 86 // For both atlased and non-atlased layers 'fRect' contains the bound of
76 // the layer in whichever texture it resides. It is empty when 'fTexture' 87 // the layer in whichever texture it resides. It is empty when 'fTexture'
77 // is NULL. 88 // is NULL.
78 GrIRect16 fRect; 89 GrIRect16 fRect;
90
91 // For atlased layers, fPlot stores the atlas plot in which the layer rests.
92 // It is always NULL for non-atlased layers.
93 GrPlot* fPlot;
79 }; 94 };
80 95
81 // The GrLayerCache caches pre-computed saveLayers for later rendering. 96 // The GrLayerCache caches pre-computed saveLayers for later rendering.
82 // Non-atlased layers are stored in their own GrTexture while the atlased 97 // Non-atlased layers are stored in their own GrTexture while the atlased
83 // layers share a single GrTexture. 98 // layers share a single GrTexture.
84 // Unlike the GrFontCache, the GrTexture atlas only has one GrAtlas (for 8888) 99 // Unlike the GrFontCache, the GrTexture atlas only has one GrAtlas (for 8888)
85 // and one GrPlot (for the entire atlas). As such, the GrLayerCache 100 // and one GrPlot (for the entire atlas). As such, the GrLayerCache
86 // roughly combines the functionality of the GrFontCache and GrTextStrike 101 // roughly combines the functionality of the GrFontCache and GrTextStrike
87 // classes. 102 // classes.
88 class GrLayerCache { 103 class GrLayerCache {
(...skipping 16 matching lines...) Expand all
105 120
106 // Inform the cache that layer's cached image is not currently required 121 // Inform the cache that layer's cached image is not currently required
107 void unlock(GrCachedLayer* layer); 122 void unlock(GrCachedLayer* layer);
108 123
109 // Remove all the layers (and unlock any resources) associated with 'picture ' 124 // Remove all the layers (and unlock any resources) associated with 'picture '
110 void purge(const SkPicture* picture); 125 void purge(const SkPicture* picture);
111 126
112 SkDEBUGCODE(void validate() const;) 127 SkDEBUGCODE(void validate() const;)
113 128
114 private: 129 private:
130 static const int kNumPlotsX = 2;
131 static const int kNumPlotsY = 2;
132
115 GrContext* fContext; // pointer back to owning context 133 GrContext* fContext; // pointer back to owning context
116 SkAutoTDelete<GrAtlas> fAtlas; // TODO: could lazily allocate 134 SkAutoTDelete<GrAtlas> fAtlas; // TODO: could lazily allocate
117 GrAtlas::ClientPlotUsage fPlotUsage; 135
136 // We cache this information here (rather then, say, on the owning picture)
137 // because we want to be able to clean it up as needed (e.g., if a picture
138 // is leaked and never cleans itself up we still want to be able to
139 // remove the GrPictureInfo once its layers are purged from all the atlas
140 // plots).
141 class PictureKey;
142 GrTHashTable<GrPictureInfo, PictureKey, 7> fPictureHash;
118 143
119 class PictureLayerKey; 144 class PictureLayerKey;
120 GrTHashTable<GrCachedLayer, PictureLayerKey, 7> fLayerHash; 145 GrTHashTable<GrCachedLayer, PictureLayerKey, 7> fLayerHash;
121 146
122 void initAtlas(); 147 void initAtlas();
123 GrCachedLayer* createLayer(const SkPicture* picture, int layerID); 148 GrCachedLayer* createLayer(const SkPicture* picture, int layerID);
124 149
125 // for testing 150 // for testing
126 friend class GetNumLayers; 151 friend class GetNumLayers;
127 int numLayers() const { return fLayerHash.count(); } 152 int numLayers() const { return fLayerHash.count(); }
128 }; 153 };
129 154
130 #endif 155 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrLayerCache.cpp » ('j') | src/gpu/GrLayerCache.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698