• 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 GrDawnGpuCommandBuffer_DEFINED
9 #define GrDawnGpuCommandBuffer_DEFINED
10 
11 #include "src/gpu/GrGpuCommandBuffer.h"
12 
13 #include "include/gpu/GrTypes.h"
14 #include "src/gpu/GrColor.h"
15 #include "src/gpu/GrMesh.h"
16 #include "dawn/dawncpp.h"
17 
18 class GrDawnGpu;
19 class GrDawnRenderTarget;
20 
21 class GrDawnGpuTextureCommandBuffer : public GrGpuTextureCommandBuffer {
22 public:
23     GrDawnGpuTextureCommandBuffer(GrDawnGpu* gpu, GrTexture* texture, GrSurfaceOrigin origin);
24     ~GrDawnGpuTextureCommandBuffer() override;
25 
26     void copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
27 
28     void transferFrom(const SkIRect& srcRect, GrColorType surfaceColorType,
29                       GrColorType bufferColorType, GrGpuBuffer* transferBuffer,
30                       size_t offset) override;
insertEventMarker(const char *)31     void insertEventMarker(const char*) override {}
32     void submit();
33 
34 private:
35     GrDawnGpu*                        fGpu;
36     dawn::CommandEncoder              fEncoder;
37 
38     typedef GrGpuTextureCommandBuffer INHERITED;
39 };
40 
41 class GrDawnGpuRTCommandBuffer : public GrGpuRTCommandBuffer, private GrMesh::SendToGpuImpl {
42 public:
43     GrDawnGpuRTCommandBuffer(GrDawnGpu*, GrRenderTarget*, GrSurfaceOrigin,
44                              const LoadAndStoreInfo&,
45                              const StencilLoadAndStoreInfo&);
46 
47     ~GrDawnGpuRTCommandBuffer() override;
48 
begin()49     void begin() override { }
50     void end() override;
51 
52     dawn::RenderPassEncoder beginRenderPass(dawn::LoadOp colorOp, dawn::LoadOp stencilOp);
53     void transferFrom(const SkIRect& srcRect, GrColorType surfaceColorType,
54                       GrColorType bufferColorType, GrGpuBuffer* transferBuffer,
55                       size_t offset) override;
56     void insertEventMarker(const char*) override;
57 
58     void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override;
59 
60     void copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
61 
62     void submit();
63 
64 private:
65     GrGpu* gpu() override;
66 
67     void setScissorState(const GrPipeline&,
68                          const GrPipeline::FixedDynamicState* fixedDynamicState,
69                          const GrPipeline::DynamicStateArrays* dynamicStateArrays);
70     void applyState(const GrPipeline& pipeline,
71                     const GrPrimitiveProcessor& primProc,
72                     const GrTextureProxy* const primProcProxies[],
73                     const GrPipeline::FixedDynamicState* fixedDynamicState,
74                     const GrPipeline::DynamicStateArrays* dynamicStateArrays,
75                     const GrPrimitiveType primitiveType,
76                     bool hasPoints);
77 
78     void onDraw(const GrPrimitiveProcessor& primProc,
79                 const GrPipeline& pipeline,
80                 const GrPipeline::FixedDynamicState* fixedDynamicState,
81                 const GrPipeline::DynamicStateArrays* dynamicStateArrays,
82                 const GrMesh mesh[],
83                 int meshCount,
84                 const SkRect& bounds) override;
85 
sendMeshToGpu(GrPrimitiveType primType,const GrBuffer * vertexBuffer,int vertexCount,int baseVertex)86     void sendMeshToGpu(GrPrimitiveType primType, const GrBuffer* vertexBuffer, int vertexCount,
87                        int baseVertex) final {
88         this->sendInstancedMeshToGpu(primType, vertexBuffer, vertexCount, baseVertex,
89                                      nullptr, 1, 0);
90     }
91 
sendIndexedMeshToGpu(GrPrimitiveType primType,const GrBuffer * indexBuffer,int indexCount,int baseIndex,uint16_t,uint16_t,const GrBuffer * vertexBuffer,int baseVertex,GrPrimitiveRestart restart)92     void sendIndexedMeshToGpu(GrPrimitiveType primType,
93                               const GrBuffer* indexBuffer, int indexCount, int baseIndex,
94                               uint16_t /*minIndexValue*/, uint16_t /*maxIndexValue*/,
95                               const GrBuffer* vertexBuffer, int baseVertex,
96                               GrPrimitiveRestart restart) final {
97         this->sendIndexedInstancedMeshToGpu(primType, indexBuffer, indexCount, baseIndex,
98                                             vertexBuffer, baseVertex, nullptr, 1, 0, restart);
99     }
100 
101     void sendInstancedMeshToGpu(GrPrimitiveType,
102                                 const GrBuffer* vertexBuffer, int vertexCount, int baseVertex,
103                                 const GrBuffer* instanceBuffer, int instanceCount,
104                                 int baseInstance) final;
105 
106     void sendIndexedInstancedMeshToGpu(GrPrimitiveType,
107                                        const GrBuffer* indexBuffer, int indexCount, int baseIndex,
108                                        const GrBuffer* vertexBuffer, int baseVertex,
109                                        const GrBuffer* instanceBuffer, int instanceCount,
110                                        int baseInstance, GrPrimitiveRestart) final;
111 
112     void onClear(const GrFixedClip&, const SkPMColor4f& color) override;
113 
114     void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) override;
115 
116     struct InlineUploadInfo {
InlineUploadInfoInlineUploadInfo117         InlineUploadInfo(GrOpFlushState* state, const GrDeferredTextureUploadFn& upload)
118                 : fFlushState(state), fUpload(upload) {}
119 
120         GrOpFlushState* fFlushState;
121         GrDeferredTextureUploadFn fUpload;
122     };
123 
124     GrDawnGpu*                  fGpu;
125     dawn::CommandEncoder        fEncoder;
126     dawn::RenderPassEncoder     fPassEncoder;
127     LoadAndStoreInfo            fColorInfo;
128 
129     typedef GrGpuRTCommandBuffer INHERITED;
130 };
131 
132 #endif
133