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.h" 11 #include "GrUserStencilSettings.h" 12 #include "SkRandom.h" 13 #include "SkTypes.h" 14 15 #if GR_TEST_UTILS 16 17 const GrUserStencilSettings* GrGetRandomStencil(SkRandom* random, GrContext* context) { 18 if (context->caps()->avoidStencilBuffers()) { 19 return &GrUserStencilSettings::kUnused; 20 } 21 static constexpr GrUserStencilSettings kReads( 22 GrUserStencilSettings::StaticInit< 23 0x8080, 24 GrUserStencilTest::kLess, 25 0xffff, 26 GrUserStencilOp::kKeep, 27 GrUserStencilOp::kKeep, 28 0xffff>() 29 ); 30 static constexpr GrUserStencilSettings kWrites( 31 GrUserStencilSettings::StaticInit< 32 0xffff, 33 GrUserStencilTest::kAlways, 34 0xffff, 35 GrUserStencilOp::kReplace, 36 GrUserStencilOp::kReplace, 37 0xffff>() 38 ); 39 static constexpr GrUserStencilSettings kReadsAndWrites( 40 GrUserStencilSettings::StaticInit< 41 0x8000, 42 GrUserStencilTest::kEqual, 43 0x6000, 44 GrUserStencilOp::kIncWrap, 45 GrUserStencilOp::kInvert, 46 0x77ff>() 47 ); 48 49 static const GrUserStencilSettings* kStencilSettings[] = { 50 &GrUserStencilSettings::kUnused, 51 &kReads, 52 &kWrites, 53 &kReadsAndWrites, 54 }; 55 return kStencilSettings[random->nextULessThan(SK_ARRAY_COUNT(kStencilSettings))]; 56 } 57 58 #endif 59