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

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

Issue 209413006: Make it possible to draw multiple paths at once to a draw target (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address review comment Created 6 years, 9 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/gl/GrGpuGL.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 "GrBufferAllocPool.h" 10 #include "GrBufferAllocPool.h"
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 GrCrash("unknown geom src type"); 379 GrCrash("unknown geom src type");
380 } 380 }
381 draw->fIndexBuffer->ref(); 381 draw->fIndexBuffer->ref();
382 } else { 382 } else {
383 draw->fIndexBuffer = NULL; 383 draw->fIndexBuffer = NULL;
384 } 384 }
385 } 385 }
386 386
387 GrInOrderDrawBuffer::StencilPath::StencilPath() {} 387 GrInOrderDrawBuffer::StencilPath::StencilPath() {}
388 GrInOrderDrawBuffer::DrawPath::DrawPath() {} 388 GrInOrderDrawBuffer::DrawPath::DrawPath() {}
389 GrInOrderDrawBuffer::DrawPaths::DrawPaths() {}
390 GrInOrderDrawBuffer::DrawPaths::~DrawPaths() {
391 if (fTransforms) {
392 SkDELETE_ARRAY(fTransforms);
393 }
394 for (size_t i = 0; i < fPathCount; ++i) {
395 fPaths[i]->unref();
396 }
397 SkDELETE_ARRAY(fPaths);
398 }
389 399
390 void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, SkPath::FillType fil l) { 400 void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, SkPath::FillType fil l) {
391 if (this->needsNewClip()) { 401 if (this->needsNewClip()) {
392 this->recordClip(); 402 this->recordClip();
393 } 403 }
394 // Only compare the subset of GrDrawState relevant to path stenciling? 404 // Only compare the subset of GrDrawState relevant to path stenciling?
395 if (this->needsNewState()) { 405 if (this->needsNewState()) {
396 this->recordState(); 406 this->recordState();
397 } 407 }
398 StencilPath* sp = this->recordStencilPath(); 408 StencilPath* sp = this->recordStencilPath();
(...skipping 13 matching lines...) Expand all
412 } 422 }
413 DrawPath* cp = this->recordDrawPath(); 423 DrawPath* cp = this->recordDrawPath();
414 cp->fPath.reset(path); 424 cp->fPath.reset(path);
415 path->ref(); 425 path->ref();
416 cp->fFill = fill; 426 cp->fFill = fill;
417 if (NULL != dstCopy) { 427 if (NULL != dstCopy) {
418 cp->fDstCopy = *dstCopy; 428 cp->fDstCopy = *dstCopy;
419 } 429 }
420 } 430 }
421 431
432 void GrInOrderDrawBuffer::onDrawPaths(size_t pathCount, const GrPath** paths,
433 const SkMatrix* transforms,
434 SkPath::FillType fill,
435 SkStrokeRec::Style stroke,
436 const GrDeviceCoordTexture* dstCopy) {
437 SkASSERT(pathCount);
438
439 if (this->needsNewClip()) {
440 this->recordClip();
441 }
442 if (this->needsNewState()) {
443 this->recordState();
444 }
445 DrawPaths* dp = this->recordDrawPaths();
446 dp->fPathCount = pathCount;
447 dp->fPaths = SkNEW_ARRAY(const GrPath*, pathCount);
448 memcpy(dp->fPaths, paths, sizeof(GrPath*) * pathCount);
449 for (size_t i = 0; i < pathCount; ++i) {
450 dp->fPaths[i]->ref();
451 }
452
453 dp->fTransforms = SkNEW_ARRAY(SkMatrix, pathCount);
454 memcpy(dp->fTransforms, transforms, sizeof(SkMatrix) * pathCount);
455
456 dp->fFill = fill;
457 dp->fStroke = stroke;
458
459 if (NULL != dstCopy) {
460 dp->fDstCopy = *dstCopy;
461 }
462 }
463
422 void GrInOrderDrawBuffer::clear(const SkIRect* rect, GrColor color, 464 void GrInOrderDrawBuffer::clear(const SkIRect* rect, GrColor color,
423 bool canIgnoreRect, GrRenderTarget* renderTarget ) { 465 bool canIgnoreRect, GrRenderTarget* renderTarget ) {
424 SkIRect r; 466 SkIRect r;
425 if (NULL == renderTarget) { 467 if (NULL == renderTarget) {
426 renderTarget = this->drawState()->getRenderTarget(); 468 renderTarget = this->drawState()->getRenderTarget();
427 SkASSERT(NULL != renderTarget); 469 SkASSERT(NULL != renderTarget);
428 } 470 }
429 if (NULL == rect) { 471 if (NULL == rect) {
430 // We could do something smart and remove previous draws and clears to 472 // We could do something smart and remove previous draws and clears to
431 // the current render target. If we get that smart we have to make sure 473 // the current render target. If we get that smart we have to make sure
(...skipping 28 matching lines...) Expand all
460 int numDraws = fDraws.count(); 502 int numDraws = fDraws.count();
461 for (int d = 0; d < numDraws; ++d) { 503 for (int d = 0; d < numDraws; ++d) {
462 // we always have a VB, but not always an IB 504 // we always have a VB, but not always an IB
463 SkASSERT(NULL != fDraws[d].fVertexBuffer); 505 SkASSERT(NULL != fDraws[d].fVertexBuffer);
464 fDraws[d].fVertexBuffer->unref(); 506 fDraws[d].fVertexBuffer->unref();
465 SkSafeUnref(fDraws[d].fIndexBuffer); 507 SkSafeUnref(fDraws[d].fIndexBuffer);
466 } 508 }
467 fCmds.reset(); 509 fCmds.reset();
468 fDraws.reset(); 510 fDraws.reset();
469 fStencilPaths.reset(); 511 fStencilPaths.reset();
512 fDrawPath.reset();
470 fDrawPaths.reset(); 513 fDrawPaths.reset();
471 fStates.reset(); 514 fStates.reset();
472 fClears.reset(); 515 fClears.reset();
473 fVertexPool.reset(); 516 fVertexPool.reset();
474 fIndexPool.reset(); 517 fIndexPool.reset();
475 fClips.reset(); 518 fClips.reset();
476 fClipOrigins.reset(); 519 fClipOrigins.reset();
477 fCopySurfaces.reset(); 520 fCopySurfaces.reset();
478 fClipSet = true; 521 fClipSet = true;
479 } 522 }
(...skipping 26 matching lines...) Expand all
506 fDstGpu->setDrawState(&playbackState); 549 fDstGpu->setDrawState(&playbackState);
507 550
508 GrClipData clipData; 551 GrClipData clipData;
509 552
510 int currState = 0; 553 int currState = 0;
511 int currClip = 0; 554 int currClip = 0;
512 int currClear = 0; 555 int currClear = 0;
513 int currDraw = 0; 556 int currDraw = 0;
514 int currStencilPath = 0; 557 int currStencilPath = 0;
515 int currDrawPath = 0; 558 int currDrawPath = 0;
559 int currDrawPaths = 0;
516 int currCopySurface = 0; 560 int currCopySurface = 0;
517 561
518 for (int c = 0; c < numCmds; ++c) { 562 for (int c = 0; c < numCmds; ++c) {
519 switch (fCmds[c]) { 563 switch (fCmds[c]) {
520 case kDraw_Cmd: { 564 case kDraw_Cmd: {
521 const DrawRecord& draw = fDraws[currDraw]; 565 const DrawRecord& draw = fDraws[currDraw];
522 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer); 566 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer);
523 if (draw.isIndexed()) { 567 if (draw.isIndexed()) {
524 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer); 568 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer);
525 } 569 }
526 fDstGpu->executeDraw(draw); 570 fDstGpu->executeDraw(draw);
527 571
528 ++currDraw; 572 ++currDraw;
529 break; 573 break;
530 } 574 }
531 case kStencilPath_Cmd: { 575 case kStencilPath_Cmd: {
532 const StencilPath& sp = fStencilPaths[currStencilPath]; 576 const StencilPath& sp = fStencilPaths[currStencilPath];
533 fDstGpu->stencilPath(sp.fPath.get(), sp.fFill); 577 fDstGpu->stencilPath(sp.fPath.get(), sp.fFill);
534 ++currStencilPath; 578 ++currStencilPath;
535 break; 579 break;
536 } 580 }
537 case kDrawPath_Cmd: { 581 case kDrawPath_Cmd: {
538 const DrawPath& cp = fDrawPaths[currDrawPath]; 582 const DrawPath& cp = fDrawPath[currDrawPath];
539 fDstGpu->executeDrawPath(cp.fPath.get(), cp.fFill, 583 fDstGpu->executeDrawPath(cp.fPath.get(), cp.fFill,
540 NULL != cp.fDstCopy.texture() ? &cp.fDs tCopy : NULL); 584 NULL != cp.fDstCopy.texture() ? &cp.fDs tCopy : NULL);
541 ++currDrawPath; 585 ++currDrawPath;
542 break; 586 break;
543 } 587 }
588 case kDrawPaths_Cmd: {
589 DrawPaths& dp = fDrawPaths[currDrawPaths];
590 const GrDeviceCoordTexture* dstCopy =
591 NULL != dp.fDstCopy.texture() ? &dp.fDstCopy : NULL;
592 fDstGpu->executeDrawPaths(dp.fPathCount, dp.fPaths,
593 dp.fTransforms, dp.fFill, dp.fStroke,
594 dstCopy);
595 ++currDrawPaths;
596 break;
597 }
544 case kSetState_Cmd: 598 case kSetState_Cmd:
545 fStates[currState].restoreTo(&playbackState); 599 fStates[currState].restoreTo(&playbackState);
546 ++currState; 600 ++currState;
547 break; 601 break;
548 case kSetClip_Cmd: 602 case kSetClip_Cmd:
549 clipData.fClipStack = &fClips[currClip]; 603 clipData.fClipStack = &fClips[currClip];
550 clipData.fOrigin = fClipOrigins[currClip]; 604 clipData.fOrigin = fClipOrigins[currClip];
551 fDstGpu->setClip(&clipData); 605 fDstGpu->setClip(&clipData);
552 ++currClip; 606 ++currClip;
553 break; 607 break;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 return &fDraws.push_back(info); 900 return &fDraws.push_back(info);
847 } 901 }
848 902
849 GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { 903 GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() {
850 fCmds.push_back(kStencilPath_Cmd); 904 fCmds.push_back(kStencilPath_Cmd);
851 return &fStencilPaths.push_back(); 905 return &fStencilPaths.push_back();
852 } 906 }
853 907
854 GrInOrderDrawBuffer::DrawPath* GrInOrderDrawBuffer::recordDrawPath() { 908 GrInOrderDrawBuffer::DrawPath* GrInOrderDrawBuffer::recordDrawPath() {
855 fCmds.push_back(kDrawPath_Cmd); 909 fCmds.push_back(kDrawPath_Cmd);
910 return &fDrawPath.push_back();
911 }
912
913 GrInOrderDrawBuffer::DrawPaths* GrInOrderDrawBuffer::recordDrawPaths() {
914 fCmds.push_back(kDrawPaths_Cmd);
856 return &fDrawPaths.push_back(); 915 return &fDrawPaths.push_back();
857 } 916 }
858 917
859 GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { 918 GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() {
860 fCmds.push_back(kClear_Cmd); 919 fCmds.push_back(kClear_Cmd);
861 return &fClears.push_back(); 920 return &fClears.push_back();
862 } 921 }
863 922
864 GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() { 923 GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() {
865 fCmds.push_back(kCopySurface_Cmd); 924 fCmds.push_back(kCopySurface_Cmd);
866 return &fCopySurfaces.push_back(); 925 return &fCopySurfaces.push_back();
867 } 926 }
868 927
869 928
870 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { 929 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) {
871 INHERITED::clipWillBeSet(newClipData); 930 INHERITED::clipWillBeSet(newClipData);
872 fClipSet = true; 931 fClipSet = true;
873 fClipProxyState = kUnknown_ClipProxyState; 932 fClipProxyState = kUnknown_ClipProxyState;
874 } 933 }
OLDNEW
« no previous file with comments | « src/gpu/GrInOrderDrawBuffer.h ('k') | src/gpu/gl/GrGpuGL.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698