| 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 "GrDrawState.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 1024 | 23 #define ATLAS_TEXTURE_HEIGHT 1024 |
| 24 | |
| 25 #define PLOT_WIDTH 256 | 24 #define PLOT_WIDTH 256 |
| 26 #define PLOT_HEIGHT 256 | 25 #define PLOT_HEIGHT 256 |
| 27 | 26 |
| 28 #define NUM_PLOTS_X (ATLAS_TEXTURE_WIDTH / PLOT_WIDTH) | 27 #define NUM_PLOTS_X (ATLAS_TEXTURE_WIDTH / PLOT_WIDTH) |
| 29 #define NUM_PLOTS_Y (ATLAS_TEXTURE_HEIGHT / PLOT_HEIGHT) | 28 #define NUM_PLOTS_Y (ATLAS_TEXTURE_HEIGHT / PLOT_HEIGHT) |
| 30 | 29 |
| 31 SK_CONF_DECLARE(bool, c_DumpPathCache, "gpu.dumpPathCache", false, | 30 SK_CONF_DECLARE(bool, c_DumpPathCache, "gpu.dumpPathCache", false, |
| 32 "Dump the contents of the path cache before every purge."); | 31 "Dump the contents of the path cache before every purge."); |
| 33 | 32 |
| 34 #ifdef DF_PATH_TRACKING | 33 #ifdef DF_PATH_TRACKING |
| 35 static int g_NumCachedPaths = 0; | 34 static int g_NumCachedPaths = 0; |
| 36 static int g_NumFreedPaths = 0; | 35 static int g_NumFreedPaths = 0; |
| 37 #endif | 36 #endif |
| 38 | 37 |
| 39 //////////////////////////////////////////////////////////////////////////////// | 38 //////////////////////////////////////////////////////////////////////////////// |
| 39 GrAADistanceFieldPathRenderer::GrAADistanceFieldPathRenderer(GrContext* context) |
| 40 : fContext(context) |
| 41 , fAtlas(NULL) |
| 42 , fEffectFlags(kInvalid_DistanceFieldEffectFlag) { |
| 43 } |
| 44 |
| 40 GrAADistanceFieldPathRenderer::~GrAADistanceFieldPathRenderer() { | 45 GrAADistanceFieldPathRenderer::~GrAADistanceFieldPathRenderer() { |
| 41 PathDataList::Iter iter; | 46 PathDataList::Iter iter; |
| 42 iter.init(fPathList, PathDataList::Iter::kHead_IterStart); | 47 iter.init(fPathList, PathDataList::Iter::kHead_IterStart); |
| 43 PathData* pathData; | 48 PathData* pathData; |
| 44 while ((pathData = iter.get())) { | 49 while ((pathData = iter.get())) { |
| 45 iter.next(); | 50 iter.next(); |
| 46 fPathList.remove(pathData); | 51 fPathList.remove(pathData); |
| 47 SkDELETE(pathData); | 52 SkDELETE(pathData); |
| 48 } | 53 } |
| 49 | 54 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 278 |
| 274 // tell the atlas to free the plot | 279 // tell the atlas to free the plot |
| 275 GrAtlas::RemovePlot(&fPlotUsage, plot); | 280 GrAtlas::RemovePlot(&fPlotUsage, plot); |
| 276 | 281 |
| 277 return true; | 282 return true; |
| 278 } | 283 } |
| 279 | 284 |
| 280 bool GrAADistanceFieldPathRenderer::internalDrawPath(const SkPath& path, | 285 bool GrAADistanceFieldPathRenderer::internalDrawPath(const SkPath& path, |
| 281 const PathData* pathData, | 286 const PathData* pathData, |
| 282 GrDrawTarget* target) { | 287 GrDrawTarget* target) { |
| 283 | |
| 284 GrTexture* texture = fAtlas->getTexture(); | 288 GrTexture* texture = fAtlas->getTexture(); |
| 285 GrDrawState* drawState = target->drawState(); | 289 GrDrawState* drawState = target->drawState(); |
| 286 GrDrawState::AutoRestoreEffects are(drawState); | 290 GrDrawState::AutoRestoreEffects are(drawState); |
| 287 | 291 |
| 288 SkASSERT(pathData->fPlot); | 292 SkASSERT(pathData->fPlot); |
| 289 GrDrawTarget::DrawToken drawToken = target->getCurrentDrawToken(); | 293 GrDrawTarget::DrawToken drawToken = target->getCurrentDrawToken(); |
| 290 pathData->fPlot->setDrawToken(drawToken); | 294 pathData->fPlot->setDrawToken(drawToken); |
| 291 | 295 |
| 292 // make me some vertices | 296 // make me some vertices |
| 293 drawState->setVertexAttribs<gSDFPathVertexAttribs>(SK_ARRAY_COUNT(gSDFPathVe
rtexAttribs), | 297 drawState->setVertexAttribs<gSDFPathVertexAttribs>(SK_ARRAY_COUNT(gSDFPathVe
rtexAttribs), |
| 294 kSDFPathVASize); | 298 kSDFPathVASize); |
| 295 void* vertices = NULL; | 299 void* vertices = NULL; |
| 296 void* indices = NULL; | 300 bool success = target->reserveVertexAndIndexSpace(4, 0, &vertices, NULL); |
| 297 bool success = target->reserveVertexAndIndexSpace(4, 6, &vertices, &indices)
; | |
| 298 GrAlwaysAssert(success); | 301 GrAlwaysAssert(success); |
| 299 | 302 |
| 300 SkScalar dx = pathData->fBounds.fLeft; | 303 SkScalar dx = pathData->fBounds.fLeft; |
| 301 SkScalar dy = pathData->fBounds.fTop; | 304 SkScalar dy = pathData->fBounds.fTop; |
| 302 SkScalar width = pathData->fBounds.width(); | 305 SkScalar width = pathData->fBounds.width(); |
| 303 SkScalar height = pathData->fBounds.height(); | 306 SkScalar height = pathData->fBounds.height(); |
| 304 | 307 |
| 305 SkScalar invScale = 1.0f/kScaleFactor; | 308 SkScalar invScale = 1.0f/kScaleFactor; |
| 306 dx *= invScale; | 309 dx *= invScale; |
| 307 dy *= invScale; | 310 dy *= invScale; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 321 | 324 |
| 322 // vertex texture coords | 325 // vertex texture coords |
| 323 intptr_t intPtr = reinterpret_cast<intptr_t>(positions); | 326 intptr_t intPtr = reinterpret_cast<intptr_t>(positions); |
| 324 SkPoint* textureCoords = reinterpret_cast<SkPoint*>(intPtr + vertSize - size
of(SkPoint)); | 327 SkPoint* textureCoords = reinterpret_cast<SkPoint*>(intPtr + vertSize - size
of(SkPoint)); |
| 325 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFix
edX(tx)), | 328 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFix
edX(tx)), |
| 326 SkFixedToFloat(texture->texturePriv().normalizeFix
edY(ty)), | 329 SkFixedToFloat(texture->texturePriv().normalizeFix
edY(ty)), |
| 327 SkFixedToFloat(texture->texturePriv().normalizeFix
edX(tx + tw)), | 330 SkFixedToFloat(texture->texturePriv().normalizeFix
edX(tx + tw)), |
| 328 SkFixedToFloat(texture->texturePriv().normalizeFix
edY(ty + th)), | 331 SkFixedToFloat(texture->texturePriv().normalizeFix
edY(ty + th)), |
| 329 vertSize); | 332 vertSize); |
| 330 | 333 |
| 331 uint16_t* indexPtr = reinterpret_cast<uint16_t*>(indices); | |
| 332 *indexPtr++ = 0; | |
| 333 *indexPtr++ = 1; | |
| 334 *indexPtr++ = 2; | |
| 335 *indexPtr++ = 0; | |
| 336 *indexPtr++ = 2; | |
| 337 *indexPtr++ = 3; | |
| 338 | |
| 339 // set up any flags | 334 // set up any flags |
| 340 uint32_t flags = 0; | 335 uint32_t flags = 0; |
| 341 const SkMatrix& vm = drawState->getViewMatrix(); | 336 const SkMatrix& vm = drawState->getViewMatrix(); |
| 342 flags |= vm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; | 337 flags |= vm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; |
| 343 | 338 |
| 344 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_
FilterMode); | 339 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_
FilterMode); |
| 345 drawState->setGeometryProcessor(GrDistanceFieldNoGammaTextureEffect::Create(
texture, | 340 if (flags != fEffectFlags) { |
| 346
params, | 341 fCachedGeometryProcessor.reset(GrDistanceFieldNoGammaTextureEffect::Crea
te(texture, |
| 347
flags))->unref(); | 342
params, |
| 348 | 343
flags)); |
| 344 fEffectFlags = flags; |
| 345 } |
| 346 drawState->setGeometryProcessor(fCachedGeometryProcessor.get()); |
| 349 | 347 |
| 350 vm.mapRect(&r); | 348 vm.mapRect(&r); |
| 349 target->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); |
| 351 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &r); | 350 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &r); |
| 352 target->resetVertexSource(); | 351 target->resetVertexSource(); |
| 353 target->resetIndexSource(); | |
| 354 | 352 |
| 355 return true; | 353 return true; |
| 356 } | 354 } |
| 357 | 355 |
| OLD | NEW |