diff options
Diffstat (limited to 'xorg-server/glamor/glamor_egl.c')
-rw-r--r-- | xorg-server/glamor/glamor_egl.c | 89 |
1 files changed, 43 insertions, 46 deletions
diff --git a/xorg-server/glamor/glamor_egl.c b/xorg-server/glamor/glamor_egl.c index 182e2e8c9..113450c8d 100644 --- a/xorg-server/glamor/glamor_egl.c +++ b/xorg-server/glamor/glamor_egl.c @@ -69,8 +69,6 @@ struct glamor_egl_screen_private { CreateScreenResourcesProcPtr CreateScreenResources; CloseScreenProcPtr CloseScreen; int fd; - EGLImageKHR front_image; - PixmapPtr *back_pixmap; int cpp; #ifdef GLAMOR_HAS_GBM struct gbm_device *gbm; @@ -176,6 +174,18 @@ glamor_create_texture_from_image(ScreenPtr screen, return TRUE; } +void * +glamor_egl_get_gbm_device(ScreenPtr screen) +{ +#ifdef GLAMOR_HAS_GBM + struct glamor_egl_screen_private *glamor_egl = + glamor_egl_get_screen_private(xf86ScreenToScrn(screen)); + return glamor_egl->gbm; +#else + return NULL; +#endif +} + unsigned int glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h) { @@ -220,13 +230,9 @@ Bool glamor_egl_create_textured_screen(ScreenPtr screen, int handle, int stride) { ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - struct glamor_pixmap_private *pixmap_priv; - struct glamor_egl_screen_private *glamor_egl; PixmapPtr screen_pixmap; - glamor_egl = glamor_egl_get_screen_private(scrn); screen_pixmap = screen->GetScreenPixmap(screen); - pixmap_priv = glamor_get_pixmap_private(screen_pixmap); if (!glamor_egl_create_textured_pixmap(screen_pixmap, handle, stride)) { xf86DrvMsg(scrn->scrnIndex, X_ERROR, @@ -234,8 +240,7 @@ glamor_egl_create_textured_screen(ScreenPtr screen, int handle, int stride) return FALSE; } - glamor_egl->front_image = pixmap_priv->base.image; - glamor_set_screen_pixmap(screen_pixmap, glamor_egl->back_pixmap); + glamor_set_screen_pixmap(screen_pixmap, NULL); return TRUE; } @@ -244,15 +249,7 @@ glamor_egl_create_textured_screen_ext(ScreenPtr screen, int handle, int stride, PixmapPtr *back_pixmap) { - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - struct glamor_egl_screen_private *glamor_egl; - - glamor_egl = glamor_egl_get_screen_private(scrn); - - glamor_egl->back_pixmap = back_pixmap; - if (!glamor_egl_create_textured_screen(screen, handle, stride)) - return FALSE; - return TRUE; + return glamor_egl_create_textured_screen(screen, handle, stride); } static Bool @@ -268,6 +265,24 @@ glamor_egl_check_has_gem(int fd) return FALSE; } +static void +glamor_egl_set_pixmap_image(PixmapPtr pixmap, EGLImageKHR image) +{ + struct glamor_pixmap_private *pixmap_priv = + glamor_get_pixmap_private(pixmap); + EGLImageKHR old; + + old = pixmap_priv->base.image; + if (old) { + ScreenPtr screen = pixmap->drawable.pScreen; + ScrnInfoPtr scrn = xf86ScreenToScrn(screen); + struct glamor_egl_screen_private *glamor_egl = glamor_egl_get_screen_private(scrn); + + eglDestroyImageKHR(glamor_egl->display, old); + } + pixmap_priv->base.image = image; +} + Bool glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride) { @@ -275,8 +290,6 @@ glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride) ScrnInfoPtr scrn = xf86ScreenToScrn(screen); struct glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); - struct glamor_pixmap_private *pixmap_priv = - glamor_get_pixmap_private(pixmap); struct glamor_egl_screen_private *glamor_egl; EGLImageKHR image; GLuint texture; @@ -311,7 +324,7 @@ glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride) glamor_create_texture_from_image(screen, image, &texture); glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM); glamor_set_pixmap_texture(pixmap, texture); - pixmap_priv->base.image = image; + glamor_egl_set_pixmap_image(pixmap, image); ret = TRUE; done: @@ -325,8 +338,6 @@ glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap, void *bo) ScrnInfoPtr scrn = xf86ScreenToScrn(screen); struct glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); - struct glamor_pixmap_private *pixmap_priv = - glamor_get_pixmap_private(pixmap); struct glamor_egl_screen_private *glamor_egl; EGLImageKHR image; GLuint texture; @@ -346,7 +357,7 @@ glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap, void *bo) glamor_create_texture_from_image(screen, image, &texture); glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM); glamor_set_pixmap_texture(pixmap, texture); - pixmap_priv->base.image = image; + glamor_egl_set_pixmap_image(pixmap, image); ret = TRUE; done: @@ -419,8 +430,8 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen, if (image == EGL_NO_IMAGE_KHR) goto failure; - pixmap_priv->base.image = image; glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM); + glamor_egl_set_pixmap_image(pixmap, image); } bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_EGL_IMAGE, image, 0); @@ -519,16 +530,17 @@ glamor_pixmap_from_fd(ScreenPtr screen, #endif } -static void -_glamor_egl_destroy_pixmap_image(PixmapPtr pixmap) +void +glamor_egl_destroy_pixmap_image(PixmapPtr pixmap) { - ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen); - struct glamor_egl_screen_private *glamor_egl = - glamor_egl_get_screen_private(scrn); struct glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap); - if (pixmap_priv->base.image) { + if (pixmap_priv && pixmap_priv->base.image) { + ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen); + struct glamor_egl_screen_private *glamor_egl = + glamor_egl_get_screen_private(scrn); + /* Before destroy an image which was attached to * a texture. we must call glFlush to make sure the * operation on that texture has been done.*/ @@ -541,9 +553,6 @@ _glamor_egl_destroy_pixmap_image(PixmapPtr pixmap) _X_EXPORT void glamor_egl_exchange_buffers(PixmapPtr front, PixmapPtr back) { - ScrnInfoPtr scrn = xf86ScreenToScrn(front->drawable.pScreen); - struct glamor_egl_screen_private *glamor_egl = - glamor_egl_get_screen_private(scrn); EGLImageKHR temp; struct glamor_pixmap_private *front_priv = glamor_get_pixmap_private(front); @@ -558,15 +567,12 @@ glamor_egl_exchange_buffers(PixmapPtr front, PixmapPtr back) glamor_set_pixmap_type(front, GLAMOR_TEXTURE_DRM); glamor_set_pixmap_type(back, GLAMOR_TEXTURE_DRM); - glamor_egl->front_image = front_priv->base.image; } void glamor_egl_destroy_textured_pixmap(PixmapPtr pixmap) { - if (pixmap->refcnt == 1) - _glamor_egl_destroy_pixmap_image(pixmap); glamor_destroy_textured_pixmap(pixmap); } @@ -583,17 +589,8 @@ glamor_egl_close_screen(ScreenPtr screen) screen_pixmap = screen->GetScreenPixmap(screen); pixmap_priv = glamor_get_pixmap_private(screen_pixmap); - eglDestroyImageKHR(glamor_egl->display, glamor_egl->front_image); + eglDestroyImageKHR(glamor_egl->display, pixmap_priv->base.image); pixmap_priv->base.image = NULL; - glamor_egl->front_image = NULL; - - if (glamor_egl->back_pixmap && *glamor_egl->back_pixmap) { - pixmap_priv = glamor_get_pixmap_private(*glamor_egl->back_pixmap); - if (pixmap_priv->base.image) { - eglDestroyImageKHR(glamor_egl->display, pixmap_priv->base.image); - pixmap_priv->base.image = NULL; - } - } screen->CloseScreen = glamor_egl->saved_close_screen; |