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(GRAPHITE_TEST_UTILS) 16 #include "include/private/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 } globalCache()40 const GlobalCache* globalCache() const { 41 return fContext->fSharedContext->globalCache(); 42 } globalCache()43 GlobalCache* globalCache() { 44 return fContext->fSharedContext->globalCache(); 45 } rendererProvider()46 const RendererProvider* rendererProvider() const { 47 return fContext->fSharedContext->rendererProvider(); 48 } resourceProvider()49 ResourceProvider* resourceProvider() const { 50 return fContext->fResourceProvider.get(); 51 } 52 53 #if defined(GRAPHITE_TEST_UTILS) startCapture()54 void startCapture() { 55 fContext->fQueueManager->startCapture(); 56 } stopCapture()57 void stopCapture() { 58 fContext->fQueueManager->stopCapture(); 59 } 60 61 void deregisterRecorder(const Recorder*); 62 63 bool readPixels(const SkPixmap&, 64 const TextureProxy*, 65 const SkImageInfo& srcImageInfo, 66 int srcX, int srcY); 67 68 bool supportsPathRendererStrategy(PathRendererStrategy); 69 #endif 70 71 private: 72 friend class Context; // to construct/copy this type. 73 ContextPriv(Context * context)74 explicit ContextPriv(Context* context) : fContext(context) {} 75 76 ContextPriv& operator=(const ContextPriv&) = delete; 77 78 // No taking addresses of this type. 79 const ContextPriv* operator&() const; 80 ContextPriv *operator&(); 81 82 Context* fContext; 83 }; 84 priv()85inline ContextPriv Context::priv() { return ContextPriv(this); } 86 87 // NOLINTNEXTLINE(readability-const-return-type) priv()88inline const ContextPriv Context::priv() const { 89 return ContextPriv(const_cast<Context *>(this)); 90 } 91 92 // This class is friended by the Context and allows the backend ContextFactory functions to 93 // trampoline through this to call the private Context ctor. We can't directly friend the factory 94 // functions in Context because they are in a different namespace and we don't want to declare the 95 // functions in Context.h 96 class ContextCtorAccessor { 97 public: 98 static std::unique_ptr<Context> MakeContext(sk_sp<SharedContext>, 99 std::unique_ptr<QueueManager>, 100 const ContextOptions&); 101 }; 102 103 } // namespace skgpu::graphite 104 105 #endif // skgpu_graphite_ContextPriv_DEFINED 106