Stencil.h revision 7c450aaa3caac2a05fcb20a177483d0e92378426
1/*
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
20#ifndef LOG_TAG
21    #define LOG_TAG "OpenGLRenderer"
22#endif
23
24#include <cutils/compiler.h>
25
26namespace android {
27namespace uirenderer {
28
29///////////////////////////////////////////////////////////////////////////////
30// Stencil buffer management
31///////////////////////////////////////////////////////////////////////////////
32
33class ANDROID_API Stencil {
34public:
35    Stencil();
36
37    /**
38     * Returns the desired size for the stencil buffer. If the returned value
39     * is 0, then no stencil buffer is required.
40     */
41    ANDROID_API static uint32_t getStencilSize();
42
43    /**
44     * Clears the stencil buffer.
45     */
46    void clear();
47
48    /**
49     * Enables stencil test. When the stencil test is enabled the stencil
50     * buffer is not written into.
51     */
52    void enableTest();
53
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
57     * buffer for each fragment.
58     */
59    void enableWrite();
60
61    /**
62     * The test passes only when equal to the specified value.
63     */
64    void enableDebugTest(GLint value, bool greater = false);
65
66    /**
67     * Used for debugging. The stencil test always passes and increments.
68     */
69    void enableDebugWrite();
70
71    /**
72     * Disables stencil test and write.
73     */
74    void disable();
75
76    /**
77     * Indicates whether either test or write is enabled.
78     */
79    bool isEnabled() {
80        return mState != kDisabled;
81    }
82
83private:
84    void enable();
85
86    enum StencilState {
87        kDisabled,
88        kTest,
89        kWrite
90    };
91
92    StencilState mState;
93
94}; // class Stencil
95
96}; // namespace uirenderer
97}; // namespace android
98
99#endif // ANDROID_HWUI_STENCIL_H
100