1 //
2 // Copyright 2015 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
7 // DisplayGL.h: GL implementation of egl::Display
8
9 #include "libANGLE/renderer/gl/DisplayGL.h"
10
11 #include "libANGLE/AttributeMap.h"
12 #include "libANGLE/Context.h"
13 #include "libANGLE/Display.h"
14 #include "libANGLE/Surface.h"
15 #include "libANGLE/renderer/gl/ContextGL.h"
16 #include "libANGLE/renderer/gl/RendererGL.h"
17 #include "libANGLE/renderer/gl/StateManagerGL.h"
18 #include "libANGLE/renderer/gl/SurfaceGL.h"
19
20 #include <EGL/eglext.h>
21
22 namespace rx
23 {
24
25 // On Linux with the amdgpu driver, the renderer string looks like:
26 //
27 // AMD Radeon (TM) <GPU model> Graphics (<GPUgeneration>, DRM <DRMversion>, <kernelversion>,
28 // LLVM <LLVMversion>) eg. AMD Radeon (TM) RX 460 Graphics (POLARIS11,
29 // DRM 3.35.0, 5.4.0-65-generic, LLVM 11.0.0)
30 //
31 // We also want to handle the case without GPUGeneration:
32 // AMD Radeon GPU model (DRM DRMversion, kernelversion, LLVM LLVMversion)
33 //
34 // Thanks to Jeff Gilbert of Mozilla for this example
35 // https://phabricator.services.mozilla.com/D105636
SanitizeRendererString(std::string rendererString)36 std::string SanitizeRendererString(std::string rendererString)
37 {
38 size_t pos = rendererString.find(", DRM ");
39 if (pos != std::string::npos)
40 {
41 rendererString.resize(pos);
42 rendererString.push_back(')');
43 return rendererString;
44 }
45 pos = rendererString.find(" (DRM ");
46 if (pos != std::string::npos)
47 {
48 rendererString.resize(pos);
49 return rendererString;
50 }
51 return rendererString;
52 }
53
54 // OpenGL ES requires a prefix of "OpenGL ES" for the GL_VERSION string.
55 // We can also add the prefix to desktop OpenGL for consistency.
SanitizeVersionString(std::string versionString,bool isES)56 std::string SanitizeVersionString(std::string versionString, bool isES)
57 {
58 if (versionString.find("OpenGL") == std::string::npos)
59 {
60 std::string prefix = "OpenGL ";
61 if (isES)
62 {
63 prefix += "ES ";
64 }
65 versionString = prefix + versionString;
66 }
67 return versionString;
68 }
69
DisplayGL(const egl::DisplayState & state)70 DisplayGL::DisplayGL(const egl::DisplayState &state) : DisplayImpl(state) {}
71
~DisplayGL()72 DisplayGL::~DisplayGL() {}
73
initialize(egl::Display * display)74 egl::Error DisplayGL::initialize(egl::Display *display)
75 {
76 return egl::NoError();
77 }
78
terminate()79 void DisplayGL::terminate() {}
80
createImage(const egl::ImageState & state,const gl::Context * context,EGLenum target,const egl::AttributeMap & attribs)81 ImageImpl *DisplayGL::createImage(const egl::ImageState &state,
82 const gl::Context *context,
83 EGLenum target,
84 const egl::AttributeMap &attribs)
85 {
86 UNIMPLEMENTED();
87 return nullptr;
88 }
89
createPbufferFromClientBuffer(const egl::SurfaceState & state,EGLenum buftype,EGLClientBuffer clientBuffer,const egl::AttributeMap & attribs)90 SurfaceImpl *DisplayGL::createPbufferFromClientBuffer(const egl::SurfaceState &state,
91 EGLenum buftype,
92 EGLClientBuffer clientBuffer,
93 const egl::AttributeMap &attribs)
94 {
95 UNIMPLEMENTED();
96 return nullptr;
97 }
98
createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType,const egl::AttributeMap & attribs)99 StreamProducerImpl *DisplayGL::createStreamProducerD3DTexture(
100 egl::Stream::ConsumerType consumerType,
101 const egl::AttributeMap &attribs)
102 {
103 UNIMPLEMENTED();
104 return nullptr;
105 }
106
createShareGroup()107 ShareGroupImpl *DisplayGL::createShareGroup()
108 {
109 return new ShareGroupGL();
110 }
111
makeCurrent(egl::Display * display,egl::Surface * drawSurface,egl::Surface * readSurface,gl::Context * context)112 egl::Error DisplayGL::makeCurrent(egl::Display *display,
113 egl::Surface *drawSurface,
114 egl::Surface *readSurface,
115 gl::Context *context)
116 {
117 // Ensure that the correct global DebugAnnotator is installed when the end2end tests change
118 // the ANGLE back-end (done frequently).
119 display->setGlobalDebugAnnotator();
120
121 if (!context)
122 {
123 return egl::NoError();
124 }
125
126 // Pause transform feedback before making a new surface current, to workaround anglebug.com/1426
127 ContextGL *glContext = GetImplAs<ContextGL>(context);
128 glContext->getStateManager()->pauseTransformFeedback();
129
130 if (drawSurface == nullptr)
131 {
132 ANGLE_TRY(makeCurrentSurfaceless(context));
133 }
134
135 return egl::NoError();
136 }
137
getMaxConformantESVersion() const138 gl::Version DisplayGL::getMaxConformantESVersion() const
139 {
140 // 3.1 support is in progress.
141 return std::min(getMaxSupportedESVersion(), gl::Version(3, 0));
142 }
143
generateExtensions(egl::DisplayExtensions * outExtensions) const144 void DisplayGL::generateExtensions(egl::DisplayExtensions *outExtensions) const
145 {
146 // Advertise robust resource initialization on all OpenGL backends for testing even though it is
147 // not fully implemented.
148 outExtensions->robustResourceInitializationANGLE = true;
149 }
150
makeCurrentSurfaceless(gl::Context * context)151 egl::Error DisplayGL::makeCurrentSurfaceless(gl::Context *context)
152 {
153 UNIMPLEMENTED();
154 return egl::NoError();
155 }
156
getRendererDescription()157 std::string DisplayGL::getRendererDescription()
158 {
159 std::string rendererString = GetRendererString(getRenderer()->getFunctions());
160 const angle::FeaturesGL &features = getRenderer()->getFeatures();
161
162 if (features.sanitizeAmdGpuRendererString.enabled)
163 {
164 return SanitizeRendererString(rendererString);
165 }
166 return rendererString;
167 }
168
getVendorString()169 std::string DisplayGL::getVendorString()
170 {
171 return GetVendorString(getRenderer()->getFunctions());
172 }
173
getVersionString()174 std::string DisplayGL::getVersionString()
175 {
176 std::string versionString = GetVersionString(getRenderer()->getFunctions());
177 return SanitizeVersionString(versionString,
178 getRenderer()->getFunctions()->standard == STANDARD_GL_ES);
179 }
180
181 } // namespace rx
182