2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2011-02-22 19:12:23 +00:00
|
|
|
#ifndef SkClipStack_DEFINED
|
|
|
|
#define SkClipStack_DEFINED
|
|
|
|
|
|
|
|
#include "SkDeque.h"
|
2012-11-29 21:05:13 +00:00
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRect.h"
|
2014-02-16 13:25:24 +00:00
|
|
|
#include "SkRRect.h"
|
2011-02-22 19:12:23 +00:00
|
|
|
#include "SkRegion.h"
|
2014-02-27 17:39:46 +00:00
|
|
|
#include "SkTLazy.h"
|
2011-02-22 19:12:23 +00:00
|
|
|
|
2014-06-05 19:40:07 +00:00
|
|
|
class SkCanvasClipVisitor;
|
2011-02-22 19:12:23 +00:00
|
|
|
|
2012-07-24 22:07:50 +00:00
|
|
|
// Because a single save/restore state can have multiple clips, this class
|
|
|
|
// stores the stack depth (fSaveCount) and clips (fDeque) separately.
|
|
|
|
// Each clip in fDeque stores the stack state to which it belongs
|
|
|
|
// (i.e., the fSaveCount in force when it was added). Restores are thus
|
|
|
|
// implemented by removing clips from fDeque that have an fSaveCount larger
|
|
|
|
// then the freshly decremented count.
|
2015-02-05 16:19:35 +00:00
|
|
|
class SK_API SkClipStack : public SkNVRefCnt<SkClipStack> {
|
2011-02-22 19:12:23 +00:00
|
|
|
public:
|
2012-11-29 21:05:13 +00:00
|
|
|
enum BoundsType {
|
|
|
|
// The bounding box contains all the pixels that can be written to
|
|
|
|
kNormal_BoundsType,
|
|
|
|
// The bounding box contains all the pixels that cannot be written to.
|
|
|
|
// The real bound extends out to infinity and all the pixels outside
|
|
|
|
// of the bound can be written to. Note that some of the pixels inside
|
|
|
|
// the bound may also be writeable but all pixels that cannot be
|
|
|
|
// written to are guaranteed to be inside.
|
|
|
|
kInsideOut_BoundsType
|
|
|
|
};
|
|
|
|
|
|
|
|
class Element {
|
|
|
|
public:
|
|
|
|
enum Type {
|
|
|
|
//!< This element makes the clip empty (regardless of previous elements).
|
|
|
|
kEmpty_Type,
|
|
|
|
//!< This element combines a rect with the current clip using a set operation
|
|
|
|
kRect_Type,
|
2014-02-16 13:25:24 +00:00
|
|
|
//!< This element combines a round-rect with the current clip using a set operation
|
|
|
|
kRRect_Type,
|
2012-11-29 21:05:13 +00:00
|
|
|
//!< This element combines a path with the current clip using a set operation
|
|
|
|
kPath_Type,
|
2014-06-09 14:59:06 +00:00
|
|
|
|
|
|
|
kLastType = kPath_Type
|
2012-11-29 21:05:13 +00:00
|
|
|
};
|
2014-06-09 14:59:06 +00:00
|
|
|
static const int kTypeCnt = kLastType + 1;
|
2012-11-29 21:05:13 +00:00
|
|
|
|
|
|
|
Element() {
|
|
|
|
this->initCommon(0, SkRegion::kReplace_Op, false);
|
|
|
|
this->setEmpty();
|
|
|
|
}
|
|
|
|
|
2014-02-27 17:39:46 +00:00
|
|
|
Element(const Element&);
|
|
|
|
|
2012-11-29 21:05:13 +00:00
|
|
|
Element(const SkRect& rect, SkRegion::Op op, bool doAA) {
|
|
|
|
this->initRect(0, rect, op, doAA);
|
|
|
|
}
|
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
Element(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
|
|
|
|
this->initRRect(0, rrect, op, doAA);
|
|
|
|
}
|
|
|
|
|
2012-11-29 21:05:13 +00:00
|
|
|
Element(const SkPath& path, SkRegion::Op op, bool doAA) {
|
|
|
|
this->initPath(0, path, op, doAA);
|
|
|
|
}
|
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
bool operator== (const Element& element) const;
|
2012-12-04 14:06:06 +00:00
|
|
|
bool operator!= (const Element& element) const { return !(*this == element); }
|
|
|
|
|
2012-11-29 21:05:13 +00:00
|
|
|
//!< Call to get the type of the clip element.
|
|
|
|
Type getType() const { return fType; }
|
|
|
|
|
2014-06-05 19:40:07 +00:00
|
|
|
//!< Call to get the save count associated with this clip element.
|
|
|
|
int getSaveCount() const { return fSaveCount; }
|
|
|
|
|
2012-11-29 21:05:13 +00:00
|
|
|
//!< Call if getType() is kPath to get the path.
|
2014-02-27 17:39:46 +00:00
|
|
|
const SkPath& getPath() const { SkASSERT(kPath_Type == fType); return *fPath.get(); }
|
2014-02-16 13:25:24 +00:00
|
|
|
|
|
|
|
//!< Call if getType() is kRRect to get the round-rect.
|
|
|
|
const SkRRect& getRRect() const { SkASSERT(kRRect_Type == fType); return fRRect; }
|
2012-11-29 21:05:13 +00:00
|
|
|
|
|
|
|
//!< Call if getType() is kRect to get the rect.
|
2014-02-21 20:09:13 +00:00
|
|
|
const SkRect& getRect() const {
|
|
|
|
SkASSERT(kRect_Type == fType && (fRRect.isRect() || fRRect.isEmpty()));
|
|
|
|
return fRRect.getBounds();
|
|
|
|
}
|
2012-11-29 21:05:13 +00:00
|
|
|
|
|
|
|
//!< Call if getType() is not kEmpty to get the set operation used to combine this element.
|
|
|
|
SkRegion::Op getOp() const { return fOp; }
|
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
//!< Call to get the element as a path, regardless of its type.
|
|
|
|
void asPath(SkPath* path) const;
|
|
|
|
|
2016-03-17 19:56:11 +00:00
|
|
|
//!< Call if getType() is not kPath to get the element as a round rect.
|
|
|
|
const SkRRect& asRRect() const { SkASSERT(kPath_Type != fType); return fRRect; }
|
|
|
|
|
2012-11-29 21:05:13 +00:00
|
|
|
/** If getType() is not kEmpty this indicates whether the clip shape should be anti-aliased
|
|
|
|
when it is rasterized. */
|
|
|
|
bool isAA() const { return fDoAA; }
|
|
|
|
|
2012-12-07 20:43:52 +00:00
|
|
|
//!< Inverts the fill of the clip shape. Note that a kEmpty element remains kEmpty.
|
|
|
|
void invertShapeFillType();
|
|
|
|
|
|
|
|
//!< Sets the set operation represented by the element.
|
2012-12-04 14:06:06 +00:00
|
|
|
void setOp(SkRegion::Op op) { fOp = op; }
|
|
|
|
|
2012-11-29 21:05:13 +00:00
|
|
|
/** The GenID can be used by clip stack clients to cache representations of the clip. The
|
|
|
|
ID corresponds to the set of clip elements up to and including this element within the
|
|
|
|
stack not to the element itself. That is the same clip path in different stacks will
|
|
|
|
have a different ID since the elements produce different clip result in the context of
|
|
|
|
their stacks. */
|
2013-11-05 15:03:08 +00:00
|
|
|
int32_t getGenID() const { SkASSERT(kInvalidGenID != fGenID); return fGenID; }
|
2012-11-29 21:05:13 +00:00
|
|
|
|
2012-12-04 14:06:06 +00:00
|
|
|
/**
|
|
|
|
* Gets the bounds of the clip element, either the rect or path bounds. (Whether the shape
|
|
|
|
* is inverse filled is not considered.)
|
|
|
|
*/
|
|
|
|
const SkRect& getBounds() const {
|
|
|
|
static const SkRect kEmpty = { 0, 0, 0, 0 };
|
|
|
|
switch (fType) {
|
2014-02-21 20:09:13 +00:00
|
|
|
case kRect_Type: // fallthrough
|
2014-02-16 13:25:24 +00:00
|
|
|
case kRRect_Type:
|
|
|
|
return fRRect.getBounds();
|
2012-12-04 14:06:06 +00:00
|
|
|
case kPath_Type:
|
2014-02-27 17:39:46 +00:00
|
|
|
return fPath.get()->getBounds();
|
2012-12-04 14:06:06 +00:00
|
|
|
case kEmpty_Type:
|
|
|
|
return kEmpty;
|
|
|
|
default:
|
|
|
|
SkDEBUGFAIL("Unexpected type.");
|
|
|
|
return kEmpty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Conservatively checks whether the clip shape contains the rect param. (Whether the shape
|
|
|
|
* is inverse filled is not considered.)
|
|
|
|
*/
|
|
|
|
bool contains(const SkRect& rect) const {
|
|
|
|
switch (fType) {
|
|
|
|
case kRect_Type:
|
2014-02-21 20:09:13 +00:00
|
|
|
return this->getRect().contains(rect);
|
2014-02-16 13:25:24 +00:00
|
|
|
case kRRect_Type:
|
|
|
|
return fRRect.contains(rect);
|
2012-12-04 14:06:06 +00:00
|
|
|
case kPath_Type:
|
2014-02-27 17:39:46 +00:00
|
|
|
return fPath.get()->conservativelyContainsRect(rect);
|
2012-12-04 14:06:06 +00:00
|
|
|
case kEmpty_Type:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
SkDEBUGFAIL("Unexpected type.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is the clip shape inverse filled.
|
|
|
|
*/
|
|
|
|
bool isInverseFilled() const {
|
2014-02-27 17:39:46 +00:00
|
|
|
return kPath_Type == fType && fPath.get()->isInverseFillType();
|
2012-12-04 14:06:06 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 19:40:07 +00:00
|
|
|
/**
|
|
|
|
* Replay this clip into the visitor.
|
|
|
|
*/
|
|
|
|
void replay(SkCanvasClipVisitor*) const;
|
|
|
|
|
2016-04-29 13:41:35 +00:00
|
|
|
#ifdef SK_DEBUG
|
2014-06-09 14:59:06 +00:00
|
|
|
/**
|
|
|
|
* Dumps the element to SkDebugf. This is intended for Skia development debugging
|
|
|
|
* Don't rely on the existence of this function or the formatting of its output.
|
|
|
|
*/
|
|
|
|
void dump() const;
|
|
|
|
#endif
|
|
|
|
|
2012-11-29 21:05:13 +00:00
|
|
|
private:
|
|
|
|
friend class SkClipStack;
|
|
|
|
|
2014-02-27 17:39:46 +00:00
|
|
|
SkTLazy<SkPath> fPath;
|
2014-02-16 13:25:24 +00:00
|
|
|
SkRRect fRRect;
|
2012-11-29 21:05:13 +00:00
|
|
|
int fSaveCount; // save count of stack when this element was added.
|
|
|
|
SkRegion::Op fOp;
|
|
|
|
Type fType;
|
|
|
|
bool fDoAA;
|
|
|
|
|
|
|
|
/* fFiniteBoundType and fFiniteBound are used to incrementally update the clip stack's
|
|
|
|
bound. When fFiniteBoundType is kNormal_BoundsType, fFiniteBound represents the
|
|
|
|
conservative bounding box of the pixels that aren't clipped (i.e., any pixels that can be
|
|
|
|
drawn to are inside the bound). When fFiniteBoundType is kInsideOut_BoundsType (which
|
|
|
|
occurs when a clip is inverse filled), fFiniteBound represents the conservative bounding
|
|
|
|
box of the pixels that _are_ clipped (i.e., any pixels that cannot be drawn to are inside
|
|
|
|
the bound). When fFiniteBoundType is kInsideOut_BoundsType the actual bound is the
|
|
|
|
infinite plane. This behavior of fFiniteBoundType and fFiniteBound is required so that we
|
|
|
|
can capture the cancelling out of the extensions to infinity when two inverse filled
|
|
|
|
clips are Booleaned together. */
|
|
|
|
SkClipStack::BoundsType fFiniteBoundType;
|
|
|
|
SkRect fFiniteBound;
|
2012-11-30 02:01:24 +00:00
|
|
|
|
2012-11-29 21:05:13 +00:00
|
|
|
// When element is applied to the previous elements in the stack is the result known to be
|
|
|
|
// equivalent to a single rect intersection? IIOW, is the clip effectively a rectangle.
|
|
|
|
bool fIsIntersectionOfRects;
|
|
|
|
|
|
|
|
int fGenID;
|
|
|
|
|
|
|
|
Element(int saveCount) {
|
|
|
|
this->initCommon(saveCount, SkRegion::kReplace_Op, false);
|
|
|
|
this->setEmpty();
|
|
|
|
}
|
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
Element(int saveCount, const SkRRect& rrect, SkRegion::Op op, bool doAA) {
|
|
|
|
this->initRRect(saveCount, rrect, op, doAA);
|
|
|
|
}
|
|
|
|
|
2012-11-29 21:05:13 +00:00
|
|
|
Element(int saveCount, const SkRect& rect, SkRegion::Op op, bool doAA) {
|
|
|
|
this->initRect(saveCount, rect, op, doAA);
|
|
|
|
}
|
|
|
|
|
|
|
|
Element(int saveCount, const SkPath& path, SkRegion::Op op, bool doAA) {
|
|
|
|
this->initPath(saveCount, path, op, doAA);
|
|
|
|
}
|
|
|
|
|
|
|
|
void initCommon(int saveCount, SkRegion::Op op, bool doAA) {
|
|
|
|
fSaveCount = saveCount;
|
|
|
|
fOp = op;
|
|
|
|
fDoAA = doAA;
|
|
|
|
// A default of inside-out and empty bounds means the bounds are effectively void as it
|
|
|
|
// indicates that nothing is known to be outside the clip.
|
|
|
|
fFiniteBoundType = kInsideOut_BoundsType;
|
|
|
|
fFiniteBound.setEmpty();
|
|
|
|
fIsIntersectionOfRects = false;
|
|
|
|
fGenID = kInvalidGenID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void initRect(int saveCount, const SkRect& rect, SkRegion::Op op, bool doAA) {
|
2014-02-21 20:09:13 +00:00
|
|
|
fRRect.setRect(rect);
|
2012-11-29 21:05:13 +00:00
|
|
|
fType = kRect_Type;
|
|
|
|
this->initCommon(saveCount, op, doAA);
|
|
|
|
}
|
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
void initRRect(int saveCount, const SkRRect& rrect, SkRegion::Op op, bool doAA) {
|
2014-02-21 20:09:13 +00:00
|
|
|
SkRRect::Type type = rrect.getType();
|
|
|
|
fRRect = rrect;
|
|
|
|
if (SkRRect::kRect_Type == type || SkRRect::kEmpty_Type == type) {
|
2014-02-16 13:25:24 +00:00
|
|
|
fType = kRect_Type;
|
|
|
|
} else {
|
|
|
|
fType = kRRect_Type;
|
|
|
|
}
|
2012-11-29 21:05:13 +00:00
|
|
|
this->initCommon(saveCount, op, doAA);
|
|
|
|
}
|
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
void initPath(int saveCount, const SkPath& path, SkRegion::Op op, bool doAA);
|
|
|
|
|
2014-02-16 14:45:45 +00:00
|
|
|
void setEmpty();
|
2012-11-29 21:05:13 +00:00
|
|
|
|
|
|
|
// All Element methods below are only used within SkClipStack.cpp
|
|
|
|
inline void checkEmpty() const;
|
|
|
|
inline bool canBeIntersectedInPlace(int saveCount, SkRegion::Op op) const;
|
|
|
|
/* This method checks to see if two rect clips can be safely merged into one. The issue here
|
2012-11-30 02:01:24 +00:00
|
|
|
is that to be strictly correct all the edges of the resulting rect must have the same
|
2012-11-29 21:05:13 +00:00
|
|
|
anti-aliasing. */
|
|
|
|
bool rectRectIntersectAllowed(const SkRect& newR, bool newAA) const;
|
|
|
|
/** Determines possible finite bounds for the Element given the previous element of the
|
|
|
|
stack */
|
|
|
|
void updateBoundAndGenID(const Element* prior);
|
|
|
|
// The different combination of fill & inverse fill when combining bounding boxes
|
|
|
|
enum FillCombo {
|
|
|
|
kPrev_Cur_FillCombo,
|
|
|
|
kPrev_InvCur_FillCombo,
|
|
|
|
kInvPrev_Cur_FillCombo,
|
|
|
|
kInvPrev_InvCur_FillCombo
|
|
|
|
};
|
|
|
|
// per-set operation functions used by updateBoundAndGenID().
|
|
|
|
inline void combineBoundsDiff(FillCombo combination, const SkRect& prevFinite);
|
|
|
|
inline void combineBoundsXOR(int combination, const SkRect& prevFinite);
|
|
|
|
inline void combineBoundsUnion(int combination, const SkRect& prevFinite);
|
|
|
|
inline void combineBoundsIntersection(int combination, const SkRect& prevFinite);
|
|
|
|
inline void combineBoundsRevDiff(int combination, const SkRect& prevFinite);
|
|
|
|
};
|
|
|
|
|
2011-02-22 19:12:23 +00:00
|
|
|
SkClipStack();
|
2011-05-03 16:26:09 +00:00
|
|
|
SkClipStack(const SkClipStack& b);
|
2012-07-26 18:39:13 +00:00
|
|
|
explicit SkClipStack(const SkRect& r);
|
2012-07-31 19:15:58 +00:00
|
|
|
explicit SkClipStack(const SkIRect& r);
|
2012-03-14 18:34:15 +00:00
|
|
|
~SkClipStack();
|
2011-02-22 19:12:23 +00:00
|
|
|
|
2011-05-03 16:26:09 +00:00
|
|
|
SkClipStack& operator=(const SkClipStack& b);
|
|
|
|
bool operator==(const SkClipStack& b) const;
|
|
|
|
bool operator!=(const SkClipStack& b) const { return !(*this == b); }
|
|
|
|
|
2011-02-22 19:12:23 +00:00
|
|
|
void reset();
|
|
|
|
|
|
|
|
int getSaveCount() const { return fSaveCount; }
|
|
|
|
void save();
|
|
|
|
void restore();
|
|
|
|
|
2012-07-24 13:54:00 +00:00
|
|
|
/**
|
|
|
|
* getBounds places the current finite bound in its first parameter. In its
|
2012-08-23 18:09:54 +00:00
|
|
|
* second, it indicates which kind of bound is being returned. If
|
2012-07-31 15:18:21 +00:00
|
|
|
* 'canvFiniteBound' is a normal bounding box then it encloses all writeable
|
2012-08-23 18:09:54 +00:00
|
|
|
* pixels. If 'canvFiniteBound' is an inside out bounding box then it
|
2012-07-24 13:54:00 +00:00
|
|
|
* encloses all the un-writeable pixels and the true/normal bound is the
|
2012-07-24 22:07:50 +00:00
|
|
|
* infinite plane. isIntersectionOfRects is an optional parameter
|
2012-07-31 15:18:21 +00:00
|
|
|
* that is true if 'canvFiniteBound' resulted from an intersection of rects.
|
2012-07-24 13:54:00 +00:00
|
|
|
*/
|
2012-08-23 18:09:54 +00:00
|
|
|
void getBounds(SkRect* canvFiniteBound,
|
2012-07-24 22:07:50 +00:00
|
|
|
BoundsType* boundType,
|
|
|
|
bool* isIntersectionOfRects = NULL) const;
|
2012-07-24 13:54:00 +00:00
|
|
|
|
2012-12-12 17:58:15 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the input rect in device space is entirely contained
|
|
|
|
* by the clip. A return value of false does not guarantee that the rect
|
|
|
|
* is not contained by the clip.
|
|
|
|
*/
|
|
|
|
bool quickContains(const SkRect& devRect) const;
|
|
|
|
|
2015-02-04 15:39:34 +00:00
|
|
|
/**
|
|
|
|
* Flattens the clip stack into a single SkPath. Returns true if any of
|
|
|
|
* the clip stack components requires anti-aliasing.
|
|
|
|
*/
|
|
|
|
bool asPath(SkPath* path) const;
|
|
|
|
|
2012-05-16 18:50:40 +00:00
|
|
|
void clipDevRect(const SkIRect& ir, SkRegion::Op op) {
|
2011-02-22 19:12:23 +00:00
|
|
|
SkRect r;
|
|
|
|
r.set(ir);
|
2011-10-12 14:34:30 +00:00
|
|
|
this->clipDevRect(r, op, false);
|
2011-02-22 19:12:23 +00:00
|
|
|
}
|
2011-10-12 14:34:30 +00:00
|
|
|
void clipDevRect(const SkRect&, SkRegion::Op, bool doAA);
|
2014-02-16 13:25:24 +00:00
|
|
|
void clipDevRRect(const SkRRect&, SkRegion::Op, bool doAA);
|
2011-10-12 14:34:30 +00:00
|
|
|
void clipDevPath(const SkPath&, SkRegion::Op, bool doAA);
|
2012-08-16 15:59:59 +00:00
|
|
|
// An optimized version of clipDevRect(emptyRect, kIntersect, ...)
|
|
|
|
void clipEmpty();
|
2011-02-22 19:12:23 +00:00
|
|
|
|
2012-07-26 18:39:13 +00:00
|
|
|
/**
|
2012-08-23 18:09:54 +00:00
|
|
|
* isWideOpen returns true if the clip state corresponds to the infinite
|
2012-07-26 18:39:13 +00:00
|
|
|
* plane (i.e., draws are not limited at all)
|
|
|
|
*/
|
|
|
|
bool isWideOpen() const;
|
|
|
|
|
2012-08-07 15:38:08 +00:00
|
|
|
/**
|
|
|
|
* The generation ID has three reserved values to indicate special
|
2012-11-07 21:19:10 +00:00
|
|
|
* (potentially ignorable) cases
|
2012-08-07 15:38:08 +00:00
|
|
|
*/
|
2013-11-05 15:03:08 +00:00
|
|
|
static const int32_t kInvalidGenID = 0; //!< Invalid id that is never returned by
|
|
|
|
//!< SkClipStack. Useful when caching clips
|
|
|
|
//!< based on GenID.
|
2012-08-07 15:38:08 +00:00
|
|
|
static const int32_t kEmptyGenID = 1; // no pixels writeable
|
|
|
|
static const int32_t kWideOpenGenID = 2; // all pixels writeable
|
|
|
|
|
2012-08-09 18:10:49 +00:00
|
|
|
int32_t getTopmostGenID() const;
|
|
|
|
|
2016-04-29 13:41:35 +00:00
|
|
|
#ifdef SK_DEBUG
|
2014-06-09 14:59:06 +00:00
|
|
|
/**
|
|
|
|
* Dumps the contents of the clip stack to SkDebugf. This is intended for Skia development
|
|
|
|
* debugging. Don't rely on the existence of this function or the formatting of its output.
|
|
|
|
*/
|
|
|
|
void dump() const;
|
|
|
|
#endif
|
|
|
|
|
2012-07-16 18:52:29 +00:00
|
|
|
public:
|
|
|
|
class Iter {
|
2011-02-22 19:12:23 +00:00
|
|
|
public:
|
2012-07-16 18:52:29 +00:00
|
|
|
enum IterStart {
|
2012-07-20 15:33:18 +00:00
|
|
|
kBottom_IterStart = SkDeque::Iter::kFront_IterStart,
|
|
|
|
kTop_IterStart = SkDeque::Iter::kBack_IterStart
|
2012-07-16 18:52:29 +00:00
|
|
|
};
|
|
|
|
|
2011-03-03 13:54:13 +00:00
|
|
|
/**
|
|
|
|
* Creates an uninitialized iterator. Must be reset()
|
|
|
|
*/
|
2012-07-16 18:52:29 +00:00
|
|
|
Iter();
|
2011-03-03 13:54:13 +00:00
|
|
|
|
2012-07-16 18:52:29 +00:00
|
|
|
Iter(const SkClipStack& stack, IterStart startLoc);
|
2011-02-22 19:12:23 +00:00
|
|
|
|
|
|
|
/**
|
2012-12-04 14:06:06 +00:00
|
|
|
* Return the clip element for this iterator. If next()/prev() returns NULL, then the
|
|
|
|
* iterator is done.
|
2011-02-22 19:12:23 +00:00
|
|
|
*/
|
2012-12-04 14:06:06 +00:00
|
|
|
const Element* next();
|
|
|
|
const Element* prev();
|
2011-02-22 19:12:23 +00:00
|
|
|
|
2012-07-18 12:06:15 +00:00
|
|
|
/**
|
2012-12-04 14:06:06 +00:00
|
|
|
* Moves the iterator to the topmost element with the specified RegionOp and returns that
|
|
|
|
* element. If no clip element with that op is found, the first element is returned.
|
2012-07-18 12:06:15 +00:00
|
|
|
*/
|
2012-12-04 14:06:06 +00:00
|
|
|
const Element* skipToTopmost(SkRegion::Op op);
|
2012-07-18 12:06:15 +00:00
|
|
|
|
2011-03-03 13:54:13 +00:00
|
|
|
/**
|
|
|
|
* Restarts the iterator on a clip stack.
|
|
|
|
*/
|
2012-07-16 18:52:29 +00:00
|
|
|
void reset(const SkClipStack& stack, IterStart startLoc);
|
2011-03-03 13:54:13 +00:00
|
|
|
|
2011-02-22 19:12:23 +00:00
|
|
|
private:
|
2012-07-18 12:06:15 +00:00
|
|
|
const SkClipStack* fStack;
|
|
|
|
SkDeque::Iter fIter;
|
2012-07-16 18:52:29 +00:00
|
|
|
};
|
|
|
|
|
2012-08-23 18:09:54 +00:00
|
|
|
/**
|
2012-07-20 15:33:18 +00:00
|
|
|
* The B2TIter iterates from the bottom of the stack to the top.
|
|
|
|
* It inherits privately from Iter to prevent access to reverse iteration.
|
|
|
|
*/
|
|
|
|
class B2TIter : private Iter {
|
2012-07-16 18:52:29 +00:00
|
|
|
public:
|
2012-07-20 15:33:18 +00:00
|
|
|
B2TIter() {}
|
2012-07-16 18:52:29 +00:00
|
|
|
|
|
|
|
/**
|
2012-08-23 18:09:54 +00:00
|
|
|
* Wrap Iter's 2 parameter ctor to force initialization to the
|
2012-07-20 15:33:18 +00:00
|
|
|
* beginning of the deque/bottom of the stack
|
2012-07-16 18:52:29 +00:00
|
|
|
*/
|
2012-08-23 18:09:54 +00:00
|
|
|
B2TIter(const SkClipStack& stack)
|
2012-07-20 15:33:18 +00:00
|
|
|
: INHERITED(stack, kBottom_IterStart) {
|
2012-07-16 18:52:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
using Iter::next;
|
|
|
|
|
|
|
|
/**
|
2012-08-23 18:09:54 +00:00
|
|
|
* Wrap Iter::reset to force initialization to the
|
2012-07-20 15:33:18 +00:00
|
|
|
* beginning of the deque/bottom of the stack
|
2012-07-16 18:52:29 +00:00
|
|
|
*/
|
|
|
|
void reset(const SkClipStack& stack) {
|
2012-07-20 15:33:18 +00:00
|
|
|
this->INHERITED::reset(stack, kBottom_IterStart);
|
2012-07-16 18:52:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
typedef Iter INHERITED;
|
2011-02-22 19:12:23 +00:00
|
|
|
};
|
|
|
|
|
2012-07-24 13:54:00 +00:00
|
|
|
/**
|
2012-08-23 18:09:54 +00:00
|
|
|
* GetConservativeBounds returns a conservative bound of the current clip.
|
|
|
|
* Since this could be the infinite plane (if inverse fills were involved) the
|
|
|
|
* maxWidth and maxHeight parameters can be used to limit the returned bound
|
2012-07-24 13:54:00 +00:00
|
|
|
* to the expected drawing area. Similarly, the offsetX and offsetY parameters
|
2012-08-23 18:09:54 +00:00
|
|
|
* allow the caller to offset the returned bound to account for translated
|
2012-07-24 13:54:00 +00:00
|
|
|
* drawing areas (i.e., those resulting from a saveLayer). For finite bounds,
|
2012-08-23 18:09:54 +00:00
|
|
|
* the translation (+offsetX, +offsetY) is applied before the clamp to the
|
2012-07-24 13:54:00 +00:00
|
|
|
* maximum rectangle: [0,maxWidth) x [0,maxHeight).
|
2012-08-23 18:09:54 +00:00
|
|
|
* isIntersectionOfRects is an optional parameter that is true when
|
2012-07-31 19:15:58 +00:00
|
|
|
* 'devBounds' is the result of an intersection of rects. In this case
|
|
|
|
* 'devBounds' is the exact answer/clip.
|
2012-07-24 13:54:00 +00:00
|
|
|
*/
|
|
|
|
void getConservativeBounds(int offsetX,
|
|
|
|
int offsetY,
|
|
|
|
int maxWidth,
|
|
|
|
int maxHeight,
|
2012-07-31 15:18:21 +00:00
|
|
|
SkRect* devBounds,
|
2012-07-24 22:07:50 +00:00
|
|
|
bool* isIntersectionOfRects = NULL) const;
|
2012-07-24 13:54:00 +00:00
|
|
|
|
2011-02-22 19:12:23 +00:00
|
|
|
private:
|
2012-07-16 18:52:29 +00:00
|
|
|
friend class Iter;
|
2011-02-22 19:12:23 +00:00
|
|
|
|
|
|
|
SkDeque fDeque;
|
|
|
|
int fSaveCount;
|
2012-08-07 15:38:08 +00:00
|
|
|
|
|
|
|
// Generation ID for the clip stack. This is incremented for each
|
|
|
|
// clipDevRect and clipDevPath call. 0 is reserved to indicate an
|
|
|
|
// invalid ID.
|
|
|
|
static int32_t gGenID;
|
|
|
|
|
2014-02-16 13:25:24 +00:00
|
|
|
/**
|
|
|
|
* Helper for clipDevPath, etc.
|
|
|
|
*/
|
|
|
|
void pushElement(const Element& element);
|
|
|
|
|
2013-06-11 11:01:48 +00:00
|
|
|
/**
|
|
|
|
* Restore the stack back to the specified save count.
|
|
|
|
*/
|
|
|
|
void restoreTo(int saveCount);
|
|
|
|
|
2012-08-07 15:38:08 +00:00
|
|
|
/**
|
|
|
|
* Return the next unique generation ID.
|
|
|
|
*/
|
|
|
|
static int32_t GetNextGenID();
|
2011-02-22 19:12:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|