OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrInOrderDrawBuffer.h" | 8 #include "GrInOrderDrawBuffer.h" |
9 | 9 |
10 #include "GrDefaultGeoProcFactory.h" | 10 #include "GrDefaultGeoProcFactory.h" |
11 #include "GrTemplates.h" | 11 #include "GrTemplates.h" |
12 | 12 |
13 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrContext* context, | 13 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrContext* context, |
14 GrVertexBufferAllocPool* vertexPool, | 14 GrVertexBufferAllocPool* vertexPool, |
15 GrIndexBufferAllocPool* indexPool) | 15 GrIndexBufferAllocPool* indexPool) |
16 : INHERITED(context, vertexPool, indexPool) | 16 : INHERITED(context, vertexPool, indexPool) |
17 , fCommands(context->getGpu(), vertexPool, indexPool) | 17 , fCommands(SkNEW_ARGS(GrCommandBuilder, (context->getGpu(), vertexPool, ind
exPool))) |
18 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4) | 18 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4) |
19 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4) | 19 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4) |
20 , fPipelineBuffer(kPipelineBufferMinReserve) | 20 , fPipelineBuffer(kPipelineBufferMinReserve) |
21 , fDrawID(0) { | 21 , fDrawID(0) { |
22 | 22 |
23 SkASSERT(vertexPool); | 23 SkASSERT(vertexPool); |
24 SkASSERT(indexPool); | 24 SkASSERT(indexPool); |
25 } | 25 } |
26 | 26 |
27 GrInOrderDrawBuffer::~GrInOrderDrawBuffer() { | 27 GrInOrderDrawBuffer::~GrInOrderDrawBuffer() { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 this->drawBatch(pipelineBuilder, batch); | 265 this->drawBatch(pipelineBuilder, batch); |
266 } | 266 } |
267 | 267 |
268 void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch, | 268 void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch, |
269 const PipelineInfo& pipelineInfo) { | 269 const PipelineInfo& pipelineInfo) { |
270 State* state = this->setupPipelineAndShouldDraw(batch, pipelineInfo); | 270 State* state = this->setupPipelineAndShouldDraw(batch, pipelineInfo); |
271 if (!state) { | 271 if (!state) { |
272 return; | 272 return; |
273 } | 273 } |
274 | 274 |
275 GrTargetCommands::Cmd* cmd = fCommands.recordDrawBatch(state, batch); | 275 GrTargetCommands::Cmd* cmd = fCommands->recordDrawBatch(state, batch); |
276 this->recordTraceMarkersIfNecessary(cmd); | 276 this->recordTraceMarkersIfNecessary(cmd); |
277 } | 277 } |
278 | 278 |
279 void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder
, | 279 void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder
, |
280 const GrPathProcessor* pathProc, | 280 const GrPathProcessor* pathProc, |
281 const GrPath* path, | 281 const GrPath* path, |
282 const GrScissorState& scissorState, | 282 const GrScissorState& scissorState, |
283 const GrStencilSettings& stencilSettings
) { | 283 const GrStencilSettings& stencilSettings
) { |
284 GrTargetCommands::Cmd* cmd = fCommands.recordStencilPath(pipelineBuilder, | 284 GrTargetCommands::Cmd* cmd = fCommands->recordStencilPath(pipelineBuilder, |
285 pathProc, path, sci
ssorState, | 285 pathProc, path, sc
issorState, |
286 stencilSettings); | 286 stencilSettings); |
287 this->recordTraceMarkersIfNecessary(cmd); | 287 this->recordTraceMarkersIfNecessary(cmd); |
288 } | 288 } |
289 | 289 |
290 void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc, | 290 void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc, |
291 const GrPath* path, | 291 const GrPath* path, |
292 const GrStencilSettings& stencilSettings, | 292 const GrStencilSettings& stencilSettings, |
293 const PipelineInfo& pipelineInfo) { | 293 const PipelineInfo& pipelineInfo) { |
294 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo); | 294 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo); |
295 if (!state) { | 295 if (!state) { |
296 return; | 296 return; |
297 } | 297 } |
298 GrTargetCommands::Cmd* cmd = fCommands.recordDrawPath(state, pathProc, path,
stencilSettings); | 298 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPath(state, pathProc, path
, stencilSettings); |
299 this->recordTraceMarkersIfNecessary(cmd); | 299 this->recordTraceMarkersIfNecessary(cmd); |
300 } | 300 } |
301 | 301 |
302 void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc, | 302 void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc, |
303 const GrPathRange* pathRange, | 303 const GrPathRange* pathRange, |
304 const void* indices, | 304 const void* indices, |
305 PathIndexType indexType, | 305 PathIndexType indexType, |
306 const float transformValues[], | 306 const float transformValues[], |
307 PathTransformType transformType, | 307 PathTransformType transformType, |
308 int count, | 308 int count, |
309 const GrStencilSettings& stencilSettings, | 309 const GrStencilSettings& stencilSettings, |
310 const PipelineInfo& pipelineInfo) { | 310 const PipelineInfo& pipelineInfo) { |
311 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo); | 311 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo); |
312 if (!state) { | 312 if (!state) { |
313 return; | 313 return; |
314 } | 314 } |
315 GrTargetCommands::Cmd* cmd = fCommands.recordDrawPaths(state, this, pathProc
, pathRange, | 315 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPaths(state, this, pathPro
c, pathRange, |
316 indices, indexType, t
ransformValues, | 316 indices, indexType,
transformValues, |
317 transformType, count, | 317 transformType, count
, |
318 stencilSettings, pipe
lineInfo); | 318 stencilSettings, pip
elineInfo); |
319 this->recordTraceMarkersIfNecessary(cmd); | 319 this->recordTraceMarkersIfNecessary(cmd); |
320 } | 320 } |
321 | 321 |
322 void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color, | 322 void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color, |
323 bool canIgnoreRect, GrRenderTarget* renderTarg
et) { | 323 bool canIgnoreRect, GrRenderTarget* renderTarg
et) { |
324 GrTargetCommands::Cmd* cmd = fCommands.recordClear(rect, color, canIgnoreRec
t, renderTarget); | 324 GrTargetCommands::Cmd* cmd = fCommands->recordClear(rect, color, canIgnoreRe
ct, renderTarget); |
325 this->recordTraceMarkersIfNecessary(cmd); | 325 this->recordTraceMarkersIfNecessary(cmd); |
326 } | 326 } |
327 | 327 |
328 void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect, | 328 void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect, |
329 bool insideClip, | 329 bool insideClip, |
330 GrRenderTarget* renderTarget) { | 330 GrRenderTarget* renderTarget) { |
331 GrTargetCommands::Cmd* cmd = fCommands.recordClearStencilClip(rect, insideCl
ip, renderTarget); | 331 GrTargetCommands::Cmd* cmd = fCommands->recordClearStencilClip(rect, insideC
lip, renderTarget); |
332 this->recordTraceMarkersIfNecessary(cmd); | 332 this->recordTraceMarkersIfNecessary(cmd); |
333 } | 333 } |
334 | 334 |
335 void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) { | 335 void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) { |
336 if (!this->caps()->discardRenderTargetSupport()) { | 336 if (!this->caps()->discardRenderTargetSupport()) { |
337 return; | 337 return; |
338 } | 338 } |
339 | 339 |
340 GrTargetCommands::Cmd* cmd = fCommands.recordDiscard(renderTarget); | 340 GrTargetCommands::Cmd* cmd = fCommands->recordDiscard(renderTarget); |
341 this->recordTraceMarkersIfNecessary(cmd); | 341 this->recordTraceMarkersIfNecessary(cmd); |
342 } | 342 } |
343 | 343 |
344 void GrInOrderDrawBuffer::onReset() { | 344 void GrInOrderDrawBuffer::onReset() { |
345 fCommands.reset(); | 345 fCommands->reset(); |
346 fPathIndexBuffer.rewind(); | 346 fPathIndexBuffer.rewind(); |
347 fPathTransformBuffer.rewind(); | 347 fPathTransformBuffer.rewind(); |
348 fGpuCmdMarkers.reset(); | 348 fGpuCmdMarkers.reset(); |
349 | 349 |
350 fPrevState.reset(NULL); | 350 fPrevState.reset(NULL); |
351 // Note, fPrevState points into fPipelineBuffer's allocation, so we have to
reset first. | 351 // Note, fPrevState points into fPipelineBuffer's allocation, so we have to
reset first. |
352 // Furthermore, we have to reset fCommands before fPipelineBuffer too. | 352 // Furthermore, we have to reset fCommands before fPipelineBuffer too. |
353 if (fDrawID % kPipelineBufferHighWaterMark) { | 353 if (fDrawID % kPipelineBufferHighWaterMark) { |
354 fPipelineBuffer.rewind(); | 354 fPipelineBuffer.rewind(); |
355 } else { | 355 } else { |
356 fPipelineBuffer.reset(); | 356 fPipelineBuffer.reset(); |
357 } | 357 } |
358 } | 358 } |
359 | 359 |
360 void GrInOrderDrawBuffer::onFlush() { | 360 void GrInOrderDrawBuffer::onFlush() { |
361 fCommands.flush(this); | 361 fCommands->flush(this); |
362 ++fDrawID; | 362 ++fDrawID; |
363 } | 363 } |
364 | 364 |
365 void GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, | 365 void GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, |
366 GrSurface* src, | 366 GrSurface* src, |
367 const SkIRect& srcRect, | 367 const SkIRect& srcRect, |
368 const SkIPoint& dstPoint) { | 368 const SkIPoint& dstPoint) { |
369 SkASSERT(this->getGpu()->canCopySurface(dst, src, srcRect, dstPoint)); | 369 SkASSERT(this->getGpu()->canCopySurface(dst, src, srcRect, dstPoint)); |
370 GrTargetCommands::Cmd* cmd = fCommands.recordCopySurface(dst, src, srcRect,
dstPoint); | 370 GrTargetCommands::Cmd* cmd = fCommands->recordCopySurface(dst, src, srcRect,
dstPoint); |
371 this->recordTraceMarkersIfNecessary(cmd); | 371 this->recordTraceMarkersIfNecessary(cmd); |
372 } | 372 } |
373 | 373 |
374 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary(GrTargetCommands::Cmd* c
md) { | 374 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary(GrTargetCommands::Cmd* c
md) { |
375 if (!cmd) { | 375 if (!cmd) { |
376 return; | 376 return; |
377 } | 377 } |
378 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); | 378 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
379 if (activeTraceMarkers.count() > 0) { | 379 if (activeTraceMarkers.count() > 0) { |
380 if (cmd->isTraced()) { | 380 if (cmd->isTraced()) { |
(...skipping 22 matching lines...) Expand all Loading... |
403 if (fPrevState && fPrevState->fPrimitiveProcessor.get() && | 403 if (fPrevState && fPrevState->fPrimitiveProcessor.get() && |
404 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, | 404 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, |
405 *state->fPrimitiveProcesso
r, | 405 *state->fPrimitiveProcesso
r, |
406 state->fBatchTracker) && | 406 state->fBatchTracker) && |
407 fPrevState->getPipeline()->isEqual(*state->getPipeline())) { | 407 fPrevState->getPipeline()->isEqual(*state->getPipeline())) { |
408 this->unallocState(state); | 408 this->unallocState(state); |
409 } else { | 409 } else { |
410 fPrevState.reset(state); | 410 fPrevState.reset(state); |
411 } | 411 } |
412 | 412 |
413 fCommands.recordXferBarrierIfNecessary(*fPrevState->getPipeline(), this); | 413 this->recordTraceMarkersIfNecessary( |
| 414 fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(),
*this->caps())); |
414 return fPrevState; | 415 return fPrevState; |
415 } | 416 } |
416 | 417 |
417 GrTargetCommands::State* | 418 GrTargetCommands::State* |
418 GrInOrderDrawBuffer::setupPipelineAndShouldDraw(GrBatch* batch, | 419 GrInOrderDrawBuffer::setupPipelineAndShouldDraw(GrBatch* batch, |
419 const GrDrawTarget::PipelineInfo
& pipelineInfo) { | 420 const GrDrawTarget::PipelineInfo
& pipelineInfo) { |
420 State* state = this->allocState(); | 421 State* state = this->allocState(); |
421 this->setupPipeline(pipelineInfo, state->pipelineLocation()); | 422 this->setupPipeline(pipelineInfo, state->pipelineLocation()); |
422 | 423 |
423 if (state->getPipeline()->mustSkip()) { | 424 if (state->getPipeline()->mustSkip()) { |
424 this->unallocState(state); | 425 this->unallocState(state); |
425 return NULL; | 426 return NULL; |
426 } | 427 } |
427 | 428 |
428 batch->initBatchTracker(state->getPipeline()->getInitBatchTracker()); | 429 batch->initBatchTracker(state->getPipeline()->getInitBatchTracker()); |
429 | 430 |
430 if (fPrevState && !fPrevState->fPrimitiveProcessor.get() && | 431 if (fPrevState && !fPrevState->fPrimitiveProcessor.get() && |
431 fPrevState->getPipeline()->isEqual(*state->getPipeline())) { | 432 fPrevState->getPipeline()->isEqual(*state->getPipeline())) { |
432 this->unallocState(state); | 433 this->unallocState(state); |
433 } else { | 434 } else { |
434 fPrevState.reset(state); | 435 fPrevState.reset(state); |
435 } | 436 } |
436 | 437 |
437 fCommands.recordXferBarrierIfNecessary(*fPrevState->getPipeline(), this); | 438 this->recordTraceMarkersIfNecessary( |
| 439 fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(),
*this->caps())); |
438 return fPrevState; | 440 return fPrevState; |
439 } | 441 } |
OLD | NEW |