blob: 999ff6390a0b573858c2bacbe637448eb913c454 [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
21bool GrDawnCaps::isConfigTexturable(GrPixelConfig config) const {
22 switch (config) {
23 case kRGBA_8888_GrPixelConfig:
24 case kBGRA_8888_GrPixelConfig:
25 case kAlpha_8_GrPixelConfig:
26 return true;
27 default:
28 return false;
29 }
30}
31
32GrPixelConfig GrDawnCaps::onGetConfigFromBackendFormat(const GrBackendFormat& format,
33 GrColorType colorType) const {
34 dawn::TextureFormat textureFormat = *format.getDawnFormat();
35 switch (colorType) {
36 case GrColorType::kUnknown:
37 return kUnknown_GrPixelConfig;
38 case GrColorType::kAlpha_8:
39 if (dawn::TextureFormat::R8Unorm == textureFormat) {
40 return kAlpha_8_as_Red_GrPixelConfig;
41 }
42 break;
43 case GrColorType::kRGBA_8888:
Stephen White3e45e122019-07-22 09:12:29 -040044 if (dawn::TextureFormat::RGBA8Unorm == textureFormat) {
Stephen White985741a2019-07-18 11:43:45 -040045 return kRGBA_8888_GrPixelConfig;
46 }
47 break;
48 case GrColorType::kRGB_888x:
49 break;
50 case GrColorType::kBGRA_8888:
Stephen White3e45e122019-07-22 09:12:29 -040051 if (dawn::TextureFormat::BGRA8Unorm == textureFormat) {
Stephen White985741a2019-07-18 11:43:45 -040052 return kBGRA_8888_GrPixelConfig;
53 }
54 break;
55 default:
56 break;
57 }
58 return kUnknown_GrPixelConfig;
59}
60
Stephen White985741a2019-07-18 11:43:45 -040061size_t GrDawnCaps::onTransferFromOffsetAlignment(GrColorType bufferColorType) const {
62 if (bufferColorType == GrColorType::kRGB_888x) {
63 return false;
64 }
65 size_t bpp = GrColorTypeBytesPerPixel(bufferColorType);
66 switch (bpp & 0b11) {
67 case 0: return bpp;
68 case 2: return 2 * bpp;
69 default: return 4 * bpp;
70 }
71}
72
73static GrSwizzle get_swizzle(const GrBackendFormat& format, GrColorType colorType,
74 bool forOutput) {
75 SkASSERT(format.getDawnFormat());
76
77 switch (colorType) {
78 case GrColorType::kAlpha_8: // fall through
79 case GrColorType::kAlpha_F16:
80 if (forOutput) {
81 return GrSwizzle::AAAA();
82 } else {
83 return GrSwizzle::RRRR();
84 }
85 case GrColorType::kGray_8:
86 if (!forOutput) {
87 return GrSwizzle::RRRA();
88 }
89 break;
90 case GrColorType::kRGB_888x:
91 if (!forOutput) {
92 return GrSwizzle::RGB1();
93 }
94 default:
95 return GrSwizzle::RGBA();
96 }
97 return GrSwizzle::RGBA();
98}
99
100bool GrDawnCaps::isFormatTexturable(GrColorType ct, const GrBackendFormat& format) const {
101 GrPixelConfig config = this->getConfigFromBackendFormat(format, ct);
102 if (kUnknown_GrPixelConfig == config) {
103 return false;
104 }
105
106 return this->isConfigTexturable(config);
107}
108
109bool GrDawnCaps::isFormatCopyable(GrColorType ct, const GrBackendFormat& format) const {
110 return true;
111}
112
113int GrDawnCaps::getRenderTargetSampleCount(int requestedCount, GrColorType ct,
114 const GrBackendFormat& format) const {
115 GrPixelConfig config = this->getConfigFromBackendFormat(format, ct);
116 if (kUnknown_GrPixelConfig == config) {
117 return 0;
118 }
119
120 return this->getRenderTargetSampleCount(requestedCount, config);
121}
122
123GrBackendFormat GrDawnCaps::getBackendFormatFromColorType(GrColorType ct) const {
124 GrPixelConfig config = GrColorTypeToPixelConfig(ct);
125 if (config == kUnknown_GrPixelConfig) {
126 return GrBackendFormat();
127 }
128 dawn::TextureFormat format;
129 if (!GrPixelConfigToDawnFormat(config, &format)) {
130 return GrBackendFormat();
131 }
132 return GrBackendFormat::MakeDawn(format);
133}
134
135GrBackendFormat GrDawnCaps::getBackendFormatFromCompressionType(SkImage::CompressionType type) const
136{
137 return GrBackendFormat();
138}
139
140GrSwizzle GrDawnCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const
141{
142 return get_swizzle(format, colorType, false);
143}
144
145bool GrDawnCaps::canClearTextureOnCreation() const {
146 return true;
147}
148
149GrSwizzle GrDawnCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const
150{
151 return get_swizzle(format, colorType, true);
152}
153
154bool GrDawnCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
155 const GrBackendFormat& format) const {
156 return true;
157}