blob: c0193eacf16e387a00178341f31554f8c5fba554 [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
Mike Klein52337de2019-07-25 09:00:52 -05008#include "src/gpu/dawn/GrDawnUtil.h"
Stephen White985741a2019-07-18 11:43:45 -04009
10GrPixelConfig GrDawnFormatToPixelConfig(dawn::TextureFormat format) {
11 switch (format) {
Stephen White3e45e122019-07-22 09:12:29 -040012 case dawn::TextureFormat::RGBA8Unorm:
Stephen White985741a2019-07-18 11:43:45 -040013 return kRGBA_8888_GrPixelConfig;
Stephen White3e45e122019-07-22 09:12:29 -040014 case dawn::TextureFormat::BGRA8Unorm:
Stephen White985741a2019-07-18 11:43:45 -040015 return kBGRA_8888_GrPixelConfig;
16 case dawn::TextureFormat::R8Unorm:
17 return kAlpha_8_GrPixelConfig;
Stephen White3e45e122019-07-22 09:12:29 -040018 case dawn::TextureFormat::Depth24PlusStencil8:
Stephen White985741a2019-07-18 11:43:45 -040019 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:
Stephen White3e45e122019-07-22 09:12:29 -040031 *format = dawn::TextureFormat::RGBA8Unorm;
Stephen White985741a2019-07-18 11:43:45 -040032 return true;
33 case kBGRA_8888_GrPixelConfig:
Stephen White3e45e122019-07-22 09:12:29 -040034 *format = dawn::TextureFormat::BGRA8Unorm;
Stephen White985741a2019-07-18 11:43:45 -040035 return true;
36 case kAlpha_8_GrPixelConfig:
37 *format = dawn::TextureFormat::R8Unorm;
38 return true;
39 default:
40 return false;
41 }
42}