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 "GrAADistanceFieldPathRenderer.h" | 8 #include "GrAADistanceFieldPathRenderer.h" |
9 | 9 |
10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 delete fAtlas; | 75 delete fAtlas; |
76 | 76 |
77 #ifdef DF_PATH_TRACKING | 77 #ifdef DF_PATH_TRACKING |
78 SkDebugf("Cached paths: %d, freed paths: %d\n", g_NumCachedPaths, g_NumFreed
Paths); | 78 SkDebugf("Cached paths: %d, freed paths: %d\n", g_NumCachedPaths, g_NumFreed
Paths); |
79 #endif | 79 #endif |
80 } | 80 } |
81 | 81 |
82 //////////////////////////////////////////////////////////////////////////////// | 82 //////////////////////////////////////////////////////////////////////////////// |
83 bool GrAADistanceFieldPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) c
onst { | 83 bool GrAADistanceFieldPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) c
onst { |
84 // We don't currently apply the dash or factor it into the DF key. (skbug.co
m/5082) | 84 // We don't currently apply the dash or factor it into the DF key. (skbug.co
m/5082) |
85 if (args.fStyle->pathEffect()) { | 85 if (args.fShape->style().pathEffect()) { |
86 return false; | 86 return false; |
87 } | 87 } |
88 // TODO: Support inverse fill | 88 // TODO: Support inverse fill |
89 if (!args.fShaderCaps->shaderDerivativeSupport() || !args.fAntiAlias || | 89 if (!args.fShaderCaps->shaderDerivativeSupport() || !args.fAntiAlias || |
90 args.fStyle->isSimpleHairline() || args.fPath->isInverseFillType() || | 90 args.fShape->style().isSimpleHairline() || args.fShape->mayBeInverseFill
edAfterStyling() || |
91 args.fPath->isVolatile()) { | 91 !args.fShape->hasUnstyledKey()) { |
92 return false; | 92 return false; |
93 } | 93 } |
94 | 94 |
95 // currently don't support perspective | 95 // currently don't support perspective |
96 if (args.fViewMatrix->hasPerspective()) { | 96 if (args.fViewMatrix->hasPerspective()) { |
97 return false; | 97 return false; |
98 } | 98 } |
99 | 99 |
100 // only support paths with bounds within kMediumMIP by kMediumMIP, | 100 // only support paths with bounds within kMediumMIP by kMediumMIP, |
101 // scaled to have bounds within 2.0f*kLargeMIP by 2.0f*kLargeMIP | 101 // scaled to have bounds within 2.0f*kLargeMIP by 2.0f*kLargeMIP |
102 // the goal is to accelerate rendering of lots of small paths that may be sc
aling | 102 // the goal is to accelerate rendering of lots of small paths that may be sc
aling |
103 SkScalar maxScale = args.fViewMatrix->getMaxScale(); | 103 SkScalar maxScale = args.fViewMatrix->getMaxScale(); |
104 SkRect bounds; | 104 SkRect bounds; |
105 args.fStyle->adjustBounds(&bounds, args.fPath->getBounds()); | 105 args.fShape->styledBounds(&bounds); |
106 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height()); | 106 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height()); |
107 | 107 |
108 return maxDim <= kMediumMIP && maxDim * maxScale <= 2.0f*kLargeMIP; | 108 return maxDim <= kMediumMIP && maxDim * maxScale <= 2.0f*kLargeMIP; |
109 } | 109 } |
110 | 110 |
111 //////////////////////////////////////////////////////////////////////////////// | 111 //////////////////////////////////////////////////////////////////////////////// |
112 | 112 |
113 // padding around path bounds to allow for antialiased pixels | 113 // padding around path bounds to allow for antialiased pixels |
114 static const SkScalar kAntiAliasPad = 1.0f; | 114 static const SkScalar kAntiAliasPad = 1.0f; |
115 | 115 |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 | 525 |
526 typedef GrVertexBatch INHERITED; | 526 typedef GrVertexBatch INHERITED; |
527 }; | 527 }; |
528 | 528 |
529 bool GrAADistanceFieldPathRenderer::onDrawPath(const DrawPathArgs& args) { | 529 bool GrAADistanceFieldPathRenderer::onDrawPath(const DrawPathArgs& args) { |
530 GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), | 530 GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), |
531 "GrAADistanceFieldPathRenderer::onDrawPath"); | 531 "GrAADistanceFieldPathRenderer::onDrawPath"); |
532 SkASSERT(!args.fDrawContext->isUnifiedMultisampled()); | 532 SkASSERT(!args.fDrawContext->isUnifiedMultisampled()); |
533 | 533 |
534 // we've already bailed on inverse filled paths, so this is safe | 534 // we've already bailed on inverse filled paths, so this is safe |
535 if (args.fPath->isEmpty()) { | 535 SkASSERT(!args.fShape->isEmpty()); |
536 return true; | |
537 } | |
538 | 536 |
539 if (!fAtlas) { | 537 if (!fAtlas) { |
540 fAtlas = args.fResourceProvider->createAtlas(kAlpha_8_GrPixelConfig, | 538 fAtlas = args.fResourceProvider->createAtlas(kAlpha_8_GrPixelConfig, |
541 ATLAS_TEXTURE_WIDTH, ATLAS_
TEXTURE_HEIGHT, | 539 ATLAS_TEXTURE_WIDTH, ATLAS_
TEXTURE_HEIGHT, |
542 NUM_PLOTS_X, NUM_PLOTS_Y, | 540 NUM_PLOTS_X, NUM_PLOTS_Y, |
543 &GrAADistanceFieldPathRende
rer::HandleEviction, | 541 &GrAADistanceFieldPathRende
rer::HandleEviction, |
544 (void*)this); | 542 (void*)this); |
545 if (!fAtlas) { | 543 if (!fAtlas) { |
546 return false; | 544 return false; |
547 } | 545 } |
548 } | 546 } |
549 | 547 |
| 548 const GrStyle& style = args.fShape->style(); |
550 // It's ok to ignore style's path effect because canDrawPath filtered out pa
th effects. | 549 // It's ok to ignore style's path effect because canDrawPath filtered out pa
th effects. |
551 AADistanceFieldPathBatch::Geometry geometry(args.fStyle->strokeRec()); | 550 AADistanceFieldPathBatch::Geometry geometry(style.strokeRec()); |
552 if (args.fStyle->isSimpleFill()) { | 551 args.fShape->asPath(&geometry.fPath); |
553 geometry.fPath = *args.fPath; | 552 // Note: this is the generation ID of the _original_ path. When a new path i
s |
554 } else { | 553 // generated due to stroking it is important that the original path's id is
used |
555 args.fStyle->strokeRec().applyToPath(&geometry.fPath, *args.fPath); | 554 // for caching. |
| 555 geometry.fGenID = geometry.fPath.getGenerationID(); |
| 556 if (!style.isSimpleFill()) { |
| 557 style.strokeRec().applyToPath(&geometry.fPath, geometry.fPath); |
556 } | 558 } |
557 geometry.fColor = args.fColor; | 559 geometry.fColor = args.fColor; |
558 geometry.fAntiAlias = args.fAntiAlias; | 560 geometry.fAntiAlias = args.fAntiAlias; |
559 // Note: this is the generation ID of the _original_ path. When a new path i
s | |
560 // generated due to stroking it is important that the original path's id is
used | |
561 // for caching. | |
562 geometry.fGenID = args.fPath->getGenerationID(); | |
563 | 561 |
564 SkAutoTUnref<GrDrawBatch> batch(AADistanceFieldPathBatch::Create(geometry, | 562 SkAutoTUnref<GrDrawBatch> batch(AADistanceFieldPathBatch::Create(geometry, |
565 *args.fView
Matrix, fAtlas, | 563 *args.fView
Matrix, fAtlas, |
566 &fPathCache
, &fPathList, | 564 &fPathCache
, &fPathList, |
567 args.fGamma
Correct)); | 565 args.fGamma
Correct)); |
568 | 566 |
569 GrPipelineBuilder pipelineBuilder(*args.fPaint); | 567 GrPipelineBuilder pipelineBuilder(*args.fPaint); |
570 pipelineBuilder.setUserStencil(args.fUserStencilSettings); | 568 pipelineBuilder.setUserStencil(args.fUserStencilSettings); |
571 | 569 |
572 args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); | 570 args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 geometry.fGenID = random->nextU(); | 643 geometry.fGenID = random->nextU(); |
646 | 644 |
647 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, | 645 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, |
648 gTestStruct.fAtlas, | 646 gTestStruct.fAtlas, |
649 &gTestStruct.fPathCache, | 647 &gTestStruct.fPathCache, |
650 &gTestStruct.fPathList, | 648 &gTestStruct.fPathList, |
651 gammaCorrect); | 649 gammaCorrect); |
652 } | 650 } |
653 | 651 |
654 #endif | 652 #endif |
OLD | NEW |