Debian Codegraph @

src/gpu/graphite/ContextPriv.h

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