Skip to content

Commit

Permalink
Enable rect clips
Browse files Browse the repository at this point in the history
  • Loading branch information
joshualitt authored and Commit bot committed Feb 24, 2015
1 parent 9ece6a9 commit 0413d43
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
37 changes: 22 additions & 15 deletions include/gpu/GrClip.h
Expand Up @@ -25,8 +25,11 @@ struct SkIRect;
*/
class GrClip : SkNoncopyable {
public:
GrClip() : fClipType(kWideOpen_ClipType) {}
GrClip() : fClipType(kWideOpen_ClipType) {
fOrigin.setZero();
}
GrClip(const SkIRect& rect) : fClipType(kIRect_ClipType) {
fOrigin.setZero();
fClip.fIRect = rect;
}
~GrClip() { this->reset(); }
Expand All @@ -38,13 +41,15 @@ class GrClip : SkNoncopyable {
default:
SkFAIL("Incomplete Switch\n");
case kWideOpen_ClipType:
fOrigin.setZero();
break;
case kClipStack_ClipType:
fClip.fClipStack.fStack = SkRef(other.clipStack());
fClip.fClipStack.fOrigin = other.origin();
fClip.fStack = SkRef(other.clipStack());
fOrigin = other.origin();
break;
case kIRect_ClipType:
fClip.fIRect = other.irect();
fOrigin.setZero();
break;
}
return *this;
Expand Down Expand Up @@ -84,19 +89,20 @@ class GrClip : SkNoncopyable {

const SkClipStack* clipStack() const {
SkASSERT(kClipStack_ClipType == fClipType);
return fClip.fClipStack.fStack;
return fClip.fStack;
}

void setClipStack(const SkClipStack* clipStack, const SkIPoint* origin = NULL) {
if (clipStack->isWideOpen()) {
fClipType = kWideOpen_ClipType;
fOrigin.setZero();
} else {
fClipType = kClipStack_ClipType;
fClip.fClipStack.fStack = SkRef(clipStack);
fClip.fStack = SkRef(clipStack);
if (origin) {
fClip.fClipStack.fOrigin = *origin;
fOrigin = *origin;
} else {
fClip.fClipStack.fOrigin.setZero();
fOrigin.setZero();
}
}
}
Expand All @@ -108,15 +114,18 @@ class GrClip : SkNoncopyable {

void reset() {
if (kClipStack_ClipType == fClipType) {
fClip.fClipStack.fStack->unref();
fClip.fClipStack.fStack = NULL;
fClip.fStack->unref();
fClip.fStack = NULL;
}
fClipType = kWideOpen_ClipType;
fOrigin.setZero();
}

// We support this for all cliptypes to simplify the logic a bit in clip mask manager.
// non clipstack clip types MUST have a (0,0) origin
const SkIPoint& origin() const {
SkASSERT(kClipStack_ClipType == fClipType);
return fClip.fClipStack.fOrigin;
SkASSERT(fClipType == kClipStack_ClipType || (fOrigin.fX == 0 && fOrigin.fY == 0));
return fOrigin;
}

bool isWideOpen(const SkRect& rect) const {
Expand Down Expand Up @@ -159,13 +168,11 @@ class GrClip : SkNoncopyable {

private:
union Clip {
struct ClipStack {
const SkClipStack* fStack;
SkIPoint fOrigin;
} fClipStack;
const SkClipStack* fStack;
SkIRect fIRect;
} fClip;

SkIPoint fOrigin;
ClipType fClipType;
};

Expand Down
3 changes: 1 addition & 2 deletions src/gpu/GrClipMaskManager.cpp
Expand Up @@ -228,8 +228,7 @@ bool GrClipMaskManager::setupClipping(GrPipelineBuilder* pipelineBuilder,
SkIRect clipSpaceRTIBounds = SkIRect::MakeWH(rt->width(), rt->height());
const GrClip& clip = pipelineBuilder->clip();
// TODO we shouldn't be ignoring the clip mask manager's clip. This is temporary.
bool ignoreClip = clip.isWideOpen(clipSpaceRTIBounds) ||
GrClip::kIRect_ClipType == clip.clipType();
bool ignoreClip = clip.isWideOpen(clipSpaceRTIBounds);
if (!ignoreClip) {
// The clip mask manager always draws with a single IRect so we special case that logic here
if (GrClip::kIRect_ClipType == clip.clipType()) {
Expand Down

0 comments on commit 0413d43

Please sign in to comment.