180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2011 Google Inc.
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef GrStencil_DEFINED
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define GrStencil_DEFINED
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "GrTypes.h"
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkRegion.h"
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/**
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Gr uses the stencil buffer to implement complex clipping inside the
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * GrDrawTarget class. The GrDrawTarget makes a subset of the stencil buffer
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * bits available for other uses by external code (clients). Client code can
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * modify these bits. GrDrawTarget will ignore ref, mask, and writemask bits
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * provided by clients that overlap the bits used to implement clipping.
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * When code outside the GrDrawTarget class uses the stencil buffer the contract
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * is as follows:
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * > Normal stencil funcs allow the client to pass / fail regardless of the
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *   reserved clip bits.
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * > Additional functions allow a test against the clip along with a limited
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *   set of tests against the client bits.
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * > Client can assume all client bits are zero initially.
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * > Client must ensure that after all its passes are finished it has only
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *   written to the color buffer in the region inside the clip. Furthermore, it
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *   must zero all client bits that were modifed (both inside and outside the
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *   clip).
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/**
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Determines which pixels pass / fail the stencil test.
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Stencil test passes if (ref & mask) FUNC (stencil & mask) is true
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruenum GrStencilFunc {
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kAlways_StencilFunc = 0,
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kNever_StencilFunc,
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kGreater_StencilFunc,
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kGEqual_StencilFunc,
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kLess_StencilFunc,
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kLEqual_StencilFunc,
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kEqual_StencilFunc,
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kNotEqual_StencilFunc,
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // Gr stores the current clip in the
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // stencil buffer in the high bits that
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // are not directly accessible modifiable
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // via the GrDrawTarget interface. The below
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // stencil funcs test against the current
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // clip in addition to the GrDrawTarget
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // client's stencil bits.
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // pass if inside the clip
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kAlwaysIfInClip_StencilFunc,
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kEqualIfInClip_StencilFunc,
6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kLessIfInClip_StencilFunc,
6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kLEqualIfInClip_StencilFunc,
6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kNonZeroIfInClip_StencilFunc, // this one forces the ref to be 0
6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // counts
6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kStencilFuncCount,
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kClipStencilFuncCount = kNonZeroIfInClip_StencilFunc -
6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                            kAlwaysIfInClip_StencilFunc + 1,
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kBasicStencilFuncCount = kStencilFuncCount - kClipStencilFuncCount
7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/**
7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Operations to perform based on whether stencil test passed failed.
7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruenum GrStencilOp {
7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kKeep_StencilOp = 0,    // preserve existing stencil value
7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kReplace_StencilOp,     // replace with reference value from stencl test
7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kIncWrap_StencilOp,     // increment and wrap at max
8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kIncClamp_StencilOp,    // increment and clamp at max
8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kDecWrap_StencilOp,     // decrement and wrap at 0
8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kDecClamp_StencilOp,    // decrement and clamp at 0
8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kZero_StencilOp,        // zero stencil bits
8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kInvert_StencilOp,      // invert stencil bits
8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kStencilOpCount
8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruenum GrStencilFlags {
9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kIsDisabled_StencilFlag      = 0x1,
9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kNotDisabled_StencilFlag     = 0x2,
9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kDoesWrite_StencilFlag       = 0x4,
9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    kDoesNotWrite_StencilFlag    = 0x8,
9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/**
9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * GrStencilState needs to be a class with accessors and setters so that it
9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * can maintain flags related to its current state. However, we also want to
9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * be able to declare pre-made stencil settings at compile time (without
10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * inserting static initializer code). So all the data members are in this
10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * struct. A macro defined after the class can be used to jam an instance of
10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * this struct that is created from an initializer list into a
10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * GrStencilSettings. (We hang our heads in shame.)
10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustruct GrStencilSettingsStruct {
10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint8_t fPassOps[2];     // op to perform when faces pass (GrStencilOp)
10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint8_t fFailOps[2];     // op to perform when faces fail (GrStencilOp)
10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint8_t fFuncs[2];       // test function for faces (GrStencilFunc)
10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint8_t fPad0;
11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint8_t fPad1;
11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint16_t fFuncMasks[2];  // mask for face tests
11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint16_t fFuncRefs[2];   // reference values for face tests
11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint16_t fWriteMasks[2]; // stencil write masks
11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    mutable uint32_t fFlags;
11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// We rely on this being packed and aligned (memcmp'ed and memcpy'ed)
11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruGR_STATIC_ASSERT(sizeof(GrStencilSettingsStruct) % 4 == 0);
11880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruGR_STATIC_ASSERT(sizeof(GrStencilSettingsStruct) ==
11980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                 4*sizeof(uint8_t) + // ops
12080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                 2*sizeof(uint8_t) + // funcs
12180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                 2*sizeof(uint8_t) + // pads
12280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                 2*sizeof(uint16_t) + // func masks
12380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                 2*sizeof(uint16_t) + // ref values
12480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                 2*sizeof(uint16_t) + // write masks
12580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                 sizeof(uint32_t)); // flags
12680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
12780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// This macro is used to compute the GrStencilSettingsStructs flags
12880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// associated to disabling. It is used both to define constant structure
12980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// initializers and inside GrStencilSettings::isDisabled()
13080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru//
13180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define GR_STENCIL_SETTINGS_IS_DISABLED(                                     \
13280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_PASS_OP,    BACK_PASS_OP,                                          \
13380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_FAIL_OP,    BACK_FAIL_OP,                                          \
13480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_FUNC,       BACK_FUNC)                                             \
13580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    ((FRONT_PASS_OP) == kKeep_StencilOp &&                                   \
13680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     (BACK_PASS_OP)  == kKeep_StencilOp &&                                   \
13780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     (FRONT_FAIL_OP) == kKeep_StencilOp &&                                   \
13880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     (BACK_FAIL_OP)  == kKeep_StencilOp &&                                   \
13980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     (FRONT_FUNC)    == kAlways_StencilFunc &&                               \
14080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     (BACK_FUNC)     == kAlways_StencilFunc)
14180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
14280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define GR_STENCIL_SETTINGS_DOES_WRITE(                                      \
14380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_PASS_OP,    BACK_PASS_OP,                                          \
14480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_FAIL_OP,    BACK_FAIL_OP,                                          \
14580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_FUNC,       BACK_FUNC)                                             \
14680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    (!(((FRONT_FUNC) == kNever_StencilFunc  ||                               \
14780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        (FRONT_PASS_OP) == kKeep_StencilOp)  &&                              \
14880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru       ((BACK_FUNC) == kNever_StencilFunc  ||                                \
14980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        (BACK_PASS_OP)  == kKeep_StencilOp) &&                               \
15080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru       ((FRONT_FUNC) == kAlways_StencilFunc ||                               \
15180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        (FRONT_FAIL_OP) == kKeep_StencilOp) &&                               \
15280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru       ((BACK_FUNC)  == kAlways_StencilFunc ||                               \
15380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        (BACK_FAIL_OP)  == kKeep_StencilOp)))
15480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
15580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define GR_STENCIL_SETTINGS_DEFAULT_FLAGS(                                   \
15680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_PASS_OP,    BACK_PASS_OP,                                          \
15780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_FAIL_OP,    BACK_FAIL_OP,                                          \
15880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_FUNC,       BACK_FUNC)                                             \
15980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru  ((GR_STENCIL_SETTINGS_IS_DISABLED(FRONT_PASS_OP,BACK_PASS_OP,              \
16080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru      FRONT_FAIL_OP,BACK_FAIL_OP,FRONT_FUNC,BACK_FUNC) ?                     \
16180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru      kIsDisabled_StencilFlag : kNotDisabled_StencilFlag) |                  \
16280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru   (GR_STENCIL_SETTINGS_DOES_WRITE(FRONT_PASS_OP,BACK_PASS_OP,               \
16380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru      FRONT_FAIL_OP,BACK_FAIL_OP,FRONT_FUNC,BACK_FUNC) ?                     \
16480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru      kDoesWrite_StencilFlag : kDoesNotWrite_StencilFlag))
16580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
16680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/**
16780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Class representing stencil state.
16880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
16980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass GrStencilSettings : private GrStencilSettingsStruct {
17080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
17280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    enum Face {
17380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        kFront_Face = 0,
17480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        kBack_Face  = 1,
17580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    };
17680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrStencilSettings() {
17880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fPad0 = fPad1 = 0;
17980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        this->setDisabled();
18080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
18180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
18280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrStencilOp passOp(Face f) const { return static_cast<GrStencilOp>(fPassOps[f]); }
18380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrStencilOp failOp(Face f) const { return static_cast<GrStencilOp>(fFailOps[f]); }
18480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrStencilFunc func(Face f) const { return static_cast<GrStencilFunc>(fFuncs[f]); }
18580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint16_t funcMask(Face f) const  { return fFuncMasks[f]; }
18680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint16_t funcRef(Face f) const   { return fFuncRefs[f]; }
18780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint16_t writeMask(Face f) const { return fWriteMasks[f]; }
18880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
18980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setPassOp(Face f, GrStencilOp op) { fPassOps[f] = op; fFlags = 0;}
19080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setFailOp(Face f, GrStencilOp op) { fFailOps[f] = op; fFlags = 0;}
19180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setFunc(Face f, GrStencilFunc func) { fFuncs[f] = func; fFlags = 0;}
19280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setFuncMask(Face f, unsigned short mask) { fFuncMasks[f] = mask; }
19380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setFuncRef(Face f, unsigned short ref) { fFuncRefs[f] = ref; }
19480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setWriteMask(Face f, unsigned short writeMask) { fWriteMasks[f] = writeMask; }
19580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
19680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void copyFrontSettingsToBack() {
19780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fPassOps[kBack_Face]    = fPassOps[kFront_Face];
19880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFailOps[kBack_Face]    = fFailOps[kFront_Face];
19980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFuncs[kBack_Face]      = fFuncs[kFront_Face];
20080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFuncMasks[kBack_Face]  = fFuncMasks[kFront_Face];
20180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFuncRefs[kBack_Face]   = fFuncRefs[kFront_Face];
20280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fWriteMasks[kBack_Face] = fWriteMasks[kFront_Face];
20380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFlags = 0;
20480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
20580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
20680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setSame(GrStencilOp passOp,
20780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                 GrStencilOp failOp,
20880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                 GrStencilFunc func,
20980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                 unsigned short funcMask,
21080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                 unsigned short funcRef,
21180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                 unsigned short writeMask) {
21280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fPassOps[kFront_Face]    = fPassOps[kBack_Face]    = passOp;
21380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFailOps[kFront_Face]    = fFailOps[kBack_Face]    = failOp;
21480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFuncs[kFront_Face]      = fFuncs[kBack_Face]      = func;
21580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFuncMasks[kFront_Face]  = fFuncMasks[kBack_Face]  = funcMask;
21680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFuncRefs[kFront_Face]   = fFuncRefs[kBack_Face]   = funcRef;
21780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fWriteMasks[kFront_Face] = fWriteMasks[kBack_Face] = writeMask;
21880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFlags = 0;
21980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
22080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
22180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setDisabled() {
22280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        memset(this, 0, sizeof(*this));
22380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GR_STATIC_ASSERT(0 == kKeep_StencilOp);
22480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GR_STATIC_ASSERT(0 == kAlways_StencilFunc);
22580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFlags = kIsDisabled_StencilFlag | kDoesNotWrite_StencilFlag;
22680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
22780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
22880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool isTwoSided() const {
22980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return fPassOps[kFront_Face]    != fPassOps[kBack_Face]   ||
23080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru               fFailOps[kFront_Face]    != fFailOps[kBack_Face]   ||
23180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru               fFuncs[kFront_Face]      != fFuncs[kBack_Face]     ||
23280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru               fFuncMasks[kFront_Face]  != fFuncMasks[kBack_Face] ||
23380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru               fFuncRefs[kFront_Face]   != fFuncRefs[kBack_Face]  ||
23480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru               fWriteMasks[kFront_Face] != fWriteMasks[kBack_Face];
23580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
23680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
23780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool usesWrapOp() const {
23880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return kIncWrap_StencilOp == fPassOps[kFront_Face] ||
23980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru               kDecWrap_StencilOp == fPassOps[kFront_Face] ||
24080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru               kIncWrap_StencilOp == fPassOps[kBack_Face]  ||
24180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru               kDecWrap_StencilOp == fPassOps[kBack_Face]  ||
24280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru               kIncWrap_StencilOp == fFailOps[kFront_Face] ||
24380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru               kDecWrap_StencilOp == fFailOps[kFront_Face] ||
24480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru               kIncWrap_StencilOp == fFailOps[kBack_Face]  ||
24580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru               kDecWrap_StencilOp == fFailOps[kBack_Face];
24680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
24780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
24880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool isDisabled() const {
24980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (fFlags & kIsDisabled_StencilFlag) {
25080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return true;
25180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
25280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (fFlags & kNotDisabled_StencilFlag) {
25380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return false;
25480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
25580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        bool disabled = GR_STENCIL_SETTINGS_IS_DISABLED(
25680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                            fPassOps[kFront_Face], fPassOps[kBack_Face],
25780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                            fFailOps[kFront_Face], fFailOps[kBack_Face],
25880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                            fFuncs[kFront_Face],   fFuncs[kBack_Face]);
25980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFlags |= disabled ? kIsDisabled_StencilFlag : kNotDisabled_StencilFlag;
26080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return disabled;
26180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
26280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
26380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool doesWrite() const {
26480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (fFlags & kDoesWrite_StencilFlag) {
26580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return true;
26680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
26780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (fFlags & kDoesNotWrite_StencilFlag) {
26880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return false;
26980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
27080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        bool writes = GR_STENCIL_SETTINGS_DOES_WRITE(
27180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                            fPassOps[kFront_Face], fPassOps[kBack_Face],
27280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                            fFailOps[kFront_Face], fFailOps[kBack_Face],
27380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                            fFuncs[kFront_Face],   fFuncs[kBack_Face]);
27480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFlags |= writes ? kDoesWrite_StencilFlag : kDoesNotWrite_StencilFlag;
27580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return writes;
27680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
27780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
27880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void invalidate()  {
27980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        // write an illegal value to the first member
28080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fPassOps[0] = (GrStencilOp)(uint8_t)-1;
28180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fFlags = 0;
28280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
28380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
28480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool operator == (const GrStencilSettings& s) const {
28580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        static const size_t gCompareSize = sizeof(GrStencilSettings) -
28680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                           sizeof(fFlags);
2870a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenberger        SkASSERT((const char*)&fFlags + sizeof(fFlags) ==
28880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                 (const char*)this + sizeof(GrStencilSettings));
28980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (this->isDisabled() & s.isDisabled()) { // using & not &&
29080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return true;
29180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
29280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return 0 == memcmp(this, &s, gCompareSize);
29380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
29480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
29580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool operator != (const GrStencilSettings& s) const {
29680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return !(*this == s);
29780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
29880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
29980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrStencilSettings& operator =(const GrStencilSettings& s) {
30080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        memcpy(this, &s, sizeof(GrStencilSettings));
30180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return *this;
30280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
30380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
30480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate:
30580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    friend class GrClipMaskManager;
30680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
30780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    enum {
30880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        kMaxStencilClipPasses = 2  // maximum number of passes to add a clip
30980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                   // element to the stencil buffer.
31080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    };
31180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
31280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
31380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * Given a thing to draw into the stencil clip, a fill type, and a set op
31480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * this function determines:
31580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *      1. Whether the thing can be draw directly to the stencil clip or
31680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *      needs to be drawn to the client portion of the stencil first.
31780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *      2. How many passes are needed.
31880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *      3. What those passes are.
31980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *      4. The fill rule that should actually be used to render (will
32080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *         always be non-inverted).
32180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *
32280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * @param op                the set op to combine this element with the
32380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *                          existing clip
32480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * @param stencilClipMask   mask with just the stencil bit used for clipping
32580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *                          enabled.
32680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * @param invertedFill      is this path inverted
32780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * @param numPasses         out: the number of passes needed to add the
32880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *                               element to the clip.
32980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * @param settings          out: the stencil settings to use for each pass
33080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *
33180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * @return true if the clip element's geometry can be drawn directly to the
33280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *         stencil clip bit. Will only be true if canBeDirect is true.
33380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *         numPasses will be 1 if return value is true.
33480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
33580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool GetClipPasses(SkRegion::Op op,
33680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                              bool canBeDirect,
33780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                              unsigned int stencilClipMask,
33880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                              bool invertedFill,
33980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                              int* numPasses,
34080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                              GrStencilSettings settings[kMaxStencilClipPasses]);
34180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
34280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
34380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruGR_STATIC_ASSERT(sizeof(GrStencilSettingsStruct) == sizeof(GrStencilSettings));
34480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
34580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define GR_STATIC_CONST_STENCIL_STRUCT(STRUCT_NAME,                          \
34680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_PASS_OP,    BACK_PASS_OP,                                          \
34780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_FAIL_OP,    BACK_FAIL_OP,                                          \
34880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_FUNC,       BACK_FUNC,                                             \
34980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_MASK,       BACK_MASK,                                             \
35080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_REF,        BACK_REF,                                              \
35180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_WRITE_MASK, BACK_WRITE_MASK)                                       \
35280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static const GrStencilSettingsStruct STRUCT_NAME = {                     \
35380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru       {(FRONT_PASS_OP),    (BACK_PASS_OP)   },                              \
35480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru       {(FRONT_FAIL_OP),    (BACK_FAIL_OP)   },                              \
35580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru       {(FRONT_FUNC),       (BACK_FUNC)      },                              \
35680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        (0),                (0),                                             \
35780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru       {(FRONT_MASK),       (BACK_MASK)      },                              \
35880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru       {(FRONT_REF),        (BACK_REF)       },                              \
35980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru       {(FRONT_WRITE_MASK), (BACK_WRITE_MASK)},                              \
36080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GR_STENCIL_SETTINGS_DEFAULT_FLAGS(                                   \
36180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            FRONT_PASS_OP, BACK_PASS_OP, FRONT_FAIL_OP, BACK_FAIL_OP,        \
36280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            FRONT_FUNC, BACK_FUNC)                                           \
36380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    };
36480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
36580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(STRUCT_PTR)            \
36680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    reinterpret_cast<const GrStencilSettings*>(STRUCT_PTR)
36780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
36880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define GR_STATIC_CONST_SAME_STENCIL_STRUCT(STRUCT_NAME,                     \
36980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    PASS_OP, FAIL_OP, FUNC, MASK, REF, WRITE_MASK)                           \
37080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GR_STATIC_CONST_STENCIL_STRUCT(STRUCT_NAME, (PASS_OP), (PASS_OP),        \
37180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    (FAIL_OP),(FAIL_OP), (FUNC), (FUNC), (MASK), (MASK), (REF), (REF),       \
37280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    (WRITE_MASK),(WRITE_MASK))
37380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
37480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define GR_STATIC_CONST_STENCIL(NAME,                                        \
37580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_PASS_OP,    BACK_PASS_OP,                                          \
37680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_FAIL_OP,    BACK_FAIL_OP,                                          \
37780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_FUNC,       BACK_FUNC,                                             \
37880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_MASK,       BACK_MASK,                                             \
37980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_REF,        BACK_REF,                                              \
38080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    FRONT_WRITE_MASK, BACK_WRITE_MASK)                                       \
38180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GR_STATIC_CONST_STENCIL_STRUCT(NAME ## _STRUCT,                          \
38280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    (FRONT_PASS_OP),(BACK_PASS_OP),(FRONT_FAIL_OP),(BACK_FAIL_OP),           \
38380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    (FRONT_FUNC),(BACK_FUNC),(FRONT_MASK),(BACK_MASK),                       \
38480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    (FRONT_REF),(BACK_REF),(FRONT_WRITE_MASK),(BACK_WRITE_MASK))             \
38580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static const GrStencilSettings& NAME =                                   \
38680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&(NAME ## _STRUCT));
38780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
38880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
38980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define GR_STATIC_CONST_SAME_STENCIL(NAME,                                   \
39080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    PASS_OP, FAIL_OP, FUNC, MASK, REF, WRITE_MASK)                           \
39180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GR_STATIC_CONST_STENCIL(NAME, (PASS_OP), (PASS_OP), (FAIL_OP),           \
39280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    (FAIL_OP), (FUNC), (FUNC), (MASK), (MASK), (REF), (REF), (WRITE_MASK),   \
39380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    (WRITE_MASK))
39480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
39580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
396