Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/gpu/GrTypes.h" |
| 12 | #include "include/private/GrTypesPriv.h" |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 13 | |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 14 | class GrBackendFormat; |
| 15 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 16 | struct GrMockTextureInfo { |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 17 | GrMockTextureInfo() |
| 18 | : fColorType(GrColorType::kUnknown) |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 19 | , fCompressionType(SkImage::CompressionType::kNone) |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 20 | , fID(0) {} |
| 21 | |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 22 | GrMockTextureInfo(GrColorType colorType, |
| 23 | SkImage::CompressionType compressionType, |
| 24 | int id) |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 25 | : fColorType(colorType) |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 26 | , fCompressionType(compressionType) |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 27 | , fID(id) { |
| 28 | SkASSERT(fID); |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 29 | if (fCompressionType != SkImage::CompressionType::kNone) { |
| 30 | SkASSERT(colorType == GrColorType::kUnknown); |
| 31 | } |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 32 | } |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 33 | |
| 34 | bool operator==(const GrMockTextureInfo& that) const { |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 35 | return fColorType == that.fColorType && |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 36 | fCompressionType == that.fCompressionType && |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 37 | fID == that.fID; |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 38 | } |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 39 | |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 40 | GrBackendFormat getBackendFormat() const; |
| 41 | |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 42 | 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 | |
| 51 | private: |
| 52 | GrColorType fColorType; |
| 53 | SkImage::CompressionType fCompressionType; |
| 54 | int fID; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | struct GrMockRenderTargetInfo { |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 58 | GrMockRenderTargetInfo() |
| 59 | : fColorType(GrColorType::kUnknown) |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 60 | , fID(0) {} |
| 61 | |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 62 | GrMockRenderTargetInfo(GrColorType colorType, int id) |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 63 | : fColorType(colorType) |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 64 | , fID(id) { |
| 65 | SkASSERT(fID); |
| 66 | } |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 67 | |
| 68 | bool operator==(const GrMockRenderTargetInfo& that) const { |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 69 | return fColorType == that.fColorType && |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 70 | fID == that.fID; |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 71 | } |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 72 | |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 73 | GrBackendFormat getBackendFormat() const; |
| 74 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 75 | GrColorType colorType() const { return fColorType; } |
| 76 | |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 77 | private: |
| 78 | GrColorType fColorType; |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 79 | int fID; |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 80 | }; |
| 81 | |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 82 | struct 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 Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 91 | /** |
| 92 | * A pointer to this type is used as the GrBackendContext when creating a Mock GrContext. It can be |
Brian Salomon | 821ef18 | 2017-11-07 16:41:11 -0500 | [diff] [blame] | 93 | * used to specify capability options for the mock context. If nullptr is used a default constructed |
| 94 | * GrMockOptions is used. |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 95 | */ |
| 96 | struct GrMockOptions { |
| 97 | GrMockOptions() { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 98 | using Renderability = ConfigOptions::Renderability; |
Robert Phillips | d090642 | 2019-07-08 09:27:39 -0400 | [diff] [blame] | 99 | // By default RGBA_8888 and BGRA_8888 are textureable and renderable and |
| 100 | // A8 and RGB565 are texturable. |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 101 | 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 Phillips | d090642 | 2019-07-08 09:27:39 -0400 | [diff] [blame] | 105 | |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 106 | fConfigOptions[(int)GrColorType::kBGRA_8888] = fConfigOptions[(int)GrColorType::kRGBA_8888]; |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 107 | |
Robert Phillips | c558f72 | 2020-01-13 13:02:26 -0500 | [diff] [blame] | 108 | fCompressedOptions[(int)SkImage::CompressionType::kETC2_RGB8_UNORM].fTexturable = true; |
Robert Phillips | 8f259a0 | 2019-12-20 11:32:27 -0500 | [diff] [blame] | 109 | fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGB8_UNORM].fTexturable = true; |
Robert Phillips | b085527 | 2020-01-15 12:56:52 -0500 | [diff] [blame] | 110 | fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGBA8_UNORM].fTexturable = true; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | struct ConfigOptions { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 114 | enum Renderability { kNo, kNonMSAA, kMSAA }; |
Brian Osman | 29c8808 | 2019-04-02 14:28:32 -0400 | [diff] [blame] | 115 | Renderability fRenderability = kNo; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 116 | bool fTexturable = false; |
| 117 | }; |
| 118 | |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 119 | // GrCaps options. |
Brian Salomon | 69100f0 | 2020-07-21 10:49:25 -0400 | [diff] [blame] | 120 | bool fMipmapSupport = false; |
Chris Dalton | a77cdee | 2020-04-03 14:50:43 -0600 | [diff] [blame] | 121 | bool fDrawInstancedSupport = false; |
Brian Osman | c6444d2 | 2019-01-09 16:30:12 -0500 | [diff] [blame] | 122 | bool fHalfFloatVertexAttributeSupport = false; |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 123 | uint32_t fMapBufferFlags = 0; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 124 | int fMaxTextureSize = 2048; |
| 125 | int fMaxRenderTargetSize = 2048; |
Robert Phillips | c4fbc8d | 2020-11-30 10:17:53 -0500 | [diff] [blame] | 126 | int fMaxWindowRectangles = 0; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 127 | int fMaxVertexAttributes = 16; |
Chris Dalton | b96995d | 2020-06-04 16:44:29 -0600 | [diff] [blame] | 128 | int fMaxTessellationSegments = 0; |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 129 | ConfigOptions fConfigOptions[kGrColorTypeCnt]; |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 130 | ConfigOptions fCompressedOptions[SkImage::kCompressionTypeCount]; |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 131 | |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 132 | // GrShaderCaps options. |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 133 | bool fIntegerSupport = false; |
| 134 | bool fFlatInterpolationSupport = false; |
| 135 | int fMaxVertexSamplers = 0; |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 136 | int fMaxFragmentSamplers = 8; |
Brian Salomon | 821ef18 | 2017-11-07 16:41:11 -0500 | [diff] [blame] | 137 | bool fShaderDerivativeSupport = true; |
Brian Osman | d2ca312 | 2019-03-26 11:31:16 -0400 | [diff] [blame] | 138 | bool fDualSourceBlendingSupport = false; |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 139 | |
| 140 | // GrMockGpu options. |
| 141 | bool fFailTextureAllocations = false; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | #endif |