From dea2f8d86378b791a2de94384a18e29f13f65a3e Mon Sep 17 00:00:00 2001 From: "bsalomon@google.com" Date: Mon, 1 Aug 2011 15:51:05 +0000 Subject: [PATCH] Remove unnecessary dirty clip flag in GrGpu, remove getUsableStencilBits() Review URL: http://codereview.appspot.com/4828050/ git-svn-id: http://skia.googlecode.com/svn/trunk@2011 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gpu/include/GrDrawTarget.h | 23 +++-------------------- gpu/include/GrGpu.h | 13 +++---------- gpu/include/GrStencil.h | 12 +++++------- gpu/src/GrDrawTarget.cpp | 4 ++++ gpu/src/GrGpu.cpp | 27 +++++++++------------------ gpu/src/GrGpuGL.cpp | 5 ++--- gpu/src/GrInOrderDrawBuffer.cpp | 3 ++- 7 files changed, 28 insertions(+), 59 deletions(-) diff --git a/gpu/include/GrDrawTarget.h b/gpu/include/GrDrawTarget.h index 177c363c6f..4431dc0839 100644 --- a/gpu/include/GrDrawTarget.h +++ b/gpu/include/GrDrawTarget.h @@ -99,23 +99,6 @@ public: kCW_DrawFace, }; - /** - * The DrawTarget may reserve some of the high bits of the stencil. The draw - * target will automatically trim reference and mask values so that the - * client doesn't overwrite these bits. - * The number of bits available is relative to the currently set render - *target. - * @return the number of bits usable by the draw target client. - */ - int getUsableStencilBits() const { - int bits = fCurrDrawState.fRenderTarget->stencilBits(); - if (bits) { - return bits - 1; - } else { - return 0; - } - } - /** * Sets the stencil settings to use for the next draw. * Changing the clip has the side-effect of possibly zeroing @@ -1234,9 +1217,9 @@ protected: virtual void onDrawNonIndexed(GrPrimitiveType type, int startVertex, int vertexCount) = 0; - // subclass overrides to be notified when clip is set. - virtual void clipWillBeSet(const GrClip& clip) = 0; - + // subclass overrides to be notified when clip is set. Must call + // INHERITED::clipwillBeSet + virtual void clipWillBeSet(const GrClip& clip); // Helpers for drawRect, protected so subclasses that override drawRect // can use them. diff --git a/gpu/include/GrGpu.h b/gpu/include/GrGpu.h index 2ec10aec66..ede6b3b4ee 100644 --- a/gpu/include/GrGpu.h +++ b/gpu/include/GrGpu.h @@ -344,16 +344,9 @@ protected: // clipping. }; - /** - * Extensions to GrDrawTarget::StateBits to implement stencil clipping - */ - struct ClipState { - bool fClipInStencil; - bool fClipIsDirty; - } fClipState; - - // GrDrawTarget override - virtual void clipWillBeSet(const GrClip& newClip); + // keep track of whether we are using stencil clipping (as opposed to + // scissor). + bool fClipInStencil; // prepares clip flushes gpu state before a draw bool setupClipAndFlushState(GrPrimitiveType type); diff --git a/gpu/include/GrStencil.h b/gpu/include/GrStencil.h index eb65eff828..e0f685564c 100644 --- a/gpu/include/GrStencil.h +++ b/gpu/include/GrStencil.h @@ -16,17 +16,15 @@ * GrDrawTarget class. The GrDrawTarget makes a subset of the stencil buffer * bits available for other uses by external code (clients). Client code can * modify these bits. GrDrawTarget will ignore ref, mask, and writemask bits - * provided by clients that overlap the bits used to implement clipping. The - * client can use the getUsableStencilBits() function to find out how many - * client accessible stencil bits are available. + * provided by clients that overlap the bits used to implement clipping. * * When code outside the GrDrawTarget class uses the stencil buffer the contract * is as follows: * - * > Normal stencil funcs allow the GrGpu client to modify the client bits of - * the stencil buffer outside of the clip. - * > Special functions allow a test against the clip. These are more limited - * than the general stencil functions. + * > Normal stencil funcs allow the client to pass / fail regardless of the + * reserved clip bits. + * > Additional functions allow a test against the clip along with a limited + * set of tests against the client bits. * > Client can assume all client bits are zero initially. * > Client must ensure that after all its passes are finished it has only * written to the color buffer in the region inside the clip. Furthermore, it diff --git a/gpu/src/GrDrawTarget.cpp b/gpu/src/GrDrawTarget.cpp index f1f113681b..ad066d8609 100644 --- a/gpu/src/GrDrawTarget.cpp +++ b/gpu/src/GrDrawTarget.cpp @@ -792,6 +792,10 @@ GrVertexLayout GrDrawTarget::GetRectVertexLayout(StageBitfield stageEnableBitfie } return layout; } + +void GrDrawTarget::clipWillBeSet(const GrClip& clip) { +} + void GrDrawTarget::SetRectVertices(const GrRect& rect, const GrMatrix* matrix, const GrRect* srcRects[], diff --git a/gpu/src/GrGpu.cpp b/gpu/src/GrGpu.cpp index 011d39d58e..c89dd4e4bb 100644 --- a/gpu/src/GrGpu.cpp +++ b/gpu/src/GrGpu.cpp @@ -257,14 +257,6 @@ const GrVertexBuffer* GrGpu::getUnitSquareVertexBuffer() const { //////////////////////////////////////////////////////////////////////////////// -void GrGpu::clipWillBeSet(const GrClip& newClip) { - if (newClip != fClip) { - fClipState.fClipIsDirty = true; - } -} - -//////////////////////////////////////////////////////////////////////////////// - // stencil settings to use when clip is in stencil const GrStencilSettings GrGpu::gClipStencilSettings = { kKeep_StencilOp, kKeep_StencilOp, @@ -402,13 +394,12 @@ bool GrGpu::setupClipAndFlushState(GrPrimitiveType type) { } r = &clipRect; - fClipState.fClipInStencil = !fClip.isRect() && - !fClip.isEmpty() && - !bounds.isEmpty(); + // use the stencil clip if we can't represent the clip as a rectangle. + fClipInStencil = !fClip.isRect() && !fClip.isEmpty() && + !bounds.isEmpty(); - if (fClipState.fClipInStencil && - (fClipState.fClipIsDirty || - fClip != rt.fLastStencilClip)) { + if (fClipInStencil && + fClip != rt.fLastStencilClip) { rt.fLastStencilClip = fClip; // we set the current clip to the bounds so that our recursive @@ -533,12 +524,12 @@ bool GrGpu::setupClipAndFlushState(GrPrimitiveType type) { } } } + // restore clip fClip = clip; - // recusive draws would have disabled this. - fClipState.fClipInStencil = true; + // recusive draws would have disabled this since they drew with + // the clip bounds as clip. + fClipInStencil = true; } - - fClipState.fClipIsDirty = false; } // Must flush the scissor after graphics state diff --git a/gpu/src/GrGpuGL.cpp b/gpu/src/GrGpuGL.cpp index b8a04068ed..249897246c 100644 --- a/gpu/src/GrGpuGL.cpp +++ b/gpu/src/GrGpuGL.cpp @@ -578,8 +578,7 @@ void GrGpuGL::resetContext() { fHWDrawState.fStencilSettings.invalidate(); fHWStencilClip = false; - fClipState.fClipIsDirty = true; - fClipState.fClipInStencil = false; + fClipInStencil = false; fHWGeometryState.fIndexBuffer = NULL; fHWGeometryState.fVertexBuffer = NULL; @@ -1761,7 +1760,7 @@ void GrGpuGL::flushStencil() { // use stencil for clipping if clipping is enabled and the clip // has been written into the stencil. - bool stencilClip = fClipState.fClipInStencil && + bool stencilClip = fClipInStencil && (kClip_StateBit & fCurrDrawState.fFlagBits); bool stencilChange = fHWStencilClip != stencilClip || fHWDrawState.fStencilSettings != *settings || diff --git a/gpu/src/GrInOrderDrawBuffer.cpp b/gpu/src/GrInOrderDrawBuffer.cpp index b2aba4c5b6..a8eb1f5d09 100644 --- a/gpu/src/GrInOrderDrawBuffer.cpp +++ b/gpu/src/GrInOrderDrawBuffer.cpp @@ -612,6 +612,7 @@ void GrInOrderDrawBuffer::pushClip() { fClipSet = false; } -void GrInOrderDrawBuffer::clipWillBeSet(const GrClip& newClip) { +void GrInOrderDrawBuffer::clipWillBeSet(const GrClip& newClip) { + INHERITED::clipWillBeSet(newClip); fClipSet = true; }