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