diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-03-03 13:54:13 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-03-03 13:54:13 +0000 |
commit | d302f1401b3c9aea094804bad4e76de98782cfe8 (patch) | |
tree | b46ec6c4de175842aef051d7b812785dacbd1d73 /include | |
parent | 1d12b1fd66e5be27fb4769ee09ce4fcd6bcc5979 (diff) |
Add support for clipstack to Gr. GrClip is now a list of rects and paths with set operations to combine them. The stencil buffer is used to perform the set operations to put the clip into the stencil buffer. Building Gr's clip from Skia's clipStack is currently disabled due to the fact that Skia's clipStack is relative to the root layer not the current layer. This will be fixed in a subsequent CL.
git-svn-id: http://skia.googlecode.com/svn/trunk@878 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkCanvas.h | 3 | ||||
-rw-r--r-- | include/core/SkClipStack.h | 10 | ||||
-rw-r--r-- | include/core/SkDeque.h | 7 | ||||
-rw-r--r-- | include/core/SkDevice.h | 3 | ||||
-rw-r--r-- | include/core/SkRegion.h | 2 | ||||
-rw-r--r-- | include/gpu/SkGpuDevice.h | 3 | ||||
-rw-r--r-- | include/gpu/SkGr.h | 87 |
7 files changed, 98 insertions, 17 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 1e153078c7..eef3aea572 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -794,7 +794,8 @@ private: SkDevice* fLastDeviceToGainFocus; SkDeviceFactory* fDeviceFactory; - void prepareForDeviceDraw(SkDevice*, const SkMatrix&, const SkRegion&); + void prepareForDeviceDraw(SkDevice*, const SkMatrix&, const SkRegion&, + const SkClipStack& clipStack); bool fDeviceCMDirty; // cleared by updateDeviceCMCache() void updateDeviceCMCache(); diff --git a/include/core/SkClipStack.h b/include/core/SkClipStack.h index fb941553b3..db42e4df26 100644 --- a/include/core/SkClipStack.h +++ b/include/core/SkClipStack.h @@ -29,6 +29,11 @@ public: class B2FIter { public: + /** + * Creates an uninitialized iterator. Must be reset() + */ + B2FIter(); + B2FIter(const SkClipStack& stack); struct Clip { @@ -48,6 +53,11 @@ public: */ const Clip* next(); + /** + * Restarts the iterator on a clip stack. + */ + void reset(const SkClipStack& stack); + private: Clip fClip; SkDeque::F2BIter fIter; diff --git a/include/core/SkDeque.h b/include/core/SkDeque.h index 99c8dd46ab..92d515300a 100644 --- a/include/core/SkDeque.h +++ b/include/core/SkDeque.h @@ -52,9 +52,16 @@ private: public: class F2BIter { public: + /** + * Creates an uninitialized iterator. Must be reset() + */ + F2BIter(); + F2BIter(const SkDeque& d); void* next(); + void reset(const SkDeque& d); + private: SkDeque::Head* fHead; char* fPos; diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index a7903993a4..c0d71c3f8e 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -141,7 +141,8 @@ public: /** Called when this device gains focus (i.e becomes the current device for drawing). */ - virtual void gainFocus(SkCanvas*, const SkMatrix&, const SkRegion&) {} + virtual void gainFocus(SkCanvas*, const SkMatrix&, const SkRegion&, + const SkClipStack&) {} /** Causes any deferred drawing to the device to be completed. */ diff --git a/include/core/SkRegion.h b/include/core/SkRegion.h index 8d9ff013ed..58f4f3fb3f 100644 --- a/include/core/SkRegion.h +++ b/include/core/SkRegion.h @@ -260,7 +260,7 @@ public: bool rewind(); // reset the iterator, using the new region void reset(const SkRegion&); - bool done() { return fDone; } + bool done() const { return fDone; } void next(); const SkIRect& rect() const { return fRect; } // may return null diff --git a/include/gpu/SkGpuDevice.h b/include/gpu/SkGpuDevice.h index 2db33800ed..3fed99ab69 100644 --- a/include/gpu/SkGpuDevice.h +++ b/include/gpu/SkGpuDevice.h @@ -68,7 +68,8 @@ public: * Override from SkGpuDevice, so we can set our FBO to be the render target * The canvas parameter must be a SkGpuCanvas */ - virtual void gainFocus(SkCanvas*, const SkMatrix&, const SkRegion&); + virtual void gainFocus(SkCanvas*, const SkMatrix&, const SkRegion&, + const SkClipStack& clipStack); virtual SkGpuTexture* accessTexture() { return (SkGpuTexture*)fTexture; } diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h index ccdd400933..d6a3fab8cc 100644 --- a/include/gpu/SkGr.h +++ b/include/gpu/SkGr.h @@ -20,7 +20,7 @@ #include <stddef.h> -// tetrark headers +// Gr headers #include "GrConfig.h" #include "GrContext.h" #include "GrFontScaler.h" @@ -33,6 +33,7 @@ #include "SkPoint.h" #include "SkRegion.h" #include "SkShader.h" +#include "SkClipStack.h" #if (GR_DEBUG && defined(SK_RELEASE)) || (GR_RELEASE && defined(SK_DEBUG)) // #error "inconsistent GR_DEBUG and SK_DEBUG" @@ -170,39 +171,99 @@ public: class SkGrPathIter : public GrPathIter { public: - SkGrPathIter(const SkPath& path) : fIter(path, false), fPath(path) {} + SkGrPathIter() { fPath = NULL; } + SkGrPathIter(const SkPath& path) { reset(path); } virtual Command next(GrPoint pts[]); virtual Command next(); virtual void rewind(); virtual ConvexHint hint() const; + + void reset(const SkPath& path) { + fPath = &path; + fIter.setPath(path, false); + } private: #if !SK_SCALAR_IS_GR_SCALAR SkPoint fPoints[4]; #endif SkPath::Iter fIter; - const SkPath& fPath; + const SkPath* fPath; }; class SkGrClipIterator : public GrClipIterator { public: - void reset(const SkRegion& clip) { - fIter.reset(clip); - this->invalidateBoundsCache(); - } + SkGrClipIterator() { fClipStack = NULL; fCurr = NULL; } + SkGrClipIterator(const SkClipStack& clipStack) { this->reset(clipStack); } + + void reset(const SkClipStack& clipStack); // overrides + virtual bool isDone() const { return NULL == fCurr; } + virtual void next() { fCurr = fIter.next(); } + virtual void rewind() { this->reset(*fClipStack); } + virtual GrClipType getType() const; + + virtual GrSetOp getOp() const; + + virtual void getRect(GrRect* rect) const { + *rect = Sk2Gr(*fCurr->fRect); + } - virtual bool isDone() { return fIter.done(); } - virtual void getRect(GrIRect* rect) { - SkGr::SetIRect(rect, fIter.rect()); + virtual GrPathIter* getPathIter() { + fPathIter.reset(*fCurr->fPath); + return &fPathIter; } + + virtual GrPathFill getPathFill() const; + +private: + const SkClipStack* fClipStack; + SkClipStack::B2FIter fIter; + SkGrPathIter fPathIter; + // SkClipStack's auto advances on each get + // so we store the current pos here. + const SkClipStack::B2FIter::Clip* fCurr; +}; + +class SkGrRegionIterator : public GrClipIterator { +public: + SkGrRegionIterator() {} + SkGrRegionIterator(const SkRegion& region) { this->reset(region); } + + void reset(const SkRegion& region) { + fRegion = ®ion; + fIter.reset(region); + } + + // overrides + virtual bool isDone() const { return fIter.done(); } virtual void next() { fIter.next(); } - virtual void rewind() { fIter.rewind(); } - virtual void computeBounds(GrIRect* bounds); + virtual void rewind() { this->reset(*fRegion); } + virtual GrClipType getType() const { return kRect_ClipType; } + + virtual GrSetOp getOp() const { return kUnion_SetOp; } + virtual void getRect(GrRect* rect) const { + const SkIRect& r = fIter.rect(); + rect->fLeft = GrIntToScalar(r.fLeft); + rect->fTop = GrIntToScalar(r.fTop); + rect->fRight = GrIntToScalar(r.fRight); + rect->fBottom = GrIntToScalar(r.fBottom); + } + + virtual GrPathIter* getPathIter() { + SkASSERT(0); + return NULL; + } + + virtual GrPathFill getPathFill() const { + SkASSERT(0); + return kWinding_PathFill; + } private: - SkRegion::Iterator fIter; + const SkRegion* fRegion; + SkRegion::Iterator fIter; }; class SkGlyphCache; |