diff options
author | joshualitt <joshualitt@chromium.org> | 2015-02-23 14:44:57 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-23 14:44:58 -0800 |
commit | 44701df5ce572ac3cccec785cf52103d3d5d14a5 (patch) | |
tree | b2f3b5465cc8490261163006376c7f7a30b5399e /include/gpu | |
parent | 98c251bc7eec5aa236700d9936c740f2744788db (diff) |
Move clip off of draw target
BUG=skia:
Review URL: https://codereview.chromium.org/947443003
Diffstat (limited to 'include/gpu')
-rw-r--r-- | include/gpu/GrClip.h | 175 | ||||
-rw-r--r-- | include/gpu/GrClipData.h | 61 | ||||
-rw-r--r-- | include/gpu/GrContext.h | 16 |
3 files changed, 183 insertions, 69 deletions
diff --git a/include/gpu/GrClip.h b/include/gpu/GrClip.h new file mode 100644 index 0000000000..f07a9749ca --- /dev/null +++ b/include/gpu/GrClip.h @@ -0,0 +1,175 @@ +/* + * 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 + * masks. 'A GrClip is either wide open, just an IRect, just a Rect(TODO), or a full clipstack. + * 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: + GrClip() : fClipType(kWideOpen_ClipType) {} + GrClip(const SkIRect& rect) : fClipType(kIRect_ClipType) { + fClip.fIRect = rect; + } + ~GrClip() { this->reset(); } + + const GrClip& operator=(const GrClip& other) { + this->reset(); + fClipType = other.fClipType; + switch (other.fClipType) { + default: + SkFAIL("Incomplete Switch\n"); + case kWideOpen_ClipType: + break; + case kClipStack_ClipType: + fClip.fClipStack.fStack = SkRef(other.clipStack()); + fClip.fClipStack.fOrigin = other.origin(); + break; + case kIRect_ClipType: + fClip.fIRect = other.irect(); + break; + } + return *this; + } + + bool operator==(const GrClip& other) const { + if (this->clipType() != other.clipType()) { + return false; + } + + switch (fClipType) { + default: + SkFAIL("Incomplete Switch\n"); + return false; + 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); + return fClip.fClipStack.fStack; + } + + void setClipStack(const SkClipStack* clipStack, const SkIPoint* origin = NULL) { + if (clipStack->isWideOpen()) { + fClipType = kWideOpen_ClipType; + } else { + fClipType = kClipStack_ClipType; + fClip.fClipStack.fStack = SkRef(clipStack); + if (origin) { + fClip.fClipStack.fOrigin = *origin; + } else { + fClip.fClipStack.fOrigin.setZero(); + } + } + } + + const SkIRect& irect() const { + SkASSERT(kIRect_ClipType == fClipType); + return fClip.fIRect; + } + + void reset() { + if (kClipStack_ClipType == fClipType) { + fClip.fClipStack.fStack->unref(); + fClip.fClipStack.fStack = NULL; + } + fClipType = kWideOpen_ClipType; + } + + const SkIPoint& origin() const { + SkASSERT(kClipStack_ClipType == fClipType); + return fClip.fClipStack.fOrigin; + } + + bool isWideOpen(const SkRect& rect) const { + return (kWideOpen_ClipType == fClipType) || + (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpen()) || + (kIRect_ClipType == fClipType && this->irect().contains(rect)); + } + + bool isWideOpen(const SkIRect& rect) const { + return (kWideOpen_ClipType == fClipType) || + (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpen()) || + (kIRect_ClipType == fClipType && this->irect().contains(rect)); + } + + bool isWideOpen() const { + return (kWideOpen_ClipType == fClipType) || + (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpen()); + } + + 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; + + static const GrClip& WideOpen() { + static GrClip clip; + return clip; + } + + enum ClipType { + kClipStack_ClipType, + kWideOpen_ClipType, + kIRect_ClipType, + }; + + ClipType clipType() const { return fClipType; } + +private: + union Clip { + struct ClipStack { + const SkClipStack* fStack; + SkIPoint fOrigin; + } fClipStack; + SkIRect fIRect; + } fClip; + + ClipType fClipType; +}; + +#endif diff --git a/include/gpu/GrClipData.h b/include/gpu/GrClipData.h deleted file mode 100644 index bb7101d8a6..0000000000 --- a/include/gpu/GrClipData.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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; - -/** - * GrClipData encapsulates the information required to construct the clip - * masks. 'fOrigin' is only non-zero when saveLayer has been called - * with an offset bounding box. The clips in 'fClipStack' are in - * device coordinates (i.e., they have been translated by -fOrigin w.r.t. - * the canvas' device coordinates). - */ -class GrClipData : SkNoncopyable { -public: - SkAutoTUnref<const SkClipStack> fClipStack; - SkIPoint fOrigin; - - GrClipData() - : fClipStack(NULL) { - fOrigin.setZero(); - } - - bool operator==(const GrClipData& other) const { - if (fOrigin != other.fOrigin) { - return false; - } - - if (fClipStack && other.fClipStack) { - return *fClipStack == *other.fClipStack; - } - - return fClipStack == other.fClipStack; - } - - bool operator!=(const GrClipData& other) const { - return !(*this == other); - } - - 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; -}; - -#endif diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 846cd0f111..2433b89189 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -8,7 +8,7 @@ #ifndef GrContext_DEFINED #define GrContext_DEFINED -#include "GrClipData.h" +#include "GrClip.h" #include "GrColor.h" #include "GrPaint.h" #include "GrPathRendererChain.h" @@ -367,13 +367,13 @@ public: * Gets the current clip. * @return the current clip. */ - const GrClipData* getClip() const { return fClip; } + const GrClip* getClip() const { return fClip; } /** * Sets the clip. * @param clipData the clip to set. */ - void setClip(const GrClipData* clipData) { fClip = clipData; } + void setClip(const GrClip* clipData) { fClip = clipData; } /////////////////////////////////////////////////////////////////////////// // Draws @@ -680,7 +680,7 @@ public: AutoClip(GrContext* context, InitialClip SkDEBUGCODE(initialState)) : fContext(context) { SkASSERT(kWideOpen_InitialClip == initialState); - fNewClipData.fClipStack.reset(SkRef(&fNewClipStack)); + fNewClipData.setClipStack(&fNewClipStack); fOldClip = context->getClip(); context->setClip(&fNewClipData); @@ -689,7 +689,7 @@ public: AutoClip(GrContext* context, const SkRect& newClipRect) : fContext(context) , fNewClipStack(newClipRect) { - fNewClipData.fClipStack.reset(SkRef(&fNewClipStack)); + fNewClipData.setClipStack(&fNewClipStack); fOldClip = fContext->getClip(); fContext->setClip(&fNewClipData); @@ -702,10 +702,10 @@ public: } private: GrContext* fContext; - const GrClipData* fOldClip; + const GrClip* fOldClip; SkClipStack fNewClipStack; - GrClipData fNewClipData; + GrClip fNewClipData; }; class AutoWideOpenIdentityDraw { @@ -761,7 +761,7 @@ public: private: GrGpu* fGpu; - const GrClipData* fClip; // TODO: make this ref counted + const GrClip* fClip; GrResourceCache* fResourceCache; GrFontCache* fFontCache; |