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

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

Issue 1120143002: Move state management to GrInOrderDrawBuffer (Closed) Base URL: https://skia.googlesource.com/skia.git@batchownsbounds
Patch Set: a bit more 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
« no previous file with comments | « src/gpu/GrInOrderDrawBuffer.h ('k') | src/gpu/GrTargetCommands.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(context->getGpu(), vertexPool, indexPool)
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 , fDrawID(0) { 21 , fDrawID(0) {
21 22
22 SkASSERT(vertexPool); 23 SkASSERT(vertexPool);
23 SkASSERT(indexPool); 24 SkASSERT(indexPool);
24 } 25 }
25 26
26 GrInOrderDrawBuffer::~GrInOrderDrawBuffer() { 27 GrInOrderDrawBuffer::~GrInOrderDrawBuffer() {
27 this->reset(); 28 this->reset();
28 } 29 }
29 30
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 } else { 294 } else {
294 geometry.fHasLocalMatrix = false; 295 geometry.fHasLocalMatrix = false;
295 } 296 }
296 297
297 SkAutoTUnref<GrBatch> batch(RectBatch::Create(geometry)); 298 SkAutoTUnref<GrBatch> batch(RectBatch::Create(geometry));
298 this->drawBatch(pipelineBuilder, batch); 299 this->drawBatch(pipelineBuilder, batch);
299 } 300 }
300 301
301 void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch, 302 void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch,
302 const PipelineInfo& pipelineInfo) { 303 const PipelineInfo& pipelineInfo) {
303 GrTargetCommands::Cmd* cmd = fCommands.recordDrawBatch(this, batch, pipeline Info); 304 State* state = this->setupPipelineAndShouldDraw(batch, pipelineInfo);
305 if (!state) {
306 return;
307 }
308
309 GrTargetCommands::Cmd* cmd = fCommands.recordDrawBatch(state, batch);
304 this->recordTraceMarkersIfNecessary(cmd); 310 this->recordTraceMarkersIfNecessary(cmd);
305 } 311 }
306 312
307 void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder , 313 void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder ,
308 const GrPathProcessor* pathProc, 314 const GrPathProcessor* pathProc,
309 const GrPath* path, 315 const GrPath* path,
310 const GrScissorState& scissorState, 316 const GrScissorState& scissorState,
311 const GrStencilSettings& stencilSettings ) { 317 const GrStencilSettings& stencilSettings ) {
312 GrTargetCommands::Cmd* cmd = fCommands.recordStencilPath(this, pipelineBuild er, 318 GrTargetCommands::Cmd* cmd = fCommands.recordStencilPath(pipelineBuilder,
313 pathProc, path, sci ssorState, 319 pathProc, path, sci ssorState,
314 stencilSettings); 320 stencilSettings);
315 this->recordTraceMarkersIfNecessary(cmd); 321 this->recordTraceMarkersIfNecessary(cmd);
316 } 322 }
317 323
318 void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc, 324 void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc,
319 const GrPath* path, 325 const GrPath* path,
320 const GrStencilSettings& stencilSettings, 326 const GrStencilSettings& stencilSettings,
321 const PipelineInfo& pipelineInfo) { 327 const PipelineInfo& pipelineInfo) {
322 GrTargetCommands::Cmd* cmd = fCommands.recordDrawPath(this, pathProc, 328 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo);
323 path, stencilSettings, 329 if (!state) {
324 pipelineInfo); 330 return;
331 }
332 GrTargetCommands::Cmd* cmd = fCommands.recordDrawPath(state, pathProc, path, stencilSettings);
325 this->recordTraceMarkersIfNecessary(cmd); 333 this->recordTraceMarkersIfNecessary(cmd);
326 } 334 }
327 335
328 void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc, 336 void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc,
329 const GrPathRange* pathRange, 337 const GrPathRange* pathRange,
330 const void* indices, 338 const void* indices,
331 PathIndexType indexType, 339 PathIndexType indexType,
332 const float transformValues[], 340 const float transformValues[],
333 PathTransformType transformType, 341 PathTransformType transformType,
334 int count, 342 int count,
335 const GrStencilSettings& stencilSettings, 343 const GrStencilSettings& stencilSettings,
336 const PipelineInfo& pipelineInfo) { 344 const PipelineInfo& pipelineInfo) {
337 GrTargetCommands::Cmd* cmd = fCommands.recordDrawPaths(this, pathProc, pathR ange, 345 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo);
346 if (!state) {
347 return;
348 }
349 GrTargetCommands::Cmd* cmd = fCommands.recordDrawPaths(state, this, pathProc , pathRange,
338 indices, indexType, t ransformValues, 350 indices, indexType, t ransformValues,
339 transformType, count, 351 transformType, count,
340 stencilSettings, pipe lineInfo); 352 stencilSettings, pipe lineInfo);
341 this->recordTraceMarkersIfNecessary(cmd); 353 this->recordTraceMarkersIfNecessary(cmd);
342 } 354 }
343 355
344 void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color, 356 void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color,
345 bool canIgnoreRect, GrRenderTarget* renderTarg et) { 357 bool canIgnoreRect, GrRenderTarget* renderTarg et) {
346 GrTargetCommands::Cmd* cmd = fCommands.recordClear(this, rect, color, 358 GrTargetCommands::Cmd* cmd = fCommands.recordClear(rect, color, canIgnoreRec t, renderTarget);
347 canIgnoreRect, renderTarg et);
348 this->recordTraceMarkersIfNecessary(cmd); 359 this->recordTraceMarkersIfNecessary(cmd);
349 } 360 }
350 361
351 void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect, 362 void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect,
352 bool insideClip, 363 bool insideClip,
353 GrRenderTarget* renderTarget) { 364 GrRenderTarget* renderTarget) {
354 GrTargetCommands::Cmd* cmd = fCommands.recordClearStencilClip(this, rect, 365 GrTargetCommands::Cmd* cmd = fCommands.recordClearStencilClip(rect, insideCl ip, renderTarget);
355 insideClip, re nderTarget);
356 this->recordTraceMarkersIfNecessary(cmd); 366 this->recordTraceMarkersIfNecessary(cmd);
357 } 367 }
358 368
359 void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) { 369 void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) {
360 if (!this->caps()->discardRenderTargetSupport()) { 370 if (!this->caps()->discardRenderTargetSupport()) {
361 return; 371 return;
362 } 372 }
363 373
364 GrTargetCommands::Cmd* cmd = fCommands.recordDiscard(this, renderTarget); 374 GrTargetCommands::Cmd* cmd = fCommands.recordDiscard(renderTarget);
365 this->recordTraceMarkersIfNecessary(cmd); 375 this->recordTraceMarkersIfNecessary(cmd);
366 } 376 }
367 377
368 void GrInOrderDrawBuffer::onReset() { 378 void GrInOrderDrawBuffer::onReset() {
369 fCommands.reset(); 379 fCommands.reset();
370 fPathIndexBuffer.rewind(); 380 fPathIndexBuffer.rewind();
371 fPathTransformBuffer.rewind(); 381 fPathTransformBuffer.rewind();
372 fGpuCmdMarkers.reset(); 382 fGpuCmdMarkers.reset();
383
384 fPrevState.reset(NULL);
385 // Note, fPrevState points into fPipelineBuffer's allocation, so we have to reset first.
386 // Furthermore, we have to reset fCommands before fPipelineBuffer too.
387 if (fDrawID % kPipelineBufferHighWaterMark) {
388 fPipelineBuffer.rewind();
389 } else {
390 fPipelineBuffer.reset();
391 }
373 } 392 }
374 393
375 void GrInOrderDrawBuffer::onFlush() { 394 void GrInOrderDrawBuffer::onFlush() {
376 fCommands.flush(this); 395 fCommands.flush(this);
377 ++fDrawID; 396 ++fDrawID;
378 } 397 }
379 398
380 void GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, 399 void GrInOrderDrawBuffer::onCopySurface(GrSurface* dst,
381 GrSurface* src, 400 GrSurface* src,
382 const SkIRect& srcRect, 401 const SkIRect& srcRect,
(...skipping 10 matching lines...) Expand all
393 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); 412 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers();
394 if (activeTraceMarkers.count() > 0) { 413 if (activeTraceMarkers.count() > 0) {
395 if (cmd->isTraced()) { 414 if (cmd->isTraced()) {
396 fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers); 415 fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers);
397 } else { 416 } else {
398 cmd->setMarkerID(fGpuCmdMarkers.count()); 417 cmd->setMarkerID(fGpuCmdMarkers.count());
399 fGpuCmdMarkers.push_back(activeTraceMarkers); 418 fGpuCmdMarkers.push_back(activeTraceMarkers);
400 } 419 }
401 } 420 }
402 } 421 }
422
423 GrTargetCommands::State*
424 GrInOrderDrawBuffer::setupPipelineAndShouldDraw(const GrPrimitiveProcessor* prim Proc,
425 const GrDrawTarget::PipelineInfo & pipelineInfo) {
426 State* state = this->allocState(primProc);
427 this->setupPipeline(pipelineInfo, state->pipelineLocation());
428
429 if (state->getPipeline()->mustSkip()) {
430 this->unallocState(state);
431 return NULL;
432 }
433
434 state->fPrimitiveProcessor->initBatchTracker(&state->fBatchTracker,
435 state->getPipeline()->getInitBa tchTracker());
436
437 if (fPrevState && fPrevState->fPrimitiveProcessor.get() &&
438 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker,
439 *state->fPrimitiveProcesso r,
440 state->fBatchTracker) &&
441 fPrevState->getPipeline()->isEqual(*state->getPipeline())) {
442 this->unallocState(state);
443 } else {
444 fPrevState.reset(state);
445 }
446
447 fCommands.recordXferBarrierIfNecessary(*fPrevState->getPipeline(), this);
448 return fPrevState;
449 }
450
451 GrTargetCommands::State*
452 GrInOrderDrawBuffer::setupPipelineAndShouldDraw(GrBatch* batch,
453 const GrDrawTarget::PipelineInfo & pipelineInfo) {
454 State* state = this->allocState();
455 this->setupPipeline(pipelineInfo, state->pipelineLocation());
456
457 if (state->getPipeline()->mustSkip()) {
458 this->unallocState(state);
459 return NULL;
460 }
461
462 batch->initBatchTracker(state->getPipeline()->getInitBatchTracker());
463
464 if (fPrevState && !fPrevState->fPrimitiveProcessor.get() &&
465 fPrevState->getPipeline()->isEqual(*state->getPipeline())) {
466 this->unallocState(state);
467 } else {
468 fPrevState.reset(state);
469 }
470
471 fCommands.recordXferBarrierIfNecessary(*fPrevState->getPipeline(), this);
472 return fPrevState;
473 }
OLDNEW
« no previous file with comments | « src/gpu/GrInOrderDrawBuffer.h ('k') | src/gpu/GrTargetCommands.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698