xref: /aosp_15_r20/external/skia/src/gpu/graphite/ContextPriv.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2021 Google LLC
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 skgpu_graphite_ContextPriv_DEFINED
9 #define skgpu_graphite_ContextPriv_DEFINED
10 
11 #include "include/gpu/graphite/Context.h"
12 #include "src/gpu/graphite/QueueManager.h"
13 #include "src/gpu/graphite/SharedContext.h"
14 
15 #if defined(GPU_TEST_UTILS)
16 #include "src/gpu/graphite/ContextOptionsPriv.h"
17 #endif
18 
19 namespace skgpu::graphite {
20 
21 class Caps;
22 class GlobalCache;
23 class RendererProvider;
24 class ResourceProvider;
25 class ShaderCodeDictionary;
26 
27 /** Class that adds methods to Context that are only intended for use internal to Skia.
28     This class is purely a privileged window into Context. It should never have additional
29     data members or virtual methods. */
30 class ContextPriv {
31 public:
caps()32     const Caps* caps() const { return fContext->fSharedContext->caps(); }
33 
shaderCodeDictionary()34     const ShaderCodeDictionary* shaderCodeDictionary() const {
35         return fContext->fSharedContext->shaderCodeDictionary();
36     }
shaderCodeDictionary()37     ShaderCodeDictionary* shaderCodeDictionary() {
38         return fContext->fSharedContext->shaderCodeDictionary();
39     }
40 #if defined(GPU_TEST_UTILS)
globalCache()41     const GlobalCache* globalCache() const {
42         return fContext->fSharedContext->globalCache();
43     }
globalCache()44     GlobalCache* globalCache() {
45         return fContext->fSharedContext->globalCache();
46     }
47 #endif
rendererProvider()48     const RendererProvider* rendererProvider() const {
49         return fContext->fSharedContext->rendererProvider();
50     }
resourceProvider()51     ResourceProvider* resourceProvider() const {
52         return fContext->fResourceProvider.get();
53     }
sharedContext()54     SharedContext* sharedContext() {
55         return fContext->fSharedContext.get();
56     }
57 
58 #if defined(GPU_TEST_UTILS)
startCapture()59     void startCapture() {
60         fContext->fQueueManager->startCapture();
61     }
stopCapture()62     void stopCapture() {
63         fContext->fQueueManager->stopCapture();
64     }
65 
deregisterRecorder(const Recorder * recorder)66     void deregisterRecorder(const Recorder* recorder) {
67         fContext->deregisterRecorder(recorder);
68     }
69 
70     bool readPixels(const SkPixmap&,
71                     const TextureProxy*,
72                     const SkImageInfo& srcImageInfo,
73                     int srcX, int srcY);
74 
75     bool supportsPathRendererStrategy(PathRendererStrategy);
76 #endif
77 
78 private:
79     friend class Context; // to construct/copy this type.
80 
ContextPriv(Context * context)81     explicit ContextPriv(Context* context) : fContext(context) {}
82 
83     ContextPriv& operator=(const ContextPriv&) = delete;
84 
85     // No taking addresses of this type.
86     const ContextPriv* operator&() const;
87     ContextPriv *operator&();
88 
89     Context* fContext;
90 };
91 
priv()92 inline ContextPriv Context::priv() { return ContextPriv(this); }
93 
94 // NOLINTNEXTLINE(readability-const-return-type)
priv()95 inline const ContextPriv Context::priv() const {
96     return ContextPriv(const_cast<Context *>(this));
97 }
98 
99 // This class is friended by the Context and allows the backend ContextFactory functions to
100 // trampoline through this to call the private Context ctor. We can't directly friend the factory
101 // functions in Context because they are in a different namespace and we don't want to declare the
102 // functions in Context.h
103 class ContextCtorAccessor {
104 public:
105     static std::unique_ptr<Context> MakeContext(sk_sp<SharedContext>,
106                                                 std::unique_ptr<QueueManager>,
107                                                 const ContextOptions&);
108 };
109 
110 } // namespace skgpu::graphite
111 
112 #endif // skgpu_graphite_ContextPriv_DEFINED
113