2015-02-23 22:44:57 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrClip_DEFINED
|
|
|
|
#define GrClip_DEFINED
|
|
|
|
|
|
|
|
#include "SkClipStack.h"
|
|
|
|
#include "GrSurface.h"
|
|
|
|
|
|
|
|
struct SkIRect;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GrClip encapsulates the information required to construct the clip
|
2015-02-25 21:19:48 +00:00
|
|
|
* masks. 'A GrClip is either wide open, just an IRect, just a Rect, or a full clipstack.
|
2015-02-23 22:44:57 +00:00
|
|
|
* If the clip is a clipstack than the origin is used to translate the stack with
|
|
|
|
* respect to device coordinates. This allows us to use a clip stack that is
|
|
|
|
* specified for a root device with a layer device that is restricted to a subset
|
|
|
|
* of the original canvas. For other clip types the origin will always be (0,0).
|
|
|
|
*
|
|
|
|
* NOTE: GrClip *must* point to a const clipstack
|
|
|
|
*/
|
|
|
|
class GrClip : SkNoncopyable {
|
|
|
|
public:
|
2015-02-24 01:52:51 +00:00
|
|
|
GrClip() : fClipType(kWideOpen_ClipType) {
|
|
|
|
fOrigin.setZero();
|
|
|
|
}
|
2015-02-25 21:19:48 +00:00
|
|
|
|
2015-02-23 22:44:57 +00:00
|
|
|
GrClip(const SkIRect& rect) : fClipType(kIRect_ClipType) {
|
2015-02-24 01:52:51 +00:00
|
|
|
fOrigin.setZero();
|
2015-02-23 22:44:57 +00:00
|
|
|
fClip.fIRect = rect;
|
|
|
|
}
|
2015-02-25 21:19:48 +00:00
|
|
|
|
2015-03-06 16:21:38 +00:00
|
|
|
GrClip(const SkRect& rect) : fClipType(kIRect_ClipType) {
|
2015-02-25 21:19:48 +00:00
|
|
|
fOrigin.setZero();
|
2015-03-06 16:21:38 +00:00
|
|
|
fClip.fIRect.fLeft = SkScalarRoundToInt(rect.fLeft);
|
|
|
|
fClip.fIRect.fTop = SkScalarRoundToInt(rect.fTop);
|
|
|
|
fClip.fIRect.fRight = SkScalarRoundToInt(rect.fRight);
|
|
|
|
fClip.fIRect.fBottom = SkScalarRoundToInt(rect.fBottom);
|
2015-02-25 21:19:48 +00:00
|
|
|
}
|
|
|
|
|
2015-02-23 22:44:57 +00:00
|
|
|
~GrClip() { this->reset(); }
|
|
|
|
|
|
|
|
const GrClip& operator=(const GrClip& other) {
|
|
|
|
this->reset();
|
|
|
|
fClipType = other.fClipType;
|
|
|
|
switch (other.fClipType) {
|
|
|
|
case kWideOpen_ClipType:
|
2015-02-24 01:52:51 +00:00
|
|
|
fOrigin.setZero();
|
2015-02-23 22:44:57 +00:00
|
|
|
break;
|
|
|
|
case kClipStack_ClipType:
|
2015-02-24 01:52:51 +00:00
|
|
|
fClip.fStack = SkRef(other.clipStack());
|
|
|
|
fOrigin = other.origin();
|
2015-02-23 22:44:57 +00:00
|
|
|
break;
|
|
|
|
case kIRect_ClipType:
|
|
|
|
fClip.fIRect = other.irect();
|
2015-02-24 01:52:51 +00:00
|
|
|
fOrigin.setZero();
|
2015-02-23 22:44:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const GrClip& other) const {
|
|
|
|
if (this->clipType() != other.clipType()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (fClipType) {
|
|
|
|
case kWideOpen_ClipType:
|
|
|
|
return true;
|
|
|
|
case kClipStack_ClipType:
|
|
|
|
if (this->origin() != other.origin()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->clipStack() && other.clipStack()) {
|
|
|
|
return *this->clipStack() == *other.clipStack();
|
|
|
|
} else {
|
|
|
|
return this->clipStack() == other.clipStack();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kIRect_ClipType:
|
|
|
|
return this->irect() == other.irect();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const GrClip& other) const {
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
|
|
|
const SkClipStack* clipStack() const {
|
|
|
|
SkASSERT(kClipStack_ClipType == fClipType);
|
2015-02-24 01:52:51 +00:00
|
|
|
return fClip.fStack;
|
2015-02-23 22:44:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setClipStack(const SkClipStack* clipStack, const SkIPoint* origin = NULL) {
|
2015-02-24 14:47:14 +00:00
|
|
|
this->reset();
|
2015-02-23 22:44:57 +00:00
|
|
|
if (clipStack->isWideOpen()) {
|
|
|
|
fClipType = kWideOpen_ClipType;
|
2015-02-24 01:52:51 +00:00
|
|
|
fOrigin.setZero();
|
2015-02-23 22:44:57 +00:00
|
|
|
} else {
|
|
|
|
fClipType = kClipStack_ClipType;
|
2015-02-24 01:52:51 +00:00
|
|
|
fClip.fStack = SkRef(clipStack);
|
2015-02-23 22:44:57 +00:00
|
|
|
if (origin) {
|
2015-02-24 01:52:51 +00:00
|
|
|
fOrigin = *origin;
|
2015-02-23 22:44:57 +00:00
|
|
|
} else {
|
2015-02-24 01:52:51 +00:00
|
|
|
fOrigin.setZero();
|
2015-02-23 22:44:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const SkIRect& irect() const {
|
|
|
|
SkASSERT(kIRect_ClipType == fClipType);
|
|
|
|
return fClip.fIRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
if (kClipStack_ClipType == fClipType) {
|
2015-02-24 01:52:51 +00:00
|
|
|
fClip.fStack->unref();
|
|
|
|
fClip.fStack = NULL;
|
2015-02-23 22:44:57 +00:00
|
|
|
}
|
|
|
|
fClipType = kWideOpen_ClipType;
|
2015-02-24 01:52:51 +00:00
|
|
|
fOrigin.setZero();
|
2015-02-23 22:44:57 +00:00
|
|
|
}
|
|
|
|
|
2015-02-24 01:52:51 +00:00
|
|
|
// 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
|
2015-02-23 22:44:57 +00:00
|
|
|
const SkIPoint& origin() const {
|
2015-02-24 01:52:51 +00:00
|
|
|
SkASSERT(fClipType == kClipStack_ClipType || (fOrigin.fX == 0 && fOrigin.fY == 0));
|
|
|
|
return fOrigin;
|
2015-02-23 22:44:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isWideOpen(const SkRect& rect) const {
|
|
|
|
return (kWideOpen_ClipType == fClipType) ||
|
|
|
|
(kClipStack_ClipType == fClipType && this->clipStack()->isWideOpen()) ||
|
2015-03-06 16:21:38 +00:00
|
|
|
(kIRect_ClipType == fClipType && this->irect().contains(rect));
|
2015-02-23 22:44:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isWideOpen(const SkIRect& rect) const {
|
|
|
|
return (kWideOpen_ClipType == fClipType) ||
|
|
|
|
(kClipStack_ClipType == fClipType && this->clipStack()->isWideOpen()) ||
|
2015-03-06 16:21:38 +00:00
|
|
|
(kIRect_ClipType == fClipType && this->irect().contains(rect));
|
2015-02-23 22:44:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isWideOpen() const {
|
|
|
|
return (kWideOpen_ClipType == fClipType) ||
|
|
|
|
(kClipStack_ClipType == fClipType && this->clipStack()->isWideOpen());
|
|
|
|
}
|
|
|
|
|
2015-02-25 21:19:48 +00:00
|
|
|
bool quickContains(const SkRect& rect) const {
|
|
|
|
return (kWideOpen_ClipType == fClipType) ||
|
|
|
|
(kClipStack_ClipType == fClipType && this->clipStack()->quickContains(rect)) ||
|
2015-03-06 16:21:38 +00:00
|
|
|
(kIRect_ClipType == fClipType && this->irect().contains(rect));
|
2015-02-25 21:19:48 +00:00
|
|
|
}
|
|
|
|
|
2015-02-23 22:44:57 +00:00
|
|
|
void getConservativeBounds(const GrSurface* surface,
|
|
|
|
SkIRect* devResult,
|
|
|
|
bool* isIntersectionOfRects = NULL) const {
|
|
|
|
this->getConservativeBounds(surface->width(), surface->height(),
|
|
|
|
devResult, isIntersectionOfRects);
|
|
|
|
}
|
|
|
|
|
|
|
|
void getConservativeBounds(int width, int height,
|
|
|
|
SkIRect* devResult,
|
|
|
|
bool* isIntersectionOfRects = NULL) const;
|
|
|
|
|
2015-02-24 01:03:33 +00:00
|
|
|
static const GrClip& WideOpen();
|
2015-02-23 22:44:57 +00:00
|
|
|
|
|
|
|
enum ClipType {
|
|
|
|
kClipStack_ClipType,
|
|
|
|
kWideOpen_ClipType,
|
|
|
|
kIRect_ClipType,
|
|
|
|
};
|
|
|
|
|
|
|
|
ClipType clipType() const { return fClipType; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
union Clip {
|
2015-02-24 01:52:51 +00:00
|
|
|
const SkClipStack* fStack;
|
2015-02-23 22:44:57 +00:00
|
|
|
SkIRect fIRect;
|
|
|
|
} fClip;
|
|
|
|
|
2015-02-24 01:52:51 +00:00
|
|
|
SkIPoint fOrigin;
|
2015-02-23 22:44:57 +00:00
|
|
|
ClipType fClipType;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|