0006-Add-EGL_IMG_cl_image-extension.patch 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. From 6d9dc4ffa940f9bde48fc68c85b54ab1b839ea49 Mon Sep 17 00:00:00 2001
  2. From: Brendan King <Brendan.King@imgtec.com>
  3. Date: Tue, 11 Mar 2014 11:50:53 +0000
  4. Subject: [PATCH] Add EGL_IMG_cl_image extension
  5. Add support for the experimental EGL_IMG_cl_image extension to EGL, and
  6. the DRI2 EGL driver.
  7. ---
  8. include/EGL/eglmesaext.h | 5 +++
  9. include/GL/internal/dri_interface.h | 13 +++++++
  10. src/egl/drivers/dri2/egl_dri2.c | 60 +++++++++++++++++++++++++----
  11. src/egl/main/eglapi.c | 1 +
  12. src/egl/main/egldisplay.h | 2 +
  13. 5 files changed, 73 insertions(+), 8 deletions(-)
  14. diff --git a/include/EGL/eglmesaext.h b/include/EGL/eglmesaext.h
  15. index f0395a8..5d11f3e 100644
  16. --- a/include/EGL/eglmesaext.h
  17. +++ b/include/EGL/eglmesaext.h
  18. @@ -49,6 +49,11 @@ typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGIONNOK) (EGLDisplay dpy, EG
  19. #define EGL_DRM_BUFFER_FORMAT_RGB565_MESA 0x3292
  20. #endif /* EGL_MESA_drm_image_formats */
  21. +#ifndef EGL_IMG_cl_image
  22. +#define EGL_IMG_cl_image 1
  23. +#define EGL_CL_IMAGE_IMG 0x6010
  24. +#endif /* Experimental eglCreateImageKHR target */
  25. +
  26. #ifdef __cplusplus
  27. }
  28. #endif
  29. diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
  30. index 5102894..b197092 100644
  31. --- a/include/GL/internal/dri_interface.h
  32. +++ b/include/GL/internal/dri_interface.h
  33. @@ -1831,6 +1831,19 @@ struct __DRIimageExtensionRec {
  34. const unsigned int modifier_count,
  35. unsigned int use,
  36. void *loaderPrivate);
  37. +
  38. + /**
  39. + * Support for experimental EGL_CL_IMAGE_IMG.
  40. + * Like createImageFromTexture, but from a buffer, the contents
  41. + * of which depend on the target.
  42. + *
  43. + * \since 8
  44. + */
  45. + __DRIimage *(*createImageFromBuffer)(__DRIcontext *context,
  46. + int target,
  47. + void *buffer,
  48. + unsigned *error,
  49. + void *loaderPrivate);
  50. };
  51. diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
  52. index eee28eb..dea5899 100644
  53. --- a/src/egl/drivers/dri2/egl_dri2.c
  54. +++ b/src/egl/drivers/dri2/egl_dri2.c
  55. @@ -995,6 +995,10 @@ dri2_setup_screen(_EGLDisplay *disp)
  56. disp->Extensions.EXT_image_dma_buf_import_modifiers = EGL_TRUE;
  57. }
  58. #endif
  59. + if (dri2_dpy->image->base.version >= 8 &&
  60. + dri2_dpy->image->createImageFromBuffer) {
  61. + disp->Extensions.IMG_cl_image = EGL_TRUE;
  62. + }
  63. }
  64. if (dri2_dpy->flush_control)
  65. @@ -2360,17 +2364,13 @@ dri2_get_sync_values_chromium(_EGLDisplay *disp, _EGLSurface *surf,
  66. return dri2_dpy->vtbl->get_sync_values(disp, surf, ust, msc, sbc);
  67. }
  68. -/**
  69. - * Set the error code after a call to
  70. - * dri2_egl_image::dri_image::createImageFromTexture.
  71. - */
  72. static void
  73. -dri2_create_image_khr_texture_error(int dri_error)
  74. +dri2_create_image_khr_error(int dri_error)
  75. {
  76. EGLint egl_error = egl_error_from_dri_image_error(dri_error);
  77. if (egl_error != EGL_SUCCESS)
  78. - _eglError(egl_error, "dri2_create_image_khr_texture");
  79. + _eglError(egl_error, "dri2_create_image_khr");
  80. }
  81. static _EGLImage *
  82. @@ -2449,7 +2449,49 @@ dri2_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx,
  83. attrs.GLTextureLevel,
  84. &error,
  85. NULL);
  86. - dri2_create_image_khr_texture_error(error);
  87. + dri2_create_image_khr_error(error);
  88. +
  89. + if (!dri2_img->dri_image) {
  90. + free(dri2_img);
  91. + return EGL_NO_IMAGE_KHR;
  92. + }
  93. + return &dri2_img->base;
  94. +}
  95. +
  96. +static _EGLImage *
  97. +dri2_create_image_img_buffer(_EGLDisplay *disp, _EGLContext *ctx,
  98. + EGLenum target,
  99. + EGLClientBuffer buffer,
  100. + const EGLint *attr_list)
  101. +{
  102. + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
  103. + struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
  104. + struct dri2_egl_image *dri2_img;
  105. + unsigned error;
  106. +
  107. + switch (target) {
  108. + case EGL_CL_IMAGE_IMG:
  109. + break;
  110. + default:
  111. + _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr");
  112. + return EGL_NO_IMAGE_KHR;
  113. + }
  114. +
  115. + dri2_img = malloc(sizeof *dri2_img);
  116. + if (!dri2_img) {
  117. + _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr");
  118. + return EGL_NO_IMAGE_KHR;
  119. + }
  120. +
  121. + _eglInitImage(&dri2_img->base, disp);
  122. +
  123. + dri2_img->dri_image =
  124. + dri2_dpy->image->createImageFromBuffer(dri2_ctx->dri_context,
  125. + target,
  126. + buffer,
  127. + &error,
  128. + NULL);
  129. + dri2_create_image_khr_error(error);
  130. if (!dri2_img->dri_image) {
  131. free(dri2_img);
  132. @@ -2916,7 +2958,7 @@ dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext *ctx,
  133. &error,
  134. NULL);
  135. }
  136. - dri2_create_image_khr_texture_error(error);
  137. + dri2_create_image_khr_error(error);
  138. if (!dri_image)
  139. return EGL_NO_IMAGE_KHR;
  140. @@ -3152,6 +3194,8 @@ dri2_create_image_khr(_EGLDisplay *disp, _EGLContext *ctx, EGLenum target,
  141. case EGL_WAYLAND_BUFFER_WL:
  142. return dri2_create_image_wayland_wl_buffer(disp, ctx, buffer, attr_list);
  143. #endif
  144. + case EGL_CL_IMAGE_IMG:
  145. + return dri2_create_image_img_buffer(disp, ctx, target, buffer, attr_list);
  146. default:
  147. _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr");
  148. return EGL_NO_IMAGE_KHR;
  149. diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
  150. index 17e36af..6ffcff8 100644
  151. --- a/src/egl/main/eglapi.c
  152. +++ b/src/egl/main/eglapi.c
  153. @@ -549,6 +549,7 @@ _eglCreateExtensionsString(_EGLDisplay *disp)
  154. _EGL_CHECK_EXTENSION(WL_bind_wayland_display);
  155. _EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
  156. + _EGL_CHECK_EXTENSION(IMG_cl_image);
  157. #undef _EGL_CHECK_EXTENSION
  158. }
  159. diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
  160. index 4d2afbc..5b05dcc 100644
  161. --- a/src/egl/main/egldisplay.h
  162. +++ b/src/egl/main/egldisplay.h
  163. @@ -150,6 +150,8 @@ struct _egl_extensions
  164. EGLBoolean WL_bind_wayland_display;
  165. EGLBoolean WL_create_wayland_buffer_from_image;
  166. +
  167. + EGLBoolean IMG_cl_image;
  168. };
  169. struct _egl_display