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
diff --git a/gpu/include/GrDrawTarget.h b/gpu/include/GrDrawTarget.h
index 177c363..4431dc0 100644
--- a/gpu/include/GrDrawTarget.h
+++ b/gpu/include/GrDrawTarget.h
@@ -100,23 +100,6 @@
};
/**
- * 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
* out the client settable stencil bits. So multipass algorithms
@@ -1234,9 +1217,9 @@
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 2ec10ae..ede6b3b 100644
--- a/gpu/include/GrGpu.h
+++ b/gpu/include/GrGpu.h
@@ -344,16 +344,9 @@
// 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 eb65eff..e0f6855 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 f1f1136..ad066d8 100644
--- a/gpu/src/GrDrawTarget.cpp
+++ b/gpu/src/GrDrawTarget.cpp
@@ -792,6 +792,10 @@
}
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 011d39d..c89dd4e 100644
--- a/gpu/src/GrGpu.cpp
+++ b/gpu/src/GrGpu.cpp
@@ -257,14 +257,6 @@
////////////////////////////////////////////////////////////////////////////////
-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 @@
}
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 @@
}
}
}
+ // 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 b8a0406..2498972 100644
--- a/gpu/src/GrGpuGL.cpp
+++ b/gpu/src/GrGpuGL.cpp
@@ -578,8 +578,7 @@
fHWDrawState.fStencilSettings.invalidate();
fHWStencilClip = false;
- fClipState.fClipIsDirty = true;
- fClipState.fClipInStencil = false;
+ fClipInStencil = false;
fHWGeometryState.fIndexBuffer = NULL;
fHWGeometryState.fVertexBuffer = NULL;
@@ -1761,7 +1760,7 @@
// 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 b2aba4c..a8eb1f5 100644
--- a/gpu/src/GrInOrderDrawBuffer.cpp
+++ b/gpu/src/GrInOrderDrawBuffer.cpp
@@ -612,6 +612,7 @@
fClipSet = false;
}
-void GrInOrderDrawBuffer::clipWillBeSet(const GrClip& newClip) {
+void GrInOrderDrawBuffer::clipWillBeSet(const GrClip& newClip) {
+ INHERITED::clipWillBeSet(newClip);
fClipSet = true;
}