blob: c9381bc005c16ebdb505121e8abb81d1e08e92b4 [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,
37 GrColorType colorType) const {
38 dawn::TextureFormat textureFormat = *format.getDawnFormat();
39 switch (colorType) {
40 case GrColorType::kUnknown:
41 return kUnknown_GrPixelConfig;
42 case GrColorType::kAlpha_8:
43 if (dawn::TextureFormat::R8Unorm == textureFormat) {
44 return kAlpha_8_as_Red_GrPixelConfig;
45 }
46 break;
47 case GrColorType::kRGBA_8888:
Stephen White3e45e122019-07-22 09:12:29 -040048 if (dawn::TextureFormat::RGBA8Unorm == textureFormat) {
Stephen White985741a2019-07-18 11:43:45 -040049 return kRGBA_8888_GrPixelConfig;
50 }
51 break;
52 case GrColorType::kRGB_888x:
53 break;
54 case GrColorType::kBGRA_8888:
Stephen White3e45e122019-07-22 09:12:29 -040055 if (dawn::TextureFormat::BGRA8Unorm == textureFormat) {
Stephen White985741a2019-07-18 11:43:45 -040056 return kBGRA_8888_GrPixelConfig;
57 }
58 break;
59 default:
60 break;
61 }
62 return kUnknown_GrPixelConfig;
63}
64
Stephen White985741a2019-07-18 11:43:45 -040065static GrSwizzle get_swizzle(const GrBackendFormat& format, GrColorType colorType,
66 bool forOutput) {
67 SkASSERT(format.getDawnFormat());
68
69 switch (colorType) {
70 case GrColorType::kAlpha_8: // fall through
71 case GrColorType::kAlpha_F16:
72 if (forOutput) {
73 return GrSwizzle::AAAA();
74 } else {
75 return GrSwizzle::RRRR();
76 }
77 case GrColorType::kGray_8:
78 if (!forOutput) {
79 return GrSwizzle::RRRA();
80 }
81 break;
82 case GrColorType::kRGB_888x:
83 if (!forOutput) {
84 return GrSwizzle::RGB1();
85 }
86 default:
87 return GrSwizzle::RGBA();
88 }
89 return GrSwizzle::RGBA();
90}
91
92bool GrDawnCaps::isFormatTexturable(GrColorType ct, const GrBackendFormat& format) const {
93 GrPixelConfig config = this->getConfigFromBackendFormat(format, ct);
94 if (kUnknown_GrPixelConfig == config) {
95 return false;
96 }
97
98 return this->isConfigTexturable(config);
99}
100
101bool GrDawnCaps::isFormatCopyable(GrColorType ct, const GrBackendFormat& format) const {
102 return true;
103}
104
105int GrDawnCaps::getRenderTargetSampleCount(int requestedCount, GrColorType ct,
106 const GrBackendFormat& format) const {
107 GrPixelConfig config = this->getConfigFromBackendFormat(format, ct);
108 if (kUnknown_GrPixelConfig == config) {
109 return 0;
110 }
111
112 return this->getRenderTargetSampleCount(requestedCount, config);
113}
114
115GrBackendFormat GrDawnCaps::getBackendFormatFromColorType(GrColorType ct) const {
116 GrPixelConfig config = GrColorTypeToPixelConfig(ct);
117 if (config == kUnknown_GrPixelConfig) {
118 return GrBackendFormat();
119 }
120 dawn::TextureFormat format;
121 if (!GrPixelConfigToDawnFormat(config, &format)) {
122 return GrBackendFormat();
123 }
124 return GrBackendFormat::MakeDawn(format);
125}
126
127GrBackendFormat GrDawnCaps::getBackendFormatFromCompressionType(SkImage::CompressionType type) const
128{
129 return GrBackendFormat();
130}
131
132GrSwizzle GrDawnCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const
133{
134 return get_swizzle(format, colorType, false);
135}
136
137bool GrDawnCaps::canClearTextureOnCreation() const {
138 return true;
139}
140
141GrSwizzle GrDawnCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const
142{
143 return get_swizzle(format, colorType, true);
144}
145
146bool GrDawnCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
147 const GrBackendFormat& format) const {
148 return true;
149}
Stephen Whiteb05ca082019-07-29 11:39:28 -0400150
151GrColorType GrDawnCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat&) const {
152 return GrColorType::kUnknown;
153}