diff options
author | 2012-07-23 17:39:44 +0000 | |
---|---|---|
committer | 2012-07-23 17:39:44 +0000 | |
commit | a6f11c4f717961070cd6fc5e60c361db14c5c4f3 (patch) | |
tree | 87e883cf1f09ac614c63e589e130f768b6cccea6 /src/gpu/GrClip.cpp | |
parent | c1d1f414a08de25d8cbf4ba08fc64d701ffca32e (diff) |
Gave GrClip an SkClipStack-style iterator
http://codereview.appspot.com/6434046/
git-svn-id: http://skia.googlecode.com/svn/trunk@4723 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/GrClip.cpp')
-rw-r--r-- | src/gpu/GrClip.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/gpu/GrClip.cpp b/src/gpu/GrClip.cpp index 7803edcf75..84f58c63ce 100644 --- a/src/gpu/GrClip.cpp +++ b/src/gpu/GrClip.cpp @@ -153,3 +153,95 @@ void GrClip::setFromIterator(GrClipIterator* iter, GrScalar tx, GrScalar ty, fConservativeBoundsValid = true; } } + +/////////////////////////////////////////////////////////////////////////////// + +GrClip::Iter::Iter() + : fStack(NULL) + , fCurIndex(0) { +} + +GrClip::Iter::Iter(const GrClip& stack, IterStart startLoc) + : fStack(&stack) { + this->reset(stack, startLoc); +} + +const GrClip::Iter::Clip* GrClip::Iter::updateClip(int index) { + + if (NULL == fStack) { + return NULL; + } + + GrAssert(0 <= index && index < fStack->getElementCount()); + + + + switch (fStack->getElementType(index)) { + case kRect_ClipType: + fClip.fRect = &fStack->getRect(index); + fClip.fPath = NULL; + break; + case kPath_ClipType: + fClip.fRect = NULL; + fClip.fPath = &fStack->getPath(index); + break; + } + fClip.fOp = fStack->getOp(index); + fClip.fDoAA = fStack->getDoAA(index); + return &fClip; +} + +const GrClip::Iter::Clip* GrClip::Iter::next() { + + if (NULL == fStack) { + return NULL; + } + + if (0 > fCurIndex || fCurIndex >= fStack->getElementCount()) { + return NULL; + } + + int oldIndex = fCurIndex; + ++fCurIndex; + + return this->updateClip(oldIndex); +} + +const GrClip::Iter::Clip* GrClip::Iter::prev() { + + if (NULL == fStack) { + return NULL; + } + + if (0 > fCurIndex || fCurIndex >= fStack->getElementCount()) { + return NULL; + } + + int oldIndex = fCurIndex; + --fCurIndex; + + return this->updateClip(oldIndex); +} + +const GrClip::Iter::Clip* GrClip::Iter::skipToTopmost(SkRegion::Op op) { + + GrAssert(SkRegion::kReplace_Op == op); + + if (NULL == fStack) { + return NULL; + } + + // GrClip removes all clips below the topmost replace + this->reset(*fStack, kBottom_IterStart); + + return this->next(); +} + +void GrClip::Iter::reset(const GrClip& stack, IterStart startLoc) { + fStack = &stack; + if (kBottom_IterStart == startLoc) { + fCurIndex = 0; + } else { + fCurIndex = fStack->getElementCount()-1; + } +} |