1 /* 2 * Copyright 2015 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "GrDrawOpTest.h" 9 #include "GrCaps.h" 10 #include "GrContext_Base.h" 11 #include "GrBaseContextPriv.h" 12 #include "GrUserStencilSettings.h" 13 #include "SkRandom.h" 14 #include "SkTypes.h" 15 16 #if GR_TEST_UTILS 17 18 const GrUserStencilSettings* GrGetRandomStencil(SkRandom* random, GrContext_Base* context) { 19 if (context->priv().caps()->avoidStencilBuffers()) { 20 return &GrUserStencilSettings::kUnused; 21 } 22 static constexpr GrUserStencilSettings kReads( 23 GrUserStencilSettings::StaticInit< 24 0x8080, 25 GrUserStencilTest::kLess, 26 0xffff, 27 GrUserStencilOp::kKeep, 28 GrUserStencilOp::kKeep, 29 0xffff>() 30 ); 31 static constexpr GrUserStencilSettings kWrites( 32 GrUserStencilSettings::StaticInit< 33 0xffff, 34 GrUserStencilTest::kAlways, 35 0xffff, 36 GrUserStencilOp::kReplace, 37 GrUserStencilOp::kReplace, 38 0xffff>() 39 ); 40 static constexpr GrUserStencilSettings kReadsAndWrites( 41 GrUserStencilSettings::StaticInit< 42 0x8000, 43 GrUserStencilTest::kEqual, 44 0x6000, 45 GrUserStencilOp::kIncWrap, 46 GrUserStencilOp::kInvert, 47 0x77ff>() 48 ); 49 50 static const GrUserStencilSettings* kStencilSettings[] = { 51 &GrUserStencilSettings::kUnused, 52 &kReads, 53 &kWrites, 54 &kReadsAndWrites, 55 }; 56 return kStencilSettings[random->nextULessThan(SK_ARRAY_COUNT(kStencilSettings))]; 57 } 58 59 #endif 60