bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/ops/GrMeshDrawOp.h" |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 9 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 10 | #include "src/gpu/GrOpFlushState.h" |
| 11 | #include "src/gpu/GrOpsRenderPass.h" |
Robert Phillips | 2669a7b | 2020-03-12 12:07:19 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrRecordingContextPriv.h" |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrResourceProvider.h" |
| 14 | |
Brian Salomon | 7dc6e75 | 2017-11-02 11:34:51 -0400 | [diff] [blame] | 15 | GrMeshDrawOp::GrMeshDrawOp(uint32_t classID) : INHERITED(classID) {} |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 16 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 17 | void GrMeshDrawOp::onPrepare(GrOpFlushState* state) { this->onPrepareDraws(state); } |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 18 | |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 19 | void GrMeshDrawOp::createProgramInfo(Target* target) { |
| 20 | this->createProgramInfo(&target->caps(), |
| 21 | target->allocator(), |
| 22 | target->outputView(), |
| 23 | target->detachAppliedClip(), |
| 24 | target->dstProxyView()); |
| 25 | } |
| 26 | |
Robert Phillips | 2669a7b | 2020-03-12 12:07:19 -0400 | [diff] [blame] | 27 | // This onPrepareDraws implementation assumes the derived Op only has a single programInfo - |
| 28 | // which is the majority of the cases. |
| 29 | void GrMeshDrawOp::onPrePrepareDraws(GrRecordingContext* context, |
| 30 | const GrSurfaceProxyView* outputView, |
| 31 | GrAppliedClip* clip, |
| 32 | const GrXferProcessor::DstProxyView& dstProxyView) { |
| 33 | SkArenaAlloc* arena = context->priv().recordTimeAllocator(); |
| 34 | |
| 35 | // This is equivalent to a GrOpFlushState::detachAppliedClip |
| 36 | GrAppliedClip appliedClip = clip ? std::move(*clip) : GrAppliedClip(); |
| 37 | |
| 38 | this->createProgramInfo(context->priv().caps(), arena, outputView, |
| 39 | std::move(appliedClip), dstProxyView); |
| 40 | |
Robert Phillips | cad8fba | 2020-03-20 15:39:29 -0400 | [diff] [blame^] | 41 | // TODO: at this point we've created both the program info and desc in the recording context's |
| 42 | // arena. In the DDL case, it would be cool if 'recordProgramInfo' could return the |
| 43 | // pre-existing versions if the program has already been seen. We could then return the |
| 44 | // memory for the current copy to the arena. |
Robert Phillips | 2669a7b | 2020-03-12 12:07:19 -0400 | [diff] [blame] | 45 | context->priv().recordProgramInfo(this->programInfo()); |
| 46 | } |
| 47 | |
Brian Salomon | b948572 | 2018-08-05 21:30:33 -0400 | [diff] [blame] | 48 | ////////////////////////////////////////////////////////////////////////////// |
| 49 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 50 | GrMeshDrawOp::PatternHelper::PatternHelper(Target* target, GrPrimitiveType primitiveType, |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 51 | size_t vertexStride, sk_sp<const GrBuffer> indexBuffer, |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 52 | int verticesPerRepetition, int indicesPerRepetition, |
Robert Phillips | ee08d52 | 2019-10-28 16:34:44 -0400 | [diff] [blame] | 53 | int repeatCount, int maxRepetitions) { |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 54 | this->init(target, primitiveType, vertexStride, std::move(indexBuffer), verticesPerRepetition, |
Robert Phillips | ee08d52 | 2019-10-28 16:34:44 -0400 | [diff] [blame] | 55 | indicesPerRepetition, repeatCount, maxRepetitions); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void GrMeshDrawOp::PatternHelper::init(Target* target, GrPrimitiveType primitiveType, |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 59 | size_t vertexStride, sk_sp<const GrBuffer> indexBuffer, |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 60 | int verticesPerRepetition, int indicesPerRepetition, |
Robert Phillips | ee08d52 | 2019-10-28 16:34:44 -0400 | [diff] [blame] | 61 | int repeatCount, int maxRepetitions) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 62 | SkASSERT(target); |
| 63 | if (!indexBuffer) { |
| 64 | return; |
| 65 | } |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 66 | sk_sp<const GrBuffer> vertexBuffer; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 67 | int firstVertex; |
| 68 | int vertexCount = verticesPerRepetition * repeatCount; |
| 69 | fVertices = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &firstVertex); |
| 70 | if (!fVertices) { |
| 71 | SkDebugf("Vertices could not be allocated for patterned rendering."); |
| 72 | return; |
| 73 | } |
| 74 | SkASSERT(vertexBuffer); |
Chris Dalton | 79f336d | 2020-02-11 14:42:56 -0700 | [diff] [blame] | 75 | fMesh = target->allocMesh(); |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 76 | fPrimitiveType = primitiveType; |
Robert Phillips | ee08d52 | 2019-10-28 16:34:44 -0400 | [diff] [blame] | 77 | |
| 78 | SkASSERT(maxRepetitions == |
| 79 | static_cast<int>(indexBuffer->size() / (sizeof(uint16_t) * indicesPerRepetition))); |
Chris Dalton | 37c7bdd | 2020-03-13 09:21:12 -0600 | [diff] [blame] | 80 | fMesh->setIndexedPatterned(std::move(indexBuffer), indicesPerRepetition, repeatCount, |
| 81 | maxRepetitions, std::move(vertexBuffer), verticesPerRepetition, |
| 82 | firstVertex); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Robert Phillips | 7cd0bfe | 2019-11-20 16:08:10 -0500 | [diff] [blame] | 85 | void GrMeshDrawOp::PatternHelper::recordDraw(Target* target, const GrGeometryProcessor* gp) const { |
| 86 | target->recordDraw(gp, fMesh, 1, fPrimitiveType); |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void GrMeshDrawOp::PatternHelper::recordDraw( |
Robert Phillips | 6c59fe4 | 2020-02-27 09:30:37 -0500 | [diff] [blame] | 90 | Target* target, |
| 91 | const GrGeometryProcessor* gp, |
Chris Dalton | 304e14d | 2020-03-17 14:29:06 -0600 | [diff] [blame] | 92 | const GrSurfaceProxy* const primProcProxies[]) const { |
| 93 | target->recordDraw(gp, fMesh, 1, primProcProxies, fPrimitiveType); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | ////////////////////////////////////////////////////////////////////////////// |
| 97 | |
| 98 | GrMeshDrawOp::QuadHelper::QuadHelper(Target* target, size_t vertexStride, int quadsToDraw) { |
Robert Phillips | ee08d52 | 2019-10-28 16:34:44 -0400 | [diff] [blame] | 99 | sk_sp<const GrGpuBuffer> indexBuffer = target->resourceProvider()->refNonAAQuadIndexBuffer(); |
| 100 | if (!indexBuffer) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 101 | SkDebugf("Could not get quad index buffer."); |
| 102 | return; |
| 103 | } |
Robert Phillips | ee08d52 | 2019-10-28 16:34:44 -0400 | [diff] [blame] | 104 | this->init(target, GrPrimitiveType::kTriangles, vertexStride, std::move(indexBuffer), |
| 105 | GrResourceProvider::NumVertsPerNonAAQuad(), |
| 106 | GrResourceProvider::NumIndicesPerNonAAQuad(), quadsToDraw, |
| 107 | GrResourceProvider::MaxNumNonAAQuads()); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 108 | } |