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