bsalomon@google.com | 170bd79 | 2012-12-05 22:26:11 +0000 | [diff] [blame] | 1 | /* |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 2 | * Copyright 2016 Google Inc. |
bsalomon@google.com | 170bd79 | 2012-12-05 22:26:11 +0000 | [diff] [blame] | 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 | |
george | 9eb182a | 2014-06-20 12:01:06 -0700 | [diff] [blame] | 8 | #ifndef GrReducedClip_DEFINED |
| 9 | #define GrReducedClip_DEFINED |
| 10 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 11 | #include "GrWindowRectangles.h" |
bsalomon@google.com | 170bd79 | 2012-12-05 22:26:11 +0000 | [diff] [blame] | 12 | #include "SkClipStack.h" |
| 13 | #include "SkTLList.h" |
| 14 | |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 15 | class GrContext; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 16 | class GrRenderTargetContext; |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 17 | |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 18 | /** |
| 19 | * This class takes a clip stack and produces a reduced set of elements that are equivalent to |
| 20 | * applying that full stack within a specified query rectangle. |
| 21 | */ |
tfarina | bf54e49 | 2014-10-23 17:47:18 -0700 | [diff] [blame] | 22 | class SK_API GrReducedClip { |
| 23 | public: |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 24 | GrReducedClip(const SkClipStack&, const SkRect& queryBounds, int maxWindowRectangles = 0); |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 27 | * If hasIBounds() is true, this is the bounding box within which the clip elements are valid. |
| 28 | * The caller must not modify any pixels outside this box. Undefined if hasIBounds() is false. |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 29 | */ |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 30 | const SkIRect& ibounds() const { SkASSERT(fHasIBounds); return fIBounds; } |
| 31 | int left() const { return this->ibounds().left(); } |
| 32 | int top() const { return this->ibounds().top(); } |
| 33 | int width() const { return this->ibounds().width(); } |
| 34 | int height() const { return this->ibounds().height(); } |
| 35 | |
| 36 | /** |
| 37 | * Indicates whether ibounds() are defined. They will always be defined if the elements() are |
| 38 | * nonempty. |
| 39 | */ |
| 40 | bool hasIBounds() const { return fHasIBounds; } |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 41 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 42 | /** |
| 43 | * If nonempty, this is a set of "exclusive" windows within which the clip elements are NOT |
| 44 | * valid. The caller must not modify any pixels inside these windows. |
| 45 | */ |
| 46 | const GrWindowRectangles& windowRectangles() const { return fWindowRects; } |
| 47 | |
bsalomon | f045d60 | 2015-11-18 19:01:12 -0800 | [diff] [blame] | 48 | typedef SkTLList<SkClipStack::Element, 16> ElementList; |
bsalomon@google.com | 170bd79 | 2012-12-05 22:26:11 +0000 | [diff] [blame] | 49 | |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 50 | /** |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 51 | * Populated with a minimal list of elements required to fully implement the clip. |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 52 | */ |
| 53 | const ElementList& elements() const { return fElements; } |
| 54 | |
| 55 | /** |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 56 | * If elements() are nonempty, uniquely identifies the list of elements within ibounds(). |
| 57 | * Otherwise undefined. |
| 58 | */ |
| 59 | int32_t elementsGenID() const { SkASSERT(!fElements.isEmpty()); return fElementsGenID; } |
| 60 | |
| 61 | /** |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 62 | * Indicates whether antialiasing is required to process any of the clip elements. |
| 63 | */ |
| 64 | bool requiresAA() const { return fRequiresAA; } |
| 65 | |
| 66 | enum class InitialState : bool { |
| 67 | kAllIn, |
| 68 | kAllOut |
tfarina | bf54e49 | 2014-10-23 17:47:18 -0700 | [diff] [blame] | 69 | }; |
bsalomon@google.com | 170bd79 | 2012-12-05 22:26:11 +0000 | [diff] [blame] | 70 | |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 71 | InitialState initialState() const { return fInitialState; } |
| 72 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 73 | bool drawAlphaClipMask(GrRenderTargetContext*) const; |
| 74 | bool drawStencilClipMask(GrContext*, GrRenderTargetContext*, const SkIPoint& clipOrigin) const; |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 75 | |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 76 | private: |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 77 | void walkStack(const SkClipStack&, const SkRect& queryBounds, int maxWindowRectangles); |
| 78 | void addInteriorWindowRectangles(int maxWindowRectangles); |
| 79 | void addWindowRectangle(const SkRect& elementInteriorRect, bool elementIsAA); |
csmartdalton | 5ecbbbe | 2016-08-23 13:26:40 -0700 | [diff] [blame] | 80 | bool intersectIBounds(const SkIRect&); |
| 81 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 82 | SkIRect fIBounds; |
| 83 | bool fHasIBounds; |
| 84 | GrWindowRectangles fWindowRects; |
| 85 | ElementList fElements; |
| 86 | int32_t fElementsGenID; |
| 87 | bool fRequiresAA; |
| 88 | InitialState fInitialState; |
bsalomon@google.com | 170bd79 | 2012-12-05 22:26:11 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
george | 9eb182a | 2014-06-20 12:01:06 -0700 | [diff] [blame] | 91 | #endif |