• 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_ContextPriv_DEFINED
9 #define skgpu_ContextPriv_DEFINED
10 
11 #include "experimental/graphite/include/Context.h"
12 
13 class SkShaderCodeDictionary;
14 
15 namespace skgpu {
16 
17 class GlobalCache;
18 class Gpu;
19 class ResourceProvider;
20 
21 /** Class that adds methods to Context that are only intended for use internal to Skia.
22     This class is purely a privileged window into Context. It should never have additional
23     data members or virtual methods. */
24 class ContextPriv {
25 public:
26     Gpu* gpu();
27     const Gpu* gpu() const;
28 
29     SkShaderCodeDictionary* shaderCodeDictionary();
30 
31 private:
32     friend class Context; // to construct/copy this type.
33 
ContextPriv(Context * context)34     explicit ContextPriv(Context* context) : fContext(context) {}
35 
36     ContextPriv& operator=(const ContextPriv&) = delete;
37 
38     // No taking addresses of this type.
39     const ContextPriv* operator&() const;
40     ContextPriv *operator&();
41 
42     Context* fContext;
43 };
44 
priv()45 inline ContextPriv Context::priv() { return ContextPriv(this); }
46 
47 // NOLINTNEXTLINE(readability-const-return-type)
priv()48 inline const ContextPriv Context::priv() const {
49     return ContextPriv(const_cast<Context *>(this));
50 }
51 
52 } // namespace skgpu
53 
54 #endif // skgpu_ContextPriv_DEFINED
55