• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GrPathStencilSettings_DEFINED
9 #define GrPathStencilSettings_DEFINED
10 
11 #include "GrUserStencilSettings.h"
12 
13 ////////////////////////////////////////////////////////////////////////////////
14 // Stencil rules for paths
15 
16 ////// Even/Odd
17 
18 static constexpr GrUserStencilSettings gEOStencilPass(
19     GrUserStencilSettings::StaticInit<
20         0xffff,
21         GrUserStencilTest::kAlwaysIfInClip,
22         0xffff,
23         GrUserStencilOp::kInvert,
24         GrUserStencilOp::kKeep,
25         0xffff>()
26 );
27 
28 // ok not to check clip b/c stencil pass only wrote inside clip
29 static constexpr GrUserStencilSettings gEOColorPass(
30     GrUserStencilSettings::StaticInit<
31         0x0000,
32         GrUserStencilTest::kNotEqual,
33         0xffff,
34         GrUserStencilOp::kZero,
35         GrUserStencilOp::kZero,
36         0xffff>()
37 );
38 
39 // have to check clip b/c outside clip will always be zero.
40 static constexpr GrUserStencilSettings gInvEOColorPass(
41     GrUserStencilSettings::StaticInit<
42         0x0000,
43         GrUserStencilTest::kEqualIfInClip,
44         0xffff,
45         GrUserStencilOp::kZero,
46         GrUserStencilOp::kZero,
47         0xffff>()
48 );
49 
50 ////// Winding
51 
52 // when we have separate stencil we increment front faces / decrement back faces
53 // when we don't have wrap incr and decr we use the stencil test to simulate
54 // them.
55 
56 static constexpr GrUserStencilSettings gWindStencilSeparateWithWrap(
57     GrUserStencilSettings::StaticInitSeparate<
58         0xffff,                                0xffff,
59         GrUserStencilTest::kAlwaysIfInClip,    GrUserStencilTest::kAlwaysIfInClip,
60         0xffff,                                0xffff,
61         GrUserStencilOp::kIncWrap,             GrUserStencilOp::kDecWrap,
62         GrUserStencilOp::kKeep,                GrUserStencilOp::kKeep,
63         0xffff,                                0xffff>()
64 );
65 
66 // if inc'ing the max value, invert to make 0
67 // if dec'ing zero invert to make all ones.
68 // we can't avoid touching the stencil on both passing and
69 // failing, so we can't resctrict ourselves to the clip.
70 static constexpr GrUserStencilSettings gWindStencilSeparateNoWrap(
71     GrUserStencilSettings::StaticInitSeparate<
72         0xffff,                                0x0000,
73         GrUserStencilTest::kEqual,             GrUserStencilTest::kEqual,
74         0xffff,                                0xffff,
75         GrUserStencilOp::kInvert,              GrUserStencilOp::kInvert,
76         GrUserStencilOp::kIncMaybeClamp,       GrUserStencilOp::kDecMaybeClamp,
77         0xffff,                                0xffff>()
78 );
79 
80 // When there are no separate faces we do two passes to setup the winding rule
81 // stencil. First we draw the front faces and inc, then we draw the back faces
82 // and dec. These are same as the above two split into the incrementing and
83 // decrementing passes.
84 static constexpr GrUserStencilSettings gWindSingleStencilWithWrapInc(
85     GrUserStencilSettings::StaticInit<
86         0xffff,
87         GrUserStencilTest::kAlwaysIfInClip,
88         0xffff,
89         GrUserStencilOp::kIncWrap,
90         GrUserStencilOp::kKeep,
91         0xffff>()
92 );
93 
94 static constexpr GrUserStencilSettings gWindSingleStencilWithWrapDec(
95     GrUserStencilSettings::StaticInit<
96         0xffff,
97         GrUserStencilTest::kAlwaysIfInClip,
98         0xffff,
99         GrUserStencilOp::kDecWrap,
100         GrUserStencilOp::kKeep,
101         0xffff>()
102 );
103 
104 static constexpr GrUserStencilSettings gWindSingleStencilNoWrapInc(
105     GrUserStencilSettings::StaticInit<
106         0xffff,
107         GrUserStencilTest::kEqual,
108         0xffff,
109         GrUserStencilOp::kInvert,
110         GrUserStencilOp::kIncMaybeClamp,
111         0xffff>()
112 );
113 
114 static constexpr GrUserStencilSettings gWindSingleStencilNoWrapDec(
115     GrUserStencilSettings::StaticInit<
116         0x0000,
117         GrUserStencilTest::kEqual,
118         0xffff,
119         GrUserStencilOp::kInvert,
120         GrUserStencilOp::kDecMaybeClamp,
121         0xffff>()
122 );
123 
124 // Color passes are the same whether we use the two-sided stencil or two passes
125 
126 static constexpr GrUserStencilSettings gWindColorPass(
127     GrUserStencilSettings::StaticInit<
128         0x0000,
129         GrUserStencilTest::kLessIfInClip, // "0 < stencil" is equivalent to "0 != stencil".
130         0xffff,
131         GrUserStencilOp::kZero,
132         GrUserStencilOp::kZero,
133         0xffff>()
134 );
135 
136 static constexpr GrUserStencilSettings gInvWindColorPass(
137     GrUserStencilSettings::StaticInit<
138         0x0000,
139         GrUserStencilTest::kEqualIfInClip,
140         0xffff,
141         GrUserStencilOp::kZero,
142         GrUserStencilOp::kZero,
143         0xffff>()
144 );
145 
146 ////// Normal render to stencil
147 
148 // Sometimes the default path renderer can draw a path directly to the stencil
149 // buffer without having to first resolve the interior / exterior.
150 static constexpr GrUserStencilSettings gDirectToStencil(
151     GrUserStencilSettings::StaticInit<
152         0x0000,
153         GrUserStencilTest::kAlwaysIfInClip,
154         0xffff,
155         GrUserStencilOp::kZero,
156         GrUserStencilOp::kIncMaybeClamp,
157         0xffff>()
158 );
159 
160 #endif
161