Debian Codegraph @

tools/gpu/ContextType.cpp

raw
1 /*
2 * Copyright 2023 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 #include "include/core/SkTypes.h"
9 #include "include/gpu/GpuTypes.h"
10 #include "tools/gpu/ContextType.h"
11
12 #if defined(SK_GANESH)
13 #include "include/gpu/ganesh/GrTypes.h"
14 #endif
15
16 const char* skgpu::ContextTypeName(skgpu::ContextType type) {
17 switch (type) {
18 case skgpu::ContextType::kGL:
19 return "OpenGL";
20 case skgpu::ContextType::kGLES:
21 return "OpenGLES";
22 case skgpu::ContextType::kANGLE_D3D9_ES2:
23 return "ANGLE D3D9 ES2";
24 case skgpu::ContextType::kANGLE_D3D11_ES2:
25 return "ANGLE D3D11 ES2";
26 case skgpu::ContextType::kANGLE_D3D11_ES3:
27 return "ANGLE D3D11 ES3";
28 case skgpu::ContextType::kANGLE_GL_ES2:
29 return "ANGLE GL ES2";
30 case skgpu::ContextType::kANGLE_GL_ES3:
31 return "ANGLE GL ES3";
32 case skgpu::ContextType::kANGLE_Metal_ES2:
33 return "ANGLE Metal ES2";
34 case skgpu::ContextType::kANGLE_Metal_ES3:
35 return "ANGLE Metal ES3";
36 case skgpu::ContextType::kVulkan:
37 return "Vulkan";
38 case skgpu::ContextType::kMetal:
39 return "Metal";
40 case skgpu::ContextType::kDirect3D:
41 return "Direct3D";
42 case skgpu::ContextType::kDawn_D3D11:
43 return "Dawn D3D11";
44 case skgpu::ContextType::kDawn_D3D12:
45 return "Dawn D3D12";
46 case skgpu::ContextType::kDawn_Metal:
47 return "Dawn Metal";
48 case skgpu::ContextType::kDawn_Vulkan:
49 return "Dawn Vulkan";
50 case skgpu::ContextType::kDawn_OpenGL:
51 return "Dawn OpenGL";
52 case skgpu::ContextType::kDawn_OpenGLES:
53 return "Dawn OpenGLES";
54 case skgpu::ContextType::kMock:
55 return "Mock";
56 }
57 SkUNREACHABLE;
58 }
59
60 bool skgpu::IsNativeBackend(skgpu::ContextType type) {
61 switch (type) {
62 case ContextType::kDirect3D:
63 case ContextType::kGL:
64 case ContextType::kGLES:
65 case ContextType::kMetal:
66 case ContextType::kVulkan:
67 return true;
68
69 default:
70 // Mock doesn't use the GPU, and Dawn and ANGLE add a layer between Skia and the native
71 // GPU backend.
72 return false;
73 }
74 }
75
76 bool skgpu::IsDawnBackend(skgpu::ContextType type) {
77 switch (type) {
78 case ContextType::kDawn_D3D11:
79 case ContextType::kDawn_D3D12:
80 case ContextType::kDawn_Metal:
81 case ContextType::kDawn_OpenGL:
82 case ContextType::kDawn_OpenGLES:
83 case ContextType::kDawn_Vulkan:
84 return true;
85
86 default:
87 return false;
88 }
89 }
90
91 bool skgpu::IsRenderingContext(ContextType type) {
92 return type != ContextType::kMock;
93 }
94
95 #if defined(SK_GANESH)
96 GrBackendApi skgpu::ganesh::ContextTypeBackend(skgpu::ContextType type) {
97 switch (type) {
98 case skgpu::ContextType::kGL:
99 case skgpu::ContextType::kGLES:
100 case skgpu::ContextType::kANGLE_D3D9_ES2:
101 case skgpu::ContextType::kANGLE_D3D11_ES2:
102 case skgpu::ContextType::kANGLE_D3D11_ES3:
103 case skgpu::ContextType::kANGLE_GL_ES2:
104 case skgpu::ContextType::kANGLE_GL_ES3:
105 case skgpu::ContextType::kANGLE_Metal_ES2:
106 case skgpu::ContextType::kANGLE_Metal_ES3:
107 return GrBackendApi::kOpenGL;
108
109 case ContextType::kVulkan:
110 return GrBackendApi::kVulkan;
111
112 case ContextType::kMetal:
113 return GrBackendApi::kMetal;
114
115 case ContextType::kDirect3D:
116 return GrBackendApi::kDirect3D;
117
118 case ContextType::kDawn_D3D11:
119 case ContextType::kDawn_D3D12:
120 case ContextType::kDawn_Metal:
121 case ContextType::kDawn_Vulkan:
122 case ContextType::kDawn_OpenGL:
123 case ContextType::kDawn_OpenGLES:
124 return GrBackendApi::kUnsupported;
125
126 case ContextType::kMock:
127 return GrBackendApi::kMock;
128 }
129 SkUNREACHABLE;
130 }
131 #endif
132
133 #if defined(SK_GRAPHITE)
134 skgpu::BackendApi skgpu::graphite::ContextTypeBackend(ContextType type) {
135 switch (type) {
136 case skgpu::ContextType::kGL:
137 case skgpu::ContextType::kGLES:
138 case skgpu::ContextType::kANGLE_D3D9_ES2:
139 case skgpu::ContextType::kANGLE_D3D11_ES2:
140 case skgpu::ContextType::kANGLE_D3D11_ES3:
141 case skgpu::ContextType::kANGLE_GL_ES2:
142 case skgpu::ContextType::kANGLE_GL_ES3:
143 case skgpu::ContextType::kANGLE_Metal_ES2:
144 case skgpu::ContextType::kANGLE_Metal_ES3:
145 case skgpu::ContextType::kDirect3D:
146 return BackendApi::kUnsupported;
147
148 case ContextType::kVulkan:
149 return BackendApi::kVulkan;
150
151 case ContextType::kMetal:
152 return BackendApi::kMetal;
153
154 case ContextType::kDawn_D3D11:
155 case ContextType::kDawn_D3D12:
156 case ContextType::kDawn_Metal:
157 case ContextType::kDawn_Vulkan:
158 case ContextType::kDawn_OpenGL:
159 case ContextType::kDawn_OpenGLES:
160 return BackendApi::kDawn;
161
162 case ContextType::kMock:
163 return BackendApi::kMock;
164 }
165 SkUNREACHABLE;
166 }
167 #endif