xref: /aosp_15_r20/external/skia/include/gpu/ganesh/mock/GrMockTypes.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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/core/SkTextureCompressionType.h"
12 #include "include/gpu/GpuTypes.h"
13 #include "include/private/base/SkAssert.h"
14 #include "include/private/gpu/ganesh/GrTypesPriv.h"
15 
16 #include <cstdint>
17 
18 class GrBackendFormat;
19 
20 struct GrMockTextureInfo {
GrMockTextureInfoGrMockTextureInfo21     GrMockTextureInfo()
22         : fColorType(GrColorType::kUnknown)
23         , fCompressionType(SkTextureCompressionType::kNone)
24         , fID(0) {}
25 
26     GrMockTextureInfo(GrColorType colorType,
27                       SkTextureCompressionType compressionType,
28                       int id,
29                       skgpu::Protected isProtected = skgpu::Protected::kNo)
fColorTypeGrMockTextureInfo30             : fColorType(colorType)
31             , fCompressionType(compressionType)
32             , fID(id)
33             , fProtected(isProtected) {
34         SkASSERT(fID);
35         if (fCompressionType != SkTextureCompressionType::kNone) {
36             SkASSERT(colorType == GrColorType::kUnknown);
37         }
38     }
39 
40     bool operator==(const GrMockTextureInfo& that) const {
41         return fColorType == that.fColorType &&
42                fCompressionType == that.fCompressionType &&
43                fID == that.fID &&
44                fProtected == that.fProtected;
45     }
46 
47     GrBackendFormat getBackendFormat() const;
48 
compressionTypeGrMockTextureInfo49     SkTextureCompressionType compressionType() const { return fCompressionType; }
50 
colorTypeGrMockTextureInfo51     GrColorType colorType() const {
52         SkASSERT(fCompressionType == SkTextureCompressionType::kNone);
53         return fColorType;
54     }
55 
idGrMockTextureInfo56     int id() const { return fID; }
57 
getProtectedGrMockTextureInfo58     skgpu::Protected getProtected() const { return fProtected; }
isProtectedGrMockTextureInfo59     bool isProtected() const { return fProtected == skgpu::Protected::kYes; }
60 
61 private:
62     GrColorType              fColorType;
63     SkTextureCompressionType fCompressionType;
64     int                      fID;
65     skgpu::Protected         fProtected = skgpu::Protected::kNo;
66 };
67 
68 struct GrMockRenderTargetInfo {
GrMockRenderTargetInfoGrMockRenderTargetInfo69     GrMockRenderTargetInfo()
70             : fColorType(GrColorType::kUnknown)
71             , fID(0) {}
72 
73     GrMockRenderTargetInfo(GrColorType colorType,
74                            int id,
75                            skgpu::Protected isProtected = skgpu::Protected::kNo)
fColorTypeGrMockRenderTargetInfo76             : fColorType(colorType)
77             , fID(id)
78             , fProtected(isProtected) {
79         SkASSERT(fID);
80     }
81 
82     bool operator==(const GrMockRenderTargetInfo& that) const {
83         return fColorType == that.fColorType &&
84                fID == that.fID &&
85                fProtected == that.fProtected;
86     }
87 
88     GrBackendFormat getBackendFormat() const;
89 
colorTypeGrMockRenderTargetInfo90     GrColorType colorType() const { return fColorType; }
91 
getProtectedGrMockRenderTargetInfo92     skgpu::Protected getProtected() const { return fProtected; }
isProtectedGrMockRenderTargetInfo93     bool isProtected() const { return fProtected == skgpu::Protected::kYes; }
94 
95 private:
96     GrColorType      fColorType;
97     int              fID;
98     skgpu::Protected fProtected = skgpu::Protected::kNo;
99 };
100 
101 struct GrMockSurfaceInfo {
102     uint32_t fSampleCount = 1;
103     uint32_t fLevelCount = 0;
104     skgpu::Protected fProtected = skgpu::Protected::kNo;
105 
106     GrColorType fColorType = GrColorType::kUnknown;
107     SkTextureCompressionType fCompressionType = SkTextureCompressionType::kNone;
108 };
109 
110 static constexpr int kSkTextureCompressionTypeCount =
111         static_cast<int>(SkTextureCompressionType::kLast) + 1;
112 
113 /**
114  * A pointer to this type is used as the GrBackendContext when creating a Mock GrContext. It can be
115  * used to specify capability options for the mock context. If nullptr is used a default constructed
116  * GrMockOptions is used.
117  */
118 struct GrMockOptions {
GrMockOptionsGrMockOptions119     GrMockOptions() {
120         using Renderability = ConfigOptions::Renderability;
121         // By default RGBA_8888 and BGRA_8888 are textureable and renderable and
122         // A8 and RGB565 are texturable.
123         fConfigOptions[(int)GrColorType::kRGBA_8888].fRenderability = Renderability::kNonMSAA;
124         fConfigOptions[(int)GrColorType::kRGBA_8888].fTexturable = true;
125         fConfigOptions[(int)GrColorType::kAlpha_8].fTexturable = true;
126         fConfigOptions[(int)GrColorType::kBGR_565].fTexturable = true;
127         fConfigOptions[(int)GrColorType::kRGB_565].fTexturable = true;
128 
129         fConfigOptions[(int)GrColorType::kBGRA_8888] = fConfigOptions[(int)GrColorType::kRGBA_8888];
130 
131         fCompressedOptions[(int)SkTextureCompressionType::kETC2_RGB8_UNORM].fTexturable = true;
132         fCompressedOptions[(int)SkTextureCompressionType::kBC1_RGB8_UNORM].fTexturable = true;
133         fCompressedOptions[(int)SkTextureCompressionType::kBC1_RGBA8_UNORM].fTexturable = true;
134     }
135 
136     struct ConfigOptions {
137         enum Renderability { kNo, kNonMSAA, kMSAA };
138         Renderability fRenderability = kNo;
139         bool fTexturable = false;
140     };
141 
142     // GrCaps options.
143     bool fMipmapSupport = false;
144     bool fDrawInstancedSupport = false;
145     bool fHalfFloatVertexAttributeSupport = false;
146     uint32_t fMapBufferFlags = 0;
147     int fMaxTextureSize = 2048;
148     int fMaxRenderTargetSize = 2048;
149     int fMaxWindowRectangles = 0;
150     int fMaxVertexAttributes = 16;
151     ConfigOptions fConfigOptions[kGrColorTypeCnt];
152     ConfigOptions fCompressedOptions[kSkTextureCompressionTypeCount];
153 
154     // GrShaderCaps options.
155     bool fIntegerSupport = false;
156     bool fFlatInterpolationSupport = false;
157     int fMaxVertexSamplers = 0;
158     int fMaxFragmentSamplers = 8;
159     bool fShaderDerivativeSupport = true;
160     bool fDualSourceBlendingSupport = false;
161 
162     // GrMockGpu options.
163     bool fFailTextureAllocations = false;
164 };
165 
166 #endif
167