• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 Google LLC
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 GrSurfaceInfo_DEFINED
9 #define GrSurfaceInfo_DEFINED
10 
11 #include "include/gpu/GrTypes.h"
12 
13 #ifdef SK_GL
14 #include "include/private/GrGLTypesPriv.h"
15 #endif
16 #ifdef SK_VULKAN
17 #include "include/private/GrVkTypesPriv.h"
18 #endif
19 #ifdef SK_DIRECT3D
20 #include "include/private/GrD3DTypesMinimal.h"
21 struct GrD3DSurfaceInfo;
22 #endif
23 #ifdef SK_METAL
24 #include "include/private/GrMtlTypesPriv.h"
25 #endif
26 #ifdef SK_DAWN
27 #include "include/private/GrDawnTypesPriv.h"
28 #endif
29 #include "include/private/GrMockTypesPriv.h"
30 
31 class GrSurfaceInfo {
32 public:
GrSurfaceInfo()33     GrSurfaceInfo() {}
34 #ifdef SK_GL
GrSurfaceInfo(const GrGLSurfaceInfo & glInfo)35     GrSurfaceInfo(const GrGLSurfaceInfo& glInfo)
36             : fBackend(GrBackendApi::kOpenGL)
37             , fValid(true)
38             , fSampleCount(glInfo.fSampleCount)
39             , fLevelCount(glInfo.fLevelCount)
40             , fProtected(glInfo.fProtected)
41             , fGLSpec(glInfo) {}
42 #endif
43 #ifdef SK_VULKAN
GrSurfaceInfo(const GrVkSurfaceInfo & vkInfo)44     GrSurfaceInfo(const GrVkSurfaceInfo& vkInfo)
45             : fBackend(GrBackendApi::kVulkan)
46             , fValid(true)
47             , fSampleCount(vkInfo.fSampleCount)
48             , fLevelCount(vkInfo.fLevelCount)
49             , fProtected(vkInfo.fProtected)
50             , fVkSpec(vkInfo) {}
51 #endif
52 #ifdef SK_DIRECT3D
53     GrSurfaceInfo(const GrD3DSurfaceInfo& d3dInfo);
54 #endif
55 #ifdef SK_METAL
GrSurfaceInfo(const GrMtlSurfaceInfo & mtlInfo)56     GrSurfaceInfo(const GrMtlSurfaceInfo& mtlInfo)
57             : fBackend(GrBackendApi::kMetal)
58             , fValid(true)
59             , fSampleCount(mtlInfo.fSampleCount)
60             , fLevelCount(mtlInfo.fLevelCount)
61             , fProtected(mtlInfo.fProtected)
62             , fMtlSpec(mtlInfo) {}
63 #endif
64 #ifdef SK_DAWN
GrSurfaceInfo(const GrDawnSurfaceInfo & dawnInfo)65     GrSurfaceInfo(const GrDawnSurfaceInfo& dawnInfo)
66             : fBackend(GrBackendApi::kDawn)
67             , fValid(true)
68             , fSampleCount(dawnInfo.fSampleCount)
69             , fLevelCount(dawnInfo.fLevelCount)
70             , fProtected(dawnInfo.fProtected)
71             , fDawnSpec(dawnInfo) {}
72 #endif
GrSurfaceInfo(const GrMockSurfaceInfo & mockInfo)73     GrSurfaceInfo(const GrMockSurfaceInfo& mockInfo)
74             : fBackend(GrBackendApi::kMock)
75             , fValid(true)
76             , fSampleCount(mockInfo.fSampleCount)
77             , fLevelCount(mockInfo.fLevelCount)
78             , fProtected(mockInfo.fProtected)
79             , fMockSpec(mockInfo) {}
80 
81     ~GrSurfaceInfo();
82     GrSurfaceInfo(const GrSurfaceInfo&) = default;
83 
isValid()84     bool isValid() const { return fValid; }
backend()85     GrBackendApi backend() const { return fBackend; }
86 
numSamples()87     uint32_t numSamples() const { return fSampleCount; }
numMipLevels()88     uint32_t numMipLevels() const { return fLevelCount; }
isProtected()89     GrProtected isProtected() const { return fProtected; }
90 
91 #ifdef SK_GL
getGLSurfaceInfo(GrGLSurfaceInfo * info)92     bool getGLSurfaceInfo(GrGLSurfaceInfo* info) const {
93         if (!this->isValid() || fBackend != GrBackendApi::kOpenGL) {
94             return false;
95         }
96         *info = GrGLTextureSpecToSurfaceInfo(fGLSpec, fSampleCount, fLevelCount, fProtected);
97         return true;
98     }
99 #endif
100 #ifdef SK_VULKAN
getVkSurfaceInfo(GrVkSurfaceInfo * info)101     bool getVkSurfaceInfo(GrVkSurfaceInfo* info) const {
102         if (!this->isValid() || fBackend != GrBackendApi::kVulkan) {
103             return false;
104         }
105         *info = GrVkImageSpecToSurfaceInfo(fVkSpec, fSampleCount, fLevelCount, fProtected);
106         return true;
107     }
108 #endif
109 #ifdef SK_DIRECT3D
110     bool getD3DSurfaceInfo(GrD3DSurfaceInfo*) const;
111 #endif
112 #ifdef SK_METAL
getMtlSurfaceInfo(GrMtlSurfaceInfo * info)113     bool getMtlSurfaceInfo(GrMtlSurfaceInfo* info) const {
114         if (!this->isValid() || fBackend != GrBackendApi::kMetal) {
115             return false;
116         }
117         *info = GrMtlTextureSpecToSurfaceInfo(fMtlSpec, fSampleCount, fLevelCount, fProtected);
118         return true;
119     }
120 #endif
121 #ifdef SK_DAWN
getDawnSurfaceInfo(GrDawnSurfaceInfo * info)122     bool getDawnSurfaceInfo(GrDawnSurfaceInfo* info) const {
123         if (!this->isValid() || fBackend != GrBackendApi::kDawn) {
124             return false;
125         }
126         *info = GrDawnTextureSpecToSurfaceInfo(fDawnSpec, fSampleCount, fLevelCount, fProtected);
127         return true;
128     }
129 #endif
getMockSurfaceInfo(GrMockSurfaceInfo * info)130     bool getMockSurfaceInfo(GrMockSurfaceInfo* info) const {
131         if (!this->isValid() || fBackend != GrBackendApi::kMock) {
132             return false;
133         }
134         *info = GrMockTextureSpecToSurfaceInfo(fMockSpec, fSampleCount, fLevelCount, fProtected);
135         return true;
136     }
137 
138 private:
139     GrBackendApi fBackend = GrBackendApi::kMock;
140     bool fValid = false;
141 
142     uint32_t fSampleCount = 1;
143     uint32_t fLevelCount = 0;
144     GrProtected fProtected = GrProtected::kNo;
145 
146     union {
147 #ifdef SK_GL
148         GrGLTextureSpec fGLSpec;
149 #endif
150 #ifdef SK_VULKAN
151         GrVkImageSpec fVkSpec;
152 #endif
153 #ifdef SK_DIRECT3D
154         GrD3DTextureResourceSpecHolder fD3DSpec;
155 #endif
156 #ifdef SK_METAL
157         GrMtlTextureSpec fMtlSpec;
158 #endif
159 #ifdef SK_DAWN
160         GrDawnTextureSpec fDawnSpec;
161 #endif
162         GrMockTextureSpec fMockSpec;
163     };
164 };
165 
166 #endif
167