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