| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrAARectRenderer.h" | 9 #include "GrAARectRenderer.h" |
| 10 #include "GrAtlasTextContext.h" | 10 #include "GrAtlasTextContext.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 void GrDrawContext::drawPaths(GrPipelineBuilder* pipelineBuilder, | 110 void GrDrawContext::drawPaths(GrPipelineBuilder* pipelineBuilder, |
| 111 const GrPathProcessor* pathProc, | 111 const GrPathProcessor* pathProc, |
| 112 const GrPathRange* pathRange, | 112 const GrPathRange* pathRange, |
| 113 const void* indices, | 113 const void* indices, |
| 114 int /*GrDrawTarget::PathIndexType*/ indexType, | 114 int /*GrDrawTarget::PathIndexType*/ indexType, |
| 115 const float transformValues[], | 115 const float transformValues[], |
| 116 int /*GrDrawTarget::PathTransformType*/ transformT
ype, | 116 int /*GrDrawTarget::PathTransformType*/ transformT
ype, |
| 117 int count, | 117 int count, |
| 118 int /*GrPathRendering::FillType*/ fill) { | 118 int /*GrPathRendering::FillType*/ fill) { |
| 119 fDrawTarget->drawPaths(pipelineBuilder, pathProc, pathRange, | 119 fDrawTarget->drawPaths(*pipelineBuilder, pathProc, pathRange, |
| 120 indices, (GrDrawTarget::PathIndexType) indexType, | 120 indices, (GrDrawTarget::PathIndexType) indexType, |
| 121 transformValues, | 121 transformValues, |
| 122 (GrDrawTarget::PathTransformType) transformType, | 122 (GrDrawTarget::PathTransformType) transformType, |
| 123 count, (GrPathRendering::FillType) fill); | 123 count, (GrPathRendering::FillType) fill); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void GrDrawContext::discard(GrRenderTarget* renderTarget) { | 126 void GrDrawContext::discard(GrRenderTarget* renderTarget) { |
| 127 RETURN_IF_ABANDONED | 127 RETURN_IF_ABANDONED |
| 128 SkASSERT(renderTarget); | 128 SkASSERT(renderTarget); |
| 129 AutoCheckFlush acf(fContext); | 129 AutoCheckFlush acf(fContext); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 SkDebugf("Could not invert matrix\n"); | 185 SkDebugf("Could not invert matrix\n"); |
| 186 return; | 186 return; |
| 187 } | 187 } |
| 188 | 188 |
| 189 AutoCheckFlush acf(fContext); | 189 AutoCheckFlush acf(fContext); |
| 190 if (!this->prepareToDraw(rt)) { | 190 if (!this->prepareToDraw(rt)) { |
| 191 return; | 191 return; |
| 192 } | 192 } |
| 193 | 193 |
| 194 GrPipelineBuilder pipelineBuilder(*paint, rt, clip); | 194 GrPipelineBuilder pipelineBuilder(*paint, rt, clip); |
| 195 fDrawTarget->drawBWRect(&pipelineBuilder, | 195 fDrawTarget->drawBWRect(pipelineBuilder, |
| 196 paint->getColor(), | 196 paint->getColor(), |
| 197 SkMatrix::I(), | 197 SkMatrix::I(), |
| 198 r, | 198 r, |
| 199 NULL, | 199 NULL, |
| 200 &localMatrix); | 200 &localMatrix); |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 | 203 |
| 204 static inline bool is_irect(const SkRect& r) { | 204 static inline bool is_irect(const SkRect& r) { |
| 205 return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) && | 205 return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) && |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 GrColor color = paint.getColor(); | 480 GrColor color = paint.getColor(); |
| 481 SkRect devBoundRect; | 481 SkRect devBoundRect; |
| 482 bool needAA = paint.isAntiAlias() && | 482 bool needAA = paint.isAntiAlias() && |
| 483 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); | 483 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); |
| 484 bool doAA = needAA && apply_aa_to_rect(fDrawTarget, &pipelineBuilder, &devBo
undRect, rect, | 484 bool doAA = needAA && apply_aa_to_rect(fDrawTarget, &pipelineBuilder, &devBo
undRect, rect, |
| 485 width, viewMatrix, color); | 485 width, viewMatrix, color); |
| 486 | 486 |
| 487 if (doAA) { | 487 if (doAA) { |
| 488 if (width >= 0) { | 488 if (width >= 0) { |
| 489 GrAARectRenderer::StrokeAARect(fDrawTarget, | 489 GrAARectRenderer::StrokeAARect(fDrawTarget, |
| 490 &pipelineBuilder, | 490 pipelineBuilder, |
| 491 color, | 491 color, |
| 492 viewMatrix, | 492 viewMatrix, |
| 493 rect, | 493 rect, |
| 494 devBoundRect, | 494 devBoundRect, |
| 495 *strokeInfo); | 495 *strokeInfo); |
| 496 } else { | 496 } else { |
| 497 // filled AA rect | 497 // filled AA rect |
| 498 GrAARectRenderer::FillAARect(fDrawTarget, | 498 GrAARectRenderer::FillAARect(fDrawTarget, |
| 499 &pipelineBuilder, | 499 pipelineBuilder, |
| 500 color, | 500 color, |
| 501 viewMatrix, | 501 viewMatrix, |
| 502 rect, | 502 rect, |
| 503 devBoundRect); | 503 devBoundRect); |
| 504 } | 504 } |
| 505 return; | 505 return; |
| 506 } | 506 } |
| 507 | 507 |
| 508 if (width >= 0) { | 508 if (width >= 0) { |
| 509 StrokeRectBatch::Geometry geometry; | 509 StrokeRectBatch::Geometry geometry; |
| 510 geometry.fViewMatrix = viewMatrix; | 510 geometry.fViewMatrix = viewMatrix; |
| 511 geometry.fColor = color; | 511 geometry.fColor = color; |
| 512 geometry.fRect = rect; | 512 geometry.fRect = rect; |
| 513 geometry.fStrokeWidth = width; | 513 geometry.fStrokeWidth = width; |
| 514 | 514 |
| 515 // Non-AA hairlines are snapped to pixel centers to make which pixels ar
e hit deterministic | 515 // Non-AA hairlines are snapped to pixel centers to make which pixels ar
e hit deterministic |
| 516 bool snapToPixelCenters = (0 == width && !rt->isUnifiedMultisampled()); | 516 bool snapToPixelCenters = (0 == width && !rt->isUnifiedMultisampled()); |
| 517 SkAutoTUnref<GrBatch> batch(StrokeRectBatch::Create(geometry, snapToPixe
lCenters)); | 517 SkAutoTUnref<GrBatch> batch(StrokeRectBatch::Create(geometry, snapToPixe
lCenters)); |
| 518 | 518 |
| 519 // Depending on sub-pixel coordinates and the particular GPU, we may los
e a corner of | 519 // Depending on sub-pixel coordinates and the particular GPU, we may los
e a corner of |
| 520 // hairline rects. We jam all the vertices to pixel centers to avoid thi
s, but not when MSAA | 520 // hairline rects. We jam all the vertices to pixel centers to avoid thi
s, but not when MSAA |
| 521 // is enabled because it can cause ugly artifacts. | 521 // is enabled because it can cause ugly artifacts. |
| 522 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_
Flag, | 522 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_
Flag, |
| 523 snapToPixelCenters); | 523 snapToPixelCenters); |
| 524 fDrawTarget->drawBatch(&pipelineBuilder, batch); | 524 fDrawTarget->drawBatch(pipelineBuilder, batch); |
| 525 } else { | 525 } else { |
| 526 // filled BW rect | 526 // filled BW rect |
| 527 fDrawTarget->drawSimpleRect(&pipelineBuilder, color, viewMatrix, rect); | 527 fDrawTarget->drawSimpleRect(pipelineBuilder, color, viewMatrix, rect); |
| 528 } | 528 } |
| 529 } | 529 } |
| 530 | 530 |
| 531 void GrDrawContext::drawNonAARectToRect(GrRenderTarget* rt, | 531 void GrDrawContext::drawNonAARectToRect(GrRenderTarget* rt, |
| 532 const GrClip& clip, | 532 const GrClip& clip, |
| 533 const GrPaint& paint, | 533 const GrPaint& paint, |
| 534 const SkMatrix& viewMatrix, | 534 const SkMatrix& viewMatrix, |
| 535 const SkRect& rectToDraw, | 535 const SkRect& rectToDraw, |
| 536 const SkRect& localRect, | 536 const SkRect& localRect, |
| 537 const SkMatrix* localMatrix) { | 537 const SkMatrix* localMatrix) { |
| 538 RETURN_IF_ABANDONED | 538 RETURN_IF_ABANDONED |
| 539 AutoCheckFlush acf(fContext); | 539 AutoCheckFlush acf(fContext); |
| 540 if (!this->prepareToDraw(rt)) { | 540 if (!this->prepareToDraw(rt)) { |
| 541 return; | 541 return; |
| 542 } | 542 } |
| 543 | 543 |
| 544 GrPipelineBuilder pipelineBuilder(paint, rt, clip); | 544 GrPipelineBuilder pipelineBuilder(paint, rt, clip); |
| 545 fDrawTarget->drawBWRect(&pipelineBuilder, | 545 fDrawTarget->drawBWRect(pipelineBuilder, |
| 546 paint.getColor(), | 546 paint.getColor(), |
| 547 viewMatrix, | 547 viewMatrix, |
| 548 rectToDraw, | 548 rectToDraw, |
| 549 &localRect, | 549 &localRect, |
| 550 localMatrix); | 550 localMatrix); |
| 551 } | 551 } |
| 552 | 552 |
| 553 static const GrGeometryProcessor* set_vertex_attributes(bool hasLocalCoords, | 553 static const GrGeometryProcessor* set_vertex_attributes(bool hasLocalCoords, |
| 554 bool hasColors, | 554 bool hasColors, |
| 555 int* colorOffset, | 555 int* colorOffset, |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 bounds.outset(0.5f, 0.5f); | 854 bounds.outset(0.5f, 0.5f); |
| 855 } | 855 } |
| 856 | 856 |
| 857 DrawVerticesBatch::Geometry geometry; | 857 DrawVerticesBatch::Geometry geometry; |
| 858 geometry.fColor = paint.getColor(); | 858 geometry.fColor = paint.getColor(); |
| 859 SkAutoTUnref<GrBatch> batch(DrawVerticesBatch::Create(geometry, primitiveTyp
e, viewMatrix, | 859 SkAutoTUnref<GrBatch> batch(DrawVerticesBatch::Create(geometry, primitiveTyp
e, viewMatrix, |
| 860 positions, vertexCount
, indices, | 860 positions, vertexCount
, indices, |
| 861 indexCount, colors, te
xCoords, | 861 indexCount, colors, te
xCoords, |
| 862 bounds)); | 862 bounds)); |
| 863 | 863 |
| 864 fDrawTarget->drawBatch(&pipelineBuilder, batch); | 864 fDrawTarget->drawBatch(pipelineBuilder, batch); |
| 865 } | 865 } |
| 866 | 866 |
| 867 /////////////////////////////////////////////////////////////////////////////// | 867 /////////////////////////////////////////////////////////////////////////////// |
| 868 | 868 |
| 869 void GrDrawContext::drawRRect(GrRenderTarget*rt, | 869 void GrDrawContext::drawRRect(GrRenderTarget*rt, |
| 870 const GrClip& clip, | 870 const GrClip& clip, |
| 871 const GrPaint& paint, | 871 const GrPaint& paint, |
| 872 const SkMatrix& viewMatrix, | 872 const SkMatrix& viewMatrix, |
| 873 const SkRRect& rrect, | 873 const SkRRect& rrect, |
| 874 const GrStrokeInfo& strokeInfo) { | 874 const GrStrokeInfo& strokeInfo) { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 GrPipelineBuilder pipelineBuilder(paint, rt, clip); | 1068 GrPipelineBuilder pipelineBuilder(paint, rt, clip); |
| 1069 if (!strokeInfo.isDashed()) { | 1069 if (!strokeInfo.isDashed()) { |
| 1070 bool useCoverageAA = paint.isAntiAlias() && | 1070 bool useCoverageAA = paint.isAntiAlias() && |
| 1071 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); | 1071 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); |
| 1072 | 1072 |
| 1073 if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) { | 1073 if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) { |
| 1074 // Concave AA paths are expensive - try to avoid them for special ca
ses | 1074 // Concave AA paths are expensive - try to avoid them for special ca
ses |
| 1075 SkRect rects[2]; | 1075 SkRect rects[2]; |
| 1076 | 1076 |
| 1077 if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) { | 1077 if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) { |
| 1078 GrAARectRenderer::FillAANestedRects(fDrawTarget, &pipelineBuilde
r, color, | 1078 GrAARectRenderer::FillAANestedRects(fDrawTarget, pipelineBuilder
, color, |
| 1079 viewMatrix, rects); | 1079 viewMatrix, rects); |
| 1080 return; | 1080 return; |
| 1081 } | 1081 } |
| 1082 } | 1082 } |
| 1083 SkRect ovalRect; | 1083 SkRect ovalRect; |
| 1084 bool isOval = path.isOval(&ovalRect); | 1084 bool isOval = path.isOval(&ovalRect); |
| 1085 | 1085 |
| 1086 if (isOval && !path.isInverseFillType()) { | 1086 if (isOval && !path.isInverseFillType()) { |
| 1087 if (GrOvalRenderer::DrawOval(fDrawTarget, | 1087 if (GrOvalRenderer::DrawOval(fDrawTarget, |
| 1088 &pipelineBuilder, | 1088 &pipelineBuilder, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 | 1181 |
| 1182 bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) { | 1182 bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) { |
| 1183 RETURN_FALSE_IF_ABANDONED | 1183 RETURN_FALSE_IF_ABANDONED |
| 1184 | 1184 |
| 1185 ASSERT_OWNED_RESOURCE(rt); | 1185 ASSERT_OWNED_RESOURCE(rt); |
| 1186 SkASSERT(rt); | 1186 SkASSERT(rt); |
| 1187 return true; | 1187 return true; |
| 1188 } | 1188 } |
| 1189 | 1189 |
| 1190 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrBatch* batch
) { | 1190 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrBatch* batch
) { |
| 1191 fDrawTarget->drawBatch(pipelineBuilder, batch); | 1191 fDrawTarget->drawBatch(*pipelineBuilder, batch); |
| 1192 } | 1192 } |
| 1193 | 1193 |
| 1194 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 1194 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 1195 | 1195 |
| 1196 #ifdef GR_TEST_UTILS | 1196 #ifdef GR_TEST_UTILS |
| 1197 | 1197 |
| 1198 BATCH_TEST_DEFINE(StrokeRectBatch) { | 1198 BATCH_TEST_DEFINE(StrokeRectBatch) { |
| 1199 StrokeRectBatch::Geometry geometry; | 1199 StrokeRectBatch::Geometry geometry; |
| 1200 geometry.fViewMatrix = GrTest::TestMatrix(random); | 1200 geometry.fViewMatrix = GrTest::TestMatrix(random); |
| 1201 geometry.fColor = GrRandomColor(random); | 1201 geometry.fColor = GrRandomColor(random); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 return DrawVerticesBatch::Create(geometry, type, viewMatrix, | 1311 return DrawVerticesBatch::Create(geometry, type, viewMatrix, |
| 1312 positions.begin(), vertexCount, | 1312 positions.begin(), vertexCount, |
| 1313 indices.begin(), hasIndices ? vertexCount :
0, | 1313 indices.begin(), hasIndices ? vertexCount :
0, |
| 1314 colors.begin(), | 1314 colors.begin(), |
| 1315 texCoords.begin(), | 1315 texCoords.begin(), |
| 1316 bounds); | 1316 bounds); |
| 1317 } | 1317 } |
| 1318 | 1318 |
| 1319 #endif | 1319 #endif |
| 1320 | 1320 |
| OLD | NEW |