robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [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 | |
| 8 | #include "GrTargetCommands.h" |
| 9 | |
| 10 | #include "GrColor.h" |
| 11 | #include "GrDefaultGeoProcFactory.h" |
| 12 | #include "GrInOrderDrawBuffer.h" |
| 13 | #include "GrTemplates.h" |
| 14 | #include "SkPoint.h" |
| 15 | |
| 16 | void GrTargetCommands::closeBatch() { |
| 17 | if (fDrawBatch) { |
| 18 | fBatchTarget.resetNumberOfDraws(); |
| 19 | fDrawBatch->execute(NULL, fPrevState); |
| 20 | fDrawBatch->fBatch->setNumberOfDraws(fBatchTarget.numberOfDraws()); |
| 21 | fDrawBatch = NULL; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettings) { |
| 26 | static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Face; |
| 27 | bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); |
| 28 | if (isWinding) { |
| 29 | // Double check that it is in fact winding. |
| 30 | SkASSERT(kIncClamp_StencilOp == pathStencilSettings.passOp(pathFace)); |
| 31 | SkASSERT(kIncClamp_StencilOp == pathStencilSettings.failOp(pathFace)); |
| 32 | SkASSERT(0x1 != pathStencilSettings.writeMask(pathFace)); |
| 33 | SkASSERT(!pathStencilSettings.isTwoSided()); |
| 34 | } |
| 35 | return isWinding; |
| 36 | } |
| 37 | |
| 38 | int GrTargetCommands::concatInstancedDraw(GrInOrderDrawBuffer* iodb, |
| 39 | const GrDrawTarget::DrawInfo& info) { |
| 40 | SkASSERT(!fCmdBuffer.empty()); |
| 41 | SkASSERT(info.isInstanced()); |
| 42 | |
| 43 | const GrIndexBuffer* ib; |
| 44 | if (!iodb->canConcatToIndexBuffer(&ib)) { |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | // Check if there is a draw info that is compatible that uses the same VB from the pool and |
| 49 | // the same IB |
robertphillips | bca3c9f | 2015-03-05 09:17:17 -0800 | [diff] [blame] | 50 | if (Cmd::kDraw_CmdType != fCmdBuffer.back().type()) { |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | Draw* draw = static_cast<Draw*>(&fCmdBuffer.back()); |
| 55 | |
| 56 | if (!draw->fInfo.isInstanced() || |
| 57 | draw->fInfo.primitiveType() != info.primitiveType() || |
| 58 | draw->fInfo.verticesPerInstance() != info.verticesPerInstance() || |
| 59 | draw->fInfo.indicesPerInstance() != info.indicesPerInstance() || |
| 60 | draw->fInfo.vertexBuffer() != info.vertexBuffer() || |
| 61 | draw->fInfo.indexBuffer() != ib) { |
| 62 | return 0; |
| 63 | } |
| 64 | if (draw->fInfo.startVertex() + draw->fInfo.vertexCount() != info.startVertex()) { |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | // how many instances can be concat'ed onto draw given the size of the index buffer |
| 69 | int instancesToConcat = iodb->indexCountInCurrentSource() / info.indicesPerInstance(); |
| 70 | instancesToConcat -= draw->fInfo.instanceCount(); |
| 71 | instancesToConcat = SkTMin(instancesToConcat, info.instanceCount()); |
| 72 | |
| 73 | draw->fInfo.adjustInstanceCount(instancesToConcat); |
| 74 | |
| 75 | // update last fGpuCmdMarkers to include any additional trace markers that have been added |
| 76 | iodb->recordTraceMarkersIfNecessary(draw); |
| 77 | return instancesToConcat; |
| 78 | } |
| 79 | |
| 80 | GrTargetCommands::Cmd* GrTargetCommands::recordDraw( |
| 81 | GrInOrderDrawBuffer* iodb, |
| 82 | const GrGeometryProcessor* gp, |
| 83 | const GrDrawTarget::DrawInfo& info, |
| 84 | const GrDrawTarget::PipelineInfo& pipelineInfo) { |
joshualitt | 0dcb8e3 | 2015-04-27 12:03:05 -0700 | [diff] [blame^] | 85 | #ifdef USE_BITMAP_TEXTBLOBS |
| 86 | SkFAIL("Non-batch no longer supported\n"); |
| 87 | #endif |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 88 | SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer())); |
joshualitt | 0dcb8e3 | 2015-04-27 12:03:05 -0700 | [diff] [blame^] | 89 | CLOSE_BATCH |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 90 | |
| 91 | if (!this->setupPipelineAndShouldDraw(iodb, gp, pipelineInfo)) { |
| 92 | return NULL; |
| 93 | } |
| 94 | |
| 95 | Draw* draw; |
| 96 | if (info.isInstanced()) { |
| 97 | int instancesConcated = this->concatInstancedDraw(iodb, info); |
| 98 | if (info.instanceCount() > instancesConcated) { |
| 99 | draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); |
| 100 | draw->fInfo.adjustInstanceCount(-instancesConcated); |
| 101 | } else { |
| 102 | return NULL; |
| 103 | } |
| 104 | } else { |
| 105 | draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); |
| 106 | } |
| 107 | |
| 108 | return draw; |
| 109 | } |
| 110 | |
| 111 | GrTargetCommands::Cmd* GrTargetCommands::recordDrawBatch( |
| 112 | GrInOrderDrawBuffer* iodb, |
| 113 | GrBatch* batch, |
| 114 | const GrDrawTarget::PipelineInfo& pipelineInfo) { |
| 115 | if (!this->setupPipelineAndShouldDraw(iodb, batch, pipelineInfo)) { |
| 116 | return NULL; |
| 117 | } |
| 118 | |
| 119 | // Check if there is a Batch Draw we can batch with |
robertphillips | bca3c9f | 2015-03-05 09:17:17 -0800 | [diff] [blame] | 120 | if (Cmd::kDrawBatch_CmdType != fCmdBuffer.back().type() || !fDrawBatch) { |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 121 | fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fBatchTarget)); |
| 122 | return fDrawBatch; |
| 123 | } |
| 124 | |
| 125 | SkASSERT(&fCmdBuffer.back() == fDrawBatch); |
| 126 | if (!fDrawBatch->fBatch->combineIfPossible(batch)) { |
joshualitt | 0dcb8e3 | 2015-04-27 12:03:05 -0700 | [diff] [blame^] | 127 | CLOSE_BATCH |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 128 | fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fBatchTarget)); |
| 129 | } |
| 130 | |
| 131 | return fDrawBatch; |
| 132 | } |
| 133 | |
| 134 | GrTargetCommands::Cmd* GrTargetCommands::recordStencilPath( |
| 135 | GrInOrderDrawBuffer* iodb, |
| 136 | const GrPipelineBuilder& pipelineBuilder, |
| 137 | const GrPathProcessor* pathProc, |
| 138 | const GrPath* path, |
| 139 | const GrScissorState& scissorState, |
| 140 | const GrStencilSettings& stencilSettings) { |
joshualitt | 0dcb8e3 | 2015-04-27 12:03:05 -0700 | [diff] [blame^] | 141 | CLOSE_BATCH |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 142 | |
| 143 | StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, |
| 144 | (path, pipelineBuilder.getRenderTarget())); |
| 145 | |
| 146 | sp->fScissor = scissorState; |
| 147 | sp->fUseHWAA = pipelineBuilder.isHWAntialias(); |
| 148 | sp->fViewMatrix = pathProc->viewMatrix(); |
| 149 | sp->fStencil = stencilSettings; |
| 150 | return sp; |
| 151 | } |
| 152 | |
| 153 | GrTargetCommands::Cmd* GrTargetCommands::recordDrawPath( |
| 154 | GrInOrderDrawBuffer* iodb, |
| 155 | const GrPathProcessor* pathProc, |
| 156 | const GrPath* path, |
| 157 | const GrStencilSettings& stencilSettings, |
| 158 | const GrDrawTarget::PipelineInfo& pipelineInfo) { |
joshualitt | 0dcb8e3 | 2015-04-27 12:03:05 -0700 | [diff] [blame^] | 159 | CLOSE_BATCH |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 160 | |
| 161 | // TODO: Only compare the subset of GrPipelineBuilder relevant to path covering? |
| 162 | if (!this->setupPipelineAndShouldDraw(iodb, pathProc, pipelineInfo)) { |
| 163 | return NULL; |
| 164 | } |
| 165 | DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path)); |
| 166 | dp->fStencilSettings = stencilSettings; |
| 167 | return dp; |
| 168 | } |
| 169 | |
| 170 | GrTargetCommands::Cmd* GrTargetCommands::recordDrawPaths( |
| 171 | GrInOrderDrawBuffer* iodb, |
| 172 | const GrPathProcessor* pathProc, |
| 173 | const GrPathRange* pathRange, |
| 174 | const void* indexValues, |
| 175 | GrDrawTarget::PathIndexType indexType, |
| 176 | const float transformValues[], |
| 177 | GrDrawTarget::PathTransformType transformType, |
| 178 | int count, |
| 179 | const GrStencilSettings& stencilSettings, |
| 180 | const GrDrawTarget::PipelineInfo& pipelineInfo) { |
| 181 | SkASSERT(pathRange); |
| 182 | SkASSERT(indexValues); |
| 183 | SkASSERT(transformValues); |
joshualitt | 0dcb8e3 | 2015-04-27 12:03:05 -0700 | [diff] [blame^] | 184 | CLOSE_BATCH |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 185 | |
| 186 | if (!this->setupPipelineAndShouldDraw(iodb, pathProc, pipelineInfo)) { |
| 187 | return NULL; |
| 188 | } |
| 189 | |
| 190 | char* savedIndices; |
| 191 | float* savedTransforms; |
| 192 | |
| 193 | iodb->appendIndicesAndTransforms(indexValues, indexType, |
| 194 | transformValues, transformType, |
| 195 | count, &savedIndices, &savedTransforms); |
| 196 | |
robertphillips | bca3c9f | 2015-03-05 09:17:17 -0800 | [diff] [blame] | 197 | if (Cmd::kDrawPaths_CmdType == fCmdBuffer.back().type()) { |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 198 | // The previous command was also DrawPaths. Try to collapse this call into the one |
| 199 | // before. Note that stenciling all the paths at once, then covering, may not be |
| 200 | // equivalent to two separate draw calls if there is overlap. Blending won't work, |
| 201 | // and the combined calls may also cancel each other's winding numbers in some |
| 202 | // places. For now the winding numbers are only an issue if the fill is even/odd, |
| 203 | // because DrawPaths is currently only used for glyphs, and glyphs in the same |
| 204 | // font tend to all wind in the same direction. |
| 205 | DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back()); |
| 206 | if (pathRange == previous->pathRange() && |
| 207 | indexType == previous->fIndexType && |
| 208 | transformType == previous->fTransformType && |
| 209 | stencilSettings == previous->fStencilSettings && |
| 210 | path_fill_type_is_winding(stencilSettings) && |
| 211 | !pipelineInfo.willBlendWithDst(pathProc)) { |
| 212 | const int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType); |
| 213 | const int xformSize = GrPathRendering::PathTransformSize(transformType); |
| 214 | if (&previous->fIndices[previous->fCount*indexBytes] == savedIndices && |
| 215 | (0 == xformSize || |
| 216 | &previous->fTransforms[previous->fCount*xformSize] == savedTransforms)) { |
| 217 | // Fold this DrawPaths call into the one previous. |
| 218 | previous->fCount += count; |
| 219 | return NULL; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange)); |
| 225 | dp->fIndices = savedIndices; |
| 226 | dp->fIndexType = indexType; |
| 227 | dp->fTransforms = savedTransforms; |
| 228 | dp->fTransformType = transformType; |
| 229 | dp->fCount = count; |
| 230 | dp->fStencilSettings = stencilSettings; |
| 231 | return dp; |
| 232 | } |
| 233 | |
| 234 | GrTargetCommands::Cmd* GrTargetCommands::recordClear(GrInOrderDrawBuffer* iodb, |
| 235 | const SkIRect* rect, |
| 236 | GrColor color, |
| 237 | bool canIgnoreRect, |
| 238 | GrRenderTarget* renderTarget) { |
| 239 | SkASSERT(renderTarget); |
joshualitt | 0dcb8e3 | 2015-04-27 12:03:05 -0700 | [diff] [blame^] | 240 | CLOSE_BATCH |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 241 | |
| 242 | SkIRect r; |
| 243 | if (NULL == rect) { |
| 244 | // We could do something smart and remove previous draws and clears to |
| 245 | // the current render target. If we get that smart we have to make sure |
| 246 | // those draws aren't read before this clear (render-to-texture). |
| 247 | r.setLTRB(0, 0, renderTarget->width(), renderTarget->height()); |
| 248 | rect = &r; |
| 249 | } |
| 250 | Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); |
| 251 | GrColorIsPMAssert(color); |
| 252 | clr->fColor = color; |
| 253 | clr->fRect = *rect; |
| 254 | clr->fCanIgnoreRect = canIgnoreRect; |
| 255 | return clr; |
| 256 | } |
| 257 | |
| 258 | GrTargetCommands::Cmd* GrTargetCommands::recordClearStencilClip(GrInOrderDrawBuffer* iodb, |
| 259 | const SkIRect& rect, |
| 260 | bool insideClip, |
| 261 | GrRenderTarget* renderTarget) { |
| 262 | SkASSERT(renderTarget); |
joshualitt | 0dcb8e3 | 2015-04-27 12:03:05 -0700 | [diff] [blame^] | 263 | CLOSE_BATCH |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 264 | |
| 265 | ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, ClearStencilClip, (renderTarget)); |
| 266 | clr->fRect = rect; |
| 267 | clr->fInsideClip = insideClip; |
| 268 | return clr; |
| 269 | } |
| 270 | |
| 271 | GrTargetCommands::Cmd* GrTargetCommands::recordDiscard(GrInOrderDrawBuffer* iodb, |
| 272 | GrRenderTarget* renderTarget) { |
| 273 | SkASSERT(renderTarget); |
joshualitt | 0dcb8e3 | 2015-04-27 12:03:05 -0700 | [diff] [blame^] | 274 | CLOSE_BATCH |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 275 | |
| 276 | Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); |
| 277 | clr->fColor = GrColor_ILLEGAL; |
| 278 | return clr; |
| 279 | } |
| 280 | |
| 281 | void GrTargetCommands::reset() { |
| 282 | fCmdBuffer.reset(); |
| 283 | fPrevState = NULL; |
| 284 | fDrawBatch = NULL; |
| 285 | } |
| 286 | |
| 287 | void GrTargetCommands::flush(GrInOrderDrawBuffer* iodb) { |
| 288 | if (fCmdBuffer.empty()) { |
| 289 | return; |
| 290 | } |
| 291 | |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 292 | // TODO this is temporary while batch is being rolled out |
joshualitt | 0dcb8e3 | 2015-04-27 12:03:05 -0700 | [diff] [blame^] | 293 | CLOSE_BATCH |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 294 | |
robertphillips | bca3c9f | 2015-03-05 09:17:17 -0800 | [diff] [blame] | 295 | // Updated every time we find a set state cmd to reflect the current state in the playback |
| 296 | // stream. |
| 297 | SetState* currentState = NULL; |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 298 | |
joshualitt | 385e26e | 2015-04-27 11:42:30 -0700 | [diff] [blame] | 299 | GrGpu* gpu = iodb->getGpu(); |
| 300 | |
joshualitt | 0dcb8e3 | 2015-04-27 12:03:05 -0700 | [diff] [blame^] | 301 | #ifdef USE_BITMAP_TEXTBLOBS |
| 302 | // Loop over all batches and generate geometry |
| 303 | CmdBuffer::Iter genIter(fCmdBuffer); |
| 304 | while (genIter.next()) { |
| 305 | if (Cmd::kDrawBatch_CmdType == genIter->type()) { |
| 306 | DrawBatch* db = reinterpret_cast<DrawBatch*>(genIter.get()); |
| 307 | fBatchTarget.resetNumberOfDraws(); |
| 308 | db->execute(NULL, currentState); |
| 309 | db->fBatch->setNumberOfDraws(fBatchTarget.numberOfDraws()); |
| 310 | } else if (Cmd::kSetState_CmdType == genIter->type()) { |
| 311 | SetState* ss = reinterpret_cast<SetState*>(genIter.get()); |
| 312 | |
| 313 | ss->execute(gpu, currentState); |
| 314 | currentState = ss; |
| 315 | } |
| 316 | } |
| 317 | #endif |
| 318 | |
| 319 | iodb->getVertexAllocPool()->unmap(); |
| 320 | iodb->getIndexAllocPool()->unmap(); |
| 321 | fBatchTarget.preFlush(); |
| 322 | |
| 323 | CmdBuffer::Iter iter(fCmdBuffer); |
| 324 | |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 325 | while (iter.next()) { |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 326 | GrGpuTraceMarker newMarker("", -1); |
| 327 | SkString traceString; |
| 328 | if (iter->isTraced()) { |
robertphillips | bca3c9f | 2015-03-05 09:17:17 -0800 | [diff] [blame] | 329 | traceString = iodb->getCmdString(iter->markerID()); |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 330 | newMarker.fMarker = traceString.c_str(); |
| 331 | gpu->addGpuTraceMarker(&newMarker); |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | // TODO temporary hack |
robertphillips | bca3c9f | 2015-03-05 09:17:17 -0800 | [diff] [blame] | 335 | if (Cmd::kDrawBatch_CmdType == iter->type()) { |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 336 | DrawBatch* db = reinterpret_cast<DrawBatch*>(iter.get()); |
| 337 | fBatchTarget.flushNext(db->fBatch->numberOfDraws()); |
robertphillips | d14101e | 2015-03-05 08:55:28 -0800 | [diff] [blame] | 338 | |
| 339 | if (iter->isTraced()) { |
| 340 | gpu->removeGpuTraceMarker(&newMarker); |
| 341 | } |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 342 | continue; |
| 343 | } |
| 344 | |
robertphillips | bca3c9f | 2015-03-05 09:17:17 -0800 | [diff] [blame] | 345 | if (Cmd::kSetState_CmdType == iter->type()) { |
joshualitt | 0dcb8e3 | 2015-04-27 12:03:05 -0700 | [diff] [blame^] | 346 | #ifndef USE_BITMAP_TEXTBLOBS |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 347 | SetState* ss = reinterpret_cast<SetState*>(iter.get()); |
| 348 | |
robertphillips | bca3c9f | 2015-03-05 09:17:17 -0800 | [diff] [blame] | 349 | ss->execute(gpu, currentState); |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 350 | currentState = ss; |
joshualitt | 0dcb8e3 | 2015-04-27 12:03:05 -0700 | [diff] [blame^] | 351 | #else |
| 352 | // TODO this is just until NVPR is in batch |
| 353 | SetState* ss = reinterpret_cast<SetState*>(iter.get()); |
| 354 | |
| 355 | if (ss->fPrimitiveProcessor) { |
| 356 | ss->execute(gpu, currentState); |
| 357 | } |
| 358 | currentState = ss; |
| 359 | #endif |
| 360 | |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 361 | } else { |
| 362 | iter->execute(gpu, currentState); |
| 363 | } |
| 364 | |
| 365 | if (iter->isTraced()) { |
| 366 | gpu->removeGpuTraceMarker(&newMarker); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | // TODO see copious notes about hack |
| 371 | fBatchTarget.postFlush(); |
| 372 | } |
| 373 | |
| 374 | void GrTargetCommands::Draw::execute(GrGpu* gpu, const SetState* state) { |
| 375 | SkASSERT(state); |
| 376 | DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state->fDesc, |
| 377 | &state->fBatchTracker); |
| 378 | gpu->draw(args, fInfo); |
| 379 | } |
| 380 | |
| 381 | void GrTargetCommands::StencilPath::execute(GrGpu* gpu, const SetState*) { |
| 382 | GrGpu::StencilPathState state; |
| 383 | state.fRenderTarget = fRenderTarget.get(); |
| 384 | state.fScissor = &fScissor; |
| 385 | state.fStencil = &fStencil; |
| 386 | state.fUseHWAA = fUseHWAA; |
| 387 | state.fViewMatrix = &fViewMatrix; |
| 388 | |
| 389 | gpu->stencilPath(this->path(), state); |
| 390 | } |
| 391 | |
| 392 | void GrTargetCommands::DrawPath::execute(GrGpu* gpu, const SetState* state) { |
| 393 | SkASSERT(state); |
| 394 | DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state->fDesc, |
| 395 | &state->fBatchTracker); |
| 396 | gpu->drawPath(args, this->path(), fStencilSettings); |
| 397 | } |
| 398 | |
| 399 | void GrTargetCommands::DrawPaths::execute(GrGpu* gpu, const SetState* state) { |
| 400 | SkASSERT(state); |
| 401 | DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state->fDesc, |
| 402 | &state->fBatchTracker); |
| 403 | gpu->drawPaths(args, this->pathRange(), |
| 404 | fIndices, fIndexType, |
| 405 | fTransforms, fTransformType, |
| 406 | fCount, fStencilSettings); |
| 407 | } |
| 408 | |
| 409 | void GrTargetCommands::DrawBatch::execute(GrGpu*, const SetState* state) { |
| 410 | SkASSERT(state); |
| 411 | fBatch->generateGeometry(fBatchTarget, state->getPipeline()); |
| 412 | } |
| 413 | |
robertphillips | bca3c9f | 2015-03-05 09:17:17 -0800 | [diff] [blame] | 414 | void GrTargetCommands::SetState::execute(GrGpu* gpu, const SetState*) { |
| 415 | // TODO sometimes we have a prim proc, othertimes we have a GrBatch. Eventually we |
| 416 | // will only have GrBatch and we can delete this |
| 417 | if (fPrimitiveProcessor) { |
| 418 | gpu->buildProgramDesc(&fDesc, *fPrimitiveProcessor, *getPipeline(), fBatchTracker); |
| 419 | } |
| 420 | } |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 421 | |
| 422 | void GrTargetCommands::Clear::execute(GrGpu* gpu, const SetState*) { |
| 423 | if (GrColor_ILLEGAL == fColor) { |
| 424 | gpu->discard(this->renderTarget()); |
| 425 | } else { |
| 426 | gpu->clear(&fRect, fColor, fCanIgnoreRect, this->renderTarget()); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | void GrTargetCommands::ClearStencilClip::execute(GrGpu* gpu, const SetState*) { |
| 431 | gpu->clearStencilClip(fRect, fInsideClip, this->renderTarget()); |
| 432 | } |
| 433 | |
| 434 | void GrTargetCommands::CopySurface::execute(GrGpu* gpu, const SetState*) { |
| 435 | gpu->copySurface(this->dst(), this->src(), fSrcRect, fDstPoint); |
| 436 | } |
| 437 | |
| 438 | GrTargetCommands::Cmd* GrTargetCommands::recordCopySurface(GrInOrderDrawBuffer* iodb, |
| 439 | GrSurface* dst, |
| 440 | GrSurface* src, |
| 441 | const SkIRect& srcRect, |
| 442 | const SkIPoint& dstPoint) { |
| 443 | if (iodb->getGpu()->canCopySurface(dst, src, srcRect, dstPoint)) { |
joshualitt | 0dcb8e3 | 2015-04-27 12:03:05 -0700 | [diff] [blame^] | 444 | CLOSE_BATCH |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 445 | CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst, src)); |
| 446 | cs->fSrcRect = srcRect; |
| 447 | cs->fDstPoint = dstPoint; |
| 448 | return cs; |
| 449 | } |
| 450 | return NULL; |
| 451 | } |
| 452 | |
| 453 | bool GrTargetCommands::setupPipelineAndShouldDraw(GrInOrderDrawBuffer* iodb, |
| 454 | const GrPrimitiveProcessor* primProc, |
| 455 | const GrDrawTarget::PipelineInfo& pipelineInfo) { |
| 456 | SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, (primProc)); |
| 457 | iodb->setupPipeline(pipelineInfo, ss->pipelineLocation()); |
| 458 | |
| 459 | if (ss->getPipeline()->mustSkip()) { |
| 460 | fCmdBuffer.pop_back(); |
| 461 | return false; |
| 462 | } |
| 463 | |
| 464 | ss->fPrimitiveProcessor->initBatchTracker(&ss->fBatchTracker, |
| 465 | ss->getPipeline()->getInitBatchTracker()); |
| 466 | |
| 467 | if (fPrevState && fPrevState->fPrimitiveProcessor.get() && |
| 468 | fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, |
| 469 | *ss->fPrimitiveProcessor, |
| 470 | ss->fBatchTracker) && |
| 471 | fPrevState->getPipeline()->isEqual(*ss->getPipeline())) { |
| 472 | fCmdBuffer.pop_back(); |
| 473 | } else { |
| 474 | fPrevState = ss; |
| 475 | iodb->recordTraceMarkersIfNecessary(ss); |
| 476 | } |
| 477 | return true; |
| 478 | } |
| 479 | |
| 480 | bool GrTargetCommands::setupPipelineAndShouldDraw(GrInOrderDrawBuffer* iodb, |
| 481 | GrBatch* batch, |
| 482 | const GrDrawTarget::PipelineInfo& pipelineInfo) { |
| 483 | SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, ()); |
| 484 | iodb->setupPipeline(pipelineInfo, ss->pipelineLocation()); |
| 485 | |
| 486 | if (ss->getPipeline()->mustSkip()) { |
| 487 | fCmdBuffer.pop_back(); |
| 488 | return false; |
| 489 | } |
| 490 | |
| 491 | batch->initBatchTracker(ss->getPipeline()->getInitBatchTracker()); |
| 492 | |
| 493 | if (fPrevState && !fPrevState->fPrimitiveProcessor.get() && |
| 494 | fPrevState->getPipeline()->isEqual(*ss->getPipeline())) { |
| 495 | fCmdBuffer.pop_back(); |
| 496 | } else { |
joshualitt | 0dcb8e3 | 2015-04-27 12:03:05 -0700 | [diff] [blame^] | 497 | CLOSE_BATCH |
robertphillips | 193ea93 | 2015-03-03 12:40:49 -0800 | [diff] [blame] | 498 | fPrevState = ss; |
| 499 | iodb->recordTraceMarkersIfNecessary(ss); |
| 500 | } |
| 501 | return true; |
| 502 | } |
| 503 | |