• 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_Context_DEFINED
9 #define skgpu_Context_DEFINED
10 
11 #include <vector>
12 #include "include/core/SkBlendMode.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/core/SkShader.h"
15 #include "include/core/SkTileMode.h"
16 
17 #include "experimental/graphite/include/GraphiteTypes.h"
18 
19 namespace skgpu {
20 
21 class ContextPriv;
22 class Gpu;
23 class Recorder;
24 class Recording;
25 namespace mtl { struct BackendContext; }
26 
27 struct ShaderCombo {
28     enum class ShaderType {
29         kNone,
30         kLinearGradient,
31         kRadialGradient,
32         kSweepGradient,
33         kConicalGradient
34     };
35 
ShaderComboShaderCombo36     ShaderCombo() {}
ShaderComboShaderCombo37     ShaderCombo(std::vector<ShaderType> types,
38                 std::vector<SkTileMode> tileModes)
39             : fTypes(std::move(types))
40             , fTileModes(std::move(tileModes)) {
41     }
42     std::vector<ShaderType> fTypes;
43     std::vector<SkTileMode> fTileModes;
44 };
45 
46 struct PaintCombo {
47     std::vector<ShaderCombo> fShaders;
48     std::vector<SkBlendMode> fBlendModes;
49 };
50 
51 class Context final : public SkRefCnt {
52 public:
53     ~Context() override;
54 
55 #ifdef SK_METAL
56     static sk_sp<Context> MakeMetal(const skgpu::mtl::BackendContext&);
57 #endif
58 
59     sk_sp<Recorder> createRecorder();
60 
61     void insertRecording(std::unique_ptr<Recording>);
62     void submit(SyncToCpu = SyncToCpu::kNo);
63 
64     void preCompile(const PaintCombo&);
65 
66     // Provides access to functions that aren't part of the public API.
67     ContextPriv priv();
68     const ContextPriv priv() const;  // NOLINT(readability-const-return-type)
69 
70 protected:
71     Context(sk_sp<Gpu>);
72 
73 private:
74     friend class ContextPriv;
75 
76     std::vector<std::unique_ptr<Recording>> fRecordings;
77     sk_sp<Gpu> fGpu;
78 };
79 
80 } // namespace skgpu
81 
82 #endif // skgpu_Context_DEFINED
83