Flutter Engine
The Flutter Engine
GrMeshDrawOp.h
Go to the documentation of this file.
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
14
15#include <type_traits>
16
17class SkArenaAlloc;
18class GrAtlasManager;
19class GrBuffer;
20class GrCaps;
22class GrOpFlushState;
23class GrProgramInfo;
24struct GrSimpleMesh;
25
26/**
27 * Base class for mesh-drawing GrDrawOps.
28 */
29class GrMeshDrawOp : public GrDrawOp {
30public:
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
36protected:
37 GrMeshDrawOp(uint32_t classID);
38
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
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. */
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.*/
64 const GrSurfaceProxy* const primProcProxies[]) const;
65
66 void* vertices() const { return fVertices; }
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
92
93 private:
95 };
96
97 static bool CombinedQuadCountWillOverflow(GrAAType aaType,
98 bool willBeUpgradedToAA,
99 int combinedQuadCount);
100
102 const GrSurfaceProxyView& writeView,
104 const GrDstProxyView&,
105 GrXferBarrierFlags renderPassXferBarriers,
106 GrLoadOp colorLoadOp);
107
108private:
110 // This method is responsible for creating all the programInfos required
111 // by this op.
112 virtual void onCreateProgramInfo(const GrCaps*,
114 const GrSurfaceProxyView& writeView,
115 bool usesMSAASurface,
117 const GrDstProxyView&,
118 GrXferBarrierFlags renderPassXferBarriers,
119 GrLoadOp colorLoadOp) = 0;
120
121 void onPrePrepare(GrRecordingContext* context,
122 const GrSurfaceProxyView& writeView,
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
133 using INHERITED = GrDrawOp;
134};
135
136#endif
GrPrimitiveType
Definition: GrTypesPriv.h:43
GrAAType
Definition: GrTypesPriv.h:200
GrLoadOp
Definition: GrTypesPriv.h:155
GrXferBarrierFlags
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
Definition: GrCaps.h:57
GrDrawOp(uint32_t classID)
Definition: GrDrawOp.h:31
void recordDraw(GrMeshDrawTarget *, const GrGeometryProcessor *) const
void init(GrMeshDrawTarget *, GrPrimitiveType, size_t vertexStride, sk_sp< const GrBuffer > indexBuffer, int verticesPerRepetition, int indicesPerRepetition, int repeatCount, int maxRepetitions)
virtual GrProgramInfo * programInfo()=0
void createProgramInfo(const GrCaps *caps, SkArenaAlloc *arena, const GrSurfaceProxyView &writeView, bool usesMSAASurface, GrAppliedClip &&appliedClip, const GrDstProxyView &dstProxyView, GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp)
Definition: GrMeshDrawOp.h:39
GrMeshDrawOp(uint32_t classID)
virtual void onPrePrepareDraws(GrRecordingContext *, const GrSurfaceProxyView &writeView, GrAppliedClip *, const GrDstProxyView &, GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp)
virtual void onCreateProgramInfo(const GrCaps *, SkArenaAlloc *, const GrSurfaceProxyView &writeView, bool usesMSAASurface, GrAppliedClip &&, const GrDstProxyView &, GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp)=0
virtual void onPrepareDraws(GrMeshDrawTarget *)=0
static bool CanUpgradeAAOnMerge(GrAAType aa1, GrAAType aa2)
Definition: GrMeshDrawOp.h:31
static bool CombinedQuadCountWillOverflow(GrAAType aaType, bool willBeUpgradedToAA, int combinedQuadCount)
Definition: GrOp.h:70
uint32_t classID() const
Definition: GrOp.h:158
AtkStateType state