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

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

Issue 559603004: Separate replacement creation from layer discovery (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix rebaselining error Created 6 years, 3 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 SkMatrix fCTM; 91 SkMatrix fCTM;
92 }; 92 };
93 93
94 static const Key& GetKey(const GrCachedLayer& layer) { return layer.fKey; } 94 static const Key& GetKey(const GrCachedLayer& layer) { return layer.fKey; }
95 static uint32_t Hash(const Key& key) { 95 static uint32_t Hash(const Key& key) {
96 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), size of(Key)); 96 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), size of(Key));
97 } 97 }
98 98
99 // GrCachedLayer proper 99 // GrCachedLayer proper
100 GrCachedLayer(uint32_t pictureID, int start, int stop, 100 GrCachedLayer(uint32_t pictureID, int start, int stop,
101 const SkIPoint& offset, const SkMatrix& ctm) 101 const SkIPoint& offset, const SkMatrix& ctm,
102 const SkPaint* paint)
102 : fKey(pictureID, start, stop, offset, ctm) 103 : fKey(pictureID, start, stop, offset, ctm)
103 , fTexture(NULL) 104 , fTexture(NULL)
105 , fPaint(paint)
104 , fRect(GrIRect16::MakeEmpty()) 106 , fRect(GrIRect16::MakeEmpty())
105 , fPlot(NULL) 107 , fPlot(NULL)
106 , fLocked(false) { 108 , fLocked(false) {
107 SkASSERT(SK_InvalidGenID != pictureID && start >= 0 && stop >= 0); 109 SkASSERT(SK_InvalidGenID != pictureID && start >= 0 && stop >= 0);
108 } 110 }
109 111
110 ~GrCachedLayer() { 112 ~GrCachedLayer() {
111 SkSafeUnref(fTexture); 113 SkSafeUnref(fTexture);
112 } 114 }
113 115
114 uint32_t pictureID() const { return fKey.pictureID(); } 116 uint32_t pictureID() const { return fKey.pictureID(); }
115 int start() const { return fKey.start(); } 117 int start() const { return fKey.start(); }
116 int stop() const { return fKey.stop(); } 118 int stop() const { return fKey.stop(); }
117 const SkIPoint& offset() const { return fKey.offset(); } 119 const SkIPoint& offset() const { return fKey.offset(); }
118 const SkMatrix& ctm() const { return fKey.ctm(); } 120 const SkMatrix& ctm() const { return fKey.ctm(); }
119 121
120 void setTexture(GrTexture* texture, const GrIRect16& rect) { 122 void setTexture(GrTexture* texture, const GrIRect16& rect) {
121 SkRefCnt_SafeAssign(fTexture, texture); 123 SkRefCnt_SafeAssign(fTexture, texture);
122 fRect = rect; 124 fRect = rect;
123 } 125 }
124 GrTexture* texture() { return fTexture; } 126 GrTexture* texture() { return fTexture; }
127 const SkPaint* paint() const { return fPaint; }
125 const GrIRect16& rect() const { return fRect; } 128 const GrIRect16& rect() const { return fRect; }
126 129
127 void setPlot(GrPlot* plot) { 130 void setPlot(GrPlot* plot) {
128 SkASSERT(NULL == plot || NULL == fPlot); 131 SkASSERT(NULL == plot || NULL == fPlot);
129 fPlot = plot; 132 fPlot = plot;
130 } 133 }
131 GrPlot* plot() { return fPlot; } 134 GrPlot* plot() { return fPlot; }
132 135
133 bool isAtlased() const { return SkToBool(fPlot); } 136 bool isAtlased() const { return SkToBool(fPlot); }
134 137
135 void setLocked(bool locked) { fLocked = locked; } 138 void setLocked(bool locked) { fLocked = locked; }
136 bool locked() const { return fLocked; } 139 bool locked() const { return fLocked; }
137 140
138 SkDEBUGCODE(const GrPlot* plot() const { return fPlot; }) 141 SkDEBUGCODE(const GrPlot* plot() const { return fPlot; })
139 SkDEBUGCODE(void validate(const GrTexture* backingTexture) const;) 142 SkDEBUGCODE(void validate(const GrTexture* backingTexture) const;)
140 143
141 private: 144 private:
142 const Key fKey; 145 const Key fKey;
143 146
147 // The paint used when dropping the layer down into the owning canvas.
148 // Can be NULL.
149 const SkPaint* fPaint;
bsalomon 2014/09/17 13:37:37 Is this just a ptr so that it can be NULL or to sa
robertphillips 2014/09/17 13:43:24 I have a TODO to clean this up (I'm leaning toward
bsalomon 2014/09/17 13:43:49 Acknowledged.
150
144 // fTexture is a ref on the atlasing texture for atlased layers and a 151 // fTexture is a ref on the atlasing texture for atlased layers and a
145 // ref on a GrTexture for non-atlased textures. 152 // ref on a GrTexture for non-atlased textures.
146 GrTexture* fTexture; 153 GrTexture* fTexture;
147 154
148 // For both atlased and non-atlased layers 'fRect' contains the bound of 155 // For both atlased and non-atlased layers 'fRect' contains the bound of
149 // the layer in whichever texture it resides. It is empty when 'fTexture' 156 // the layer in whichever texture it resides. It is empty when 'fTexture'
150 // is NULL. 157 // is NULL.
151 GrIRect16 fRect; 158 GrIRect16 fRect;
152 159
153 // For atlased layers, fPlot stores the atlas plot in which the layer rests. 160 // For atlased layers, fPlot stores the atlas plot in which the layer rests.
(...skipping 23 matching lines...) Expand all
177 184
178 // As a cache, the GrLayerCache can be ordered to free up all its cached 185 // As a cache, the GrLayerCache can be ordered to free up all its cached
179 // elements by the GrContext 186 // elements by the GrContext
180 void freeAll(); 187 void freeAll();
181 188
182 GrCachedLayer* findLayer(uint32_t pictureID, int start, int stop, 189 GrCachedLayer* findLayer(uint32_t pictureID, int start, int stop,
183 const SkIPoint& offset, const SkMatrix& ctm); 190 const SkIPoint& offset, const SkMatrix& ctm);
184 GrCachedLayer* findLayerOrCreate(uint32_t pictureID, 191 GrCachedLayer* findLayerOrCreate(uint32_t pictureID,
185 int start, int stop, 192 int start, int stop,
186 const SkIPoint& offset, 193 const SkIPoint& offset,
187 const SkMatrix& ctm); 194 const SkMatrix& ctm,
195 const SkPaint* paint);
188 196
189 // Inform the cache that layer's cached image is now required. 197 // Inform the cache that layer's cached image is now required.
190 // Return true if the layer must be re-rendered. Return false if the 198 // Return true if the layer must be re-rendered. Return false if the
191 // layer was found in the cache and can be reused. 199 // layer was found in the cache and can be reused.
192 bool lock(GrCachedLayer* layer, const GrTextureDesc& desc, bool dontAtlas); 200 bool lock(GrCachedLayer* layer, const GrTextureDesc& desc, bool dontAtlas);
193 201
194 // Inform the cache that layer's cached image is not currently required 202 // Inform the cache that layer's cached image is not currently required
195 void unlock(GrCachedLayer* layer); 203 void unlock(GrCachedLayer* layer);
196 204
197 // Setup to be notified when 'picture' is deleted 205 // Setup to be notified when 'picture' is deleted
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // This implements a plot-centric locking mechanism (since the atlas 239 // This implements a plot-centric locking mechanism (since the atlas
232 // backing texture is always locked). Each layer that is locked (i.e., 240 // backing texture is always locked). Each layer that is locked (i.e.,
233 // needed for the current rendering) in a plot increments the plot lock 241 // needed for the current rendering) in a plot increments the plot lock
234 // count for that plot. Similarly, once a rendering is complete all the 242 // count for that plot. Similarly, once a rendering is complete all the
235 // layers used in it decrement the lock count for the used plots. 243 // layers used in it decrement the lock count for the used plots.
236 // Plots with a 0 lock count are open for recycling/purging. 244 // Plots with a 0 lock count are open for recycling/purging.
237 int fPlotLocks[kNumPlotsX * kNumPlotsY]; 245 int fPlotLocks[kNumPlotsX * kNumPlotsY];
238 246
239 void initAtlas(); 247 void initAtlas();
240 GrCachedLayer* createLayer(uint32_t pictureID, int start, int stop, 248 GrCachedLayer* createLayer(uint32_t pictureID, int start, int stop,
241 const SkIPoint& offset, const SkMatrix& ctm); 249 const SkIPoint& offset, const SkMatrix& ctm,
250 const SkPaint* paint);
242 251
243 void purgeAll(); 252 void purgeAll();
244 253
245 // Remove all the layers (and unlock any resources) associated with 'picture ID' 254 // Remove all the layers (and unlock any resources) associated with 'picture ID'
246 void purge(uint32_t pictureID); 255 void purge(uint32_t pictureID);
247 256
248 static bool PlausiblyAtlasable(int width, int height) { 257 static bool PlausiblyAtlasable(int width, int height) {
249 return width <= kPlotWidth && height <= kPlotHeight; 258 return width <= kPlotWidth && height <= kPlotHeight;
250 } 259 }
251 260
252 void purgePlot(GrPlot* plot); 261 void purgePlot(GrPlot* plot);
253 262
254 // Try to find a purgeable plot and clear it out. Return true if a plot 263 // Try to find a purgeable plot and clear it out. Return true if a plot
255 // was purged; false otherwise. 264 // was purged; false otherwise.
256 bool purgePlot(); 265 bool purgePlot();
257 266
258 // for testing 267 // for testing
259 friend class TestingAccess; 268 friend class TestingAccess;
260 int numLayers() const { return fLayerHash.count(); } 269 int numLayers() const { return fLayerHash.count(); }
261 }; 270 };
262 271
263 #endif 272 #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