| 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); | 12 DECLARE_SKMESSAGEBUS_MESSAGE(GrPictureDeletedMessage); |
| 13 | 13 |
| 14 #ifdef SK_DEBUG | 14 #ifdef SK_DEBUG |
| 15 void GrCachedLayer::validate(const GrTexture* backingTexture) const { | 15 void GrCachedLayer::validate(const GrTexture* backingTexture) const { |
| 16 SkASSERT(SK_InvalidGenID != fKey.pictureID()); | 16 SkASSERT(SK_InvalidGenID != fKey.pictureID()); |
| 17 SkASSERT(fKey.start() > 0 && fKey.stop() > 0); | 17 SkASSERT(fKey.start() > 0); |
| 18 | 18 |
| 19 | 19 |
| 20 if (fTexture) { | 20 if (fTexture) { |
| 21 // 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 |
| 22 SkASSERT(!fRect.isEmpty()); | 22 SkASSERT(!fRect.isEmpty()); |
| 23 if (!this->isAtlased()) { | 23 if (!this->isAtlased()) { |
| 24 // If it isn't atlased then the rectangle should start at the origin | 24 // If it isn't atlased then the rectangle should start at the origin |
| 25 SkASSERT(0.0f == fRect.fLeft && 0.0f == fRect.fTop); | 25 SkASSERT(0.0f == fRect.fLeft && 0.0f == fRect.fTop); |
| 26 } | 26 } |
| 27 } else { | 27 } else { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 fAtlas.free(); | 112 fAtlas.free(); |
| 113 // GrLayerCache always assumes an atlas exists so recreate it. The atlas | 113 // GrLayerCache always assumes an atlas exists so recreate it. The atlas |
| 114 // lazily allocates a replacement texture so reallocating a new | 114 // lazily allocates a replacement texture so reallocating a new |
| 115 // atlas here won't disrupt a GrContext::abandonContext or freeGpuResources. | 115 // atlas here won't disrupt a GrContext::abandonContext or freeGpuResources. |
| 116 // TODO: Make GrLayerCache lazily allocate the atlas manager? | 116 // TODO: Make GrLayerCache lazily allocate the atlas manager? |
| 117 this->initAtlas(); | 117 this->initAtlas(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID, | 120 GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID, |
| 121 int start, int stop, | 121 int start, int stop, |
| 122 const SkIPoint& offset, | |
| 123 const SkMatrix& ctm, | 122 const SkMatrix& ctm, |
| 124 const SkPaint* paint) { | 123 const SkPaint* paint) { |
| 125 SkASSERT(pictureID != SK_InvalidGenID && start > 0 && stop > 0); | 124 SkASSERT(pictureID != SK_InvalidGenID && start > 0 && stop > 0); |
| 126 | 125 |
| 127 GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, of
fset, ctm, paint)); | 126 GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, ct
m, paint)); |
| 128 fLayerHash.add(layer); | 127 fLayerHash.add(layer); |
| 129 return layer; | 128 return layer; |
| 130 } | 129 } |
| 131 | 130 |
| 132 GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID, | 131 GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID, |
| 133 int start, int stop, | 132 int start, |
| 134 const SkIPoint& offset, | |
| 135 const SkMatrix& ctm) { | 133 const SkMatrix& ctm) { |
| 136 SkASSERT(pictureID != SK_InvalidGenID && start > 0 && stop > 0); | 134 SkASSERT(pictureID != SK_InvalidGenID && start > 0); |
| 137 return fLayerHash.find(GrCachedLayer::Key(pictureID, start, stop, offset, ct
m)); | 135 return fLayerHash.find(GrCachedLayer::Key(pictureID, start, ctm)); |
| 138 } | 136 } |
| 139 | 137 |
| 140 GrCachedLayer* GrLayerCache::findLayerOrCreate(uint32_t pictureID, | 138 GrCachedLayer* GrLayerCache::findLayerOrCreate(uint32_t pictureID, |
| 141 int start, int stop, | 139 int start, int stop, |
| 142 const SkIPoint& offset, | |
| 143 const SkMatrix& ctm, | 140 const SkMatrix& ctm, |
| 144 const SkPaint* paint) { | 141 const SkPaint* paint) { |
| 145 SkASSERT(pictureID != SK_InvalidGenID && start > 0 && stop > 0); | 142 SkASSERT(pictureID != SK_InvalidGenID && start > 0 && stop > 0); |
| 146 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, start,
stop, offset, ctm)); | 143 GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, start,
ctm)); |
| 147 if (NULL == layer) { | 144 if (NULL == layer) { |
| 148 layer = this->createLayer(pictureID, start, stop, offset, ctm, paint); | 145 layer = this->createLayer(pictureID, start, stop, ctm, paint); |
| 149 } | 146 } |
| 150 | 147 |
| 151 return layer; | 148 return layer; |
| 152 } | 149 } |
| 153 | 150 |
| 154 bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc, bool do
ntAtlas) { | 151 bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc, bool do
ntAtlas) { |
| 155 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas->getTexture(), layer);) | 152 SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas->getTexture(), layer);) |
| 156 | 153 |
| 157 if (layer->locked()) { | 154 if (layer->locked()) { |
| 158 // This layer is already locked | 155 // This layer is already locked |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 | 416 |
| 420 void GrLayerCache::processDeletedPictures() { | 417 void GrLayerCache::processDeletedPictures() { |
| 421 SkTDArray<GrPictureDeletedMessage> deletedPictures; | 418 SkTDArray<GrPictureDeletedMessage> deletedPictures; |
| 422 fPictDeletionInbox.poll(&deletedPictures); | 419 fPictDeletionInbox.poll(&deletedPictures); |
| 423 | 420 |
| 424 for (int i = 0; i < deletedPictures.count(); i++) { | 421 for (int i = 0; i < deletedPictures.count(); i++) { |
| 425 this->purge(deletedPictures[i].pictureID); | 422 this->purge(deletedPictures[i].pictureID); |
| 426 } | 423 } |
| 427 } | 424 } |
| 428 | 425 |
| OLD | NEW |