diff options
author | 2016-05-13 10:25:00 -0700 | |
---|---|---|
committer | 2016-05-13 10:25:00 -0700 | |
commit | 846c051a4800b3cea341a0195db24297d6d9047f (patch) | |
tree | 7dadb5396d2dad36a45686c9c10ada5bc2e76f01 /src/gpu/GrClip.cpp | |
parent | 670f01f2fc88f02ec9a6f1b47af29daeadc3b301 (diff) |
Convert GrClip to an abstract base class
Converts GrClip to an abstract base class and adds a "GrFixedClip"
implementation. GrFixedClip denotes a clip implemented with fixed-
function hardware. GrFixedClip allows us to remove the stateful
"fClipMode" member from GrClipMaskManager, and in the future will
be able to nicely encapsulate window rectangles.
After this change GrClipMaskManager is just a wrapper around
GrDrawTarget. We may want to consider removing it altogether.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1971343002
Review-Url: https://codereview.chromium.org/1971343002
Diffstat (limited to 'src/gpu/GrClip.cpp')
-rw-r--r-- | src/gpu/GrClip.cpp | 110 |
1 files changed, 73 insertions, 37 deletions
diff --git a/src/gpu/GrClip.cpp b/src/gpu/GrClip.cpp index 5c4a27ccad..15065aa484 100644 --- a/src/gpu/GrClip.cpp +++ b/src/gpu/GrClip.cpp @@ -7,47 +7,83 @@ #include "GrClip.h" -#include "GrSurface.h" -#include "SkRect.h" +#include "GrClipMaskManager.h" -/////////////////////////////////////////////////////////////////////////////// +void GrNoClip::getConservativeBounds(int width, int height, SkIRect* devResult, + bool* isIntersectionOfRects) const { + devResult->setXYWH(0, 0, width, height); + if (isIntersectionOfRects) { + *isIntersectionOfRects = true; + } +} -/** - * getConservativeBounds returns the conservative bounding box of the clip - * in device (as opposed to canvas) coordinates. If the bounding box is - * the result of purely intersections of rects (with an initial replace) - * isIntersectionOfRects will be set to true. - */ -void GrClip::getConservativeBounds(int width, int height, SkIRect* devResult, - bool* isIntersectionOfRects) const { - switch (fClipType) { - case kWideOpen_ClipType: { - devResult->setLTRB(0, 0, width, height); - if (isIntersectionOfRects) { - *isIntersectionOfRects = true; - } - } break; - case kIRect_ClipType: { - *devResult = this->irect(); - if (isIntersectionOfRects) { - *isIntersectionOfRects = true; - } - } break; - case kClipStack_ClipType: { - SkRect devBounds; - this->clipStack()->getConservativeBounds(-this->origin().fX, - -this->origin().fY, - width, - height, - &devBounds, - isIntersectionOfRects); - devBounds.roundOut(devResult); - } break; +bool GrFixedClip::quickContains(const SkRect& rect) const { + if (fHasStencilClip) { + return false; + } + if (!fScissorState.enabled()) { + return true; + } + return fScissorState.rect().contains(rect); +} + +void GrFixedClip::getConservativeBounds(int width, int height, SkIRect* devResult, + bool* isIntersectionOfRects) const { + devResult->setXYWH(0, 0, width, height); + if (fScissorState.enabled()) { + if (!devResult->intersect(fScissorState.rect())) { + devResult->setEmpty(); + } + } + if (isIntersectionOfRects) { + *isIntersectionOfRects = true; + } +} + +bool GrFixedClip::apply(GrClipMaskManager*, const GrPipelineBuilder& pipelineBuilder, + const SkRect* devBounds, GrAppliedClip* out) const { + if (fScissorState.enabled()) { + const GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); + SkIRect tightScissor; + if (!tightScissor.intersect(fScissorState.rect(), + SkIRect::MakeWH(rt->width(), rt->height()))) { + return false; + } + if (devBounds && !devBounds->intersects(SkRect::Make(tightScissor))) { + return false; + } + out->fScissorState.set(tightScissor); + } + out->fHasStencilClip = fHasStencilClip; + return true; +} + +bool GrClipStackClip::quickContains(const SkRect& rect) const { + if (!fStack) { + return true; + } + return fStack->quickContains(rect.makeOffset(SkIntToScalar(fOrigin.x()), + SkIntToScalar(fOrigin.y()))); +} +void GrClipStackClip::getConservativeBounds(int width, int height, SkIRect* devResult, + bool* isIntersectionOfRects) const { + if (!fStack) { + devResult->setXYWH(0, 0, width, height); + if (isIntersectionOfRects) { + *isIntersectionOfRects = true; + } + return; } + SkRect devBounds; + fStack->getConservativeBounds(-fOrigin.x(), -fOrigin.y(), width, height, &devBounds, + isIntersectionOfRects); + devBounds.roundOut(devResult); } -const GrClip& GrClip::WideOpen() { - static const GrClip clip; - return clip; +bool GrClipStackClip::apply(GrClipMaskManager* clipMaskManager, + const GrPipelineBuilder& pipelineBuilder, const SkRect* devBounds, + GrAppliedClip* out) const { + // TODO: Collapse ClipMaskManager into this class.(?) + return clipMaskManager->setupClipping(pipelineBuilder, *this, devBounds, out); } |