OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrTargetCommands.h" | 8 #include "GrTargetCommands.h" |
9 | 9 |
10 #include "GrColor.h" | 10 #include "GrColor.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // update last fGpuCmdMarkers to include any additional trace markers that h
ave been added | 75 // update last fGpuCmdMarkers to include any additional trace markers that h
ave been added |
76 iodb->recordTraceMarkersIfNecessary(draw); | 76 iodb->recordTraceMarkersIfNecessary(draw); |
77 return instancesToConcat; | 77 return instancesToConcat; |
78 } | 78 } |
79 | 79 |
80 GrTargetCommands::Cmd* GrTargetCommands::recordDraw( | 80 GrTargetCommands::Cmd* GrTargetCommands::recordDraw( |
81 GrInOrderDrawBuffer* iodb, | 81 GrInOrderDrawBuffer* iodb, |
82 const GrGeometryProcessor* gp, | 82 const GrGeometryProcessor* gp, |
83 const GrDrawTarget::DrawInfo&
info, | 83 const GrDrawTarget::DrawInfo&
info, |
84 const GrDrawTarget::PipelineIn
fo& pipelineInfo) { | 84 const GrDrawTarget::PipelineIn
fo& pipelineInfo) { |
| 85 #ifdef USE_BITMAP_TEXTBLOBS |
| 86 SkFAIL("Non-batch no longer supported\n"); |
| 87 #endif |
85 SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer())); | 88 SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer())); |
86 this->closeBatch(); | 89 CLOSE_BATCH |
87 | 90 |
88 if (!this->setupPipelineAndShouldDraw(iodb, gp, pipelineInfo)) { | 91 if (!this->setupPipelineAndShouldDraw(iodb, gp, pipelineInfo)) { |
89 return NULL; | 92 return NULL; |
90 } | 93 } |
91 | 94 |
92 Draw* draw; | 95 Draw* draw; |
93 if (info.isInstanced()) { | 96 if (info.isInstanced()) { |
94 int instancesConcated = this->concatInstancedDraw(iodb, info); | 97 int instancesConcated = this->concatInstancedDraw(iodb, info); |
95 if (info.instanceCount() > instancesConcated) { | 98 if (info.instanceCount() > instancesConcated) { |
96 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); | 99 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); |
(...skipping 17 matching lines...) Expand all Loading... |
114 } | 117 } |
115 | 118 |
116 // Check if there is a Batch Draw we can batch with | 119 // Check if there is a Batch Draw we can batch with |
117 if (Cmd::kDrawBatch_CmdType != fCmdBuffer.back().type() || !fDrawBatch) { | 120 if (Cmd::kDrawBatch_CmdType != fCmdBuffer.back().type() || !fDrawBatch) { |
118 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fB
atchTarget)); | 121 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fB
atchTarget)); |
119 return fDrawBatch; | 122 return fDrawBatch; |
120 } | 123 } |
121 | 124 |
122 SkASSERT(&fCmdBuffer.back() == fDrawBatch); | 125 SkASSERT(&fCmdBuffer.back() == fDrawBatch); |
123 if (!fDrawBatch->fBatch->combineIfPossible(batch)) { | 126 if (!fDrawBatch->fBatch->combineIfPossible(batch)) { |
124 this->closeBatch(); | 127 CLOSE_BATCH |
125 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fB
atchTarget)); | 128 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fB
atchTarget)); |
126 } | 129 } |
127 | 130 |
128 return fDrawBatch; | 131 return fDrawBatch; |
129 } | 132 } |
130 | 133 |
131 GrTargetCommands::Cmd* GrTargetCommands::recordStencilPath( | 134 GrTargetCommands::Cmd* GrTargetCommands::recordStencilPath( |
132 GrInOrderDrawBuffer* iod
b, | 135 GrInOrderDrawBuffer* iod
b, |
133 const GrPipelineBuilder&
pipelineBuilder, | 136 const GrPipelineBuilder&
pipelineBuilder, |
134 const GrPathProcessor* p
athProc, | 137 const GrPathProcessor* p
athProc, |
135 const GrPath* path, | 138 const GrPath* path, |
136 const GrScissorState& sc
issorState, | 139 const GrScissorState& sc
issorState, |
137 const GrStencilSettings&
stencilSettings) { | 140 const GrStencilSettings&
stencilSettings) { |
138 this->closeBatch(); | 141 CLOSE_BATCH |
139 | 142 |
140 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, | 143 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, |
141 (path, pipelineBuilder.getRenderT
arget())); | 144 (path, pipelineBuilder.getRenderT
arget())); |
142 | 145 |
143 sp->fScissor = scissorState; | 146 sp->fScissor = scissorState; |
144 sp->fUseHWAA = pipelineBuilder.isHWAntialias(); | 147 sp->fUseHWAA = pipelineBuilder.isHWAntialias(); |
145 sp->fViewMatrix = pathProc->viewMatrix(); | 148 sp->fViewMatrix = pathProc->viewMatrix(); |
146 sp->fStencil = stencilSettings; | 149 sp->fStencil = stencilSettings; |
147 return sp; | 150 return sp; |
148 } | 151 } |
149 | 152 |
150 GrTargetCommands::Cmd* GrTargetCommands::recordDrawPath( | 153 GrTargetCommands::Cmd* GrTargetCommands::recordDrawPath( |
151 GrInOrderDrawBuffer* iodb, | 154 GrInOrderDrawBuffer* iodb, |
152 const GrPathProcessor* pathPro
c, | 155 const GrPathProcessor* pathPro
c, |
153 const GrPath* path, | 156 const GrPath* path, |
154 const GrStencilSettings& stenc
ilSettings, | 157 const GrStencilSettings& stenc
ilSettings, |
155 const GrDrawTarget::PipelineIn
fo& pipelineInfo) { | 158 const GrDrawTarget::PipelineIn
fo& pipelineInfo) { |
156 this->closeBatch(); | 159 CLOSE_BATCH |
157 | 160 |
158 // TODO: Only compare the subset of GrPipelineBuilder relevant to path cover
ing? | 161 // TODO: Only compare the subset of GrPipelineBuilder relevant to path cover
ing? |
159 if (!this->setupPipelineAndShouldDraw(iodb, pathProc, pipelineInfo)) { | 162 if (!this->setupPipelineAndShouldDraw(iodb, pathProc, pipelineInfo)) { |
160 return NULL; | 163 return NULL; |
161 } | 164 } |
162 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path)); | 165 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path)); |
163 dp->fStencilSettings = stencilSettings; | 166 dp->fStencilSettings = stencilSettings; |
164 return dp; | 167 return dp; |
165 } | 168 } |
166 | 169 |
167 GrTargetCommands::Cmd* GrTargetCommands::recordDrawPaths( | 170 GrTargetCommands::Cmd* GrTargetCommands::recordDrawPaths( |
168 GrInOrderDrawBuffer* iodb, | 171 GrInOrderDrawBuffer* iodb, |
169 const GrPathProcessor* pathPro
c, | 172 const GrPathProcessor* pathPro
c, |
170 const GrPathRange* pathRange, | 173 const GrPathRange* pathRange, |
171 const void* indexValues, | 174 const void* indexValues, |
172 GrDrawTarget::PathIndexType in
dexType, | 175 GrDrawTarget::PathIndexType in
dexType, |
173 const float transformValues[], | 176 const float transformValues[], |
174 GrDrawTarget::PathTransformTyp
e transformType, | 177 GrDrawTarget::PathTransformTyp
e transformType, |
175 int count, | 178 int count, |
176 const GrStencilSettings& stenc
ilSettings, | 179 const GrStencilSettings& stenc
ilSettings, |
177 const GrDrawTarget::PipelineIn
fo& pipelineInfo) { | 180 const GrDrawTarget::PipelineIn
fo& pipelineInfo) { |
178 SkASSERT(pathRange); | 181 SkASSERT(pathRange); |
179 SkASSERT(indexValues); | 182 SkASSERT(indexValues); |
180 SkASSERT(transformValues); | 183 SkASSERT(transformValues); |
181 this->closeBatch(); | 184 CLOSE_BATCH |
182 | 185 |
183 if (!this->setupPipelineAndShouldDraw(iodb, pathProc, pipelineInfo)) { | 186 if (!this->setupPipelineAndShouldDraw(iodb, pathProc, pipelineInfo)) { |
184 return NULL; | 187 return NULL; |
185 } | 188 } |
186 | 189 |
187 char* savedIndices; | 190 char* savedIndices; |
188 float* savedTransforms; | 191 float* savedTransforms; |
189 | 192 |
190 iodb->appendIndicesAndTransforms(indexValues, indexType, | 193 iodb->appendIndicesAndTransforms(indexValues, indexType, |
191 transformValues, transformType, | 194 transformValues, transformType, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 dp->fStencilSettings = stencilSettings; | 230 dp->fStencilSettings = stencilSettings; |
228 return dp; | 231 return dp; |
229 } | 232 } |
230 | 233 |
231 GrTargetCommands::Cmd* GrTargetCommands::recordClear(GrInOrderDrawBuffer* iodb, | 234 GrTargetCommands::Cmd* GrTargetCommands::recordClear(GrInOrderDrawBuffer* iodb, |
232 const SkIRect* rect, | 235 const SkIRect* rect, |
233 GrColor color, | 236 GrColor color, |
234 bool canIgnoreRect, | 237 bool canIgnoreRect, |
235 GrRenderTarget* renderTarge
t) { | 238 GrRenderTarget* renderTarge
t) { |
236 SkASSERT(renderTarget); | 239 SkASSERT(renderTarget); |
237 this->closeBatch(); | 240 CLOSE_BATCH |
238 | 241 |
239 SkIRect r; | 242 SkIRect r; |
240 if (NULL == rect) { | 243 if (NULL == rect) { |
241 // We could do something smart and remove previous draws and clears to | 244 // We could do something smart and remove previous draws and clears to |
242 // the current render target. If we get that smart we have to make sure | 245 // the current render target. If we get that smart we have to make sure |
243 // those draws aren't read before this clear (render-to-texture). | 246 // those draws aren't read before this clear (render-to-texture). |
244 r.setLTRB(0, 0, renderTarget->width(), renderTarget->height()); | 247 r.setLTRB(0, 0, renderTarget->width(), renderTarget->height()); |
245 rect = &r; | 248 rect = &r; |
246 } | 249 } |
247 Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); | 250 Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); |
248 GrColorIsPMAssert(color); | 251 GrColorIsPMAssert(color); |
249 clr->fColor = color; | 252 clr->fColor = color; |
250 clr->fRect = *rect; | 253 clr->fRect = *rect; |
251 clr->fCanIgnoreRect = canIgnoreRect; | 254 clr->fCanIgnoreRect = canIgnoreRect; |
252 return clr; | 255 return clr; |
253 } | 256 } |
254 | 257 |
255 GrTargetCommands::Cmd* GrTargetCommands::recordClearStencilClip(GrInOrderDrawBuf
fer* iodb, | 258 GrTargetCommands::Cmd* GrTargetCommands::recordClearStencilClip(GrInOrderDrawBuf
fer* iodb, |
256 const SkIRect& r
ect, | 259 const SkIRect& r
ect, |
257 bool insideClip, | 260 bool insideClip, |
258 GrRenderTarget*
renderTarget) { | 261 GrRenderTarget*
renderTarget) { |
259 SkASSERT(renderTarget); | 262 SkASSERT(renderTarget); |
260 this->closeBatch(); | 263 CLOSE_BATCH |
261 | 264 |
262 ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, ClearStencilCli
p, (renderTarget)); | 265 ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, ClearStencilCli
p, (renderTarget)); |
263 clr->fRect = rect; | 266 clr->fRect = rect; |
264 clr->fInsideClip = insideClip; | 267 clr->fInsideClip = insideClip; |
265 return clr; | 268 return clr; |
266 } | 269 } |
267 | 270 |
268 GrTargetCommands::Cmd* GrTargetCommands::recordDiscard(GrInOrderDrawBuffer* iodb
, | 271 GrTargetCommands::Cmd* GrTargetCommands::recordDiscard(GrInOrderDrawBuffer* iodb
, |
269 GrRenderTarget* renderTar
get) { | 272 GrRenderTarget* renderTar
get) { |
270 SkASSERT(renderTarget); | 273 SkASSERT(renderTarget); |
271 this->closeBatch(); | 274 CLOSE_BATCH |
272 | 275 |
273 Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); | 276 Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); |
274 clr->fColor = GrColor_ILLEGAL; | 277 clr->fColor = GrColor_ILLEGAL; |
275 return clr; | 278 return clr; |
276 } | 279 } |
277 | 280 |
278 void GrTargetCommands::reset() { | 281 void GrTargetCommands::reset() { |
279 fCmdBuffer.reset(); | 282 fCmdBuffer.reset(); |
280 fPrevState = NULL; | 283 fPrevState = NULL; |
281 fDrawBatch = NULL; | 284 fDrawBatch = NULL; |
282 } | 285 } |
283 | 286 |
284 void GrTargetCommands::flush(GrInOrderDrawBuffer* iodb) { | 287 void GrTargetCommands::flush(GrInOrderDrawBuffer* iodb) { |
285 if (fCmdBuffer.empty()) { | 288 if (fCmdBuffer.empty()) { |
286 return; | 289 return; |
287 } | 290 } |
288 | 291 |
289 // TODO this is temporary while batch is being rolled out | 292 // TODO this is temporary while batch is being rolled out |
290 this->closeBatch(); | 293 CLOSE_BATCH |
291 iodb->getVertexAllocPool()->unmap(); | |
292 iodb->getIndexAllocPool()->unmap(); | |
293 fBatchTarget.preFlush(); | |
294 | 294 |
295 // Updated every time we find a set state cmd to reflect the current state i
n the playback | 295 // Updated every time we find a set state cmd to reflect the current state i
n the playback |
296 // stream. | 296 // stream. |
297 SetState* currentState = NULL; | 297 SetState* currentState = NULL; |
298 | 298 |
| 299 GrGpu* gpu = iodb->getGpu(); |
| 300 |
| 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 |
299 CmdBuffer::Iter iter(fCmdBuffer); | 323 CmdBuffer::Iter iter(fCmdBuffer); |
300 | 324 |
301 GrGpu* gpu = iodb->getGpu(); | |
302 | |
303 while (iter.next()) { | 325 while (iter.next()) { |
304 GrGpuTraceMarker newMarker("", -1); | 326 GrGpuTraceMarker newMarker("", -1); |
305 SkString traceString; | 327 SkString traceString; |
306 if (iter->isTraced()) { | 328 if (iter->isTraced()) { |
307 traceString = iodb->getCmdString(iter->markerID()); | 329 traceString = iodb->getCmdString(iter->markerID()); |
308 newMarker.fMarker = traceString.c_str(); | 330 newMarker.fMarker = traceString.c_str(); |
309 gpu->addGpuTraceMarker(&newMarker); | 331 gpu->addGpuTraceMarker(&newMarker); |
310 } | 332 } |
311 | 333 |
312 // TODO temporary hack | 334 // TODO temporary hack |
313 if (Cmd::kDrawBatch_CmdType == iter->type()) { | 335 if (Cmd::kDrawBatch_CmdType == iter->type()) { |
314 DrawBatch* db = reinterpret_cast<DrawBatch*>(iter.get()); | 336 DrawBatch* db = reinterpret_cast<DrawBatch*>(iter.get()); |
315 fBatchTarget.flushNext(db->fBatch->numberOfDraws()); | 337 fBatchTarget.flushNext(db->fBatch->numberOfDraws()); |
316 | 338 |
317 if (iter->isTraced()) { | 339 if (iter->isTraced()) { |
318 gpu->removeGpuTraceMarker(&newMarker); | 340 gpu->removeGpuTraceMarker(&newMarker); |
319 } | 341 } |
320 continue; | 342 continue; |
321 } | 343 } |
322 | 344 |
323 if (Cmd::kSetState_CmdType == iter->type()) { | 345 if (Cmd::kSetState_CmdType == iter->type()) { |
| 346 #ifndef USE_BITMAP_TEXTBLOBS |
324 SetState* ss = reinterpret_cast<SetState*>(iter.get()); | 347 SetState* ss = reinterpret_cast<SetState*>(iter.get()); |
325 | 348 |
326 ss->execute(gpu, currentState); | 349 ss->execute(gpu, currentState); |
327 currentState = ss; | 350 currentState = ss; |
| 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 |
328 } else { | 361 } else { |
329 iter->execute(gpu, currentState); | 362 iter->execute(gpu, currentState); |
330 } | 363 } |
331 | 364 |
332 if (iter->isTraced()) { | 365 if (iter->isTraced()) { |
333 gpu->removeGpuTraceMarker(&newMarker); | 366 gpu->removeGpuTraceMarker(&newMarker); |
334 } | 367 } |
335 } | 368 } |
336 | 369 |
337 // TODO see copious notes about hack | 370 // TODO see copious notes about hack |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 void GrTargetCommands::CopySurface::execute(GrGpu* gpu, const SetState*) { | 434 void GrTargetCommands::CopySurface::execute(GrGpu* gpu, const SetState*) { |
402 gpu->copySurface(this->dst(), this->src(), fSrcRect, fDstPoint); | 435 gpu->copySurface(this->dst(), this->src(), fSrcRect, fDstPoint); |
403 } | 436 } |
404 | 437 |
405 GrTargetCommands::Cmd* GrTargetCommands::recordCopySurface(GrInOrderDrawBuffer*
iodb, | 438 GrTargetCommands::Cmd* GrTargetCommands::recordCopySurface(GrInOrderDrawBuffer*
iodb, |
406 GrSurface* dst, | 439 GrSurface* dst, |
407 GrSurface* src, | 440 GrSurface* src, |
408 const SkIRect& srcRec
t, | 441 const SkIRect& srcRec
t, |
409 const SkIPoint& dstPo
int) { | 442 const SkIPoint& dstPo
int) { |
410 if (iodb->getGpu()->canCopySurface(dst, src, srcRect, dstPoint)) { | 443 if (iodb->getGpu()->canCopySurface(dst, src, srcRect, dstPoint)) { |
411 this->closeBatch(); | 444 CLOSE_BATCH |
412 CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst
, src)); | 445 CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst
, src)); |
413 cs->fSrcRect = srcRect; | 446 cs->fSrcRect = srcRect; |
414 cs->fDstPoint = dstPoint; | 447 cs->fDstPoint = dstPoint; |
415 return cs; | 448 return cs; |
416 } | 449 } |
417 return NULL; | 450 return NULL; |
418 } | 451 } |
419 | 452 |
420 bool GrTargetCommands::setupPipelineAndShouldDraw(GrInOrderDrawBuffer* iodb, | 453 bool GrTargetCommands::setupPipelineAndShouldDraw(GrInOrderDrawBuffer* iodb, |
421 const GrPrimitiveProcessor* pr
imProc, | 454 const GrPrimitiveProcessor* pr
imProc, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 fCmdBuffer.pop_back(); | 487 fCmdBuffer.pop_back(); |
455 return false; | 488 return false; |
456 } | 489 } |
457 | 490 |
458 batch->initBatchTracker(ss->getPipeline()->getInitBatchTracker()); | 491 batch->initBatchTracker(ss->getPipeline()->getInitBatchTracker()); |
459 | 492 |
460 if (fPrevState && !fPrevState->fPrimitiveProcessor.get() && | 493 if (fPrevState && !fPrevState->fPrimitiveProcessor.get() && |
461 fPrevState->getPipeline()->isEqual(*ss->getPipeline())) { | 494 fPrevState->getPipeline()->isEqual(*ss->getPipeline())) { |
462 fCmdBuffer.pop_back(); | 495 fCmdBuffer.pop_back(); |
463 } else { | 496 } else { |
464 this->closeBatch(); | 497 CLOSE_BATCH |
465 fPrevState = ss; | 498 fPrevState = ss; |
466 iodb->recordTraceMarkersIfNecessary(ss); | 499 iodb->recordTraceMarkersIfNecessary(ss); |
467 } | 500 } |
468 return true; | 501 return true; |
469 } | 502 } |
470 | 503 |
OLD | NEW |