blob: 8964d61df801c4cc215a8389d7bb2e3ea6799c53 [file] [log] [blame]
Stephen White985741a2019-07-18 11:43:45 -04001/*
2 * Copyright 2019 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
Mike Klein52337de2019-07-25 09:00:52 -05008#include "src/gpu/dawn/GrDawnCaps.h"
Stephen White985741a2019-07-18 11:43:45 -04009
10GrDawnCaps::GrDawnCaps(const GrContextOptions& contextOptions) : INHERITED(contextOptions) {
11 fBufferMapThreshold = SK_MaxS32; // FIXME: get this from Dawn?
12 fShaderCaps.reset(new GrShaderCaps(contextOptions));
13 fMaxTextureSize = 2048;
14 fPerformPartialClearsAsDraws = true;
15}
16
17bool GrDawnCaps::isFormatSRGB(const GrBackendFormat& format) const {
18 return false;
19}
20
Robert Phillips8ff8bcc2019-07-29 17:03:35 -040021bool GrDawnCaps::isFormatCompressed(const GrBackendFormat& format) const {
22 return false;
23}
24
Stephen White985741a2019-07-18 11:43:45 -040025bool GrDawnCaps::isConfigTexturable(GrPixelConfig config) const {
26 switch (config) {
27 case kRGBA_8888_GrPixelConfig:
28 case kBGRA_8888_GrPixelConfig:
29 case kAlpha_8_GrPixelConfig:
30 return true;
31 default:
32 return false;
33 }
34}
35
36GrPixelConfig GrDawnCaps::onGetConfigFromBackendFormat(const GrBackendFormat& format,
Stephen Whited7325182019-08-02 17:22:59 -040037 GrColorType colorType) const {
Brian Salomond4764a12019-08-08 12:08:24 -040038 dawn::TextureFormat dawnFormat;
39 if (!format.asDawnFormat(&dawnFormat)) {
Stephen Whited7325182019-08-02 17:22:59 -040040 return kUnknown_GrPixelConfig;
41 }
Stephen White985741a2019-07-18 11:43:45 -040042 switch (colorType) {
43 case GrColorType::kUnknown:
44 return kUnknown_GrPixelConfig;
45 case GrColorType::kAlpha_8:
Brian Salomond4764a12019-08-08 12:08:24 -040046 if (dawn::TextureFormat::R8Unorm == dawnFormat) {
Stephen White985741a2019-07-18 11:43:45 -040047 return kAlpha_8_as_Red_GrPixelConfig;
48 }
49 break;
50 case GrColorType::kRGBA_8888:
Brian Salomond4764a12019-08-08 12:08:24 -040051 if (dawn::TextureFormat::RGBA8Unorm == dawnFormat) {
Stephen White985741a2019-07-18 11:43:45 -040052 return kRGBA_8888_GrPixelConfig;
53 }
54 break;
55 case GrColorType::kRGB_888x:
56 break;
57 case GrColorType::kBGRA_8888:
Brian Salomond4764a12019-08-08 12:08:24 -040058 if (dawn::TextureFormat::BGRA8Unorm == dawnFormat) {
Stephen White985741a2019-07-18 11:43:45 -040059 return kBGRA_8888_GrPixelConfig;
60 }
61 break;
62 default:
63 break;
64 }
65 return kUnknown_GrPixelConfig;
66}
67
Stephen White985741a2019-07-18 11:43:45 -040068static GrSwizzle get_swizzle(const GrBackendFormat& format, GrColorType colorType,
69 bool forOutput) {
Brian Salomond4764a12019-08-08 12:08:24 -040070 SkDEBUGCODE(dawn::TextureFormat format;)
71 SkASSERT(format.asDawnFormat(&format));
Stephen White985741a2019-07-18 11:43:45 -040072
73 switch (colorType) {
74 case GrColorType::kAlpha_8: // fall through
75 case GrColorType::kAlpha_F16:
76 if (forOutput) {
77 return GrSwizzle::AAAA();
78 } else {
79 return GrSwizzle::RRRR();
80 }
81 case GrColorType::kGray_8:
82 if (!forOutput) {
83 return GrSwizzle::RRRA();
84 }
85 break;
86 case GrColorType::kRGB_888x:
87 if (!forOutput) {
88 return GrSwizzle::RGB1();
89 }
90 default:
91 return GrSwizzle::RGBA();
92 }
93 return GrSwizzle::RGBA();
94}
95
96bool GrDawnCaps::isFormatTexturable(GrColorType ct, const GrBackendFormat& format) const {
97 GrPixelConfig config = this->getConfigFromBackendFormat(format, ct);
98 if (kUnknown_GrPixelConfig == config) {
99 return false;
100 }
101
102 return this->isConfigTexturable(config);
103}
104
Stephen Whited7325182019-08-02 17:22:59 -0400105bool GrDawnCaps::isFormatRenderable(GrColorType ct, const GrBackendFormat& format,
106 int sampleCount) const {
Brian Salomond4764a12019-08-08 12:08:24 -0400107 dawn::TextureFormat dawnFormat;
108 if (!format.isValid() || sampleCount > 1 || !format.asDawnFormat(&dawnFormat)) {
Stephen Whited7325182019-08-02 17:22:59 -0400109 return false;
Stephen White985741a2019-07-18 11:43:45 -0400110 }
111
Brian Salomond4764a12019-08-08 12:08:24 -0400112 return GrDawnFormatIsRenderable(dawnFormat);
Stephen Whited7325182019-08-02 17:22:59 -0400113}
114
115int GrDawnCaps::getRenderTargetSampleCount(int requestedCount, GrColorType ct,
116 const GrBackendFormat& backendFormat) const {
Brian Salomond4764a12019-08-08 12:08:24 -0400117 dawn::TextureFormat dawnFormat;
118 if (!format.asDawnFormat(&dawnFormat)) {
Stephen Whited7325182019-08-02 17:22:59 -0400119 return 0;
120 }
Brian Salomond4764a12019-08-08 12:08:24 -0400121 return GrDawnFormatIsRenderable(dawnFormat) ? 1 : 0;
Stephen Whited7325182019-08-02 17:22:59 -0400122}
123
124int GrDawnCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
125 dawn::TextureFormat format;
126 if (!GrPixelConfigToDawnFormat(config, &format)) {
127 return 0;
128 }
129 return GrDawnFormatIsRenderable(format) ? 1 : 0;
130}
131
132int GrDawnCaps::maxRenderTargetSampleCount(const GrBackendFormat& format) const {
133 return format.isValid() ? 1 : 0;
Stephen White985741a2019-07-18 11:43:45 -0400134}
135
Robert Phillips0a15cc62019-07-30 12:49:10 -0400136GrBackendFormat GrDawnCaps::onGetDefaultBackendFormat(GrColorType ct,
137 GrRenderable renderable) const {
Stephen White985741a2019-07-18 11:43:45 -0400138 GrPixelConfig config = GrColorTypeToPixelConfig(ct);
139 if (config == kUnknown_GrPixelConfig) {
140 return GrBackendFormat();
141 }
142 dawn::TextureFormat format;
143 if (!GrPixelConfigToDawnFormat(config, &format)) {
144 return GrBackendFormat();
145 }
146 return GrBackendFormat::MakeDawn(format);
147}
148
149GrBackendFormat GrDawnCaps::getBackendFormatFromCompressionType(SkImage::CompressionType type) const
150{
151 return GrBackendFormat();
152}
153
154GrSwizzle GrDawnCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const
155{
156 return get_swizzle(format, colorType, false);
157}
158
159bool GrDawnCaps::canClearTextureOnCreation() const {
160 return true;
161}
162
163GrSwizzle GrDawnCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const
164{
165 return get_swizzle(format, colorType, true);
166}
167
168bool GrDawnCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
169 const GrBackendFormat& format) const {
170 return true;
171}
Stephen Whiteb05ca082019-07-29 11:39:28 -0400172
Robert Phillips00c9f0d2019-08-02 17:17:35 -0400173GrColorType GrDawnCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat&,
174 bool isAlphaChannel) const {
Stephen Whiteb05ca082019-07-29 11:39:28 -0400175 return GrColorType::kUnknown;
176}
Stephen Whited7325182019-08-02 17:22:59 -0400177
178#if GR_TEST_UTILS
179std::vector<GrCaps::TestFormatColorTypeCombination> GrDawnCaps::getTestingCombinations() const {
180 std::vector<GrCaps::TestFormatColorTypeCombination> combos = {
181 { GrColorType::kAlpha_8, GrBackendFormat::MakeDawn(dawn::TextureFormat::R8Unorm) },
182 { GrColorType::kRGBA_8888, GrBackendFormat::MakeDawn(dawn::TextureFormat::RGBA8Unorm) },
183 { GrColorType::kRGB_888x, GrBackendFormat::MakeDawn(dawn::TextureFormat::RGBA8Unorm) },
184 { GrColorType::kBGRA_8888, GrBackendFormat::MakeDawn(dawn::TextureFormat::BGRA8Unorm) },
185 };
186
187#ifdef SK_DEBUG
188 for (auto combo : combos) {
189 SkASSERT(this->onAreColorTypeAndFormatCompatible(combo.fColorType, combo.fFormat));
190 }
191#endif
192 return combos;
193}
194#endif