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