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 |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 #define PLOT_WIDTH 256 | 25 #define PLOT_WIDTH 256 |
26 #define PLOT_HEIGHT 256 | 26 #define PLOT_HEIGHT 256 |
27 | 27 |
28 #define NUM_PLOTS_X (ATLAS_TEXTURE_WIDTH / PLOT_WIDTH) | 28 #define NUM_PLOTS_X (ATLAS_TEXTURE_WIDTH / PLOT_WIDTH) |
29 #define NUM_PLOTS_Y (ATLAS_TEXTURE_HEIGHT / PLOT_HEIGHT) | 29 #define NUM_PLOTS_Y (ATLAS_TEXTURE_HEIGHT / PLOT_HEIGHT) |
30 | 30 |
31 SK_CONF_DECLARE(bool, c_DumpPathCache, "gpu.dumpPathCache", false, | 31 SK_CONF_DECLARE(bool, c_DumpPathCache, "gpu.dumpPathCache", false, |
32 "Dump the contents of the path cache before every purge."); | 32 "Dump the contents of the path cache before every purge."); |
33 | 33 |
| 34 #ifdef DF_PATH_TRACKING |
| 35 static int g_NumCachedPaths = 0; |
| 36 static int g_NumFreedPaths = 0; |
| 37 #endif |
| 38 |
34 //////////////////////////////////////////////////////////////////////////////// | 39 //////////////////////////////////////////////////////////////////////////////// |
35 GrAADistanceFieldPathRenderer::~GrAADistanceFieldPathRenderer() { | 40 GrAADistanceFieldPathRenderer::~GrAADistanceFieldPathRenderer() { |
36 PathDataList::Iter iter; | 41 PathDataList::Iter iter; |
37 iter.init(fPathList, PathDataList::Iter::kHead_IterStart); | 42 iter.init(fPathList, PathDataList::Iter::kHead_IterStart); |
38 PathData* pathData; | 43 PathData* pathData; |
39 while ((pathData = iter.get())) { | 44 while ((pathData = iter.get())) { |
40 iter.next(); | 45 iter.next(); |
41 fPathList.remove(pathData); | 46 fPathList.remove(pathData); |
42 SkDELETE(pathData); | 47 SkDELETE(pathData); |
43 } | 48 } |
44 | 49 |
45 SkDELETE(fAtlas); | 50 SkDELETE(fAtlas); |
| 51 |
| 52 #ifdef DF_PATH_TRACKING |
| 53 SkDebugf("Num cached paths: %d\n", g_NumCachedPaths); |
| 54 SkDebugf("Num freed paths: %d\n", g_NumFreedPaths); |
| 55 #endif |
46 } | 56 } |
47 | 57 |
48 //////////////////////////////////////////////////////////////////////////////// | 58 //////////////////////////////////////////////////////////////////////////////// |
49 bool GrAADistanceFieldPathRenderer::canDrawPath(const SkPath& path, | 59 bool GrAADistanceFieldPathRenderer::canDrawPath(const SkPath& path, |
50 const SkStrokeRec& stroke, | 60 const SkStrokeRec& stroke, |
51 const GrDrawTarget* target, | 61 const GrDrawTarget* target, |
52 bool antiAlias) const { | 62 bool antiAlias) const { |
| 63 |
53 // TODO: Support inverse fill | 64 // TODO: Support inverse fill |
54 // TODO: Support strokes | 65 // TODO: Support strokes |
55 if (!target->caps()->shaderDerivativeSupport() || !antiAlias || path.isInver
seFillType() | 66 if (!target->caps()->shaderDerivativeSupport() || !antiAlias || path.isInver
seFillType() |
56 || SkStrokeRec::kFill_Style != stroke.getStyle()) { | 67 || path.isVolatile() || SkStrokeRec::kFill_Style != stroke.getStyle()) { |
57 return false; | 68 return false; |
58 } | 69 } |
59 | 70 |
60 // currently don't support perspective or scaling more than 3x | 71 // currently don't support perspective or scaling more than 3x |
61 const GrDrawState& drawState = target->getDrawState(); | 72 const GrDrawState& drawState = target->getDrawState(); |
62 const SkMatrix& vm = drawState.getViewMatrix(); | 73 const SkMatrix& vm = drawState.getViewMatrix(); |
63 if (vm.hasPerspective() || vm.getMaxScale() > 3.0f) { | 74 if (vm.hasPerspective() || vm.getMaxScale() > 3.0f) { |
64 return false; | 75 return false; |
65 } | 76 } |
66 | 77 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 scaledBounds.offset(-SkIntToScalar(SK_DistanceFieldInset) - kAntiAliasPad +
dx, | 234 scaledBounds.offset(-SkIntToScalar(SK_DistanceFieldInset) - kAntiAliasPad +
dx, |
224 -SkIntToScalar(SK_DistanceFieldInset) - kAntiAliasPad +
dy); | 235 -SkIntToScalar(SK_DistanceFieldInset) - kAntiAliasPad +
dy); |
225 pathData->fBounds = scaledBounds; | 236 pathData->fBounds = scaledBounds; |
226 // origin we render from is inset from distance field edge | 237 // origin we render from is inset from distance field edge |
227 atlasLocation.fX += SK_DistanceFieldInset; | 238 atlasLocation.fX += SK_DistanceFieldInset; |
228 atlasLocation.fY += SK_DistanceFieldInset; | 239 atlasLocation.fY += SK_DistanceFieldInset; |
229 pathData->fAtlasLocation = atlasLocation; | 240 pathData->fAtlasLocation = atlasLocation; |
230 | 241 |
231 fPathCache.add(pathData); | 242 fPathCache.add(pathData); |
232 fPathList.addToTail(pathData); | 243 fPathList.addToTail(pathData); |
233 | 244 #ifdef DF_PATH_TRACKING |
| 245 ++g_NumCachedPaths; |
| 246 #endif |
| 247 |
234 return pathData; | 248 return pathData; |
235 } | 249 } |
236 | 250 |
237 bool GrAADistanceFieldPathRenderer::freeUnusedPlot() { | 251 bool GrAADistanceFieldPathRenderer::freeUnusedPlot() { |
238 // find an unused plot | 252 // find an unused plot |
239 GrPlot* plot = fAtlas->getUnusedPlot(); | 253 GrPlot* plot = fAtlas->getUnusedPlot(); |
240 if (NULL == plot) { | 254 if (NULL == plot) { |
241 return false; | 255 return false; |
242 } | 256 } |
243 plot->resetRects(); | 257 plot->resetRects(); |
244 | 258 |
245 // remove any paths that use this plot | 259 // remove any paths that use this plot |
246 PathDataList::Iter iter; | 260 PathDataList::Iter iter; |
247 iter.init(fPathList, PathDataList::Iter::kHead_IterStart); | 261 iter.init(fPathList, PathDataList::Iter::kHead_IterStart); |
248 PathData* pathData; | 262 PathData* pathData; |
249 while ((pathData = iter.get())) { | 263 while ((pathData = iter.get())) { |
250 iter.next(); | 264 iter.next(); |
251 if (plot == pathData->fPlot) { | 265 if (plot == pathData->fPlot) { |
252 fPathCache.remove(pathData->fGenID); | 266 fPathCache.remove(pathData->fGenID); |
253 fPathList.remove(pathData); | 267 fPathList.remove(pathData); |
254 SkDELETE(pathData); | 268 SkDELETE(pathData); |
| 269 #ifdef DF_PATH_TRACKING |
| 270 --g_NumFreedPaths; |
| 271 #endif |
255 } | 272 } |
256 } | 273 } |
257 | 274 |
258 // tell the atlas to free the plot | 275 // tell the atlas to free the plot |
259 GrAtlas::RemovePlot(&fPlotUsage, plot); | 276 GrAtlas::RemovePlot(&fPlotUsage, plot); |
260 | 277 |
261 return true; | 278 return true; |
262 } | 279 } |
263 | 280 |
264 bool GrAADistanceFieldPathRenderer::internalDrawPath(const SkPath& path, | 281 bool GrAADistanceFieldPathRenderer::internalDrawPath(const SkPath& path, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 | 349 |
333 | 350 |
334 vm.mapRect(&r); | 351 vm.mapRect(&r); |
335 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &r); | 352 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &r); |
336 target->resetVertexSource(); | 353 target->resetVertexSource(); |
337 target->resetIndexSource(); | 354 target->resetIndexSource(); |
338 | 355 |
339 return true; | 356 return true; |
340 } | 357 } |
341 | 358 |
OLD | NEW |