Make text context responsible for setting GrPaint on GrDrawState.
R=robertphillips@google.com Review URL: https://codereview.chromium.org/16928010 git-svn-id: http://skia.googlecode.com/svn/trunk@9588 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
07f01471c8
commit
21c10c5ff5
@ -836,7 +836,7 @@ public:
|
||||
GrGpu* getGpu() { return fGpu; }
|
||||
const GrGpu* getGpu() const { return fGpu; }
|
||||
GrFontCache* getFontCache() { return fFontCache; }
|
||||
GrDrawTarget* getTextTarget(const GrPaint& paint);
|
||||
GrDrawTarget* getTextTarget();
|
||||
const GrIndexBuffer* getQuadIndexBuffer() const;
|
||||
|
||||
/**
|
||||
|
@ -1654,8 +1654,8 @@ void GrContext::setupDrawBuffer() {
|
||||
fDrawBuffer->setDrawState(fDrawState);
|
||||
}
|
||||
|
||||
GrDrawTarget* GrContext::getTextTarget(const GrPaint& paint) {
|
||||
return this->prepareToDraw(&paint, BUFFERED_DRAW);
|
||||
GrDrawTarget* GrContext::getTextTarget() {
|
||||
return this->prepareToDraw(NULL, BUFFERED_DRAW);
|
||||
}
|
||||
|
||||
const GrIndexBuffer* GrContext::getQuadIndexBuffer() const {
|
||||
|
@ -64,6 +64,9 @@ void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende
|
||||
fCommon.fStencilSettings.setDisabled();
|
||||
this->resetStateFlags();
|
||||
|
||||
// Enable the clip bit
|
||||
this->enableState(GrDrawState::kClip_StateBit);
|
||||
|
||||
this->setColor(paint.getColor());
|
||||
this->setState(GrDrawState::kDither_StateBit, paint.isDither());
|
||||
this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias());
|
||||
|
@ -94,7 +94,7 @@ public:
|
||||
* Initializes the GrDrawState based on a GrPaint, view matrix and render target. Note that
|
||||
* GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that have no GrPaint
|
||||
* equivalents are set to default values. GrPaint has fewer stages than GrDrawState. The extra
|
||||
* GrDrawState stages are disabled.
|
||||
* GrDrawState stages are disabled. Clipping will be enabled.
|
||||
*/
|
||||
void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarget*);
|
||||
|
||||
|
@ -27,7 +27,10 @@ void GrTextContext::flushGlyphs() {
|
||||
if (NULL == fDrawTarget) {
|
||||
return;
|
||||
}
|
||||
GrDrawTarget::AutoStateRestore asr(fDrawTarget, GrDrawTarget::kPreserve_ASRInit);
|
||||
GrDrawState* drawState = fDrawTarget->drawState();
|
||||
drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget());
|
||||
|
||||
if (fCurrVertex > 0) {
|
||||
// setup our sampler state for our text texture/atlas
|
||||
GrAssert(GrIsALIGN4(fCurrVertex));
|
||||
@ -68,8 +71,6 @@ void GrTextContext::flushGlyphs() {
|
||||
fCurrVertex = 0;
|
||||
GrSafeSetNull(fCurrTexture);
|
||||
}
|
||||
drawState->disableStages();
|
||||
fDrawTarget = NULL;
|
||||
}
|
||||
|
||||
GrTextContext::GrTextContext(GrContext* context, const GrPaint& paint) : fPaint(paint) {
|
||||
@ -93,7 +94,7 @@ GrTextContext::GrTextContext(GrContext* context, const GrPaint& paint) : fPaint(
|
||||
|
||||
fAutoMatrix.setIdentity(fContext, &fPaint);
|
||||
|
||||
fDrawTarget = NULL;
|
||||
fDrawTarget = fContext->getTextTarget();
|
||||
|
||||
fVertices = NULL;
|
||||
fMaxVertices = 0;
|
||||
@ -101,9 +102,6 @@ GrTextContext::GrTextContext(GrContext* context, const GrPaint& paint) : fPaint(
|
||||
|
||||
GrTextContext::~GrTextContext() {
|
||||
this->flushGlyphs();
|
||||
if (fDrawTarget) {
|
||||
fDrawTarget->drawState()->disableStages();
|
||||
}
|
||||
}
|
||||
|
||||
void GrTextContext::flush() {
|
||||
@ -123,6 +121,9 @@ extern const GrVertexAttrib gTextVertexAttribs[] = {
|
||||
void GrTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
|
||||
GrFixed vx, GrFixed vy,
|
||||
GrFontScaler* scaler) {
|
||||
if (NULL == fDrawTarget) {
|
||||
return;
|
||||
}
|
||||
if (NULL == fStrike) {
|
||||
fStrike = fContext->getFontCache()->getStrike(scaler);
|
||||
}
|
||||
@ -205,18 +206,14 @@ HAS_ATLAS:
|
||||
// If we need to reserve vertices allow the draw target to suggest
|
||||
// a number of verts to reserve and whether to perform a flush.
|
||||
fMaxVertices = kMinRequestedVerts;
|
||||
bool flush = false;
|
||||
fDrawTarget = fContext->getTextTarget(fPaint);
|
||||
if (NULL != fDrawTarget) {
|
||||
fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(SK_ARRAY_COUNT(gTextVertexAttribs));
|
||||
flush = fDrawTarget->geometryHints(&fMaxVertices, NULL);
|
||||
}
|
||||
fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
|
||||
SK_ARRAY_COUNT(gTextVertexAttribs));
|
||||
bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL);
|
||||
if (flush) {
|
||||
this->flushGlyphs();
|
||||
fContext->flush();
|
||||
// flushGlyphs() will reset fDrawTarget to NULL.
|
||||
fDrawTarget = fContext->getTextTarget(fPaint);
|
||||
fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(SK_ARRAY_COUNT(gTextVertexAttribs));
|
||||
fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
|
||||
SK_ARRAY_COUNT(gTextVertexAttribs));
|
||||
}
|
||||
fMaxVertices = kDefaultRequestedVerts;
|
||||
// ignore return, no point in flushing again.
|
||||
@ -229,11 +226,10 @@ HAS_ATLAS:
|
||||
// don't exceed the limit of the index buffer
|
||||
fMaxVertices = maxQuadVertices;
|
||||
}
|
||||
bool success = fDrawTarget->reserveVertexAndIndexSpace(
|
||||
fMaxVertices,
|
||||
0,
|
||||
GrTCast<void**>(&fVertices),
|
||||
NULL);
|
||||
bool success = fDrawTarget->reserveVertexAndIndexSpace(fMaxVertices,
|
||||
0,
|
||||
GrTCast<void**>(&fVertices),
|
||||
NULL);
|
||||
GrAlwaysAssert(success);
|
||||
GrAssert(2*sizeof(GrPoint) == fDrawTarget->getDrawState().getVertexSize());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user