Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1 | /* |
| 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 Klein | 52337de | 2019-07-25 09:00:52 -0500 | [diff] [blame] | 8 | #include "src/gpu/dawn/GrDawnCaps.h" |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 9 | |
| 10 | GrDawnCaps::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 | |
| 17 | bool GrDawnCaps::isFormatSRGB(const GrBackendFormat& format) const { |
| 18 | return false; |
| 19 | } |
| 20 | |
Robert Phillips | 8ff8bcc | 2019-07-29 17:03:35 -0400 | [diff] [blame] | 21 | bool GrDawnCaps::isFormatCompressed(const GrBackendFormat& format) const { |
| 22 | return false; |
| 23 | } |
| 24 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 25 | bool 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 | |
| 36 | GrPixelConfig GrDawnCaps::onGetConfigFromBackendFormat(const GrBackendFormat& format, |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 37 | GrColorType colorType) const { |
| 38 | const dawn::TextureFormat* dawnFormat = format.getDawnFormat(); |
| 39 | if (!dawnFormat) { |
| 40 | return kUnknown_GrPixelConfig; |
| 41 | } |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 42 | switch (colorType) { |
| 43 | case GrColorType::kUnknown: |
| 44 | return kUnknown_GrPixelConfig; |
| 45 | case GrColorType::kAlpha_8: |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 46 | if (dawn::TextureFormat::R8Unorm == *dawnFormat) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 47 | return kAlpha_8_as_Red_GrPixelConfig; |
| 48 | } |
| 49 | break; |
| 50 | case GrColorType::kRGBA_8888: |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 51 | if (dawn::TextureFormat::RGBA8Unorm == *dawnFormat) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 52 | return kRGBA_8888_GrPixelConfig; |
| 53 | } |
| 54 | break; |
| 55 | case GrColorType::kRGB_888x: |
| 56 | break; |
| 57 | case GrColorType::kBGRA_8888: |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 58 | if (dawn::TextureFormat::BGRA8Unorm == *dawnFormat) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 59 | return kBGRA_8888_GrPixelConfig; |
| 60 | } |
| 61 | break; |
| 62 | default: |
| 63 | break; |
| 64 | } |
| 65 | return kUnknown_GrPixelConfig; |
| 66 | } |
| 67 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 68 | static 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 | |
| 95 | bool 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 White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 104 | bool GrDawnCaps::isFormatRenderable(GrColorType ct, const GrBackendFormat& format, |
| 105 | int sampleCount) const { |
| 106 | if (!format.isValid() || sampleCount > 1) { |
| 107 | return false; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 108 | } |
| 109 | |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 110 | return GrDawnFormatIsRenderable(*format.getDawnFormat()) ? 1 : 0; |
| 111 | } |
| 112 | |
| 113 | int 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 | |
| 121 | int 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 | |
| 129 | int GrDawnCaps::maxRenderTargetSampleCount(const GrBackendFormat& format) const { |
| 130 | return format.isValid() ? 1 : 0; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 131 | } |
| 132 | |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 133 | GrBackendFormat GrDawnCaps::onGetDefaultBackendFormat(GrColorType ct, |
| 134 | GrRenderable renderable) const { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 135 | 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 | |
| 146 | GrBackendFormat GrDawnCaps::getBackendFormatFromCompressionType(SkImage::CompressionType type) const |
| 147 | { |
| 148 | return GrBackendFormat(); |
| 149 | } |
| 150 | |
| 151 | GrSwizzle GrDawnCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const |
| 152 | { |
| 153 | return get_swizzle(format, colorType, false); |
| 154 | } |
| 155 | |
| 156 | bool GrDawnCaps::canClearTextureOnCreation() const { |
| 157 | return true; |
| 158 | } |
| 159 | |
| 160 | GrSwizzle GrDawnCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const |
| 161 | { |
| 162 | return get_swizzle(format, colorType, true); |
| 163 | } |
| 164 | |
| 165 | bool GrDawnCaps::onAreColorTypeAndFormatCompatible(GrColorType ct, |
| 166 | const GrBackendFormat& format) const { |
| 167 | return true; |
| 168 | } |
Stephen White | b05ca08 | 2019-07-29 11:39:28 -0400 | [diff] [blame] | 169 | |
Robert Phillips | 00c9f0d | 2019-08-02 17:17:35 -0400 | [diff] [blame^] | 170 | GrColorType GrDawnCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat&, |
| 171 | bool isAlphaChannel) const { |
Stephen White | b05ca08 | 2019-07-29 11:39:28 -0400 | [diff] [blame] | 172 | return GrColorType::kUnknown; |
| 173 | } |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 174 | |
| 175 | #if GR_TEST_UTILS |
| 176 | std::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 |