aboutsummaryrefslogtreecommitdiff
path: root/src/deps/skia/include/gpu/GrSurfaceInfo.h
blob: e4ef3c18d6c1aafb236ec0fe8e272740b0f3ea9a (plain) (blame)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 * Copyright 2021 Google LLC
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrSurfaceInfo_DEFINED
#define GrSurfaceInfo_DEFINED

#include "include/gpu/GrTypes.h"

#ifdef SK_GL
#include "include/private/GrGLTypesPriv.h"
#endif
#ifdef SK_VULKAN
#include "include/private/GrVkTypesPriv.h"
#endif
#ifdef SK_DIRECT3D
#include "include/private/GrD3DTypesMinimal.h"
struct GrD3DSurfaceInfo;
#endif
#ifdef SK_METAL
#include "include/private/GrMtlTypesPriv.h"
#endif
#ifdef SK_DAWN
#include "include/private/GrDawnTypesPriv.h"
#endif
#include "include/private/GrMockTypesPriv.h"

class GrSurfaceInfo {
public:
    GrSurfaceInfo() {}
#ifdef SK_GL
    GrSurfaceInfo(const GrGLSurfaceInfo& glInfo)
            : fBackend(GrBackendApi::kOpenGL)
            , fValid(true)
            , fSampleCount(glInfo.fSampleCount)
            , fLevelCount(glInfo.fLevelCount)
            , fProtected(glInfo.fProtected)
            , fGLSpec(glInfo) {}
#endif
#ifdef SK_VULKAN
    GrSurfaceInfo(const GrVkSurfaceInfo& vkInfo)
            : fBackend(GrBackendApi::kVulkan)
            , fValid(true)
            , fSampleCount(vkInfo.fSampleCount)
            , fLevelCount(vkInfo.fLevelCount)
            , fProtected(vkInfo.fProtected)
            , fVkSpec(vkInfo) {}
#endif
#ifdef SK_DIRECT3D
    GrSurfaceInfo(const GrD3DSurfaceInfo& d3dInfo);
#endif
#ifdef SK_METAL
    GrSurfaceInfo(const GrMtlSurfaceInfo& mtlInfo)
            : fBackend(GrBackendApi::kMetal)
            , fValid(true)
            , fSampleCount(mtlInfo.fSampleCount)
            , fLevelCount(mtlInfo.fLevelCount)
            , fProtected(mtlInfo.fProtected)
            , fMtlSpec(mtlInfo) {}
#endif
#ifdef SK_DAWN
    GrSurfaceInfo(const GrDawnSurfaceInfo& dawnInfo)
            : fBackend(GrBackendApi::kDawn)
            , fValid(true)
            , fSampleCount(dawnInfo.fSampleCount)
            , fLevelCount(dawnInfo.fLevelCount)
            , fProtected(dawnInfo.fProtected)
            , fDawnSpec(dawnInfo) {}
#endif
    GrSurfaceInfo(const GrMockSurfaceInfo& mockInfo)
            : fBackend(GrBackendApi::kMock)
            , fValid(true)
            , fSampleCount(mockInfo.fSampleCount)
            , fLevelCount(mockInfo.fLevelCount)
            , fProtected(mockInfo.fProtected)
            , fMockSpec(mockInfo) {}

    ~GrSurfaceInfo();
    GrSurfaceInfo(const GrSurfaceInfo&) = default;

    bool isValid() const { return fValid; }
    GrBackendApi backend() const { return fBackend; }

    uint32_t numSamples() const { return fSampleCount; }
    uint32_t numMipLevels() const { return fLevelCount; }
    GrProtected isProtected() const { return fProtected; }

#ifdef SK_GL
    bool getGLSurfaceInfo(GrGLSurfaceInfo* info) const {
        if (!this->isValid() || fBackend != GrBackendApi::kOpenGL) {
            return false;
        }
        *info = GrGLTextureSpecToSurfaceInfo(fGLSpec, fSampleCount, fLevelCount, fProtected);
        return true;
    }
#endif
#ifdef SK_VULKAN
    bool getVkSurfaceInfo(GrVkSurfaceInfo* info) const {
        if (!this->isValid() || fBackend != GrBackendApi::kVulkan) {
            return false;
        }
        *info = GrVkImageSpecToSurfaceInfo(fVkSpec, fSampleCount, fLevelCount, fProtected);
        return true;
    }
#endif
#ifdef SK_DIRECT3D
    bool getD3DSurfaceInfo(GrD3DSurfaceInfo*) const;
#endif
#ifdef SK_METAL
    bool getMtlSurfaceInfo(GrMtlSurfaceInfo* info) const {
        if (!this->isValid() || fBackend != GrBackendApi::kMetal) {
            return false;
        }
        *info = GrMtlTextureSpecToSurfaceInfo(fMtlSpec, fSampleCount, fLevelCount, fProtected);
        return true;
    }
#endif
#ifdef SK_DAWN
    bool getDawnSurfaceInfo(GrDawnSurfaceInfo* info) const {
        if (!this->isValid() || fBackend != GrBackendApi::kDawn) {
            return false;
        }
        *info = GrDawnTextureSpecToSurfaceInfo(fDawnSpec, fSampleCount, fLevelCount, fProtected);
        return true;
    }
#endif
    bool getMockSurfaceInfo(GrMockSurfaceInfo* info) const {
        if (!this->isValid() || fBackend != GrBackendApi::kMock) {
            return false;
        }
        *info = GrMockTextureSpecToSurfaceInfo(fMockSpec, fSampleCount, fLevelCount, fProtected);
        return true;
    }

private:
    GrBackendApi fBackend = GrBackendApi::kMock;
    bool fValid = false;

    uint32_t fSampleCount = 1;
    uint32_t fLevelCount = 0;
    GrProtected fProtected = GrProtected::kNo;

    union {
#ifdef SK_GL
        GrGLTextureSpec fGLSpec;
#endif
#ifdef SK_VULKAN
        GrVkImageSpec fVkSpec;
#endif
#ifdef SK_DIRECT3D
        GrD3DTextureResourceSpecHolder fD3DSpec;
#endif
#ifdef SK_METAL
        GrMtlTextureSpec fMtlSpec;
#endif
#ifdef SK_DAWN
        GrDawnTextureSpec fDawnSpec;
#endif
        GrMockTextureSpec fMockSpec;
    };
};

#endif