summarylogtreecommitdiffstats
path: root/0001-gl-renderer-Add-EGLDevice-enumeration-support.patch
blob: 5f6a4b9bb88a53d645cb454e295a33baf549c983 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
From 78f72e9eb8e42b2791099c519cf8c47e89c4143f Mon Sep 17 00:00:00 2001
From: "Miguel A. Vico" <mvicomoya@nvidia.com>
Date: Mon, 2 May 2016 15:56:37 +0200
Subject: [PATCH 1/6] gl-renderer: Add EGLDevice enumeration support
X-NVConfidentiality: public

EGLDevice provides means to enumerate native devices.

In preparation for follow-on changes to support frame presentation
through EGLDevice+EGLOutput, this change adds both
gl_renderer_get_devices() and gl_renderer_get_drm_device_file()
functions which will help to enumerate EGLDevices and match them to DRM
devices.

Signed-off-by: Miguel A Vico Moya <mvicomoya@nvidia.com>
Reviewed-by: Andy Ritger <aritger@nvidia.com>
Reviewed-by: Adam Cheney <acheney@nvidia.com>
Reviewed-by: James Jones <jajones@nvidia.com>
---
 libweston/renderer-gl/gl-renderer.c | 89 ++++++++++++++++++++++++++++-
 libweston/renderer-gl/gl-renderer.h |  8 +++
 2 files changed, 96 insertions(+), 1 deletion(-)

diff --git a/libweston/renderer-gl/gl-renderer.c b/libweston/renderer-gl/gl-renderer.c
index 54f8b1cd..a6be2b7b 100644
--- a/libweston/renderer-gl/gl-renderer.c
+++ b/libweston/renderer-gl/gl-renderer.c
@@ -4084,6 +4084,90 @@ gl_renderer_setup(struct weston_compositor *ec, EGLSurface egl_surface)
 	return 0;
 }
 
+static int
+gl_renderer_get_devices(EGLint max_devices, EGLDeviceEXT *devices,
+			EGLint *num_devices)
+{
+	const char *extensions;
+	PFNEGLQUERYDEVICESEXTPROC query_devices;
+
+	extensions = (const char *)eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+	if (!extensions) {
+		weston_log("Retrieving EGL extension string failed.\n");
+		return -1;
+	}
+
+	if (!weston_check_egl_extension(extensions, "EGL_EXT_device_base") &&
+	    (!weston_check_egl_extension(extensions, "EGL_EXT_device_query") ||
+	     !weston_check_egl_extension(extensions, "EGL_EXT_device_enumeration"))) {
+		weston_log("EGL_EXT_device_base not supported\n");
+		return -1;
+	}
+
+	query_devices = (void *) eglGetProcAddress("eglQueryDevicesEXT");
+	if (!query_devices) {
+		weston_log("Failed to get eglQueryDevicesEXT function\n");
+		return -1;
+	}
+
+	if (query_devices(max_devices, devices, num_devices) != EGL_TRUE) {
+		weston_log("Failed to query EGL Devices\n");
+		gl_renderer_print_egl_error_state();
+		return -1;
+	}
+
+	return 0;
+}
+
+static int
+gl_renderer_get_drm_device_file(EGLDeviceEXT device,
+				const char **drm_device_file)
+{
+	const char *exts;
+	PFNEGLQUERYDEVICESTRINGEXTPROC query_device_string;
+
+	exts = (const char *)eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+	if (!exts) {
+		weston_log("Retrieving EGL extension string failed.\n");
+		return -1;
+	}
+
+	if (!weston_check_egl_extension(exts, "EGL_EXT_device_base") &&
+	    (!weston_check_egl_extension(exts, "EGL_EXT_device_query") ||
+	     !weston_check_egl_extension(exts, "EGL_EXT_device_enumeration"))) {
+		weston_log("EGL_EXT_device_base not supported.\n");
+		return -1;
+	}
+
+	query_device_string =
+		(void *) eglGetProcAddress("eglQueryDeviceStringEXT");
+	if (!query_device_string) {
+		weston_log("Failed to get eglQueryDeviceStringEXT function\n");
+		return -1;
+	}
+
+	exts = query_device_string(device, EGL_EXTENSIONS);
+	if (!exts) {
+		weston_log("Retrieving EGL extension string failed.\n");
+		return -1;
+	}
+
+	if (!weston_check_egl_extension(exts, "EGL_EXT_device_drm")) {
+		weston_log("EGL_EXT_device_drm not supported.\n");
+		return -1;
+	}
+
+	(*drm_device_file) = query_device_string(device,
+						 EGL_DRM_DEVICE_FILE_EXT);
+	if (*drm_device_file == NULL) {
+		weston_log("Failed to query DRM device name.\n");
+		gl_renderer_print_egl_error_state();
+		return -1;
+	}
+
+	return 0;
+}
+
 WL_EXPORT struct gl_renderer_interface gl_renderer_interface = {
 	.opaque_attribs = gl_renderer_opaque_attribs,
 	.alpha_attribs = gl_renderer_alpha_attribs,
@@ -4095,5 +4179,8 @@ WL_EXPORT struct gl_renderer_interface gl_renderer_interface = {
 	.output_surface = gl_renderer_output_surface,
 	.output_set_border = gl_renderer_output_set_border,
 	.create_fence_fd = gl_renderer_create_fence_fd,
-	.print_egl_error_state = gl_renderer_print_egl_error_state
+	.print_egl_error_state = gl_renderer_print_egl_error_state,
+
+	.get_devices = gl_renderer_get_devices,
+	.get_drm_device_file = gl_renderer_get_drm_device_file
 };
diff --git a/libweston/renderer-gl/gl-renderer.h b/libweston/renderer-gl/gl-renderer.h
index b1d6abbe..cd330932 100644
--- a/libweston/renderer-gl/gl-renderer.h
+++ b/libweston/renderer-gl/gl-renderer.h
@@ -40,6 +40,7 @@
 
 typedef int EGLint;
 typedef int EGLenum;
+typedef void *EGLDeviceEXT;
 typedef void *EGLDisplay;
 typedef void *EGLSurface;
 typedef void *EGLConfig;
@@ -123,5 +124,12 @@ struct gl_renderer_interface {
 	int (*create_fence_fd)(struct weston_output *output);
 
 	void (*print_egl_error_state)(void);
+
+	int (*get_devices)(EGLint max_devices,
+			   EGLDeviceEXT *devices,
+			   EGLint *num_devices);
+
+	int (*get_drm_device_file)(EGLDeviceEXT device,
+				   const char **drm_device_file);
 };
 
-- 
2.21.0