egl: store the native surface pointer in struct _egl_surface
authorPaulo Zanoni <paulo.r.zanoni@intel.com>
Wed, 1 May 2019 22:42:26 +0000 (15:42 -0700)
committerEric Engestrom <eric@engestrom.ch>
Tue, 14 May 2019 12:41:14 +0000 (12:41 +0000)
Each platform stores this in a different place:
  - platform_drm uses dri2_surf->gbm_surf->base
  - platform_android uses dri2_surf->window
  - platform_wayland uses dri2_surf->wl_win
  - platform_x11 uses dri2_surf->drawable
  - platform_x11_dri3 uses dri3_surf->loader_drawable.drawable
  - haiku doesn't even store it!

We need access to the native surface since the specification asks us
to refuse creating a new surface if there's already an EGLSurface
associated with native_surface.

An alternative to this patch would be to create a new
API.GetNativeWindow callback that each platform would have to
implement. While that's something we can definitely do, I prefer
this approach.

Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
src/egl/drivers/dri2/egl_dri2.c
src/egl/drivers/dri2/egl_dri2.h
src/egl/drivers/dri2/platform_android.c
src/egl/drivers/dri2/platform_drm.c
src/egl/drivers/dri2/platform_surfaceless.c
src/egl/drivers/dri2/platform_wayland.c
src/egl/drivers/dri2/platform_x11.c
src/egl/drivers/dri2/platform_x11_dri3.c
src/egl/drivers/haiku/egl_haiku.cpp
src/egl/main/eglsurface.c
src/egl/main/eglsurface.h

index d584bccdebe72c033edd86038247464aa0f56592..09d6315b19e5a6a07953cdce4e04042abe433f80 100644 (file)
@@ -1354,7 +1354,8 @@ dri2_destroy_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx)
 
 EGLBoolean
 dri2_init_surface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
-        _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean enable_out_fence)
+        _EGLConfig *conf, const EGLint *attrib_list,
+        EGLBoolean enable_out_fence, void *native_surface)
 {
    struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
@@ -1368,7 +1369,7 @@ dri2_init_surface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
       dri2_surf->enable_out_fence = enable_out_fence;
    }
 
-   return _eglInitSurface(surf, disp, type, conf, attrib_list);
+   return _eglInitSurface(surf, disp, type, conf, attrib_list, native_surface);
 }
 
 static void
index aa143deb86792cfcc24e46280d7a2bac03d79b2c..4918517b572fb151f5a21109ecc27ddf5ccba235 100644 (file)
@@ -535,7 +535,8 @@ dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf);
 
 EGLBoolean
 dri2_init_surface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
-        _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean enable_out_fence);
+        _EGLConfig *conf, const EGLint *attrib_list,
+        EGLBoolean enable_out_fence, void *native_surface);
 
 void
 dri2_fini_surface(_EGLSurface *surf);
index e9ea9e6002bef62f7cb51be68bf5d92828398fb1..fece214d9393ae3a6383b6d797009d34263cdbc5 100644 (file)
@@ -354,7 +354,8 @@ droid_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
       return NULL;
    }
 
-   if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list, true))
+   if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list,
+                          true, native_window))
       goto cleanup_surface;
 
    if (type == EGL_WINDOW_BIT) {
index c1ab1c9b0f6ec1331073aa7d25b41f6e60831ed1..7d916fe92b7ed30d24ef9a01a5bfbf7ad48d2fe2 100644 (file)
@@ -149,7 +149,7 @@ dri2_drm_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
    }
 
    if (!dri2_init_surface(&dri2_surf->base, disp, EGL_WINDOW_BIT, conf,
-                          attrib_list, false))
+                          attrib_list, false, native_surface))
       goto cleanup_surf;
 
    config = dri2_get_dri_config(dri2_conf, EGL_WINDOW_BIT,
index fefb2b449d05f97c59f23378117233755270a048..27b1d44ebec3aaeed807ab4a0496b2f058371524 100644 (file)
@@ -124,7 +124,8 @@ dri2_surfaceless_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
       return NULL;
    }
 
-   if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list, false))
+   if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list,
+                          false, NULL))
       goto cleanup_surface;
 
    config = dri2_get_dri_config(dri2_conf, type,
index 2a2c8214169bb2164c5112a3aeb9bd2956ec4253..bf4f2530feb7df09bb3533576b91d74a8bc0eae7 100644 (file)
@@ -287,7 +287,7 @@ dri2_wl_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
    }
 
    if (!dri2_init_surface(&dri2_surf->base, disp, EGL_WINDOW_BIT, conf,
-                          attrib_list, false))
+                          attrib_list, false, native_window))
       goto cleanup_surf;
 
    config = dri2_get_dri_config(dri2_conf, EGL_WINDOW_BIT,
index c8c676d2f00161d25050c263b65560e27d44ed72..1d5efc0126d1f8a290f4e8709148655ca177a92a 100644 (file)
@@ -267,7 +267,8 @@ dri2_x11_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
       return NULL;
    }
    
-   if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list, false))
+   if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list,
+                          false, native_surface))
       goto cleanup_surf;
 
    dri2_surf->region = XCB_NONE;
index 189212745cedfccb885e6453b04f54cff808568e..adcc884c5c2af48ba299953e5ada6bc09d2e4fa9 100644 (file)
@@ -155,7 +155,8 @@ dri3_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
       return NULL;
    }
 
-   if (!dri2_init_surface(&dri3_surf->surf.base, disp, type, conf, attrib_list, false))
+   if (!dri2_init_surface(&dri3_surf->surf.base, disp, type, conf,
+                          attrib_list, false, native_surface))
       goto cleanup_surf;
 
    if (type == EGL_PBUFFER_BIT) {
index 517c264088a370acf179b09641cb5c46ece7397c..6edd551b53d27b7f4939594ba1d48ff82c017378 100644 (file)
@@ -89,7 +89,7 @@ haiku_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
        }
 
        if (!_eglInitSurface(&surface->surf, disp, EGL_WINDOW_BIT,
-               conf, attrib_list)) {
+               conf, attrib_list, native_window)) {
                free(surface);
                return NULL;
        }
index 7d96514f77553e145e72ec873d8dcd0bbce7b595..22257391d5c3810871b6ea85b89ed49210eebfd3 100644 (file)
@@ -334,7 +334,8 @@ _eglParseSurfaceAttribList(_EGLSurface *surf, const EGLint *attrib_list)
  */
 EGLBoolean
 _eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
-                _EGLConfig *conf, const EGLint *attrib_list)
+                _EGLConfig *conf, const EGLint *attrib_list,
+                void *native_surface)
 {
    const char *func;
    EGLint renderBuffer = EGL_BACK_BUFFER;
@@ -421,6 +422,8 @@ _eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
       surf->Height = MIN2(surf->Height, _EGL_MAX_PBUFFER_HEIGHT);
    }
 
+   surf->NativeSurface = native_surface;
+
    return EGL_TRUE;
 }
 
index df8e2e6bdfb80f4f478996a79aae9618f92f28ec..903957a6eb307c0cc9661f753674131b74fdaf33 100644 (file)
@@ -170,12 +170,15 @@ struct _egl_surface
    EGLBoolean PostSubBufferSupportedNV;
 
    struct _egl_hdr_metadata HdrMetadata;
+
+   void *NativeSurface;
 };
 
 
 extern EGLBoolean
 _eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
-                _EGLConfig *config, const EGLint *attrib_list);
+                _EGLConfig *config, const EGLint *attrib_list,
+                void *native_surface);
 
 
 extern EGLBoolean