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 GrDawnOpsRenderPass_DEFINED
9 #define GrDawnOpsRenderPass_DEFINED
10 
11 #include "src/gpu/GrOpsRenderPass.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 GrDawnOpsRenderPass : public GrOpsRenderPass, private GrMesh::SendToGpuImpl {
22 public:
23     GrDawnOpsRenderPass(GrDawnGpu*, GrRenderTarget*, GrSurfaceOrigin,
24                         const LoadAndStoreInfo&, const StencilLoadAndStoreInfo&);
25 
26     ~GrDawnOpsRenderPass() override;
27 
begin()28     void begin() override { }
29     void end() override;
30 
31     dawn::RenderPassEncoder beginRenderPass(dawn::LoadOp colorOp, dawn::LoadOp stencilOp);
32     void insertEventMarker(const char*) override;
33 
34     void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override;
35 
36     void submit();
37 
38 private:
39     GrGpu* gpu() override;
40 
41     void setScissorState(const GrProgramInfo&);
42     void applyState(const GrProgramInfo& programInfo,
43                     const GrPrimitiveType primitiveType);
44 
45     void onDraw(const GrProgramInfo& programInfo,
46                 const GrMesh mesh[],
47                 int meshCount,
48                 const SkRect& bounds) override;
49 
sendMeshToGpu(GrPrimitiveType primType,const GrBuffer * vertexBuffer,int vertexCount,int baseVertex)50     void sendMeshToGpu(GrPrimitiveType primType, const GrBuffer* vertexBuffer, int vertexCount,
51                        int baseVertex) final {
52         this->sendInstancedMeshToGpu(primType, vertexBuffer, vertexCount, baseVertex,
53                                      nullptr, 1, 0);
54     }
55 
sendIndexedMeshToGpu(GrPrimitiveType primType,const GrBuffer * indexBuffer,int indexCount,int baseIndex,uint16_t,uint16_t,const GrBuffer * vertexBuffer,int baseVertex,GrPrimitiveRestart restart)56     void sendIndexedMeshToGpu(GrPrimitiveType primType,
57                               const GrBuffer* indexBuffer, int indexCount, int baseIndex,
58                               uint16_t /*minIndexValue*/, uint16_t /*maxIndexValue*/,
59                               const GrBuffer* vertexBuffer, int baseVertex,
60                               GrPrimitiveRestart restart) final {
61         this->sendIndexedInstancedMeshToGpu(primType, indexBuffer, indexCount, baseIndex,
62                                             vertexBuffer, baseVertex, nullptr, 1, 0, restart);
63     }
64 
65     void sendInstancedMeshToGpu(GrPrimitiveType,
66                                 const GrBuffer* vertexBuffer, int vertexCount, int baseVertex,
67                                 const GrBuffer* instanceBuffer, int instanceCount,
68                                 int baseInstance) final;
69 
70     void sendIndexedInstancedMeshToGpu(GrPrimitiveType,
71                                        const GrBuffer* indexBuffer, int indexCount, int baseIndex,
72                                        const GrBuffer* vertexBuffer, int baseVertex,
73                                        const GrBuffer* instanceBuffer, int instanceCount,
74                                        int baseInstance, GrPrimitiveRestart) final;
75 
76     void onClear(const GrFixedClip&, const SkPMColor4f& color) override;
77 
78     void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) override;
79 
80     struct InlineUploadInfo {
InlineUploadInfoInlineUploadInfo81         InlineUploadInfo(GrOpFlushState* state, const GrDeferredTextureUploadFn& upload)
82                 : fFlushState(state), fUpload(upload) {}
83 
84         GrOpFlushState* fFlushState;
85         GrDeferredTextureUploadFn fUpload;
86     };
87 
88     GrDawnGpu*                  fGpu;
89     dawn::CommandEncoder        fEncoder;
90     dawn::RenderPassEncoder     fPassEncoder;
91     LoadAndStoreInfo            fColorInfo;
92 
93     typedef GrOpsRenderPass     INHERITED;
94 };
95 
96 #endif
97