OLD | NEW |
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 "GrAAHairLinePathRenderer.h" | 8 #include "GrAAHairLinePathRenderer.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 "GrBufferAllocPool.h" | 13 #include "GrBufferAllocPool.h" |
13 #include "GrContext.h" | 14 #include "GrContext.h" |
14 #include "GrDefaultGeoProcFactory.h" | 15 #include "GrDefaultGeoProcFactory.h" |
15 #include "GrDrawTargetCaps.h" | 16 #include "GrDrawTargetCaps.h" |
16 #include "GrGpu.h" | 17 #include "GrGpu.h" |
17 #include "GrIndexBuffer.h" | 18 #include "GrIndexBuffer.h" |
18 #include "GrPathUtils.h" | 19 #include "GrPathUtils.h" |
19 #include "GrPipelineBuilder.h" | 20 #include "GrPipelineBuilder.h" |
20 #include "GrProcessor.h" | 21 #include "GrProcessor.h" |
21 #include "GrVertexBuffer.h" | 22 #include "GrVertexBuffer.h" |
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 info.setIndexCount(kIdxsPerQuad*n); | 1022 info.setIndexCount(kIdxsPerQuad*n); |
1022 batchTarget->draw(info); | 1023 batchTarget->draw(info); |
1023 | 1024 |
1024 conics += n; | 1025 conics += n; |
1025 } | 1026 } |
1026 } | 1027 } |
1027 } | 1028 } |
1028 } | 1029 } |
1029 } | 1030 } |
1030 | 1031 |
| 1032 static GrBatch* create_hairline_batch(GrColor color, |
| 1033 const SkMatrix& viewMatrix, |
| 1034 const SkPath& path, |
| 1035 const GrStrokeInfo& stroke, |
| 1036 const SkIRect& devClipBounds, |
| 1037 const GrIndexBuffer* linesIndexBuffer, |
| 1038 const GrIndexBuffer* quadsIndexBuffer) { |
| 1039 SkScalar hairlineCoverage; |
| 1040 uint8_t newCoverage = 0xff; |
| 1041 if (GrPathRenderer::IsStrokeHairlineOrEquivalent(stroke, viewMatrix, &hairli
neCoverage)) { |
| 1042 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); |
| 1043 } |
| 1044 |
| 1045 AAHairlineBatch::Geometry geometry; |
| 1046 geometry.fColor = color; |
| 1047 geometry.fCoverage = newCoverage; |
| 1048 geometry.fViewMatrix = viewMatrix; |
| 1049 geometry.fPath = path; |
| 1050 geometry.fDevClipBounds = devClipBounds; |
| 1051 |
| 1052 return AAHairlineBatch::Create(geometry, linesIndexBuffer, quadsIndexBuffer)
; |
| 1053 } |
| 1054 |
1031 bool GrAAHairLinePathRenderer::onDrawPath(GrDrawTarget* target, | 1055 bool GrAAHairLinePathRenderer::onDrawPath(GrDrawTarget* target, |
1032 GrPipelineBuilder* pipelineBuilder, | 1056 GrPipelineBuilder* pipelineBuilder, |
1033 GrColor color, | 1057 GrColor color, |
1034 const SkMatrix& viewMatrix, | 1058 const SkMatrix& viewMatrix, |
1035 const SkPath& path, | 1059 const SkPath& path, |
1036 const GrStrokeInfo& stroke, | 1060 const GrStrokeInfo& stroke, |
1037 bool) { | 1061 bool) { |
1038 if (!fLinesIndexBuffer || !fQuadsIndexBuffer) { | 1062 if (!fLinesIndexBuffer || !fQuadsIndexBuffer) { |
1039 SkDebugf("unable to allocate indices\n"); | 1063 SkDebugf("unable to allocate indices\n"); |
1040 return false; | 1064 return false; |
1041 } | 1065 } |
1042 | 1066 |
1043 SkScalar hairlineCoverage; | |
1044 uint8_t newCoverage = 0xff; | |
1045 if (IsStrokeHairlineOrEquivalent(stroke, viewMatrix, &hairlineCoverage)) { | |
1046 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); | |
1047 } | |
1048 | |
1049 SkIRect devClipBounds; | 1067 SkIRect devClipBounds; |
1050 pipelineBuilder->clip().getConservativeBounds(pipelineBuilder->getRenderTarg
et(), | 1068 pipelineBuilder->clip().getConservativeBounds(pipelineBuilder->getRenderTarg
et(), |
1051 &devClipBounds); | 1069 &devClipBounds); |
1052 | 1070 |
1053 AAHairlineBatch::Geometry geometry; | 1071 SkAutoTUnref<GrBatch> batch(create_hairline_batch(color, viewMatrix, path, s
troke, |
1054 geometry.fColor = color; | 1072 devClipBounds, fLinesIndex
Buffer, |
1055 geometry.fCoverage = newCoverage; | 1073 fQuadsIndexBuffer)); |
1056 geometry.fViewMatrix = viewMatrix; | |
1057 geometry.fPath = path; | |
1058 geometry.fDevClipBounds = devClipBounds; | |
1059 | |
1060 SkAutoTUnref<GrBatch> batch(AAHairlineBatch::Create(geometry, fLinesIndexBuf
fer, | |
1061 fQuadsIndexBuffer)); | |
1062 target->drawBatch(pipelineBuilder, batch); | 1074 target->drawBatch(pipelineBuilder, batch); |
1063 | 1075 |
1064 return true; | 1076 return true; |
1065 } | 1077 } |
| 1078 |
| 1079 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 1080 |
| 1081 #ifdef GR_TEST_UTILS |
| 1082 |
| 1083 BATCH_TEST_DEFINE(AAHairlineBatch) { |
| 1084 // TODO put these in the cache |
| 1085 static GrIndexBuffer* gQuadIndexBuffer; |
| 1086 static GrIndexBuffer* gLineIndexBuffer; |
| 1087 if (!gQuadIndexBuffer) { |
| 1088 gQuadIndexBuffer = context->getGpu()->createInstancedIndexBuffer(kQuadId
xBufPattern, |
| 1089 kIdxsPe
rQuad, |
| 1090 kQuadsN
umInIdxBuffer, |
| 1091 kQuadNu
mVertices); |
| 1092 gLineIndexBuffer = context->getGpu()->createInstancedIndexBuffer(kLineSe
gIdxBufPattern, |
| 1093 kIdxsPe
rLineSeg, |
| 1094 kLineSe
gsNumInIdxBuffer, |
| 1095 kLineSe
gNumVertices); |
| 1096 } |
| 1097 |
| 1098 GrColor color = GrRandomColor(random); |
| 1099 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
| 1100 GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle); |
| 1101 SkPath path = GrTest::TestPath(random); |
| 1102 SkIRect devClipBounds; |
| 1103 devClipBounds.setEmpty(); |
| 1104 return create_hairline_batch(color, viewMatrix, path, stroke, devClipBounds,
gLineIndexBuffer, |
| 1105 gQuadIndexBuffer); |
| 1106 } |
| 1107 |
| 1108 #endif |
OLD | NEW |