blob: fbb7b43470d742ed410c4c5cda5a8cd1c604d3bd [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
8#include "GrDawnUtil.h"
9
10GrPixelConfig GrDawnFormatToPixelConfig(dawn::TextureFormat format) {
11 switch (format) {
12 case dawn::TextureFormat::R8G8B8A8Unorm:
13 return kRGBA_8888_GrPixelConfig;
14 case dawn::TextureFormat::B8G8R8A8Unorm:
15 return kBGRA_8888_GrPixelConfig;
16 case dawn::TextureFormat::R8Unorm:
17 return kAlpha_8_GrPixelConfig;
18 case dawn::TextureFormat::D32FloatS8Uint:
19 default:
20 SkASSERT(false);
21 return kRGBA_8888_GrPixelConfig;
22 }
23}
24
25bool GrPixelConfigToDawnFormat(GrPixelConfig config, dawn::TextureFormat* format) {
26 switch (config) {
27 case kRGBA_8888_GrPixelConfig:
28 case kRGBA_4444_GrPixelConfig:
29 case kRGB_565_GrPixelConfig:
30 case kGray_8_GrPixelConfig:
31 *format = dawn::TextureFormat::R8G8B8A8Unorm;
32 return true;
33 case kBGRA_8888_GrPixelConfig:
34 *format = dawn::TextureFormat::B8G8R8A8Unorm;
35 return true;
36 case kAlpha_8_GrPixelConfig:
37 *format = dawn::TextureFormat::R8Unorm;
38 return true;
39 default:
40 return false;
41 }
42}