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 #include "GrSurfacePriv.h" | 11 #include "GrSurfacePriv.h" |
12 | 12 |
13 DECLARE_SKMESSAGEBUS_MESSAGE(GrPictureDeletedMessage); | |
14 | |
15 #ifdef SK_DEBUG | 13 #ifdef SK_DEBUG |
16 void GrCachedLayer::validate(const GrTexture* backingTexture) const { | 14 void GrCachedLayer::validate(const GrTexture* backingTexture) const { |
17 SkASSERT(SK_InvalidGenID != fKey.pictureID()); | 15 SkASSERT(SK_InvalidGenID != fKey.pictureID()); |
18 SkASSERT(fKey.start() >= 0); | 16 SkASSERT(fKey.start() >= 0); |
19 | 17 |
20 if (fTexture) { | 18 if (fTexture) { |
21 // If the layer is in some texture then it must occupy some rectangle | 19 // If the layer is in some texture then it must occupy some rectangle |
22 SkASSERT(!fRect.isEmpty()); | 20 SkASSERT(!fRect.isEmpty()); |
23 if (!this->isAtlased()) { | 21 if (!this->isAtlased()) { |
24 // If it isn't atlased then the rectangle should start at the origin | 22 // If it isn't atlased then the rectangle should start at the origin |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 | 447 |
450 this->purgePlot(plot); | 448 this->purgePlot(plot); |
451 } | 449 } |
452 | 450 |
453 SkASSERT(0 == fPictureHash.count()); | 451 SkASSERT(0 == fPictureHash.count()); |
454 | 452 |
455 fContext->discardRenderTarget(fAtlas->getTexture()->asRenderTarget()); | 453 fContext->discardRenderTarget(fAtlas->getTexture()->asRenderTarget()); |
456 } | 454 } |
457 #endif | 455 #endif |
458 | 456 |
459 class GrPictureDeletionListener : public SkPicture::DeletionListener { | |
460 virtual void onDeletion(uint32_t pictureID) SK_OVERRIDE{ | |
461 const GrPictureDeletedMessage message = { pictureID }; | |
462 SkMessageBus<GrPictureDeletedMessage>::Post(message); | |
463 } | |
464 }; | |
465 | |
466 void GrLayerCache::trackPicture(const SkPicture* picture) { | |
467 if (NULL == fDeletionListener) { | |
468 fDeletionListener.reset(SkNEW(GrPictureDeletionListener)); | |
469 } | |
470 | |
471 picture->addDeletionListener(fDeletionListener); | |
472 } | |
473 | |
474 void GrLayerCache::processDeletedPictures() { | 457 void GrLayerCache::processDeletedPictures() { |
475 SkTDArray<GrPictureDeletedMessage> deletedPictures; | 458 SkTDArray<SkPicture::DeletionMessage> deletedPictures; |
476 fPictDeletionInbox.poll(&deletedPictures); | 459 fPictDeletionInbox.poll(&deletedPictures); |
477 | 460 |
478 for (int i = 0; i < deletedPictures.count(); i++) { | 461 for (int i = 0; i < deletedPictures.count(); i++) { |
479 this->purge(deletedPictures[i].pictureID); | 462 this->purge(deletedPictures[i].uniqueID); |
480 } | 463 } |
481 } | 464 } |
482 | 465 |
483 #ifdef SK_DEVELOPER | 466 #ifdef SK_DEVELOPER |
484 void GrLayerCache::writeLayersToDisk(const SkString& dirName) { | 467 void GrLayerCache::writeLayersToDisk(const SkString& dirName) { |
485 | 468 |
486 if (fAtlas) { | 469 if (fAtlas) { |
487 GrTexture* atlasTexture = fAtlas->getTexture(); | 470 GrTexture* atlasTexture = fAtlas->getTexture(); |
488 if (NULL != atlasTexture) { | 471 if (NULL != atlasTexture) { |
489 SkString fileName(dirName); | 472 SkString fileName(dirName); |
(...skipping 11 matching lines...) Expand all Loading... |
501 continue; | 484 continue; |
502 } | 485 } |
503 | 486 |
504 SkString fileName(dirName); | 487 SkString fileName(dirName); |
505 fileName.appendf("\\%d-%d.png", layer->fKey.pictureID(), layer->fKey.sta
rt()); | 488 fileName.appendf("\\%d-%d.png", layer->fKey.pictureID(), layer->fKey.sta
rt()); |
506 | 489 |
507 layer->texture()->surfacePriv().savePixels(fileName.c_str()); | 490 layer->texture()->surfacePriv().savePixels(fileName.c_str()); |
508 } | 491 } |
509 } | 492 } |
510 #endif | 493 #endif |
OLD | NEW |