Store clip mask location in GrClipMaskManager as a enum rather than two bools

Review URL: http://codereview.appspot.com/6306092/



git-svn-id: http://skia.googlecode.com/svn/trunk@4274 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2012-06-18 13:44:51 +00:00
parent b702c0fcc0
commit c8f7f47afa
4 changed files with 43 additions and 32 deletions

View File

@ -119,9 +119,9 @@ bool GrClipMaskManager::createClipMask(const GrClip& clipIn,
GrAssert(scissorSettings);
scissorSettings->fEnableScissoring = false;
fClipMaskInStencil = false;
fClipMaskInAlpha = false;
fCurrClipMaskType = kNone_ClipMaskType;
GrDrawState* drawState = fGpu->drawState();
if (!drawState->isClipState()) {
return true;
@ -143,8 +143,6 @@ bool GrClipMaskManager::createClipMask(const GrClip& clipIn,
GrTexture* result = NULL;
GrIRect bound;
if (this->createSoftwareClipMask(fGpu, clipIn, &result, &bound)) {
fClipMaskInAlpha = true;
setup_drawstate_aaclip(fGpu, result, bound);
return true;
}
@ -165,8 +163,6 @@ bool GrClipMaskManager::createClipMask(const GrClip& clipIn,
GrTexture* result = NULL;
GrIRect bound;
if (this->createAlphaClipMask(fGpu, clipIn, &result, &bound)) {
fClipMaskInAlpha = true;
setup_drawstate_aaclip(fGpu, result, bound);
return true;
}
@ -208,10 +204,10 @@ bool GrClipMaskManager::createClipMask(const GrClip& clipIn,
scissorSettings->fEnableScissoring = true;
// use the stencil clip if we can't represent the clip as a rectangle.
fClipMaskInStencil = !clipIn.isRect() && !clipIn.isEmpty() &&
!bounds.isEmpty();
bool useStencil = !clipIn.isRect() && !clipIn.isEmpty() &&
!bounds.isEmpty();
if (fClipMaskInStencil) {
if (useStencil) {
return this->createStencilClipMask(clipIn, bounds, scissorSettings);
}
@ -546,13 +542,15 @@ bool GrClipMaskManager::createAlphaClipMask(const GrClip& clipIn,
GrTexture** result,
GrIRect *resultBounds) {
GrAssert(kNone_ClipMaskType == fCurrClipMaskType);
if (this->clipMaskPreamble(clipIn, result, resultBounds)) {
fCurrClipMaskType = kAlpha_ClipMaskType;
return true;
}
GrTexture* accum = fAACache.getLastMask();
if (NULL == accum) {
fClipMaskInAlpha = false;
fAACache.reset();
return false;
}
@ -613,7 +611,6 @@ bool GrClipMaskManager::createAlphaClipMask(const GrClip& clipIn,
getTemp(*resultBounds, &temp);
if (NULL == temp.texture()) {
fClipMaskInAlpha = false;
fAACache.reset();
return false;
}
@ -659,7 +656,7 @@ bool GrClipMaskManager::createAlphaClipMask(const GrClip& clipIn,
}
*result = accum;
fCurrClipMaskType = kAlpha_ClipMaskType;
return true;
}
@ -669,7 +666,7 @@ bool GrClipMaskManager::createStencilClipMask(const GrClip& clipIn,
const GrRect& bounds,
ScissoringSettings* scissorSettings) {
GrAssert(fClipMaskInStencil);
GrAssert(kNone_ClipMaskType == fCurrClipMaskType);
GrDrawState* drawState = fGpu->drawState();
GrAssert(drawState->isClipState());
@ -758,7 +755,6 @@ bool GrClipMaskManager::createStencilClipMask(const GrClip& clipIn,
fill, fGpu, false,
true);
if (NULL == pr) {
fClipMaskInStencil = false;
fGpu->setClip(clipCopy); // restore to the original
return false;
}
@ -824,11 +820,10 @@ bool GrClipMaskManager::createStencilClipMask(const GrClip& clipIn,
}
// restore clip
fGpu->setClip(clipCopy);
// recusive draws would have disabled this since they drew with
// the clip bounds as clip.
fClipMaskInStencil = true;
}
// set this last because recursive draws may overwrite it back to kNone.
GrAssert(kNone_ClipMaskType == fCurrClipMaskType);
fCurrClipMaskType = kStencil_ClipMaskType;
return true;
}
@ -950,6 +945,7 @@ GrPathFill invert_fill(GrPathFill fill) {
bool GrClipMaskManager::createSoftwareClipMask(const GrClip& clipIn,
GrTexture** result,
GrIRect *resultBounds) {
GrAssert(kNone_ClipMaskType == fCurrClipMaskType);
if (this->clipMaskPreamble(clipIn, result, resultBounds)) {
return true;
@ -957,7 +953,6 @@ bool GrClipMaskManager::createSoftwareClipMask(const GrClip& clipIn,
GrTexture* accum = fAACache.getLastMask();
if (NULL == accum) {
fClipMaskInAlpha = false;
fAACache.reset();
return false;
}
@ -1057,6 +1052,7 @@ bool GrClipMaskManager::createSoftwareClipMask(const GrClip& clipIn,
*result = accum;
fCurrClipMaskType = kAlpha_ClipMaskType;
return true;
}

View File

@ -285,8 +285,7 @@ class GrClipMaskManager : public GrNoncopyable {
public:
GrClipMaskManager(GrGpu* gpu)
: fGpu(gpu)
, fClipMaskInStencil(false)
, fClipMaskInAlpha(false) {
, fCurrClipMaskType(kNone_ClipMaskType) {
}
bool createClipMask(const GrClip& clip,
@ -294,11 +293,17 @@ public:
void releaseResources();
bool isClipInStencil() const { return fClipMaskInStencil; }
bool isClipInAlpha() const { return fClipMaskInAlpha; }
bool isClipInStencil() const {
return kStencil_ClipMaskType == fCurrClipMaskType;
}
bool isClipInAlpha() const {
return kAlpha_ClipMaskType == fCurrClipMaskType;
}
void resetMask() {
fClipMaskInStencil = false;
void invalidateStencilMask() {
if (kStencil_ClipMaskType == fCurrClipMaskType) {
fCurrClipMaskType = kNone_ClipMaskType;
}
}
void postClipPush() {
@ -350,8 +355,18 @@ public:
private:
GrGpu* fGpu;
bool fClipMaskInStencil; // is the clip mask in the stencil buffer?
bool fClipMaskInAlpha; // is the clip mask in an alpha texture?
/**
* We may represent the clip as a mask in the stencil buffer or as an alpha
* texture. It may be neither because the scissor rect suffices or we
* haven't yet examined the clip.
*/
enum ClipMaskType {
kNone_ClipMaskType,
kStencil_ClipMaskType,
kAlpha_ClipMaskType,
} fCurrClipMaskType;
GrClipMaskCache fAACache; // cache for the AA path
bool createStencilClipMask(const GrClip& clip,

View File

@ -429,7 +429,7 @@ protected:
void finalizeReservedIndices();
// called when the 3D context state is unknown. Subclass should emit any
// assumed 3D context state and dirty any state cache
// assumed 3D context state and dirty any state cache.
virtual void onResetContext() = 0;
@ -558,6 +558,10 @@ private:
void prepareIndexPool();
void resetContext() {
// We call this because the client may have messed with the
// stencil buffer. Perhaps we should detect whether it is a
// internally created stencil buffer and if so skip the invalidate.
fClipMaskManager.invalidateStencilMask();
this->onResetContext();
++fResetTimestamp;
}

View File

@ -508,10 +508,6 @@ void GrGpuGL::onResetContext() {
// stencil on the next draw.
fHWStencilClipMode = GrClipMaskManager::kRespectClip_StencilClipMode;
// TODO: I believe this should actually go in GrGpu::onResetContext
// rather than here
fClipMaskManager.resetMask();
fHWGeometryState.fIndexBuffer = NULL;
fHWGeometryState.fVertexBuffer = NULL;