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

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

Issue 753253002: Use variable length key (rather than accumulated matrix) as save layer hoisting key (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Compiling Created 6 years 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
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
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // get a ref to the GrTexture in which they reside. In both cases 'fRect' 69 // get a ref to the GrTexture in which they reside. In both cases 'fRect'
70 // contains the layer's extent in its texture. 70 // contains the layer's extent in its texture.
71 // Atlased layers also get a pointer to the plot in which they reside. 71 // Atlased layers also get a pointer to the plot in which they reside.
72 // For non-atlased layers, the lock field just corresponds to locking in 72 // For non-atlased layers, the lock field just corresponds to locking in
73 // the resource cache. For atlased layers, it implements an additional level 73 // the resource cache. For atlased layers, it implements an additional level
74 // of locking to allow atlased layers to be reused multiple times. 74 // of locking to allow atlased layers to be reused multiple times.
75 struct GrCachedLayer { 75 struct GrCachedLayer {
76 public: 76 public:
77 // For SkTDynamicHash 77 // For SkTDynamicHash
78 struct Key { 78 struct Key {
79 Key(uint32_t pictureID, int start, const SkIRect& bounds, const SkMatrix & ctm) 79 Key(uint32_t pictureID, int start, const SkIRect& bounds, const SkMatrix & ctm,
80 const int* key, int keySize)
80 : fPictureID(pictureID) 81 : fPictureID(pictureID)
81 , fStart(start) 82 , fStart(start)
82 , fBounds(bounds) 83 , fBounds(bounds)
83 , fCTM(ctm) { 84 , fCTM(ctm)
85 , fKey(key)
86 , fKeySize(keySize) {
84 fCTM.getType(); // force initialization of type so hashes match 87 fCTM.getType(); // force initialization of type so hashes match
85 88
89 #if 0
86 // Key needs to be tightly packed. 90 // Key needs to be tightly packed.
87 GR_STATIC_ASSERT(sizeof(Key) == sizeof(uint32_t) + // picture I D 91 GR_STATIC_ASSERT(sizeof(Key) == sizeof(uint32_t) + // picture I D
88 sizeof(int) + // start ind ex 92 sizeof(int) + // start ind ex
89 4 * sizeof(uint32_t) + // bounds 93 4 * sizeof(uint32_t) + // bounds
90 9 * sizeof(SkScalar) + sizeof(uint32 _t)); // matrix 94 9 * sizeof(SkScalar) + sizeof(uint32 _t)); // matrix
95 #endif
91 } 96 }
92 97
93 bool operator==(const Key& other) const { 98 bool operator==(const Key& other) const {
99 if (fKeySize != other.fKeySize) {
100 return false;
101 }
94 return fPictureID == other.fPictureID && 102 return fPictureID == other.fPictureID &&
95 fStart == other.fStart && 103 fStart == other.fStart &&
96 fBounds == other.fBounds && 104 fBounds == other.fBounds &&
97 fCTM.cheapEqualTo(other.fCTM); 105 fCTM.cheapEqualTo(other.fCTM) &&
106 !memcmp(fKey, other.fKey, fKeySize * sizeof(int));
98 } 107 }
99 108
100 uint32_t pictureID() const { return fPictureID; } 109 uint32_t pictureID() const { return fPictureID; }
101 int start() const { return fStart; } 110 int start() const { return fStart; }
102 const SkIRect& bound() const { return fBounds; } 111 const SkIRect& bound() const { return fBounds; }
103 112
113 const int* key() const { return fKey; }
114 int keySize() const { return fKeySize; }
115
104 private: 116 private:
105 // ID of the picture of which this layer is a part 117 // ID of the picture of which this layer is a part
106 const uint32_t fPictureID; 118 const uint32_t fPictureID;
107 // The the index of the saveLayer command in the picture 119 // The the index of the saveLayer command in the picture
108 const int fStart; 120 const int fStart;
109 // The bounds of the layer. The TL corner is its offset. 121 // The bounds of the layer. The TL corner is its offset.
110 const SkIRect fBounds; 122 const SkIRect fBounds;
111 // The 2x2 portion of the CTM applied to this layer in the picture 123 // The 2x2 portion of the CTM applied to this layer in the picture
112 SkMatrix fCTM; 124 SkMatrix fCTM;
125
126 const int* fKey;
127 const int fKeySize;
113 }; 128 };
114 129
115 static const Key& GetKey(const GrCachedLayer& layer) { return layer.fKey; } 130 static const Key& GetKey(const GrCachedLayer& layer) { return layer.fKey; }
116 static uint32_t Hash(const Key& key) { 131 static uint32_t Hash(const Key& key) {
117 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), size of(Key)); 132 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(key.key()),
133 key.keySize() * sizeof(int));
118 } 134 }
119 135
120 // GrCachedLayer proper 136 // GrCachedLayer proper
121 GrCachedLayer(uint32_t pictureID, int start, int stop, 137 GrCachedLayer(uint32_t pictureID, int start, int stop,
122 const SkIRect& bounds, const SkMatrix& ctm, 138 const SkIRect& bounds, const SkMatrix& ctm,
139 const int* key, int keySize,
123 const SkPaint* paint) 140 const SkPaint* paint)
124 : fKey(pictureID, start, bounds, ctm) 141 : fKey(pictureID, start, bounds, ctm, key, keySize)
125 , fStop(stop) 142 , fStop(stop)
126 , fPaint(paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL) 143 , fPaint(paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL)
127 , fTexture(NULL) 144 , fTexture(NULL)
128 , fRect(GrIRect16::MakeEmpty()) 145 , fRect(GrIRect16::MakeEmpty())
129 , fPlot(NULL) 146 , fPlot(NULL)
130 , fUses(0) 147 , fUses(0)
131 , fLocked(false) { 148 , fLocked(false) {
132 SkASSERT(SK_InvalidGenID != pictureID && start >= 0 && stop >= 0); 149 SkASSERT(SK_InvalidGenID != pictureID && start >= 0 && stop >= 0);
133 } 150 }
134 151
135 ~GrCachedLayer() { 152 ~GrCachedLayer() {
136 SkSafeUnref(fTexture); 153 SkSafeUnref(fTexture);
137 SkDELETE(fPaint); 154 SkDELETE(fPaint);
138 } 155 }
139 156
140 uint32_t pictureID() const { return fKey.pictureID(); } 157 uint32_t pictureID() const { return fKey.pictureID(); }
141 int start() const { return fKey.start(); } 158 int start() const { return fKey.start(); }
159 const int* key() const { return fKey.key(); }
160 int keySize() const { return fKey.keySize(); }
161
142 const SkIRect& bound() const { return fKey.bound(); } 162 const SkIRect& bound() const { return fKey.bound(); }
143 163
144 int stop() const { return fStop; } 164 int stop() const { return fStop; }
145 void setTexture(GrTexture* texture, const GrIRect16& rect) { 165 void setTexture(GrTexture* texture, const GrIRect16& rect) {
146 SkRefCnt_SafeAssign(fTexture, texture); 166 SkRefCnt_SafeAssign(fTexture, texture);
147 fRect = rect; 167 fRect = rect;
148 } 168 }
149 GrTexture* texture() { return fTexture; } 169 GrTexture* texture() { return fTexture; }
150 const SkPaint* paint() const { return fPaint; } 170 const SkPaint* paint() const { return fPaint; }
151 const GrIRect16& rect() const { return fRect; } 171 const GrIRect16& rect() const { return fRect; }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // classes. 237 // classes.
218 class GrLayerCache { 238 class GrLayerCache {
219 public: 239 public:
220 GrLayerCache(GrContext*); 240 GrLayerCache(GrContext*);
221 ~GrLayerCache(); 241 ~GrLayerCache();
222 242
223 // As a cache, the GrLayerCache can be ordered to free up all its cached 243 // As a cache, the GrLayerCache can be ordered to free up all its cached
224 // elements by the GrContext 244 // elements by the GrContext
225 void freeAll(); 245 void freeAll();
226 246
227 GrCachedLayer* findLayer(uint32_t pictureID, int start, 247 GrCachedLayer* findLayer(uint32_t pictureID, int start,
228 const SkIRect& bounds, const SkMatrix& ctm); 248 const SkIRect& bounds, const SkMatrix& ctm,
249 const int* key, int keySize);
229 GrCachedLayer* findLayerOrCreate(uint32_t pictureID, 250 GrCachedLayer* findLayerOrCreate(uint32_t pictureID,
230 int start, int stop, 251 int start, int stop,
231 const SkIRect& bounds, 252 const SkIRect& bounds,
232 const SkMatrix& ctm, 253 const SkMatrix& ctm,
254 const int* key, int keySize,
233 const SkPaint* paint); 255 const SkPaint* paint);
234 256
235 // Attempt to place 'layer' in the atlas. Return true on success; false on f ailure. 257 // Attempt to place 'layer' in the atlas. Return true on success; false on f ailure.
236 // When true is returned, 'needsRendering' will indicate if the layer must b e (re)drawn. 258 // When true is returned, 'needsRendering' will indicate if the layer must b e (re)drawn.
237 // Additionally, the GPU resources will be locked. 259 // Additionally, the GPU resources will be locked.
238 bool tryToAtlas(GrCachedLayer* layer, const GrSurfaceDesc& desc, bool* needs Rendering); 260 bool tryToAtlas(GrCachedLayer* layer, const GrSurfaceDesc& desc, bool* needs Rendering);
239 261
240 // Attempt to lock the GPU resources required for a layer. Return true on su ccess; 262 // Attempt to lock the GPU resources required for a layer. Return true on su ccess;
241 // false on failure. When true is returned 'needsRendering' will indicate if the 263 // false on failure. When true is returned 'needsRendering' will indicate if the
242 // layer must be (re)drawn. 264 // layer must be (re)drawn.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 // needed for the current rendering) in a plot increments the plot lock 325 // needed for the current rendering) in a plot increments the plot lock
304 // count for that plot. Similarly, once a rendering is complete all the 326 // count for that plot. Similarly, once a rendering is complete all the
305 // layers used in it decrement the lock count for the used plots. 327 // layers used in it decrement the lock count for the used plots.
306 // Plots with a 0 lock count are open for recycling/purging. 328 // Plots with a 0 lock count are open for recycling/purging.
307 int fPlotLocks[kNumPlotsX * kNumPlotsY]; 329 int fPlotLocks[kNumPlotsX * kNumPlotsY];
308 330
309 // Inform the cache that layer's cached image is not currently required 331 // Inform the cache that layer's cached image is not currently required
310 void unlock(GrCachedLayer* layer); 332 void unlock(GrCachedLayer* layer);
311 333
312 void initAtlas(); 334 void initAtlas();
313 GrCachedLayer* createLayer(uint32_t pictureID, int start, int stop, 335 GrCachedLayer* createLayer(uint32_t pictureID, int start, int stop,
314 const SkIRect& bounds, const SkMatrix& ctm, 336 const SkIRect& bounds, const SkMatrix& ctm,
337 const int* key, int keySize,
315 const SkPaint* paint); 338 const SkPaint* paint);
316 339
317 // Remove all the layers (and unlock any resources) associated with 'picture ID' 340 // Remove all the layers (and unlock any resources) associated with 'picture ID'
318 void purge(uint32_t pictureID); 341 void purge(uint32_t pictureID);
319 342
320 void purgePlot(GrPlot* plot); 343 void purgePlot(GrPlot* plot);
321 344
322 // Try to find a purgeable plot and clear it out. Return true if a plot 345 // Try to find a purgeable plot and clear it out. Return true if a plot
323 // was purged; false otherwise. 346 // was purged; false otherwise.
324 bool purgePlot(); 347 bool purgePlot();
325 348
326 void incPlotLock(int plotIdx) { ++fPlotLocks[plotIdx]; } 349 void incPlotLock(int plotIdx) { ++fPlotLocks[plotIdx]; }
327 void decPlotLock(int plotIdx) { 350 void decPlotLock(int plotIdx) {
328 SkASSERT(fPlotLocks[plotIdx] > 0); 351 SkASSERT(fPlotLocks[plotIdx] > 0);
329 --fPlotLocks[plotIdx]; 352 --fPlotLocks[plotIdx];
330 } 353 }
331 354
332 // for testing 355 // for testing
333 friend class TestingAccess; 356 friend class TestingAccess;
334 int numLayers() const { return fLayerHash.count(); } 357 int numLayers() const { return fLayerHash.count(); }
335 }; 358 };
336 359
337 #endif 360 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698