| 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 "GrBatch.h" | 10 #include "GrBatch.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom); | 149 SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom); |
| 150 } | 150 } |
| 151 | 151 |
| 152 static bool apply_aa_to_rect(GrDrawTarget* target, | 152 static bool apply_aa_to_rect(GrDrawTarget* target, |
| 153 GrPipelineBuilder* pipelineBuilder, | 153 GrPipelineBuilder* pipelineBuilder, |
| 154 SkRect* devBoundRect, | 154 SkRect* devBoundRect, |
| 155 const SkRect& rect, | 155 const SkRect& rect, |
| 156 SkScalar strokeWidth, | 156 SkScalar strokeWidth, |
| 157 const SkMatrix& combinedMatrix, | 157 const SkMatrix& combinedMatrix, |
| 158 GrColor color) { | 158 GrColor color) { |
| 159 if (pipelineBuilder->getRenderTarget()->isMultisampled()) { | 159 if (pipelineBuilder->getRenderTarget()->isUnifiedMultisampled()) { |
| 160 return false; | 160 return false; |
| 161 } | 161 } |
| 162 | 162 |
| 163 #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) | 163 #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) |
| 164 if (strokeWidth >= 0) { | 164 if (strokeWidth >= 0) { |
| 165 #endif | 165 #endif |
| 166 if (!combinedMatrix.preservesAxisAlignment()) { | 166 if (!combinedMatrix.preservesAxisAlignment()) { |
| 167 return false; | 167 return false; |
| 168 } | 168 } |
| 169 | 169 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 if (paint.isConstantBlendedColor(&clearColor)) { | 415 if (paint.isConstantBlendedColor(&clearColor)) { |
| 416 fDrawTarget->clear(NULL, clearColor, true, rt); | 416 fDrawTarget->clear(NULL, clearColor, true, rt); |
| 417 return; | 417 return; |
| 418 } | 418 } |
| 419 } | 419 } |
| 420 } | 420 } |
| 421 } | 421 } |
| 422 | 422 |
| 423 GrColor color = paint.getColor(); | 423 GrColor color = paint.getColor(); |
| 424 SkRect devBoundRect; | 424 SkRect devBoundRect; |
| 425 bool needAA = paint.isAntiAlias() && !pipelineBuilder.getRenderTarget()->isM
ultisampled(); | 425 bool needAA = paint.isAntiAlias() && |
| 426 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); |
| 426 bool doAA = needAA && apply_aa_to_rect(fDrawTarget, &pipelineBuilder, &devBo
undRect, rect, | 427 bool doAA = needAA && apply_aa_to_rect(fDrawTarget, &pipelineBuilder, &devBo
undRect, rect, |
| 427 width, viewMatrix, color); | 428 width, viewMatrix, color); |
| 428 | 429 |
| 429 if (doAA) { | 430 if (doAA) { |
| 430 if (width >= 0) { | 431 if (width >= 0) { |
| 431 GrAARectRenderer::StrokeAARect(fDrawTarget, | 432 GrAARectRenderer::StrokeAARect(fDrawTarget, |
| 432 &pipelineBuilder, | 433 &pipelineBuilder, |
| 433 color, | 434 color, |
| 434 viewMatrix, | 435 viewMatrix, |
| 435 rect, | 436 rect, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 448 } | 449 } |
| 449 | 450 |
| 450 if (width >= 0) { | 451 if (width >= 0) { |
| 451 StrokeRectBatch::Geometry geometry; | 452 StrokeRectBatch::Geometry geometry; |
| 452 geometry.fViewMatrix = viewMatrix; | 453 geometry.fViewMatrix = viewMatrix; |
| 453 geometry.fColor = color; | 454 geometry.fColor = color; |
| 454 geometry.fRect = rect; | 455 geometry.fRect = rect; |
| 455 geometry.fStrokeWidth = width; | 456 geometry.fStrokeWidth = width; |
| 456 | 457 |
| 457 // Non-AA hairlines are snapped to pixel centers to make which pixels ar
e hit deterministic | 458 // Non-AA hairlines are snapped to pixel centers to make which pixels ar
e hit deterministic |
| 458 bool snapToPixelCenters = (0 == width && !rt->isMultisampled()); | 459 bool snapToPixelCenters = (0 == width && !rt->isUnifiedMultisampled()); |
| 459 SkAutoTUnref<GrBatch> batch(StrokeRectBatch::Create(geometry, snapToPixe
lCenters)); | 460 SkAutoTUnref<GrBatch> batch(StrokeRectBatch::Create(geometry, snapToPixe
lCenters)); |
| 460 | 461 |
| 461 // Depending on sub-pixel coordinates and the particular GPU, we may los
e a corner of | 462 // Depending on sub-pixel coordinates and the particular GPU, we may los
e a corner of |
| 462 // hairline rects. We jam all the vertices to pixel centers to avoid thi
s, but not when MSAA | 463 // hairline rects. We jam all the vertices to pixel centers to avoid thi
s, but not when MSAA |
| 463 // is enabled because it can cause ugly artifacts. | 464 // is enabled because it can cause ugly artifacts. |
| 464 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_
Flag, | 465 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_
Flag, |
| 465 snapToPixelCenters); | 466 snapToPixelCenters); |
| 466 fDrawTarget->drawBatch(&pipelineBuilder, batch); | 467 fDrawTarget->drawBatch(&pipelineBuilder, batch); |
| 467 } else { | 468 } else { |
| 468 // filled BW rect | 469 // filled BW rect |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 // the writePixels that uploads to the scratch will perform a flush so we're | 1008 // the writePixels that uploads to the scratch will perform a flush so we're |
| 1008 // OK. | 1009 // OK. |
| 1009 AutoCheckFlush acf(fContext); | 1010 AutoCheckFlush acf(fContext); |
| 1010 GrPipelineBuilder pipelineBuilder; | 1011 GrPipelineBuilder pipelineBuilder; |
| 1011 if (!this->prepareToDraw(&pipelineBuilder, rt, clip, &paint)) { | 1012 if (!this->prepareToDraw(&pipelineBuilder, rt, clip, &paint)) { |
| 1012 return; | 1013 return; |
| 1013 } | 1014 } |
| 1014 | 1015 |
| 1015 if (!strokeInfo.isDashed()) { | 1016 if (!strokeInfo.isDashed()) { |
| 1016 bool useCoverageAA = paint.isAntiAlias() && | 1017 bool useCoverageAA = paint.isAntiAlias() && |
| 1017 !pipelineBuilder.getRenderTarget()->isMultisampled(); | 1018 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); |
| 1018 | 1019 |
| 1019 if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) { | 1020 if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) { |
| 1020 // Concave AA paths are expensive - try to avoid them for special ca
ses | 1021 // Concave AA paths are expensive - try to avoid them for special ca
ses |
| 1021 SkRect rects[2]; | 1022 SkRect rects[2]; |
| 1022 | 1023 |
| 1023 if (is_nested_rects(fDrawTarget, &pipelineBuilder, color, viewMatrix
, path, strokeInfo, | 1024 if (is_nested_rects(fDrawTarget, &pipelineBuilder, color, viewMatrix
, path, strokeInfo, |
| 1024 rects)) { | 1025 rects)) { |
| 1025 GrAARectRenderer::FillAANestedRects(fDrawTarget, &pipelineBuilde
r, color, | 1026 GrAARectRenderer::FillAANestedRects(fDrawTarget, &pipelineBuilde
r, color, |
| 1026 viewMatrix, rects); | 1027 viewMatrix, rects); |
| 1027 return; | 1028 return; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1055 const GrStrokeInfo& strokeInfo) { | 1056 const GrStrokeInfo& strokeInfo) { |
| 1056 RETURN_IF_ABANDONED | 1057 RETURN_IF_ABANDONED |
| 1057 SkASSERT(!path.isEmpty()); | 1058 SkASSERT(!path.isEmpty()); |
| 1058 | 1059 |
| 1059 | 1060 |
| 1060 // An Assumption here is that path renderer would use some form of tweaking | 1061 // An Assumption here is that path renderer would use some form of tweaking |
| 1061 // the src color (either the input alpha or in the frag shader) to implement | 1062 // the src color (either the input alpha or in the frag shader) to implement |
| 1062 // aa. If we have some future driver-mojo path AA that can do the right | 1063 // aa. If we have some future driver-mojo path AA that can do the right |
| 1063 // thing WRT to the blend then we'll need some query on the PR. | 1064 // thing WRT to the blend then we'll need some query on the PR. |
| 1064 bool useCoverageAA = useAA && | 1065 bool useCoverageAA = useAA && |
| 1065 !pipelineBuilder->getRenderTarget()->isMultisampled(); | 1066 !pipelineBuilder->getRenderTarget()->isUnifiedMultisampled(); |
| 1066 | 1067 |
| 1067 | 1068 |
| 1068 GrPathRendererChain::DrawType type = | 1069 GrPathRendererChain::DrawType type = |
| 1069 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType : | 1070 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType : |
| 1070 GrPathRendererChain::kColor_DrawType; | 1071 GrPathRendererChain::kColor_DrawType; |
| 1071 | 1072 |
| 1072 const SkPath* pathPtr = &path; | 1073 const SkPath* pathPtr = &path; |
| 1073 SkTLazy<SkPath> tmpPath; | 1074 SkTLazy<SkPath> tmpPath; |
| 1074 const GrStrokeInfo* strokeInfoPtr = &strokeInfo; | 1075 const GrStrokeInfo* strokeInfoPtr = &strokeInfo; |
| 1075 | 1076 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1266 return DrawVerticesBatch::Create(geometry, type, viewMatrix, | 1267 return DrawVerticesBatch::Create(geometry, type, viewMatrix, |
| 1267 positions.begin(), vertexCount, | 1268 positions.begin(), vertexCount, |
| 1268 indices.begin(), hasIndices ? vertexCount :
0, | 1269 indices.begin(), hasIndices ? vertexCount :
0, |
| 1269 colors.begin(), | 1270 colors.begin(), |
| 1270 texCoords.begin(), | 1271 texCoords.begin(), |
| 1271 bounds); | 1272 bounds); |
| 1272 } | 1273 } |
| 1273 | 1274 |
| 1274 #endif | 1275 #endif |
| 1275 | 1276 |
| OLD | NEW |