-
Notifications
You must be signed in to change notification settings - Fork 1
/
0034-egl-query-the-supported-ES2-context-version.patch
201 lines (181 loc) · 7.43 KB
/
0034-egl-query-the-supported-ES2-context-version.patch
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
From 54f3460420a85d6fdcccab9ca05a49881e926064 Mon Sep 17 00:00:00 2001
From: Brendan King <[email protected]>
Date: Mon, 10 Feb 2020 09:23:03 +0000
Subject: [PATCH] egl: query the supported ES2 context version
For OpenGL ES contexts, the EGL specification states that querying
EGL_CONTEXT_CLIENT_VERSION with eglQueryContext may return a version
that differs from that specified at context creation time. For example,
if an OpenGL ES2 context is specified at context creation time, an
OpenGL ES3 context may be created, and so "3" should be returned
when EGL_CONTEXT_CLIENT_VERSION is queried.
A new EGL driver API function has been added,
QueryContextClientVersion, that is called when the context client
version is queried, allowing EGL drivers to override the default
value (i.e. the version specified at context creation time). If the
function returns zero, the default is used.
For DRI drivers, QueryContextClientVersion returns zero for all API
contexts other than OpenGL ES2. For OpenGL ES2, the supported context
client version is queried via the Query Renderer driver extension, using
integer query __DRI2_RENDERER_OPENGL_ES2_CONTEXT_CLIENT_VERSION_IMG. If
the query isn't supported, or the query returns zero, zero is returned
to the caller.
IMG NOTE: In order to avoid potential name and value clashes, "_IMG"
has been added to the end of the new query name, this should be removed
if an attempt is made to push this patch upstream. The value of the new
query should be adjusted to be the next one in sequence, rather than the
large value it currently has.
---
include/GL/internal/dri_interface.h | 2 ++
src/egl/drivers/dri2/egl_dri2.c | 21 +++++++++++++++++++++
src/egl/drivers/haiku/egl_haiku.cpp | 9 +++++++++
src/egl/main/eglapi.c | 2 +-
src/egl/main/eglcontext.c | 16 ++++++++++++++--
src/egl/main/eglcontext.h | 3 ++-
src/egl/main/egldriver.h | 1 +
7 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index 80acaf3..acd58cc 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1958,6 +1958,8 @@ typedef struct __DRIDriverVtableExtensionRec {
#define __DRI2_RENDERER_PREFER_BACK_BUFFER_REUSE 0x000f
#define __DRI2_RENDERER_HAS_NO_ERROR_CONTEXT 0x0010
+#define __DRI2_RENDERER_OPENGL_ES2_CONTEXT_CLIENT_VERSION_IMG 0x7001
+
typedef struct __DRI2rendererQueryExtensionRec __DRI2rendererQueryExtension;
struct __DRI2rendererQueryExtensionRec {
__DRIextension base;
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index b25c023..3ae5cdd 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2006,6 +2006,26 @@ dri2_make_current(_EGLDisplay *disp, _EGLSurface *dsurf,
return EGL_TRUE;
}
+static EGLint
+dri2_query_context_client_version(_EGLDisplay *disp, _EGLContext *ctx)
+{
+ struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+ switch (dri2_ctx->base.ClientAPI) {
+ case EGL_OPENGL_ES_API:
+ switch (dri2_ctx->base.ClientMajorVersion) {
+ case 2:
+ return dri2_renderer_query_integer(dri2_dpy,
+ __DRI2_RENDERER_OPENGL_ES2_CONTEXT_CLIENT_VERSION_IMG);
+ default:
+ return 0;
+ }
+ default:
+ return 0;
+ }
+}
+
__DRIdrawable *
dri2_surface_get_dri_drawable(_EGLSurface *surf)
{
@@ -3885,6 +3905,7 @@ const _EGLDriver _eglDriver = {
.CreateContext = dri2_create_context,
.DestroyContext = dri2_destroy_context,
.MakeCurrent = dri2_make_current,
+ .QueryContextClientVersion = dri2_query_context_client_version,
.CreateWindowSurface = dri2_create_window_surface,
.CreatePixmapSurface = dri2_create_pixmap_surface,
.CreatePbufferSurface = dri2_create_pbuffer_surface,
diff --git a/src/egl/drivers/haiku/egl_haiku.cpp b/src/egl/drivers/haiku/egl_haiku.cpp
index 18c73c9..2690a82 100644
--- a/src/egl/drivers/haiku/egl_haiku.cpp
+++ b/src/egl/drivers/haiku/egl_haiku.cpp
@@ -297,6 +297,14 @@ haiku_make_current(_EGLDisplay *disp, _EGLSurface *dsurf,
}
+extern "C"
+EGLint
+haiku_dri2_query_context_client_version(_EGLDisplay *disp, _EGLContext *ctx)
+{
+ // Tell caller to use the default value.
+ return 0;
+}
+
extern "C"
EGLBoolean
haiku_swap_buffers(_EGLDisplay *disp, _EGLSurface *surf)
@@ -316,6 +324,7 @@ const _EGLDriver _eglDriver = {
.CreateContext = haiku_create_context,
.DestroyContext = haiku_destroy_context,
.MakeCurrent = haiku_make_current,
+ .QueryContextClientVersion = haiku_dri2_query_context_client_version,
.CreateWindowSurface = haiku_create_window_surface,
.CreatePixmapSurface = haiku_create_pixmap_surface,
.CreatePbufferSurface = haiku_create_pbuffer_surface,
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index d9fbb7a..69ac50f 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -941,7 +941,7 @@ eglQueryContext(EGLDisplay dpy, EGLContext ctx,
_EGL_CHECK_CONTEXT(disp, context, EGL_FALSE);
- ret = _eglQueryContext(context, attribute, value);
+ ret = _eglQueryContext(disp, context, attribute, value);
RETURN_EGL_EVAL(disp, ret);
}
diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c
index 15de7c9..7274d24 100644
--- a/src/egl/main/eglcontext.c
+++ b/src/egl/main/eglcontext.c
@@ -35,6 +35,7 @@
#include "eglcontext.h"
#include "egldisplay.h"
#include "eglcurrent.h"
+#include "egldriver.h"
#include "eglsurface.h"
#include "egllog.h"
#include "util/macros.h"
@@ -670,8 +671,19 @@ _eglQueryContextRenderBuffer(_EGLContext *ctx)
}
+static EGLint
+_eglQueryContextClientVersion(_EGLDisplay *disp, _EGLContext *ctx)
+{
+ EGLint version;
+
+ version = disp->Driver->QueryContextClientVersion(disp, ctx);
+
+ return (version) ? version : ctx->ClientMajorVersion;
+}
+
EGLBoolean
-_eglQueryContext(_EGLContext *c, EGLint attribute, EGLint *value)
+_eglQueryContext(_EGLDisplay *disp, _EGLContext *c,
+ EGLint attribute, EGLint *value)
{
if (!value)
return _eglError(EGL_BAD_PARAMETER, "eglQueryContext");
@@ -688,7 +700,7 @@ _eglQueryContext(_EGLContext *c, EGLint attribute, EGLint *value)
*value = c->Config ? c->Config->ConfigID : 0;
break;
case EGL_CONTEXT_CLIENT_VERSION:
- *value = c->ClientMajorVersion;
+ *value = _eglQueryContextClientVersion(disp, c);
break;
case EGL_CONTEXT_CLIENT_TYPE:
*value = c->ClientAPI;
diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h
index 06029e8..d890217 100644
--- a/src/egl/main/eglcontext.h
+++ b/src/egl/main/eglcontext.h
@@ -74,7 +74,8 @@ _eglInitContext(_EGLContext *ctx, _EGLDisplay *disp,
extern EGLBoolean
-_eglQueryContext(_EGLContext *ctx, EGLint attribute, EGLint *value);
+_eglQueryContext(_EGLDisplay *disp, _EGLContext *ctx,
+ EGLint attribute, EGLint *value);
extern EGLBoolean
diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h
index 12f9a0a..92af8bd 100644
--- a/src/egl/main/egldriver.h
+++ b/src/egl/main/egldriver.h
@@ -97,6 +97,7 @@ struct _egl_driver
EGLBoolean (*MakeCurrent)(_EGLDisplay *disp,
_EGLSurface *draw, _EGLSurface *read,
_EGLContext *ctx);
+ EGLint (*QueryContextClientVersion)(_EGLDisplay *disp, _EGLContext *ctx);
/* surface funcs */
_EGLSurface *(*CreateWindowSurface)(_EGLDisplay *disp, _EGLConfig *config,