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