Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrMockCaps.h
Go to the documentation of this file.
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 GrMockCaps_DEFINED
9#define GrMockCaps_DEFINED
10
14#include "include/gpu/GrTypes.h"
19#include "src/gpu/Swizzle.h"
25
26#include <algorithm>
27#include <cstdint>
28#include <memory>
29#include <vector>
30
31class GrProgramInfo;
32class GrRenderTarget;
33namespace GrTest { struct TestFormatColorTypeCombination; }
34struct GrContextOptions;
35struct SkIRect;
36
37class GrMockCaps : public GrCaps {
38public:
39 GrMockCaps(const GrContextOptions& contextOptions, const GrMockOptions& options)
40 : INHERITED(contextOptions), fOptions(options) {
42 fDrawInstancedSupport = options.fDrawInstancedSupport;
43 fHalfFloatVertexAttributeSupport = options.fHalfFloatVertexAttributeSupport;
44 fMapBufferFlags = options.fMapBufferFlags;
45 fBufferMapThreshold = SK_MaxS32; // Overridable in GrContextOptions.
46 fMaxTextureSize = options.fMaxTextureSize;
47 fMaxWindowRectangles = options.fMaxWindowRectangles;
48 fMaxRenderTargetSize = std::min(options.fMaxRenderTargetSize, fMaxTextureSize);
50 fMaxVertexAttributes = options.fMaxVertexAttributes;
53
54 fShaderCaps = std::make_unique<GrShaderCaps>();
55 fShaderCaps->fIntegerSupport = options.fIntegerSupport;
56 fShaderCaps->fFlatInterpolationSupport = options.fFlatInterpolationSupport;
57 fShaderCaps->fMaxFragmentSamplers = options.fMaxFragmentSamplers;
58 fShaderCaps->fShaderDerivativeSupport = options.fShaderDerivativeSupport;
59 fShaderCaps->fDualSourceBlendingSupport = options.fDualSourceBlendingSupport;
60 fShaderCaps->fSampleMaskSupport = true;
61
62 this->finishInitialization(contextOptions);
63 }
64
65 bool isFormatSRGB(const GrBackendFormat& format) const override {
66 SkTextureCompressionType compression = format.asMockCompressionType();
67 if (compression != SkTextureCompressionType::kNone) {
68 return false;
69 }
70
71 auto ct = format.asMockColorType();
73 }
74
76 SkTextureCompressionType compression = format.asMockCompressionType();
77 if (compression != SkTextureCompressionType::kNone) {
78 return fOptions.fCompressedOptions[(int)compression].fTexturable;
79 }
80
81 auto index = static_cast<int>(format.asMockColorType());
82 return fOptions.fConfigOptions[index].fTexturable;
83 }
84
85 bool isFormatCopyable(const GrBackendFormat& format) const override {
86 return false;
87 }
88
90 int sampleCount = 1) const override {
91 // Currently we don't allow RGB_888X to be renderable because we don't have a way to
92 // handle blends that reference dst alpha when the values in the dst alpha channel are
93 // uninitialized.
94 if (ct == GrColorType::kRGB_888x) {
95 return false;
96 }
97 return this->isFormatRenderable(format, sampleCount);
98 }
99
100 bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const override {
101 if (format.asMockCompressionType() != SkTextureCompressionType::kNone) {
102 return false; // compressed formats are never renderable
103 }
104
105 return sampleCount <= this->maxRenderTargetSampleCount(format.asMockColorType());
106 }
107
108 int getRenderTargetSampleCount(int requestCount, GrColorType) const;
109
110 int getRenderTargetSampleCount(int requestCount,
111 const GrBackendFormat& format) const override {
112 SkTextureCompressionType compression = format.asMockCompressionType();
113 if (compression != SkTextureCompressionType::kNone) {
114 return 0; // no compressed format is renderable
115 }
116
117 return this->getRenderTargetSampleCount(requestCount, format.asMockColorType());
118 }
119
121 switch (fOptions.fConfigOptions[(int)ct].fRenderability) {
123 return 0;
125 return 1;
127 return kMaxSampleCnt;
128 }
129 return 0;
130 }
131
133 SkTextureCompressionType compression = format.asMockCompressionType();
134 if (compression != SkTextureCompressionType::kNone) {
135 return 0; // no compressed format is renderable
136 }
137
138 return this->maxRenderTargetSampleCount(format.asMockColorType());
139 }
140
142 const GrBackendFormat& surfaceFormat,
143 GrColorType srcColorType) const override {
144 return {surfaceColorType, 1};
145 }
146
151
155
160
161 uint64_t computeFormatKey(const GrBackendFormat&) const override;
162
164 const GrProgramInfo&,
165 ProgramDescOverrideFlags) const override;
166
167#if defined(GR_TEST_UTILS)
168 std::vector<GrTest::TestFormatColorTypeCombination> getTestingCombinations() const override;
169#endif
170
171private:
172 bool onSurfaceSupportsWritePixels(const GrSurface*) const override { return true; }
173 bool onCanCopySurface(const GrSurfaceProxy* dst, const SkIRect& dstRect,
174 const GrSurfaceProxy* src, const SkIRect& srcRect) const override {
175 if (src->isProtected() == GrProtected::kYes && dst->isProtected() != GrProtected::kYes) {
176 return false;
177 }
178 return true;
179 }
183
185 const GrBackendFormat& format) const override {
186 if (ct == GrColorType::kUnknown) {
187 return false;
188 }
189
190 SkTextureCompressionType compression = format.asMockCompressionType();
193 return ct == GrColorType::kRGB_888x; // TODO: this may be too restrictive
194 }
196 return ct == GrColorType::kRGBA_8888;
197 }
198
199 return ct == format.asMockColorType();
200 }
201
203 GrColorType) const override {
204 return SupportedRead{srcColorType, 1};
205 }
206
211
212 static const int kMaxSampleCnt = 16;
213
214 GrMockOptions fOptions;
215 using INHERITED = GrCaps;
216};
217
218#endif
const char * options
static constexpr GrColorFormatDesc GrGetColorTypeDesc(GrColorType ct)
GrTextureType
GrColorType
#define SkASSERT(cond)
Definition SkAssert.h:116
static constexpr int32_t SK_MaxS32
Definition SkMath.h:21
Type::kYUV Type::kRGBA() int(0.7 *637)
static GrBackendFormat MakeMock(GrColorType colorType, SkTextureCompressionType compression, bool isStencilFormat=false)
GrColorType asMockColorType() const
bool fSupportsProtectedContent
Definition GrCaps.h:648
SurfaceReadPixelsSupport
Definition GrCaps.h:296
int fMaxPreferredRenderTargetSize
Definition GrCaps.h:658
int fMaxVertexAttributes
Definition GrCaps.h:659
int fMaxRenderTargetSize
Definition GrCaps.h:657
std::unique_ptr< GrShaderCaps > fShaderCaps
Definition GrCaps.h:584
int fBufferMapThreshold
Definition GrCaps.h:655
bool fHalfFloatVertexAttributeSupport
Definition GrCaps.h:610
bool fSampleLocationsSupport
Definition GrCaps.h:594
bool areColorTypeAndFormatCompatible(GrColorType grCT, const GrBackendFormat &format) const
Definition GrCaps.cpp:428
int fMaxWindowRectangles
Definition GrCaps.h:661
bool fMipmapSupport
Definition GrCaps.h:587
ProgramDescOverrideFlags
Definition GrCaps.h:511
uint32_t fMapBufferFlags
Definition GrCaps.h:654
void finishInitialization(const GrContextOptions &options)
Definition GrCaps.cpp:107
bool fDrawInstancedSupport
Definition GrCaps.h:595
int fMaxTextureSize
Definition GrCaps.h:660
constexpr GrColorTypeEncoding encoding() const
bool isFormatCopyable(const GrBackendFormat &format) const override
Definition GrMockCaps.h:85
int maxRenderTargetSampleCount(const GrBackendFormat &format) const override
Definition GrMockCaps.h:132
bool onAreColorTypeAndFormatCompatible(GrColorType ct, const GrBackendFormat &format) const override
Definition GrMockCaps.h:184
GrBackendFormat getBackendFormatFromCompressionType(SkTextureCompressionType) const override
Definition GrMockCaps.h:152
bool onCanCopySurface(const GrSurfaceProxy *dst, const SkIRect &dstRect, const GrSurfaceProxy *src, const SkIRect &srcRect) const override
Definition GrMockCaps.h:173
uint64_t computeFormatKey(const GrBackendFormat &) const override
bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat &format, int sampleCount=1) const override
Definition GrMockCaps.h:89
GrProgramDesc makeDesc(GrRenderTarget *, const GrProgramInfo &, ProgramDescOverrideFlags) const override
bool onSurfaceSupportsWritePixels(const GrSurface *) const override
Definition GrMockCaps.h:172
bool isFormatTexturable(const GrBackendFormat &format, GrTextureType) const override
Definition GrMockCaps.h:75
skgpu::Swizzle getWriteSwizzle(const GrBackendFormat &format, GrColorType ct) const override
Definition GrMockCaps.h:156
GrMockCaps(const GrContextOptions &contextOptions, const GrMockOptions &options)
Definition GrMockCaps.h:39
SupportedRead onSupportedReadPixelsColorType(GrColorType srcColorType, const GrBackendFormat &, GrColorType) const override
Definition GrMockCaps.h:202
int getRenderTargetSampleCount(int requestCount, GrColorType) const
bool isFormatRenderable(const GrBackendFormat &format, int sampleCount) const override
Definition GrMockCaps.h:100
GrBackendFormat onGetDefaultBackendFormat(GrColorType ct) const override
Definition GrMockCaps.h:180
int getRenderTargetSampleCount(int requestCount, const GrBackendFormat &format) const override
Definition GrMockCaps.h:110
skgpu::Swizzle onGetReadSwizzle(const GrBackendFormat &format, GrColorType ct) const override
Definition GrMockCaps.h:207
bool isFormatSRGB(const GrBackendFormat &format) const override
Definition GrMockCaps.h:65
SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType, const GrBackendFormat &surfaceFormat, GrColorType srcColorType) const override
Definition GrMockCaps.h:141
int maxRenderTargetSampleCount(GrColorType ct) const
Definition GrMockCaps.h:120
SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface *surface) const override
Definition GrMockCaps.h:147
VkSurfaceKHR surface
Definition main.cc:49
uint32_t uint32_t * format
ConfigOptions fCompressedOptions[kSkTextureCompressionTypeCount]
ConfigOptions fConfigOptions[kGrColorTypeCnt]