Flutter Engine
The Flutter Engine
Caps.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google LLC
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
9
19#include "src/sksl/SkSLUtil.h"
20
21namespace skgpu::graphite {
22
24 : fShaderCaps(std::make_unique<SkSL::ShaderCaps>())
25 , fCapabilities(new SkCapabilities()) {}
26
28
30 fCapabilities->initSkCaps(fShaderCaps.get());
31
32 fDefaultMSAASamples = options.fInternalMultisampleCount;
33
34 if (options.fShaderErrorHandler) {
35 fShaderErrorHandler = options.fShaderErrorHandler;
36 } else {
38 }
39
40#if defined(GRAPHITE_TEST_UTILS)
41 if (options.fOptionsPriv) {
42 fMaxTextureSize = std::min(fMaxTextureSize, options.fOptionsPriv->fMaxTextureSizeOverride);
43 fMaxTextureAtlasSize = options.fOptionsPriv->fMaxTextureAtlasSize;
44 fRequestedPathRendererStrategy = options.fOptionsPriv->fPathRendererStrategy;
45 }
46#endif
47 fGlyphCacheTextureMaximumBytes = options.fGlyphCacheTextureMaximumBytes;
48 fMinDistanceFieldFontSize = options.fMinDistanceFieldFontSize;
49 fGlyphsAsPathsFontSize = options.fGlyphsAsPathsFontSize;
50 fMaxPathAtlasTextureSize = options.fMaxPathAtlasTextureSize;
51 fAllowMultipleAtlasTextures = options.fAllowMultipleAtlasTextures;
52 fSupportBilerpFromGlyphAtlas = options.fSupportBilerpFromGlyphAtlas;
53 if (options.fDisableCachedGlyphUploads) {
55 }
56 fSetBackendLabels = options.fSetBackendLabels;
57}
58
59sk_sp<SkCapabilities> Caps::capabilities() const { return fCapabilities; }
60
62 const SkISize colorAttachmentDimensions) const {
63 return colorAttachmentDimensions;
64}
65
67 if (info.numSamples() > 1) {
68 return false;
69 }
70 return this->onIsTexturable(info);
71}
72
74 GraphiteResourceKey samplerKey;
76 GraphiteResourceKey::Builder builder(&samplerKey, kType, /*data32Count=*/1, Shareable::kYes);
77
78 // The default impl. of this method adds no additional backend information to the key.
79 builder[0] = samplerDesc.desc();
80
81 builder.finish();
82 return samplerKey;
83}
84
86 // TODO: add SkTextureCompressionType handling
87 // (can be handled by setting up the colorTypeInfo instead?)
88
89 return SkToBool(this->getColorTypeInfo(ct, info));
90}
91
93 switch (ct) {
94 // kRGBA_8888 is our default fallback for many color types that may not have renderable
95 // backend formats.
109 default:
111 }
112}
113
115 do {
116 auto texInfo = this->getDefaultSampledTextureInfo(ct,
120 // We continue to the fallback color type if there is no default renderable format
121 if (texInfo.isValid() && this->isRenderable(texInfo)) {
122 return ct;
123 }
124 ct = color_type_fallback(ct);
125 } while (ct != kUnknown_SkColorType);
127}
128
130 // TODO: add SkTextureCompressionType handling
131 // (can be handled by setting up the colorTypeInfo instead?)
132
133 auto colorTypeInfo = this->getColorTypeInfo(ct, info);
134 if (!colorTypeInfo) {
135 SkDEBUGFAILF("Illegal color type (%d) and format combination.", static_cast<int>(ct));
136 return {};
137 }
138
139 return colorTypeInfo->fReadSwizzle;
140}
141
143 auto colorTypeInfo = this->getColorTypeInfo(ct, info);
144 if (!colorTypeInfo) {
145 SkDEBUGFAILF("Illegal color type (%d) and format combination.", static_cast<int>(ct));
146 return {};
147 }
148
149 return colorTypeInfo->fWriteSwizzle;
150}
151
153 // TODO(b/238757201): Currently this only supports dst reads by FB fetch and texture copy.
154 if (this->shaderCaps()->fFBFetchSupport) {
156 } else {
158 }
159}
160
161sktext::gpu::SDFTControl Caps::getSDFTControl(bool useSDFTForSmallText) const {
162#if !defined(SK_DISABLE_SDF_TEXT)
165 useSDFTForSmallText,
166 true, /*ableToUsePerspectiveSDFT*/
168 this->glyphsAsPathsFontSize()};
169#else
171#endif
172}
173
174} // namespace skgpu::graphite
const char * options
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SkDEBUGFAILF(fmt,...)
Definition: SkAssert.h:119
SkColorType
Definition: SkColorType.h:19
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
Definition: SkColorType.h:23
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition: SkColorType.h:38
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition: SkColorType.h:21
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition: SkColorType.h:35
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition: SkColorType.h:22
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
Definition: SkColorType.h:25
@ kBGRA_1010102_SkColorType
10 bits for blue, green, red; 2 bits for alpha; in 32-bit word
Definition: SkColorType.h:28
@ kA16_float_SkColorType
pixel with a half float for alpha
Definition: SkColorType.h:45
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
Definition: SkColorType.h:27
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
Definition: SkColorType.h:36
@ kUnknown_SkColorType
uninitialized
Definition: SkColorType.h:20
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
void initSkCaps(const SkSL::ShaderCaps *)
virtual bool onIsTexturable(const TextureInfo &) const =0
virtual GraphiteResourceKey makeSamplerKey(const SamplerDesc &samplerDesc) const
Definition: Caps.cpp:73
virtual const ColorTypeInfo * getColorTypeInfo(SkColorType, const TextureInfo &) const =0
skgpu::Swizzle getReadSwizzle(SkColorType, const TextureInfo &) const
Definition: Caps.cpp:129
float fMinDistanceFieldFontSize
Definition: Caps.h:401
bool isTexturable(const TextureInfo &) const
Definition: Caps.cpp:66
bool fSupportBilerpFromGlyphAtlas
Definition: Caps.h:407
sktext::gpu::SDFTControl getSDFTControl(bool useSDFTForSmallText) const
Definition: Caps.cpp:161
int fMaxPathAtlasTextureSize
Definition: Caps.h:404
virtual SkISize getDepthAttachmentDimensions(const TextureInfo &, const SkISize colorAttachmentDimensions) const
Definition: Caps.cpp:61
size_t fGlyphCacheTextureMaximumBytes
Definition: Caps.h:399
skgpu::Swizzle getWriteSwizzle(SkColorType, const TextureInfo &) const
Definition: Caps.cpp:142
float fGlyphsAsPathsFontSize
Definition: Caps.h:402
SkColorType getRenderableColorType(SkColorType) const
Definition: Caps.cpp:114
std::unique_ptr< SkSL::ShaderCaps > fShaderCaps
Definition: Caps.h:363
sk_sp< SkCapabilities > capabilities() const
Definition: Caps.cpp:59
float glyphsAsPathsFontSize() const
Definition: Caps.h:279
DstReadRequirement getDstReadRequirement() const
Definition: Caps.cpp:152
virtual ~Caps()
Definition: Caps.cpp:27
virtual TextureInfo getDefaultSampledTextureInfo(SkColorType, Mipmapped mipmapped, Protected, Renderable) const =0
bool fSetBackendLabels
Definition: Caps.h:412
bool areColorTypeAndTextureInfoCompatible(SkColorType, const TextureInfo &) const
Definition: Caps.cpp:85
bool fRequireOrderedRecordings
Definition: Caps.h:410
ShaderErrorHandler * fShaderErrorHandler
Definition: Caps.h:392
float minDistanceFieldFontSize() const
Definition: Caps.h:278
void finishInitialization(const ContextOptions &)
Definition: Caps.cpp:29
const SkSL::ShaderCaps * shaderCaps() const
Definition: Caps.h:75
int fDefaultMSAASamples
Definition: Caps.h:357
bool fAllowMultipleAtlasTextures
Definition: Caps.h:406
static float min(float r, float g, float b)
Definition: hsl.cpp:48
uint32_t ResourceType
static SkColorType color_type_fallback(SkColorType ct)
Definition: Caps.cpp:92
DstReadRequirement
Definition: Caps.h:64
ShaderErrorHandler * DefaultShaderErrorHandler()
Definition: ref_ptr.h:256
Definition: SkSize.h:16
bool supportsDistanceFieldText() const
Definition: SkSLUtil.h:80