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

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

Issue 476833004: Refactor GrLayerCache for new API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add DISABLE_CACHING guard Created 6 years, 4 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') | no next file with comments »
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
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 const SkMatrix& ctm() const { return fKey.ctm(); } 110 const SkMatrix& ctm() const { return fKey.ctm(); }
111 111
112 void setTexture(GrTexture* texture, const GrIRect16& rect) { 112 void setTexture(GrTexture* texture, const GrIRect16& rect) {
113 SkRefCnt_SafeAssign(fTexture, texture); 113 SkRefCnt_SafeAssign(fTexture, texture);
114 fRect = rect; 114 fRect = rect;
115 } 115 }
116 GrTexture* texture() { return fTexture; } 116 GrTexture* texture() { return fTexture; }
117 const GrIRect16& rect() const { return fRect; } 117 const GrIRect16& rect() const { return fRect; }
118 118
119 void setPlot(GrPlot* plot) { 119 void setPlot(GrPlot* plot) {
120 SkASSERT(NULL == fPlot); 120 SkASSERT(NULL == plot || NULL == fPlot);
121 fPlot = plot; 121 fPlot = plot;
122 } 122 }
123 GrPlot* plot() { return fPlot; } 123 GrPlot* plot() { return fPlot; }
124 124
125 bool isAtlased() const { return NULL != fPlot; } 125 bool isAtlased() const { return NULL != fPlot; }
126 126
127 void setLocked(bool locked) { fLocked = locked; } 127 void setLocked(bool locked) { fLocked = locked; }
128 bool locked() const { return fLocked; } 128 bool locked() const { return fLocked; }
129 129
130 SkDEBUGCODE(const GrPlot* plot() const { return fPlot; }) 130 SkDEBUGCODE(const GrPlot* plot() const { return fPlot; })
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // classes. 164 // classes.
165 class GrLayerCache { 165 class GrLayerCache {
166 public: 166 public:
167 GrLayerCache(GrContext*); 167 GrLayerCache(GrContext*);
168 ~GrLayerCache(); 168 ~GrLayerCache();
169 169
170 // As a cache, the GrLayerCache can be ordered to free up all its cached 170 // As a cache, the GrLayerCache can be ordered to free up all its cached
171 // elements by the GrContext 171 // elements by the GrContext
172 void freeAll(); 172 void freeAll();
173 173
174 GrCachedLayer* findLayer(const SkPicture* picture, int start, int stop, cons t SkMatrix& ctm); 174 GrCachedLayer* findLayer(uint32_t pictureID, int start, int stop, const SkMa trix& ctm);
175 GrCachedLayer* findLayerOrCreate(const SkPicture* picture, 175 GrCachedLayer* findLayerOrCreate(uint32_t pictureID,
176 int start, int stop, 176 int start, int stop,
177 const SkMatrix& ctm); 177 const SkMatrix& ctm);
178 178
179 // Inform the cache that layer's cached image is now required. Return true 179 // Inform the cache that layer's cached image is now required.
180 // if it was found in the ResourceCache and doesn't need to be regenerated. 180 // Return true if the layer must be re-rendered. Return false if the
181 // If false is returned the caller should (re)render the layer into the 181 // layer was found in the cache and can be reused.
182 // newly acquired texture. 182 bool lock(GrCachedLayer* layer, const GrTextureDesc& desc, bool dontAtlas);
183 bool lock(GrCachedLayer* layer, const GrTextureDesc& desc);
184 183
185 // Inform the cache that layer's cached image is not currently required 184 // Inform the cache that layer's cached image is not currently required
186 void unlock(GrCachedLayer* layer); 185 void unlock(GrCachedLayer* layer);
187 186
188 // Setup to be notified when 'picture' is deleted 187 // Setup to be notified when 'picture' is deleted
189 void trackPicture(const SkPicture* picture); 188 void trackPicture(const SkPicture* picture);
190 189
191 // Cleanup after any SkPicture deletions 190 // Cleanup after any SkPicture deletions
192 void processDeletedPictures(); 191 void processDeletedPictures();
193 192
(...skipping 27 matching lines...) Expand all
221 220
222 // This implements a plot-centric locking mechanism (since the atlas 221 // This implements a plot-centric locking mechanism (since the atlas
223 // backing texture is always locked). Each layer that is locked (i.e., 222 // backing texture is always locked). Each layer that is locked (i.e.,
224 // needed for the current rendering) in a plot increments the plot lock 223 // needed for the current rendering) in a plot increments the plot lock
225 // count for that plot. Similarly, once a rendering is complete all the 224 // count for that plot. Similarly, once a rendering is complete all the
226 // layers used in it decrement the lock count for the used plots. 225 // layers used in it decrement the lock count for the used plots.
227 // Plots with a 0 lock count are open for recycling/purging. 226 // Plots with a 0 lock count are open for recycling/purging.
228 int fPlotLocks[kNumPlotsX * kNumPlotsY]; 227 int fPlotLocks[kNumPlotsX * kNumPlotsY];
229 228
230 void initAtlas(); 229 void initAtlas();
231 GrCachedLayer* createLayer(const SkPicture* picture, int start, int stop, co nst SkMatrix& ctm); 230 GrCachedLayer* createLayer(uint32_t pictureID, int start, int stop, const Sk Matrix& ctm);
231
232 public:
233 void purgeAll();
232 234
233 // Remove all the layers (and unlock any resources) associated with 'picture ID' 235 // Remove all the layers (and unlock any resources) associated with 'picture ID'
234 void purge(uint32_t pictureID); 236 void purge(uint32_t pictureID);
235 237
236 static bool PlausiblyAtlasable(int width, int height) { 238 static bool PlausiblyAtlasable(int width, int height) {
237 return width <= kPlotWidth && height <= kPlotHeight; 239 return width <= kPlotWidth && height <= kPlotHeight;
238 } 240 }
239 241
242 void purgePlot(GrPlot* plot);
243
240 // Try to find a purgeable plot and clear it out. Return true if a plot 244 // Try to find a purgeable plot and clear it out. Return true if a plot
241 // was purged; false otherwise. 245 // was purged; false otherwise.
242 bool purgePlot(); 246 bool purgePlot();
243 247
244 // for testing 248 // for testing
245 friend class TestingAccess; 249 friend class TestingAccess;
246 int numLayers() const { return fLayerHash.count(); } 250 int numLayers() const { return fLayerHash.count(); }
247 }; 251 };
248 252
249 #endif 253 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrLayerCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698