GLX: Enable glx support.

If we are using MESA as our GL library, then both xserver's
GLX and glamor are link to the same library. As xserver's
GLX has its own _glapi_get/set_context/dispatch etc, and it
is a simplified version derived from mesa thus is not
sufficient for mesa/egl's dri loader which is used by glamor.

Then if glx module is loaded before glamoregl module, the
initialization of mesa/egl/opengl will not be correct, and
will fail at a very early stage, most likely fail to map
the element buffer.

Two methodis to fix this problem, first is to modify the xserver's
glx's glapi.c to fit mesa's requirement. The second is to put
a glamor.conf as below, to the system's xorg.conf path.

Section "Module"
        Load  "glamoregl"
EndSection

Then glamor will be loaded firstly, and the mesa's libglapi.so
will be used. As current xserver's dispatch table is the same
as mesa's, then the glx's dri loader can work without problem.

We took the second method as it don't need any change to xorg.:)
Although this is not a graceful implementation as it depends
on the xserver's dispatch table and the mesa's dispatch table
is the same and the context set and get is using the same method.
Anyway it works.

As by default, xserver will enable GLX_USE_TLS. But mesa will not
enable it, you may need to enable that when build mesa.

Three pre-requirements to make this glamor version work:

0. Make sure xserver has commit 66e603, if not please pull the latest
   master branch.
1. Rebuild mesa by enable GLX_USE_TLS.
2. Put the glamor.conf to your system's xorg.conf path and make sure
   it loaded prior to glx module.

Preliminary testing shows indirect glxgears works fine.

If user want to use GLES2 for glamor by using MESA, GLX will not
work correctly.

If you are not using normal MESA, for example PVR's private GLES
implementation, then it should be ok to use GLES2 glamor and the
GLX should work as expected. In this commit, I use gbm to check
whether we are using MESA or non-mesa. Maybe not the best way.

Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
This commit is contained in:
Zhigang Gong 2012-02-10 16:04:07 +08:00 committed by Eric Anholt
parent 0a8fb8563f
commit 430bc16ca0
20 changed files with 391 additions and 51 deletions

View File

@ -53,9 +53,9 @@ if EGL
LIBGLAMOREGL = libglamoregl.la LIBGLAMOREGL = libglamoregl.la
module_LTLIBRARIES = $(LIBGLAMOREGL) module_LTLIBRARIES = $(LIBGLAMOREGL)
libglamoregl_la_DEPENDENCIES = libglamor.la libglamoregl_la_DEPENDENCIES = libglamor.la
libglamoregl_la_LDFLAGS = -avoid-version -module $(EGL_LIBS) -lglamor libglamoregl_la_LDFLAGS = -avoid-version -module $(EGL_LIBS) -lglamor $(GLX_SYS_LIBS)
libglamoregl_la_SOURCES = glamor_eglmodule.c $(top_srcdir)/src/glamor_egl.c libglamoregl_la_SOURCES = glamor_eglmodule.c $(top_srcdir)/src/glamor_egl.c
libglamoregl_la_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/src $(LIBDRM_CFLAGS) $(EGL_CFLAGS) libglamoregl_la_CFLAGS = $(AM_CFLAGS) $(GLX_DEFINES) -I$(top_srcdir)/src $(LIBDRM_CFLAGS) $(EGL_CFLAGS)
endif endif

View File

@ -83,11 +83,9 @@ glamor_set_pixmap_texture(PixmapPtr pixmap, unsigned int tex)
ScreenPtr screen = pixmap->drawable.pScreen; ScreenPtr screen = pixmap->drawable.pScreen;
glamor_pixmap_private *pixmap_priv; glamor_pixmap_private *pixmap_priv;
glamor_screen_private *glamor_priv; glamor_screen_private *glamor_priv;
glamor_gl_dispatch *dispatch;
glamor_pixmap_fbo *fbo; glamor_pixmap_fbo *fbo;
glamor_priv = glamor_get_screen_private(screen); glamor_priv = glamor_get_screen_private(screen);
dispatch = &glamor_priv->dispatch;
pixmap_priv = glamor_get_pixmap_private(pixmap); pixmap_priv = glamor_get_pixmap_private(pixmap);
if (pixmap_priv->fbo) { if (pixmap_priv->fbo) {
@ -130,7 +128,6 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
glamor_pixmap_private *pixmap_priv; glamor_pixmap_private *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_pixmap_fbo *fbo; glamor_pixmap_fbo *fbo;
int pitch; int pitch;
int flag; int flag;
@ -149,7 +146,6 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
fbDestroyPixmap(pixmap); fbDestroyPixmap(pixmap);
return fbCreatePixmap(screen, w, h, depth, usage); return fbCreatePixmap(screen, w, h, depth, usage);
} }
glamor_set_pixmap_private(pixmap, pixmap_priv); glamor_set_pixmap_private(pixmap, pixmap_priv);
pixmap_priv->container = pixmap; pixmap_priv->container = pixmap;
@ -201,11 +197,14 @@ 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_priv->dispatch;
GLAMOR_DEFINE_CONTEXT;
GLAMOR_SET_CONTEXT(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);
} }
static void static void
@ -392,6 +391,7 @@ glamor_init(ScreenPtr screen, unsigned int flags)
glamor_pixmap_init(screen); glamor_pixmap_init(screen);
glamor_priv->flags = flags; glamor_priv->flags = flags;
glamor_priv->screen = screen;
return TRUE; return TRUE;

View File

@ -145,6 +145,10 @@ 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_restore_context(ScreenPtr screen, void *context);
#ifdef GLAMOR_FOR_XORG #ifdef GLAMOR_FOR_XORG
#define GLAMOR_EGL_MODULE_NAME "glamoregl" #define GLAMOR_EGL_MODULE_NAME "glamoregl"

View File

@ -308,6 +308,7 @@ _glamor_copy_n_to_n(DrawablePtr src,
PixmapPtr dst_pixmap, src_pixmap, temp_pixmap = NULL; PixmapPtr dst_pixmap, src_pixmap, temp_pixmap = NULL;
DrawablePtr temp_src = src; DrawablePtr temp_src = src;
glamor_pixmap_private *dst_pixmap_priv, *src_pixmap_priv; glamor_pixmap_private *dst_pixmap_priv, *src_pixmap_priv;
glamor_screen_private *glamor_priv;
BoxRec bound; BoxRec bound;
ScreenPtr screen; ScreenPtr screen;
int temp_dx = dx; int temp_dx = dx;
@ -315,7 +316,8 @@ _glamor_copy_n_to_n(DrawablePtr src,
int src_x_off, src_y_off, dst_x_off, dst_y_off; int src_x_off, src_y_off, dst_x_off, dst_y_off;
int i; int i;
int overlaped = 0; int overlaped = 0;
Bool ret = TRUE; 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);
@ -323,6 +325,9 @@ _glamor_copy_n_to_n(DrawablePtr src,
src_pixmap_priv = glamor_get_pixmap_private(src_pixmap); src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
screen = dst_pixmap->drawable.pScreen; screen = dst_pixmap->drawable.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",
dst_pixmap); dst_pixmap);
@ -356,6 +361,7 @@ _glamor_copy_n_to_n(DrawablePtr src,
|| !src_pixmap_priv->gl_tex || !dst_pixmap_priv->gl_tex) || !src_pixmap_priv->gl_tex || !dst_pixmap_priv->gl_tex)
&& glamor_copy_n_to_n_fbo_blit(src, dst, gc, box, nbox, dx, && glamor_copy_n_to_n_fbo_blit(src, dst, gc, box, nbox, dx,
dy)) { dy)) {
ret = TRUE;
goto done; goto done;
} }
#endif #endif
@ -400,6 +406,7 @@ _glamor_copy_n_to_n(DrawablePtr src,
if (glamor_copy_n_to_n_textured if (glamor_copy_n_to_n_textured
(temp_src, dst, gc, box, nbox, temp_dx, temp_dy)) { (temp_src, dst, gc, box, nbox, temp_dx, temp_dy)) {
ret = TRUE;
goto done; goto done;
} }
@ -408,10 +415,8 @@ _glamor_copy_n_to_n(DrawablePtr src,
if (!fallback if (!fallback
&& glamor_ddx_fallback_check_pixmap(src) && glamor_ddx_fallback_check_pixmap(src)
&& glamor_ddx_fallback_check_pixmap(dst)) { && glamor_ddx_fallback_check_pixmap(dst))
ret = FALSE;
goto done; goto done;
}
glamor_report_delayed_fallbacks(src->pScreen); glamor_report_delayed_fallbacks(src->pScreen);
glamor_report_delayed_fallbacks(dst->pScreen); glamor_report_delayed_fallbacks(dst->pScreen);
@ -436,12 +441,14 @@ _glamor_copy_n_to_n(DrawablePtr src,
} }
glamor_finish_access(dst, GLAMOR_ACCESS_RW); glamor_finish_access(dst, GLAMOR_ACCESS_RW);
} }
ret = TRUE;
done: done:
glamor_clear_delayed_fallbacks(src->pScreen); glamor_clear_delayed_fallbacks(src->pScreen);
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;
} }

View File

@ -37,17 +37,24 @@ _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;
if (!fallback if (!fallback
&& glamor_ddx_fallback_check_gc(pGC) && glamor_ddx_fallback_check_gc(pGC)
&& glamor_ddx_fallback_check_pixmap(pSrc) && glamor_ddx_fallback_check_pixmap(pSrc)
&& glamor_ddx_fallback_check_pixmap(pDst)) && glamor_ddx_fallback_check_pixmap(pDst))
goto fail; goto fail;
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:

View File

@ -63,6 +63,9 @@
#include "glamor.h" #include "glamor.h"
#include "glamor_gl_dispatch.h" #include "glamor_gl_dispatch.h"
#ifdef GLX_USE_SHARED_DISPATCH
#include "glapi.h"
#endif
static const char glamor_name[] = "glamor"; static const char glamor_name[] = "glamor";
@ -90,6 +93,7 @@ struct glamor_egl_screen_private {
struct gbm_device *gbm; struct gbm_device *gbm;
#endif #endif
int has_gem; int has_gem;
void *gl_context;
PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr; PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr;
PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image_khr; PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image_khr;
@ -101,13 +105,46 @@ struct glamor_egl_screen_private {
int xf86GlamorEGLPrivateIndex = -1; int xf86GlamorEGLPrivateIndex = -1;
static struct glamor_egl_screen_private static struct glamor_egl_screen_private *
*
glamor_egl_get_screen_private(ScrnInfoPtr scrn) glamor_egl_get_screen_private(ScrnInfoPtr scrn)
{ {
return (struct glamor_egl_screen_private *) return (struct glamor_egl_screen_private *)
scrn->privates[xf86GlamorEGLPrivateIndex].ptr; scrn->privates[xf86GlamorEGLPrivateIndex].ptr;
} }
#ifdef GLX_USE_SHARED_DISPATCH
_X_EXPORT void *
glamor_egl_make_current(ScreenPtr screen)
{
ScrnInfoPtr scrn = xf86Screens[screen->myNum];
struct glamor_egl_screen_private *glamor_egl =
glamor_egl_get_screen_private(scrn);
GET_CURRENT_CONTEXT(current);
if (glamor_egl->gl_context != current) {
eglMakeCurrent(glamor_egl->display, EGL_NO_SURFACE,
EGL_NO_SURFACE, EGL_NO_CONTEXT);
if (!eglMakeCurrent(glamor_egl->display,
EGL_NO_SURFACE, EGL_NO_SURFACE,
glamor_egl->context)) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"Failed to make EGL context current\n");
return NULL;
}
return current;
}
return NULL;
}
_X_EXPORT void
glamor_egl_restore_context(ScreenPtr screen, void *context)
{
if (context)
SET_CURRENT_CONTEXT(context);
}
#else
#define glamor_egl_make_current(x) NULL
#define glamor_egl_restore_context(s, c)
#endif
static EGLImageKHR static EGLImageKHR
_glamor_egl_create_image(struct glamor_egl_screen_private *glamor_egl, _glamor_egl_create_image(struct glamor_egl_screen_private *glamor_egl,
@ -215,9 +252,12 @@ 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;
glamor_egl = glamor_egl_get_screen_private(scrn); glamor_egl = glamor_egl_get_screen_private(scrn);
prev_context = 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,
@ -235,15 +275,19 @@ glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride)
name, name,
pixmap->drawable.depth); pixmap->drawable.depth);
if (image == EGL_NO_IMAGE_KHR) if (image == EGL_NO_IMAGE_KHR)
return FALSE; goto done;
glamor_create_texture_from_image(glamor_egl, image, &texture); glamor_create_texture_from_image(glamor_egl, image, &texture);
glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM); glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);
glamor_set_pixmap_texture(pixmap, texture); glamor_set_pixmap_texture(pixmap, texture);
dixSetPrivate(&pixmap->devPrivates, glamor_egl_pixmap_private_key, dixSetPrivate(&pixmap->devPrivates, glamor_egl_pixmap_private_key,
image); image);
ret = TRUE;
return TRUE; done:
if (prev_context)
glamor_egl_restore_context(screen, prev_context);
return ret;
} }
static void static void
@ -447,7 +491,10 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)
"Failed to make EGL context current\n"); "Failed to make EGL context current\n");
return FALSE; return FALSE;
} }
#ifdef GLX_USE_SHARED_DISPATCH
GET_CURRENT_CONTEXT(current);
glamor_egl->gl_context = current;
#endif
glamor_egl->saved_free_screen = scrn->FreeScreen; glamor_egl->saved_free_screen = scrn->FreeScreen;
scrn->FreeScreen = glamor_egl_free_screen; scrn->FreeScreen = glamor_egl_free_screen;
return TRUE; return TRUE;

View File

@ -126,6 +126,9 @@ glamor_pixmap_fbo_cache_get(glamor_screen_private *glamor_priv,
void void
glamor_purge_fbo(glamor_pixmap_fbo *fbo) glamor_purge_fbo(glamor_pixmap_fbo *fbo)
{ {
GLAMOR_DEFINE_CONTEXT;
GLAMOR_SET_CONTEXT(fbo->glamor_priv);
glamor_gl_dispatch *dispatch = &fbo->glamor_priv->dispatch; glamor_gl_dispatch *dispatch = &fbo->glamor_priv->dispatch;
if (fbo->fb) if (fbo->fb)
dispatch->glDeleteFramebuffers(1, &fbo->fb); dispatch->glDeleteFramebuffers(1, &fbo->fb);
@ -133,6 +136,7 @@ glamor_purge_fbo(glamor_pixmap_fbo *fbo)
dispatch->glDeleteTextures(1, &fbo->tex); dispatch->glDeleteTextures(1, &fbo->tex);
if (fbo->pbo) if (fbo->pbo)
dispatch->glDeleteBuffers(1, &fbo->pbo); dispatch->glDeleteBuffers(1, &fbo->pbo);
GLAMOR_RESTORE_CONTEXT(fbo->glamor_priv);
free(fbo); free(fbo);
} }
@ -166,7 +170,6 @@ glamor_pixmap_fbo *
glamor_create_fbo_from_tex(glamor_screen_private *glamor_priv, glamor_create_fbo_from_tex(glamor_screen_private *glamor_priv,
int w, int h, int depth, GLint tex, int flag) int w, int h, int depth, GLint tex, int flag)
{ {
glamor_gl_dispatch *dispatch;
glamor_pixmap_fbo *fbo; glamor_pixmap_fbo *fbo;
GLenum format; GLenum format;
@ -276,8 +279,6 @@ glamor_fini_pixmap_fbo(ScreenPtr screen)
void void
glamor_destroy_fbo(glamor_pixmap_fbo *fbo) glamor_destroy_fbo(glamor_pixmap_fbo *fbo)
{ {
glamor_gl_dispatch *dispatch = &fbo->glamor_priv->dispatch;
list_del(&fbo->list); list_del(&fbo->list);
glamor_pixmap_fbo_cache_put(fbo); glamor_pixmap_fbo_cache_put(fbo);
@ -291,6 +292,7 @@ glamor_create_tex_obj(glamor_screen_private *glamor_priv,
glamor_pixmap_fbo *fbo; glamor_pixmap_fbo *fbo;
int cache_flag = GLAMOR_CACHE_TEXTURE; int cache_flag = GLAMOR_CACHE_TEXTURE;
GLuint tex; GLuint tex;
GLAMOR_DEFINE_CONTEXT;
if (flag == GLAMOR_CREATE_TEXTURE_EXACT_SIZE) if (flag == GLAMOR_CREATE_TEXTURE_EXACT_SIZE)
cache_flag |= GLAMOR_CACHE_EXACT_SIZE; cache_flag |= GLAMOR_CACHE_EXACT_SIZE;
@ -303,6 +305,7 @@ glamor_create_tex_obj(glamor_screen_private *glamor_priv,
if (fbo == NULL) if (fbo == NULL)
return NULL; return NULL;
GLAMOR_SET_CONTEXT(glamor_priv);
list_init(&fbo->list); list_init(&fbo->list);
dispatch = &glamor_priv->dispatch; dispatch = &glamor_priv->dispatch;
@ -319,6 +322,7 @@ glamor_create_tex_obj(glamor_screen_private *glamor_priv,
fbo->height = h; fbo->height = h;
fbo->format = format; fbo->format = format;
fbo->glamor_priv = glamor_priv; fbo->glamor_priv = glamor_priv;
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return fbo; return fbo;
} }
@ -340,6 +344,7 @@ glamor_create_fbo(glamor_screen_private *glamor_priv,
GLenum format; GLenum format;
GLint tex; GLint tex;
int cache_flag; int cache_flag;
GLAMOR_DEFINE_CONTEXT;
if (!glamor_check_fbo_size(glamor_priv, w, h) if (!glamor_check_fbo_size(glamor_priv, w, h)
|| !glamor_check_fbo_depth(depth)) || !glamor_check_fbo_depth(depth))
@ -359,6 +364,8 @@ glamor_create_fbo(glamor_screen_private *glamor_priv,
if (fbo) if (fbo)
return fbo; return fbo;
new_fbo: new_fbo:
GLAMOR_SET_CONTEXT(glamor_priv);
dispatch = &glamor_priv->dispatch; dispatch = &glamor_priv->dispatch;
dispatch->glGenTextures(1, &tex); dispatch->glGenTextures(1, &tex);
dispatch->glBindTexture(GL_TEXTURE_2D, tex); dispatch->glBindTexture(GL_TEXTURE_2D, tex);
@ -370,6 +377,7 @@ new_fbo:
GL_UNSIGNED_BYTE, NULL); GL_UNSIGNED_BYTE, NULL);
fbo = glamor_create_fbo_from_tex(glamor_priv, w, h, depth, tex, flag); fbo = glamor_create_fbo_from_tex(glamor_priv, w, h, depth, tex, flag);
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return fbo; return fbo;
} }

View File

@ -40,6 +40,12 @@ _glamor_fill_spans(DrawablePtr drawable,
BoxPtr pbox; BoxPtr pbox;
int x1, x2, y; int x1, x2, y;
RegionPtr pClip = fbGetCompositeClip(gc); RegionPtr pClip = fbGetCompositeClip(gc);
glamor_screen_private *glamor_priv;
GLAMOR_DEFINE_CONTEXT;
Bool ret = FALSE;
glamor_priv = glamor_get_screen_private(drawable->pScreen);
GLAMOR_SET_CONTEXT(glamor_priv);
if (gc->fillStyle != FillSolid && gc->fillStyle != FillTiled) if (gc->fillStyle != FillSolid && gc->fillStyle != FillTiled)
goto fail; goto fail;
@ -71,13 +77,15 @@ _glamor_fill_spans(DrawablePtr drawable,
pbox++; pbox++;
} }
} }
return TRUE; ret = TRUE;
goto done;
fail: fail:
if (!fallback if (!fallback
&& glamor_ddx_fallback_check_pixmap(drawable) && glamor_ddx_fallback_check_pixmap(drawable)
&& glamor_ddx_fallback_check_gc(gc)) && glamor_ddx_fallback_check_gc(gc)) {
return FALSE; goto done;
}
glamor_fallback("to %p (%c)\n", drawable, glamor_fallback("to %p (%c)\n", drawable,
glamor_get_drawable_location(drawable)); glamor_get_drawable_location(drawable));
if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) { if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
@ -88,7 +96,11 @@ _glamor_fill_spans(DrawablePtr drawable,
} }
glamor_finish_access(drawable, GLAMOR_ACCESS_RW); glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
} }
return TRUE; ret = TRUE;
done:
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return ret;
} }

View File

@ -46,8 +46,14 @@ _glamor_get_image(DrawablePtr drawable, int x, int y, int w, int h,
int no_alpha, no_revert; int no_alpha, no_revert;
PixmapPtr temp_pixmap = NULL; PixmapPtr temp_pixmap = NULL;
glamor_gl_dispatch * dispatch; glamor_gl_dispatch * dispatch;
GLAMOR_DEFINE_CONTEXT;
Bool ret = FALSE;
goto fall_back; goto fall_back;
glamor_priv = glamor_get_screen_private(drawable->pScreen);
GLAMOR_SET_CONTEXT(glamor_priv);
if (format != ZPixmap) if (format != ZPixmap)
goto fall_back; goto fall_back;
@ -113,9 +119,13 @@ _glamor_get_image(DrawablePtr drawable, int x, int y, int w, int h,
tex_type, d); tex_type, d);
if (temp_pixmap) if (temp_pixmap)
glamor_destroy_pixmap(temp_pixmap); glamor_destroy_pixmap(temp_pixmap);
return TRUE;
ret = TRUE;
fall_back: fall_back:
GLAMOR_RESTORE_CONTEXT(glamor_priv);
if (ret == FALSE)
miGetImage(drawable, x, y, w, h, format, planeMask, d); miGetImage(drawable, x, y, w, h, format, planeMask, d);
return TRUE; return TRUE;
} }

View File

@ -49,7 +49,10 @@ _glamor_get_spans(DrawablePtr drawable,
int i; int i;
uint8_t *readpixels_dst = (uint8_t *) dst; uint8_t *readpixels_dst = (uint8_t *) dst;
int x_off, y_off; int x_off, y_off;
GLAMOR_DEFINE_CONTEXT;
Bool ret = FALSE;
GLAMOR_SET_CONTEXT(glamor_priv);
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)) { if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)) {
glamor_fallback("pixmap has no fbo.\n"); glamor_fallback("pixmap has no fbo.\n");
goto fail; goto fail;
@ -97,20 +100,24 @@ _glamor_get_spans(DrawablePtr drawable,
} }
if (temp_pixmap) if (temp_pixmap)
glamor_destroy_pixmap(temp_pixmap); glamor_destroy_pixmap(temp_pixmap);
return TRUE;
ret = TRUE;
goto done;
fail: fail:
if (!fallback if (!fallback
&& glamor_ddx_fallback_check_pixmap(drawable)) && glamor_ddx_fallback_check_pixmap(drawable))
return FALSE; goto done;
glamor_fallback("from %p (%c)\n", drawable, glamor_fallback("from %p (%c)\n", drawable,
glamor_get_drawable_location(drawable)); glamor_get_drawable_location(drawable));
if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RO)) { if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RO)) {
fbGetSpans(drawable, wmax, points, widths, count, dst); fbGetSpans(drawable, wmax, points, widths, count, dst);
glamor_finish_access(drawable, GLAMOR_ACCESS_RO); glamor_finish_access(drawable, GLAMOR_ACCESS_RO);
} }
return TRUE; done:
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return ret;
} }
void void

View File

@ -37,15 +37,22 @@ _glamor_image_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
int x, int y, unsigned int nglyph, int x, int y, unsigned int nglyph,
CharInfoPtr * ppci, pointer pglyphBase, Bool fallback) CharInfoPtr * ppci, pointer pglyphBase, Bool fallback)
{ {
GLAMOR_DEFINE_CONTEXT;
glamor_screen_private *glamor_priv;
if (!fallback if (!fallback
&& glamor_ddx_fallback_check_pixmap(pDrawable) && glamor_ddx_fallback_check_pixmap(pDrawable)
&& glamor_ddx_fallback_check_gc(pGC)) && glamor_ddx_fallback_check_gc(pGC))
goto fail; goto fail;
glamor_priv = glamor_get_screen_private(pDrawable->pScreen);
GLAMOR_SET_CONTEXT(glamor_priv);
glamor_prepare_access(pDrawable, GLAMOR_ACCESS_RW); glamor_prepare_access(pDrawable, GLAMOR_ACCESS_RW);
glamor_prepare_access_gc(pGC); glamor_prepare_access_gc(pGC);
fbImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase); fbImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
glamor_finish_access_gc(pGC); glamor_finish_access_gc(pGC);
glamor_finish_access(pDrawable, GLAMOR_ACCESS_RW); glamor_finish_access(pDrawable, GLAMOR_ACCESS_RW);
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return TRUE; return TRUE;
fail: fail:
return FALSE; return FALSE;
@ -72,15 +79,22 @@ _glamor_poly_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
int x, int y, unsigned int nglyph, int x, int y, unsigned int nglyph,
CharInfoPtr * ppci, pointer pglyphBase, Bool fallback) CharInfoPtr * ppci, pointer pglyphBase, Bool fallback)
{ {
GLAMOR_DEFINE_CONTEXT;
glamor_screen_private *glamor_priv;
if (!fallback if (!fallback
&& glamor_ddx_fallback_check_pixmap(pDrawable) && glamor_ddx_fallback_check_pixmap(pDrawable)
&& glamor_ddx_fallback_check_gc(pGC)) && glamor_ddx_fallback_check_gc(pGC))
goto fail; goto fail;
glamor_priv = glamor_get_screen_private(pDrawable->pScreen);
GLAMOR_SET_CONTEXT(glamor_priv);
glamor_prepare_access(pDrawable, GLAMOR_ACCESS_RW); glamor_prepare_access(pDrawable, GLAMOR_ACCESS_RW);
glamor_prepare_access_gc(pGC); glamor_prepare_access_gc(pGC);
fbPolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase); fbPolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
glamor_finish_access_gc(pGC); glamor_finish_access_gc(pGC);
glamor_finish_access(pDrawable, GLAMOR_ACCESS_RW); glamor_finish_access(pDrawable, GLAMOR_ACCESS_RW);
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return TRUE; return TRUE;
fail: fail:
return FALSE; return FALSE;
@ -106,11 +120,17 @@ static Bool
_glamor_push_pixels(GCPtr pGC, PixmapPtr pBitmap, _glamor_push_pixels(GCPtr pGC, PixmapPtr pBitmap,
DrawablePtr pDrawable, int w, int h, int x, int y, Bool fallback) DrawablePtr pDrawable, int w, int h, int x, int y, Bool fallback)
{ {
GLAMOR_DEFINE_CONTEXT;
glamor_screen_private *glamor_priv;
if (!fallback if (!fallback
&& glamor_ddx_fallback_check_pixmap(pDrawable) && glamor_ddx_fallback_check_pixmap(pDrawable)
&& glamor_ddx_fallback_check_pixmap(&pBitmap->drawable) && glamor_ddx_fallback_check_pixmap(&pBitmap->drawable)
&& glamor_ddx_fallback_check_gc(pGC)) && glamor_ddx_fallback_check_gc(pGC))
goto fail; goto fail;
glamor_priv = glamor_get_screen_private(pDrawable->pScreen);
GLAMOR_SET_CONTEXT(glamor_priv);
glamor_prepare_access(pDrawable, GLAMOR_ACCESS_RW); glamor_prepare_access(pDrawable, GLAMOR_ACCESS_RW);
glamor_prepare_access(&pBitmap->drawable, GLAMOR_ACCESS_RO); glamor_prepare_access(&pBitmap->drawable, GLAMOR_ACCESS_RO);
glamor_prepare_access_gc(pGC); glamor_prepare_access_gc(pGC);
@ -118,6 +138,7 @@ _glamor_push_pixels(GCPtr pGC, PixmapPtr pBitmap,
glamor_finish_access_gc(pGC); glamor_finish_access_gc(pGC);
glamor_finish_access(&pBitmap->drawable, GLAMOR_ACCESS_RO); glamor_finish_access(&pBitmap->drawable, GLAMOR_ACCESS_RO);
glamor_finish_access(pDrawable, GLAMOR_ACCESS_RW); glamor_finish_access(pDrawable, GLAMOR_ACCESS_RW);
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return TRUE; return TRUE;
fail: fail:
return FALSE; return FALSE;

View File

@ -45,8 +45,14 @@ _glamor_poly_fill_rect(DrawablePtr drawable,
int xorg, yorg; int xorg, yorg;
int n; int n;
register BoxPtr pbox; register BoxPtr pbox;
RegionPtr pClip = fbGetCompositeClip(gc); RegionPtr pClip = fbGetCompositeClip(gc);
Bool ret = FALSE;
glamor_screen_private *glamor_priv;
GLAMOR_DEFINE_CONTEXT;
glamor_priv = glamor_get_screen_private(drawable->pScreen);
GLAMOR_SET_CONTEXT(glamor_priv);
if (gc->fillStyle != FillSolid && gc->fillStyle != FillTiled) { if (gc->fillStyle != FillSolid && gc->fillStyle != FillTiled) {
goto fail; goto fail;
} }
@ -91,14 +97,15 @@ _glamor_poly_fill_rect(DrawablePtr drawable,
goto fail; goto fail;
} }
} }
return TRUE; ret = TRUE;
goto done;
fail: fail:
if (!fallback if (!fallback
&& glamor_ddx_fallback_check_pixmap(drawable) && glamor_ddx_fallback_check_pixmap(drawable)
&& glamor_ddx_fallback_check_gc(gc)) && glamor_ddx_fallback_check_gc(gc))
return FALSE; goto done;
glamor_fallback(" to %p (%c)\n", glamor_fallback(" to %p (%c)\n",
drawable, glamor_get_drawable_location(drawable)); drawable, glamor_get_drawable_location(drawable));
@ -109,7 +116,11 @@ _glamor_poly_fill_rect(DrawablePtr drawable,
} }
glamor_finish_access(drawable, GLAMOR_ACCESS_RW); glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
} }
return TRUE; ret = TRUE;
done:
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return ret;
} }

View File

@ -49,6 +49,9 @@ _glamor_poly_lines(DrawablePtr drawable, GCPtr gc, int mode, int n,
xRectangle *rects; xRectangle *rects;
int x1, x2, y1, y2; int x1, x2, y1, y2;
int i; int i;
glamor_screen_private *glamor_priv;
GLAMOR_DEFINE_CONTEXT;
/* Don't try to do wide lines or non-solid fill style. */ /* Don't try to do wide lines or non-solid fill style. */
if (gc->lineWidth != 0) { if (gc->lineWidth != 0) {
/* This ends up in miSetSpans, which is accelerated as well as we /* This ends up in miSetSpans, which is accelerated as well as we
@ -108,6 +111,8 @@ _glamor_poly_lines(DrawablePtr drawable, GCPtr gc, int mode, int n,
&& glamor_ddx_fallback_check_gc(gc)) && glamor_ddx_fallback_check_gc(gc))
return FALSE; return FALSE;
glamor_priv = glamor_get_screen_private(drawable->pScreen);
GLAMOR_SET_CONTEXT(glamor_priv);
if (gc->lineWidth == 0) { if (gc->lineWidth == 0) {
if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) { if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
if (glamor_prepare_access_gc(gc)) { if (glamor_prepare_access_gc(gc)) {
@ -121,6 +126,7 @@ wide_line:
/* fb calls mi functions in the lineWidth != 0 case. */ /* fb calls mi functions in the lineWidth != 0 case. */
fbPolyLine(drawable, gc, mode, n, points); fbPolyLine(drawable, gc, mode, n, points);
} }
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return TRUE; return TRUE;
} }

View File

@ -36,15 +36,22 @@ static Bool
_glamor_poly_point(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt, _glamor_poly_point(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
DDXPointPtr ppt, Bool fallback) DDXPointPtr ppt, Bool fallback)
{ {
GLAMOR_DEFINE_CONTEXT;
glamor_screen_private *glamor_priv;
if (!fallback if (!fallback
&& glamor_ddx_fallback_check_gc(pGC) && glamor_ddx_fallback_check_gc(pGC)
&& glamor_ddx_fallback_check_pixmap(pDrawable)) && glamor_ddx_fallback_check_pixmap(pDrawable))
goto fail; goto fail;
glamor_priv = glamor_get_screen_private(pDrawable->pScreen);
GLAMOR_SET_CONTEXT(glamor_priv);
glamor_prepare_access_gc(pGC); glamor_prepare_access_gc(pGC);
glamor_prepare_access(pDrawable, GLAMOR_ACCESS_RW); glamor_prepare_access(pDrawable, GLAMOR_ACCESS_RW);
fbPolyPoint(pDrawable, pGC, mode, npt, ppt); fbPolyPoint(pDrawable, pGC, mode, npt, ppt);
glamor_finish_access(pDrawable, GLAMOR_ACCESS_RW); glamor_finish_access(pDrawable, GLAMOR_ACCESS_RW);
glamor_finish_access_gc(pGC); glamor_finish_access_gc(pGC);
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return TRUE; return TRUE;
fail: fail:
@ -69,10 +76,16 @@ static Bool
_glamor_poly_segment(DrawablePtr pDrawable, GCPtr pGC, int nseg, _glamor_poly_segment(DrawablePtr pDrawable, GCPtr pGC, int nseg,
xSegment *pSeg, Bool fallback) xSegment *pSeg, Bool fallback)
{ {
GLAMOR_DEFINE_CONTEXT;
glamor_screen_private *glamor_priv;
if (!fallback if (!fallback
&& glamor_ddx_fallback_check_gc(pGC) && glamor_ddx_fallback_check_gc(pGC)
&& glamor_ddx_fallback_check_pixmap(pDrawable)) && glamor_ddx_fallback_check_pixmap(pDrawable))
goto fail; goto fail;
glamor_priv = glamor_get_screen_private(pDrawable->pScreen);
GLAMOR_SET_CONTEXT(glamor_priv);
/* For lineWidth is not zero, fb calls to mi functions. */ /* For lineWidth is not zero, fb calls to mi functions. */
if (pGC->lineWidth == 0) { if (pGC->lineWidth == 0) {
glamor_prepare_access_gc(pGC); glamor_prepare_access_gc(pGC);
@ -83,6 +96,7 @@ _glamor_poly_segment(DrawablePtr pDrawable, GCPtr pGC, int nseg,
} else } else
fbPolySegment(pDrawable, pGC, nseg, pSeg); fbPolySegment(pDrawable, pGC, nseg, pSeg);
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return TRUE; return TRUE;
fail: fail:
@ -107,11 +121,17 @@ static Bool
_glamor_poly_line(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt, _glamor_poly_line(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
DDXPointPtr ppt, Bool fallback) DDXPointPtr ppt, Bool fallback)
{ {
GLAMOR_DEFINE_CONTEXT;
glamor_screen_private *glamor_priv;
if (!fallback if (!fallback
&& glamor_ddx_fallback_check_gc(pGC) && glamor_ddx_fallback_check_gc(pGC)
&& glamor_ddx_fallback_check_pixmap(pDrawable)) && glamor_ddx_fallback_check_pixmap(pDrawable))
goto fail; goto fail;
/* For lineWidth is not zero, fb calls to mi functions. */ /* For lineWidth is not zero, fb calls to mi functions. */
glamor_priv = glamor_get_screen_private(pDrawable->pScreen);
GLAMOR_SET_CONTEXT(glamor_priv);
if (pGC->lineWidth == 0) { if (pGC->lineWidth == 0) {
glamor_prepare_access_gc(pGC); glamor_prepare_access_gc(pGC);
glamor_prepare_access(pDrawable, GLAMOR_ACCESS_RW); glamor_prepare_access(pDrawable, GLAMOR_ACCESS_RW);
@ -121,6 +141,7 @@ _glamor_poly_line(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
} else } else
fbPolyLine(pDrawable, pGC, mode, npt, ppt); fbPolyLine(pDrawable, pGC, mode, npt, ppt);
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return TRUE; return TRUE;
fail: fail:

View File

@ -219,6 +219,7 @@ typedef struct glamor_screen_private {
int delayed_fallback_pending; int delayed_fallback_pending;
glamor_pixmap_validate_function_t *pixmap_validate_funcs; glamor_pixmap_validate_function_t *pixmap_validate_funcs;
int flags; int flags;
ScreenPtr screen;
} glamor_screen_private; } glamor_screen_private;
typedef enum glamor_access { typedef enum glamor_access {

View File

@ -265,6 +265,10 @@ _glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y,
GLfloat xscale, yscale, txscale, tyscale; GLfloat xscale, yscale, txscale, tyscale;
GLuint tex; GLuint tex;
int no_alpha, no_revert; int no_alpha, no_revert;
GLAMOR_DEFINE_CONTEXT;
Bool ret = FALSE;
GLAMOR_SET_CONTEXT(glamor_priv);
if (image_format == XYBitmap) { if (image_format == XYBitmap) {
assert(depth == 1); assert(depth == 1);
goto fail; goto fail;
@ -396,14 +400,16 @@ _glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y,
dispatch->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); dispatch->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glamor_set_alu(dispatch, GXcopy); glamor_set_alu(dispatch, GXcopy);
glamor_set_planemask(pixmap, ~0); glamor_set_planemask(pixmap, ~0);
return TRUE;
ret = TRUE;
goto done;
fail: fail:
glamor_set_planemask(pixmap, ~0); glamor_set_planemask(pixmap, ~0);
if (!fallback if (!fallback
&& glamor_ddx_fallback_check_pixmap(&pixmap->drawable)) && glamor_ddx_fallback_check_pixmap(&pixmap->drawable))
return FALSE; goto done;
glamor_fallback("to %p (%c)\n", glamor_fallback("to %p (%c)\n",
drawable, glamor_get_drawable_location(drawable)); drawable, glamor_get_drawable_location(drawable));
@ -412,7 +418,11 @@ _glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y,
left_pad, image_format, bits); left_pad, image_format, bits);
glamor_finish_access(&pixmap->drawable, GLAMOR_ACCESS_RW); glamor_finish_access(&pixmap->drawable, GLAMOR_ACCESS_RW);
} }
return TRUE; ret = TRUE;
done:
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return ret;
} }
void void

View File

@ -870,7 +870,10 @@ glamor_composite_with_shader(CARD8 op,
dest_pixmap_priv = glamor_get_pixmap_private(dest_pixmap); dest_pixmap_priv = glamor_get_pixmap_private(dest_pixmap);
int vert_stride = 4; int vert_stride = 4;
int nrect_max; int nrect_max;
GLAMOR_DEFINE_CONTEXT;
Bool ret = FALSE;
GLAMOR_SET_CONTEXT(glamor_priv);
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dest_pixmap_priv)) { if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dest_pixmap_priv)) {
glamor_fallback("dest has no fbo.\n"); glamor_fallback("dest has no fbo.\n");
goto fail; goto fail;
@ -1230,7 +1233,9 @@ glamor_composite_with_shader(CARD8 op,
dispatch->glUseProgram(0); dispatch->glUseProgram(0);
if (saved_source_format) if (saved_source_format)
source->format = saved_source_format; source->format = saved_source_format;
return TRUE;
ret = TRUE;
goto done;
fail: fail:
if (saved_source_format) if (saved_source_format)
@ -1238,7 +1243,10 @@ glamor_composite_with_shader(CARD8 op,
dispatch->glDisable(GL_BLEND); dispatch->glDisable(GL_BLEND);
dispatch->glUseProgram(0); dispatch->glUseProgram(0);
return FALSE;
done:
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return ret;
} }
static PicturePtr static PicturePtr
@ -1308,11 +1316,11 @@ _glamor_composite(CARD8 op,
int prect_size = ARRAY_SIZE(rect); int prect_size = ARRAY_SIZE(rect);
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;
Bool ret = TRUE; Bool ret = TRUE;
RegionRec region; RegionRec region;
BoxPtr box; BoxPtr box;
int nbox, i, ok; int nbox, i, ok;
GLAMOR_DEFINE_CONTEXT;
x_temp_src = x_source; x_temp_src = x_source;
y_temp_src = y_source; y_temp_src = y_source;
@ -1320,6 +1328,7 @@ _glamor_composite(CARD8 op,
y_temp_mask = y_mask; y_temp_mask = y_mask;
dest_pixmap_priv = glamor_get_pixmap_private(dest_pixmap); dest_pixmap_priv = glamor_get_pixmap_private(dest_pixmap);
GLAMOR_SET_CONTEXT(glamor_priv);
/* Currently. Always fallback to cpu if destination is in CPU memory. */ /* Currently. Always fallback to cpu if destination is in CPU memory. */
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dest_pixmap_priv)) { if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dest_pixmap_priv)) {
goto fail; goto fail;
@ -1475,8 +1484,6 @@ _glamor_composite(CARD8 op,
fail: fail:
dispatch->glUseProgram(0);
dispatch->glDisable(GL_BLEND);
if (!fallback if (!fallback
&& glamor_ddx_fallback_check_pixmap(&dest_pixmap->drawable) && glamor_ddx_fallback_check_pixmap(&dest_pixmap->drawable)
&& (!source_pixmap && (!source_pixmap
@ -1528,6 +1535,7 @@ _glamor_composite(CARD8 op,
FreePicture(temp_mask, 0); FreePicture(temp_mask, 0);
if (prect != rect) if (prect != rect)
free(prect); free(prect);
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return ret; return ret;
} }

View File

@ -47,7 +47,10 @@ _glamor_set_spans(DrawablePtr drawable, GCPtr gc, char *src,
RegionPtr clip = fbGetCompositeClip(gc); RegionPtr clip = fbGetCompositeClip(gc);
BoxRec *pbox; BoxRec *pbox;
int x_off, y_off; int x_off, y_off;
GLAMOR_DEFINE_CONTEXT;
Bool ret = FALSE;
GLAMOR_SET_CONTEXT(glamor_priv);
dest_pixmap_priv = glamor_get_pixmap_private(dest_pixmap); dest_pixmap_priv = glamor_get_pixmap_private(dest_pixmap);
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dest_pixmap_priv)) { if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dest_pixmap_priv)) {
glamor_fallback("pixmap has no fbo.\n"); glamor_fallback("pixmap has no fbo.\n");
@ -100,18 +103,25 @@ _glamor_set_spans(DrawablePtr drawable, GCPtr gc, char *src,
glamor_set_planemask(dest_pixmap, ~0); glamor_set_planemask(dest_pixmap, ~0);
glamor_set_alu(dispatch, GXcopy); glamor_set_alu(dispatch, GXcopy);
dispatch->glDisable(GL_SCISSOR_TEST); dispatch->glDisable(GL_SCISSOR_TEST);
return TRUE; ret = TRUE;
goto done;
fail: fail:
if (!fallback if (!fallback
&& glamor_ddx_fallback_check_pixmap(drawable)) && glamor_ddx_fallback_check_pixmap(drawable))
return FALSE; goto done;
glamor_fallback("to %p (%c)\n", glamor_fallback("to %p (%c)\n",
drawable, glamor_get_drawable_location(drawable)); drawable, glamor_get_drawable_location(drawable));
if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) { if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
fbSetSpans(drawable, gc, src, points, widths, n, sorted); fbSetSpans(drawable, gc, src, points, widths, n, sorted);
glamor_finish_access(drawable, GLAMOR_ACCESS_RW); glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
} }
return TRUE; ret = TRUE;
done:
GLAMOR_RESTORE_CONTEXT(glamor_priv);
return ret;
} }
void void

View File

@ -663,4 +663,33 @@ static inline void glamor_dump_pixmap(PixmapPtr pixmap, int x, int y, int w, int
} }
glamor_finish_access(&pixmap->drawable, GLAMOR_ACCESS_RO); glamor_finish_access(&pixmap->drawable, GLAMOR_ACCESS_RO);
} }
static inline void *glamor_make_current(ScreenPtr screen)
{
return glamor_egl_make_current(screen);
}
static inline void glamor_restore_current(ScreenPtr screen, void *previous_context)
{
glamor_egl_restore_context(screen, previous_context);
}
#ifdef GLX_USE_SHARED_DISPATCH
#define GLAMOR_DEFINE_CONTEXT void *_previous_context_ = NULL
#define GLAMOR_SET_CONTEXT(glamor_priv) \
if (glamor_priv->flags & GLAMOR_USE_EGL_SCREEN) \
_previous_context_ = glamor_make_current(glamor_priv->screen)
#define GLAMOR_RESTORE_CONTEXT(glamor_priv) \
if ((glamor_priv->flags & GLAMOR_USE_EGL_SCREEN) \
&& _previous_context_ != NULL) \
glamor_restore_current(glamor_priv->screen, _previous_context_)
#else
#define GLAMOR_DEFINE_CONTEXT
#define GLAMOR_SET_CONTEXT(glamor_priv)
#define GLAMOR_RESTORE_CONTEXT(glamor_priv)
#endif
#endif #endif

121
glamor/glapi.h Normal file
View File

@ -0,0 +1,121 @@
/*
* Mesa 3-D graphics library
* Version: 7.1
*
* Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* \mainpage Mesa GL API Module
*
* \section GLAPIIntroduction Introduction
*
* The Mesa GL API module is responsible for dispatching all the
* gl*() functions. All GL functions are dispatched by jumping through
* the current dispatch table (basically a struct full of function
* pointers.)
*
* A per-thread current dispatch table and per-thread current context
* pointer are managed by this module too.
*
* This module is intended to be non-Mesa-specific so it can be used
* with the X/DRI libGL also.
*/
#ifndef _GLAPI_H
#define _GLAPI_H
#define GL_GLEXT_PROTOTYPES
#if GLAMOR_GLES2
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#else
#include <GL/gl.h>
#include "GL/glext.h"
#endif
/* Is this needed? It is incomplete anyway. */
#ifdef USE_MGL_NAMESPACE
#define _glapi_set_dispatch _mglapi_set_dispatch
#define _glapi_get_dispatch _mglapi_get_dispatch
#define _glapi_set_context _mglapi_set_context
#define _glapi_get_context _mglapi_get_context
#define _glapi_Dispatch _mglapi_Dispatch
#define _glapi_Context _mglapi_Context
#endif
typedef void (*_glapi_proc)(void);
struct _glapi_table;
#if defined (GLX_USE_TLS)
extern __thread struct _glapi_table * _glapi_tls_Dispatch
__attribute__((tls_model("initial-exec")));
extern __thread void * _glapi_tls_Context
__attribute__((tls_model("initial-exec")));
extern const struct _glapi_table *_glapi_Dispatch;
extern const void *_glapi_Context;
# define GET_DISPATCH() _glapi_tls_Dispatch
# define GET_CURRENT_CONTEXT(C) struct gl_context *C = (struct gl_context *) _glapi_tls_Context
# define SET_CURRENT_CONTEXT(C) _glapi_tls_Context = (void*)C
#else
extern struct _glapi_table *_glapi_Dispatch;
extern void *_glapi_Context;
# ifdef THREADS
# define GET_DISPATCH() \
(likely(_glapi_Dispatch) ? _glapi_Dispatch : _glapi_get_dispatch())
# define GET_CURRENT_CONTEXT(C) struct gl_context *C = (struct gl_context *) \
(likely(_glapi_Context) ? _glapi_Context : _glapi_get_context())
# define SET_CURRENT_CONTEXT(C) do { if (likely(_glapi_Context)) \
_glapi_Context = (void*)C; \
else \
_glapi_set_context(C); } while(0)
# else
# define GET_DISPATCH() _glapi_Dispatch
# define GET_CURRENT_CONTEXT(C) struct gl_context *C = (struct gl_context *) _glapi_Context
# define SET_CURRENT_CONTEXT(C) _glapi_Context = (void*)C
# endif
#endif /* defined (GLX_USE_TLS) */
extern void
_glapi_set_context(void *context);
extern void *
_glapi_get_context(void);
#endif