joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrTextBlobCache.h" |
| 9 | |
Florin Malita | 4a01ac9 | 2017-03-13 16:45:28 -0400 | [diff] [blame^] | 10 | DECLARE_SKMESSAGEBUS_MESSAGE(GrTextBlobCache::PurgeBlobMessage) |
| 11 | |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 12 | GrTextBlobCache::~GrTextBlobCache() { |
Florin Malita | c337c9e | 2017-03-10 18:02:29 +0000 | [diff] [blame] | 13 | SkDEBUGCODE(this->freeAll();) |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 14 | } |
| 15 | |
joshualitt | 26ffc00 | 2015-04-16 11:24:04 -0700 | [diff] [blame] | 16 | void GrTextBlobCache::freeAll() { |
Florin Malita | 33fdb8d | 2017-03-07 16:51:57 -0500 | [diff] [blame] | 17 | fBlobIDCache.foreach([this](uint32_t, BlobIDCacheEntry* entry) { |
Florin Malita | c337c9e | 2017-03-10 18:02:29 +0000 | [diff] [blame] | 18 | for (const auto& blob : entry->fBlobs) { |
| 19 | fBlobList.remove(blob.get()); |
Florin Malita | 33fdb8d | 2017-03-07 16:51:57 -0500 | [diff] [blame] | 20 | } |
| 21 | }); |
| 22 | |
| 23 | fBlobIDCache.reset(); |
joshualitt | 20ccd40 | 2016-01-05 08:56:56 -0800 | [diff] [blame] | 24 | |
| 25 | // There should be no allocations in the memory pool at this point |
| 26 | SkASSERT(fPool.isEmpty()); |
Florin Malita | 33fdb8d | 2017-03-07 16:51:57 -0500 | [diff] [blame] | 27 | SkASSERT(fBlobList.isEmpty()); |
joshualitt | 26ffc00 | 2015-04-16 11:24:04 -0700 | [diff] [blame] | 28 | } |
Florin Malita | 4a01ac9 | 2017-03-13 16:45:28 -0400 | [diff] [blame^] | 29 | |
| 30 | void GrTextBlobCache::PostPurgeBlobMessage(uint32_t id) { |
| 31 | SkASSERT(id != SK_InvalidGenID); |
| 32 | SkMessageBus<PurgeBlobMessage>::Post(PurgeBlobMessage({id})); |
| 33 | } |