xref: /aosp_15_r20/external/skia/src/gpu/ganesh/GrContextThreadSafeProxyPriv.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2018 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 GrContextThreadSafeProxyPriv_DEFINED
9 #define GrContextThreadSafeProxyPriv_DEFINED
10 
11 #include "include/gpu/ganesh/GrContextThreadSafeProxy.h"
12 #include "include/private/gpu/ganesh/GrContext_Base.h"
13 
14 #include "src/gpu/ganesh/GrCaps.h"
15 #include "src/text/gpu/TextBlobRedrawCoordinator.h"
16 
17 /**
18  * Class that adds methods to GrContextThreadSafeProxy that are only intended for use internal to
19  * Skia. This class is purely a privileged window into GrContextThreadSafeProxy. It should never
20  * have additional data members or virtual methods.
21  */
22 class GrContextThreadSafeProxyPriv {
23 public:
24     void init(sk_sp<const GrCaps>, sk_sp<GrThreadSafePipelineBuilder>) const;
25 
matches(GrContext_Base * candidate)26     bool matches(GrContext_Base* candidate) const {
27         return fProxy == candidate->threadSafeProxy().get();
28     }
29 
backend()30     GrBackend backend() const { return fProxy->fBackend; }
options()31     const GrContextOptions& options() const { return fProxy->fOptions; }
contextID()32     uint32_t contextID() const { return fProxy->fContextID; }
33 
caps()34     const GrCaps* caps() const { return fProxy->fCaps.get(); }
refCaps()35     sk_sp<const GrCaps> refCaps() const { return fProxy->fCaps; }
36 
getTextBlobRedrawCoordinator()37     sktext::gpu::TextBlobRedrawCoordinator* getTextBlobRedrawCoordinator() {
38         return fProxy->fTextBlobRedrawCoordinator.get();
39     }
getTextBlobRedrawCoordinator()40     const sktext::gpu::TextBlobRedrawCoordinator* getTextBlobRedrawCoordinator() const {
41         return fProxy->fTextBlobRedrawCoordinator.get();
42     }
43 
threadSafeCache()44     GrThreadSafeCache* threadSafeCache() { return fProxy->fThreadSafeCache.get(); }
threadSafeCache()45     const GrThreadSafeCache* threadSafeCache() const { return fProxy->fThreadSafeCache.get(); }
46 
abandonContext()47     void abandonContext() { fProxy->abandonContext(); }
abandoned()48     bool abandoned() const { return fProxy->abandoned(); }
49 
50     // GrContextThreadSafeProxyPriv
51     static sk_sp<GrContextThreadSafeProxy> Make(GrBackendApi, const GrContextOptions&);
52 
53 private:
GrContextThreadSafeProxyPriv(GrContextThreadSafeProxy * proxy)54     explicit GrContextThreadSafeProxyPriv(GrContextThreadSafeProxy* proxy) : fProxy(proxy) {}
55     GrContextThreadSafeProxyPriv& operator=(const GrContextThreadSafeProxyPriv&) = delete;
56 
57     // No taking addresses of this type.
58     const GrContextThreadSafeProxyPriv* operator&() const = delete;
59     GrContextThreadSafeProxyPriv* operator&() = delete;
60 
61     GrContextThreadSafeProxy* fProxy;
62 
63     friend class GrContextThreadSafeProxy;  // to construct/copy this type.
64 };
65 
priv()66 inline GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() {
67     return GrContextThreadSafeProxyPriv(this);
68 }
69 
priv()70 inline const GrContextThreadSafeProxyPriv GrContextThreadSafeProxy::priv() const {  // NOLINT(readability-const-return-type)
71     return GrContextThreadSafeProxyPriv(const_cast<GrContextThreadSafeProxy*>(this));
72 }
73 
74 #endif
75