Commit 556adfa6 authored by Chris Wilson's avatar Chris Wilson 🤔 Committed by Eric Anholt

Fixup glx support

Renaming glamor_priv->dispatch and wrapping the access to
the dispatch table with a function that also ensured the
context was bound.

 dispatch = glamor_get_dispatch(glamor_priv);
 ...
 glamor_put_dispatch(glamor_priv);

So that we catch all places where we attempt to call into GL withouta
context. As an optimisation we can then do glamor_get_context();
glamor_put_context() around the rendering entry points to reduce the
frequency of having to restore the old context. (Along with allowing
the context to be recursively acquired and making the old context part of
the glamor_egl state.)
Reviewed-by: default avatarZhigang Gong <zhigang.gong@linux.intel.com>
Signed-off-by: default avatarZhigang Gong <zhigang.gong@linux.intel.com>
parent 430bc16c
...@@ -196,24 +196,25 @@ glamor_block_handler(ScreenPtr screen) ...@@ -196,24 +196,25 @@ glamor_block_handler(ScreenPtr screen)
{ {
glamor_screen_private *glamor_priv = glamor_screen_private *glamor_priv =
glamor_get_screen_private(screen); glamor_get_screen_private(screen);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch; glamor_gl_dispatch *dispatch;
GLAMOR_DEFINE_CONTEXT;
GLAMOR_SET_CONTEXT(glamor_priv); dispatch = glamor_get_dispatch(glamor_priv);
glamor_priv->tick++; glamor_priv->tick++;
dispatch->glFlush(); dispatch->glFlush();
dispatch->glFinish(); dispatch->glFinish();
glamor_fbo_expire(glamor_priv); glamor_fbo_expire(glamor_priv);
GLAMOR_RESTORE_CONTEXT(glamor_priv); glamor_put_dispatch(glamor_priv);
} }
static void static void
_glamor_block_handler(void *data, OSTimePtr timeout, _glamor_block_handler(void *data, OSTimePtr timeout,
void *last_select_mask) void *last_select_mask)
{ {
glamor_gl_dispatch *dispatch = data; glamor_screen_private *glamor_priv = data;
glamor_gl_dispatch *dispatch = glamor_get_dispatch(glamor_priv);
dispatch->glFlush(); dispatch->glFlush();
dispatch->glFinish(); dispatch->glFinish();
glamor_put_dispatch(glamor_priv);
} }
static void static void
...@@ -289,8 +290,7 @@ glamor_init(ScreenPtr screen, unsigned int flags) ...@@ -289,8 +290,7 @@ glamor_init(ScreenPtr screen, unsigned int flags)
} }
#endif #endif
glamor_gl_dispatch_init(screen, &glamor_priv->dispatch, glamor_gl_dispatch_init(screen, &glamor_priv->_dispatch, gl_version);
gl_version);
#ifdef GLAMOR_GLES2 #ifdef GLAMOR_GLES2
if (!glamor_gl_has_extension("GL_EXT_texture_format_BGRA8888")) { if (!glamor_gl_has_extension("GL_EXT_texture_format_BGRA8888")) {
...@@ -303,8 +303,8 @@ glamor_init(ScreenPtr screen, unsigned int flags) ...@@ -303,8 +303,8 @@ glamor_init(ScreenPtr screen, unsigned int flags)
glamor_gl_has_extension("GL_MESA_pack_invert"); glamor_gl_has_extension("GL_MESA_pack_invert");
glamor_priv->has_fbo_blit = glamor_priv->has_fbo_blit =
glamor_gl_has_extension("GL_EXT_framebuffer_blit"); glamor_gl_has_extension("GL_EXT_framebuffer_blit");
glamor_priv->dispatch.glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, glamor_priv->_dispatch.glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE,
&glamor_priv->max_fbo_size); &glamor_priv->max_fbo_size);
glamor_set_debug_level(&glamor_debug_level); glamor_set_debug_level(&glamor_debug_level);
...@@ -324,8 +324,7 @@ glamor_init(ScreenPtr screen, unsigned int flags) ...@@ -324,8 +324,7 @@ glamor_init(ScreenPtr screen, unsigned int flags)
if (flags & GLAMOR_USE_SCREEN) { if (flags & GLAMOR_USE_SCREEN) {
if (!RegisterBlockAndWakeupHandlers(_glamor_block_handler, if (!RegisterBlockAndWakeupHandlers(_glamor_block_handler,
_glamor_wakeup_handler, _glamor_wakeup_handler,
(void *) glamor_priv)) {
&glamor_priv->dispatch)) {
goto fail; goto fail;
} }
......
...@@ -28,18 +28,16 @@ ...@@ -28,18 +28,16 @@
#ifndef GLAMOR_H #ifndef GLAMOR_H
#define GLAMOR_H #define GLAMOR_H
#include "scrnintstr.h" #include <scrnintstr.h>
#ifdef GLAMOR_FOR_XORG #ifdef GLAMOR_FOR_XORG
#include "xf86str.h" #include <xf86str.h>
#endif #endif
#include "pixmapstr.h" #include <pixmapstr.h>
#include "windowstr.h" #include <windowstr.h>
#include "gcstruct.h" #include <gcstruct.h>
#include "picturestr.h" #include <picturestr.h>
#include "fb.h" #include <fb.h>
#include "fbpict.h" #include <fbpict.h>
#endif /* GLAMOR_H */
/* /*
* glamor_pixmap_type : glamor pixmap's type. * glamor_pixmap_type : glamor pixmap's type.
...@@ -145,9 +143,8 @@ extern _X_EXPORT PixmapPtr glamor_create_pixmap(ScreenPtr screen, int w, int h, ...@@ -145,9 +143,8 @@ extern _X_EXPORT PixmapPtr glamor_create_pixmap(ScreenPtr screen, int w, int h,
extern _X_EXPORT void glamor_egl_screen_init(ScreenPtr screen); extern _X_EXPORT void glamor_egl_screen_init(ScreenPtr screen);
extern _X_EXPORT void * glamor_egl_make_current(ScreenPtr screen); extern _X_EXPORT void glamor_egl_make_current(ScreenPtr screen);
extern _X_EXPORT void glamor_egl_restore_context(ScreenPtr screen);
extern _X_EXPORT void glamor_egl_restore_context(ScreenPtr screen, void *context);
#ifdef GLAMOR_FOR_XORG #ifdef GLAMOR_FOR_XORG
...@@ -320,3 +317,4 @@ extern _X_EXPORT Bool glamor_poly_line_nf(DrawablePtr pDrawable, GCPtr pGC, int ...@@ -320,3 +317,4 @@ extern _X_EXPORT Bool glamor_poly_line_nf(DrawablePtr pDrawable, GCPtr pGC, int
extern _X_EXPORT Bool glamor_poly_lines_nf(DrawablePtr drawable, GCPtr gc, int mode, int n, extern _X_EXPORT Bool glamor_poly_lines_nf(DrawablePtr drawable, GCPtr gc, int mode, int n,
DDXPointPtr points); DDXPointPtr points);
#endif /* GLAMOR_H */
...@@ -26,10 +26,6 @@ ...@@ -26,10 +26,6 @@
* *
*/ */
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include "glamor_priv.h" #include "glamor_priv.h"
static Bool static Bool
......
...@@ -21,10 +21,6 @@ ...@@ -21,10 +21,6 @@
* PERFORMANCE OF THIS SOFTWARE. * PERFORMANCE OF THIS SOFTWARE.
*/ */
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include "glamor_priv.h" #include "glamor_priv.h"
/** @file glamor_copyarea.c /** @file glamor_copyarea.c
...@@ -43,7 +39,7 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src, ...@@ -43,7 +39,7 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
glamor_pixmap_private *src_pixmap_priv; glamor_pixmap_private *src_pixmap_priv;
glamor_screen_private *glamor_priv = glamor_screen_private *glamor_priv =
glamor_get_screen_private(screen); glamor_get_screen_private(screen);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch; glamor_gl_dispatch *dispatch;
int dst_x_off, dst_y_off, src_x_off, src_y_off, i; int dst_x_off, dst_y_off, src_x_off, src_y_off, i;
if (!glamor_priv->has_fbo_blit) { if (!glamor_priv->has_fbo_blit) {
...@@ -78,6 +74,7 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src, ...@@ -78,6 +74,7 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
} }
glamor_validate_pixmap(dst_pixmap); glamor_validate_pixmap(dst_pixmap);
dispatch = glamor_get_dispatch(glamor_priv);
dispatch->glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, dispatch->glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT,
src_pixmap_priv->fbo->fb); src_pixmap_priv->fbo->fb);
glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off, glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off,
...@@ -136,6 +133,7 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src, ...@@ -136,6 +133,7 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
GL_NEAREST); GL_NEAREST);
} }
} }
glamor_put_dispatch(glamor_priv);
return TRUE; return TRUE;
} }
#endif #endif
...@@ -147,7 +145,7 @@ glamor_copy_n_to_n_textured(DrawablePtr src, ...@@ -147,7 +145,7 @@ glamor_copy_n_to_n_textured(DrawablePtr src,
{ {
glamor_screen_private *glamor_priv = glamor_screen_private *glamor_priv =
glamor_get_screen_private(dst->pScreen); glamor_get_screen_private(dst->pScreen);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch; glamor_gl_dispatch *dispatch;
PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src); PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst); PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
int i; int i;
...@@ -158,23 +156,24 @@ glamor_copy_n_to_n_textured(DrawablePtr src, ...@@ -158,23 +156,24 @@ glamor_copy_n_to_n_textured(DrawablePtr src,
enum glamor_pixmap_status src_status = GLAMOR_NONE; enum glamor_pixmap_status src_status = GLAMOR_NONE;
GLfloat dst_xscale, dst_yscale, src_xscale, src_yscale; GLfloat dst_xscale, dst_yscale, src_xscale, src_yscale;
int flush_needed = 0; int flush_needed = 0;
int alu = GXcopy;
src_pixmap_priv = glamor_get_pixmap_private(src_pixmap); src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
dst_pixmap_priv = glamor_get_pixmap_private(dst_pixmap); dst_pixmap_priv = glamor_get_pixmap_private(dst_pixmap);
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dst_pixmap_priv)) { if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dst_pixmap_priv)) {
glamor_delayed_fallback(dst->pScreen, "dst has no fbo.\n"); glamor_delayed_fallback(dst->pScreen, "dst has no fbo.\n");
goto fail; return FALSE;
} }
if (!src_pixmap_priv || !src_pixmap_priv->gl_fbo) { if (!src_pixmap_priv || !src_pixmap_priv->gl_fbo) {
#ifndef GLAMOR_PIXMAP_DYNAMIC_UPLOAD #ifndef GLAMOR_PIXMAP_DYNAMIC_UPLOAD
glamor_delayed_fallback(dst->pScreen, "src has no fbo.\n"); glamor_delayed_fallback(dst->pScreen, "src has no fbo.\n");
goto fail; return FALSE;
#else #else
src_status = glamor_upload_pixmap_to_texture(src_pixmap); src_status = glamor_upload_pixmap_to_texture(src_pixmap);
if (src_status != GLAMOR_UPLOAD_DONE) if (src_status != GLAMOR_UPLOAD_DONE)
goto fail; return FALSE;
src_pixmap_priv = glamor_get_pixmap_private(src_pixmap); src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
#endif #endif
...@@ -182,25 +181,26 @@ glamor_copy_n_to_n_textured(DrawablePtr src, ...@@ -182,25 +181,26 @@ glamor_copy_n_to_n_textured(DrawablePtr src,
flush_needed = 1; flush_needed = 1;
if (gc) { if (gc) {
glamor_set_alu(dispatch, gc->alu);
if (!glamor_set_planemask(dst_pixmap, gc->planemask)) if (!glamor_set_planemask(dst_pixmap, gc->planemask))
goto fail; return FALSE;
if (gc->alu != GXcopy) { alu = gc->alu;
glamor_set_destination_pixmap_priv_nc
(src_pixmap_priv);
glamor_validate_pixmap(src_pixmap);
}
} }
glamor_set_destination_pixmap_priv_nc(dst_pixmap_priv);
glamor_validate_pixmap(dst_pixmap);
pixmap_priv_get_scale(dst_pixmap_priv, &dst_xscale, &dst_yscale); pixmap_priv_get_scale(dst_pixmap_priv, &dst_xscale, &dst_yscale);
pixmap_priv_get_scale(src_pixmap_priv, &src_xscale, &src_yscale); pixmap_priv_get_scale(src_pixmap_priv, &src_xscale, &src_yscale);
glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off, glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off,
&dst_y_off); &dst_y_off);
dispatch = glamor_get_dispatch(glamor_priv);
glamor_set_alu(dispatch, alu);
if (alu != GXcopy) {
glamor_set_destination_pixmap_priv_nc (src_pixmap_priv);
glamor_validate_pixmap(src_pixmap);
}
glamor_set_destination_pixmap_priv_nc(dst_pixmap_priv);
glamor_validate_pixmap(dst_pixmap);
dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
GL_FALSE, 2 * sizeof(float), GL_FALSE, 2 * sizeof(float),
vertices); vertices);
...@@ -284,12 +284,8 @@ glamor_copy_n_to_n_textured(DrawablePtr src, ...@@ -284,12 +284,8 @@ glamor_copy_n_to_n_textured(DrawablePtr src,
/* The source texture is bound to a fbo, we have to flush it here. */ /* The source texture is bound to a fbo, we have to flush it here. */
if (flush_needed) if (flush_needed)
dispatch->glFlush(); dispatch->glFlush();
glamor_put_dispatch(glamor_priv);
return TRUE; return TRUE;
fail:
glamor_set_alu(dispatch, GXcopy);
glamor_set_planemask(dst_pixmap, ~0);
return FALSE;
} }
static Bool static Bool
...@@ -317,7 +313,6 @@ _glamor_copy_n_to_n(DrawablePtr src, ...@@ -317,7 +313,6 @@ _glamor_copy_n_to_n(DrawablePtr src,
int i; int i;
int overlaped = 0; int overlaped = 0;
Bool ret = FALSE; Bool ret = FALSE;
GLAMOR_DEFINE_CONTEXT;
dst_pixmap = glamor_get_drawable_pixmap(dst); dst_pixmap = glamor_get_drawable_pixmap(dst);
dst_pixmap_priv = glamor_get_pixmap_private(dst_pixmap); dst_pixmap_priv = glamor_get_pixmap_private(dst_pixmap);
...@@ -326,7 +321,6 @@ _glamor_copy_n_to_n(DrawablePtr src, ...@@ -326,7 +321,6 @@ _glamor_copy_n_to_n(DrawablePtr src,
screen = dst_pixmap->drawable.pScreen; screen = dst_pixmap->drawable.pScreen;
glamor_priv = glamor_get_screen_private(dst->pScreen); glamor_priv = glamor_get_screen_private(dst->pScreen);
GLAMOR_SET_CONTEXT(glamor_priv);
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dst_pixmap_priv)) { if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dst_pixmap_priv)) {
glamor_fallback("dest pixmap %p has no fbo. \n", glamor_fallback("dest pixmap %p has no fbo. \n",
...@@ -448,7 +442,6 @@ _glamor_copy_n_to_n(DrawablePtr src, ...@@ -448,7 +442,6 @@ _glamor_copy_n_to_n(DrawablePtr src,
glamor_clear_delayed_fallbacks(dst->pScreen); glamor_clear_delayed_fallbacks(dst->pScreen);
if (temp_src != src) if (temp_src != src)
glamor_destroy_pixmap(temp_pixmap); glamor_destroy_pixmap(temp_pixmap);
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return ret; return ret;
} }
......
...@@ -26,10 +26,6 @@ ...@@ -26,10 +26,6 @@
* *
*/ */
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include "glamor_priv.h" #include "glamor_priv.h"
static Bool static Bool
...@@ -37,7 +33,6 @@ _glamor_copy_plane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC, ...@@ -37,7 +33,6 @@ _glamor_copy_plane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
int srcx, int srcy, int w, int h, int dstx, int dsty, int srcx, int srcy, int w, int h, int dstx, int dsty,
unsigned long bitPlane, RegionPtr *pRegion, Bool fallback) unsigned long bitPlane, RegionPtr *pRegion, Bool fallback)
{ {
GLAMOR_DEFINE_CONTEXT;
glamor_screen_private *glamor_priv; glamor_screen_private *glamor_priv;
if (!fallback if (!fallback
...@@ -47,14 +42,12 @@ _glamor_copy_plane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC, ...@@ -47,14 +42,12 @@ _glamor_copy_plane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
goto fail; goto fail;
glamor_priv = glamor_get_screen_private(pDst->pScreen); glamor_priv = glamor_get_screen_private(pDst->pScreen);
GLAMOR_SET_CONTEXT(glamor_priv);
glamor_prepare_access(pDst, GLAMOR_ACCESS_RW); glamor_prepare_access(pDst, GLAMOR_ACCESS_RW);
glamor_prepare_access(pSrc, GLAMOR_ACCESS_RO); glamor_prepare_access(pSrc, GLAMOR_ACCESS_RO);
*pRegion = fbCopyPlane(pSrc, pDst, pGC, srcx, srcy, w, h, *pRegion = fbCopyPlane(pSrc, pDst, pGC, srcx, srcy, w, h,
dstx, dsty, bitPlane); dstx, dsty, bitPlane);
glamor_finish_access(pSrc, GLAMOR_ACCESS_RO); glamor_finish_access(pSrc, GLAMOR_ACCESS_RO);
glamor_finish_access(pDst, GLAMOR_ACCESS_RW); glamor_finish_access(pDst, GLAMOR_ACCESS_RW);
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return TRUE; return TRUE;
fail: fail:
......
...@@ -21,10 +21,6 @@ ...@@ -21,10 +21,6 @@
* PERFORMANCE OF THIS SOFTWARE. * PERFORMANCE OF THIS SOFTWARE.
*/ */
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include "glamor_priv.h" #include "glamor_priv.h"
/** @file glamor_copywindow.c /** @file glamor_copywindow.c
......
...@@ -31,10 +31,6 @@ ...@@ -31,10 +31,6 @@
* This file covers core X rendering in glamor. * This file covers core X rendering in glamor.
*/ */
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include "glamor_priv.h" #include "glamor_priv.h"
...@@ -174,7 +170,7 @@ glamor_init_finish_access_shaders(ScreenPtr screen) ...@@ -174,7 +170,7 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
GLint sampler_uniform_location; GLint sampler_uniform_location;
glamor_priv = glamor_get_screen_private(screen); glamor_priv = glamor_get_screen_private(screen);
dispatch = &glamor_priv->dispatch; dispatch = glamor_get_dispatch(glamor_priv);
glamor_priv->finish_access_prog[0] = dispatch->glCreateProgram(); glamor_priv->finish_access_prog[0] = dispatch->glCreateProgram();
glamor_priv->finish_access_prog[1] = dispatch->glCreateProgram(); glamor_priv->finish_access_prog[1] = dispatch->glCreateProgram();
...@@ -248,7 +244,7 @@ glamor_init_finish_access_shaders(ScreenPtr screen) ...@@ -248,7 +244,7 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
dispatch->glUniform1i(sampler_uniform_location, 0); dispatch->glUniform1i(sampler_uniform_location, 0);
dispatch->glUniform1i(glamor_priv->finish_access_swap_rb[1], 0); dispatch->glUniform1i(glamor_priv->finish_access_swap_rb[1], 0);
dispatch->glUseProgram(0); dispatch->glUseProgram(0);
glamor_put_dispatch(glamor_priv);
} }
void void
...@@ -258,9 +254,10 @@ glamor_fini_finish_access_shaders(ScreenPtr screen) ...@@ -258,9 +254,10 @@ glamor_fini_finish_access_shaders(ScreenPtr screen)
glamor_gl_dispatch *dispatch; glamor_gl_dispatch *dispatch;
glamor_priv = glamor_get_screen_private(screen); glamor_priv = glamor_get_screen_private(screen);
dispatch = &glamor_priv->dispatch; dispatch = glamor_get_dispatch(glamor_priv);
dispatch->glDeleteProgram(glamor_priv->finish_access_prog[0]); dispatch->glDeleteProgram(glamor_priv->finish_access_prog[0]);
dispatch->glDeleteProgram(glamor_priv->finish_access_prog[1]); dispatch->glDeleteProgram(glamor_priv->finish_access_prog[1]);
glamor_put_dispatch(glamor_priv);
} }
void void
...@@ -271,7 +268,6 @@ glamor_finish_access(DrawablePtr drawable, glamor_access_t access_mode) ...@@ -271,7 +268,6 @@ glamor_finish_access(DrawablePtr drawable, glamor_access_t access_mode)
glamor_get_pixmap_private(pixmap); glamor_get_pixmap_private(pixmap);
glamor_screen_private *glamor_priv = glamor_screen_private *glamor_priv =
glamor_get_screen_private(drawable->pScreen); glamor_get_screen_private(drawable->pScreen);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO_DOWNLOADED(pixmap_priv)) if (!GLAMOR_PIXMAP_PRIV_HAS_FBO_DOWNLOADED(pixmap_priv))
return; return;
...@@ -281,11 +277,17 @@ glamor_finish_access(DrawablePtr drawable, glamor_access_t access_mode) ...@@ -281,11 +277,17 @@ glamor_finish_access(DrawablePtr drawable, glamor_access_t access_mode)
} }
if (pixmap_priv->fbo->pbo != 0 && pixmap_priv->fbo->pbo_valid) { if (pixmap_priv->fbo->pbo != 0 && pixmap_priv->fbo->pbo_valid) {
glamor_gl_dispatch *dispatch;
assert(glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP); assert(glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP);
dispatch = glamor_get_dispatch(glamor_priv);
dispatch->glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); dispatch->glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
dispatch->glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); dispatch->glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
pixmap_priv->fbo->pbo_valid = FALSE;
dispatch->glDeleteBuffers(1, &pixmap_priv->fbo->pbo); dispatch->glDeleteBuffers(1, &pixmap_priv->fbo->pbo);
glamor_put_dispatch(glamor_priv);
pixmap_priv->fbo->pbo_valid = FALSE;
pixmap_priv->fbo->pbo = 0; pixmap_priv->fbo->pbo = 0;
} else { } else {
free(pixmap->devPrivate.ptr); free(pixmap->devPrivate.ptr);
......
...@@ -31,11 +31,8 @@ ...@@ -31,11 +31,8 @@
#include "config.h" #include "config.h"
#endif #endif
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#define GLAMOR_FOR_XORG #define GLAMOR_FOR_XORG
#include "xorg-server.h" #include <xorg-server.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
...@@ -93,7 +90,8 @@ struct glamor_egl_screen_private { ...@@ -93,7 +90,8 @@ struct glamor_egl_screen_private {
struct gbm_device *gbm; struct gbm_device *gbm;
#endif #endif
int has_gem; int has_gem;
void *gl_context; void *gl_context, *old_context;
int gl_context_depth;
PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr; PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr;
PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image_khr; PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image_khr;
...@@ -112,13 +110,18 @@ glamor_egl_get_screen_private(ScrnInfoPtr scrn) ...@@ -112,13 +110,18 @@ glamor_egl_get_screen_private(ScrnInfoPtr scrn)
scrn->privates[xf86GlamorEGLPrivateIndex].ptr; scrn->privates[xf86GlamorEGLPrivateIndex].ptr;
} }
#ifdef GLX_USE_SHARED_DISPATCH #ifdef GLX_USE_SHARED_DISPATCH
_X_EXPORT void * _X_EXPORT void
glamor_egl_make_current(ScreenPtr screen) glamor_egl_make_current(ScreenPtr screen)
{ {
ScrnInfoPtr scrn = xf86Screens[screen->myNum]; ScrnInfoPtr scrn = xf86Screens[screen->myNum];
struct glamor_egl_screen_private *glamor_egl = struct glamor_egl_screen_private *glamor_egl =
glamor_egl_get_screen_private(scrn); glamor_egl_get_screen_private(scrn);
if (glamor_egl->gl_context_depth++)
return;
GET_CURRENT_CONTEXT(current); GET_CURRENT_CONTEXT(current);
glamor_egl->old_context = current;
if (glamor_egl->gl_context != current) { if (glamor_egl->gl_context != current) {
eglMakeCurrent(glamor_egl->display, EGL_NO_SURFACE, eglMakeCurrent(glamor_egl->display, EGL_NO_SURFACE,
...@@ -126,24 +129,28 @@ glamor_egl_make_current(ScreenPtr screen) ...@@ -126,24 +129,28 @@ glamor_egl_make_current(ScreenPtr screen)
if (!eglMakeCurrent(glamor_egl->display, if (!eglMakeCurrent(glamor_egl->display,
EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_SURFACE,
glamor_egl->context)) { glamor_egl->context)) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR, FatalError("Failed to make EGL context current\n");
"Failed to make EGL context current\n");
return NULL;
} }
return current;
} }
return NULL;
} }
_X_EXPORT void _X_EXPORT void
glamor_egl_restore_context(ScreenPtr screen, void *context) glamor_egl_restore_context(ScreenPtr screen)
{ {
if (context) ScrnInfoPtr scrn = xf86Screens[screen->myNum];
SET_CURRENT_CONTEXT(context); struct glamor_egl_screen_private *glamor_egl =
glamor_egl_get_screen_private(scrn);
if (--glamor_egl->gl_context_depth)
return;
if (glamor_egl->old_context &&
glamor_egl->gl_context != glamor_egl->old_context)
SET_CURRENT_CONTEXT(glamor_egl->old_context);
} }
#else #else
#define glamor_egl_make_current(x) NULL #define glamor_egl_make_current(x)
#define glamor_egl_restore_context(s, c) #define glamor_egl_restore_context(s)
#endif #endif
static EGLImageKHR static EGLImageKHR
...@@ -252,12 +259,11 @@ glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride) ...@@ -252,12 +259,11 @@ glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride)
EGLImageKHR image; EGLImageKHR image;
GLuint texture; GLuint texture;
int name; int name;
void *prev_context;
Bool ret = FALSE; Bool ret = FALSE;
glamor_egl = glamor_egl_get_screen_private(scrn); glamor_egl = glamor_egl_get_screen_private(scrn);
prev_context = glamor_egl_make_current(screen); glamor_egl_make_current(screen);
if (glamor_egl->has_gem) { if (glamor_egl->has_gem) {
if (!glamor_get_flink_name(glamor_egl->fd, handle, &name)) { if (!glamor_get_flink_name(glamor_egl->fd, handle, &name)) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR, xf86DrvMsg(scrn->scrnIndex, X_ERROR,
...@@ -285,8 +291,7 @@ glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride) ...@@ -285,8 +291,7 @@ glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride)
ret = TRUE; ret = TRUE;
done: done:
if (prev_context) glamor_egl_restore_context(screen);
glamor_egl_restore_context(screen, prev_context);
return ret; return ret;
} }
...@@ -497,6 +502,13 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd) ...@@ -497,6 +502,13 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)
#endif #endif
glamor_egl->saved_free_screen = scrn->FreeScreen; glamor_egl->saved_free_screen = scrn->FreeScreen;
scrn->FreeScreen = glamor_egl_free_screen;