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 | |
| 21 | bool 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 | |
| 32 | GrPixelConfig 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 White | 3e45e12 | 2019-07-22 09:12:29 -0400 | [diff] [blame] | 44 | if (dawn::TextureFormat::RGBA8Unorm == textureFormat) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 45 | return kRGBA_8888_GrPixelConfig; |
| 46 | } |
| 47 | break; |
| 48 | case GrColorType::kRGB_888x: |
| 49 | break; |
| 50 | case GrColorType::kBGRA_8888: |
Stephen White | 3e45e12 | 2019-07-22 09:12:29 -0400 | [diff] [blame] | 51 | if (dawn::TextureFormat::BGRA8Unorm == textureFormat) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 52 | return kBGRA_8888_GrPixelConfig; |
| 53 | } |
| 54 | break; |
| 55 | default: |
| 56 | break; |
| 57 | } |
| 58 | return kUnknown_GrPixelConfig; |
| 59 | } |
| 60 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 61 | static 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 | |
| 88 | bool 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 | |
| 97 | bool GrDawnCaps::isFormatCopyable(GrColorType ct, const GrBackendFormat& format) const { |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | int 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 | |
| 111 | GrBackendFormat 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 | |
| 123 | GrBackendFormat GrDawnCaps::getBackendFormatFromCompressionType(SkImage::CompressionType type) const |
| 124 | { |
| 125 | return GrBackendFormat(); |
| 126 | } |
| 127 | |
| 128 | GrSwizzle GrDawnCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const |
| 129 | { |
| 130 | return get_swizzle(format, colorType, false); |
| 131 | } |
| 132 | |
| 133 | bool GrDawnCaps::canClearTextureOnCreation() const { |
| 134 | return true; |
| 135 | } |
| 136 | |
| 137 | GrSwizzle GrDawnCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const |
| 138 | { |
| 139 | return get_swizzle(format, colorType, true); |
| 140 | } |
| 141 | |
| 142 | bool GrDawnCaps::onAreColorTypeAndFormatCompatible(GrColorType ct, |
| 143 | const GrBackendFormat& format) const { |
| 144 | return true; |
| 145 | } |
Stephen White | b05ca08 | 2019-07-29 11:39:28 -0400 | [diff] [blame^] | 146 | |
| 147 | GrColorType GrDawnCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat&) const { |
| 148 | return GrColorType::kUnknown; |
| 149 | } |