11cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 21cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger/* 31cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger * Copyright 2011 Google Inc. 41cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger * 51cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger * Use of this source code is governed by a BSD-style license that can be 61cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger * found in the LICENSE file. 71cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger */ 81cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 91cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 101cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger#include "GrStencil.h" 111cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 121cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger//////////////////////////////////////////////////////////////////////////////// 131cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// Stencil Rules for Merging user stencil space into clip 141cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 151cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// We can't include the clip bit in the ref or mask values because the division 161cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// between user and clip bits in the stencil depends on the number of stencil 171cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// bits in the runtime. Comments below indicate what the code should do to 181cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// incorporate the clip bit into these settings. 191cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 201cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger/////// 211cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// Replace 221cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 231cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// set the ref to be the clip bit, but mask it out for the test 241cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gUserToClipReplace, 251cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 261cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 271cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kLess_StencilFunc, 281cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, // unset clip bit 291cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, // set clip bit 301cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff); 311cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 321cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gInvUserToClipReplace, 331cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 341cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 351cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kEqual_StencilFunc, 361cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, // unset clip bit 371cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, // set clip bit 381cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff); 391cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 401cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger/////// 411cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// Intersect 421cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gUserToClipIsect, 431cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 441cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 451cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kLess_StencilFunc, 461cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, 471cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, // set clip bit 481cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff); 491cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 501cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gInvUserToClipIsect, 511cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 521cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 531cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kEqual_StencilFunc, 541cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, 551cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, // set clip bit 561cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff); 571cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 581cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger/////// 591cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// Difference 601cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gUserToClipDiff, 611cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 621cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 631cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kEqual_StencilFunc, 641cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, 651cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, // set clip bit 661cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff); 671cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 681cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gInvUserToClipDiff, 691cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 701cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 711cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kLess_StencilFunc, 721cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, 731cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, // set clip bit 741cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff); 751cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 761cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger/////// 771cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// Union 781cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 791cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// first pass makes all the passing cases >= just clip bit set. 801cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gUserToClipUnionPass0, 811cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 821cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kKeep_StencilOp, 831cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kLEqual_StencilFunc, 841cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, 851cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0001, // set clip bit 861cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff); 871cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 881cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// second pass allows anything greater than just clip bit set to pass 891cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gUserToClipUnionPass1, 901cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 911cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 921cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kLEqual_StencilFunc, 931cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, 941cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, // set clip bit 951cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff); 961cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 971cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// first pass finds zeros in the user bits and if found sets 981cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// the clip bit to 1 991cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gInvUserToClipUnionPass0, 1001cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 1011cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kKeep_StencilOp, 1021cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kEqual_StencilFunc, 1031cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, 1041cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, // set clip bit 1051cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000 // set clip bit 1061cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger); 1071cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 1081cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// second pass zeros the user bits 1091cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gInvUserToClipUnionPass1, 1101cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 1111cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 1121cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kLess_StencilFunc, 1131cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, 1141cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, 1151cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff // unset clip bit 1161cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger); 1171cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 1181cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger/////// 1191cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// Xor 1201cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gUserToClipXorPass0, 1211cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kInvert_StencilOp, 1221cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kKeep_StencilOp, 1231cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kEqual_StencilFunc, 1241cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, // unset clip bit 1251cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, 1261cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff); 1271cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 1281cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gUserToClipXorPass1, 1291cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 1301cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 1311cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kGreater_StencilFunc, 1321cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, 1331cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, // set clip bit 1341cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff); 1351cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 1361cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gInvUserToClipXorPass0, 1371cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kInvert_StencilOp, 1381cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kKeep_StencilOp, 1391cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kEqual_StencilFunc, 1401cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, // unset clip bit 1411cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, 1421cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff); 1431cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 1441cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gInvUserToClipXorPass1, 1451cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 1461cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 1471cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kLess_StencilFunc, 1481cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, 1491cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, // set clip bit 1501cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff); 1511cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 1521cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger/////// 1531cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// Reverse Diff 1541cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gUserToClipRDiffPass0, 1551cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kInvert_StencilOp, 1561cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 1571cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kLess_StencilFunc, 1581cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, // unset clip bit 1591cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, // set clip bit 1601cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff); 1611cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 1621cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gUserToClipRDiffPass1, 1631cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 1641cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 1651cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kEqual_StencilFunc, 1661cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, // set clip bit 1671cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, // set clip bit 1681cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff); 1691cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 1701cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gInvUserToClipRDiff, 1711cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kInvert_StencilOp, 1721cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 1731cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kEqual_StencilFunc, 1741cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, 1751cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, 1761cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000 // set clip bit 1771cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger); 1781cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger/////// 1791cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// Direct to Stencil 1801cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 1811cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// We can render a clip element directly without first writing to the client 1821cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// portion of the clip when the fill is not inverse and the set operation will 1831cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// only modify the in/out status of samples covered by the clip element. 1841cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 1851cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// this one only works if used right after stencil clip was cleared. 1861cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger// Our GrClip doesn't allow midstream replace ops. 1871cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gReplaceClip, 1881cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 1891cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 1901cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kAlways_StencilFunc, 1911cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, 1921cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, // set clip bit 1931cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000 // set clipBit 1941cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger); 1951cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 1961cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gUnionClip, 1971cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 1981cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kReplace_StencilOp, 1991cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kAlways_StencilFunc, 2001cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, 2011cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, // set clip bit 2021cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000 // set clip bit 2031cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger); 2041cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 2051cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gXorClip, 2061cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kInvert_StencilOp, 2071cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kInvert_StencilOp, 2081cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kAlways_StencilFunc, 2091cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, 2101cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, 2111cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000 // set clip bit 2121cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger); 2131cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 2141cab2921ab279367f8206cdadc9259d12e603548Derek SollenbergerGR_STATIC_CONST_SAME_STENCIL(gDiffClip, 2151cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 2161cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kZero_StencilOp, 2171cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger kAlways_StencilFunc, 2181cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0xffff, 2191cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000, 2201cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 0x0000 // set clip bit 2211cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger); 2221cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 2231cab2921ab279367f8206cdadc9259d12e603548Derek Sollenbergerbool GrStencilSettings::GetClipPasses(GrSetOp op, 2241cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger bool canBeDirect, 2251cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger unsigned int stencilClipMask, 2261cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger bool invertedFill, 2271cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger int* numPasses, 2281cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger GrStencilSettings settings[kMaxStencilClipPasses]) { 2291cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger if (canBeDirect && !invertedFill) { 2301cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger *numPasses = 0; 2311cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger switch (op) { 2321cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger case kReplace_SetOp: 2331cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger *numPasses = 1; 2341cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0] = gReplaceClip; 2351cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger break; 2361cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger case kUnion_SetOp: 2371cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger *numPasses = 1; 2381cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0] = gUnionClip; 2391cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger break; 2401cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger case kXor_SetOp: 2411cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger *numPasses = 1; 2421cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0] = gXorClip; 2431cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger break; 2441cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger case kDifference_SetOp: 2451cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger *numPasses = 1; 2461cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0] = gDiffClip; 2471cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger break; 2481cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger default: // suppress warning 2491cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger break; 2501cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger } 2511cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger if (1 == *numPasses) { 2521cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontFuncRef |= stencilClipMask; 2531cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontWriteMask |= stencilClipMask; 2541cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackFuncRef = settings[0].fFrontFuncRef; 2551cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackWriteMask = settings[0].fFrontWriteMask; 2561cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger return true; 2571cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger } 2581cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger } 2591cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger switch (op) { 2601cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger // if we make the path renderer go to stencil we always give it a 2611cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger // non-inverted fill and we use the stencil rules on the client->clipbit 2621cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger // pass to select either the zeros or nonzeros. 2631cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger case kReplace_SetOp: 2641cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger *numPasses= 1; 2651cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0] = invertedFill ? gInvUserToClipReplace : gUserToClipReplace; 2661cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontFuncMask &= ~stencilClipMask; 2671cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontFuncRef |= stencilClipMask; 2681cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackFuncMask = settings[0].fFrontFuncMask; 2691cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackFuncRef = settings[0].fFrontFuncRef; 2701cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger break; 2711cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger case kIntersect_SetOp: 2721cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger *numPasses = 1; 2731cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0] = invertedFill ? gInvUserToClipIsect : gUserToClipIsect; 2741cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontFuncRef = stencilClipMask; 2751cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackFuncRef = settings[0].fFrontFuncRef; 2761cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger break; 2771cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger case kUnion_SetOp: 2781cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger *numPasses = 2; 2791cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger if (invertedFill) { 2801cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0] = gInvUserToClipUnionPass0; 2811cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontFuncMask &= ~stencilClipMask; 2821cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackFuncMask = settings[0].fFrontFuncMask; 2831cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontFuncRef |= stencilClipMask; 2841cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackFuncRef = settings[0].fFrontFuncRef; 2851cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontWriteMask |= stencilClipMask; 2861cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackWriteMask = settings[0].fFrontWriteMask; 2871cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 2881cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1] = gInvUserToClipUnionPass1; 2891cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1].fFrontWriteMask &= ~stencilClipMask; 2901cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1].fBackWriteMask &= settings[1].fFrontWriteMask; 2911cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 2921cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger } else { 2931cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0] = gUserToClipUnionPass0; 2941cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontFuncMask &= ~stencilClipMask; 2951cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontFuncRef |= stencilClipMask; 2961cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackFuncMask = settings[0].fFrontFuncMask; 2971cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackFuncRef = settings[0].fFrontFuncRef; 2981cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 2991cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1] = gUserToClipUnionPass1; 3001cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1].fFrontFuncRef |= stencilClipMask; 3011cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1].fBackFuncRef = settings[1].fFrontFuncRef; 3021cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger } 3031cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger break; 3041cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger case kXor_SetOp: 3051cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger *numPasses = 2; 3061cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger if (invertedFill) { 3071cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0] = gInvUserToClipXorPass0; 3081cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontFuncMask &= ~stencilClipMask; 3091cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackFuncMask = settings[0].fFrontFuncMask; 3101cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 3111cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1] = gInvUserToClipXorPass1; 3121cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1].fFrontFuncRef |= stencilClipMask; 3131cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1].fBackFuncRef = settings[1].fFrontFuncRef; 3141cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger } else { 3151cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0] = gUserToClipXorPass0; 3161cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontFuncMask &= ~stencilClipMask; 3171cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackFuncMask = settings[0].fFrontFuncMask; 3181cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 3191cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1] = gUserToClipXorPass1; 3201cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1].fFrontFuncRef |= stencilClipMask; 3211cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1].fBackFuncRef = settings[1].fFrontFuncRef; 3221cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger } 3231cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger break; 3241cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger case kDifference_SetOp: 3251cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger *numPasses = 1; 3261cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0] = invertedFill ? gInvUserToClipDiff : gUserToClipDiff; 3271cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontFuncRef |= stencilClipMask; 3281cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackFuncRef = settings[0].fFrontFuncRef; 3291cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger break; 3301cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger case kReverseDifference_SetOp: 3311cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger if (invertedFill) { 3321cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger *numPasses = 1; 3331cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0] = gInvUserToClipRDiff; 3341cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontWriteMask |= stencilClipMask; 3351cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackWriteMask = settings[0].fFrontWriteMask; 3361cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger } else { 3371cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger *numPasses = 2; 3381cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0] = gUserToClipRDiffPass0; 3391cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontFuncMask &= ~stencilClipMask; 3401cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackFuncMask = settings[0].fFrontFuncMask; 3411cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fFrontFuncRef |= stencilClipMask; 3421cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[0].fBackFuncRef = settings[0].fFrontFuncRef; 3431cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger 3441cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1] = gUserToClipRDiffPass1; 3451cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1].fFrontFuncMask |= stencilClipMask; 3461cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1].fFrontFuncRef |= stencilClipMask; 3471cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1].fBackFuncMask = settings[1].fFrontFuncMask; 3481cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger settings[1].fBackFuncRef = settings[1].fFrontFuncRef; 3491cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger } 3501cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger break; 3511cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger default: 3521cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger GrCrash("Unknown set op"); 3531cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger } 3541cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger return false; 3551cab2921ab279367f8206cdadc9259d12e603548Derek Sollenberger} 356