blob: dbffe3ceb3f8362b63f4208571157e5f38d5f416 [file] [log] [blame]
Brian Salomoncfe910d2017-07-06 16:40:18 -04001/*
2 * Copyright 2017 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#ifndef GrMockOptions_DEFINED
9#define GrMockOptions_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/GrTypes.h"
12#include "include/private/GrTypesPriv.h"
Brian Salomoncfe910d2017-07-06 16:40:18 -040013
Robert Phillipsa5e78be2019-07-09 12:34:38 -040014class GrBackendFormat;
15
Brian Salomon8fe24272017-07-07 12:56:11 -040016struct GrMockTextureInfo {
Robert Phillipsa5e78be2019-07-09 12:34:38 -040017 GrMockTextureInfo()
18 : fColorType(GrColorType::kUnknown)
Robert Phillipsa27d6252019-12-10 14:48:36 -050019 , fCompressionType(SkImage::CompressionType::kNone)
Robert Phillipsa5e78be2019-07-09 12:34:38 -040020 , fID(0) {}
21
Robert Phillipsa27d6252019-12-10 14:48:36 -050022 GrMockTextureInfo(GrColorType colorType,
23 SkImage::CompressionType compressionType,
24 int id)
Robert Phillipsa5e78be2019-07-09 12:34:38 -040025 : fColorType(colorType)
Robert Phillipsa27d6252019-12-10 14:48:36 -050026 , fCompressionType(compressionType)
Robert Phillipsa5e78be2019-07-09 12:34:38 -040027 , fID(id) {
28 SkASSERT(fID);
Robert Phillipsa27d6252019-12-10 14:48:36 -050029 if (fCompressionType != SkImage::CompressionType::kNone) {
30 SkASSERT(colorType == GrColorType::kUnknown);
31 }
Robert Phillipsa5e78be2019-07-09 12:34:38 -040032 }
Robert Phillipsc5509952018-04-04 15:54:55 -040033
34 bool operator==(const GrMockTextureInfo& that) const {
Robert Phillipsa5e78be2019-07-09 12:34:38 -040035 return fColorType == that.fColorType &&
Robert Phillipsa27d6252019-12-10 14:48:36 -050036 fCompressionType == that.fCompressionType &&
Robert Phillipsa5e78be2019-07-09 12:34:38 -040037 fID == that.fID;
Robert Phillipsc5509952018-04-04 15:54:55 -040038 }
Robert Phillipsa5e78be2019-07-09 12:34:38 -040039
Robert Phillipsa5e78be2019-07-09 12:34:38 -040040 GrBackendFormat getBackendFormat() const;
41
Robert Phillipsa27d6252019-12-10 14:48:36 -050042 SkImage::CompressionType compressionType() const { return fCompressionType; }
43
44 GrColorType colorType() const {
45 SkASSERT(fCompressionType == SkImage::CompressionType::kNone);
46 return fColorType;
47 }
48
49 int id() const { return fID; }
50
51private:
52 GrColorType fColorType;
53 SkImage::CompressionType fCompressionType;
54 int fID;
Brian Salomon0c51eea2018-03-09 17:02:09 -050055};
56
57struct GrMockRenderTargetInfo {
Robert Phillipsa5e78be2019-07-09 12:34:38 -040058 GrMockRenderTargetInfo()
59 : fColorType(GrColorType::kUnknown)
Robert Phillipsa5e78be2019-07-09 12:34:38 -040060 , fID(0) {}
61
Greg Daniele877dce2019-07-11 10:52:43 -040062 GrMockRenderTargetInfo(GrColorType colorType, int id)
Robert Phillipsa5e78be2019-07-09 12:34:38 -040063 : fColorType(colorType)
Robert Phillipsa5e78be2019-07-09 12:34:38 -040064 , fID(id) {
65 SkASSERT(fID);
66 }
Robert Phillipsc5509952018-04-04 15:54:55 -040067
68 bool operator==(const GrMockRenderTargetInfo& that) const {
Robert Phillipsa5e78be2019-07-09 12:34:38 -040069 return fColorType == that.fColorType &&
Robert Phillipsa5e78be2019-07-09 12:34:38 -040070 fID == that.fID;
Robert Phillipsc5509952018-04-04 15:54:55 -040071 }
Robert Phillipsa5e78be2019-07-09 12:34:38 -040072
Robert Phillipsa5e78be2019-07-09 12:34:38 -040073 GrBackendFormat getBackendFormat() const;
74
Robert Phillipsc80b0e92019-07-23 10:27:09 -040075 GrColorType colorType() const { return fColorType; }
76
Robert Phillipsa5e78be2019-07-09 12:34:38 -040077private:
78 GrColorType fColorType;
Robert Phillipsa5e78be2019-07-09 12:34:38 -040079 int fID;
Brian Salomon8fe24272017-07-07 12:56:11 -040080};
81
Greg Daniel84261652021-09-19 17:53:40 -040082struct GrMockSurfaceInfo {
83 uint32_t fSampleCount = 1;
84 uint32_t fLevelCount = 0;
85 GrProtected fProtected = GrProtected::kNo;
86
87 GrColorType fColorType = GrColorType::kUnknown;
88 SkImage::CompressionType fCompressionType = SkImage::CompressionType::kNone;
89};
90
Brian Salomoncfe910d2017-07-06 16:40:18 -040091/**
92 * A pointer to this type is used as the GrBackendContext when creating a Mock GrContext. It can be
Brian Salomon821ef182017-11-07 16:41:11 -050093 * used to specify capability options for the mock context. If nullptr is used a default constructed
94 * GrMockOptions is used.
Brian Salomoncfe910d2017-07-06 16:40:18 -040095 */
96struct GrMockOptions {
97 GrMockOptions() {
Brian Salomonbdecacf2018-02-02 20:32:49 -050098 using Renderability = ConfigOptions::Renderability;
Robert Phillipsd0906422019-07-08 09:27:39 -040099 // By default RGBA_8888 and BGRA_8888 are textureable and renderable and
100 // A8 and RGB565 are texturable.
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400101 fConfigOptions[(int)GrColorType::kRGBA_8888].fRenderability = Renderability::kNonMSAA;
102 fConfigOptions[(int)GrColorType::kRGBA_8888].fTexturable = true;
103 fConfigOptions[(int)GrColorType::kAlpha_8].fTexturable = true;
104 fConfigOptions[(int)GrColorType::kBGR_565].fTexturable = true;
Robert Phillipsd0906422019-07-08 09:27:39 -0400105
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400106 fConfigOptions[(int)GrColorType::kBGRA_8888] = fConfigOptions[(int)GrColorType::kRGBA_8888];
Robert Phillipsa27d6252019-12-10 14:48:36 -0500107
Robert Phillipsc558f722020-01-13 13:02:26 -0500108 fCompressedOptions[(int)SkImage::CompressionType::kETC2_RGB8_UNORM].fTexturable = true;
Robert Phillips8f259a02019-12-20 11:32:27 -0500109 fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGB8_UNORM].fTexturable = true;
Robert Phillipsb0855272020-01-15 12:56:52 -0500110 fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGBA8_UNORM].fTexturable = true;
Brian Salomoncfe910d2017-07-06 16:40:18 -0400111 }
112
113 struct ConfigOptions {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500114 enum Renderability { kNo, kNonMSAA, kMSAA };
Brian Osman29c88082019-04-02 14:28:32 -0400115 Renderability fRenderability = kNo;
Brian Salomoncfe910d2017-07-06 16:40:18 -0400116 bool fTexturable = false;
117 };
118
Chris Dalton91ab1552018-04-18 13:24:25 -0600119 // GrCaps options.
Brian Salomon69100f02020-07-21 10:49:25 -0400120 bool fMipmapSupport = false;
Chris Daltona77cdee2020-04-03 14:50:43 -0600121 bool fDrawInstancedSupport = false;
Brian Osmanc6444d22019-01-09 16:30:12 -0500122 bool fHalfFloatVertexAttributeSupport = false;
Chris Daltonfddb6c02017-11-04 15:22:22 -0600123 uint32_t fMapBufferFlags = 0;
Brian Salomoncfe910d2017-07-06 16:40:18 -0400124 int fMaxTextureSize = 2048;
125 int fMaxRenderTargetSize = 2048;
Robert Phillipsc4fbc8d2020-11-30 10:17:53 -0500126 int fMaxWindowRectangles = 0;
Brian Salomoncfe910d2017-07-06 16:40:18 -0400127 int fMaxVertexAttributes = 16;
Chris Daltonb96995d2020-06-04 16:44:29 -0600128 int fMaxTessellationSegments = 0;
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400129 ConfigOptions fConfigOptions[kGrColorTypeCnt];
Robert Phillipsa27d6252019-12-10 14:48:36 -0500130 ConfigOptions fCompressedOptions[SkImage::kCompressionTypeCount];
Chris Daltonfddb6c02017-11-04 15:22:22 -0600131
Chris Dalton91ab1552018-04-18 13:24:25 -0600132 // GrShaderCaps options.
Chris Daltonfddb6c02017-11-04 15:22:22 -0600133 bool fIntegerSupport = false;
134 bool fFlatInterpolationSupport = false;
135 int fMaxVertexSamplers = 0;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500136 int fMaxFragmentSamplers = 8;
Brian Salomon821ef182017-11-07 16:41:11 -0500137 bool fShaderDerivativeSupport = true;
Brian Osmand2ca3122019-03-26 11:31:16 -0400138 bool fDualSourceBlendingSupport = false;
Chris Dalton91ab1552018-04-18 13:24:25 -0600139
140 // GrMockGpu options.
141 bool fFailTextureAllocations = false;
Brian Salomoncfe910d2017-07-06 16:40:18 -0400142};
143
144#endif