Home | History | Annotate | Download | only in renderstate
      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 #include <GLES2/gl2.h>
     21 
     22 #include <cutils/compiler.h>
     23 
     24 namespace android {
     25 namespace uirenderer {
     26 
     27 ///////////////////////////////////////////////////////////////////////////////
     28 // Stencil buffer management
     29 ///////////////////////////////////////////////////////////////////////////////
     30 
     31 class ANDROID_API Stencil {
     32 public:
     33     /**
     34      * Returns the desired size for the stencil buffer. If the returned value
     35      * is 0, then no stencil buffer is required.
     36      */
     37     ANDROID_API static uint8_t getStencilSize();
     38 
     39     static GLenum getLayerStencilFormat();
     40 
     41     /**
     42      * Clears the stencil buffer.
     43      */
     44     void clear();
     45 
     46     /**
     47      * 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.
     51      */
     52     void enableTest(int incrementThreshold);
     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. 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.
     60      */
     61     void enableWrite(int incrementThreshold);
     62 
     63     /**
     64      * 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     /**
     74      * Disables stencil test and write.
     75      */
     76     void disable();
     77 
     78     /**
     79      * Indicates whether either test or write is enabled.
     80      */
     81     bool isEnabled() {
     82         return mState != StencilState::Disabled;
     83     }
     84 
     85     /**
     86      * Indicates whether testing only is enabled.
     87      */
     88     bool isTestEnabled() {
     89         return mState == StencilState::Test;
     90     }
     91 
     92     bool isWriteEnabled() {
     93         return mState == StencilState::Write;
     94     }
     95 
     96     void dump();
     97 
     98 private:
     99     enum class StencilState {
    100         Disabled,
    101         Test,
    102         Write
    103     };
    104 
    105     void enable();
    106     StencilState mState = StencilState::Disabled;
    107 
    108 }; // class Stencil
    109 
    110 }; // namespace uirenderer
    111 }; // namespace android
    112 
    113 #endif // ANDROID_HWUI_STENCIL_H
    114