• 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_Gpu_DEFINED
9 #define skgpu_Gpu_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/core/SkSize.h"
13 #include "include/private/SkDeque.h"
14 
15 #include "experimental/graphite/include/GraphiteTypes.h"
16 
17 namespace SkSL {
18     class Compiler;
19 }
20 
21 namespace skgpu {
22 
23 class BackendTexture;
24 class Caps;
25 class CommandBuffer;
26 class GlobalCache;
27 class GpuWorkSubmission;
28 class ResourceProvider;
29 class SingleOwner;
30 class TextureInfo;
31 
32 // TODO: Figure out if we need to fission Gpu into parts that are needed by a Recorder and parts
33 // that are needed only by the Context. In general the Recorder part of Gpu should not be stateful
34 // as it will be shared and used by all Recorders. We also don't need calls like submit on the
35 // Recorders.
36 class Gpu : public SkRefCnt {
37 public:
38     ~Gpu() override;
39 
40     /**
41      * Gets the capabilities of the draw target.
42      */
caps()43     const Caps* caps() const { return fCaps.get(); }
44     sk_sp<const Caps> refCaps() const;
45 
shaderCompiler()46     SkSL::Compiler* shaderCompiler() const { return fCompiler.get(); }
47 
48     virtual std::unique_ptr<ResourceProvider> makeResourceProvider(sk_sp<GlobalCache>,
49                                                                    SingleOwner*) const = 0;
50 
51     bool submit(sk_sp<CommandBuffer>);
52     void checkForFinishedWork(SyncToCpu);
53 
54     BackendTexture createBackendTexture(SkISize dimensions, const TextureInfo&);
55     void deleteBackendTexture(BackendTexture&);
56 
57 #if GRAPHITE_TEST_UTILS
testingOnly_startCapture()58     virtual void testingOnly_startCapture() {}
testingOnly_endCapture()59     virtual void testingOnly_endCapture() {}
60 #endif
61 
62 protected:
63     Gpu(sk_sp<const Caps>);
64 
65     // Subclass must call this to initialize compiler in its constructor.
66     void initCompiler();
67 
68     using OutstandingSubmission = std::unique_ptr<GpuWorkSubmission>;
69     SkDeque fOutstandingSubmissions;
70 
71 private:
72     virtual bool onSubmit(sk_sp<CommandBuffer>) = 0;
73 
74     virtual BackendTexture onCreateBackendTexture(SkISize dimensions, const TextureInfo&) = 0;
75     virtual void onDeleteBackendTexture(BackendTexture&) = 0;
76 
77     sk_sp<const Caps> fCaps;
78     // Compiler used for compiling SkSL into backend shader code. We only want to create the
79     // compiler once, as there is significant overhead to the first compile.
80     std::unique_ptr<SkSL::Compiler> fCompiler;
81 };
82 
83 } // namespace skgpu
84 
85 #endif // skgpu_Gpu_DEFINED
86