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)); |
Stephen White | d67c71f | 2019-08-06 11:15:41 -0400 | [diff] [blame] | 13 | fMaxTextureSize = 2048; // FIXME |
| 14 | fMaxVertexAttributes = 16; // FIXME |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 15 | fPerformPartialClearsAsDraws = true; |
Stephen White | f813ef7 | 2019-08-09 12:28:37 -0400 | [diff] [blame^] | 16 | |
| 17 | this->applyOptionsOverrides(contextOptions); |
| 18 | fShaderCaps->applyOptionsOverrides(contextOptions); |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | bool GrDawnCaps::isFormatSRGB(const GrBackendFormat& format) const { |
| 22 | return false; |
| 23 | } |
| 24 | |
Robert Phillips | 8ff8bcc | 2019-07-29 17:03:35 -0400 | [diff] [blame] | 25 | bool GrDawnCaps::isFormatCompressed(const GrBackendFormat& format) const { |
| 26 | return false; |
| 27 | } |
| 28 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 29 | bool GrDawnCaps::isConfigTexturable(GrPixelConfig config) const { |
| 30 | switch (config) { |
| 31 | case kRGBA_8888_GrPixelConfig: |
| 32 | case kBGRA_8888_GrPixelConfig: |
| 33 | case kAlpha_8_GrPixelConfig: |
| 34 | return true; |
| 35 | default: |
| 36 | return false; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | GrPixelConfig GrDawnCaps::onGetConfigFromBackendFormat(const GrBackendFormat& format, |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 41 | GrColorType colorType) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 42 | dawn::TextureFormat dawnFormat; |
| 43 | if (!format.asDawnFormat(&dawnFormat)) { |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 44 | return kUnknown_GrPixelConfig; |
| 45 | } |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 46 | switch (colorType) { |
| 47 | case GrColorType::kUnknown: |
| 48 | return kUnknown_GrPixelConfig; |
| 49 | case GrColorType::kAlpha_8: |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 50 | if (dawn::TextureFormat::R8Unorm == dawnFormat) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 51 | return kAlpha_8_as_Red_GrPixelConfig; |
| 52 | } |
| 53 | break; |
| 54 | case GrColorType::kRGBA_8888: |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 55 | if (dawn::TextureFormat::RGBA8Unorm == dawnFormat) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 56 | return kRGBA_8888_GrPixelConfig; |
Stephen White | fe55c73 | 2019-08-09 12:24:30 -0400 | [diff] [blame] | 57 | } else if (dawn::TextureFormat::BGRA8Unorm == dawnFormat) { |
Stephen White | d67c71f | 2019-08-06 11:15:41 -0400 | [diff] [blame] | 58 | // FIXME: This shouldn't be necessary, but on some platforms (Mac) |
| 59 | // Skia byte order is RGBA, while preferred swap format is BGRA. |
| 60 | return kBGRA_8888_GrPixelConfig; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 61 | } |
| 62 | break; |
| 63 | case GrColorType::kRGB_888x: |
| 64 | break; |
| 65 | case GrColorType::kBGRA_8888: |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 66 | if (dawn::TextureFormat::BGRA8Unorm == dawnFormat) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 67 | return kBGRA_8888_GrPixelConfig; |
Stephen White | fe55c73 | 2019-08-09 12:24:30 -0400 | [diff] [blame] | 68 | } else if (dawn::TextureFormat::RGBA8Unorm == dawnFormat) { |
Stephen White | d67c71f | 2019-08-06 11:15:41 -0400 | [diff] [blame] | 69 | return kRGBA_8888_GrPixelConfig; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 70 | } |
| 71 | break; |
| 72 | default: |
| 73 | break; |
| 74 | } |
| 75 | return kUnknown_GrPixelConfig; |
| 76 | } |
| 77 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 78 | static GrSwizzle get_swizzle(const GrBackendFormat& format, GrColorType colorType, |
| 79 | bool forOutput) { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 80 | SkDEBUGCODE(dawn::TextureFormat format;) |
| 81 | SkASSERT(format.asDawnFormat(&format)); |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 82 | |
| 83 | switch (colorType) { |
| 84 | case GrColorType::kAlpha_8: // fall through |
| 85 | case GrColorType::kAlpha_F16: |
| 86 | if (forOutput) { |
| 87 | return GrSwizzle::AAAA(); |
| 88 | } else { |
| 89 | return GrSwizzle::RRRR(); |
| 90 | } |
| 91 | case GrColorType::kGray_8: |
| 92 | if (!forOutput) { |
| 93 | return GrSwizzle::RRRA(); |
| 94 | } |
| 95 | break; |
| 96 | case GrColorType::kRGB_888x: |
| 97 | if (!forOutput) { |
| 98 | return GrSwizzle::RGB1(); |
| 99 | } |
| 100 | default: |
| 101 | return GrSwizzle::RGBA(); |
| 102 | } |
| 103 | return GrSwizzle::RGBA(); |
| 104 | } |
| 105 | |
| 106 | bool GrDawnCaps::isFormatTexturable(GrColorType ct, const GrBackendFormat& format) const { |
| 107 | GrPixelConfig config = this->getConfigFromBackendFormat(format, ct); |
| 108 | if (kUnknown_GrPixelConfig == config) { |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | return this->isConfigTexturable(config); |
| 113 | } |
| 114 | |
Stephen White | fe55c73 | 2019-08-09 12:24:30 -0400 | [diff] [blame] | 115 | bool GrDawnCaps::isFormatRenderable(const GrBackendFormat& format, |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 116 | int sampleCount) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 117 | dawn::TextureFormat dawnFormat; |
| 118 | if (!format.isValid() || sampleCount > 1 || !format.asDawnFormat(&dawnFormat)) { |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 119 | return false; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 120 | } |
| 121 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 122 | return GrDawnFormatIsRenderable(dawnFormat); |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 123 | } |
| 124 | |
Stephen White | fe55c73 | 2019-08-09 12:24:30 -0400 | [diff] [blame] | 125 | bool GrDawnCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, |
| 126 | int sampleCount) const { |
| 127 | return isFormatRenderable(format, sampleCount); |
| 128 | } |
| 129 | |
| 130 | int GrDawnCaps::getRenderTargetSampleCount(int requestedCount, |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 131 | const GrBackendFormat& backendFormat) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 132 | dawn::TextureFormat dawnFormat; |
Stephen White | fe55c73 | 2019-08-09 12:24:30 -0400 | [diff] [blame] | 133 | if (!backendFormat.asDawnFormat(&dawnFormat)) { |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 134 | return 0; |
| 135 | } |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 136 | return GrDawnFormatIsRenderable(dawnFormat) ? 1 : 0; |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 137 | } |
| 138 | |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 139 | int GrDawnCaps::maxRenderTargetSampleCount(const GrBackendFormat& format) const { |
| 140 | return format.isValid() ? 1 : 0; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 141 | } |
| 142 | |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 143 | GrBackendFormat GrDawnCaps::onGetDefaultBackendFormat(GrColorType ct, |
| 144 | GrRenderable renderable) const { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 145 | 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 | |
| 156 | GrBackendFormat GrDawnCaps::getBackendFormatFromCompressionType(SkImage::CompressionType type) const |
| 157 | { |
| 158 | return GrBackendFormat(); |
| 159 | } |
| 160 | |
| 161 | GrSwizzle GrDawnCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const |
| 162 | { |
| 163 | return get_swizzle(format, colorType, false); |
| 164 | } |
| 165 | |
| 166 | bool GrDawnCaps::canClearTextureOnCreation() const { |
| 167 | return true; |
| 168 | } |
| 169 | |
| 170 | GrSwizzle GrDawnCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const |
| 171 | { |
| 172 | return get_swizzle(format, colorType, true); |
| 173 | } |
| 174 | |
| 175 | bool GrDawnCaps::onAreColorTypeAndFormatCompatible(GrColorType ct, |
| 176 | const GrBackendFormat& format) const { |
| 177 | return true; |
| 178 | } |
Stephen White | b05ca08 | 2019-07-29 11:39:28 -0400 | [diff] [blame] | 179 | |
Robert Phillips | 00c9f0d | 2019-08-02 17:17:35 -0400 | [diff] [blame] | 180 | GrColorType GrDawnCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat&, |
| 181 | bool isAlphaChannel) const { |
Stephen White | b05ca08 | 2019-07-29 11:39:28 -0400 | [diff] [blame] | 182 | return GrColorType::kUnknown; |
| 183 | } |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 184 | |
| 185 | #if GR_TEST_UTILS |
| 186 | std::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 |