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 
8 #ifndef GrDawnUtil_DEFINED
9 #define GrDawnUtil_DEFINED
10 
11 #include "include/private/GrTypesPriv.h"
12 #include "dawn/webgpu_cpp.h"
13 
14 size_t GrDawnBytesPerBlock(wgpu::TextureFormat format);
15 int GrDawnFormatStencilBits(wgpu::TextureFormat format);
16 bool GrDawnFormatIsRenderable(wgpu::TextureFormat format);
17 bool GrColorTypeToDawnFormat(GrColorType colorType, wgpu::TextureFormat* format);
18 bool GrDawnFormatToGrColorType(wgpu::TextureFormat format, GrColorType* colorType);
19 size_t GrDawnRoundRowBytes(size_t rowBytes);
20 #if defined(SK_DEBUG) || GR_TEST_UTILS
21 const char* GrDawnFormatToStr(wgpu::TextureFormat format);
22 #endif
23 
GrDawnFormatChannels(wgpu::TextureFormat format)24 static constexpr uint32_t GrDawnFormatChannels(wgpu::TextureFormat format) {
25     switch (format) {
26         case wgpu::TextureFormat::RGBA8Unorm:   return kRGBA_SkColorChannelFlags;
27         case wgpu::TextureFormat::BGRA8Unorm:   return kRGBA_SkColorChannelFlags;
28         case wgpu::TextureFormat::R8Unorm:      return kRed_SkColorChannelFlag;
29 
30         default:                                return 0;
31     }
32 }
33 
34 #endif // GrDawnUtil_DEFINED
35