OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 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 "GrAADistanceFieldPathRenderer.h" | 9 #include "GrAADistanceFieldPathRenderer.h" |
10 | 10 |
11 #include "GrBatch.h" | 11 #include "GrBatch.h" |
12 #include "GrBatchTarget.h" | 12 #include "GrBatchTarget.h" |
13 #include "GrBufferAllocPool.h" | 13 #include "GrBufferAllocPool.h" |
14 #include "GrContext.h" | 14 #include "GrContext.h" |
15 #include "GrPipelineBuilder.h" | 15 #include "GrPipelineBuilder.h" |
| 16 #include "GrStrokeInfo.h" |
16 #include "GrSurfacePriv.h" | 17 #include "GrSurfacePriv.h" |
17 #include "GrSWMaskHelper.h" | 18 #include "GrSWMaskHelper.h" |
18 #include "GrTexturePriv.h" | 19 #include "GrTexturePriv.h" |
19 #include "effects/GrDistanceFieldGeoProc.h" | 20 #include "effects/GrDistanceFieldGeoProc.h" |
20 | 21 |
21 #include "SkDistanceFieldGen.h" | 22 #include "SkDistanceFieldGen.h" |
22 #include "SkRTConf.h" | 23 #include "SkRTConf.h" |
23 | 24 |
24 #define ATLAS_TEXTURE_WIDTH 1024 | 25 #define ATLAS_TEXTURE_WIDTH 1024 |
25 #define ATLAS_TEXTURE_HEIGHT 2048 | 26 #define ATLAS_TEXTURE_HEIGHT 2048 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 #ifdef DF_PATH_TRACKING | 80 #ifdef DF_PATH_TRACKING |
80 SkDebugf("Cached paths: %d, freed paths: %d\n", g_NumCachedPaths, g_NumFreed
Paths); | 81 SkDebugf("Cached paths: %d, freed paths: %d\n", g_NumCachedPaths, g_NumFreed
Paths); |
81 #endif | 82 #endif |
82 } | 83 } |
83 | 84 |
84 //////////////////////////////////////////////////////////////////////////////// | 85 //////////////////////////////////////////////////////////////////////////////// |
85 bool GrAADistanceFieldPathRenderer::canDrawPath(const GrDrawTarget* target, | 86 bool GrAADistanceFieldPathRenderer::canDrawPath(const GrDrawTarget* target, |
86 const GrPipelineBuilder* pipelin
eBuilder, | 87 const GrPipelineBuilder* pipelin
eBuilder, |
87 const SkMatrix& viewMatrix, | 88 const SkMatrix& viewMatrix, |
88 const SkPath& path, | 89 const SkPath& path, |
89 const SkStrokeRec& stroke, | 90 const GrStrokeInfo& stroke, |
90 bool antiAlias) const { | 91 bool antiAlias) const { |
91 | 92 |
92 // TODO: Support inverse fill | 93 // TODO: Support inverse fill |
93 // TODO: Support strokes | 94 // TODO: Support strokes |
94 if (!target->caps()->shaderDerivativeSupport() || !antiAlias || path.isInver
seFillType() | 95 if (!target->caps()->shaderDerivativeSupport() || !antiAlias || path.isInver
seFillType() |
95 || path.isVolatile() || SkStrokeRec::kFill_Style != stroke.getStyle()) { | 96 || path.isVolatile() || SkStrokeRec::kFill_Style != stroke.getStrokeRec(
).getStyle()) { |
96 return false; | 97 return false; |
97 } | 98 } |
98 | 99 |
99 // currently don't support perspective | 100 // currently don't support perspective |
100 if (viewMatrix.hasPerspective()) { | 101 if (viewMatrix.hasPerspective()) { |
101 return false; | 102 return false; |
102 } | 103 } |
103 | 104 |
104 // only support paths smaller than 64x64, scaled to less than 256x256 | 105 // only support paths smaller than 64x64, scaled to less than 256x256 |
105 // the goal is to accelerate rendering of lots of small paths that may be sc
aling | 106 // the goal is to accelerate rendering of lots of small paths that may be sc
aling |
106 SkScalar maxScale = viewMatrix.getMaxScale(); | 107 SkScalar maxScale = viewMatrix.getMaxScale(); |
107 const SkRect& bounds = path.getBounds(); | 108 const SkRect& bounds = path.getBounds(); |
108 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height()); | 109 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height()); |
109 return maxDim < 64.f && maxDim * maxScale < 256.f; | 110 return maxDim < 64.f && maxDim * maxScale < 256.f; |
110 } | 111 } |
111 | 112 |
112 | 113 |
113 GrPathRenderer::StencilSupport | 114 GrPathRenderer::StencilSupport |
114 GrAADistanceFieldPathRenderer::onGetStencilSupport(const GrDrawTarget*, | 115 GrAADistanceFieldPathRenderer::onGetStencilSupport(const GrDrawTarget*, |
115 const GrPipelineBuilder*, | 116 const GrPipelineBuilder*, |
116 const SkPath&, | 117 const SkPath&, |
117 const SkStrokeRec&) const { | 118 const GrStrokeInfo&) const { |
118 return GrPathRenderer::kNoSupport_StencilSupport; | 119 return GrPathRenderer::kNoSupport_StencilSupport; |
119 } | 120 } |
120 | 121 |
121 //////////////////////////////////////////////////////////////////////////////// | 122 //////////////////////////////////////////////////////////////////////////////// |
122 | 123 |
123 // padding around path bounds to allow for antialiased pixels | 124 // padding around path bounds to allow for antialiased pixels |
124 static const SkScalar kAntiAliasPad = 1.0f; | 125 static const SkScalar kAntiAliasPad = 1.0f; |
125 | 126 |
126 class AADistanceFieldPathBatch : public GrBatch { | 127 class AADistanceFieldPathBatch : public GrBatch { |
127 public: | 128 public: |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 GrBatchAtlas* fAtlas; | 564 GrBatchAtlas* fAtlas; |
564 PathCache* fPathCache; | 565 PathCache* fPathCache; |
565 PathDataList* fPathList; | 566 PathDataList* fPathList; |
566 }; | 567 }; |
567 | 568 |
568 bool GrAADistanceFieldPathRenderer::onDrawPath(GrDrawTarget* target, | 569 bool GrAADistanceFieldPathRenderer::onDrawPath(GrDrawTarget* target, |
569 GrPipelineBuilder* pipelineBuilde
r, | 570 GrPipelineBuilder* pipelineBuilde
r, |
570 GrColor color, | 571 GrColor color, |
571 const SkMatrix& viewMatrix, | 572 const SkMatrix& viewMatrix, |
572 const SkPath& path, | 573 const SkPath& path, |
573 const SkStrokeRec& stroke, | 574 const GrStrokeInfo& stroke, |
574 bool antiAlias) { | 575 bool antiAlias) { |
575 // we've already bailed on inverse filled paths, so this is safe | 576 // we've already bailed on inverse filled paths, so this is safe |
576 if (path.isEmpty()) { | 577 if (path.isEmpty()) { |
577 return true; | 578 return true; |
578 } | 579 } |
579 | 580 |
580 SkASSERT(fContext); | 581 SkASSERT(fContext); |
581 | 582 |
582 if (!fAtlas) { | 583 if (!fAtlas) { |
583 // Create a new atlas | 584 // Create a new atlas |
584 GrSurfaceDesc desc; | 585 GrSurfaceDesc desc; |
585 desc.fFlags = kNone_GrSurfaceFlags; | 586 desc.fFlags = kNone_GrSurfaceFlags; |
586 desc.fWidth = ATLAS_TEXTURE_WIDTH; | 587 desc.fWidth = ATLAS_TEXTURE_WIDTH; |
587 desc.fHeight = ATLAS_TEXTURE_HEIGHT; | 588 desc.fHeight = ATLAS_TEXTURE_HEIGHT; |
588 desc.fConfig = kAlpha_8_GrPixelConfig; | 589 desc.fConfig = kAlpha_8_GrPixelConfig; |
589 | 590 |
590 // We don't want to flush the context so we claim we're in the middle of
flushing so as to | 591 // We don't want to flush the context so we claim we're in the middle of
flushing so as to |
591 // guarantee we do not recieve a texture with pending IO | 592 // guarantee we do not recieve a texture with pending IO |
592 GrTexture* texture = fContext->refScratchTexture(desc, GrContext::kAppro
x_ScratchTexMatch, | 593 GrTexture* texture = fContext->refScratchTexture(desc, GrContext::kAppro
x_ScratchTexMatch, |
593 true); | 594 true); |
594 if (texture) { | 595 if (texture) { |
595 fAtlas = SkNEW_ARGS(GrBatchAtlas, (texture, NUM_PLOTS_X, NUM_PLOTS_Y
)); | 596 fAtlas = SkNEW_ARGS(GrBatchAtlas, (texture, NUM_PLOTS_X, NUM_PLOTS_Y
)); |
596 } else { | 597 } else { |
597 return false; | 598 return false; |
598 } | 599 } |
599 fAtlas->registerEvictionCallback(&GrAADistanceFieldPathRenderer::HandleE
viction, | 600 fAtlas->registerEvictionCallback(&GrAADistanceFieldPathRenderer::HandleE
viction, |
600 (void*)this); | 601 (void*)this); |
601 } | 602 } |
602 | 603 |
603 AADistanceFieldPathBatch::Geometry geometry(stroke); | 604 AADistanceFieldPathBatch::Geometry geometry(stroke.getStrokeRec()); |
604 geometry.fPath = path; | 605 geometry.fPath = path; |
605 geometry.fAntiAlias = antiAlias; | 606 geometry.fAntiAlias = antiAlias; |
606 | 607 |
607 SkAutoTUnref<GrBatch> batch(AADistanceFieldPathBatch::Create(geometry, color
, viewMatrix, | 608 SkAutoTUnref<GrBatch> batch(AADistanceFieldPathBatch::Create(geometry, color
, viewMatrix, |
608 fAtlas, &fPathC
ache, &fPathList)); | 609 fAtlas, &fPathC
ache, &fPathList)); |
609 | 610 |
610 SkRect bounds = path.getBounds(); | 611 SkRect bounds = path.getBounds(); |
611 viewMatrix.mapRect(&bounds); | 612 viewMatrix.mapRect(&bounds); |
612 target->drawBatch(pipelineBuilder, batch, &bounds); | 613 target->drawBatch(pipelineBuilder, batch, &bounds); |
613 | 614 |
614 return true; | 615 return true; |
615 } | 616 } |
616 | 617 |
OLD | NEW |