• 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 GrDawnTypes_DEFINED
9 #define GrDawnTypes_DEFINED
10 
11 #include "include/gpu/GrTypes.h"
12 
13 #ifdef Always
14 #undef Always
15 static constexpr int Always = 2;
16 #endif
17 #ifdef Success
18 #undef Success
19 static constexpr int Success = 0;
20 #endif
21 #ifdef None
22 #undef None
23 static constexpr int None = 0L;
24 #endif
25 #include "dawn/webgpu_cpp.h"
26 
27 struct GrDawnTextureInfo {
28     wgpu::Texture       fTexture;
29     wgpu::TextureFormat fFormat;
30     uint32_t            fLevelCount;
GrDawnTextureInfoGrDawnTextureInfo31     GrDawnTextureInfo() : fTexture(nullptr), fFormat(), fLevelCount(0) {
32     }
GrDawnTextureInfoGrDawnTextureInfo33     GrDawnTextureInfo(const GrDawnTextureInfo& other)
34         : fTexture(other.fTexture)
35         , fFormat(other.fFormat)
36         , fLevelCount(other.fLevelCount) {
37     }
38     GrDawnTextureInfo& operator=(const GrDawnTextureInfo& other) {
39         fTexture = other.fTexture;
40         fFormat = other.fFormat;
41         fLevelCount = other.fLevelCount;
42         return *this;
43     }
44     bool operator==(const GrDawnTextureInfo& other) const {
45         return fTexture.Get() == other.fTexture.Get() &&
46                fFormat == other.fFormat &&
47                fLevelCount == other.fLevelCount;
48     }
49 };
50 
51 // GrDawnRenderTargetInfo holds a reference to a (1-mip) TextureView. This means that, for now,
52 // GrDawnRenderTarget is suitable for rendering, but not readPixels() or writePixels(). Also,
53 // backdrop filters and certain blend modes requiring copying the destination framebuffer
54 // will not work.
55 struct GrDawnRenderTargetInfo {
56     wgpu::TextureView   fTextureView;
57     wgpu::TextureFormat fFormat;
58     uint32_t            fLevelCount;
GrDawnRenderTargetInfoGrDawnRenderTargetInfo59     GrDawnRenderTargetInfo() : fTextureView(nullptr), fFormat(), fLevelCount(0) {
60     }
GrDawnRenderTargetInfoGrDawnRenderTargetInfo61     GrDawnRenderTargetInfo(const GrDawnRenderTargetInfo& other)
62         : fTextureView(other.fTextureView)
63         , fFormat(other.fFormat)
64         , fLevelCount(other.fLevelCount) {
65     }
GrDawnRenderTargetInfoGrDawnRenderTargetInfo66     explicit GrDawnRenderTargetInfo(const GrDawnTextureInfo& texInfo)
67         : fFormat(texInfo.fFormat)
68         , fLevelCount(1) {
69         wgpu::TextureViewDescriptor desc;
70         desc.format = texInfo.fFormat;
71         desc.mipLevelCount = 1;
72         fTextureView = texInfo.fTexture.CreateView(&desc);
73     }
74     GrDawnRenderTargetInfo& operator=(const GrDawnRenderTargetInfo& other) {
75         fTextureView = other.fTextureView;
76         fFormat = other.fFormat;
77         fLevelCount = other.fLevelCount;
78         return *this;
79     }
80     bool operator==(const GrDawnRenderTargetInfo& other) const {
81         return fTextureView.Get() == other.fTextureView.Get() &&
82                fFormat == other.fFormat &&
83                fLevelCount == other.fLevelCount;
84     }
85 };
86 
87 struct GrDawnSurfaceInfo {
88     uint32_t fSampleCount = 1;
89     uint32_t fLevelCount = 0;
90     GrProtected fProtected = GrProtected::kNo;
91 
92     wgpu::TextureFormat fFormat;
93 };
94 
95 #endif
96