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 "GrAtlas.h" | 11 #include "GrAtlas.h" |
12 #include "GrContext.h" | 12 #include "GrContext.h" |
13 #include "GrDrawState.h" | 13 #include "GrPipelineBuilder.h" |
14 #include "GrSurfacePriv.h" | 14 #include "GrSurfacePriv.h" |
15 #include "GrSWMaskHelper.h" | 15 #include "GrSWMaskHelper.h" |
16 #include "GrTexturePriv.h" | 16 #include "GrTexturePriv.h" |
17 #include "effects/GrDistanceFieldTextureEffect.h" | 17 #include "effects/GrDistanceFieldTextureEffect.h" |
18 | 18 |
19 #include "SkDistanceFieldGen.h" | 19 #include "SkDistanceFieldGen.h" |
20 #include "SkRTConf.h" | 20 #include "SkRTConf.h" |
21 | 21 |
22 #define ATLAS_TEXTURE_WIDTH 1024 | 22 #define ATLAS_TEXTURE_WIDTH 1024 |
23 #define ATLAS_TEXTURE_HEIGHT 2048 | 23 #define ATLAS_TEXTURE_HEIGHT 2048 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 SkDELETE(fAtlas); | 60 SkDELETE(fAtlas); |
61 | 61 |
62 #ifdef DF_PATH_TRACKING | 62 #ifdef DF_PATH_TRACKING |
63 SkDebugf("Cached paths: %d, freed paths: %d\n", g_NumCachedPaths, g_NumFreed
Paths); | 63 SkDebugf("Cached paths: %d, freed paths: %d\n", g_NumCachedPaths, g_NumFreed
Paths); |
64 #endif | 64 #endif |
65 } | 65 } |
66 | 66 |
67 //////////////////////////////////////////////////////////////////////////////// | 67 //////////////////////////////////////////////////////////////////////////////// |
68 bool GrAADistanceFieldPathRenderer::canDrawPath(const GrDrawTarget* target, | 68 bool GrAADistanceFieldPathRenderer::canDrawPath(const GrDrawTarget* target, |
69 const GrDrawState* drawState, | 69 const GrPipelineBuilder* pipelin
eBuilder, |
70 const SkMatrix& viewMatrix, | 70 const SkMatrix& viewMatrix, |
71 const SkPath& path, | 71 const SkPath& path, |
72 const SkStrokeRec& stroke, | 72 const SkStrokeRec& stroke, |
73 bool antiAlias) const { | 73 bool antiAlias) const { |
74 | 74 |
75 // TODO: Support inverse fill | 75 // TODO: Support inverse fill |
76 // TODO: Support strokes | 76 // TODO: Support strokes |
77 if (!target->caps()->shaderDerivativeSupport() || !antiAlias || path.isInver
seFillType() | 77 if (!target->caps()->shaderDerivativeSupport() || !antiAlias || path.isInver
seFillType() |
78 || path.isVolatile() || SkStrokeRec::kFill_Style != stroke.getStyle()) { | 78 || path.isVolatile() || SkStrokeRec::kFill_Style != stroke.getStyle()) { |
79 return false; | 79 return false; |
80 } | 80 } |
81 | 81 |
82 // currently don't support perspective | 82 // currently don't support perspective |
83 if (viewMatrix.hasPerspective()) { | 83 if (viewMatrix.hasPerspective()) { |
84 return false; | 84 return false; |
85 } | 85 } |
86 | 86 |
87 // only support paths smaller than 64x64, scaled to less than 256x256 | 87 // only support paths smaller than 64x64, scaled to less than 256x256 |
88 // the goal is to accelerate rendering of lots of small paths that may be sc
aling | 88 // the goal is to accelerate rendering of lots of small paths that may be sc
aling |
89 SkScalar maxScale = viewMatrix.getMaxScale(); | 89 SkScalar maxScale = viewMatrix.getMaxScale(); |
90 const SkRect& bounds = path.getBounds(); | 90 const SkRect& bounds = path.getBounds(); |
91 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height()); | 91 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height()); |
92 return maxDim < 64.f && maxDim*maxScale < 256.f; | 92 return maxDim < 64.f && maxDim*maxScale < 256.f; |
93 } | 93 } |
94 | 94 |
95 | 95 |
96 GrPathRenderer::StencilSupport | 96 GrPathRenderer::StencilSupport |
97 GrAADistanceFieldPathRenderer::onGetStencilSupport(const GrDrawTarget*, | 97 GrAADistanceFieldPathRenderer::onGetStencilSupport(const GrDrawTarget*, |
98 const GrDrawState*, | 98 const GrPipelineBuilder*, |
99 const SkPath&, | 99 const SkPath&, |
100 const SkStrokeRec&) const { | 100 const SkStrokeRec&) const { |
101 return GrPathRenderer::kNoSupport_StencilSupport; | 101 return GrPathRenderer::kNoSupport_StencilSupport; |
102 } | 102 } |
103 | 103 |
104 //////////////////////////////////////////////////////////////////////////////// | 104 //////////////////////////////////////////////////////////////////////////////// |
105 | 105 |
106 bool GrAADistanceFieldPathRenderer::onDrawPath(GrDrawTarget* target, | 106 bool GrAADistanceFieldPathRenderer::onDrawPath(GrDrawTarget* target, |
107 GrDrawState* drawState, | 107 GrPipelineBuilder* pipelineBuilde
r, |
108 GrColor color, | 108 GrColor color, |
109 const SkMatrix& viewMatrix, | 109 const SkMatrix& viewMatrix, |
110 const SkPath& path, | 110 const SkPath& path, |
111 const SkStrokeRec& stroke, | 111 const SkStrokeRec& stroke, |
112 bool antiAlias) { | 112 bool antiAlias) { |
113 // we've already bailed on inverse filled paths, so this is safe | 113 // we've already bailed on inverse filled paths, so this is safe |
114 if (path.isEmpty()) { | 114 if (path.isEmpty()) { |
115 return true; | 115 return true; |
116 } | 116 } |
117 | 117 |
(...skipping 19 matching lines...) Expand all Loading... |
137 PathData* pathData = fPathCache.find(key); | 137 PathData* pathData = fPathCache.find(key); |
138 if (NULL == pathData) { | 138 if (NULL == pathData) { |
139 SkScalar scale = desiredDimension/maxDim; | 139 SkScalar scale = desiredDimension/maxDim; |
140 pathData = this->addPathToAtlas(path, stroke, antiAlias, desiredDimensio
n, scale); | 140 pathData = this->addPathToAtlas(path, stroke, antiAlias, desiredDimensio
n, scale); |
141 if (NULL == pathData) { | 141 if (NULL == pathData) { |
142 return false; | 142 return false; |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 // use signed distance field to render | 146 // use signed distance field to render |
147 return this->internalDrawPath(target, drawState, color, viewMatrix, path, pa
thData); | 147 return this->internalDrawPath(target, pipelineBuilder, color, viewMatrix, pa
th, pathData); |
148 } | 148 } |
149 | 149 |
150 // padding around path bounds to allow for antialiased pixels | 150 // padding around path bounds to allow for antialiased pixels |
151 const SkScalar kAntiAliasPad = 1.0f; | 151 const SkScalar kAntiAliasPad = 1.0f; |
152 | 152 |
153 GrAADistanceFieldPathRenderer::PathData* GrAADistanceFieldPathRenderer::addPathT
oAtlas( | 153 GrAADistanceFieldPathRenderer::PathData* GrAADistanceFieldPathRenderer::addPathT
oAtlas( |
154 const Sk
Path& path, | 154 const Sk
Path& path, |
155 const Sk
StrokeRec& stroke, | 155 const Sk
StrokeRec& stroke, |
156 bool ant
iAlias, | 156 bool ant
iAlias, |
157 uint32_t
dimension, | 157 uint32_t
dimension, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 } | 299 } |
300 } | 300 } |
301 | 301 |
302 // tell the atlas to free the plot | 302 // tell the atlas to free the plot |
303 GrAtlas::RemovePlot(&fPlotUsage, plot); | 303 GrAtlas::RemovePlot(&fPlotUsage, plot); |
304 | 304 |
305 return true; | 305 return true; |
306 } | 306 } |
307 | 307 |
308 bool GrAADistanceFieldPathRenderer::internalDrawPath(GrDrawTarget* target, | 308 bool GrAADistanceFieldPathRenderer::internalDrawPath(GrDrawTarget* target, |
309 GrDrawState* drawState, | 309 GrPipelineBuilder* pipeline
Builder, |
310 GrColor color, | 310 GrColor color, |
311 const SkMatrix& viewMatrix, | 311 const SkMatrix& viewMatrix, |
312 const SkPath& path, | 312 const SkPath& path, |
313 const PathData* pathData) { | 313 const PathData* pathData) { |
314 GrTexture* texture = fAtlas->getTexture(); | 314 GrTexture* texture = fAtlas->getTexture(); |
315 GrDrawState::AutoRestoreEffects are(drawState); | 315 GrPipelineBuilder::AutoRestoreEffects are(pipelineBuilder); |
316 | 316 |
317 SkASSERT(pathData->fPlot); | 317 SkASSERT(pathData->fPlot); |
318 GrDrawTarget::DrawToken drawToken = target->getCurrentDrawToken(); | 318 GrDrawTarget::DrawToken drawToken = target->getCurrentDrawToken(); |
319 pathData->fPlot->setDrawToken(drawToken); | 319 pathData->fPlot->setDrawToken(drawToken); |
320 | 320 |
321 // set up any flags | 321 // set up any flags |
322 uint32_t flags = 0; | 322 uint32_t flags = 0; |
323 flags |= viewMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0
; | 323 flags |= viewMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0
; |
324 | 324 |
325 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_
FilterMode); | 325 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_
FilterMode); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 intptr_t intPtr = reinterpret_cast<intptr_t>(positions); | 367 intptr_t intPtr = reinterpret_cast<intptr_t>(positions); |
368 SkPoint* textureCoords = reinterpret_cast<SkPoint*>(intPtr + vertSize - size
of(SkPoint)); | 368 SkPoint* textureCoords = reinterpret_cast<SkPoint*>(intPtr + vertSize - size
of(SkPoint)); |
369 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFix
edX(tx)), | 369 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFix
edX(tx)), |
370 SkFixedToFloat(texture->texturePriv().normalizeFix
edY(ty)), | 370 SkFixedToFloat(texture->texturePriv().normalizeFix
edY(ty)), |
371 SkFixedToFloat(texture->texturePriv().normalizeFix
edX(tx + tw)), | 371 SkFixedToFloat(texture->texturePriv().normalizeFix
edX(tx + tw)), |
372 SkFixedToFloat(texture->texturePriv().normalizeFix
edY(ty + th)), | 372 SkFixedToFloat(texture->texturePriv().normalizeFix
edY(ty + th)), |
373 vertSize); | 373 vertSize); |
374 | 374 |
375 viewMatrix.mapRect(&r); | 375 viewMatrix.mapRect(&r); |
376 target->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); | 376 target->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); |
377 target->drawIndexedInstances(drawState, fCachedGeometryProcessor.get(), | 377 target->drawIndexedInstances(pipelineBuilder, fCachedGeometryProcessor.get()
, |
378 kTriangles_GrPrimitiveType, 1, 4, 6, &r); | 378 kTriangles_GrPrimitiveType, 1, 4, 6, &r); |
379 target->resetVertexSource(); | 379 target->resetVertexSource(); |
380 | 380 |
381 return true; | 381 return true; |
382 } | 382 } |
383 | 383 |
OLD | NEW |