OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrReducedClip_DEFINED | 8 #ifndef GrReducedClip_DEFINED |
9 #define GrReducedClip_DEFINED | 9 #define GrReducedClip_DEFINED |
10 | 10 |
| 11 #include "GrWindowRectangles.h" |
11 #include "SkClipStack.h" | 12 #include "SkClipStack.h" |
12 #include "SkTLList.h" | 13 #include "SkTLList.h" |
13 | 14 |
14 class GrContext; | 15 class GrContext; |
15 class GrDrawContext; | 16 class GrDrawContext; |
16 | 17 |
17 /** | 18 /** |
18 * This class takes a clip stack and produces a reduced set of elements that are
equivalent to | 19 * This class takes a clip stack and produces a reduced set of elements that are
equivalent to |
19 * applying that full stack within a specified query rectangle. | 20 * applying that full stack within a specified query rectangle. |
20 */ | 21 */ |
21 class SK_API GrReducedClip { | 22 class SK_API GrReducedClip { |
22 public: | 23 public: |
23 GrReducedClip(const SkClipStack& stack, const SkRect& queryBounds); | 24 GrReducedClip(const SkClipStack&, const SkRect& queryBounds, int maxWindowRe
ctangles = 0); |
24 | 25 |
25 /** | 26 /** |
26 * If hasIBounds() is true, this is the bounding box within which the reduce
d clip is valid, and | 27 * If hasIBounds() is true, this is the bounding box within which the clip e
lements are valid. |
27 * the caller must not modify any pixels outside this box. Undefined if hasI
Bounds() is false. | 28 * The caller must not modify any pixels outside this box. Undefined if hasI
Bounds() is false. |
28 */ | 29 */ |
29 const SkIRect& ibounds() const { SkASSERT(fHasIBounds); return fIBounds; } | 30 const SkIRect& ibounds() const { SkASSERT(fHasIBounds); return fIBounds; } |
30 int left() const { return this->ibounds().left(); } | 31 int left() const { return this->ibounds().left(); } |
31 int top() const { return this->ibounds().top(); } | 32 int top() const { return this->ibounds().top(); } |
32 int width() const { return this->ibounds().width(); } | 33 int width() const { return this->ibounds().width(); } |
33 int height() const { return this->ibounds().height(); } | 34 int height() const { return this->ibounds().height(); } |
34 | 35 |
35 /** | 36 /** |
36 * Indicates whether ibounds() are defined. They will always be defined if t
he elements() are | 37 * Indicates whether ibounds() are defined. They will always be defined if t
he elements() are |
37 * nonempty. | 38 * nonempty. |
38 */ | 39 */ |
39 bool hasIBounds() const { return fHasIBounds; } | 40 bool hasIBounds() const { return fHasIBounds; } |
40 | 41 |
| 42 /** |
| 43 * If nonempty, this is a set of "exclusive" windows within which the clip e
lements are NOT |
| 44 * valid. The caller must not modify any pixels inside these windows. |
| 45 */ |
| 46 const GrWindowRectangles& windowRectangles() const { return fWindowRects; } |
| 47 |
41 typedef SkTLList<SkClipStack::Element, 16> ElementList; | 48 typedef SkTLList<SkClipStack::Element, 16> ElementList; |
42 | 49 |
43 /** | 50 /** |
44 * Populated with a minimal list of elements that implement the clip. | 51 * Populated with a minimal list of elements required to fully implement the
clip. |
45 */ | 52 */ |
46 const ElementList& elements() const { return fElements; } | 53 const ElementList& elements() const { return fElements; } |
47 | 54 |
48 /** | 55 /** |
49 * If elements() are nonempty, uniquely identifies the list of elements with
in ibounds(). | 56 * If elements() are nonempty, uniquely identifies the list of elements with
in ibounds(). |
50 * Otherwise undefined. | 57 * Otherwise undefined. |
51 */ | 58 */ |
52 int32_t elementsGenID() const { SkASSERT(!fElements.isEmpty()); return fElem
entsGenID; } | 59 int32_t elementsGenID() const { SkASSERT(!fElements.isEmpty()); return fElem
entsGenID; } |
53 | 60 |
54 /** | 61 /** |
55 * Indicates whether antialiasing is required to process any of the clip ele
ments. | 62 * Indicates whether antialiasing is required to process any of the clip ele
ments. |
56 */ | 63 */ |
57 bool requiresAA() const { return fRequiresAA; } | 64 bool requiresAA() const { return fRequiresAA; } |
58 | 65 |
59 enum class InitialState : bool { | 66 enum class InitialState : bool { |
60 kAllIn, | 67 kAllIn, |
61 kAllOut | 68 kAllOut |
62 }; | 69 }; |
63 | 70 |
64 InitialState initialState() const { return fInitialState; } | 71 InitialState initialState() const { return fInitialState; } |
65 | 72 |
66 bool drawAlphaClipMask(GrDrawContext*) const; | 73 bool drawAlphaClipMask(GrDrawContext*) const; |
67 bool drawStencilClipMask(GrContext*, GrDrawContext*, const SkIPoint& clipOri
gin) const; | 74 bool drawStencilClipMask(GrContext*, GrDrawContext*, const SkIPoint& clipOri
gin) const; |
68 | 75 |
69 private: | 76 private: |
70 void walkStack(const SkClipStack&, const SkRect& queryBounds); | 77 void walkStack(const SkClipStack&, const SkRect& queryBounds, int maxWindowR
ectangles); |
| 78 void addInteriorWindowRectangles(int maxWindowRectangles); |
| 79 void addWindowRectangle(const SkRect& elementInteriorRect, bool elementIsAA)
; |
71 bool intersectIBounds(const SkIRect&); | 80 bool intersectIBounds(const SkIRect&); |
72 | 81 |
73 SkIRect fIBounds; | 82 SkIRect fIBounds; |
74 bool fHasIBounds; | 83 bool fHasIBounds; |
75 ElementList fElements; | 84 GrWindowRectangles fWindowRects; |
76 int32_t fElementsGenID; | 85 ElementList fElements; |
77 bool fRequiresAA; | 86 int32_t fElementsGenID; |
78 InitialState fInitialState; | 87 bool fRequiresAA; |
| 88 InitialState fInitialState; |
79 }; | 89 }; |
80 | 90 |
81 #endif | 91 #endif |
OLD | NEW |