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
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index cca476b..712eff6 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -836,7 +836,7 @@
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;
/**
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index acae5b2..a28f1bc 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -1654,8 +1654,8 @@
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 {
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp
index f114ccc..2a81e26 100644
--- a/src/gpu/GrDrawState.cpp
+++ b/src/gpu/GrDrawState.cpp
@@ -64,6 +64,9 @@
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());
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index 90c35f1..5b1194d 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -94,7 +94,7 @@
* 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*);
diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp
index 804165b..19f18b5 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -27,7 +27,10 @@
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 @@
fCurrVertex = 0;
GrSafeSetNull(fCurrTexture);
}
- drawState->disableStages();
- fDrawTarget = NULL;
}
GrTextContext::GrTextContext(GrContext* context, const GrPaint& paint) : fPaint(paint) {
@@ -93,7 +94,7 @@
fAutoMatrix.setIdentity(fContext, &fPaint);
- fDrawTarget = NULL;
+ fDrawTarget = fContext->getTextTarget();
fVertices = NULL;
fMaxVertices = 0;
@@ -101,9 +102,6 @@
GrTextContext::~GrTextContext() {
this->flushGlyphs();
- if (fDrawTarget) {
- fDrawTarget->drawState()->disableStages();
- }
}
void GrTextContext::flush() {
@@ -123,6 +121,9 @@
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 @@
// 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 @@
// 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());
}