| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 void freeAll(); | 201 void freeAll(); |
| 202 | 202 |
| 203 GrCachedLayer* findLayer(uint32_t pictureID, int start, | 203 GrCachedLayer* findLayer(uint32_t pictureID, int start, |
| 204 const SkIRect& bounds, const SkMatrix& ctm); | 204 const SkIRect& bounds, const SkMatrix& ctm); |
| 205 GrCachedLayer* findLayerOrCreate(uint32_t pictureID, | 205 GrCachedLayer* findLayerOrCreate(uint32_t pictureID, |
| 206 int start, int stop, | 206 int start, int stop, |
| 207 const SkIRect& bounds, | 207 const SkIRect& bounds, |
| 208 const SkMatrix& ctm, | 208 const SkMatrix& ctm, |
| 209 const SkPaint* paint); | 209 const SkPaint* paint); |
| 210 | 210 |
| 211 // Inform the cache that layer's cached image is now required. | 211 // Attempt to place 'layer' in the atlas. Return true on success; false on f
ailure. |
| 212 // Return true if the layer must be re-rendered. Return false if the | 212 // When true is returned, 'needsRendering' will indicate if the layer must b
e (re)drawn. |
| 213 // layer was found in the cache and can be reused. | 213 // Additionally, the GPU resources will be locked. |
| 214 bool lock(GrCachedLayer* layer, const GrTextureDesc& desc, bool dontAtlas); | 214 bool tryToAtlas(GrCachedLayer* layer, const GrTextureDesc& desc, bool* needs
Rendering); |
| 215 |
| 216 // Attempt to lock the GPU resources required for a layer. Return true on su
ccess; |
| 217 // false on failure. When true is returned 'needsRendering' will indicate if
the |
| 218 // layer must be (re)drawn. |
| 219 // Note that atlased layers should already have been locked and rendered so
only |
| 220 // free floating layers will have 'needsRendering' set. |
| 221 // Currently, this path always uses a new scratch texture for non-Atlased la
yers |
| 222 // and (thus) doesn't cache anything. This can yield a lot of re-rendering. |
| 223 // TODO: allow rediscovery of free-floating layers that are still in the res
ource cache. |
| 224 bool lock(GrCachedLayer* layer, const GrTextureDesc& desc, bool* needsRender
ing); |
| 215 | 225 |
| 216 // addUse is just here to keep the API symmetric | 226 // addUse is just here to keep the API symmetric |
| 217 void addUse(GrCachedLayer* layer) { layer->addUse(); } | 227 void addUse(GrCachedLayer* layer) { layer->addUse(); } |
| 218 void removeUse(GrCachedLayer* layer) { | 228 void removeUse(GrCachedLayer* layer) { |
| 219 layer->removeUse(); | 229 layer->removeUse(); |
| 220 if (layer->uses() == 0) { | 230 if (layer->uses() == 0) { |
| 221 // If no one cares about the layer allow it to be recycled. | 231 // If no one cares about the layer allow it to be recycled. |
| 222 this->unlock(layer); | 232 this->unlock(layer); |
| 223 } | 233 } |
| 224 } | 234 } |
| 225 | 235 |
| 226 // Setup to be notified when 'picture' is deleted | 236 // Setup to be notified when 'picture' is deleted |
| 227 void trackPicture(const SkPicture* picture); | 237 void trackPicture(const SkPicture* picture); |
| 228 | 238 |
| 229 // Cleanup after any SkPicture deletions | 239 // Cleanup after any SkPicture deletions |
| 230 void processDeletedPictures(); | 240 void processDeletedPictures(); |
| 231 | 241 |
| 232 SkDEBUGCODE(void validate() const;) | 242 SkDEBUGCODE(void validate() const;) |
| 233 | 243 |
| 234 #ifdef SK_DEVELOPER | 244 #ifdef SK_DEVELOPER |
| 235 void writeLayersToDisk(const SkString& dirName); | 245 void writeLayersToDisk(const SkString& dirName); |
| 236 #endif | 246 #endif |
| 237 | 247 |
| 248 static bool PlausiblyAtlasable(int width, int height) { |
| 249 return width <= kPlotWidth && height <= kPlotHeight; |
| 250 } |
| 251 |
| 238 private: | 252 private: |
| 239 static const int kAtlasTextureWidth = 1024; | 253 static const int kAtlasTextureWidth = 1024; |
| 240 static const int kAtlasTextureHeight = 1024; | 254 static const int kAtlasTextureHeight = 1024; |
| 241 | 255 |
| 242 static const int kNumPlotsX = 2; | 256 static const int kNumPlotsX = 2; |
| 243 static const int kNumPlotsY = 2; | 257 static const int kNumPlotsY = 2; |
| 244 | 258 |
| 245 static const int kPlotWidth = kAtlasTextureWidth / kNumPlotsX; | 259 static const int kPlotWidth = kAtlasTextureWidth / kNumPlotsX; |
| 246 static const int kPlotHeight = kAtlasTextureHeight / kNumPlotsY; | 260 static const int kPlotHeight = kAtlasTextureHeight / kNumPlotsY; |
| 247 | 261 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 275 void initAtlas(); | 289 void initAtlas(); |
| 276 GrCachedLayer* createLayer(uint32_t pictureID, int start, int stop, | 290 GrCachedLayer* createLayer(uint32_t pictureID, int start, int stop, |
| 277 const SkIRect& bounds, const SkMatrix& ctm, | 291 const SkIRect& bounds, const SkMatrix& ctm, |
| 278 const SkPaint* paint); | 292 const SkPaint* paint); |
| 279 | 293 |
| 280 void purgeAll(); | 294 void purgeAll(); |
| 281 | 295 |
| 282 // Remove all the layers (and unlock any resources) associated with 'picture
ID' | 296 // Remove all the layers (and unlock any resources) associated with 'picture
ID' |
| 283 void purge(uint32_t pictureID); | 297 void purge(uint32_t pictureID); |
| 284 | 298 |
| 285 static bool PlausiblyAtlasable(int width, int height) { | |
| 286 return width <= kPlotWidth && height <= kPlotHeight; | |
| 287 } | |
| 288 | |
| 289 void purgePlot(GrPlot* plot); | 299 void purgePlot(GrPlot* plot); |
| 290 | 300 |
| 291 // Try to find a purgeable plot and clear it out. Return true if a plot | 301 // Try to find a purgeable plot and clear it out. Return true if a plot |
| 292 // was purged; false otherwise. | 302 // was purged; false otherwise. |
| 293 bool purgePlot(); | 303 bool purgePlot(); |
| 294 | 304 |
| 295 void incPlotLock(int plotIdx) { ++fPlotLocks[plotIdx]; } | 305 void incPlotLock(int plotIdx) { ++fPlotLocks[plotIdx]; } |
| 296 void decPlotLock(int plotIdx) { | 306 void decPlotLock(int plotIdx) { |
| 297 SkASSERT(fPlotLocks[plotIdx] > 0); | 307 SkASSERT(fPlotLocks[plotIdx] > 0); |
| 298 --fPlotLocks[plotIdx]; | 308 --fPlotLocks[plotIdx]; |
| 299 } | 309 } |
| 300 | 310 |
| 301 // for testing | 311 // for testing |
| 302 friend class TestingAccess; | 312 friend class TestingAccess; |
| 303 int numLayers() const { return fLayerHash.count(); } | 313 int numLayers() const { return fLayerHash.count(); } |
| 304 }; | 314 }; |
| 305 | 315 |
| 306 #endif | 316 #endif |
| OLD | NEW |