blob: 2c2e313b4fb67b7fed261bc1bb75f90bd812e332 [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
Robert Phillips06273bc2021-08-11 15:43:50 -04008#include "src/gpu/GrDrawOpTest.h"
9
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkTypes.h"
11#include "include/private/GrContext_Base.h"
12#include "include/utils/SkRandom.h"
13#include "src/gpu/GrBaseContextPriv.h"
14#include "src/gpu/GrCaps.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/GrUserStencilSettings.h"
Brian Salomon5ec9def2016-12-20 15:34:05 -050016
Hal Canary6f6961e2017-01-31 13:50:44 -050017#if GR_TEST_UTILS
Brian Salomon5ec9def2016-12-20 15:34:05 -050018
Robert Phillipsb97da532019-02-12 15:24:12 -050019const GrUserStencilSettings* GrGetRandomStencil(SkRandom* random, GrContext_Base* context) {
Robert Phillips9da87e02019-02-04 13:26:26 -050020 if (context->priv().caps()->avoidStencilBuffers()) {
Brian Salomon17726632017-05-12 14:09:46 -040021 return &GrUserStencilSettings::kUnused;
22 }
23 static constexpr GrUserStencilSettings kReads(
24 GrUserStencilSettings::StaticInit<
25 0x8080,
26 GrUserStencilTest::kLess,
27 0xffff,
28 GrUserStencilOp::kKeep,
29 GrUserStencilOp::kKeep,
30 0xffff>()
31 );
32 static constexpr GrUserStencilSettings kWrites(
33 GrUserStencilSettings::StaticInit<
34 0xffff,
35 GrUserStencilTest::kAlways,
36 0xffff,
37 GrUserStencilOp::kReplace,
38 GrUserStencilOp::kReplace,
39 0xffff>()
40 );
41 static constexpr GrUserStencilSettings kReadsAndWrites(
42 GrUserStencilSettings::StaticInit<
43 0x8000,
44 GrUserStencilTest::kEqual,
45 0x6000,
46 GrUserStencilOp::kIncWrap,
47 GrUserStencilOp::kInvert,
48 0x77ff>()
49 );
Brian Salomon5ec9def2016-12-20 15:34:05 -050050
Brian Salomon17726632017-05-12 14:09:46 -040051 static const GrUserStencilSettings* kStencilSettings[] = {
52 &GrUserStencilSettings::kUnused,
53 &kReads,
54 &kWrites,
55 &kReadsAndWrites,
Brian Salomon5ec9def2016-12-20 15:34:05 -050056 };
Brian Salomon17726632017-05-12 14:09:46 -040057 return kStencilSettings[random->nextULessThan(SK_ARRAY_COUNT(kStencilSettings))];
Brian Salomon5ec9def2016-12-20 15:34:05 -050058}
Brian Salomon17726632017-05-12 14:09:46 -040059
Brian Salomon5ec9def2016-12-20 15:34:05 -050060#endif