Robert Phillips | 26f3aeb | 2020-09-16 10:57:32 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 "src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.h" |
| 9 | |
| 10 | GrThreadSafeUniquelyKeyedProxyViewCache::GrThreadSafeUniquelyKeyedProxyViewCache() {} |
| 11 | |
| 12 | GrThreadSafeUniquelyKeyedProxyViewCache::~GrThreadSafeUniquelyKeyedProxyViewCache() { |
Robert Phillips | f3e2b3c | 2020-09-18 14:07:43 -0400 | [diff] [blame^] | 13 | fUniquelyKeyedProxyViews.foreach([this](Entry* v) { this->recycleEntry(v); }); |
Robert Phillips | 26f3aeb | 2020-09-16 10:57:32 -0400 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | #if GR_TEST_UTILS |
| 17 | int GrThreadSafeUniquelyKeyedProxyViewCache::numEntries() const { |
| 18 | SkAutoSpinlock lock{fSpinLock}; |
| 19 | |
| 20 | return fUniquelyKeyedProxyViews.count(); |
| 21 | } |
| 22 | |
Robert Phillips | 752f7e1 | 2020-09-18 12:28:59 -0400 | [diff] [blame] | 23 | int GrThreadSafeUniquelyKeyedProxyViewCache::count() const { |
Robert Phillips | 26f3aeb | 2020-09-16 10:57:32 -0400 | [diff] [blame] | 24 | SkAutoSpinlock lock{fSpinLock}; |
| 25 | |
Robert Phillips | 752f7e1 | 2020-09-18 12:28:59 -0400 | [diff] [blame] | 26 | return fUniquelyKeyedProxyViews.count(); |
Robert Phillips | 26f3aeb | 2020-09-16 10:57:32 -0400 | [diff] [blame] | 27 | } |
| 28 | #endif |
| 29 | |
| 30 | void GrThreadSafeUniquelyKeyedProxyViewCache::dropAllRefs() { |
| 31 | SkAutoSpinlock lock{fSpinLock}; |
| 32 | |
Robert Phillips | f3e2b3c | 2020-09-18 14:07:43 -0400 | [diff] [blame^] | 33 | fUniquelyKeyedProxyViews.foreach([this](Entry* v) { this->recycleEntry(v); }); |
Robert Phillips | 26f3aeb | 2020-09-16 10:57:32 -0400 | [diff] [blame] | 34 | fUniquelyKeyedProxyViews.reset(); |
| 35 | } |
| 36 | |
Robert Phillips | 12d06a3 | 2020-09-16 12:31:34 -0400 | [diff] [blame] | 37 | void GrThreadSafeUniquelyKeyedProxyViewCache::dropAllUniqueRefs() { |
| 38 | SkAutoSpinlock lock{fSpinLock}; |
| 39 | |
Robert Phillips | 752f7e1 | 2020-09-18 12:28:59 -0400 | [diff] [blame] | 40 | fUniquelyKeyedProxyViews.foreach([](Entry* v) { |
Robert Phillips | 12d06a3 | 2020-09-16 12:31:34 -0400 | [diff] [blame] | 41 | // problematic |
| 42 | }); |
| 43 | } |
| 44 | |
Robert Phillips | 26f3aeb | 2020-09-16 10:57:32 -0400 | [diff] [blame] | 45 | GrSurfaceProxyView GrThreadSafeUniquelyKeyedProxyViewCache::find(const GrUniqueKey& key) { |
| 46 | SkAutoSpinlock lock{fSpinLock}; |
| 47 | |
Robert Phillips | 752f7e1 | 2020-09-18 12:28:59 -0400 | [diff] [blame] | 48 | Entry* tmp = fUniquelyKeyedProxyViews.find(key); |
Robert Phillips | 26f3aeb | 2020-09-16 10:57:32 -0400 | [diff] [blame] | 49 | if (tmp) { |
Robert Phillips | 752f7e1 | 2020-09-18 12:28:59 -0400 | [diff] [blame] | 50 | return tmp->fView; |
Robert Phillips | 26f3aeb | 2020-09-16 10:57:32 -0400 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | return {}; |
| 54 | } |
| 55 | |
| 56 | GrSurfaceProxyView GrThreadSafeUniquelyKeyedProxyViewCache::internalAdd( |
| 57 | const GrUniqueKey& key, |
| 58 | const GrSurfaceProxyView& view) { |
Robert Phillips | 752f7e1 | 2020-09-18 12:28:59 -0400 | [diff] [blame] | 59 | Entry* tmp = fUniquelyKeyedProxyViews.find(key); |
Robert Phillips | 26f3aeb | 2020-09-16 10:57:32 -0400 | [diff] [blame] | 60 | if (!tmp) { |
Robert Phillips | f3e2b3c | 2020-09-18 14:07:43 -0400 | [diff] [blame^] | 61 | tmp = this->getEntry(key, view); |
Robert Phillips | 752f7e1 | 2020-09-18 12:28:59 -0400 | [diff] [blame] | 62 | fUniquelyKeyedProxyViews.add(tmp); |
Robert Phillips | 26f3aeb | 2020-09-16 10:57:32 -0400 | [diff] [blame] | 63 | } |
| 64 | |
Robert Phillips | 752f7e1 | 2020-09-18 12:28:59 -0400 | [diff] [blame] | 65 | return tmp->fView; |
Robert Phillips | 26f3aeb | 2020-09-16 10:57:32 -0400 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | GrSurfaceProxyView GrThreadSafeUniquelyKeyedProxyViewCache::add(const GrUniqueKey& key, |
| 69 | const GrSurfaceProxyView& view) { |
| 70 | SkAutoSpinlock lock{fSpinLock}; |
| 71 | |
| 72 | return this->internalAdd(key, view); |
| 73 | } |