0043-egl-query-the-supported-ES2-context-version.patch 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. From 1ae221afb2c03d2b3cd0a607dc6646f33c07341c Mon Sep 17 00:00:00 2001
  2. From: Brendan King <Brendan.King@imgtec.com>
  3. Date: Mon, 10 Feb 2020 09:23:03 +0000
  4. Subject: [PATCH] egl: query the supported ES2 context version
  5. For OpenGL ES contexts, the EGL specification states that querying
  6. EGL_CONTEXT_CLIENT_VERSION with eglQueryContext may return a version
  7. that differs from that specified at context creation time. For example,
  8. if an OpenGL ES2 context is specified at context creation time, an
  9. OpenGL ES3 context may be created, and so "3" should be returned
  10. when EGL_CONTEXT_CLIENT_VERSION is queried.
  11. A new EGL driver API function has been added,
  12. QueryContextClientVersion, that is called when the context client
  13. version is queried, allowing EGL drivers to override the default
  14. value (i.e. the version specified at context creation time). If the
  15. function returns zero, the default is used.
  16. For DRI drivers, QueryContextClientVersion returns zero for all API
  17. contexts other than OpenGL ES2. For OpenGL ES2, the supported context
  18. client version is queried via the Query Renderer driver extension, using
  19. integer query __DRI2_RENDERER_OPENGL_ES2_CONTEXT_CLIENT_VERSION_IMG. If
  20. the query isn't supported, or the query returns zero, zero is returned
  21. to the caller.
  22. IMG NOTE: In order to avoid potential name and value clashes, "_IMG"
  23. has been added to the end of the new query name, this should be removed
  24. if an attempt is made to push this patch upstream. The value of the new
  25. query should be adjusted to be the next one in sequence, rather than the
  26. large value it currently has.
  27. ---
  28. include/GL/internal/dri_interface.h | 2 ++
  29. src/egl/drivers/dri2/egl_dri2.c | 21 +++++++++++++++++++++
  30. src/egl/drivers/haiku/egl_haiku.cpp | 9 +++++++++
  31. src/egl/main/eglapi.c | 2 +-
  32. src/egl/main/eglcontext.c | 16 ++++++++++++++--
  33. src/egl/main/eglcontext.h | 3 ++-
  34. src/egl/main/egldriver.h | 1 +
  35. 7 files changed, 50 insertions(+), 4 deletions(-)
  36. diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
  37. index 6490f6e..9c7bcac 100644
  38. --- a/include/GL/internal/dri_interface.h
  39. +++ b/include/GL/internal/dri_interface.h
  40. @@ -2052,6 +2052,8 @@ typedef struct __DRIDriverVtableExtensionRec {
  41. #define __DRI2_RENDERER_HAS_PROTECTED_CONTENT 0x000e
  42. +#define __DRI2_RENDERER_OPENGL_ES2_CONTEXT_CLIENT_VERSION_IMG 0x7001
  43. +
  44. typedef struct __DRI2rendererQueryExtensionRec __DRI2rendererQueryExtension;
  45. struct __DRI2rendererQueryExtensionRec {
  46. __DRIextension base;
  47. diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
  48. index 6b26ff9..c4a49ca 100644
  49. --- a/src/egl/drivers/dri2/egl_dri2.c
  50. +++ b/src/egl/drivers/dri2/egl_dri2.c
  51. @@ -2055,6 +2055,26 @@ dri2_make_current(_EGLDisplay *disp, _EGLSurface *dsurf,
  52. return EGL_TRUE;
  53. }
  54. +static EGLint
  55. +dri2_query_context_client_version(_EGLDisplay *disp, _EGLContext *ctx)
  56. +{
  57. + struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
  58. + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
  59. +
  60. + switch (dri2_ctx->base.ClientAPI) {
  61. + case EGL_OPENGL_ES_API:
  62. + switch (dri2_ctx->base.ClientMajorVersion) {
  63. + case 2:
  64. + return dri2_renderer_query_integer(dri2_dpy,
  65. + __DRI2_RENDERER_OPENGL_ES2_CONTEXT_CLIENT_VERSION_IMG);
  66. + default:
  67. + return 0;
  68. + }
  69. + default:
  70. + return 0;
  71. + }
  72. +}
  73. +
  74. __DRIdrawable *
  75. dri2_surface_get_dri_drawable(_EGLSurface *surf)
  76. {
  77. @@ -4336,6 +4356,7 @@ const _EGLDriver _eglDriver = {
  78. .CreateContext = dri2_create_context,
  79. .DestroyContext = dri2_destroy_context,
  80. .MakeCurrent = dri2_make_current,
  81. + .QueryContextClientVersion = dri2_query_context_client_version,
  82. .CreateWindowSurface = dri2_create_window_surface,
  83. .CreatePixmapSurface = dri2_create_pixmap_surface,
  84. .CreatePbufferSurface = dri2_create_pbuffer_surface,
  85. diff --git a/src/egl/drivers/haiku/egl_haiku.cpp b/src/egl/drivers/haiku/egl_haiku.cpp
  86. index 18c73c9..2690a82 100644
  87. --- a/src/egl/drivers/haiku/egl_haiku.cpp
  88. +++ b/src/egl/drivers/haiku/egl_haiku.cpp
  89. @@ -297,6 +297,14 @@ haiku_make_current(_EGLDisplay *disp, _EGLSurface *dsurf,
  90. }
  91. +extern "C"
  92. +EGLint
  93. +haiku_dri2_query_context_client_version(_EGLDisplay *disp, _EGLContext *ctx)
  94. +{
  95. + // Tell caller to use the default value.
  96. + return 0;
  97. +}
  98. +
  99. extern "C"
  100. EGLBoolean
  101. haiku_swap_buffers(_EGLDisplay *disp, _EGLSurface *surf)
  102. @@ -316,6 +324,7 @@ const _EGLDriver _eglDriver = {
  103. .CreateContext = haiku_create_context,
  104. .DestroyContext = haiku_destroy_context,
  105. .MakeCurrent = haiku_make_current,
  106. + .QueryContextClientVersion = haiku_dri2_query_context_client_version,
  107. .CreateWindowSurface = haiku_create_window_surface,
  108. .CreatePixmapSurface = haiku_create_pixmap_surface,
  109. .CreatePbufferSurface = haiku_create_pbuffer_surface,
  110. diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
  111. index 2d3931d..1cbff96 100644
  112. --- a/src/egl/main/eglapi.c
  113. +++ b/src/egl/main/eglapi.c
  114. @@ -948,7 +948,7 @@ eglQueryContext(EGLDisplay dpy, EGLContext ctx,
  115. _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE);
  116. - ret = _eglQueryContext(context, attribute, value);
  117. + ret = _eglQueryContext(disp, context, attribute, value);
  118. RETURN_EGL_EVAL(disp, ret);
  119. }
  120. diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c
  121. index 15de7c9..7274d24 100644
  122. --- a/src/egl/main/eglcontext.c
  123. +++ b/src/egl/main/eglcontext.c
  124. @@ -35,6 +35,7 @@
  125. #include "eglcontext.h"
  126. #include "egldisplay.h"
  127. #include "eglcurrent.h"
  128. +#include "egldriver.h"
  129. #include "eglsurface.h"
  130. #include "egllog.h"
  131. #include "util/macros.h"
  132. @@ -670,8 +671,19 @@ _eglQueryContextRenderBuffer(_EGLContext *ctx)
  133. }
  134. +static EGLint
  135. +_eglQueryContextClientVersion(_EGLDisplay *disp, _EGLContext *ctx)
  136. +{
  137. + EGLint version;
  138. +
  139. + version = disp->Driver->QueryContextClientVersion(disp, ctx);
  140. +
  141. + return (version) ? version : ctx->ClientMajorVersion;
  142. +}
  143. +
  144. EGLBoolean
  145. -_eglQueryContext(_EGLContext *c, EGLint attribute, EGLint *value)
  146. +_eglQueryContext(_EGLDisplay *disp, _EGLContext *c,
  147. + EGLint attribute, EGLint *value)
  148. {
  149. if (!value)
  150. return _eglError(EGL_BAD_PARAMETER, "eglQueryContext");
  151. @@ -688,7 +700,7 @@ _eglQueryContext(_EGLContext *c, EGLint attribute, EGLint *value)
  152. *value = c->Config ? c->Config->ConfigID : 0;
  153. break;
  154. case EGL_CONTEXT_CLIENT_VERSION:
  155. - *value = c->ClientMajorVersion;
  156. + *value = _eglQueryContextClientVersion(disp, c);
  157. break;
  158. case EGL_CONTEXT_CLIENT_TYPE:
  159. *value = c->ClientAPI;
  160. diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h
  161. index 06029e8..d890217 100644
  162. --- a/src/egl/main/eglcontext.h
  163. +++ b/src/egl/main/eglcontext.h
  164. @@ -74,7 +74,8 @@ _eglInitContext(_EGLContext *ctx, _EGLDisplay *disp,
  165. extern EGLBoolean
  166. -_eglQueryContext(_EGLContext *ctx, EGLint attribute, EGLint *value);
  167. +_eglQueryContext(_EGLDisplay *disp, _EGLContext *ctx,
  168. + EGLint attribute, EGLint *value);
  169. extern EGLBoolean
  170. diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h
  171. index 12f9a0a..92af8bd 100644
  172. --- a/src/egl/main/egldriver.h
  173. +++ b/src/egl/main/egldriver.h
  174. @@ -97,6 +97,7 @@ struct _egl_driver
  175. EGLBoolean (*MakeCurrent)(_EGLDisplay *disp,
  176. _EGLSurface *draw, _EGLSurface *read,
  177. _EGLContext *ctx);
  178. + EGLint (*QueryContextClientVersion)(_EGLDisplay *disp, _EGLContext *ctx);
  179. /* surface funcs */
  180. _EGLSurface *(*CreateWindowSurface)(_EGLDisplay *disp, _EGLConfig *config,