• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 Google Inc.
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 GrDawnGpu_DEFINED
9 #define GrDawnGpu_DEFINED
10 
11 #include "src/gpu/GrGpu.h"
12 #include "dawn/dawncpp.h"
13 
14 class GrPipeline;
15 class GrDawnGpuRTCommandBuffer;
16 class GrDawnGpuTextureCommandBuffer;
17 
18 namespace SkSL {
19     class Compiler;
20 }
21 
22 class GrDawnGpu : public GrGpu {
23 public:
24     static sk_sp<GrGpu> Make(const dawn::Device& device, const GrContextOptions&, GrContext*);
25     GrDawnGpu(GrContext* context, const GrContextOptions& options, const dawn::Device& device);
26 
27     ~GrDawnGpu() override;
28 
29     void disconnect(DisconnectType) override;
30 
device()31     const dawn::Device& device() const { return fDevice; }
queue()32     const dawn::Queue&  queue() const { return fQueue; }
33 
xferBarrier(GrRenderTarget *,GrXferBarrierType)34     void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
35 
36     GrBackendTexture createBackendTexture(int w, int h,
37                                           const GrBackendFormat &,
38                                           GrMipMapped,
39                                           GrRenderable,
40                                           const void* pixels,
41                                           size_t rowBytes,
42                                           const SkColor4f* color,
43                                           GrProtected isProtected) override;
44     void deleteBackendTexture(const GrBackendTexture&) override;
45 #if GR_TEST_UTILS
46     bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
47 
48     GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override;
49     void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
50 
51     void testingOnly_flushGpuAndSync() override;
52 #endif
53 
54     GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
55                                                                 int width,
56                                                                 int height,
57                                                                 int numStencilSamples) override;
58 
59     GrGpuRTCommandBuffer* getCommandBuffer(
60             GrRenderTarget*, GrSurfaceOrigin, const SkRect& bounds,
61             const GrGpuRTCommandBuffer::LoadAndStoreInfo&,
62             const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override;
63 
64     GrGpuTextureCommandBuffer* getCommandBuffer(GrTexture*, GrSurfaceOrigin) override;
65 
shaderCompiler()66     SkSL::Compiler* shaderCompiler() const {
67         return fCompiler.get();
68     }
69 
70     void submit(GrGpuCommandBuffer* cb) override;
71     GrFence SK_WARN_UNUSED_RESULT insertFence() override;
72     bool waitFence(GrFence, uint64_t timeout) override;
73     void deleteFence(GrFence) const override;
74 
75     sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned = true) override;
76     sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
77                                             GrResourceProvider::SemaphoreWrapType wrapType,
78                                             GrWrapOwnership ownership) override;
79     void insertSemaphore(sk_sp<GrSemaphore> semaphore) override;
80     void waitSemaphore(sk_sp<GrSemaphore> semaphore) override;
81     void checkFinishProcs() override;
82 
83     sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override;
84 
85 private:
onResetContext(uint32_t resetBits)86     void onResetContext(uint32_t resetBits) override {}
87 
querySampleLocations(GrRenderTarget *,SkTArray<SkPoint> *)88     virtual void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>*) override {}
89 
90     sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc& desc,
91                                      const GrBackendFormat&,
92                                      GrRenderable,
93                                      int renderTargetSampleCnt,
94                                      SkBudgeted,
95                                      GrProtected,
96                                      const GrMipLevel texels[],
97                                      int mipLevelCount) override;
98 
99     sk_sp<GrTexture> onCreateCompressedTexture(int width, int height, const GrBackendFormat&,
100                                                SkImage::CompressionType, SkBudgeted,
101                                                const void* data) override;
102 
103     sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType, GrWrapOwnership,
104                                           GrWrapCacheable, GrIOType) override;
105     sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
106                                                     GrColorType, GrWrapOwnership,
107                                                     GrWrapCacheable) override;
108     sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
109                                                     GrColorType) override;
110 
111     sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, int sampleCnt,
112                                                              GrColorType) override;
113 
114     sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType type, GrAccessPattern,
115                                       const void* data) override;
116 
117     bool onReadPixels(GrSurface* surface, int left, int top, int width, int height,
118                       GrColorType surfaceColorType, GrColorType dstColorType, void* buffer,
119                       size_t rowBytes) override;
120 
121     bool onWritePixels(GrSurface* surface, int left, int top, int width, int height,
122                        GrColorType surfaceColorType, GrColorType dstColorType,
123                        const GrMipLevel texels[], int mipLevelCount) override;
124 
125     bool onTransferPixelsTo(GrTexture*, int left, int top, int width, int height,
126                             GrColorType textureColorType, GrColorType bufferColorType,
127                             GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override;
128 
129     bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
130                               GrColorType surfaceColorType, GrColorType bufferColorType,
131                               GrGpuBuffer* transferBuffer, size_t offset) override;
132 
onResolveRenderTarget(GrRenderTarget * target)133     void onResolveRenderTarget(GrRenderTarget* target) override {
134     }
135 
136     bool onRegenerateMipMapLevels(GrTexture*) override;
137 
138     bool onCopySurface(GrSurface* dst, GrSurface* src,
139                        const SkIRect& srcRect, const SkIPoint& dstPoint,
140                        bool canDiscardOutsideDstRect) override;
141 
142     void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access,
143                        const GrFlushInfo& info, const GrPrepareForExternalIORequests&) override;
144 
145     dawn::Device                                    fDevice;
146     dawn::Queue                                     fQueue;
147     std::unique_ptr<SkSL::Compiler>                 fCompiler;
148     std::unique_ptr<GrDawnGpuRTCommandBuffer>       fRTCommandBuffer;
149     std::unique_ptr<GrDawnGpuTextureCommandBuffer>  fTextureCommandBuffer;
150 
151     typedef GrGpu INHERITED;
152 };
153 
154 #endif
155