1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2019 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#ifndef GrDawnUtil_DEFINED
9cb93a386Sopenharmony_ci#define GrDawnUtil_DEFINED
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ci#include "include/private/GrTypesPriv.h"
12cb93a386Sopenharmony_ci#include "dawn/webgpu_cpp.h"
13cb93a386Sopenharmony_ci
14cb93a386Sopenharmony_cisize_t GrDawnBytesPerBlock(wgpu::TextureFormat format);
15cb93a386Sopenharmony_ciint GrDawnFormatStencilBits(wgpu::TextureFormat format);
16cb93a386Sopenharmony_cibool GrDawnFormatIsRenderable(wgpu::TextureFormat format);
17cb93a386Sopenharmony_cibool GrColorTypeToDawnFormat(GrColorType colorType, wgpu::TextureFormat* format);
18cb93a386Sopenharmony_cibool GrDawnFormatToGrColorType(wgpu::TextureFormat format, GrColorType* colorType);
19cb93a386Sopenharmony_cisize_t GrDawnRoundRowBytes(size_t rowBytes);
20cb93a386Sopenharmony_ci#if defined(SK_DEBUG) || GR_TEST_UTILS
21cb93a386Sopenharmony_ciconst char* GrDawnFormatToStr(wgpu::TextureFormat format);
22cb93a386Sopenharmony_ci#endif
23cb93a386Sopenharmony_ci
24cb93a386Sopenharmony_cistatic constexpr uint32_t GrDawnFormatChannels(wgpu::TextureFormat format) {
25cb93a386Sopenharmony_ci    switch (format) {
26cb93a386Sopenharmony_ci        case wgpu::TextureFormat::RGBA8Unorm:   return kRGBA_SkColorChannelFlags;
27cb93a386Sopenharmony_ci        case wgpu::TextureFormat::BGRA8Unorm:   return kRGBA_SkColorChannelFlags;
28cb93a386Sopenharmony_ci        case wgpu::TextureFormat::R8Unorm:      return kRed_SkColorChannelFlag;
29cb93a386Sopenharmony_ci
30cb93a386Sopenharmony_ci        default:                                return 0;
31cb93a386Sopenharmony_ci    }
32cb93a386Sopenharmony_ci}
33cb93a386Sopenharmony_ci
34cb93a386Sopenharmony_cistatic constexpr GrColorFormatDesc GrDawnFormatDesc(wgpu::TextureFormat format) {
35cb93a386Sopenharmony_ci    switch (format) {
36cb93a386Sopenharmony_ci        case wgpu::TextureFormat::RGBA8Unorm:
37cb93a386Sopenharmony_ci            return GrColorFormatDesc::MakeRGBA(8, GrColorTypeEncoding::kUnorm);
38cb93a386Sopenharmony_ci        case wgpu::TextureFormat::BGRA8Unorm:
39cb93a386Sopenharmony_ci            return GrColorFormatDesc::MakeRGBA(8, GrColorTypeEncoding::kUnorm);
40cb93a386Sopenharmony_ci        case wgpu::TextureFormat::R8Unorm:
41cb93a386Sopenharmony_ci            return GrColorFormatDesc::MakeR(8, GrColorTypeEncoding::kUnorm);
42cb93a386Sopenharmony_ci
43cb93a386Sopenharmony_ci        default:
44cb93a386Sopenharmony_ci            return GrColorFormatDesc::MakeInvalid();
45cb93a386Sopenharmony_ci    }
46cb93a386Sopenharmony_ci}
47cb93a386Sopenharmony_ci
48cb93a386Sopenharmony_ci#endif // GrDawnUtil_DEFINED
49