blob: 9e8954bf22ccbcf39ffc762cde25c8bf1c99ef46 [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 -040061static GrSwizzle get_swizzle(const GrBackendFormat& format, GrColorType colorType,
62 bool forOutput) {
63 SkASSERT(format.getDawnFormat());
64
65 switch (colorType) {
66 case GrColorType::kAlpha_8: // fall through
67 case GrColorType::kAlpha_F16:
68 if (forOutput) {
69 return GrSwizzle::AAAA();
70 } else {
71 return GrSwizzle::RRRR();
72 }
73 case GrColorType::kGray_8:
74 if (!forOutput) {
75 return GrSwizzle::RRRA();
76 }
77 break;
78 case GrColorType::kRGB_888x:
79 if (!forOutput) {
80 return GrSwizzle::RGB1();
81 }
82 default:
83 return GrSwizzle::RGBA();
84 }
85 return GrSwizzle::RGBA();
86}
87
88bool GrDawnCaps::isFormatTexturable(GrColorType ct, const GrBackendFormat& format) const {
89 GrPixelConfig config = this->getConfigFromBackendFormat(format, ct);
90 if (kUnknown_GrPixelConfig == config) {
91 return false;
92 }
93
94 return this->isConfigTexturable(config);
95}
96
97bool GrDawnCaps::isFormatCopyable(GrColorType ct, const GrBackendFormat& format) const {
98 return true;
99}
100
101int GrDawnCaps::getRenderTargetSampleCount(int requestedCount, GrColorType ct,
102 const GrBackendFormat& format) const {
103 GrPixelConfig config = this->getConfigFromBackendFormat(format, ct);
104 if (kUnknown_GrPixelConfig == config) {
105 return 0;
106 }
107
108 return this->getRenderTargetSampleCount(requestedCount, config);
109}
110
111GrBackendFormat GrDawnCaps::getBackendFormatFromColorType(GrColorType ct) const {
112 GrPixelConfig config = GrColorTypeToPixelConfig(ct);
113 if (config == kUnknown_GrPixelConfig) {
114 return GrBackendFormat();
115 }
116 dawn::TextureFormat format;
117 if (!GrPixelConfigToDawnFormat(config, &format)) {
118 return GrBackendFormat();
119 }
120 return GrBackendFormat::MakeDawn(format);
121}
122
123GrBackendFormat GrDawnCaps::getBackendFormatFromCompressionType(SkImage::CompressionType type) const
124{
125 return GrBackendFormat();
126}
127
128GrSwizzle GrDawnCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const
129{
130 return get_swizzle(format, colorType, false);
131}
132
133bool GrDawnCaps::canClearTextureOnCreation() const {
134 return true;
135}
136
137GrSwizzle GrDawnCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const
138{
139 return get_swizzle(format, colorType, true);
140}
141
142bool GrDawnCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
143 const GrBackendFormat& format) const {
144 return true;
145}
Stephen Whiteb05ca082019-07-29 11:39:28 -0400146
147GrColorType GrDawnCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat&) const {
148 return GrColorType::kUnknown;
149}