1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qeglstreamconvenience_p.h"
5#include <string.h>
6
7QT_BEGIN_NAMESPACE
8
9QEGLStreamConvenience::QEGLStreamConvenience()
10 : initialized(false),
11 has_egl_platform_device(false),
12 has_egl_device_base(false),
13 has_egl_stream(false),
14 has_egl_stream_producer_eglsurface(false),
15 has_egl_stream_consumer_egloutput(false),
16 has_egl_output_drm(false),
17 has_egl_output_base(false),
18 has_egl_stream_cross_process_fd(false),
19 has_egl_stream_consumer_gltexture(false)
20{
21 const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
22 if (!extensions) {
23 qWarning(msg: "Failed to query EGL extensions");
24 return;
25 }
26
27 query_devices = reinterpret_cast<PFNEGLQUERYDEVICESEXTPROC>(eglGetProcAddress(procname: "eglQueryDevicesEXT"));
28 query_device_string = reinterpret_cast<PFNEGLQUERYDEVICESTRINGEXTPROC>(eglGetProcAddress(procname: "eglQueryDeviceStringEXT"));
29 get_platform_display = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(eglGetProcAddress(procname: "eglGetPlatformDisplayEXT"));
30
31 has_egl_device_base = strstr(haystack: extensions, needle: "EGL_EXT_device_base");
32 has_egl_platform_device = strstr(haystack: extensions, needle: "EGL_EXT_platform_device");
33}
34
35void QEGLStreamConvenience::initialize(EGLDisplay dpy)
36{
37 if (initialized)
38 return;
39
40 if (!eglBindAPI(EGL_OPENGL_ES_API)) {
41 qWarning(msg: "Failed to bind OpenGL ES API");
42 return;
43 }
44
45 const char *extensions = eglQueryString(dpy, EGL_EXTENSIONS);
46 if (!extensions) {
47 qWarning(msg: "Failed to query EGL extensions");
48 return;
49 }
50
51 create_stream = reinterpret_cast<PFNEGLCREATESTREAMKHRPROC>(eglGetProcAddress(procname: "eglCreateStreamKHR"));
52 destroy_stream = reinterpret_cast<PFNEGLDESTROYSTREAMKHRPROC>(eglGetProcAddress(procname: "eglDestroyStreamKHR"));
53 stream_attrib = reinterpret_cast<PFNEGLSTREAMATTRIBKHRPROC>(eglGetProcAddress(procname: "eglStreamAttribKHR"));
54 query_stream = reinterpret_cast<PFNEGLQUERYSTREAMKHRPROC>(eglGetProcAddress(procname: "eglQueryStreamKHR"));
55 query_stream_u64 = reinterpret_cast<PFNEGLQUERYSTREAMU64KHRPROC>(eglGetProcAddress(procname: "eglQueryStreamu64KHR"));
56 create_stream_producer_surface = reinterpret_cast<PFNEGLCREATESTREAMPRODUCERSURFACEKHRPROC>(eglGetProcAddress(procname: "eglCreateStreamProducerSurfaceKHR"));
57 stream_consumer_output = reinterpret_cast<PFNEGLSTREAMCONSUMEROUTPUTEXTPROC>(eglGetProcAddress(procname: "eglStreamConsumerOutputEXT"));
58 get_output_layers = reinterpret_cast<PFNEGLGETOUTPUTLAYERSEXTPROC>(eglGetProcAddress(procname: "eglGetOutputLayersEXT"));
59 get_output_ports = reinterpret_cast<PFNEGLGETOUTPUTPORTSEXTPROC>(eglGetProcAddress(procname: "eglGetOutputPortsEXT"));
60 output_layer_attrib = reinterpret_cast<PFNEGLOUTPUTLAYERATTRIBEXTPROC>(eglGetProcAddress(procname: "eglOutputLayerAttribEXT"));
61 query_output_layer_attrib = reinterpret_cast<PFNEGLQUERYOUTPUTLAYERATTRIBEXTPROC>(eglGetProcAddress(procname: "eglQueryOutputLayerAttribEXT"));
62 query_output_layer_string = reinterpret_cast<PFNEGLQUERYOUTPUTLAYERSTRINGEXTPROC>(eglGetProcAddress(procname: "eglQueryOutputLayerStringEXT"));
63 query_output_port_attrib = reinterpret_cast<PFNEGLQUERYOUTPUTPORTATTRIBEXTPROC>(eglGetProcAddress(procname: "eglQueryOutputPortAttribEXT"));
64 query_output_port_string = reinterpret_cast<PFNEGLQUERYOUTPUTPORTSTRINGEXTPROC>(eglGetProcAddress(procname: "eglQueryOutputPortStringEXT"));
65 get_stream_file_descriptor = reinterpret_cast<PFNEGLGETSTREAMFILEDESCRIPTORKHRPROC>(eglGetProcAddress(procname: "eglGetStreamFileDescriptorKHR"));
66 create_stream_from_file_descriptor = reinterpret_cast<PFNEGLCREATESTREAMFROMFILEDESCRIPTORKHRPROC>(eglGetProcAddress(procname: "eglCreateStreamFromFileDescriptorKHR"));
67 stream_consumer_gltexture = reinterpret_cast<PFNEGLSTREAMCONSUMERGLTEXTUREEXTERNALKHRPROC>(eglGetProcAddress(procname: "eglStreamConsumerGLTextureExternalKHR"));
68 stream_consumer_acquire = reinterpret_cast<PFNEGLSTREAMCONSUMERACQUIREKHRPROC>(eglGetProcAddress(procname: "eglStreamConsumerAcquireKHR"));
69 stream_consumer_release = reinterpret_cast<PFNEGLSTREAMCONSUMERRELEASEKHRPROC>(eglGetProcAddress(procname: "eglStreamConsumerReleaseKHR"));
70 create_stream_attrib_nv = reinterpret_cast<PFNEGLCREATESTREAMATTRIBNVPROC>(eglGetProcAddress(procname: "eglCreateStreamAttribNV"));
71 set_stream_attrib_nv = reinterpret_cast<PFNEGLSETSTREAMATTRIBNVPROC>(eglGetProcAddress(procname: "eglSetStreamAttribNV"));
72 query_stream_attrib_nv = reinterpret_cast<PFNEGLQUERYSTREAMATTRIBNVPROC>(eglGetProcAddress(procname: "eglQueryStreamAttribNV"));
73 acquire_stream_attrib_nv = reinterpret_cast<PFNEGLSTREAMCONSUMERACQUIREATTRIBNVPROC>(eglGetProcAddress(procname: "eglStreamConsumerAcquireAttribNV"));
74 release_stream_attrib_nv = reinterpret_cast<PFNEGLSTREAMCONSUMERRELEASEATTRIBNVPROC>(eglGetProcAddress(procname: "eglStreamConsumerReleaseAttribNV"));
75
76 has_egl_stream = strstr(haystack: extensions, needle: "EGL_KHR_stream");
77 has_egl_stream_producer_eglsurface = strstr(haystack: extensions, needle: "EGL_KHR_stream_producer_eglsurface");
78 has_egl_stream_consumer_egloutput = strstr(haystack: extensions, needle: "EGL_EXT_stream_consumer_egloutput");
79 has_egl_output_drm = strstr(haystack: extensions, needle: "EGL_EXT_output_drm");
80 has_egl_output_base = strstr(haystack: extensions, needle: "EGL_EXT_output_base");
81 has_egl_stream_cross_process_fd = strstr(haystack: extensions, needle: "EGL_KHR_stream_cross_process_fd");
82 has_egl_stream_consumer_gltexture = strstr(haystack: extensions, needle: "EGL_KHR_stream_consumer_gltexture");
83
84 initialized = true;
85}
86
87QT_END_NAMESPACE
88

source code of qtbase/src/gui/opengl/platform/egl/qeglstreamconvenience.cpp