Use AutoMatrix in GrTextContext

Review URL: https://codereview.appspot.com/6691043

git-svn-id: http://skia.googlecode.com/svn/trunk@5952 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2012-10-15 14:25:50 +00:00
parent 1e269b5a08
commit 858804dfe6
2 changed files with 8 additions and 40 deletions

View File

@ -11,9 +11,9 @@
#ifndef GrTextContext_DEFINED
#define GrTextContext_DEFINED
#include "GrContext.h"
#include "GrGlyph.h"
#include "GrPaint.h"
#include "GrMatrix.h"
struct GrGpuTextVertex;
class GrContext;
@ -50,14 +50,14 @@ private:
kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4,
};
GrGpuTextVertex* fVertices;
GrGpuTextVertex* fVertices;
int32_t fMaxVertices;
GrTexture* fCurrTexture;
int fCurrVertex;
int32_t fMaxVertices;
GrTexture* fCurrTexture;
int fCurrVertex;
GrIRect fClipRect;
GrMatrix fOrigViewMatrix; // restore previous viewmatrix
GrIRect fClipRect;
GrContext::AutoMatrix fAutoMatrix;
};
#endif

View File

@ -89,38 +89,7 @@ GrTextContext::GrTextContext(GrContext* context, const GrPaint& paint) : fPaint(
devConservativeBound.roundOut(&fClipRect);
// save the context's original matrix off and restore in destructor
// this must be done before getTextTarget.
fOrigViewMatrix = fContext->getMatrix();
fContext->setIdentityMatrix();
/*
We need to call preConcatMatrix with our viewmatrix's inverse, for each
texture and mask in the paint. However, computing the inverse can be
expensive, and its possible we may not have any textures or masks, so these
two loops are written such that we only compute the inverse (once) if we
need it. We do this on our copy of the paint rather than directly on the
draw target because we re-provide the paint to the context when we have
to flush our glyphs or draw a glyph as a path midstream.
*/
bool invVMComputed = false;
GrMatrix invVM;
for (int t = 0; t < GrPaint::kMaxColorStages; ++t) {
if (fPaint.isColorStageEnabled(t)) {
if (invVMComputed || fOrigViewMatrix.invert(&invVM)) {
invVMComputed = true;
fPaint.colorSampler(t)->preConcatMatrix(invVM);
}
}
}
for (int m = 0; m < GrPaint::kMaxCoverageStages; ++m) {
if (fPaint.isCoverageStageEnabled(m)) {
if (invVMComputed || fOrigViewMatrix.invert(&invVM)) {
invVMComputed = true;
fPaint.coverageSampler(m)->preConcatMatrix(invVM);
}
}
}
fAutoMatrix.setIdentity(fContext, &fPaint);
fDrawTarget = NULL;
@ -137,7 +106,6 @@ GrTextContext::~GrTextContext() {
if (fDrawTarget) {
fDrawTarget->drawState()->disableStages();
}
fContext->setMatrix(fOrigViewMatrix);
}
void GrTextContext::flush() {