• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 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 GrMeshDrawOp_DEFINED
9 #define GrMeshDrawOp_DEFINED
10 
11 #include "src/gpu/ganesh/GrAppliedClip.h"
12 #include "src/gpu/ganesh/GrGeometryProcessor.h"
13 #include "src/gpu/ganesh/ops/GrDrawOp.h"
14 
15 #include <type_traits>
16 
17 class SkArenaAlloc;
18 class GrAtlasManager;
19 class GrBuffer;
20 class GrCaps;
21 class GrMeshDrawTarget;
22 class GrOpFlushState;
23 class GrProgramInfo;
24 struct GrSimpleMesh;
25 
26 /**
27  * Base class for mesh-drawing GrDrawOps.
28  */
29 class GrMeshDrawOp : public GrDrawOp {
30 public:
CanUpgradeAAOnMerge(GrAAType aa1,GrAAType aa2)31     static bool CanUpgradeAAOnMerge(GrAAType aa1, GrAAType aa2) {
32         return (aa1 == GrAAType::kNone && aa2 == GrAAType::kCoverage) ||
33                (aa1 == GrAAType::kCoverage && aa2 == GrAAType::kNone);
34     }
35 
36 protected:
37     GrMeshDrawOp(uint32_t classID);
38 
createProgramInfo(const GrCaps * caps,SkArenaAlloc * arena,const GrSurfaceProxyView & writeView,bool usesMSAASurface,GrAppliedClip && appliedClip,const GrDstProxyView & dstProxyView,GrXferBarrierFlags renderPassXferBarriers,GrLoadOp colorLoadOp)39     void createProgramInfo(const GrCaps* caps,
40                            SkArenaAlloc* arena,
41                            const GrSurfaceProxyView& writeView,
42                            bool usesMSAASurface,
43                            GrAppliedClip&& appliedClip,
44                            const GrDstProxyView& dstProxyView,
45                            GrXferBarrierFlags renderPassXferBarriers,
46                            GrLoadOp colorLoadOp) {
47         this->onCreateProgramInfo(caps, arena, writeView, usesMSAASurface, std::move(appliedClip),
48                                   dstProxyView, renderPassXferBarriers, colorLoadOp);
49     }
50 
51     void createProgramInfo(GrMeshDrawTarget*);
52 
53     /** Helper for rendering repeating meshes using a patterned index buffer. This class creates the
54         space for the vertices and flushes the draws to the GrMeshDrawTarget. */
55     class PatternHelper {
56     public:
57         PatternHelper(GrMeshDrawTarget*, GrPrimitiveType, size_t vertexStride,
58                       sk_sp<const GrBuffer> indexBuffer, int verticesPerRepetition,
59                       int indicesPerRepetition, int repeatCount, int maxRepetitions);
60 
61         /** Called to issue draws to the GrMeshDrawTarget.*/
62         void recordDraw(GrMeshDrawTarget*, const GrGeometryProcessor*) const;
63         void recordDraw(GrMeshDrawTarget*, const GrGeometryProcessor*,
64                         const GrSurfaceProxy* const primProcProxies[]) const;
65 
vertices()66         void* vertices() const { return fVertices; }
mesh()67         GrSimpleMesh* mesh() { return fMesh; }
68 
69     protected:
70         PatternHelper() = default;
71         void init(GrMeshDrawTarget*, GrPrimitiveType, size_t vertexStride,
72                   sk_sp<const GrBuffer> indexBuffer, int verticesPerRepetition,
73                   int indicesPerRepetition, int repeatCount, int maxRepetitions);
74 
75     private:
76         void* fVertices = nullptr;
77         GrSimpleMesh* fMesh = nullptr;
78         GrPrimitiveType fPrimitiveType;
79     };
80 
81     /** A specialization of InstanceHelper for quad rendering.
82      *  It only draws non-antialiased indexed quads.
83      */
84     class QuadHelper : private PatternHelper {
85     public:
86         QuadHelper() = delete;
87         QuadHelper(GrMeshDrawTarget*, size_t vertexStride, int quadsToDraw);
88 
89         using PatternHelper::mesh;
90         using PatternHelper::recordDraw;
91         using PatternHelper::vertices;
92 
93     private:
94         using INHERITED = PatternHelper;
95     };
96 
97     static bool CombinedQuadCountWillOverflow(GrAAType aaType,
98                                               bool willBeUpgradedToAA,
99                                               int combinedQuadCount);
100 
101     virtual void onPrePrepareDraws(GrRecordingContext*,
102                                    const GrSurfaceProxyView& writeView,
103                                    GrAppliedClip*,
104                                    const GrDstProxyView&,
105                                    GrXferBarrierFlags renderPassXferBarriers,
106                                    GrLoadOp colorLoadOp);
107 
108 private:
109     virtual GrProgramInfo* programInfo() = 0;
110     // This method is responsible for creating all the programInfos required
111     // by this op.
112     virtual void onCreateProgramInfo(const GrCaps*,
113                                      SkArenaAlloc*,
114                                      const GrSurfaceProxyView& writeView,
115                                      bool usesMSAASurface,
116                                      GrAppliedClip&&,
117                                      const GrDstProxyView&,
118                                      GrXferBarrierFlags renderPassXferBarriers,
119                                      GrLoadOp colorLoadOp) = 0;
120 
onPrePrepare(GrRecordingContext * context,const GrSurfaceProxyView & writeView,GrAppliedClip * clip,const GrDstProxyView & dstProxyView,GrXferBarrierFlags renderPassXferBarriers,GrLoadOp colorLoadOp)121     void onPrePrepare(GrRecordingContext* context,
122                       const GrSurfaceProxyView& writeView,
123                       GrAppliedClip* clip,
124                       const GrDstProxyView& dstProxyView,
125                       GrXferBarrierFlags renderPassXferBarriers,
126                       GrLoadOp colorLoadOp) final {
127         this->onPrePrepareDraws(context, writeView, clip, dstProxyView, renderPassXferBarriers,
128                                 colorLoadOp);
129     }
130     void onPrepare(GrOpFlushState* state) final;
131 
132     virtual void onPrepareDraws(GrMeshDrawTarget*) = 0;
133     using INHERITED = GrDrawOp;
134 };
135 
136 #endif
137