1 //
2 // Copyright 2022 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 // DeviceEGL.cpp:
7 // Implements the class methods for DeviceEGL.
8 //
9
10 #include "libANGLE/renderer/gl/egl/DeviceEGL.h"
11
12 #include <stdint.h>
13
14 #include "common/debug.h"
15 #include "common/string_utils.h"
16 #include "libANGLE/Display.h"
17 #include "libANGLE/renderer/gl/egl/DisplayEGL.h"
18 #include "libANGLE/renderer/gl/egl/FunctionsEGL.h"
19
20 namespace rx
21 {
22
DeviceEGL(DisplayEGL * display)23 DeviceEGL::DeviceEGL(DisplayEGL *display) : mDisplay(display) {}
24
~DeviceEGL()25 DeviceEGL::~DeviceEGL() {}
26
initialize()27 egl::Error DeviceEGL::initialize()
28 {
29 if (mDisplay->getFunctionsEGL()->hasExtension("EGL_EXT_device_query") &&
30 mDisplay->getFunctionsEGL()->queryDisplayAttribEXT(EGL_DEVICE_EXT, (EGLAttrib *)&mDevice))
31 {
32 const char *extensions =
33 mDisplay->getFunctionsEGL()->queryDeviceStringEXT(mDevice, EGL_EXTENSIONS);
34 if (extensions != nullptr)
35 {
36 angle::SplitStringAlongWhitespace(extensions, &mExtensions);
37 }
38 }
39
40 return egl::NoError();
41 }
42
getAttribute(const egl::Display * display,EGLint attribute,void ** outValue)43 egl::Error DeviceEGL::getAttribute(const egl::Display *display, EGLint attribute, void **outValue)
44 {
45 UNREACHABLE();
46 return egl::EglBadAttribute();
47 }
48
getType()49 EGLint DeviceEGL::getType()
50 {
51 UNREACHABLE();
52 return EGL_NONE;
53 }
54
generateExtensions(egl::DeviceExtensions * outExtensions) const55 void DeviceEGL::generateExtensions(egl::DeviceExtensions *outExtensions) const
56 {
57 if (hasExtension("EGL_EXT_device_drm"))
58 {
59 outExtensions->deviceDrmEXT = true;
60 }
61
62 if (hasExtension("EGL_EXT_device_drm_render_node"))
63 {
64 outExtensions->deviceDrmRenderNodeEXT = true;
65 }
66 }
67
getDeviceString(EGLint name)68 const std::string DeviceEGL::getDeviceString(EGLint name)
69 {
70 switch (name)
71 {
72 case EGL_DRM_DEVICE_FILE_EXT:
73 case EGL_DRM_RENDER_NODE_FILE_EXT:
74 return std::string(mDisplay->getFunctionsEGL()->queryDeviceStringEXT(mDevice, name));
75 default:
76 UNREACHABLE();
77 return std::string();
78 }
79 }
80
hasExtension(const char * extension) const81 bool DeviceEGL::hasExtension(const char *extension) const
82 {
83 return std::find(mExtensions.begin(), mExtensions.end(), extension) != mExtensions.end();
84 }
85
86 } // namespace rx
87