blob: 0c305d2021873d8eb291594000a4d9e8f3ac0e94 [file] [log] [blame]
Robert Phillips26f3aeb2020-09-16 10:57:32 -04001/*
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
10GrThreadSafeUniquelyKeyedProxyViewCache::GrThreadSafeUniquelyKeyedProxyViewCache() {}
11
12GrThreadSafeUniquelyKeyedProxyViewCache::~GrThreadSafeUniquelyKeyedProxyViewCache() {
Robert Phillipsf3e2b3c2020-09-18 14:07:43 -040013 fUniquelyKeyedProxyViews.foreach([this](Entry* v) { this->recycleEntry(v); });
Robert Phillips26f3aeb2020-09-16 10:57:32 -040014}
15
16#if GR_TEST_UTILS
17int GrThreadSafeUniquelyKeyedProxyViewCache::numEntries() const {
18 SkAutoSpinlock lock{fSpinLock};
19
20 return fUniquelyKeyedProxyViews.count();
21}
22
Robert Phillips752f7e12020-09-18 12:28:59 -040023int GrThreadSafeUniquelyKeyedProxyViewCache::count() const {
Robert Phillips26f3aeb2020-09-16 10:57:32 -040024 SkAutoSpinlock lock{fSpinLock};
25
Robert Phillips752f7e12020-09-18 12:28:59 -040026 return fUniquelyKeyedProxyViews.count();
Robert Phillips26f3aeb2020-09-16 10:57:32 -040027}
28#endif
29
30void GrThreadSafeUniquelyKeyedProxyViewCache::dropAllRefs() {
31 SkAutoSpinlock lock{fSpinLock};
32
Robert Phillipsf3e2b3c2020-09-18 14:07:43 -040033 fUniquelyKeyedProxyViews.foreach([this](Entry* v) { this->recycleEntry(v); });
Robert Phillips26f3aeb2020-09-16 10:57:32 -040034 fUniquelyKeyedProxyViews.reset();
35}
36
Robert Phillips12d06a32020-09-16 12:31:34 -040037void GrThreadSafeUniquelyKeyedProxyViewCache::dropAllUniqueRefs() {
38 SkAutoSpinlock lock{fSpinLock};
39
Robert Phillips752f7e12020-09-18 12:28:59 -040040 fUniquelyKeyedProxyViews.foreach([](Entry* v) {
Robert Phillips12d06a32020-09-16 12:31:34 -040041 // problematic
42 });
43}
44
Robert Phillips26f3aeb2020-09-16 10:57:32 -040045GrSurfaceProxyView GrThreadSafeUniquelyKeyedProxyViewCache::find(const GrUniqueKey& key) {
46 SkAutoSpinlock lock{fSpinLock};
47
Robert Phillips752f7e12020-09-18 12:28:59 -040048 Entry* tmp = fUniquelyKeyedProxyViews.find(key);
Robert Phillips26f3aeb2020-09-16 10:57:32 -040049 if (tmp) {
Robert Phillips752f7e12020-09-18 12:28:59 -040050 return tmp->fView;
Robert Phillips26f3aeb2020-09-16 10:57:32 -040051 }
52
53 return {};
54}
55
56GrSurfaceProxyView GrThreadSafeUniquelyKeyedProxyViewCache::internalAdd(
57 const GrUniqueKey& key,
58 const GrSurfaceProxyView& view) {
Robert Phillips752f7e12020-09-18 12:28:59 -040059 Entry* tmp = fUniquelyKeyedProxyViews.find(key);
Robert Phillips26f3aeb2020-09-16 10:57:32 -040060 if (!tmp) {
Robert Phillipsf3e2b3c2020-09-18 14:07:43 -040061 tmp = this->getEntry(key, view);
Robert Phillips752f7e12020-09-18 12:28:59 -040062 fUniquelyKeyedProxyViews.add(tmp);
Robert Phillips26f3aeb2020-09-16 10:57:32 -040063 }
64
Robert Phillips752f7e12020-09-18 12:28:59 -040065 return tmp->fView;
Robert Phillips26f3aeb2020-09-16 10:57:32 -040066}
67
68GrSurfaceProxyView GrThreadSafeUniquelyKeyedProxyViewCache::add(const GrUniqueKey& key,
69 const GrSurfaceProxyView& view) {
70 SkAutoSpinlock lock{fSpinLock};
71
72 return this->internalAdd(key, view);
73}