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