blob: 020502396daf0ef049c84b934f2cb66523544848 [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 {
38 const dawn::TextureFormat* dawnFormat = format.getDawnFormat();
39 if (!dawnFormat) {
40 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:
Stephen Whited7325182019-08-02 17:22:59 -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:
Stephen Whited7325182019-08-02 17:22:59 -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:
Stephen Whited7325182019-08-02 17:22:59 -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) {
70 SkASSERT(format.getDawnFormat());
71
72 switch (colorType) {
73 case GrColorType::kAlpha_8: // fall through
74 case GrColorType::kAlpha_F16:
75 if (forOutput) {
76 return GrSwizzle::AAAA();
77 } else {
78 return GrSwizzle::RRRR();
79 }
80 case GrColorType::kGray_8:
81 if (!forOutput) {
82 return GrSwizzle::RRRA();
83 }
84 break;
85 case GrColorType::kRGB_888x:
86 if (!forOutput) {
87 return GrSwizzle::RGB1();
88 }
89 default:
90 return GrSwizzle::RGBA();
91 }
92 return GrSwizzle::RGBA();
93}
94
95bool GrDawnCaps::isFormatTexturable(GrColorType ct, const GrBackendFormat& format) const {
96 GrPixelConfig config = this->getConfigFromBackendFormat(format, ct);
97 if (kUnknown_GrPixelConfig == config) {
98 return false;
99 }
100
101 return this->isConfigTexturable(config);
102}
103
Stephen Whited7325182019-08-02 17:22:59 -0400104bool GrDawnCaps::isFormatRenderable(GrColorType ct, const GrBackendFormat& format,
105 int sampleCount) const {
106 if (!format.isValid() || sampleCount > 1) {
107 return false;
Stephen White985741a2019-07-18 11:43:45 -0400108 }
109
Stephen Whited7325182019-08-02 17:22:59 -0400110 return GrDawnFormatIsRenderable(*format.getDawnFormat()) ? 1 : 0;
111}
112
113int GrDawnCaps::getRenderTargetSampleCount(int requestedCount, GrColorType ct,
114 const GrBackendFormat& backendFormat) const {
115 if (!backendFormat.getDawnFormat()) {
116 return 0;
117 }
118 return GrDawnFormatIsRenderable(*backendFormat.getDawnFormat()) ? 1 : 0;
119}
120
121int GrDawnCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
122 dawn::TextureFormat format;
123 if (!GrPixelConfigToDawnFormat(config, &format)) {
124 return 0;
125 }
126 return GrDawnFormatIsRenderable(format) ? 1 : 0;
127}
128
129int GrDawnCaps::maxRenderTargetSampleCount(const GrBackendFormat& format) const {
130 return format.isValid() ? 1 : 0;
Stephen White985741a2019-07-18 11:43:45 -0400131}
132
Robert Phillips0a15cc62019-07-30 12:49:10 -0400133GrBackendFormat GrDawnCaps::onGetDefaultBackendFormat(GrColorType ct,
134 GrRenderable renderable) const {
Stephen White985741a2019-07-18 11:43:45 -0400135 GrPixelConfig config = GrColorTypeToPixelConfig(ct);
136 if (config == kUnknown_GrPixelConfig) {
137 return GrBackendFormat();
138 }
139 dawn::TextureFormat format;
140 if (!GrPixelConfigToDawnFormat(config, &format)) {
141 return GrBackendFormat();
142 }
143 return GrBackendFormat::MakeDawn(format);
144}
145
146GrBackendFormat GrDawnCaps::getBackendFormatFromCompressionType(SkImage::CompressionType type) const
147{
148 return GrBackendFormat();
149}
150
151GrSwizzle GrDawnCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const
152{
153 return get_swizzle(format, colorType, false);
154}
155
156bool GrDawnCaps::canClearTextureOnCreation() const {
157 return true;
158}
159
160GrSwizzle GrDawnCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const
161{
162 return get_swizzle(format, colorType, true);
163}
164
165bool GrDawnCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
166 const GrBackendFormat& format) const {
167 return true;
168}
Stephen Whiteb05ca082019-07-29 11:39:28 -0400169
Robert Phillips00c9f0d2019-08-02 17:17:35 -0400170GrColorType GrDawnCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat&,
171 bool isAlphaChannel) const {
Stephen Whiteb05ca082019-07-29 11:39:28 -0400172 return GrColorType::kUnknown;
173}
Stephen Whited7325182019-08-02 17:22:59 -0400174
175#if GR_TEST_UTILS
176std::vector<GrCaps::TestFormatColorTypeCombination> GrDawnCaps::getTestingCombinations() const {
177 std::vector<GrCaps::TestFormatColorTypeCombination> combos = {
178 { GrColorType::kAlpha_8, GrBackendFormat::MakeDawn(dawn::TextureFormat::R8Unorm) },
179 { GrColorType::kRGBA_8888, GrBackendFormat::MakeDawn(dawn::TextureFormat::RGBA8Unorm) },
180 { GrColorType::kRGB_888x, GrBackendFormat::MakeDawn(dawn::TextureFormat::RGBA8Unorm) },
181 { GrColorType::kBGRA_8888, GrBackendFormat::MakeDawn(dawn::TextureFormat::BGRA8Unorm) },
182 };
183
184#ifdef SK_DEBUG
185 for (auto combo : combos) {
186 SkASSERT(this->onAreColorTypeAndFormatCompatible(combo.fColorType, combo.fFormat));
187 }
188#endif
189 return combos;
190}
191#endif