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

Side by Side Diff: src/gpu/effects/GrDashingEffect.cpp

Issue 1116943004: Move instanced index buffer creation to flush time (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix missing assignment of keys to index buffers 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/effects/GrDashingEffect.h ('k') | no next file » | 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 2014 Google Inc. 2 * Copyright 2014 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 "GrDashingEffect.h" 8 #include "GrDashingEffect.h"
9 9
10 #include "GrBatch.h" 10 #include "GrBatch.h"
11 #include "GrBatchTarget.h" 11 #include "GrBatchTarget.h"
12 #include "GrBatchTest.h" 12 #include "GrBatchTest.h"
13 #include "GrBufferAllocPool.h" 13 #include "GrBufferAllocPool.h"
14 #include "GrGeometryProcessor.h" 14 #include "GrGeometryProcessor.h"
15 #include "GrContext.h" 15 #include "GrContext.h"
16 #include "GrCoordTransform.h" 16 #include "GrCoordTransform.h"
17 #include "GrDefaultGeoProcFactory.h" 17 #include "GrDefaultGeoProcFactory.h"
18 #include "GrDrawTarget.h" 18 #include "GrDrawTarget.h"
19 #include "GrDrawTargetCaps.h" 19 #include "GrDrawTargetCaps.h"
20 #include "GrInvariantOutput.h" 20 #include "GrInvariantOutput.h"
21 #include "GrProcessor.h" 21 #include "GrProcessor.h"
22 #include "GrResourceProvider.h"
22 #include "GrStrokeInfo.h" 23 #include "GrStrokeInfo.h"
23 #include "GrVertexBuffer.h" 24 #include "GrVertexBuffer.h"
24 #include "SkGr.h" 25 #include "SkGr.h"
25 #include "gl/GrGLGeometryProcessor.h" 26 #include "gl/GrGLGeometryProcessor.h"
26 #include "gl/GrGLProcessor.h" 27 #include "gl/GrGLProcessor.h"
27 #include "gl/GrGLSL.h" 28 #include "gl/GrGLSL.h"
28 #include "gl/builders/GrGLProgramBuilder.h" 29 #include "gl/builders/GrGLProgramBuilder.h"
29 30
30 /////////////////////////////////////////////////////////////////////////////// 31 ///////////////////////////////////////////////////////////////////////////////
31 32
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 draw.fStartOffset = startOffset; 529 draw.fStartOffset = startOffset;
529 draw.fDevBloatX = devBloatX; 530 draw.fDevBloatX = devBloatX;
530 draw.fDevBloatY = devBloatY; 531 draw.fDevBloatY = devBloatY;
531 draw.fHalfDevStroke = halfDevStroke; 532 draw.fHalfDevStroke = halfDevStroke;
532 draw.fStrokeWidth = strokeWidth; 533 draw.fStrokeWidth = strokeWidth;
533 draw.fHasStartRect = hasStartRect; 534 draw.fHasStartRect = hasStartRect;
534 draw.fLineDone = lineDone; 535 draw.fLineDone = lineDone;
535 draw.fHasEndRect = hasEndRect; 536 draw.fHasEndRect = hasEndRect;
536 } 537 }
537 538
539 SkAutoTUnref<const GrIndexBuffer> indexBuffer(
540 batchTarget->resourceProvider()->refQuadIndexBuffer());
541
538 const GrVertexBuffer* vertexBuffer; 542 const GrVertexBuffer* vertexBuffer;
539 int firstVertex; 543 int firstVertex;
540
541 size_t vertexStride = gp->getVertexStride(); 544 size_t vertexStride = gp->getVertexStride();
542 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, 545 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride,
543 totalRectCount * k VertsPerDash, 546 totalRectCount * k VertsPerDash,
544 &vertexBuffer, 547 &vertexBuffer,
545 &firstVertex); 548 &firstVertex);
546 549 if (!vertices || !indexBuffer) {
547 if (!vertices || !batchTarget->quadIndexBuffer()) {
548 SkDebugf("Could not allocate buffers\n"); 550 SkDebugf("Could not allocate buffers\n");
549 return; 551 return;
550 } 552 }
551 553
552 int curVIdx = 0; 554 int curVIdx = 0;
553 int rectIndex = 0; 555 int rectIndex = 0;
554 for (int i = 0; i < instanceCount; i++) { 556 for (int i = 0; i < instanceCount; i++) {
555 Geometry& args = fGeoData[i]; 557 Geometry& args = fGeoData[i];
556 558
557 if (!draws[i].fLineDone) { 559 if (!draws[i].fLineDone) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 } else { 602 } else {
601 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); 603 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices);
602 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); 604 SkASSERT(gp->getVertexStride() == sizeof(SkPoint));
603 setup_dashed_rect_pos(rects[rectIndex], curVIdx, args.fSrcRo tInv, verts); 605 setup_dashed_rect_pos(rects[rectIndex], curVIdx, args.fSrcRo tInv, verts);
604 } 606 }
605 curVIdx += 4; 607 curVIdx += 4;
606 } 608 }
607 rectIndex++; 609 rectIndex++;
608 } 610 }
609 611
610 const GrIndexBuffer* dashIndexBuffer = batchTarget->quadIndexBuffer();
611
612 GrDrawTarget::DrawInfo drawInfo; 612 GrDrawTarget::DrawInfo drawInfo;
613 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); 613 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType);
614 drawInfo.setStartVertex(0); 614 drawInfo.setStartVertex(0);
615 drawInfo.setStartIndex(0); 615 drawInfo.setStartIndex(0);
616 drawInfo.setVerticesPerInstance(kVertsPerDash); 616 drawInfo.setVerticesPerInstance(kVertsPerDash);
617 drawInfo.setIndicesPerInstance(kIndicesPerDash); 617 drawInfo.setIndicesPerInstance(kIndicesPerDash);
618 drawInfo.adjustStartVertex(firstVertex); 618 drawInfo.adjustStartVertex(firstVertex);
619 drawInfo.setVertexBuffer(vertexBuffer); 619 drawInfo.setVertexBuffer(vertexBuffer);
620 drawInfo.setIndexBuffer(dashIndexBuffer); 620 drawInfo.setIndexBuffer(indexBuffer);
621 621
622 int maxInstancesPerDraw = dashIndexBuffer->maxQuads(); 622 int maxInstancesPerDraw = indexBuffer->maxQuads();
623 while (totalRectCount) { 623 while (totalRectCount) {
624 drawInfo.setInstanceCount(SkTMin(totalRectCount, maxInstancesPerDraw )); 624 drawInfo.setInstanceCount(SkTMin(totalRectCount, maxInstancesPerDraw ));
625 drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.vertices PerInstance()); 625 drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.vertices PerInstance());
626 drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPe rInstance()); 626 drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPe rInstance());
627 627
628 batchTarget->draw(drawInfo); 628 batchTarget->draw(drawInfo);
629 629
630 drawInfo.setStartVertex(drawInfo.startVertex() + drawInfo.vertexCoun t()); 630 drawInfo.setStartVertex(drawInfo.startVertex() + drawInfo.vertexCoun t());
631 totalRectCount -= drawInfo.instanceCount(); 631 totalRectCount -= drawInfo.instanceCount();
632 } 632 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 754
755 geometry.fColor = color; 755 geometry.fColor = color;
756 geometry.fViewMatrix = viewMatrix; 756 geometry.fViewMatrix = viewMatrix;
757 geometry.fPhase = info.fPhase; 757 geometry.fPhase = info.fPhase;
758 geometry.fIntervals[0] = info.fIntervals[0]; 758 geometry.fIntervals[0] = info.fIntervals[0];
759 geometry.fIntervals[1] = info.fIntervals[1]; 759 geometry.fIntervals[1] = info.fIntervals[1];
760 760
761 return DashBatch::Create(geometry, cap, aaMode, fullDash); 761 return DashBatch::Create(geometry, cap, aaMode, fullDash);
762 } 762 }
763 763
764 bool GrDashingEffect::DrawDashLine(GrGpu* gpu, GrDrawTarget* target, 764 bool GrDashingEffect::DrawDashLine(GrDrawTarget* target,
765 GrPipelineBuilder* pipelineBuilder, GrColor c olor, 765 GrPipelineBuilder* pipelineBuilder, GrColor c olor,
766 const SkMatrix& viewMatrix, const SkPoint pts [2], 766 const SkMatrix& viewMatrix, const SkPoint pts [2],
767 bool useAA, const GrStrokeInfo& strokeInfo) { 767 bool useAA, const GrStrokeInfo& strokeInfo) {
768 SkAutoTUnref<GrBatch> batch(create_batch(color, viewMatrix, pts, useAA, stro keInfo, 768 SkAutoTUnref<GrBatch> batch(create_batch(color, viewMatrix, pts, useAA, stro keInfo,
769 pipelineBuilder->getRenderTarget()- >isMultisampled())); 769 pipelineBuilder->getRenderTarget()- >isMultisampled()));
770 if (!batch) { 770 if (!batch) {
771 return false; 771 return false;
772 } 772 }
773 773
774 target->drawBatch(pipelineBuilder, batch); 774 target->drawBatch(pipelineBuilder, batch);
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 info.fIntervals = intervals; 1372 info.fIntervals = intervals;
1373 info.fCount = 2; 1373 info.fCount = 2;
1374 info.fPhase = phase; 1374 info.fPhase = phase;
1375 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); 1375 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info);
1376 SkASSERT(success); 1376 SkASSERT(success);
1377 1377
1378 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); 1378 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT);
1379 } 1379 }
1380 1380
1381 #endif 1381 #endif
OLDNEW
« no previous file with comments | « src/gpu/effects/GrDashingEffect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698