diff options
author | jvanverth <jvanverth@google.com> | 2014-10-28 11:10:48 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-28 11:10:49 -0700 |
commit | 6d22ecaa71cf4400feebc3438bf0e0dd68179500 (patch) | |
tree | bf091a4cbe05803189dc207bbfa89c24d11ff192 /src | |
parent | 27c46a08a9210e9306b8ea1b00349ec198153c38 (diff) |
Distance field path optimizations and clean up.
Adds the following:
- Use cached geometry processor rather than recreating all the time.
- Use context's quad index buffer.
Review URL: https://codereview.chromium.org/683923002
Diffstat (limited to 'src')
-rwxr-xr-x | src/gpu/GrAADistanceFieldPathRenderer.cpp | 32 | ||||
-rwxr-xr-x | src/gpu/GrAADistanceFieldPathRenderer.h | 9 | ||||
-rwxr-xr-x | src/gpu/GrDistanceFieldTextContext.cpp | 2 | ||||
-rw-r--r-- | src/gpu/effects/GrDistanceFieldTextureEffect.h | 2 |
4 files changed, 22 insertions, 23 deletions
diff --git a/src/gpu/GrAADistanceFieldPathRenderer.cpp b/src/gpu/GrAADistanceFieldPathRenderer.cpp index e2cee650dc..bcdbd8ed22 100755 --- a/src/gpu/GrAADistanceFieldPathRenderer.cpp +++ b/src/gpu/GrAADistanceFieldPathRenderer.cpp @@ -21,7 +21,6 @@ #define ATLAS_TEXTURE_WIDTH 1024 #define ATLAS_TEXTURE_HEIGHT 1024 - #define PLOT_WIDTH 256 #define PLOT_HEIGHT 256 @@ -37,6 +36,12 @@ static int g_NumFreedPaths = 0; #endif //////////////////////////////////////////////////////////////////////////////// +GrAADistanceFieldPathRenderer::GrAADistanceFieldPathRenderer(GrContext* context) + : fContext(context) + , fAtlas(NULL) + , fEffectFlags(kInvalid_DistanceFieldEffectFlag) { +} + GrAADistanceFieldPathRenderer::~GrAADistanceFieldPathRenderer() { PathDataList::Iter iter; iter.init(fPathList, PathDataList::Iter::kHead_IterStart); @@ -280,7 +285,6 @@ bool GrAADistanceFieldPathRenderer::freeUnusedPlot() { bool GrAADistanceFieldPathRenderer::internalDrawPath(const SkPath& path, const PathData* pathData, GrDrawTarget* target) { - GrTexture* texture = fAtlas->getTexture(); GrDrawState* drawState = target->drawState(); GrDrawState::AutoRestoreEffects are(drawState); @@ -293,8 +297,7 @@ bool GrAADistanceFieldPathRenderer::internalDrawPath(const SkPath& path, drawState->setVertexAttribs<gSDFPathVertexAttribs>(SK_ARRAY_COUNT(gSDFPathVertexAttribs), kSDFPathVASize); void* vertices = NULL; - void* indices = NULL; - bool success = target->reserveVertexAndIndexSpace(4, 6, &vertices, &indices); + bool success = target->reserveVertexAndIndexSpace(4, 0, &vertices, NULL); GrAlwaysAssert(success); SkScalar dx = pathData->fBounds.fLeft; @@ -328,29 +331,24 @@ bool GrAADistanceFieldPathRenderer::internalDrawPath(const SkPath& path, SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty + th)), vertSize); - uint16_t* indexPtr = reinterpret_cast<uint16_t*>(indices); - *indexPtr++ = 0; - *indexPtr++ = 1; - *indexPtr++ = 2; - *indexPtr++ = 0; - *indexPtr++ = 2; - *indexPtr++ = 3; - // set up any flags uint32_t flags = 0; const SkMatrix& vm = drawState->getViewMatrix(); flags |= vm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_FilterMode); - drawState->setGeometryProcessor(GrDistanceFieldNoGammaTextureEffect::Create(texture, - params, - flags))->unref(); - + if (flags != fEffectFlags) { + fCachedGeometryProcessor.reset(GrDistanceFieldNoGammaTextureEffect::Create(texture, + params, + flags)); + fEffectFlags = flags; + } + drawState->setGeometryProcessor(fCachedGeometryProcessor.get()); vm.mapRect(&r); + target->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &r); target->resetVertexSource(); - target->resetIndexSource(); return true; } diff --git a/src/gpu/GrAADistanceFieldPathRenderer.h b/src/gpu/GrAADistanceFieldPathRenderer.h index 4c09f127c9..40430bbd2f 100755 --- a/src/gpu/GrAADistanceFieldPathRenderer.h +++ b/src/gpu/GrAADistanceFieldPathRenderer.h @@ -21,11 +21,7 @@ class GrPlot; class GrAADistanceFieldPathRenderer : public GrPathRenderer { public: - GrAADistanceFieldPathRenderer(GrContext* context) - : fContext(context) - , fAtlas(NULL) { - } - + GrAADistanceFieldPathRenderer(GrContext* context); virtual ~GrAADistanceFieldPathRenderer(); virtual bool canDrawPath(const SkPath& path, @@ -63,6 +59,9 @@ private: GrContext* fContext; GrAtlas* fAtlas; + SkAutoTUnref<GrGeometryProcessor> fCachedGeometryProcessor; + // current set of flags used to create the cached geometry processor + uint32_t fEffectFlags; GrAtlas::ClientPlotUsage fPlotUsage; SkTDynamicHash<PathData, uint32_t> fPathCache; PathDataList fPathList; diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp index 66ec123ae7..118565af29 100755 --- a/src/gpu/GrDistanceFieldTextContext.cpp +++ b/src/gpu/GrDistanceFieldTextContext.cpp @@ -74,7 +74,7 @@ GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, fEffectTextureUniqueID = SK_InvalidUniqueID; fEffectColor = GrColor_ILLEGAL; - fEffectFlags = 0; + fEffectFlags = kInvalid_DistanceFieldEffectFlag; fVertices = NULL; fCurrVertex = 0; diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.h b/src/gpu/effects/GrDistanceFieldTextureEffect.h index c24673bd27..ea02d195b7 100644 --- a/src/gpu/effects/GrDistanceFieldTextureEffect.h +++ b/src/gpu/effects/GrDistanceFieldTextureEffect.h @@ -21,6 +21,8 @@ enum GrDistanceFieldEffectFlags { kUseLCD_DistanceFieldEffectFlag = 0x04, // use lcd text kBGR_DistanceFieldEffectFlag = 0x08, // lcd display has bgr order kPortrait_DistanceFieldEffectFlag = 0x10, // lcd display is in portrait mode (not used yet) + + kInvalid_DistanceFieldEffectFlag = 0x80, // invalid state (for initialization) kUniformScale_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag | kRectToRect_DistanceFieldEffectFlag, |