| 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 #include "GrAtlas.h" | 8 #include "GrAtlas.h" |
| 9 #include "GrGpu.h" | 9 #include "GrGpu.h" |
| 10 #include "GrLayerCache.h" | 10 #include "GrLayerCache.h" |
| 11 | 11 |
| 12 DECLARE_SKMESSAGEBUS_MESSAGE(GrPictureDeletedMessage); |
| 13 |
| 12 #ifdef SK_DEBUG | 14 #ifdef SK_DEBUG |
| 13 void GrCachedLayer::validate(const GrTexture* backingTexture) const { | 15 void GrCachedLayer::validate(const GrTexture* backingTexture) const { |
| 14 SkASSERT(SK_InvalidGenID != fKey.getPictureID()); | 16 SkASSERT(SK_InvalidGenID != fKey.getPictureID()); |
| 15 SkASSERT(-1 != fKey.getLayerID()); | 17 SkASSERT(-1 != fKey.getLayerID()); |
| 16 | 18 |
| 17 | 19 |
| 18 if (NULL != fTexture) { | 20 if (NULL != fTexture) { |
| 19 // If the layer is in some texture then it must occupy some rectangle | 21 // If the layer is in some texture then it must occupy some rectangle |
| 20 SkASSERT(!fRect.isEmpty()); | 22 SkASSERT(!fRect.isEmpty()); |
| 21 if (!this->isAtlased()) { | 23 if (!this->isAtlased()) { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 fCache->validate(); | 218 fCache->validate(); |
| 217 } | 219 } |
| 218 ~GrAutoValidateCache() { | 220 ~GrAutoValidateCache() { |
| 219 fCache->validate(); | 221 fCache->validate(); |
| 220 } | 222 } |
| 221 private: | 223 private: |
| 222 GrLayerCache* fCache; | 224 GrLayerCache* fCache; |
| 223 }; | 225 }; |
| 224 #endif | 226 #endif |
| 225 | 227 |
| 226 void GrLayerCache::purge(const SkPicture* picture) { | 228 void GrLayerCache::purge(uint32_t pictureID) { |
| 229 |
| 227 SkDEBUGCODE(GrAutoValidateCache avc(this);) | 230 SkDEBUGCODE(GrAutoValidateCache avc(this);) |
| 228 | 231 |
| 229 // We need to find all the layers associated with 'picture' and remove them. | 232 // We need to find all the layers associated with 'picture' and remove them. |
| 230 SkTDArray<GrCachedLayer*> toBeRemoved; | 233 SkTDArray<GrCachedLayer*> toBeRemoved; |
| 231 | 234 |
| 232 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); | 235 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); |
| 233 for (; !iter.done(); ++iter) { | 236 for (; !iter.done(); ++iter) { |
| 234 if (picture->uniqueID() == (*iter).pictureID()) { | 237 if (pictureID == (*iter).pictureID()) { |
| 235 *toBeRemoved.append() = &(*iter); | 238 *toBeRemoved.append() = &(*iter); |
| 236 } | 239 } |
| 237 } | 240 } |
| 238 | 241 |
| 239 for (int i = 0; i < toBeRemoved.count(); ++i) { | 242 for (int i = 0; i < toBeRemoved.count(); ++i) { |
| 240 this->unlock(toBeRemoved[i]); | 243 this->unlock(toBeRemoved[i]); |
| 241 fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i])); | 244 fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i])); |
| 242 SkDELETE(toBeRemoved[i]); | 245 SkDELETE(toBeRemoved[i]); |
| 243 } | 246 } |
| 244 | 247 |
| 245 GrPictureInfo* pictInfo = fPictureHash.find(picture->uniqueID()); | 248 GrPictureInfo* pictInfo = fPictureHash.find(pictureID); |
| 246 if (NULL != pictInfo) { | 249 if (NULL != pictInfo) { |
| 247 fPictureHash.remove(picture->uniqueID()); | 250 fPictureHash.remove(pictureID); |
| 248 SkDELETE(pictInfo); | 251 SkDELETE(pictInfo); |
| 249 } | 252 } |
| 250 } | 253 } |
| 254 |
| 255 class GrPictureDeletionListener : public SkPicture::DeletionListener { |
| 256 virtual void onDeletion(uint32_t pictureID) SK_OVERRIDE{ |
| 257 const GrPictureDeletedMessage message = { pictureID }; |
| 258 SkMessageBus<GrPictureDeletedMessage>::Post(message); |
| 259 } |
| 260 }; |
| 261 |
| 262 void GrLayerCache::trackPicture(const SkPicture* picture) { |
| 263 if (NULL == fDeletionListener) { |
| 264 fDeletionListener.reset(SkNEW(GrPictureDeletionListener)); |
| 265 } |
| 266 |
| 267 picture->addDeletionListener(fDeletionListener); |
| 268 } |
| 269 |
| 270 void GrLayerCache::processDeletedPictures() { |
| 271 SkTDArray<GrPictureDeletedMessage> deletedPictures; |
| 272 fPictDeletionInbox.poll(&deletedPictures); |
| 273 |
| 274 for (int i = 0; i < deletedPictures.count(); i++) { |
| 275 this->purge(deletedPictures[i].pictureID); |
| 276 } |
| 277 } |
| 278 |
| OLD | NEW |