1 /* 2 * Copyright 2016 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrAppliedClip_DEFINED 9 #define GrAppliedClip_DEFINED 10 11 #include "GrFragmentProcessor.h" 12 #include "GrScissorState.h" 13 #include "GrWindowRectsState.h" 14 15 #include "SkClipStack.h" 16 17 /** 18 * Produced by GrClip. It provides a set of modifications to the drawing state that are used to 19 * create the final GrPipeline for a GrOp. 20 */ 21 class GrAppliedClip { 22 public: 23 GrAppliedClip() = default; 24 GrAppliedClip(GrAppliedClip&& that) = default; 25 GrAppliedClip(const GrAppliedClip&) = delete; 26 scissorState()27 const GrScissorState& scissorState() const { return fScissorState; } windowRectsState()28 const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; } clipCoverageFragmentProcessor()29 GrFragmentProcessor* clipCoverageFragmentProcessor() const { return fClipCoverageFP.get(); } hasStencilClip()30 bool hasStencilClip() const { return SkClipStack::kInvalidGenID != fClipStackID; } 31 32 /** 33 * Intersects the applied clip with the provided rect. Returns false if the draw became empty. 34 * 'clippedDrawBounds' will be intersected with 'irect'. This returns false if the clip becomes 35 * empty or the draw no longer intersects the clip. In either case the draw can be skipped. 36 */ addScissor(const SkIRect & irect,SkRect * clippedDrawBounds)37 bool addScissor(const SkIRect& irect, SkRect* clippedDrawBounds) { 38 return fScissorState.intersect(irect) && clippedDrawBounds->intersect(SkRect::Make(irect)); 39 } 40 addWindowRectangles(const GrWindowRectsState & windowState)41 void addWindowRectangles(const GrWindowRectsState& windowState) { 42 SkASSERT(!fWindowRectsState.enabled()); 43 fWindowRectsState = windowState; 44 } 45 addWindowRectangles(const GrWindowRectangles & windows,GrWindowRectsState::Mode mode)46 void addWindowRectangles(const GrWindowRectangles& windows, GrWindowRectsState::Mode mode) { 47 SkASSERT(!fWindowRectsState.enabled()); 48 fWindowRectsState.set(windows, mode); 49 } 50 addCoverageFP(sk_sp<GrFragmentProcessor> fp)51 void addCoverageFP(sk_sp<GrFragmentProcessor> fp) { 52 SkASSERT(!fClipCoverageFP); 53 fClipCoverageFP = fp; 54 } 55 addStencilClip(uint32_t clipStackID)56 void addStencilClip(uint32_t clipStackID) { 57 SkASSERT(SkClipStack::kInvalidGenID == fClipStackID); 58 fClipStackID = clipStackID; 59 } 60 doesClip()61 bool doesClip() const { 62 return fScissorState.enabled() || fClipCoverageFP || this->hasStencilClip() || 63 fWindowRectsState.enabled(); 64 } 65 66 bool operator==(const GrAppliedClip& that) const { 67 if (fScissorState != that.fScissorState || fClipStackID != that.fClipStackID) { 68 return false; 69 } 70 if (SkToBool(fClipCoverageFP)) { 71 if (!SkToBool(that.fClipCoverageFP) || 72 !that.fClipCoverageFP->isEqual(*fClipCoverageFP)) { 73 return false; 74 } 75 } else if (SkToBool(that.fClipCoverageFP)) { 76 return false; 77 } 78 return fWindowRectsState == that.fWindowRectsState; 79 } 80 bool operator!=(const GrAppliedClip& that) const { return !(*this == that); } 81 82 private: 83 GrScissorState fScissorState; 84 GrWindowRectsState fWindowRectsState; 85 sk_sp<GrFragmentProcessor> fClipCoverageFP; 86 uint32_t fClipStackID = SkClipStack::kInvalidGenID; 87 }; 88 89 #endif 90