OLD | NEW |
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" | |
23 #include "GrStrokeInfo.h" | 22 #include "GrStrokeInfo.h" |
24 #include "GrVertexBuffer.h" | 23 #include "GrVertexBuffer.h" |
25 #include "SkGr.h" | 24 #include "SkGr.h" |
26 #include "gl/GrGLGeometryProcessor.h" | 25 #include "gl/GrGLGeometryProcessor.h" |
27 #include "gl/GrGLProcessor.h" | 26 #include "gl/GrGLProcessor.h" |
28 #include "gl/GrGLSL.h" | 27 #include "gl/GrGLSL.h" |
29 #include "gl/builders/GrGLProgramBuilder.h" | 28 #include "gl/builders/GrGLProgramBuilder.h" |
30 | 29 |
31 /////////////////////////////////////////////////////////////////////////////// | 30 /////////////////////////////////////////////////////////////////////////////// |
32 | 31 |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 draw.fStartOffset = startOffset; | 528 draw.fStartOffset = startOffset; |
530 draw.fDevBloatX = devBloatX; | 529 draw.fDevBloatX = devBloatX; |
531 draw.fDevBloatY = devBloatY; | 530 draw.fDevBloatY = devBloatY; |
532 draw.fHalfDevStroke = halfDevStroke; | 531 draw.fHalfDevStroke = halfDevStroke; |
533 draw.fStrokeWidth = strokeWidth; | 532 draw.fStrokeWidth = strokeWidth; |
534 draw.fHasStartRect = hasStartRect; | 533 draw.fHasStartRect = hasStartRect; |
535 draw.fLineDone = lineDone; | 534 draw.fLineDone = lineDone; |
536 draw.fHasEndRect = hasEndRect; | 535 draw.fHasEndRect = hasEndRect; |
537 } | 536 } |
538 | 537 |
539 SkAutoTUnref<const GrIndexBuffer> indexBuffer( | |
540 batchTarget->resourceProvider()->refQuadIndexBuffer()); | |
541 | |
542 const GrVertexBuffer* vertexBuffer; | 538 const GrVertexBuffer* vertexBuffer; |
543 int firstVertex; | 539 int firstVertex; |
| 540 |
544 size_t vertexStride = gp->getVertexStride(); | 541 size_t vertexStride = gp->getVertexStride(); |
545 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, | 542 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, |
546 totalRectCount * k
VertsPerDash, | 543 totalRectCount * k
VertsPerDash, |
547 &vertexBuffer, | 544 &vertexBuffer, |
548 &firstVertex); | 545 &firstVertex); |
549 if (!vertices || !indexBuffer) { | 546 |
| 547 if (!vertices || !batchTarget->quadIndexBuffer()) { |
550 SkDebugf("Could not allocate buffers\n"); | 548 SkDebugf("Could not allocate buffers\n"); |
551 return; | 549 return; |
552 } | 550 } |
553 | 551 |
554 int curVIdx = 0; | 552 int curVIdx = 0; |
555 int rectIndex = 0; | 553 int rectIndex = 0; |
556 for (int i = 0; i < instanceCount; i++) { | 554 for (int i = 0; i < instanceCount; i++) { |
557 Geometry& args = fGeoData[i]; | 555 Geometry& args = fGeoData[i]; |
558 | 556 |
559 if (!draws[i].fLineDone) { | 557 if (!draws[i].fLineDone) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 } else { | 600 } else { |
603 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); | 601 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); |
604 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); | 602 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
605 setup_dashed_rect_pos(rects[rectIndex], curVIdx, args.fSrcRo
tInv, verts); | 603 setup_dashed_rect_pos(rects[rectIndex], curVIdx, args.fSrcRo
tInv, verts); |
606 } | 604 } |
607 curVIdx += 4; | 605 curVIdx += 4; |
608 } | 606 } |
609 rectIndex++; | 607 rectIndex++; |
610 } | 608 } |
611 | 609 |
| 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(indexBuffer); | 620 drawInfo.setIndexBuffer(dashIndexBuffer); |
621 | 621 |
622 int maxInstancesPerDraw = indexBuffer->maxQuads(); | 622 int maxInstancesPerDraw = dashIndexBuffer->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 Loading... |
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(GrDrawTarget* target, | 764 bool GrDashingEffect::DrawDashLine(GrGpu* gpu, 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 Loading... |
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 |
OLD | NEW |