Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: src/gpu/GrInOrderDrawBuffer.cpp

Issue 1113313003: Create GrCommandBuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 this->drawBatch(pipelineBuilder, batch); 299 this->drawBatch(pipelineBuilder, batch);
300 } 300 }
301 301
302 void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch, 302 void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch,
303 const PipelineInfo& pipelineInfo) { 303 const PipelineInfo& pipelineInfo) {
304 State* state = this->setupPipelineAndShouldDraw(batch, pipelineInfo); 304 State* state = this->setupPipelineAndShouldDraw(batch, pipelineInfo);
305 if (!state) { 305 if (!state) {
306 return; 306 return;
307 } 307 }
308 308
309 GrTargetCommands::Cmd* cmd = fCommands.recordDrawBatch(state, batch); 309 GrTargetCommands::Cmd* cmd = fCommands->recordDrawBatch(state, batch);
310 this->recordTraceMarkersIfNecessary(cmd); 310 this->recordTraceMarkersIfNecessary(cmd);
311 } 311 }
312 312
313 void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder , 313 void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder ,
314 const GrPathProcessor* pathProc, 314 const GrPathProcessor* pathProc,
315 const GrPath* path, 315 const GrPath* path,
316 const GrScissorState& scissorState, 316 const GrScissorState& scissorState,
317 const GrStencilSettings& stencilSettings ) { 317 const GrStencilSettings& stencilSettings ) {
318 GrTargetCommands::Cmd* cmd = fCommands.recordStencilPath(pipelineBuilder, 318 GrTargetCommands::Cmd* cmd = fCommands->recordStencilPath(pipelineBuilder,
319 pathProc, path, sci ssorState, 319 pathProc, path, sc issorState,
320 stencilSettings); 320 stencilSettings);
321 this->recordTraceMarkersIfNecessary(cmd); 321 this->recordTraceMarkersIfNecessary(cmd);
322 } 322 }
323 323
324 void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc, 324 void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc,
325 const GrPath* path, 325 const GrPath* path,
326 const GrStencilSettings& stencilSettings, 326 const GrStencilSettings& stencilSettings,
327 const PipelineInfo& pipelineInfo) { 327 const PipelineInfo& pipelineInfo) {
328 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo); 328 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo);
329 if (!state) { 329 if (!state) {
330 return; 330 return;
331 } 331 }
332 GrTargetCommands::Cmd* cmd = fCommands.recordDrawPath(state, pathProc, path, stencilSettings); 332 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPath(state, pathProc, path , stencilSettings);
333 this->recordTraceMarkersIfNecessary(cmd); 333 this->recordTraceMarkersIfNecessary(cmd);
334 } 334 }
335 335
336 void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc, 336 void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc,
337 const GrPathRange* pathRange, 337 const GrPathRange* pathRange,
338 const void* indices, 338 const void* indices,
339 PathIndexType indexType, 339 PathIndexType indexType,
340 const float transformValues[], 340 const float transformValues[],
341 PathTransformType transformType, 341 PathTransformType transformType,
342 int count, 342 int count,
343 const GrStencilSettings& stencilSettings, 343 const GrStencilSettings& stencilSettings,
344 const PipelineInfo& pipelineInfo) { 344 const PipelineInfo& pipelineInfo) {
345 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo); 345 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo);
346 if (!state) { 346 if (!state) {
347 return; 347 return;
348 } 348 }
349 GrTargetCommands::Cmd* cmd = fCommands.recordDrawPaths(state, this, pathProc , pathRange, 349 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPaths(state, this, pathPro c, pathRange,
350 indices, indexType, t ransformValues, 350 indices, indexType, transformValues,
351 transformType, count, 351 transformType, count ,
352 stencilSettings, pipe lineInfo); 352 stencilSettings, pip elineInfo);
353 this->recordTraceMarkersIfNecessary(cmd); 353 this->recordTraceMarkersIfNecessary(cmd);
354 } 354 }
355 355
356 void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color, 356 void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color,
357 bool canIgnoreRect, GrRenderTarget* renderTarg et) { 357 bool canIgnoreRect, GrRenderTarget* renderTarg et) {
358 GrTargetCommands::Cmd* cmd = fCommands.recordClear(rect, color, canIgnoreRec t, renderTarget); 358 GrTargetCommands::Cmd* cmd = fCommands->recordClear(rect, color, canIgnoreRe ct, renderTarget);
359 this->recordTraceMarkersIfNecessary(cmd); 359 this->recordTraceMarkersIfNecessary(cmd);
360 } 360 }
361 361
362 void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect, 362 void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect,
363 bool insideClip, 363 bool insideClip,
364 GrRenderTarget* renderTarget) { 364 GrRenderTarget* renderTarget) {
365 GrTargetCommands::Cmd* cmd = fCommands.recordClearStencilClip(rect, insideCl ip, renderTarget); 365 GrTargetCommands::Cmd* cmd = fCommands->recordClearStencilClip(rect, insideC lip, renderTarget);
366 this->recordTraceMarkersIfNecessary(cmd); 366 this->recordTraceMarkersIfNecessary(cmd);
367 } 367 }
368 368
369 void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) { 369 void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) {
370 if (!this->caps()->discardRenderTargetSupport()) { 370 if (!this->caps()->discardRenderTargetSupport()) {
371 return; 371 return;
372 } 372 }
373 373
374 GrTargetCommands::Cmd* cmd = fCommands.recordDiscard(renderTarget); 374 GrTargetCommands::Cmd* cmd = fCommands->recordDiscard(renderTarget);
375 this->recordTraceMarkersIfNecessary(cmd); 375 this->recordTraceMarkersIfNecessary(cmd);
376 } 376 }
377 377
378 void GrInOrderDrawBuffer::onReset() { 378 void GrInOrderDrawBuffer::onReset() {
379 fCommands.reset(); 379 fCommands->reset();
380 fPathIndexBuffer.rewind(); 380 fPathIndexBuffer.rewind();
381 fPathTransformBuffer.rewind(); 381 fPathTransformBuffer.rewind();
382 fGpuCmdMarkers.reset(); 382 fGpuCmdMarkers.reset();
383 383
384 fPrevState.reset(NULL); 384 fPrevState.reset(NULL);
385 // Note, fPrevState points into fPipelineBuffer's allocation, so we have to reset first. 385 // Note, fPrevState points into fPipelineBuffer's allocation, so we have to reset first.
386 // Furthermore, we have to reset fCommands before fPipelineBuffer too. 386 // Furthermore, we have to reset fCommands before fPipelineBuffer too.
387 if (fDrawID % kPipelineBufferHighWaterMark) { 387 if (fDrawID % kPipelineBufferHighWaterMark) {
388 fPipelineBuffer.rewind(); 388 fPipelineBuffer.rewind();
389 } else { 389 } else {
390 fPipelineBuffer.reset(); 390 fPipelineBuffer.reset();
391 } 391 }
392 } 392 }
393 393
394 void GrInOrderDrawBuffer::onFlush() { 394 void GrInOrderDrawBuffer::onFlush() {
395 fCommands.flush(this); 395 fCommands->flush(this);
396 ++fDrawID; 396 ++fDrawID;
397 } 397 }
398 398
399 void GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, 399 void GrInOrderDrawBuffer::onCopySurface(GrSurface* dst,
400 GrSurface* src, 400 GrSurface* src,
401 const SkIRect& srcRect, 401 const SkIRect& srcRect,
402 const SkIPoint& dstPoint) { 402 const SkIPoint& dstPoint) {
403 SkASSERT(this->getGpu()->canCopySurface(dst, src, srcRect, dstPoint)); 403 SkASSERT(this->getGpu()->canCopySurface(dst, src, srcRect, dstPoint));
404 GrTargetCommands::Cmd* cmd = fCommands.recordCopySurface(dst, src, srcRect, dstPoint); 404 GrTargetCommands::Cmd* cmd = fCommands->recordCopySurface(dst, src, srcRect, dstPoint);
405 this->recordTraceMarkersIfNecessary(cmd); 405 this->recordTraceMarkersIfNecessary(cmd);
406 } 406 }
407 407
408 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary(GrTargetCommands::Cmd* c md) { 408 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary(GrTargetCommands::Cmd* c md) {
409 if (!cmd) { 409 if (!cmd) {
410 return; 410 return;
411 } 411 }
412 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); 412 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers();
413 if (activeTraceMarkers.count() > 0) { 413 if (activeTraceMarkers.count() > 0) {
414 if (cmd->isTraced()) { 414 if (cmd->isTraced()) {
(...skipping 22 matching lines...) Expand all
437 if (fPrevState && fPrevState->fPrimitiveProcessor.get() && 437 if (fPrevState && fPrevState->fPrimitiveProcessor.get() &&
438 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, 438 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker,
439 *state->fPrimitiveProcesso r, 439 *state->fPrimitiveProcesso r,
440 state->fBatchTracker) && 440 state->fBatchTracker) &&
441 fPrevState->getPipeline()->isEqual(*state->getPipeline())) { 441 fPrevState->getPipeline()->isEqual(*state->getPipeline())) {
442 this->unallocState(state); 442 this->unallocState(state);
443 } else { 443 } else {
444 fPrevState.reset(state); 444 fPrevState.reset(state);
445 } 445 }
446 446
447 fCommands.recordXferBarrierIfNecessary(*fPrevState->getPipeline(), this); 447 this->recordTraceMarkersIfNecessary(
448 fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(), *this->caps()));
448 return fPrevState; 449 return fPrevState;
449 } 450 }
450 451
451 GrTargetCommands::State* 452 GrTargetCommands::State*
452 GrInOrderDrawBuffer::setupPipelineAndShouldDraw(GrBatch* batch, 453 GrInOrderDrawBuffer::setupPipelineAndShouldDraw(GrBatch* batch,
453 const GrDrawTarget::PipelineInfo & pipelineInfo) { 454 const GrDrawTarget::PipelineInfo & pipelineInfo) {
454 State* state = this->allocState(); 455 State* state = this->allocState();
455 this->setupPipeline(pipelineInfo, state->pipelineLocation()); 456 this->setupPipeline(pipelineInfo, state->pipelineLocation());
456 457
457 if (state->getPipeline()->mustSkip()) { 458 if (state->getPipeline()->mustSkip()) {
458 this->unallocState(state); 459 this->unallocState(state);
459 return NULL; 460 return NULL;
460 } 461 }
461 462
462 batch->initBatchTracker(state->getPipeline()->getInitBatchTracker()); 463 batch->initBatchTracker(state->getPipeline()->getInitBatchTracker());
463 464
464 if (fPrevState && !fPrevState->fPrimitiveProcessor.get() && 465 if (fPrevState && !fPrevState->fPrimitiveProcessor.get() &&
465 fPrevState->getPipeline()->isEqual(*state->getPipeline())) { 466 fPrevState->getPipeline()->isEqual(*state->getPipeline())) {
466 this->unallocState(state); 467 this->unallocState(state);
467 } else { 468 } else {
468 fPrevState.reset(state); 469 fPrevState.reset(state);
469 } 470 }
470 471
471 fCommands.recordXferBarrierIfNecessary(*fPrevState->getPipeline(), this); 472 this->recordTraceMarkersIfNecessary(
473 fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(), *this->caps()));
472 return fPrevState; 474 return fPrevState;
473 } 475 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698