blob: df906ed03254c79fe8d1ffb95548824cda95cfc2 [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));
Stephen Whited67c71f2019-08-06 11:15:41 -040013 fMaxTextureSize = 2048; // FIXME
14 fMaxVertexAttributes = 16; // FIXME
Stephen White985741a2019-07-18 11:43:45 -040015 fPerformPartialClearsAsDraws = true;
16}
17
18bool GrDawnCaps::isFormatSRGB(const GrBackendFormat& format) const {
19 return false;
20}
21
Robert Phillips8ff8bcc2019-07-29 17:03:35 -040022bool GrDawnCaps::isFormatCompressed(const GrBackendFormat& format) const {
23 return false;
24}
25
Stephen White985741a2019-07-18 11:43:45 -040026bool GrDawnCaps::isConfigTexturable(GrPixelConfig config) const {
27 switch (config) {
28 case kRGBA_8888_GrPixelConfig:
29 case kBGRA_8888_GrPixelConfig:
30 case kAlpha_8_GrPixelConfig:
31 return true;
32 default:
33 return false;
34 }
35}
36
37GrPixelConfig GrDawnCaps::onGetConfigFromBackendFormat(const GrBackendFormat& format,
Stephen Whited7325182019-08-02 17:22:59 -040038 GrColorType colorType) const {
Brian Salomond4764a12019-08-08 12:08:24 -040039 dawn::TextureFormat dawnFormat;
40 if (!format.asDawnFormat(&dawnFormat)) {
Stephen Whited7325182019-08-02 17:22:59 -040041 return kUnknown_GrPixelConfig;
42 }
Stephen White985741a2019-07-18 11:43:45 -040043 switch (colorType) {
44 case GrColorType::kUnknown:
45 return kUnknown_GrPixelConfig;
46 case GrColorType::kAlpha_8:
Brian Salomond4764a12019-08-08 12:08:24 -040047 if (dawn::TextureFormat::R8Unorm == dawnFormat) {
Stephen White985741a2019-07-18 11:43:45 -040048 return kAlpha_8_as_Red_GrPixelConfig;
49 }
50 break;
51 case GrColorType::kRGBA_8888:
Brian Salomond4764a12019-08-08 12:08:24 -040052 if (dawn::TextureFormat::RGBA8Unorm == dawnFormat) {
Stephen White985741a2019-07-18 11:43:45 -040053 return kRGBA_8888_GrPixelConfig;
Stephen Whited67c71f2019-08-06 11:15:41 -040054 } else if (dawn::TextureFormat::BGRA8Unorm == *dawnFormat) {
55 // FIXME: This shouldn't be necessary, but on some platforms (Mac)
56 // Skia byte order is RGBA, while preferred swap format is BGRA.
57 return kBGRA_8888_GrPixelConfig;
Stephen White985741a2019-07-18 11:43:45 -040058 }
59 break;
60 case GrColorType::kRGB_888x:
61 break;
62 case GrColorType::kBGRA_8888:
Brian Salomond4764a12019-08-08 12:08:24 -040063 if (dawn::TextureFormat::BGRA8Unorm == dawnFormat) {
Stephen White985741a2019-07-18 11:43:45 -040064 return kBGRA_8888_GrPixelConfig;
Stephen Whited67c71f2019-08-06 11:15:41 -040065 } else if (dawn::TextureFormat::RGBA8Unorm == *dawnFormat) {
66 return kRGBA_8888_GrPixelConfig;
Stephen White985741a2019-07-18 11:43:45 -040067 }
68 break;
69 default:
70 break;
71 }
72 return kUnknown_GrPixelConfig;
73}
74
Stephen White985741a2019-07-18 11:43:45 -040075static GrSwizzle get_swizzle(const GrBackendFormat& format, GrColorType colorType,
76 bool forOutput) {
Brian Salomond4764a12019-08-08 12:08:24 -040077 SkDEBUGCODE(dawn::TextureFormat format;)
78 SkASSERT(format.asDawnFormat(&format));
Stephen White985741a2019-07-18 11:43:45 -040079
80 switch (colorType) {
81 case GrColorType::kAlpha_8: // fall through
82 case GrColorType::kAlpha_F16:
83 if (forOutput) {
84 return GrSwizzle::AAAA();
85 } else {
86 return GrSwizzle::RRRR();
87 }
88 case GrColorType::kGray_8:
89 if (!forOutput) {
90 return GrSwizzle::RRRA();
91 }
92 break;
93 case GrColorType::kRGB_888x:
94 if (!forOutput) {
95 return GrSwizzle::RGB1();
96 }
97 default:
98 return GrSwizzle::RGBA();
99 }
100 return GrSwizzle::RGBA();
101}
102
103bool GrDawnCaps::isFormatTexturable(GrColorType ct, const GrBackendFormat& format) const {
104 GrPixelConfig config = this->getConfigFromBackendFormat(format, ct);
105 if (kUnknown_GrPixelConfig == config) {
106 return false;
107 }
108
109 return this->isConfigTexturable(config);
110}
111
Stephen Whited7325182019-08-02 17:22:59 -0400112bool GrDawnCaps::isFormatRenderable(GrColorType ct, const GrBackendFormat& format,
113 int sampleCount) const {
Brian Salomond4764a12019-08-08 12:08:24 -0400114 dawn::TextureFormat dawnFormat;
115 if (!format.isValid() || sampleCount > 1 || !format.asDawnFormat(&dawnFormat)) {
Stephen Whited7325182019-08-02 17:22:59 -0400116 return false;
Stephen White985741a2019-07-18 11:43:45 -0400117 }
118
Brian Salomond4764a12019-08-08 12:08:24 -0400119 return GrDawnFormatIsRenderable(dawnFormat);
Stephen Whited7325182019-08-02 17:22:59 -0400120}
121
122int GrDawnCaps::getRenderTargetSampleCount(int requestedCount, GrColorType ct,
123 const GrBackendFormat& backendFormat) const {
Brian Salomond4764a12019-08-08 12:08:24 -0400124 dawn::TextureFormat dawnFormat;
125 if (!format.asDawnFormat(&dawnFormat)) {
Stephen Whited7325182019-08-02 17:22:59 -0400126 return 0;
127 }
Brian Salomond4764a12019-08-08 12:08:24 -0400128 return GrDawnFormatIsRenderable(dawnFormat) ? 1 : 0;
Stephen Whited7325182019-08-02 17:22:59 -0400129}
130
131int GrDawnCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
132 dawn::TextureFormat format;
133 if (!GrPixelConfigToDawnFormat(config, &format)) {
134 return 0;
135 }
136 return GrDawnFormatIsRenderable(format) ? 1 : 0;
137}
138
139int GrDawnCaps::maxRenderTargetSampleCount(const GrBackendFormat& format) const {
140 return format.isValid() ? 1 : 0;
Stephen White985741a2019-07-18 11:43:45 -0400141}
142
Robert Phillips0a15cc62019-07-30 12:49:10 -0400143GrBackendFormat GrDawnCaps::onGetDefaultBackendFormat(GrColorType ct,
144 GrRenderable renderable) const {
Stephen White985741a2019-07-18 11:43:45 -0400145 GrPixelConfig config = GrColorTypeToPixelConfig(ct);
146 if (config == kUnknown_GrPixelConfig) {
147 return GrBackendFormat();
148 }
149 dawn::TextureFormat format;
150 if (!GrPixelConfigToDawnFormat(config, &format)) {
151 return GrBackendFormat();
152 }
153 return GrBackendFormat::MakeDawn(format);
154}
155
156GrBackendFormat GrDawnCaps::getBackendFormatFromCompressionType(SkImage::CompressionType type) const
157{
158 return GrBackendFormat();
159}
160
161GrSwizzle GrDawnCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const
162{
163 return get_swizzle(format, colorType, false);
164}
165
166bool GrDawnCaps::canClearTextureOnCreation() const {
167 return true;
168}
169
170GrSwizzle GrDawnCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const
171{
172 return get_swizzle(format, colorType, true);
173}
174
175bool GrDawnCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
176 const GrBackendFormat& format) const {
177 return true;
178}
Stephen Whiteb05ca082019-07-29 11:39:28 -0400179
Robert Phillips00c9f0d2019-08-02 17:17:35 -0400180GrColorType GrDawnCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat&,
181 bool isAlphaChannel) const {
Stephen Whiteb05ca082019-07-29 11:39:28 -0400182 return GrColorType::kUnknown;
183}
Stephen Whited7325182019-08-02 17:22:59 -0400184
185#if GR_TEST_UTILS
186std::vector<GrCaps::TestFormatColorTypeCombination> GrDawnCaps::getTestingCombinations() const {
187 std::vector<GrCaps::TestFormatColorTypeCombination> combos = {
188 { GrColorType::kAlpha_8, GrBackendFormat::MakeDawn(dawn::TextureFormat::R8Unorm) },
189 { GrColorType::kRGBA_8888, GrBackendFormat::MakeDawn(dawn::TextureFormat::RGBA8Unorm) },
190 { GrColorType::kRGB_888x, GrBackendFormat::MakeDawn(dawn::TextureFormat::RGBA8Unorm) },
191 { GrColorType::kBGRA_8888, GrBackendFormat::MakeDawn(dawn::TextureFormat::BGRA8Unorm) },
192 };
193
194#ifdef SK_DEBUG
195 for (auto combo : combos) {
196 SkASSERT(this->onAreColorTypeAndFormatCompatible(combo.fColorType, combo.fFormat));
197 }
198#endif
199 return combos;
200}
201#endif