2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "src/gpu/ganesh/ops/GrMeshDrawOp.h"
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"
15 GrMeshDrawOp::GrMeshDrawOp(uint32_t classID) : INHERITED(classID) {}
17 void GrMeshDrawOp::onPrepare(GrOpFlushState* state) { this->onPrepareDraws(state); }
19 void GrMeshDrawOp::createProgramInfo(GrMeshDrawTarget* target) {
20 this->createProgramInfo(&target->caps(),
23 target->usesMSAASurface(),
24 target->detachAppliedClip(),
25 target->dstProxyView(),
26 target->renderPassBarriers(),
27 target->colorLoadOp());
30 bool GrMeshDrawOp::CombinedQuadCountWillOverflow(GrAAType aaType,
31 bool willBeUpgradedToAA,
32 int combinedQuadCount) {
33 bool willBeAA = (aaType == GrAAType::kCoverage) || willBeUpgradedToAA;
35 return combinedQuadCount > (willBeAA ? GrResourceProvider::MaxNumAAQuads()
36 : GrResourceProvider::MaxNumNonAAQuads());
39 // This onPrepareDraws implementation assumes the derived Op only has a single programInfo -
40 // which is the majority of the cases.
41 void GrMeshDrawOp::onPrePrepareDraws(GrRecordingContext* context,
42 const GrSurfaceProxyView& writeView,
44 const GrDstProxyView& dstProxyView,
45 GrXferBarrierFlags renderPassXferBarriers,
46 GrLoadOp colorLoadOp) {
47 SkArenaAlloc* arena = context->priv().recordTimeAllocator();
49 // http://skbug.com/12201 -- DDL does not yet support DMSAA.
50 bool usesMSAASurface = writeView.asRenderTargetProxy()->numSamples() > 1;
52 // This is equivalent to a GrOpFlushState::detachAppliedClip
53 GrAppliedClip appliedClip = clip ? std::move(*clip) : GrAppliedClip::Disabled();
55 this->createProgramInfo(context->priv().caps(), arena, writeView, usesMSAASurface,
56 std::move(appliedClip), dstProxyView, renderPassXferBarriers,
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());
66 //////////////////////////////////////////////////////////////////////////////
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);
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) {
84 sk_sp<const GrBuffer> vertexBuffer;
86 int vertexCount = verticesPerRepetition * repeatCount;
87 fVertices = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &firstVertex);
89 SkDebugf("Vertices could not be allocated for patterned rendering.");
92 SkASSERT(vertexBuffer);
93 fMesh = target->allocMesh();
94 fPrimitiveType = primitiveType;
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,
103 void GrMeshDrawOp::PatternHelper::recordDraw(GrMeshDrawTarget* target,
104 const GrGeometryProcessor* gp) const {
105 target->recordDraw(gp, fMesh, 1, fPrimitiveType);
108 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);
115 //////////////////////////////////////////////////////////////////////////////
117 GrMeshDrawOp::QuadHelper::QuadHelper(GrMeshDrawTarget* target,
120 sk_sp<const GrGpuBuffer> indexBuffer = target->resourceProvider()->refNonAAQuadIndexBuffer();
122 SkDebugf("Could not get quad index buffer.");
125 this->init(target, GrPrimitiveType::kTriangles, vertexStride, std::move(indexBuffer),
126 GrResourceProvider::NumVertsPerNonAAQuad(),
127 GrResourceProvider::NumIndicesPerNonAAQuad(), quadsToDraw,
128 GrResourceProvider::MaxNumNonAAQuads());