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
This commit is contained in:
parent
27c46a08a9
commit
6d22ecaa71
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -74,7 +74,7 @@ GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context,
|
||||
|
||||
fEffectTextureUniqueID = SK_InvalidUniqueID;
|
||||
fEffectColor = GrColor_ILLEGAL;
|
||||
fEffectFlags = 0;
|
||||
fEffectFlags = kInvalid_DistanceFieldEffectFlag;
|
||||
|
||||
fVertices = NULL;
|
||||
fCurrVertex = 0;
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user