• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2020 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 
6 #include "angle_test_platform.h"
7 
8 #include "common/platform.h"
9 #include "gpu_info_util/SystemInfo.h"
10 
11 #if defined(ANGLE_PLATFORM_WINDOWS)
12 #    include <VersionHelpers.h>
13 #endif  // defined(ANGLE_PLATFORM_WINDOWS)
14 
15 using namespace angle;
16 
IsAdreno()17 bool IsAdreno()
18 {
19     std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
20     return (rendererString.find("Adreno") != std::string::npos);
21 }
22 
IsD3D11()23 bool IsD3D11()
24 {
25     std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
26     return (rendererString.find("Direct3D11 vs_5_0") != std::string::npos);
27 }
28 
IsD3D11_FL93()29 bool IsD3D11_FL93()
30 {
31     std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
32     return (rendererString.find("Direct3D11 vs_4_0_") != std::string::npos);
33 }
34 
IsD3D9()35 bool IsD3D9()
36 {
37     std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
38     return (rendererString.find("Direct3D9") != std::string::npos);
39 }
40 
IsD3DSM3()41 bool IsD3DSM3()
42 {
43     return IsD3D9() || IsD3D11_FL93();
44 }
45 
IsDesktopOpenGL()46 bool IsDesktopOpenGL()
47 {
48     return IsOpenGL() && !IsOpenGLES();
49 }
50 
IsOpenGLES()51 bool IsOpenGLES()
52 {
53     std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
54     return (rendererString.find("OpenGL ES") != std::string::npos);
55 }
56 
IsOpenGL()57 bool IsOpenGL()
58 {
59     std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
60     return (rendererString.find("OpenGL") != std::string::npos);
61 }
62 
IsNULL()63 bool IsNULL()
64 {
65     std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
66     return (rendererString.find("NULL") != std::string::npos);
67 }
68 
IsVulkan()69 bool IsVulkan()
70 {
71     const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
72     std::string rendererString(renderer);
73     return (rendererString.find("Vulkan") != std::string::npos);
74 }
75 
IsMetal()76 bool IsMetal()
77 {
78     const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
79     std::string rendererString(renderer);
80     return (rendererString.find("ANGLE Metal") != std::string::npos);
81 }
82 
IsD3D()83 bool IsD3D()
84 {
85     return IsD3D9() || IsD3D11();
86 }
87 
IsDebug()88 bool IsDebug()
89 {
90 #if !defined(NDEBUG)
91     return true;
92 #else
93     return false;
94 #endif
95 }
96 
IsRelease()97 bool IsRelease()
98 {
99     return !IsDebug();
100 }
101 
EnsureGLExtensionEnabled(const std::string & extName)102 bool EnsureGLExtensionEnabled(const std::string &extName)
103 {
104     if (IsGLExtensionEnabled("GL_ANGLE_request_extension") && IsGLExtensionRequestable(extName))
105     {
106         glRequestExtensionANGLE(extName.c_str());
107     }
108 
109     return IsGLExtensionEnabled(extName);
110 }
111 
IsEGLClientExtensionEnabled(const std::string & extName)112 bool IsEGLClientExtensionEnabled(const std::string &extName)
113 {
114     return CheckExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName);
115 }
116 
IsEGLDeviceExtensionEnabled(EGLDeviceEXT device,const std::string & extName)117 bool IsEGLDeviceExtensionEnabled(EGLDeviceEXT device, const std::string &extName)
118 {
119     return CheckExtensionExists(eglQueryDeviceStringEXT(device, EGL_EXTENSIONS), extName);
120 }
121 
IsEGLDisplayExtensionEnabled(EGLDisplay display,const std::string & extName)122 bool IsEGLDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
123 {
124     return CheckExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
125 }
126 
IsGLExtensionEnabled(const std::string & extName)127 bool IsGLExtensionEnabled(const std::string &extName)
128 {
129     return CheckExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
130                                 extName);
131 }
132 
IsGLExtensionRequestable(const std::string & extName)133 bool IsGLExtensionRequestable(const std::string &extName)
134 {
135     return CheckExtensionExists(
136         reinterpret_cast<const char *>(glGetString(GL_REQUESTABLE_EXTENSIONS_ANGLE)), extName);
137 }
138