blob: 5f7d4056b51d14e266193cabe55cbdf8d58595a0 [file] [log] [blame]
Romain Guy0baaac52012-08-31 20:31:01 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_HWUI_STENCIL_H
18#define ANDROID_HWUI_STENCIL_H
19
Romain Guy3bbacf22013-02-06 16:51:04 -080020#include <GLES2/gl2.h>
21
Romain Guy0baaac52012-08-31 20:31:01 -070022#include <cutils/compiler.h>
23
24namespace android {
25namespace uirenderer {
26
27///////////////////////////////////////////////////////////////////////////////
28// Stencil buffer management
29///////////////////////////////////////////////////////////////////////////////
30
31class ANDROID_API Stencil {
32public:
Romain Guy0baaac52012-08-31 20:31:01 -070033 /**
34 * Returns the desired size for the stencil buffer. If the returned value
35 * is 0, then no stencil buffer is required.
36 */
John Reck23b797a2014-01-03 18:08:34 -080037 ANDROID_API static uint8_t getStencilSize();
Romain Guy0baaac52012-08-31 20:31:01 -070038
Chris Craike1450132015-04-28 17:55:50 -070039 static GLenum getLayerStencilFormat();
Romain Guy3bbacf22013-02-06 16:51:04 -080040
41 /**
Romain Guy0baaac52012-08-31 20:31:01 -070042 * Clears the stencil buffer.
43 */
44 void clear();
45
46 /**
Rob Tsuk487a92c2015-01-06 13:22:54 -080047 * Enables stencil test. When the stencil test is enabled the stencil buffer is not written
48 * into. An increment threshold of zero causes the stencil to use a constant reference value
49 * and GL_EQUAL for the test. A non-zero increment threshold causes the stencil to use that
50 * value as the reference value and GL_EQUAL for the test.
Romain Guy0baaac52012-08-31 20:31:01 -070051 */
Rob Tsuk487a92c2015-01-06 13:22:54 -080052 void enableTest(int incrementThreshold);
Romain Guy0baaac52012-08-31 20:31:01 -070053
54 /**
55 * Enables stencil write. When stencil write is enabled, the stencil
56 * test always succeeds and the value 0x1 is written in the stencil
Rob Tsuk487a92c2015-01-06 13:22:54 -080057 * buffer for each fragment. An increment threshold of zero causes the stencil to use a constant
58 * reference value and GL_EQUAL for the test. A non-zero increment threshold causes the stencil
59 * to use that value as the reference value and GL_EQUAL for the test.
Romain Guy0baaac52012-08-31 20:31:01 -070060 */
Rob Tsuk487a92c2015-01-06 13:22:54 -080061 void enableWrite(int incrementThreshold);
Romain Guy0baaac52012-08-31 20:31:01 -070062
63 /**
Romain Guy7c450aa2012-09-21 19:15:00 -070064 * The test passes only when equal to the specified value.
65 */
66 void enableDebugTest(GLint value, bool greater = false);
67
68 /**
69 * Used for debugging. The stencil test always passes and increments.
70 */
71 void enableDebugWrite();
72
73 /**
Romain Guy0baaac52012-08-31 20:31:01 -070074 * Disables stencil test and write.
75 */
76 void disable();
77
78 /**
79 * Indicates whether either test or write is enabled.
80 */
81 bool isEnabled() {
Chris Craikb9ce116d2015-08-20 15:14:06 -070082 return mState != StencilState::Disabled;
Romain Guy0baaac52012-08-31 20:31:01 -070083 }
84
Romain Guy3ff0bfd2013-02-25 14:15:37 -080085 /**
86 * Indicates whether testing only is enabled.
87 */
88 bool isTestEnabled() {
Chris Craikb9ce116d2015-08-20 15:14:06 -070089 return mState == StencilState::Test;
Romain Guy3ff0bfd2013-02-25 14:15:37 -080090 }
91
Chris Craik2ab95d72015-02-06 15:25:51 -080092 bool isWriteEnabled() {
Chris Craikb9ce116d2015-08-20 15:14:06 -070093 return mState == StencilState::Write;
Chris Craik2ab95d72015-02-06 15:25:51 -080094 }
95
Chris Craik117bdbc2015-02-05 10:12:38 -080096 void dump();
97
Romain Guy0baaac52012-08-31 20:31:01 -070098private:
Chris Craikb9ce116d2015-08-20 15:14:06 -070099 enum class StencilState {
100 Disabled,
101 Test,
102 Write
Romain Guy0baaac52012-08-31 20:31:01 -0700103 };
104
Chris Craikb9ce116d2015-08-20 15:14:06 -0700105 void enable();
106 StencilState mState = StencilState::Disabled;
Romain Guy0baaac52012-08-31 20:31:01 -0700107
108}; // class Stencil
109
110}; // namespace uirenderer
111}; // namespace android
112
113#endif // ANDROID_HWUI_STENCIL_H