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