xref: /aosp_15_r20/external/skia/src/gpu/ganesh/GrTextureProxyCacheAccess.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2017 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 #ifndef GrTextureProxyCacheAccess_DEFINED
9 #define GrTextureProxyCacheAccess_DEFINED
10 
11 #include "src/gpu/ganesh/GrTextureProxy.h"
12 
13 class GrProxyProvider;
14 
15 namespace skgpu {
16 class UniqueKey;
17 }
18 
19 /**
20  * This class allows GrResourceCache increased privileged access to GrTextureProxy objects.
21  */
22 class GrTextureProxy::CacheAccess {
23 private:
setUniqueKey(GrProxyProvider * proxyProvider,const skgpu::UniqueKey & key)24     void setUniqueKey(GrProxyProvider* proxyProvider, const skgpu::UniqueKey& key) {
25         fTextureProxy->setUniqueKey(proxyProvider, key);
26     }
27 
clearUniqueKey()28     void clearUniqueKey() {
29         fTextureProxy->clearUniqueKey();
30     }
31 
CacheAccess(GrTextureProxy * textureProxy)32     explicit CacheAccess(GrTextureProxy* textureProxy) : fTextureProxy(textureProxy) {}
33     CacheAccess& operator=(const CacheAccess&) = delete;
34 
35     // No taking addresses of this type.
36     const CacheAccess* operator&() const;
37     CacheAccess* operator&();
38 
39     GrTextureProxy* fTextureProxy;
40 
41     friend class GrTextureProxy;  // to construct/copy this type.
42     friend class GrProxyProvider; // to use this type
43 };
44 
cacheAccess()45 inline GrTextureProxy::CacheAccess GrTextureProxy::cacheAccess() { return CacheAccess(this); }
46 
cacheAccess()47 inline const GrTextureProxy::CacheAccess GrTextureProxy::cacheAccess() const {  // NOLINT(readability-const-return-type)
48     return CacheAccess(const_cast<GrTextureProxy*>(this));
49 }
50 
51 #endif
52