Add support for clipstack to Gr. GrClip is now a list of rects and paths with set operations to combine them. The stencil buffer is used to perform the set operations to put the clip into the stencil buffer. Building Gr's clip from Skia's clipStack is currently disabled due to the fact that Skia's clipStack is relative to the root layer not the current layer. This will be fixed in a subsequent CL.
git-svn-id: http://skia.googlecode.com/svn/trunk@878 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 3dfe02a..e925e53 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -267,19 +267,30 @@
///////////////////////////////////////////////////////////////////////////////
+#define USE_CLIP_STACK 0
+
static void convert_matrixclip(GrContext* context, const SkMatrix& matrix,
- const SkRegion& clip) {
+ const SkClipStack& clipStack,
+ const SkRegion& clipRegion) {
GrMatrix grmat;
SkGr::SkMatrix2GrMatrix(matrix, &grmat);
context->setMatrix(grmat);
+#if USE_CLIP_STACK
SkGrClipIterator iter;
- iter.reset(clip);
- GrClip grc(&iter);
- if (context->getClip() == grc) {
- } else {
- context->setClip(grc);
- }
+ iter.reset(clipStack);
+#else
+ SkGrRegionIterator iter;
+ iter.reset(clipRegion);
+#endif
+ const SkIRect& skBounds = clipRegion.getBounds();
+ GrRect bounds;
+ bounds.setLTRB(GrIntToScalar(skBounds.fLeft),
+ GrIntToScalar(skBounds.fTop),
+ GrIntToScalar(skBounds.fRight),
+ GrIntToScalar(skBounds.fBottom));
+ GrClip grc(&iter, NULL);
+ context->setClip(grc);
}
// call this ever each draw call, to ensure that the context reflects our state,
@@ -289,7 +300,9 @@
fContext->getRenderTarget() != fRenderTarget) {
fContext->setRenderTarget(fRenderTarget);
- convert_matrixclip(fContext, *draw.fMatrix, *draw.fClip);
+ SkASSERT(draw.fClipStack);
+ convert_matrixclip(fContext, *draw.fMatrix,
+ *draw.fClipStack, *draw.fClip);
fNeedPrepareRenderTarget = false;
}
}
@@ -298,16 +311,17 @@
const SkClipStack& clipStack) {
this->INHERITED::setMatrixClip(matrix, clip, clipStack);
- convert_matrixclip(fContext, matrix, clip);
+ convert_matrixclip(fContext, matrix, clipStack, clip);
}
void SkGpuDevice::gainFocus(SkCanvas* canvas, const SkMatrix& matrix,
- const SkRegion& clip) {
+ const SkRegion& clip, const SkClipStack& clipStack) {
+
fContext->setRenderTarget(fRenderTarget);
- this->INHERITED::gainFocus(canvas, matrix, clip);
+ this->INHERITED::gainFocus(canvas, matrix, clip, clipStack);
- convert_matrixclip(fContext, matrix, clip);
+ convert_matrixclip(fContext, matrix, clipStack, clip);
if (fNeedClear) {
fContext->eraseColor(0x0);