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 11 #include "include/gpu/GrTypes.h" 12 #include "include/private/gpu/ganesh/GrTypesPriv.h" 13 14 class GrBackendFormat; 15 16 struct GrMockTextureInfo { GrMockTextureInfoGrMockTextureInfo17 GrMockTextureInfo() 18 : fColorType(GrColorType::kUnknown) 19 , fCompressionType(SkImage::CompressionType::kNone) 20 , fID(0) {} 21 GrMockTextureInfoGrMockTextureInfo22 GrMockTextureInfo(GrColorType colorType, 23 SkImage::CompressionType compressionType, 24 int id) 25 : fColorType(colorType) 26 , fCompressionType(compressionType) 27 , fID(id) { 28 SkASSERT(fID); 29 if (fCompressionType != SkImage::CompressionType::kNone) { 30 SkASSERT(colorType == GrColorType::kUnknown); 31 } 32 } 33 34 bool operator==(const GrMockTextureInfo& that) const { 35 return fColorType == that.fColorType && 36 fCompressionType == that.fCompressionType && 37 fID == that.fID; 38 } 39 40 GrBackendFormat getBackendFormat() const; 41 compressionTypeGrMockTextureInfo42 SkImage::CompressionType compressionType() const { return fCompressionType; } 43 colorTypeGrMockTextureInfo44 GrColorType colorType() const { 45 SkASSERT(fCompressionType == SkImage::CompressionType::kNone); 46 return fColorType; 47 } 48 idGrMockTextureInfo49 int id() const { return fID; } 50 51 private: 52 GrColorType fColorType; 53 SkImage::CompressionType fCompressionType; 54 int fID; 55 }; 56 57 struct GrMockRenderTargetInfo { GrMockRenderTargetInfoGrMockRenderTargetInfo58 GrMockRenderTargetInfo() 59 : fColorType(GrColorType::kUnknown) 60 , fID(0) {} 61 GrMockRenderTargetInfoGrMockRenderTargetInfo62 GrMockRenderTargetInfo(GrColorType colorType, int id) 63 : fColorType(colorType) 64 , fID(id) { 65 SkASSERT(fID); 66 } 67 68 bool operator==(const GrMockRenderTargetInfo& that) const { 69 return fColorType == that.fColorType && 70 fID == that.fID; 71 } 72 73 GrBackendFormat getBackendFormat() const; 74 colorTypeGrMockRenderTargetInfo75 GrColorType colorType() const { return fColorType; } 76 77 private: 78 GrColorType fColorType; 79 int fID; 80 }; 81 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 91 /** 92 * A pointer to this type is used as the GrBackendContext when creating a Mock GrContext. It can be 93 * used to specify capability options for the mock context. If nullptr is used a default constructed 94 * GrMockOptions is used. 95 */ 96 struct GrMockOptions { GrMockOptionsGrMockOptions97 GrMockOptions() { 98 using Renderability = ConfigOptions::Renderability; 99 // By default RGBA_8888 and BGRA_8888 are textureable and renderable and 100 // A8 and RGB565 are texturable. 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; 105 106 fConfigOptions[(int)GrColorType::kBGRA_8888] = fConfigOptions[(int)GrColorType::kRGBA_8888]; 107 108 fCompressedOptions[(int)SkImage::CompressionType::kETC2_RGB8_UNORM].fTexturable = true; 109 fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGB8_UNORM].fTexturable = true; 110 fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGBA8_UNORM].fTexturable = true; 111 } 112 113 struct ConfigOptions { 114 enum Renderability { kNo, kNonMSAA, kMSAA }; 115 Renderability fRenderability = kNo; 116 bool fTexturable = false; 117 }; 118 119 // GrCaps options. 120 bool fMipmapSupport = false; 121 bool fDrawInstancedSupport = false; 122 bool fHalfFloatVertexAttributeSupport = false; 123 uint32_t fMapBufferFlags = 0; 124 int fMaxTextureSize = 2048; 125 int fMaxRenderTargetSize = 2048; 126 int fMaxWindowRectangles = 0; 127 int fMaxVertexAttributes = 16; 128 ConfigOptions fConfigOptions[kGrColorTypeCnt]; 129 ConfigOptions fCompressedOptions[SkImage::kCompressionTypeCount]; 130 131 // GrShaderCaps options. 132 bool fIntegerSupport = false; 133 bool fFlatInterpolationSupport = false; 134 int fMaxVertexSamplers = 0; 135 int fMaxFragmentSamplers = 8; 136 bool fShaderDerivativeSupport = true; 137 bool fDualSourceBlendingSupport = false; 138 139 // GrMockGpu options. 140 bool fFailTextureAllocations = false; 141 }; 142 143 #endif 144