bsalomon | 7539856 | 2015-08-17 12:55:38 -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 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 8 | #ifndef GrOpFlushState_DEFINED |
| 9 | #define GrOpFlushState_DEFINED |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 10 | |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 11 | #include "GrAppliedClip.h" |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 12 | #include "GrBufferAllocPool.h" |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 13 | #include "SkArenaAlloc.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 14 | #include "ops/GrMeshDrawOp.h" |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 15 | |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 16 | class GrGpu; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 17 | class GrGpuCommandBuffer; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 18 | class GrGpuRTCommandBuffer; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 19 | class GrResourceProvider; |
| 20 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 21 | /** Tracks the state across all the GrOps (really just the GrDrawOps) in a GrOpList flush. */ |
| 22 | class GrOpFlushState { |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 23 | public: |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 24 | GrOpFlushState(GrGpu*, GrResourceProvider*); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 25 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 26 | ~GrOpFlushState() { this->reset(); } |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 27 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 28 | /** Inserts an upload to be executed after all ops in the flush prepared their draws but before |
| 29 | the draws are executed to the backend 3D API. */ |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 30 | void addASAPUpload(GrDrawOp::DeferredUploadFn&& upload) { |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 31 | fAsapUploads.emplace_back(std::move(upload)); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 34 | const GrCaps& caps() const; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 35 | GrResourceProvider* resourceProvider() const { return fResourceProvider; } |
| 36 | |
| 37 | /** Has the token been flushed to the backend 3D API. */ |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 38 | bool hasDrawBeenFlushed(GrDrawOpUploadToken token) const { |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 39 | return token.fSequenceNumber <= fLastFlushedToken.fSequenceNumber; |
| 40 | } |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 41 | |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 42 | /** Issue a token to an operation that is being enqueued. */ |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 43 | GrDrawOpUploadToken issueDrawToken() { |
| 44 | return GrDrawOpUploadToken(++fLastIssuedToken.fSequenceNumber); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /** Call every time a draw that was issued a token is flushed */ |
| 48 | void flushToken() { ++fLastFlushedToken.fSequenceNumber; } |
| 49 | |
| 50 | /** Gets the next draw token that will be issued. */ |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 51 | GrDrawOpUploadToken nextDrawToken() const { |
| 52 | return GrDrawOpUploadToken(fLastIssuedToken.fSequenceNumber + 1); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 53 | } |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 54 | |
| 55 | /** The last token flushed to all the way to the backend API. */ |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 56 | GrDrawOpUploadToken nextTokenToFlush() const { |
| 57 | return GrDrawOpUploadToken(fLastFlushedToken.fSequenceNumber + 1); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 58 | } |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 59 | |
| 60 | void* makeVertexSpace(size_t vertexSize, int vertexCount, |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 61 | const GrBuffer** buffer, int* startVertex); |
| 62 | uint16_t* makeIndexSpace(int indexCount, const GrBuffer** buffer, int* startIndex); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 63 | |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 64 | void* makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount, int fallbackVertexCount, |
| 65 | const GrBuffer** buffer, int* startVertex, int* actualVertexCount); |
| 66 | uint16_t* makeIndexSpaceAtLeast(int minIndexCount, int fallbackIndexCount, |
| 67 | const GrBuffer** buffer, int* startIndex, |
| 68 | int* actualIndexCount); |
| 69 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 70 | /** This is called after each op has a chance to prepare its draws and before the draws are |
| 71 | issued. */ |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 72 | void preIssueDraws() { |
| 73 | fVertexPool.unmap(); |
| 74 | fIndexPool.unmap(); |
| 75 | int uploadCount = fAsapUploads.count(); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 76 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 77 | for (int i = 0; i < uploadCount; i++) { |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 78 | this->doUpload(fAsapUploads[i]); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 79 | } |
| 80 | fAsapUploads.reset(); |
| 81 | } |
| 82 | |
Brian Salomon | 9bada54 | 2017-06-12 12:09:30 -0400 | [diff] [blame] | 83 | void doUpload(GrDrawOp::DeferredUploadFn&); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 84 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 85 | void putBackIndices(size_t indices) { fIndexPool.putBack(indices * sizeof(uint16_t)); } |
| 86 | |
| 87 | void putBackVertexSpace(size_t sizeInBytes) { fVertexPool.putBack(sizeInBytes); } |
| 88 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 89 | GrGpuCommandBuffer* commandBuffer() { return fCommandBuffer; } |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 90 | // Helper function used by Ops that are only called via RenderTargetOpLists |
| 91 | GrGpuRTCommandBuffer* rtCommandBuffer(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 92 | void setCommandBuffer(GrGpuCommandBuffer* buffer) { fCommandBuffer = buffer; } |
| 93 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 94 | GrGpu* gpu() { return fGpu; } |
| 95 | |
joshualitt | f6d259b | 2015-10-02 11:27:14 -0700 | [diff] [blame] | 96 | void reset() { |
| 97 | fVertexPool.reset(); |
| 98 | fIndexPool.reset(); |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 99 | fPipelines.reset(); |
joshualitt | f6d259b | 2015-10-02 11:27:14 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 102 | /** Additional data required on a per-op basis when executing GrDrawOps. */ |
| 103 | struct DrawOpArgs { |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 104 | GrRenderTarget* renderTarget() const { return fProxy->priv().peekRenderTarget(); } |
| 105 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 106 | // TODO: do we still need the dst proxy here? |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 107 | GrRenderTargetProxy* fProxy; |
| 108 | GrAppliedClip* fAppliedClip; |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 109 | GrXferProcessor::DstProxy fDstProxy; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | void setDrawOpArgs(DrawOpArgs* opArgs) { fOpArgs = opArgs; } |
| 113 | |
| 114 | const DrawOpArgs& drawOpArgs() const { |
| 115 | SkASSERT(fOpArgs); |
| 116 | return *fOpArgs; |
| 117 | } |
| 118 | |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 119 | GrAppliedClip detachAppliedClip() { |
| 120 | SkASSERT(fOpArgs); |
| 121 | return fOpArgs->fAppliedClip ? std::move(*fOpArgs->fAppliedClip) : GrAppliedClip(); |
| 122 | } |
| 123 | |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 124 | template <typename... Args> |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 125 | GrPipeline* allocPipeline(Args&&... args) { |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 126 | return fPipelines.make<GrPipeline>(std::forward<Args>(args)...); |
| 127 | } |
| 128 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 129 | private: |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 130 | GrGpu* fGpu; |
| 131 | GrResourceProvider* fResourceProvider; |
| 132 | GrGpuCommandBuffer* fCommandBuffer; |
| 133 | GrVertexBufferAllocPool fVertexPool; |
| 134 | GrIndexBufferAllocPool fIndexPool; |
| 135 | SkSTArray<4, GrDrawOp::DeferredUploadFn> fAsapUploads; |
| 136 | GrDrawOpUploadToken fLastIssuedToken; |
| 137 | GrDrawOpUploadToken fLastFlushedToken; |
| 138 | DrawOpArgs* fOpArgs; |
| 139 | SkArenaAlloc fPipelines{sizeof(GrPipeline) * 100}; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | /** |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 143 | * A word about uploads and tokens: Ops should usually schedule their uploads to occur at the |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 144 | * begining of a frame whenever possible. These are called ASAP uploads. Of course, this requires |
| 145 | * that there are no draws that have yet to be flushed that rely on the old texture contents. In |
| 146 | * that case the ASAP upload would happen prior to the previous draw causing the draw to read the |
| 147 | * new (wrong) texture data. In that case they should schedule an inline upload. |
| 148 | * |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 149 | * Ops, in conjunction with helpers such as GrDrawOpAtlas, can use the token system to know |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 150 | * what the most recent draw was that referenced a resource (or portion of a resource). Each draw |
| 151 | * is assigned a token. A resource (or portion) can be tagged with the most recent draw's |
| 152 | * token. The target provides a facility for testing whether the draw corresponding to the token |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 153 | * has been flushed. If it has not been flushed then the op must perform an inline upload instead. |
| 154 | * When scheduling an inline upload the op provides the token of the draw that the upload must occur |
| 155 | * before. The upload will then occur between the draw that requires the new data but after the |
| 156 | * token that requires the old data. |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 157 | * |
Brian Salomon | dad2923 | 2016-12-01 16:40:24 -0500 | [diff] [blame] | 158 | * TODO: Currently the token/upload interface is spread over GrDrawOp, GrMeshDrawOp, |
| 159 | * GrDrawOp::Target, and GrMeshDrawOp::Target. However, the interface at the GrDrawOp level is not |
| 160 | * complete and isn't useful. We should push it down to GrMeshDrawOp until it is required at the |
| 161 | * GrDrawOp level. |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 162 | */ |
Brian Salomon | dad2923 | 2016-12-01 16:40:24 -0500 | [diff] [blame] | 163 | |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 164 | /** |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 165 | * GrDrawOp instances use this object to allocate space for their geometry and to issue the draws |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 166 | * that render their op. |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 167 | */ |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 168 | class GrDrawOp::Target { |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 169 | public: |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 170 | Target(GrOpFlushState* state, GrDrawOp* op) : fState(state), fOp(op) {} |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 171 | |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 172 | /** Returns the token of the draw that this upload will occur before. */ |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 173 | GrDrawOpUploadToken addInlineUpload(DeferredUploadFn&& upload) { |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 174 | fOp->fInlineUploads.emplace_back(std::move(upload), fState->nextDrawToken()); |
| 175 | return fOp->fInlineUploads.back().fUploadBeforeToken; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 176 | } |
| 177 | |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 178 | /** Returns the token of the draw that this upload will occur before. Since ASAP uploads |
| 179 | are done first during a flush, this will be the first token since the most recent |
| 180 | flush. */ |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 181 | GrDrawOpUploadToken addAsapUpload(DeferredUploadFn&& upload) { |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 182 | fState->addASAPUpload(std::move(upload)); |
| 183 | return fState->nextTokenToFlush(); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 184 | } |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 185 | |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 186 | bool hasDrawBeenFlushed(GrDrawOpUploadToken token) const { |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 187 | return fState->hasDrawBeenFlushed(token); |
| 188 | } |
| 189 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 190 | /** Gets the next draw token that will be issued by this target. This can be used by an op |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 191 | to record that the next draw it issues will use a resource (e.g. texture) while preparing |
| 192 | that draw. */ |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 193 | GrDrawOpUploadToken nextDrawToken() const { return fState->nextDrawToken(); } |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 194 | |
| 195 | const GrCaps& caps() const { return fState->caps(); } |
| 196 | |
| 197 | GrResourceProvider* resourceProvider() const { return fState->resourceProvider(); } |
| 198 | |
| 199 | protected: |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 200 | GrDrawOp* op() { return fOp; } |
| 201 | GrOpFlushState* state() { return fState; } |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 202 | const GrOpFlushState* state() const { return fState; } |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 203 | |
| 204 | private: |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 205 | GrOpFlushState* fState; |
| 206 | GrDrawOp* fOp; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 207 | }; |
| 208 | |
Brian Salomon | dad2923 | 2016-12-01 16:40:24 -0500 | [diff] [blame] | 209 | /** Extension of GrDrawOp::Target for use by GrMeshDrawOp. Adds the ability to create vertex |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 210 | draws. */ |
Brian Salomon | dad2923 | 2016-12-01 16:40:24 -0500 | [diff] [blame] | 211 | class GrMeshDrawOp::Target : public GrDrawOp::Target { |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 212 | public: |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 213 | Target(GrOpFlushState* state, GrMeshDrawOp* op) : INHERITED(state, op) {} |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 214 | |
Brian Salomon | d3ccb0a | 2017-04-03 10:38:00 -0400 | [diff] [blame] | 215 | void draw(const GrGeometryProcessor* gp, const GrPipeline* pipeline, const GrMesh& mesh); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 216 | |
| 217 | void* makeVertexSpace(size_t vertexSize, int vertexCount, |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 218 | const GrBuffer** buffer, int* startVertex) { |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 219 | return this->state()->makeVertexSpace(vertexSize, vertexCount, buffer, startVertex); |
| 220 | } |
| 221 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 222 | uint16_t* makeIndexSpace(int indexCount, const GrBuffer** buffer, int* startIndex) { |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 223 | return this->state()->makeIndexSpace(indexCount, buffer, startIndex); |
| 224 | } |
| 225 | |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 226 | void* makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount, int fallbackVertexCount, |
| 227 | const GrBuffer** buffer, int* startVertex, |
| 228 | int* actualVertexCount) { |
| 229 | return this->state()->makeVertexSpaceAtLeast(vertexSize, minVertexCount, |
| 230 | fallbackVertexCount, buffer, startVertex, |
| 231 | actualVertexCount); |
| 232 | } |
| 233 | |
| 234 | uint16_t* makeIndexSpaceAtLeast(int minIndexCount, int fallbackIndexCount, |
| 235 | const GrBuffer** buffer, int* startIndex, |
| 236 | int* actualIndexCount) { |
| 237 | return this->state()->makeIndexSpaceAtLeast(minIndexCount, fallbackIndexCount, buffer, |
| 238 | startIndex, actualIndexCount); |
| 239 | } |
| 240 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 241 | /** Helpers for ops which over-allocate and then return data to the pool. */ |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 242 | void putBackIndices(int indices) { this->state()->putBackIndices(indices); } |
| 243 | void putBackVertices(int vertices, size_t vertexStride) { |
| 244 | this->state()->putBackVertexSpace(vertices * vertexStride); |
| 245 | } |
| 246 | |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 247 | GrRenderTargetProxy* proxy() const { return this->state()->drawOpArgs().fProxy; } |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 248 | |
| 249 | const GrAppliedClip* clip() const { return this->state()->drawOpArgs().fAppliedClip; } |
| 250 | |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 251 | GrAppliedClip detachAppliedClip() { return this->state()->detachAppliedClip(); } |
| 252 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 253 | const GrXferProcessor::DstProxy& dstProxy() const { |
| 254 | return this->state()->drawOpArgs().fDstProxy; |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | template <typename... Args> |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 258 | GrPipeline* allocPipeline(Args&&... args) { |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 259 | return this->state()->allocPipeline(std::forward<Args>(args)...); |
| 260 | } |
| 261 | |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 262 | /** |
| 263 | * Helper that makes a pipeline targeting the op's render target that incorporates the op's |
| 264 | * GrAppliedClip. |
| 265 | * */ |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 266 | GrPipeline* makePipeline(uint32_t pipelineFlags, GrProcessorSet&& processorSet, |
| 267 | GrAppliedClip&& clip) { |
Brian Salomon | 98222ac | 2017-07-12 15:27:54 -0400 | [diff] [blame] | 268 | GrPipeline::InitArgs pipelineArgs; |
| 269 | pipelineArgs.fFlags = pipelineFlags; |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 270 | pipelineArgs.fProxy = this->proxy(); |
Brian Salomon | 98222ac | 2017-07-12 15:27:54 -0400 | [diff] [blame] | 271 | pipelineArgs.fDstProxy = this->dstProxy(); |
| 272 | pipelineArgs.fCaps = &this->caps(); |
| 273 | pipelineArgs.fResourceProvider = this->resourceProvider(); |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 274 | return this->allocPipeline(pipelineArgs, std::move(processorSet), std::move(clip)); |
Brian Salomon | 98222ac | 2017-07-12 15:27:54 -0400 | [diff] [blame] | 275 | } |
| 276 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 277 | private: |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 278 | GrMeshDrawOp* meshDrawOp() { return static_cast<GrMeshDrawOp*>(this->op()); } |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 279 | typedef GrDrawOp::Target INHERITED; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 280 | }; |
| 281 | |
| 282 | #endif |