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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 74 } |
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 | 84 // We don't currently apply the dash or factor it into the DF key. (skbug.co
m/5082) |
| 85 if (args.fStyle->pathEffect()) { |
| 86 return false; |
| 87 } |
85 // TODO: Support inverse fill | 88 // TODO: Support inverse fill |
86 if (!args.fShaderCaps->shaderDerivativeSupport() || !args.fAntiAlias || | 89 if (!args.fShaderCaps->shaderDerivativeSupport() || !args.fAntiAlias || |
87 SkStrokeRec::kHairline_Style == args.fStroke->getStyle() || | 90 args.fStyle->isSimpleHairline() || args.fPath->isInverseFillType() || |
88 args.fPath->isInverseFillType() || args.fPath->isVolatile() || | 91 args.fPath->isVolatile()) { |
89 // We don't currently apply the dash or factor it into the DF key. (skbu
g.com/5082) | |
90 args.fStroke->isDashed()) { | |
91 return false; | 92 return false; |
92 } | 93 } |
93 | 94 |
94 // currently don't support perspective | 95 // currently don't support perspective |
95 if (args.fViewMatrix->hasPerspective()) { | 96 if (args.fViewMatrix->hasPerspective()) { |
96 return false; | 97 return false; |
97 } | 98 } |
98 | 99 |
99 // only support paths with bounds within kMediumMIP by kMediumMIP, | 100 // only support paths with bounds within kMediumMIP by kMediumMIP, |
100 // 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 |
101 // 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 |
102 SkScalar maxScale = args.fViewMatrix->getMaxScale(); | 103 SkScalar maxScale = args.fViewMatrix->getMaxScale(); |
| 104 #if 0 // This is more accurate but changes some GMs. TODO: Standalone change to
enable this. |
| 105 SkRect bounds; |
| 106 args.fStyle->adjustBounds(&bounds, args.fPath->getBounds()); |
| 107 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height()); |
| 108 #else |
103 const SkRect& bounds = args.fPath->getBounds(); | 109 const SkRect& bounds = args.fPath->getBounds(); |
104 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height()); | 110 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height()); |
| 111 const SkStrokeRec& stroke = args.fStyle->strokeRec(); |
105 // Approximate stroked size by adding the maximum of the stroke width or 2x
the miter limit | 112 // Approximate stroked size by adding the maximum of the stroke width or 2x
the miter limit |
106 if (!args.fStroke->isFillStyle()) { | 113 if (!stroke.isFillStyle()) { |
107 SkScalar extraWidth = args.fStroke->getWidth(); | 114 SkScalar extraWidth = stroke.getWidth(); |
108 if (SkPaint::kMiter_Join == args.fStroke->getJoin()) { | 115 if (SkPaint::kMiter_Join == stroke.getJoin()) { |
109 extraWidth = SkTMax(extraWidth, 2.0f*args.fStroke->getMiter()); | 116 extraWidth = SkTMax(extraWidth, 2.0f*stroke.getMiter()); |
110 } | 117 } |
111 maxDim += extraWidth; | 118 maxDim += extraWidth; |
112 } | 119 } |
| 120 #endif |
113 | 121 |
114 return maxDim <= kMediumMIP && maxDim * maxScale <= 2.0f*kLargeMIP; | 122 return maxDim <= kMediumMIP && maxDim * maxScale <= 2.0f*kLargeMIP; |
115 } | 123 } |
116 | 124 |
117 //////////////////////////////////////////////////////////////////////////////// | 125 //////////////////////////////////////////////////////////////////////////////// |
118 | 126 |
119 // padding around path bounds to allow for antialiased pixels | 127 // padding around path bounds to allow for antialiased pixels |
120 static const SkScalar kAntiAliasPad = 1.0f; | 128 static const SkScalar kAntiAliasPad = 1.0f; |
121 | 129 |
122 class AADistanceFieldPathBatch : public GrVertexBatch { | 130 class AADistanceFieldPathBatch : public GrVertexBatch { |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 fAtlas = args.fResourceProvider->createAtlas(kAlpha_8_GrPixelConfig, | 553 fAtlas = args.fResourceProvider->createAtlas(kAlpha_8_GrPixelConfig, |
546 ATLAS_TEXTURE_WIDTH, ATLAS_
TEXTURE_HEIGHT, | 554 ATLAS_TEXTURE_WIDTH, ATLAS_
TEXTURE_HEIGHT, |
547 NUM_PLOTS_X, NUM_PLOTS_Y, | 555 NUM_PLOTS_X, NUM_PLOTS_Y, |
548 &GrAADistanceFieldPathRende
rer::HandleEviction, | 556 &GrAADistanceFieldPathRende
rer::HandleEviction, |
549 (void*)this); | 557 (void*)this); |
550 if (!fAtlas) { | 558 if (!fAtlas) { |
551 return false; | 559 return false; |
552 } | 560 } |
553 } | 561 } |
554 | 562 |
555 AADistanceFieldPathBatch::Geometry geometry(*args.fStroke); | 563 // It's ok to ignore style's path effect because canDrawPath filtered out pa
th effects. |
556 if (SkStrokeRec::kFill_Style == args.fStroke->getStyle()) { | 564 AADistanceFieldPathBatch::Geometry geometry(args.fStyle->strokeRec()); |
| 565 if (args.fStyle->isSimpleFill()) { |
557 geometry.fPath = *args.fPath; | 566 geometry.fPath = *args.fPath; |
558 } else { | 567 } else { |
559 args.fStroke->applyToPath(&geometry.fPath, *args.fPath); | 568 args.fStyle->strokeRec().applyToPath(&geometry.fPath, *args.fPath); |
560 } | 569 } |
561 geometry.fColor = args.fColor; | 570 geometry.fColor = args.fColor; |
562 geometry.fAntiAlias = args.fAntiAlias; | 571 geometry.fAntiAlias = args.fAntiAlias; |
563 // Note: this is the generation ID of the _original_ path. When a new path i
s | 572 // Note: this is the generation ID of the _original_ path. When a new path i
s |
564 // generated due to stroking it is important that the original path's id is
used | 573 // generated due to stroking it is important that the original path's id is
used |
565 // for caching. | 574 // for caching. |
566 geometry.fGenID = args.fPath->getGenerationID(); | 575 geometry.fGenID = args.fPath->getGenerationID(); |
567 | 576 |
568 SkAutoTUnref<GrDrawBatch> batch(AADistanceFieldPathBatch::Create(geometry, | 577 SkAutoTUnref<GrDrawBatch> batch(AADistanceFieldPathBatch::Create(geometry, |
569 *args.fView
Matrix, fAtlas, | 578 *args.fView
Matrix, fAtlas, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 geometry.fGenID = random->nextU(); | 654 geometry.fGenID = random->nextU(); |
646 | 655 |
647 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, | 656 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, |
648 gTestStruct.fAtlas, | 657 gTestStruct.fAtlas, |
649 &gTestStruct.fPathCache, | 658 &gTestStruct.fPathCache, |
650 &gTestStruct.fPathList, | 659 &gTestStruct.fPathList, |
651 gammaCorrect); | 660 gammaCorrect); |
652 } | 661 } |
653 | 662 |
654 #endif | 663 #endif |
OLD | NEW |