Stencil.h revision 0baaac5e9adf3ee280ae1239e2e58754a9d2b099
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     * Disables stencil test and write.
63     */
64    void disable();
65
66    /**
67     * Indicates whether either test or write is enabled.
68     */
69    bool isEnabled() {
70        return mState != kDisabled;
71    }
72
73private:
74    void enable();
75
76    enum StencilState {
77        kDisabled,
78        kTest,
79        kWrite
80    };
81
82    StencilState mState;
83
84}; // class Stencil
85
86}; // namespace uirenderer
87}; // namespace android
88
89#endif // ANDROID_HWUI_STENCIL_H
90