summaryrefslogtreecommitdiffstats
path: root/gfx/skia/skia/include/gpu/dawn/GrDawnTypes.h
blob: fbd3dbaf55cb1ad2456c5ab0d83718e88c770537 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * Copyright 2019 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrDawnTypes_DEFINED
#define GrDawnTypes_DEFINED

#include "include/gpu/GpuTypes.h"

#ifdef Always
#undef Always
static constexpr int Always = 2;
#endif
#ifdef Success
#undef Success
static constexpr int Success = 0;
#endif
#ifdef None
#undef None
static constexpr int None = 0L;
#endif
#include "webgpu/webgpu_cpp.h" // IWYU pragma: export

struct GrDawnTextureInfo {
    wgpu::Texture       fTexture;
    wgpu::TextureFormat fFormat;
    uint32_t            fLevelCount;
    GrDawnTextureInfo() : fTexture(nullptr), fFormat(), fLevelCount(0) {
    }
    GrDawnTextureInfo(const GrDawnTextureInfo& other)
        : fTexture(other.fTexture)
        , fFormat(other.fFormat)
        , fLevelCount(other.fLevelCount) {
    }
    GrDawnTextureInfo& operator=(const GrDawnTextureInfo& other) {
        fTexture = other.fTexture;
        fFormat = other.fFormat;
        fLevelCount = other.fLevelCount;
        return *this;
    }
    bool operator==(const GrDawnTextureInfo& other) const {
        return fTexture.Get() == other.fTexture.Get() &&
               fFormat == other.fFormat &&
               fLevelCount == other.fLevelCount;
    }
};

// GrDawnRenderTargetInfo holds a reference to a (1-mip) TextureView. This means that, for now,
// GrDawnRenderTarget is suitable for rendering, but not readPixels() or writePixels(). Also,
// backdrop filters and certain blend modes requiring copying the destination framebuffer
// will not work.
struct GrDawnRenderTargetInfo {
    wgpu::TextureView   fTextureView;
    wgpu::TextureFormat fFormat;
    uint32_t            fLevelCount;
    GrDawnRenderTargetInfo() : fTextureView(nullptr), fFormat(), fLevelCount(0) {
    }
    GrDawnRenderTargetInfo(const GrDawnRenderTargetInfo& other)
        : fTextureView(other.fTextureView)
        , fFormat(other.fFormat)
        , fLevelCount(other.fLevelCount) {
    }
    explicit GrDawnRenderTargetInfo(const GrDawnTextureInfo& texInfo)
        : fFormat(texInfo.fFormat)
        , fLevelCount(1) {
        wgpu::TextureViewDescriptor desc;
        desc.format = texInfo.fFormat;
        desc.mipLevelCount = 1;
        fTextureView = texInfo.fTexture.CreateView(&desc);
    }
    GrDawnRenderTargetInfo& operator=(const GrDawnRenderTargetInfo& other) {
        fTextureView = other.fTextureView;
        fFormat = other.fFormat;
        fLevelCount = other.fLevelCount;
        return *this;
    }
    bool operator==(const GrDawnRenderTargetInfo& other) const {
        return fTextureView.Get() == other.fTextureView.Get() &&
               fFormat == other.fFormat &&
               fLevelCount == other.fLevelCount;
    }
};

struct GrDawnSurfaceInfo {
    uint32_t fSampleCount = 1;
    uint32_t fLevelCount = 0;
    skgpu::Protected fProtected = skgpu::Protected::kNo;

    wgpu::TextureFormat fFormat;
};

#endif