Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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}
57
58sk_sp<SkCapabilities> Caps::capabilities() const { return fCapabilities; }
59
61 const SkISize colorAttachmentDimensions) const {
62 return colorAttachmentDimensions;
63}
64
66 if (info.numSamples() > 1) {
67 return false;
68 }
69 return this->onIsTexturable(info);
70}
71
73 GraphiteResourceKey samplerKey;
75 GraphiteResourceKey::Builder builder(&samplerKey, kType, /*data32Count=*/1, Shareable::kYes);
76
77 // The default impl. of this method adds no additional backend information to the key.
78 builder[0] = samplerDesc.desc();
79
80 builder.finish();
81 return samplerKey;
82}
83
85 // TODO: add SkTextureCompressionType handling
86 // (can be handled by setting up the colorTypeInfo instead?)
87
88 return SkToBool(this->getColorTypeInfo(ct, info));
89}
90
92 switch (ct) {
93 // kRGBA_8888 is our default fallback for many color types that may not have renderable
94 // backend formats.
108 default:
110 }
111}
112
114 do {
115 auto texInfo = this->getDefaultSampledTextureInfo(ct,
116 Mipmapped::kNo,
117 Protected::kNo,
118 Renderable::kYes);
119 // We continue to the fallback color type if there is no default renderable format
120 if (texInfo.isValid() && this->isRenderable(texInfo)) {
121 return ct;
122 }
123 ct = color_type_fallback(ct);
124 } while (ct != kUnknown_SkColorType);
126}
127
129 // TODO: add SkTextureCompressionType handling
130 // (can be handled by setting up the colorTypeInfo instead?)
131
132 auto colorTypeInfo = this->getColorTypeInfo(ct, info);
133 if (!colorTypeInfo) {
134 SkDEBUGFAILF("Illegal color type (%d) and format combination.", static_cast<int>(ct));
135 return {};
136 }
137
138 return colorTypeInfo->fReadSwizzle;
139}
140
142 auto colorTypeInfo = this->getColorTypeInfo(ct, info);
143 if (!colorTypeInfo) {
144 SkDEBUGFAILF("Illegal color type (%d) and format combination.", static_cast<int>(ct));
145 return {};
146 }
147
148 return colorTypeInfo->fWriteSwizzle;
149}
150
152 // TODO(b/238757201): Currently this only supports dst reads by FB fetch and texture copy.
153 if (this->shaderCaps()->fFBFetchSupport) {
155 } else {
157 }
158}
159
160sktext::gpu::SDFTControl Caps::getSDFTControl(bool useSDFTForSmallText) const {
161#if !defined(SK_DISABLE_SDF_TEXT)
164 useSDFTForSmallText,
165 true, /*ableToUsePerspectiveSDFT*/
167 this->glyphsAsPathsFontSize()};
168#else
170#endif
171}
172
173} // 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:72
virtual const ColorTypeInfo * getColorTypeInfo(SkColorType, const TextureInfo &) const =0
skgpu::Swizzle getReadSwizzle(SkColorType, const TextureInfo &) const
Definition Caps.cpp:128
float fMinDistanceFieldFontSize
Definition Caps.h:384
bool isTexturable(const TextureInfo &) const
Definition Caps.cpp:65
bool fSupportBilerpFromGlyphAtlas
Definition Caps.h:390
sktext::gpu::SDFTControl getSDFTControl(bool useSDFTForSmallText) const
Definition Caps.cpp:160
int fMaxPathAtlasTextureSize
Definition Caps.h:387
virtual SkISize getDepthAttachmentDimensions(const TextureInfo &, const SkISize colorAttachmentDimensions) const
Definition Caps.cpp:60
size_t fGlyphCacheTextureMaximumBytes
Definition Caps.h:382
skgpu::Swizzle getWriteSwizzle(SkColorType, const TextureInfo &) const
Definition Caps.cpp:141
float fGlyphsAsPathsFontSize
Definition Caps.h:385
SkColorType getRenderableColorType(SkColorType) const
Definition Caps.cpp:113
std::unique_ptr< SkSL::ShaderCaps > fShaderCaps
Definition Caps.h:346
sk_sp< SkCapabilities > capabilities() const
Definition Caps.cpp:58
float glyphsAsPathsFontSize() const
Definition Caps.h:272
DstReadRequirement getDstReadRequirement() const
Definition Caps.cpp:151
virtual ~Caps()
Definition Caps.cpp:27
virtual TextureInfo getDefaultSampledTextureInfo(SkColorType, Mipmapped mipmapped, Protected, Renderable) const =0
bool areColorTypeAndTextureInfoCompatible(SkColorType, const TextureInfo &) const
Definition Caps.cpp:84
bool fRequireOrderedRecordings
Definition Caps.h:393
ShaderErrorHandler * fShaderErrorHandler
Definition Caps.h:375
float minDistanceFieldFontSize() const
Definition Caps.h:271
void finishInitialization(const ContextOptions &)
Definition Caps.cpp:29
const SkSL::ShaderCaps * shaderCaps() const
Definition Caps.h:74
bool fAllowMultipleAtlasTextures
Definition Caps.h:389
uint32_t ResourceType
static SkColorType color_type_fallback(SkColorType ct)
Definition Caps.cpp:91
ShaderErrorHandler * DefaultShaderErrorHandler()
Definition ref_ptr.h:256
bool supportsDistanceFieldText() const
Definition SkSLUtil.h:80