• 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 #include "src/gpu/ganesh/ops/GrMeshDrawOp.h"
9 
10 #include "src/gpu/ganesh/GrOpFlushState.h"
11 #include "src/gpu/ganesh/GrOpsRenderPass.h"
12 #include "src/gpu/ganesh/GrRecordingContextPriv.h"
13 #include "src/gpu/ganesh/GrResourceProvider.h"
14 
GrMeshDrawOp(uint32_t classID)15 GrMeshDrawOp::GrMeshDrawOp(uint32_t classID) : INHERITED(classID) {}
16 
onPrepare(GrOpFlushState * state)17 void GrMeshDrawOp::onPrepare(GrOpFlushState* state) { this->onPrepareDraws(state); }
18 
createProgramInfo(GrMeshDrawTarget * target)19 void GrMeshDrawOp::createProgramInfo(GrMeshDrawTarget* target) {
20     this->createProgramInfo(&target->caps(),
21                             target->allocator(),
22                             target->writeView(),
23                             target->usesMSAASurface(),
24                             target->detachAppliedClip(),
25                             target->dstProxyView(),
26                             target->renderPassBarriers(),
27                             target->colorLoadOp());
28 }
29 
CombinedQuadCountWillOverflow(GrAAType aaType,bool willBeUpgradedToAA,int combinedQuadCount)30 bool GrMeshDrawOp::CombinedQuadCountWillOverflow(GrAAType aaType,
31                                                  bool willBeUpgradedToAA,
32                                                  int combinedQuadCount) {
33     bool willBeAA = (aaType == GrAAType::kCoverage) || willBeUpgradedToAA;
34 
35     return combinedQuadCount > (willBeAA ? GrResourceProvider::MaxNumAAQuads()
36                                          : GrResourceProvider::MaxNumNonAAQuads());
37 }
38 
39 // This onPrepareDraws implementation assumes the derived Op only has a single programInfo -
40 // which is the majority of the cases.
onPrePrepareDraws(GrRecordingContext * context,const GrSurfaceProxyView & writeView,GrAppliedClip * clip,const GrDstProxyView & dstProxyView,GrXferBarrierFlags renderPassXferBarriers,GrLoadOp colorLoadOp)41 void GrMeshDrawOp::onPrePrepareDraws(GrRecordingContext* context,
42                                      const GrSurfaceProxyView& writeView,
43                                      GrAppliedClip* clip,
44                                      const GrDstProxyView& dstProxyView,
45                                      GrXferBarrierFlags renderPassXferBarriers,
46                                      GrLoadOp colorLoadOp) {
47     SkArenaAlloc* arena = context->priv().recordTimeAllocator();
48 
49     // http://skbug.com/12201 -- DDL does not yet support DMSAA.
50     bool usesMSAASurface = writeView.asRenderTargetProxy()->numSamples() > 1;
51 
52     // This is equivalent to a GrOpFlushState::detachAppliedClip
53     GrAppliedClip appliedClip = clip ? std::move(*clip) : GrAppliedClip::Disabled();
54 
55     this->createProgramInfo(context->priv().caps(), arena, writeView, usesMSAASurface,
56                             std::move(appliedClip), dstProxyView, renderPassXferBarriers,
57                             colorLoadOp);
58 
59     // TODO: at this point we've created both the program info and desc in the recording context's
60     // arena. In the DDL case, it would be cool if 'recordProgramInfo' could return the
61     // pre-existing versions if the program has already been seen. We could then return the
62     // memory for the current copy to the arena.
63     context->priv().recordProgramInfo(this->programInfo());
64 }
65 
66 //////////////////////////////////////////////////////////////////////////////
67 
PatternHelper(GrMeshDrawTarget * target,GrPrimitiveType primitiveType,size_t vertexStride,sk_sp<const GrBuffer> indexBuffer,int verticesPerRepetition,int indicesPerRepetition,int repeatCount,int maxRepetitions)68 GrMeshDrawOp::PatternHelper::PatternHelper(GrMeshDrawTarget* target, GrPrimitiveType primitiveType,
69                                            size_t vertexStride, sk_sp<const GrBuffer> indexBuffer,
70                                            int verticesPerRepetition, int indicesPerRepetition,
71                                            int repeatCount, int maxRepetitions) {
72     this->init(target, primitiveType, vertexStride, std::move(indexBuffer), verticesPerRepetition,
73                indicesPerRepetition, repeatCount, maxRepetitions);
74 }
75 
init(GrMeshDrawTarget * target,GrPrimitiveType primitiveType,size_t vertexStride,sk_sp<const GrBuffer> indexBuffer,int verticesPerRepetition,int indicesPerRepetition,int repeatCount,int maxRepetitions)76 void GrMeshDrawOp::PatternHelper::init(GrMeshDrawTarget* target, GrPrimitiveType primitiveType,
77                                        size_t vertexStride, sk_sp<const GrBuffer> indexBuffer,
78                                        int verticesPerRepetition, int indicesPerRepetition,
79                                        int repeatCount, int maxRepetitions) {
80     SkASSERT(target);
81     if (!indexBuffer) {
82         return;
83     }
84     sk_sp<const GrBuffer> vertexBuffer;
85     int firstVertex;
86     int vertexCount = verticesPerRepetition * repeatCount;
87     fVertices = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &firstVertex);
88     if (!fVertices) {
89         SkDebugf("Vertices could not be allocated for patterned rendering.");
90         return;
91     }
92     SkASSERT(vertexBuffer);
93     fMesh = target->allocMesh();
94     fPrimitiveType = primitiveType;
95 
96     SkASSERT(maxRepetitions ==
97              static_cast<int>(indexBuffer->size() / (sizeof(uint16_t) * indicesPerRepetition)));
98     fMesh->setIndexedPatterned(std::move(indexBuffer), indicesPerRepetition, repeatCount,
99                                maxRepetitions, std::move(vertexBuffer), verticesPerRepetition,
100                                firstVertex);
101 }
102 
recordDraw(GrMeshDrawTarget * target,const GrGeometryProcessor * gp) const103 void GrMeshDrawOp::PatternHelper::recordDraw(GrMeshDrawTarget* target,
104                                              const GrGeometryProcessor* gp) const {
105     target->recordDraw(gp, fMesh, 1, fPrimitiveType);
106 }
107 
recordDraw(GrMeshDrawTarget * target,const GrGeometryProcessor * gp,const GrSurfaceProxy * const primProcProxies[]) const108 void GrMeshDrawOp::PatternHelper::recordDraw(
109         GrMeshDrawTarget* target,
110         const GrGeometryProcessor* gp,
111         const GrSurfaceProxy* const primProcProxies[]) const {
112     target->recordDraw(gp, fMesh, 1, primProcProxies, fPrimitiveType);
113 }
114 
115 //////////////////////////////////////////////////////////////////////////////
116 
QuadHelper(GrMeshDrawTarget * target,size_t vertexStride,int quadsToDraw)117 GrMeshDrawOp::QuadHelper::QuadHelper(GrMeshDrawTarget* target,
118                                      size_t vertexStride,
119                                      int quadsToDraw) {
120     sk_sp<const GrGpuBuffer> indexBuffer = target->resourceProvider()->refNonAAQuadIndexBuffer();
121     if (!indexBuffer) {
122         SkDebugf("Could not get quad index buffer.");
123         return;
124     }
125     this->init(target, GrPrimitiveType::kTriangles, vertexStride, std::move(indexBuffer),
126                GrResourceProvider::NumVertsPerNonAAQuad(),
127                GrResourceProvider::NumIndicesPerNonAAQuad(), quadsToDraw,
128                GrResourceProvider::MaxNumNonAAQuads());
129 }
130