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"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
|
2011-02-22 21:00:31 +00:00
|
|
|
struct SkRect;
|
2011-02-22 19:12:23 +00:00
|
|
|
class SkPath;
|
|
|
|
|
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.
|
2011-03-15 21:27:08 +00:00
|
|
|
class SK_API SkClipStack {
|
2011-02-22 19:12:23 +00:00
|
|
|
public:
|
|
|
|
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
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getBounds places the current finite bound in its first parameter. In its
|
|
|
|
* 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
|
|
|
|
* 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-07-31 15:18:21 +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-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);
|
|
|
|
void clipDevPath(const SkPath&, SkRegion::Op, bool doAA);
|
2011-02-22 19:12:23 +00:00
|
|
|
|
2012-07-26 18:39:13 +00:00
|
|
|
/**
|
|
|
|
* isWideOpen returns true if the clip state corresponds to the infinite
|
|
|
|
* plane (i.e., draws are not limited at all)
|
|
|
|
*/
|
|
|
|
bool isWideOpen() const;
|
|
|
|
|
2012-07-16 18:52:29 +00:00
|
|
|
private:
|
|
|
|
struct Rec;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
struct Clip {
|
2012-04-16 14:49:14 +00:00
|
|
|
Clip() : fRect(NULL), fPath(NULL), fOp(SkRegion::kIntersect_Op),
|
|
|
|
fDoAA(false) {}
|
2011-05-09 07:55:58 +00:00
|
|
|
friend bool operator==(const Clip& a, const Clip& b);
|
2011-05-25 01:27:52 +00:00
|
|
|
friend bool operator!=(const Clip& a, const Clip& b);
|
2011-02-22 19:12:23 +00:00
|
|
|
const SkRect* fRect; // if non-null, this is a rect clip
|
|
|
|
const SkPath* fPath; // if non-null, this is a path clip
|
|
|
|
SkRegion::Op fOp;
|
2011-10-12 14:34:30 +00:00
|
|
|
bool fDoAA;
|
2011-02-22 19:12:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the clip for this element in the iterator. If next() returns
|
|
|
|
* NULL, then the iterator is done. The type of clip is determined by
|
|
|
|
* the pointers fRect and fPath:
|
|
|
|
*
|
|
|
|
* fRect==NULL fPath!=NULL path clip
|
|
|
|
* fRect!=NULL fPath==NULL rect clip
|
|
|
|
* fRect==NULL fPath==NULL empty clip
|
|
|
|
*/
|
|
|
|
const Clip* next();
|
2012-07-16 18:52:29 +00:00
|
|
|
const Clip* prev();
|
2011-02-22 19:12:23 +00:00
|
|
|
|
2012-07-18 12:06:15 +00:00
|
|
|
/**
|
2012-07-20 15:33:18 +00:00
|
|
|
* Moves the iterator to the topmost clip with the specified RegionOp
|
2012-07-18 12:06:15 +00:00
|
|
|
* and returns that clip. If no clip with that op is found,
|
|
|
|
* returns NULL.
|
|
|
|
*/
|
2012-07-20 15:33:18 +00:00
|
|
|
const Clip* 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;
|
|
|
|
Clip fClip;
|
|
|
|
SkDeque::Iter fIter;
|
2012-07-16 18:52:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* updateClip updates fClip to the current state of fIter. It unifies
|
|
|
|
* functionality needed by both next() and prev().
|
|
|
|
*/
|
|
|
|
const Clip* updateClip(const SkClipStack::Rec* rec);
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-07-20 15:33:18 +00:00
|
|
|
B2TIter(const SkClipStack& stack)
|
|
|
|
: INHERITED(stack, kBottom_IterStart) {
|
2012-07-16 18:52:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
using Iter::Clip;
|
|
|
|
using Iter::next;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* to the expected drawing area. Similarly, the offsetX and offsetY parameters
|
|
|
|
* allow the caller to offset the returned bound to account for translated
|
|
|
|
* drawing areas (i.e., those resulting from a saveLayer). For finite bounds,
|
|
|
|
* the translation (+offsetX, +offsetY) is applied before the clamp to the
|
|
|
|
* maximum rectangle: [0,maxWidth) x [0,maxHeight).
|
2012-07-24 22:07:50 +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;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|