• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/gpu/ganesh/GrTypesPriv.h"
12 #include "webgpu/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 
GrDawnFormatDesc(wgpu::TextureFormat format)34 static constexpr GrColorFormatDesc GrDawnFormatDesc(wgpu::TextureFormat format) {
35     switch (format) {
36         case wgpu::TextureFormat::RGBA8Unorm:
37             return GrColorFormatDesc::MakeRGBA(8, GrColorTypeEncoding::kUnorm);
38         case wgpu::TextureFormat::BGRA8Unorm:
39             return GrColorFormatDesc::MakeRGBA(8, GrColorTypeEncoding::kUnorm);
40         case wgpu::TextureFormat::R8Unorm:
41             return GrColorFormatDesc::MakeR(8, GrColorTypeEncoding::kUnorm);
42 
43         default:
44             return GrColorFormatDesc::MakeInvalid();
45     }
46 }
47 
48 #endif // GrDawnUtil_DEFINED
49