xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/gl/egl/DeviceEGL.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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 
generateExtensions(egl::DeviceExtensions * outExtensions) const49 void DeviceEGL::generateExtensions(egl::DeviceExtensions *outExtensions) const
50 {
51     if (hasExtension("EGL_EXT_device_drm"))
52     {
53         outExtensions->deviceDrmEXT = true;
54     }
55 
56     if (hasExtension("EGL_EXT_device_drm_render_node"))
57     {
58         outExtensions->deviceDrmRenderNodeEXT = true;
59     }
60 }
61 
getDeviceString(EGLint name)62 const std::string DeviceEGL::getDeviceString(EGLint name)
63 {
64     switch (name)
65     {
66         case EGL_DRM_DEVICE_FILE_EXT:
67         case EGL_DRM_RENDER_NODE_FILE_EXT:
68         {
69             // eglQueryDeviceStringEXT can return nullptr if there is no render
70             // node attached to egl device.
71             const char *str = mDisplay->getFunctionsEGL()->queryDeviceStringEXT(mDevice, name);
72             return str ? std::string(str) : std::string();
73         }
74         default:
75             UNREACHABLE();
76             return std::string();
77     }
78 }
79 
hasExtension(const char * extension) const80 bool DeviceEGL::hasExtension(const char *extension) const
81 {
82     return std::find(mExtensions.begin(), mExtensions.end(), extension) != mExtensions.end();
83 }
84 
85 }  // namespace rx
86