blob: 7aba424b3da0f0040010d12e6b369495e3506411 [file] [log] [blame]
Brian Salomon5ec9def2016-12-20 15:34:05 -05001/*
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"
Brian Salomon17726632017-05-12 14:09:46 -04009#include "GrCaps.h"
10#include "GrContext.h"
11#include "GrUserStencilSettings.h"
Brian Salomon5ec9def2016-12-20 15:34:05 -050012#include "SkRandom.h"
13#include "SkTypes.h"
14
Hal Canary6f6961e2017-01-31 13:50:44 -050015#if GR_TEST_UTILS
Brian Salomon5ec9def2016-12-20 15:34:05 -050016
Brian Salomon17726632017-05-12 14:09:46 -040017const 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 );
Brian Salomon5ec9def2016-12-20 15:34:05 -050048
Brian Salomon17726632017-05-12 14:09:46 -040049 static const GrUserStencilSettings* kStencilSettings[] = {
50 &GrUserStencilSettings::kUnused,
51 &kReads,
52 &kWrites,
53 &kReadsAndWrites,
Brian Salomon5ec9def2016-12-20 15:34:05 -050054 };
Brian Salomon17726632017-05-12 14:09:46 -040055 return kStencilSettings[random->nextULessThan(SK_ARRAY_COUNT(kStencilSettings))];
Brian Salomon5ec9def2016-12-20 15:34:05 -050056}
Brian Salomon17726632017-05-12 14:09:46 -040057
Brian Salomon5ec9def2016-12-20 15:34:05 -050058#endif