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/GrDawnUtil.h" |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 9 | |
| 10 | GrPixelConfig GrDawnFormatToPixelConfig(dawn::TextureFormat format) { |
| 11 | switch (format) { |
Stephen White | 3e45e12 | 2019-07-22 09:12:29 -0400 | [diff] [blame] | 12 | case dawn::TextureFormat::RGBA8Unorm: |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 13 | return kRGBA_8888_GrPixelConfig; |
Stephen White | 3e45e12 | 2019-07-22 09:12:29 -0400 | [diff] [blame] | 14 | case dawn::TextureFormat::BGRA8Unorm: |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 15 | return kBGRA_8888_GrPixelConfig; |
| 16 | case dawn::TextureFormat::R8Unorm: |
| 17 | return kAlpha_8_GrPixelConfig; |
Stephen White | 3e45e12 | 2019-07-22 09:12:29 -0400 | [diff] [blame] | 18 | case dawn::TextureFormat::Depth24PlusStencil8: |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 19 | default: |
| 20 | SkASSERT(false); |
| 21 | return kRGBA_8888_GrPixelConfig; |
| 22 | } |
| 23 | } |
| 24 | |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame^] | 25 | bool GrDawnFormatIsRenderable(dawn::TextureFormat format) { |
| 26 | // For now, all the formats above are renderable. If a non-renderable format is added |
| 27 | // (see dawn/src/dawn_native/Format.cpp), an exception should be added here. |
| 28 | return true; |
| 29 | } |
| 30 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 31 | bool GrPixelConfigToDawnFormat(GrPixelConfig config, dawn::TextureFormat* format) { |
| 32 | switch (config) { |
| 33 | case kRGBA_8888_GrPixelConfig: |
| 34 | case kRGBA_4444_GrPixelConfig: |
| 35 | case kRGB_565_GrPixelConfig: |
| 36 | case kGray_8_GrPixelConfig: |
Stephen White | 3e45e12 | 2019-07-22 09:12:29 -0400 | [diff] [blame] | 37 | *format = dawn::TextureFormat::RGBA8Unorm; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 38 | return true; |
| 39 | case kBGRA_8888_GrPixelConfig: |
Stephen White | 3e45e12 | 2019-07-22 09:12:29 -0400 | [diff] [blame] | 40 | *format = dawn::TextureFormat::BGRA8Unorm; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 41 | return true; |
| 42 | case kAlpha_8_GrPixelConfig: |
| 43 | *format = dawn::TextureFormat::R8Unorm; |
| 44 | return true; |
| 45 | default: |
| 46 | return false; |
| 47 | } |
| 48 | } |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame^] | 49 | |
| 50 | #if GR_TEST_UTILS |
| 51 | const char* GrDawnFormatToStr(dawn::TextureFormat format) { |
| 52 | switch (format) { |
| 53 | case dawn::TextureFormat::RGBA8Unorm: |
| 54 | return "RGBA8Unorm"; |
| 55 | case dawn::TextureFormat::BGRA8Unorm: |
| 56 | return "BGRA8Unorm"; |
| 57 | case dawn::TextureFormat::R8Unorm: |
| 58 | return "R8Unorm"; |
| 59 | case dawn::TextureFormat::Depth24PlusStencil8: |
| 60 | return "Depth24PlusStencil8"; |
| 61 | default: |
| 62 | SkASSERT(false); |
| 63 | return "Unknown"; |
| 64 | } |
| 65 | } |
| 66 | #endif |