10baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy/*
20baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy * Copyright (C) 2012 The Android Open Source Project
30baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy *
40baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy * Licensed under the Apache License, Version 2.0 (the "License");
50baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy * you may not use this file except in compliance with the License.
60baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy * You may obtain a copy of the License at
70baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy *
80baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy *      http://www.apache.org/licenses/LICENSE-2.0
90baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy *
100baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy * Unless required by applicable law or agreed to in writing, software
110baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy * distributed under the License is distributed on an "AS IS" BASIS,
120baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy * See the License for the specific language governing permissions and
140baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy * limitations under the License.
150baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy */
160baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
170baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy#ifndef ANDROID_HWUI_STENCIL_H
180baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy#define ANDROID_HWUI_STENCIL_H
190baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
200baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy#ifndef LOG_TAG
210baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    #define LOG_TAG "OpenGLRenderer"
220baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy#endif
230baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
240baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy#include <cutils/compiler.h>
250baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
260baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guynamespace android {
270baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guynamespace uirenderer {
280baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
290baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy///////////////////////////////////////////////////////////////////////////////
300baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy// Stencil buffer management
310baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy///////////////////////////////////////////////////////////////////////////////
320baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
330baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guyclass ANDROID_API Stencil {
340baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guypublic:
350baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    Stencil();
360baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
370baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    /**
380baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     * Returns the desired size for the stencil buffer. If the returned value
390baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     * is 0, then no stencil buffer is required.
400baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     */
410baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    ANDROID_API static uint32_t getStencilSize();
420baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
430baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    /**
440baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     * Clears the stencil buffer.
450baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     */
460baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    void clear();
470baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
480baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    /**
490baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     * Enables stencil test. When the stencil test is enabled the stencil
500baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     * buffer is not written into.
510baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     */
520baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    void enableTest();
530baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
540baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    /**
550baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     * Enables stencil write. When stencil write is enabled, the stencil
560baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     * test always succeeds and the value 0x1 is written in the stencil
570baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     * buffer for each fragment.
580baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     */
590baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    void enableWrite();
600baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
610baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    /**
627c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy     * The test passes only when equal to the specified value.
637c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy     */
647c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    void enableDebugTest(GLint value, bool greater = false);
657c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy
667c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    /**
677c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy     * Used for debugging. The stencil test always passes and increments.
687c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy     */
697c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    void enableDebugWrite();
707c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy
717c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    /**
720baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     * Disables stencil test and write.
730baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     */
740baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    void disable();
750baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
760baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    /**
770baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     * Indicates whether either test or write is enabled.
780baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy     */
790baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    bool isEnabled() {
800baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy        return mState != kDisabled;
810baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    }
820baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
830baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guyprivate:
840baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    void enable();
850baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
860baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    enum StencilState {
870baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy        kDisabled,
880baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy        kTest,
890baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy        kWrite
900baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    };
910baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
920baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    StencilState mState;
930baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
940baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy}; // class Stencil
950baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
960baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy}; // namespace uirenderer
970baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy}; // namespace android
980baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy
990baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy#endif // ANDROID_HWUI_STENCIL_H
100