summaryrefslogtreecommitdiff
path: root/src/gallium/state_trackers/egl
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/state_trackers/egl')
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d.c285
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d.h14
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d_image.c136
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d_image.h41
-rw-r--r--src/gallium/state_trackers/egl/common/native.h91
-rw-r--r--src/gallium/state_trackers/egl/common/native_modeset.h87
-rw-r--r--src/gallium/state_trackers/egl/common/st_public_tmp.h2
-rw-r--r--src/gallium/state_trackers/egl/kms/native_kms.c51
-rw-r--r--src/gallium/state_trackers/egl/kms/native_kms.h2
-rw-r--r--src/gallium/state_trackers/egl/x11/native_dri2.c286
-rw-r--r--src/gallium/state_trackers/egl/x11/native_x11.c20
-rw-r--r--src/gallium/state_trackers/egl/x11/native_x11.h7
-rw-r--r--src/gallium/state_trackers/egl/x11/native_ximage.c382
-rw-r--r--src/gallium/state_trackers/egl/x11/sw_winsys.c231
-rw-r--r--src/gallium/state_trackers/egl/x11/sw_winsys.h40
-rw-r--r--src/gallium/state_trackers/egl/x11/x11_screen.c68
-rw-r--r--src/gallium/state_trackers/egl/x11/x11_screen.h10
17 files changed, 968 insertions, 785 deletions
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c
index d769d253ac..e4972d493d 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d.c
+++ b/src/gallium/state_trackers/egl/common/egl_g3d.c
@@ -36,6 +36,7 @@
#include "native.h"
#include "egl_g3d.h"
+#include "egl_g3d_image.h"
#include "egl_st.h"
/**
@@ -508,29 +509,33 @@ egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id)
}
/**
- * Flush the front buffer of the context's draw surface.
+ * Re-validate the context.
*/
static void
-egl_g3d_flush_frontbuffer(struct pipe_screen *screen,
- struct pipe_surface *surf, void *context_private)
+egl_g3d_update_buffer(struct pipe_screen *screen, void *context_private)
{
struct egl_g3d_context *gctx = egl_g3d_context(context_private);
- struct egl_g3d_surface *gsurf = egl_g3d_surface(gctx->base.DrawSurface);
-
- if (gsurf)
- gsurf->native->flush_frontbuffer(gsurf->native);
+ egl_g3d_validate_context(gctx->base.Resource.Display, &gctx->base);
}
-/**
- * Re-validate the context.
- */
static void
-egl_g3d_update_buffer(struct pipe_screen *screen, void *context_private)
+egl_g3d_invalid_surface(struct native_display *ndpy,
+ struct native_surface *nsurf,
+ unsigned int seq_num)
{
- struct egl_g3d_context *gctx = egl_g3d_context(context_private);
- egl_g3d_validate_context(gctx->base.Resource.Display, &gctx->base);
+ /* XXX not thread safe? */
+ struct egl_g3d_surface *gsurf = egl_g3d_surface(nsurf->user_data);
+ struct egl_g3d_context *gctx = egl_g3d_context(gsurf->base.CurrentContext);
+
+ /* set force_validate to skip an unnecessary check */
+ if (gctx)
+ gctx->force_validate = TRUE;
}
+static struct native_event_handler egl_g3d_native_event_handler = {
+ .invalid_surface = egl_g3d_invalid_surface
+};
+
static EGLBoolean
egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy)
{
@@ -575,13 +580,14 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy,
}
dpy->DriverData = gdpy;
- gdpy->native = native_create_display(dpy->NativeDisplay);
+ gdpy->native = native_create_display(dpy->NativeDisplay,
+ &egl_g3d_native_event_handler);
if (!gdpy->native) {
_eglError(EGL_NOT_INITIALIZED, "eglInitialize(no usable display)");
goto fail;
}
- gdpy->native->screen->flush_frontbuffer = egl_g3d_flush_frontbuffer;
+ gdpy->native->user_data = (void *) dpy;
gdpy->native->screen->update_buffer = egl_g3d_update_buffer;
egl_g3d_init_st(&gdrv->base);
@@ -595,6 +601,10 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy,
}
#endif
+ dpy->Extensions.KHR_image_base = EGL_TRUE;
+ if (gdpy->native->get_param(gdpy->native, NATIVE_PARAM_USE_NATIVE_BUFFER))
+ dpy->Extensions.KHR_image_pixmap = EGL_TRUE;
+
if (egl_g3d_add_configs(drv, dpy, 1) == 1) {
_eglError(EGL_NOT_INITIALIZED, "eglInitialize(unable to add configs)");
goto fail;
@@ -687,131 +697,144 @@ egl_g3d_destroy_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
return EGL_TRUE;
}
-static EGLBoolean
-init_surface_geometry(_EGLSurface *surf)
-{
- struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
-
- return gsurf->native->validate(gsurf->native, 0x0,
- &gsurf->sequence_number, NULL,
- &gsurf->base.Width, &gsurf->base.Height);
-}
+struct egl_g3d_create_surface_arg {
+ EGLint type;
+ union {
+ EGLNativeWindowType win;
+ EGLNativePixmapType pix;
+ } u;
+};
static _EGLSurface *
-egl_g3d_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy,
- _EGLConfig *conf, EGLNativeWindowType win,
- const EGLint *attribs)
+egl_g3d_create_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
+ struct egl_g3d_create_surface_arg *arg,
+ const EGLint *attribs)
{
struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
struct egl_g3d_config *gconf = egl_g3d_config(conf);
struct egl_g3d_surface *gsurf;
+ struct native_surface *nsurf;
+ const char *err;
+
+ switch (arg->type) {
+ case EGL_WINDOW_BIT:
+ err = "eglCreateWindowSurface";
+ break;
+ case EGL_PIXMAP_BIT:
+ err = "eglCreatePixmapSurface";
+ break;
+ case EGL_PBUFFER_BIT:
+ err = "eglCreatePBufferSurface";
+ break;
+#ifdef EGL_MESA_screen_surface
+ case EGL_SCREEN_BIT_MESA:
+ err = "eglCreateScreenSurface";
+ break;
+#endif
+ default:
+ err = "eglCreateUnknownSurface";
+ break;
+ }
gsurf = CALLOC_STRUCT(egl_g3d_surface);
if (!gsurf) {
- _eglError(EGL_BAD_ALLOC, "eglCreateWindowSurface");
+ _eglError(EGL_BAD_ALLOC, err);
return NULL;
}
- if (!_eglInitSurface(&gsurf->base, dpy, EGL_WINDOW_BIT, conf, attribs)) {
+ if (!_eglInitSurface(&gsurf->base, dpy, arg->type, conf, attribs)) {
free(gsurf);
return NULL;
}
- gsurf->native =
- gdpy->native->create_window_surface(gdpy->native, win, gconf->native);
- if (!gsurf->native) {
+ /* create the native surface */
+ switch (arg->type) {
+ case EGL_WINDOW_BIT:
+ nsurf = gdpy->native->create_window_surface(gdpy->native,
+ arg->u.win, gconf->native);
+ break;
+ case EGL_PIXMAP_BIT:
+ nsurf = gdpy->native->create_pixmap_surface(gdpy->native,
+ arg->u.pix, gconf->native);
+ break;
+ case EGL_PBUFFER_BIT:
+ nsurf = gdpy->native->create_pbuffer_surface(gdpy->native,
+ gconf->native, gsurf->base.Width, gsurf->base.Height);
+ break;
+#ifdef EGL_MESA_screen_surface
+ case EGL_SCREEN_BIT_MESA:
+ /* prefer back buffer (move to _eglInitSurface?) */
+ gsurf->base.RenderBuffer = EGL_BACK_BUFFER;
+ nsurf = gdpy->native->modeset->create_scanout_surface(gdpy->native,
+ gconf->native, gsurf->base.Width, gsurf->base.Height);
+ break;
+#endif
+ default:
+ nsurf = NULL;
+ break;
+ }
+
+ if (!nsurf) {
free(gsurf);
return NULL;
}
-
- if (!init_surface_geometry(&gsurf->base)) {
- gsurf->native->destroy(gsurf->native);
+ /* initialize the geometry */
+ if (!nsurf->validate(nsurf, 0x0, &gsurf->sequence_number, NULL,
+ &gsurf->base.Width, &gsurf->base.Height)) {
+ nsurf->destroy(nsurf);
free(gsurf);
return NULL;
}
- gsurf->render_att = (gsurf->base.RenderBuffer == EGL_SINGLE_BUFFER ||
- !gconf->native->mode.doubleBufferMode) ?
+ nsurf->user_data = &gsurf->base;
+ gsurf->native = nsurf;
+
+ gsurf->render_att = (gsurf->base.RenderBuffer == EGL_SINGLE_BUFFER) ?
NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT;
+ if (!gconf->native->mode.doubleBufferMode)
+ gsurf->render_att = NATIVE_ATTACHMENT_FRONT_LEFT;
return &gsurf->base;
}
static _EGLSurface *
-egl_g3d_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy,
- _EGLConfig *conf, EGLNativePixmapType pix,
+egl_g3d_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy,
+ _EGLConfig *conf, EGLNativeWindowType win,
const EGLint *attribs)
{
- struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
- struct egl_g3d_config *gconf = egl_g3d_config(conf);
- struct egl_g3d_surface *gsurf;
-
- gsurf = CALLOC_STRUCT(egl_g3d_surface);
- if (!gsurf) {
- _eglError(EGL_BAD_ALLOC, "eglCreatePixmapSurface");
- return NULL;
- }
+ struct egl_g3d_create_surface_arg arg;
- if (!_eglInitSurface(&gsurf->base, dpy, EGL_PIXMAP_BIT, conf, attribs)) {
- free(gsurf);
- return NULL;
- }
+ memset(&arg, 0, sizeof(arg));
+ arg.type = EGL_WINDOW_BIT;
+ arg.u.win = win;
- gsurf->native =
- gdpy->native->create_pixmap_surface(gdpy->native, pix, gconf->native);
- if (!gsurf->native) {
- free(gsurf);
- return NULL;
- }
+ return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs);
+}
- if (!init_surface_geometry(&gsurf->base)) {
- gsurf->native->destroy(gsurf->native);
- free(gsurf);
- return NULL;
- }
+static _EGLSurface *
+egl_g3d_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy,
+ _EGLConfig *conf, EGLNativePixmapType pix,
+ const EGLint *attribs)
+{
+ struct egl_g3d_create_surface_arg arg;
- gsurf->render_att = NATIVE_ATTACHMENT_FRONT_LEFT;
+ memset(&arg, 0, sizeof(arg));
+ arg.type = EGL_PIXMAP_BIT;
+ arg.u.pix = pix;
- return &gsurf->base;
+ return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs);
}
static _EGLSurface *
egl_g3d_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy,
_EGLConfig *conf, const EGLint *attribs)
{
- struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
- struct egl_g3d_config *gconf = egl_g3d_config(conf);
- struct egl_g3d_surface *gsurf;
-
- gsurf = CALLOC_STRUCT(egl_g3d_surface);
- if (!gsurf) {
- _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface");
- return NULL;
- }
-
- if (!_eglInitSurface(&gsurf->base, dpy, EGL_PBUFFER_BIT, conf, attribs)) {
- free(gsurf);
- return NULL;
- }
+ struct egl_g3d_create_surface_arg arg;
- gsurf->native =
- gdpy->native->create_pbuffer_surface(gdpy->native, gconf->native,
- gsurf->base.Width, gsurf->base.Height);
- if (!gsurf->native) {
- free(gsurf);
- return NULL;
- }
-
- if (!init_surface_geometry(&gsurf->base)) {
- gsurf->native->destroy(gsurf->native);
- free(gsurf);
- return NULL;
- }
+ memset(&arg, 0, sizeof(arg));
+ arg.type = EGL_PBUFFER_BIT;
- gsurf->render_att = (!gconf->native->mode.doubleBufferMode) ?
- NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT;
-
- return &gsurf->base;
+ return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs);
}
/**
@@ -869,8 +892,13 @@ egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy,
if (gctx) {
ok = egl_g3d_realloc_context(dpy, &gctx->base);
if (ok) {
+ /* XXX: need to pass the winsys argument for
+ * flush_frontbuffer in the fourth parameter here:
+ */
ok = gctx->stapi->st_make_current(gctx->st_ctx,
- gctx->draw.st_fb, gctx->read.st_fb);
+ gctx->draw.st_fb,
+ gctx->read.st_fb,
+ NULL);
if (ok) {
egl_g3d_validate_context(dpy, &gctx->base);
if (gdraw->base.Type == EGL_WINDOW_BIT) {
@@ -882,7 +910,7 @@ egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy,
}
}
else if (old_gctx) {
- ok = old_gctx->stapi->st_make_current(NULL, NULL, NULL);
+ ok = old_gctx->stapi->st_make_current(NULL, NULL, NULL, NULL);
old_gctx->base.WindowRenderBuffer = EGL_NONE;
}
@@ -919,32 +947,14 @@ egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
if (gctx)
gctx->stapi->st_notify_swapbuffers(gctx->draw.st_fb);
- /*
- * We drew on the back buffer, unless there was no back buffer.
- * In that case, we drew on the front buffer. Either case, we call
- * swap_buffers.
- */
- if (!gsurf->native->swap_buffers(gsurf->native))
- return EGL_FALSE;
-
- if (gctx) {
- struct egl_g3d_config *gconf = egl_g3d_config(gsurf->base.Config);
-
- /* force validation if the swap method is not copy */
- if (gconf->native->mode.swapMethod != GLX_SWAP_COPY_OML) {
- gctx->force_validate = EGL_TRUE;
- egl_g3d_validate_context(dpy, &gctx->base);
- }
- }
-
- return EGL_TRUE;
+ return gsurf->native->swap_buffers(gsurf->native);
}
/**
* Find a config that supports the pixmap.
*/
-static _EGLConfig *
-find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix)
+_EGLConfig *
+egl_g3d_find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix)
{
struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
struct egl_g3d_config *gconf;
@@ -996,7 +1006,7 @@ egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
if (!gsurf->render_surface)
return EGL_TRUE;
- gconf = egl_g3d_config(find_pixmap_config(dpy, target));
+ gconf = egl_g3d_config(egl_g3d_find_pixmap_config(dpy, target));
if (!gconf)
return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers");
@@ -1103,7 +1113,7 @@ egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
target_format = PIPE_FORMAT_R8G8B8_UNORM;
break;
case EGL_TEXTURE_RGBA:
- target_format = PIPE_FORMAT_A8R8G8B8_UNORM;
+ target_format = PIPE_FORMAT_B8G8R8A8_UNORM;
break;
default:
return _eglError(EGL_BAD_MATCH, "eglBindTexImage");
@@ -1171,34 +1181,12 @@ static _EGLSurface *
egl_g3d_create_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy,
_EGLConfig *conf, const EGLint *attribs)
{
- struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
- struct egl_g3d_config *gconf = egl_g3d_config(conf);
- struct egl_g3d_surface *gsurf;
+ struct egl_g3d_create_surface_arg arg;
- gsurf = CALLOC_STRUCT(egl_g3d_surface);
- if (!gsurf) {
- _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface");
- return NULL;
- }
-
- if (!_eglInitSurface(&gsurf->base, dpy,
- EGL_SCREEN_BIT_MESA, conf, attribs)) {
- free(gsurf);
- return NULL;
- }
+ memset(&arg, 0, sizeof(arg));
+ arg.type = EGL_SCREEN_BIT_MESA;
- gsurf->native =
- gdpy->native->modeset->create_scanout_surface(gdpy->native,
- gconf->native, gsurf->base.Width, gsurf->base.Height);
- if (!gsurf->native) {
- free(gsurf);
- return NULL;
- }
-
- gsurf->render_att = (!gconf->native->mode.doubleBufferMode) ?
- NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT;
-
- return &gsurf->base;
+ return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs);
}
static EGLBoolean
@@ -1329,6 +1317,9 @@ _eglMain(const char *args)
gdrv->base.API.BindTexImage = egl_g3d_bind_tex_image;
gdrv->base.API.ReleaseTexImage = egl_g3d_release_tex_image;
+ gdrv->base.API.CreateImageKHR = egl_g3d_create_image;
+ gdrv->base.API.DestroyImageKHR = egl_g3d_destroy_image;
+
#ifdef EGL_MESA_screen_surface
gdrv->base.API.CreateScreenSurfaceMESA = egl_g3d_create_screen_surface;
gdrv->base.API.ShowScreenSurfaceMESA = egl_g3d_show_screen_surface;
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.h b/src/gallium/state_trackers/egl/common/egl_g3d.h
index 5d2d9c481a..e3e55e46d3 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d.h
+++ b/src/gallium/state_trackers/egl/common/egl_g3d.h
@@ -34,6 +34,7 @@
#include "eglcontext.h"
#include "eglsurface.h"
#include "eglconfig.h"
+#include "eglimage.h"
#include "eglscreen.h"
#include "eglmode.h"
@@ -81,6 +82,14 @@ struct egl_g3d_config {
const struct native_config *native;
};
+struct egl_g3d_image {
+ _EGLImage base;
+ struct pipe_texture *texture;
+ unsigned face;
+ unsigned level;
+ unsigned zslice;
+};
+
struct egl_g3d_screen {
_EGLScreen base;
const struct native_connector *native;
@@ -90,5 +99,10 @@ struct egl_g3d_screen {
/* standard typecasts */
_EGL_DRIVER_STANDARD_TYPECASTS(egl_g3d)
_EGL_DRIVER_TYPECAST(egl_g3d_screen, _EGLScreen, obj)
+_EGL_DRIVER_TYPECAST(egl_g3d_image, _EGLImage, obj)
+
+
+_EGLConfig *
+egl_g3d_find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix);
#endif /* _EGL_G3D_H_ */
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_image.c b/src/gallium/state_trackers/egl/common/egl_g3d_image.c
new file mode 100644
index 0000000000..d701f9c9a8
--- /dev/null
+++ b/src/gallium/state_trackers/egl/common/egl_g3d_image.c
@@ -0,0 +1,136 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.8
+ *
+ * Copyright (C) 2010 LunarG Inc.
+ *
+ * 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.
+ *
+ * Authors:
+ * Chia-I Wu <olv@lunarg.com>
+ */
+
+#include <assert.h>
+#include "pipe/p_screen.h"
+#include "util/u_memory.h"
+#include "util/u_rect.h"
+#include "util/u_inlines.h"
+#include "eglcurrent.h"
+#include "egllog.h"
+
+#include "native.h"
+#include "egl_g3d.h"
+#include "egl_g3d_image.h"
+
+/**
+ * Reference and return the front left buffer of the native pixmap.
+ */
+static struct pipe_texture *
+egl_g3d_reference_native_pixmap(_EGLDisplay *dpy, EGLNativePixmapType pix)
+{
+ struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+ struct egl_g3d_config *gconf;
+ struct native_surface *nsurf;
+ struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
+ enum native_attachment natt;
+
+ gconf = egl_g3d_config(egl_g3d_find_pixmap_config(dpy, pix));
+ if (!gconf)
+ return NULL;
+
+ nsurf = gdpy->native->create_pixmap_surface(gdpy->native,
+ pix, gconf->native);
+ if (!nsurf)
+ return NULL;
+
+ natt = NATIVE_ATTACHMENT_FRONT_LEFT;
+ if (!nsurf->validate(nsurf, 1 << natt, NULL, textures, NULL, NULL))
+ textures[natt] = NULL;
+
+ nsurf->destroy(nsurf);
+
+ return textures[natt];
+}
+
+_EGLImage *
+egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
+ EGLenum target, EGLClientBuffer buffer,
+ const EGLint *attribs)
+{
+ struct pipe_texture *ptex;
+ struct egl_g3d_image *gimg;
+ unsigned face = 0, level = 0, zslice = 0;
+
+ gimg = CALLOC_STRUCT(egl_g3d_image);
+ if (!gimg) {
+ _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface");
+ return NULL;
+ }
+
+ if (!_eglInitImage(&gimg->base, dpy, attribs)) {
+ free(gimg);
+ return NULL;
+ }
+
+ switch (target) {
+ case EGL_NATIVE_PIXMAP_KHR:
+ ptex = egl_g3d_reference_native_pixmap(dpy,
+ (EGLNativePixmapType) buffer);
+ break;
+ default:
+ ptex = NULL;
+ break;
+ }
+
+ if (!ptex) {
+ free(gimg);
+ return NULL;
+ }
+
+ if (level > ptex->last_level) {
+ _eglError(EGL_BAD_MATCH, "eglCreateEGLImageKHR");
+ pipe_texture_reference(&gimg->texture, NULL);
+ free(gimg);
+ return NULL;
+ }
+ if (zslice > ptex->depth0) {
+ _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
+ pipe_texture_reference(&gimg->texture, NULL);
+ free(gimg);
+ return NULL;
+ }
+
+ /* transfer the ownership to the image */
+ gimg->texture = ptex;
+ gimg->face = face;
+ gimg->level = level;
+ gimg->zslice = zslice;
+
+ return &gimg->base;
+}
+
+EGLBoolean
+egl_g3d_destroy_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *img)
+{
+ struct egl_g3d_image *gimg = egl_g3d_image(img);
+
+ pipe_texture_reference(&gimg->texture, NULL);
+ free(gimg);
+
+ return EGL_TRUE;
+}
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_image.h b/src/gallium/state_trackers/egl/common/egl_g3d_image.h
new file mode 100644
index 0000000000..c199c46645
--- /dev/null
+++ b/src/gallium/state_trackers/egl/common/egl_g3d_image.h
@@ -0,0 +1,41 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.8
+ *
+ * Copyright (C) 2010 LunarG Inc.
+ *
+ * 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.
+ *
+ * Authors:
+ * Chia-I Wu <olv@lunarg.com>
+ */
+
+#ifndef _EGL_G3D_IMAGE_H_
+#define _EGL_G3D_IMAGE_H_
+
+#include "egl_g3d.h"
+
+_EGLImage *
+egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
+ EGLenum target, EGLClientBuffer buffer,
+ const EGLint *attribs);
+
+EGLBoolean
+egl_g3d_destroy_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *image);
+
+#endif /* _EGL_G3D_IMAGE_H_ */
diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h
index 4f9758545a..93c81b26e1 100644
--- a/src/gallium/state_trackers/egl/common/native.h
+++ b/src/gallium/state_trackers/egl/common/native.h
@@ -34,6 +34,8 @@
#include "pipe/p_context.h"
#include "pipe/p_state.h"
+#include "native_modeset.h"
+
/**
* Only color buffers are listed. The others are allocated privately through,
* for example, st_renderbuffer_alloc_storage().
@@ -47,6 +49,14 @@ enum native_attachment {
NUM_NATIVE_ATTACHMENTS
};
+enum native_param_type {
+ /*
+ * Return TRUE if window/pixmap surfaces use the buffers of the native
+ * types.
+ */
+ NATIVE_PARAM_USE_NATIVE_BUFFER
+};
+
/**
* Enumerations for probe results.
*/
@@ -69,6 +79,11 @@ struct native_probe {
};
struct native_surface {
+ /**
+ * Available for caller's use.
+ */
+ void *user_data;
+
void (*destroy)(struct native_surface *nsurf);
/**
@@ -117,18 +132,6 @@ struct native_config {
boolean scanout_bit;
};
-struct native_connector {
- int dummy;
-};
-
-struct native_mode {
- const char *desc;
- int width, height;
- int refresh_rate;
-};
-
-struct native_display_modeset;
-
/**
* A pipe winsys abstracts the OS. A pipe screen abstracts the graphcis
* hardware. A native display consists of a pipe winsys, a pipe screen, and
@@ -137,15 +140,25 @@ struct native_display_modeset;
struct native_display {
/**
* The pipe screen of the native display.
- *
- * Note that the "flush_frontbuffer" and "update_buffer" callbacks will be
- * overridden.
*/
struct pipe_screen *screen;
+ /**
+ * Available for caller's use.
+ */
+ void *user_data;
+
void (*destroy)(struct native_display *ndpy);
/**
+ * Query the parameters of the native display.
+ *
+ * The return value is defined by the parameter.
+ */
+ int (*get_param)(struct native_display *ndpy,
+ enum native_param_type param);
+
+ /**
* Get the supported configs. The configs are owned by the display, but
* the returned array should be free()ed.
*
@@ -196,46 +209,17 @@ struct native_display {
};
/**
- * Mode setting interface of the native display. It exposes the mode setting
- * capabilities of the underlying graphics hardware.
+ * The handler for events that a native display may generate. The events are
+ * generated asynchronously and the handler may be called by any thread at any
+ * time.
*/
-struct native_display_modeset {
- /**
- * Get the available physical connectors and the number of CRTCs.
- */
- const struct native_connector **(*get_connectors)(struct native_display *ndpy,
- int *num_connectors,
- int *num_crtcs);
-
- /**
- * Get the current supported modes of a connector. The returned modes may
- * change every time this function is called and those from previous calls
- * might become invalid.
- */
- const struct native_mode **(*get_modes)(struct native_display *ndpy,
- const struct native_connector *nconn,
- int *num_modes);
-
- /**
- * Create a scan-out surface. Required unless no config has
- * GLX_SCREEN_BIT_MESA set.
- */
- struct native_surface *(*create_scanout_surface)(struct native_display *ndpy,
- const struct native_config *nconf,
- uint width, uint height);
-
+struct native_event_handler {
/**
- * Program the CRTC to output the surface to the given connectors with the
- * given mode. When surface is not given, the CRTC is disabled.
- *
- * This interface does not export a way to query capabilities of the CRTCs.
- * The native display usually needs to dynamically map the index to a CRTC
- * that supports the given connectors.
+ * This function is called when a surface needs to be validated.
*/
- boolean (*program)(struct native_display *ndpy, int crtc_idx,
- struct native_surface *nsurf, uint x, uint y,
- const struct native_connector **nconns, int num_nconns,
- const struct native_mode *nmode);
+ void (*invalid_surface)(struct native_display *ndpy,
+ struct native_surface *nsurf,
+ unsigned int seq_num);
};
/**
@@ -267,6 +251,7 @@ const char *
native_get_name(void);
struct native_display *
-native_create_display(EGLNativeDisplayType dpy);
+native_create_display(EGLNativeDisplayType dpy,
+ struct native_event_handler *handler);
#endif /* _NATIVE_H_ */
diff --git a/src/gallium/state_trackers/egl/common/native_modeset.h b/src/gallium/state_trackers/egl/common/native_modeset.h
new file mode 100644
index 0000000000..71dc3ec860
--- /dev/null
+++ b/src/gallium/state_trackers/egl/common/native_modeset.h
@@ -0,0 +1,87 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.8
+ *
+ * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
+ *
+ * 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.
+ */
+
+#ifndef _NATIVE_MODESET_H_
+#define _NATIVE_MODESET_H_
+
+#include "pipe/p_compiler.h"
+
+struct native_display;
+struct native_surface;
+struct native_config;
+
+struct native_connector {
+ int dummy;
+};
+
+struct native_mode {
+ const char *desc;
+ int width, height;
+ int refresh_rate;
+};
+
+/**
+ * Mode setting interface of the native display. It exposes the mode setting
+ * capabilities of the underlying graphics hardware.
+ */
+struct native_display_modeset {
+ /**
+ * Get the available physical connectors and the number of CRTCs.
+ */
+ const struct native_connector **(*get_connectors)(struct native_display *ndpy,
+ int *num_connectors,
+ int *num_crtcs);
+
+ /**
+ * Get the current supported modes of a connector. The returned modes may
+ * change every time this function is called and those from previous calls
+ * might become invalid.
+ */
+ const struct native_mode **(*get_modes)(struct native_display *ndpy,
+ const struct native_connector *nconn,
+ int *num_modes);
+
+ /**
+ * Create a scan-out surface. Required unless no config has
+ * GLX_SCREEN_BIT_MESA set.
+ */
+ struct native_surface *(*create_scanout_surface)(struct native_display *ndpy,
+ const struct native_config *nconf,
+ uint width, uint height);
+
+ /**
+ * Program the CRTC to output the surface to the given connectors with the
+ * given mode. When surface is not given, the CRTC is disabled.
+ *
+ * This interface does not export a way to query capabilities of the CRTCs.
+ * The native display usually needs to dynamically map the index to a CRTC
+ * that supports the given connectors.
+ */
+ boolean (*program)(struct native_display *ndpy, int crtc_idx,
+ struct native_surface *nsurf, uint x, uint y,
+ const struct native_connector **nconns, int num_nconns,
+ const struct native_mode *nmode);
+};
+
+#endif /* _NATIVE_MODESET_H_ */
diff --git a/src/gallium/state_trackers/egl/common/st_public_tmp.h b/src/gallium/state_trackers/egl/common/st_public_tmp.h
index 507a0ec402..562dd68c15 100644
--- a/src/gallium/state_trackers/egl/common/st_public_tmp.h
+++ b/src/gallium/state_trackers/egl/common/st_public_tmp.h
@@ -9,7 +9,7 @@ ST_PUBLIC(st_get_framebuffer_surface, int, struct st_f
ST_PUBLIC(st_get_framebuffer_texture, int, struct st_framebuffer *stfb, uint surfIndex, struct pipe_texture **texture)
ST_PUBLIC(st_framebuffer_private, void *, struct st_framebuffer *stfb)
ST_PUBLIC(st_unreference_framebuffer, void, struct st_framebuffer *stfb)
-ST_PUBLIC(st_make_current, GLboolean, struct st_context *st, struct st_framebuffer *draw, struct st_framebuffer *read)
+ST_PUBLIC(st_make_current, GLboolean, struct st_context *st, struct st_framebuffer *draw, struct st_framebuffer *read, void *winsys_drawable_handle)
ST_PUBLIC(st_get_current, struct st_context *, void)
ST_PUBLIC(st_flush, void, struct st_context *st, uint pipeFlushFlags, struct pipe_fence_handle **fence)
ST_PUBLIC(st_finish, void, struct st_context *st)
diff --git a/src/gallium/state_trackers/egl/kms/native_kms.c b/src/gallium/state_trackers/egl/kms/native_kms.c
index ee6ab2e60b..7322240856 100644
--- a/src/gallium/state_trackers/egl/kms/native_kms.c
+++ b/src/gallium/state_trackers/egl/kms/native_kms.c
@@ -55,7 +55,7 @@ kms_surface_validate(struct native_surface *nsurf, uint attachment_mask,
templ.format = ksurf->color_format;
templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
if (ksurf->type == KMS_SURFACE_TYPE_SCANOUT)
- templ.tex_usage |= PIPE_TEXTURE_USAGE_PRIMARY;
+ templ.tex_usage |= PIPE_TEXTURE_USAGE_SCANOUT;
}
/* create textures */
@@ -100,7 +100,7 @@ kms_surface_init_framebuffers(struct native_surface *nsurf, boolean need_back)
for (i = 0; i < num_framebuffers; i++) {
struct kms_framebuffer *fb;
enum native_attachment natt;
- unsigned int handle, stride;
+ struct winsys_handle whandle;
uint block_bits;
if (i == 0) {
@@ -128,13 +128,17 @@ kms_surface_init_framebuffers(struct native_surface *nsurf, boolean need_back)
/* TODO detect the real value */
fb->is_passive = TRUE;
- if (!kdpy->api->local_handle_from_texture(kdpy->api,
- kdpy->base.screen, fb->texture, &stride, &handle))
+ memset(&whandle, 0, sizeof(whandle));
+ whandle.type = DRM_API_HANDLE_TYPE_KMS;
+
+ if (!kdpy->base.screen->texture_get_handle(kdpy->base.screen,
+ fb->texture, &whandle))
return FALSE;
block_bits = util_format_get_blocksizebits(ksurf->color_format);
err = drmModeAddFB(kdpy->fd, ksurf->width, ksurf->height,
- block_bits, block_bits, stride, handle, &fb->buffer_id);
+ block_bits, block_bits, whandle.stride, whandle.handle,
+ &fb->buffer_id);
if (err) {
fb->buffer_id = 0;
return FALSE;
@@ -201,6 +205,8 @@ kms_surface_swap_buffers(struct native_surface *nsurf)
/* the front/back textures are swapped */
ksurf->sequence_number++;
+ kdpy->event_handler->invalid_surface(&kdpy->base,
+ &ksurf->base, ksurf->sequence_number);
return TRUE;
}
@@ -609,9 +615,9 @@ kms_display_get_configs(struct native_display *ndpy, int *num_configs)
/* always double-buffered */
nconf->mode.doubleBufferMode = TRUE;
- format = PIPE_FORMAT_A8R8G8B8_UNORM;
+ format = PIPE_FORMAT_B8G8R8A8_UNORM;
if (!kms_display_is_format_supported(&kdpy->base, format, TRUE)) {
- format = PIPE_FORMAT_B8G8R8A8_UNORM;
+ format = PIPE_FORMAT_A8R8G8B8_UNORM;
if (!kms_display_is_format_supported(&kdpy->base, format, TRUE))
format = PIPE_FORMAT_NONE;
}
@@ -625,9 +631,9 @@ kms_display_get_configs(struct native_display *ndpy, int *num_configs)
nconf->mode.alphaBits = 8;
nconf->mode.rgbBits = 32;
- format = PIPE_FORMAT_S8Z24_UNORM;
+ format = PIPE_FORMAT_Z24S8_UNORM;
if (!kms_display_is_format_supported(&kdpy->base, format, FALSE)) {
- format = PIPE_FORMAT_Z24S8_UNORM;
+ format = PIPE_FORMAT_S8Z24_UNORM;
if (!kms_display_is_format_supported(&kdpy->base, format, FALSE))
format = PIPE_FORMAT_NONE;
}
@@ -663,6 +669,21 @@ kms_display_get_configs(struct native_display *ndpy, int *num_configs)
return configs;
}
+static int
+kms_display_get_param(struct native_display *ndpy,
+ enum native_param_type param)
+{
+ int val;
+
+ switch (param) {
+ default:
+ val = 0;
+ break;
+ }
+
+ return val;
+}
+
static void
kms_display_destroy(struct native_display *ndpy)
{
@@ -762,7 +783,9 @@ static struct native_display_modeset kms_display_modeset = {
};
static struct native_display *
-kms_create_display(EGLNativeDisplayType dpy, struct drm_api *api)
+kms_create_display(EGLNativeDisplayType dpy,
+ struct native_event_handler *event_handler,
+ struct drm_api *api)
{
struct kms_display *kdpy;
@@ -770,6 +793,8 @@ kms_create_display(EGLNativeDisplayType dpy, struct drm_api *api)
if (!kdpy)
return NULL;
+ kdpy->event_handler = event_handler;
+
kdpy->api = api;
if (!kdpy->api) {
_eglLog(_EGL_WARNING, "failed to create DRM API");
@@ -805,6 +830,7 @@ kms_create_display(EGLNativeDisplayType dpy, struct drm_api *api)
}
kdpy->base.destroy = kms_display_destroy;
+ kdpy->base.get_param = kms_display_get_param;
kdpy->base.get_configs = kms_display_get_configs;
kdpy->base.create_pbuffer_surface = kms_display_create_pbuffer_surface;
@@ -845,7 +871,8 @@ native_get_name(void)
}
struct native_display *
-native_create_display(EGLNativeDisplayType dpy)
+native_create_display(EGLNativeDisplayType dpy,
+ struct native_event_handler *event_handler)
{
struct native_display *ndpy = NULL;
@@ -853,7 +880,7 @@ native_create_display(EGLNativeDisplayType dpy)
drm_api = drm_api_create();
if (drm_api)
- ndpy = kms_create_display(dpy, drm_api);
+ ndpy = kms_create_display(dpy, event_handler, drm_api);
return ndpy;
}
diff --git a/src/gallium/state_trackers/egl/kms/native_kms.h b/src/gallium/state_trackers/egl/kms/native_kms.h
index 095186e3cf..f9cbcb158b 100644
--- a/src/gallium/state_trackers/egl/kms/native_kms.h
+++ b/src/gallium/state_trackers/egl/kms/native_kms.h
@@ -53,6 +53,8 @@ struct kms_crtc {
struct kms_display {
struct native_display base;
+ struct native_event_handler *event_handler;
+
int fd;
struct drm_api *api;
drmModeResPtr resources;
diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c b/src/gallium/state_trackers/egl/x11/native_dri2.c
index dbd1a64992..9839979231 100644
--- a/src/gallium/state_trackers/egl/x11/native_dri2.c
+++ b/src/gallium/state_trackers/egl/x11/native_dri2.c
@@ -26,6 +26,7 @@
#include "util/u_math.h"
#include "util/u_format.h"
#include "util/u_inlines.h"
+#include "util/u_hash_table.h"
#include "pipe/p_compiler.h"
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
@@ -47,12 +48,18 @@ struct dri2_display {
Display *dpy;
boolean own_dpy;
+ struct native_event_handler *event_handler;
+
struct drm_api *api;
struct x11_screen *xscr;
int xscr_number;
+ const char *dri_driver;
+ int dri_major, dri_minor;
struct dri2_config *configs;
int num_configs;
+
+ struct util_hash_table *surfaces;
};
struct dri2_surface {
@@ -62,7 +69,8 @@ struct dri2_surface {
enum pipe_format color_format;
struct dri2_display *dri2dpy;
- unsigned int sequence_number;
+ unsigned int server_stamp;
+ unsigned int client_stamp;
int width, height;
struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
uint valid_mask;
@@ -96,65 +104,24 @@ dri2_config(const struct native_config *nconf)
}
/**
- * Get the buffers from the server.
+ * Process the buffers returned by the server.
*/
static void
-dri2_surface_get_buffers(struct native_surface *nsurf, uint buffer_mask)
+dri2_surface_process_drawable_buffers(struct native_surface *nsurf,
+ struct x11_drawable_buffer *xbufs,
+ int num_xbufs)
{
struct dri2_surface *dri2surf = dri2_surface(nsurf);
struct dri2_display *dri2dpy = dri2surf->dri2dpy;
- unsigned int dri2atts[NUM_NATIVE_ATTACHMENTS];
- int num_ins, num_outs, att, i;
- struct x11_drawable_buffer *xbufs;
struct pipe_texture templ;
+ struct winsys_handle whandle;
uint valid_mask;
+ int i;
- /* prepare the attachments */
- num_ins = 0;
- for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
- if (native_attachment_mask_test(buffer_mask, att)) {
- unsigned int dri2att;
-
- switch (att) {
- case NATIVE_ATTACHMENT_FRONT_LEFT:
- dri2att = DRI2BufferFrontLeft;
- break;
- case NATIVE_ATTACHMENT_BACK_LEFT:
- dri2att = DRI2BufferBackLeft;
- break;
- case NATIVE_ATTACHMENT_FRONT_RIGHT:
- dri2att = DRI2BufferFrontRight;
- break;
- case NATIVE_ATTACHMENT_BACK_RIGHT:
- dri2att = DRI2BufferBackRight;
- break;
- default:
- assert(0);
- dri2att = 0;
- break;
- }
-
- dri2atts[num_ins] = dri2att;
- num_ins++;
- }
- }
-
- xbufs = x11_drawable_get_buffers(dri2dpy->xscr, dri2surf->drawable,
- &dri2surf->width, &dri2surf->height,
- dri2atts, FALSE, num_ins, &num_outs);
-
- /* we should be able to do better... */
- if (xbufs && dri2surf->last_num_xbufs == num_outs &&
- memcmp(dri2surf->last_xbufs, xbufs, sizeof(*xbufs) * num_outs) == 0) {
- free(xbufs);
- return;
- }
-
- /* free the old buffers */
+ /* free the old textures */
for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++)
pipe_texture_reference(&dri2surf->textures[i], NULL);
dri2surf->valid_mask = 0x0;
- dri2surf->sequence_number++;
dri2surf->have_back = FALSE;
dri2surf->have_fake = FALSE;
@@ -172,7 +139,7 @@ dri2_surface_get_buffers(struct native_surface *nsurf, uint buffer_mask)
templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
valid_mask = 0x0;
- for (i = 0; i < num_outs; i++) {
+ for (i = 0; i < num_xbufs; i++) {
struct x11_drawable_buffer *xbuf = &xbufs[i];
const char *desc;
enum native_attachment natt;
@@ -205,19 +172,81 @@ dri2_surface_get_buffers(struct native_surface *nsurf, uint buffer_mask)
continue;
}
- dri2surf->textures[natt] =
- dri2dpy->api->texture_from_shared_handle(dri2dpy->api,
- dri2dpy->base.screen, &templ, desc, xbuf->pitch, xbuf->name);
+ memset(&whandle, 0, sizeof(whandle));
+ whandle.stride = xbuf->pitch;
+ whandle.handle = xbuf->name;
+ dri2surf->textures[natt] = dri2dpy->base.screen->texture_from_handle(
+ dri2dpy->base.screen, &templ, &whandle);
if (dri2surf->textures[natt])
valid_mask |= 1 << natt;
}
+ dri2surf->valid_mask = valid_mask;
+}
+
+/**
+ * Get the buffers from the server.
+ */
+static void
+dri2_surface_get_buffers(struct native_surface *nsurf, uint buffer_mask)
+{
+ struct dri2_surface *dri2surf = dri2_surface(nsurf);
+ struct dri2_display *dri2dpy = dri2surf->dri2dpy;
+ unsigned int dri2atts[NUM_NATIVE_ATTACHMENTS];
+ int num_ins, num_outs, att;
+ struct x11_drawable_buffer *xbufs;
+
+ /* prepare the attachments */
+ num_ins = 0;
+ for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
+ if (native_attachment_mask_test(buffer_mask, att)) {
+ unsigned int dri2att;
+
+ switch (att) {
+ case NATIVE_ATTACHMENT_FRONT_LEFT:
+ dri2att = DRI2BufferFrontLeft;
+ break;
+ case NATIVE_ATTACHMENT_BACK_LEFT:
+ dri2att = DRI2BufferBackLeft;
+ break;
+ case NATIVE_ATTACHMENT_FRONT_RIGHT:
+ dri2att = DRI2BufferFrontRight;
+ break;
+ case NATIVE_ATTACHMENT_BACK_RIGHT:
+ dri2att = DRI2BufferBackRight;
+ break;
+ default:
+ assert(0);
+ dri2att = 0;
+ break;
+ }
+
+ dri2atts[num_ins] = dri2att;
+ num_ins++;
+ }
+ }
+
+ xbufs = x11_drawable_get_buffers(dri2dpy->xscr, dri2surf->drawable,
+ &dri2surf->width, &dri2surf->height,
+ dri2atts, FALSE, num_ins, &num_outs);
+
+ /* we should be able to do better... */
+ if (xbufs && dri2surf->last_num_xbufs == num_outs &&
+ memcmp(dri2surf->last_xbufs, xbufs, sizeof(*xbufs) * num_outs) == 0) {
+ free(xbufs);
+ dri2surf->client_stamp = dri2surf->server_stamp;
+ return;
+ }
+
+ dri2_surface_process_drawable_buffers(&dri2surf->base, xbufs, num_outs);
+
+ dri2surf->server_stamp++;
+ dri2surf->client_stamp = dri2surf->server_stamp;
+
if (dri2surf->last_xbufs)
free(dri2surf->last_xbufs);
dri2surf->last_xbufs = xbufs;
dri2surf->last_num_xbufs = num_outs;
-
- dri2surf->valid_mask = valid_mask;
}
/**
@@ -264,7 +293,7 @@ dri2_surface_update_buffers(struct native_surface *nsurf, uint buffer_mask)
}
}
dri2surf->valid_mask |= new_valid;
- /* no need to update sequence number */
+ /* no need to update the stamps */
}
else {
dri2_surface_get_buffers(&dri2surf->base, buffer_mask);
@@ -273,6 +302,16 @@ dri2_surface_update_buffers(struct native_surface *nsurf, uint buffer_mask)
return ((dri2surf->valid_mask & buffer_mask) == buffer_mask);
}
+/**
+ * Return TRUE if the surface receives DRI2_InvalidateBuffers events.
+ */
+static INLINE boolean
+dri2_surface_receive_events(struct native_surface *nsurf)
+{
+ struct dri2_surface *dri2surf = dri2_surface(nsurf);
+ return (dri2surf->dri2dpy->dri_minor >= 3);
+}
+
static boolean
dri2_surface_flush_frontbuffer(struct native_surface *nsurf)
{
@@ -289,6 +328,13 @@ dri2_surface_flush_frontbuffer(struct native_surface *nsurf)
0, 0, dri2surf->width, dri2surf->height,
DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft);
+ /* force buffers to be updated in next validation call */
+ if (!dri2_surface_receive_events(&dri2surf->base)) {
+ dri2surf->server_stamp++;
+ dri2dpy->event_handler->invalid_surface(&dri2dpy->base,
+ &dri2surf->base, dri2surf->server_stamp);
+ }
+
return TRUE;
}
@@ -314,6 +360,13 @@ dri2_surface_swap_buffers(struct native_surface *nsurf)
0, 0, dri2surf->width, dri2surf->height,
DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
+ /* force buffers to be updated in next validation call */
+ if (!dri2_surface_receive_events(&dri2surf->base)) {
+ dri2surf->server_stamp++;
+ dri2dpy->event_handler->invalid_surface(&dri2dpy->base,
+ &dri2surf->base, dri2surf->server_stamp);
+ }
+
return TRUE;
}
@@ -324,11 +377,14 @@ dri2_surface_validate(struct native_surface *nsurf, uint attachment_mask,
{
struct dri2_surface *dri2surf = dri2_surface(nsurf);
- if (!dri2_surface_update_buffers(&dri2surf->base, attachment_mask))
- return FALSE;
+ if (dri2surf->server_stamp != dri2surf->client_stamp ||
+ (dri2surf->valid_mask & attachment_mask) != attachment_mask) {
+ if (!dri2_surface_update_buffers(&dri2surf->base, attachment_mask))
+ return FALSE;
+ }
if (seq_num)
- *seq_num = dri2surf->sequence_number;
+ *seq_num = dri2surf->client_stamp;
if (textures) {
int att;
@@ -377,9 +433,13 @@ dri2_surface_destroy(struct native_surface *nsurf)
pipe_texture_reference(&ptex, NULL);
}
- if (dri2surf->drawable)
+ if (dri2surf->drawable) {
x11_drawable_enable_dri2(dri2surf->dri2dpy->xscr,
dri2surf->drawable, FALSE);
+
+ util_hash_table_remove(dri2surf->dri2dpy->surfaces,
+ (void *) dri2surf->drawable);
+ }
free(dri2surf);
}
@@ -408,8 +468,14 @@ dri2_display_create_surface(struct native_display *ndpy,
dri2surf->base.validate = dri2_surface_validate;
dri2surf->base.wait = dri2_surface_wait;
- if (drawable)
+ if (drawable) {
x11_drawable_enable_dri2(dri2dpy->xscr, drawable, TRUE);
+ /* initialize the geometry */
+ dri2_surface_update_buffers(&dri2surf->base, 0x0);
+
+ util_hash_table_set(dri2surf->dri2dpy->surfaces,
+ (void *) dri2surf->drawable, (void *) &dri2surf->base);
+ }
return dri2surf;
}
@@ -461,17 +527,17 @@ choose_color_format(const __GLcontextModes *mode, enum pipe_format formats[32])
switch (mode->rgbBits) {
case 32:
- formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM;
formats[count++] = PIPE_FORMAT_B8G8R8A8_UNORM;
+ formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM;
break;
case 24:
- formats[count++] = PIPE_FORMAT_X8R8G8B8_UNORM;
formats[count++] = PIPE_FORMAT_B8G8R8X8_UNORM;
- formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM;
+ formats[count++] = PIPE_FORMAT_X8R8G8B8_UNORM;
formats[count++] = PIPE_FORMAT_B8G8R8A8_UNORM;
+ formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM;
break;
case 16:
- formats[count++] = PIPE_FORMAT_R5G6B5_UNORM;
+ formats[count++] = PIPE_FORMAT_B5G6R5_UNORM;
break;
default:
break;
@@ -492,12 +558,12 @@ choose_depth_stencil_format(const __GLcontextModes *mode,
break;
case 24:
if (mode->stencilBits) {
- formats[count++] = PIPE_FORMAT_S8Z24_UNORM;
formats[count++] = PIPE_FORMAT_Z24S8_UNORM;
+ formats[count++] = PIPE_FORMAT_S8Z24_UNORM;
}
else {
- formats[count++] = PIPE_FORMAT_X8Z24_UNORM;
formats[count++] = PIPE_FORMAT_Z24X8_UNORM;
+ formats[count++] = PIPE_FORMAT_X8Z24_UNORM;
}
break;
case 16:
@@ -644,6 +710,25 @@ dri2_display_is_pixmap_supported(struct native_display *ndpy,
return (depth == nconf_depth || (depth == 24 && depth + 8 == nconf_depth));
}
+static int
+dri2_display_get_param(struct native_display *ndpy,
+ enum native_param_type param)
+{
+ int val;
+
+ switch (param) {
+ case NATIVE_PARAM_USE_NATIVE_BUFFER:
+ /* DRI2GetBuffers use the native buffers */
+ val = TRUE;
+ break;
+ default:
+ val = 0;
+ break;
+ }
+
+ return val;
+}
+
static void
dri2_display_destroy(struct native_display *ndpy)
{
@@ -655,6 +740,9 @@ dri2_display_destroy(struct native_display *ndpy)
if (dri2dpy->base.screen)
dri2dpy->base.screen->destroy(dri2dpy->base.screen);
+ if (dri2dpy->surfaces)
+ util_hash_table_destroy(dri2dpy->surfaces);
+
if (dri2dpy->xscr)
x11_screen_destroy(dri2dpy->xscr);
if (dri2dpy->own_dpy)
@@ -664,6 +752,27 @@ dri2_display_destroy(struct native_display *ndpy)
free(dri2dpy);
}
+static void
+dri2_display_invalidate_buffers(struct x11_screen *xscr, Drawable drawable,
+ void *user_data)
+{
+ struct native_display *ndpy = (struct native_display* ) user_data;
+ struct dri2_display *dri2dpy = dri2_display(ndpy);
+ struct native_surface *nsurf;
+ struct dri2_surface *dri2surf;
+
+ nsurf = (struct native_surface *)
+ util_hash_table_get(dri2dpy->surfaces, (void *) drawable);
+ if (!nsurf)
+ return;
+
+ dri2surf = dri2_surface(nsurf);
+
+ dri2surf->server_stamp++;
+ dri2dpy->event_handler->invalid_surface(&dri2dpy->base,
+ &dri2surf->base, dri2surf->server_stamp);
+}
+
/**
* Initialize DRI2 and pipe screen.
*/
@@ -681,7 +790,17 @@ dri2_display_init_screen(struct native_display *ndpy)
return FALSE;
}
- fd = x11_screen_enable_dri2(dri2dpy->xscr, driver);
+ dri2dpy->dri_driver = x11_screen_probe_dri2(dri2dpy->xscr,
+ &dri2dpy->dri_major, &dri2dpy->dri_minor);
+ if (!dri2dpy->dri_driver || !driver ||
+ strcmp(dri2dpy->dri_driver, driver) != 0) {
+ _eglLog(_EGL_WARNING, "Driver mismatch: %s != %s",
+ dri2dpy->dri_driver, dri2dpy->api->name);
+ return FALSE;
+ }
+
+ fd = x11_screen_enable_dri2(dri2dpy->xscr,
+ dri2_display_invalidate_buffers, &dri2dpy->base);
if (fd < 0)
return FALSE;
@@ -696,8 +815,23 @@ dri2_display_init_screen(struct native_display *ndpy)
return TRUE;
}
+static unsigned
+dri2_display_hash_table_hash(void *key)
+{
+ XID drawable = pointer_to_uintptr(key);
+ return (unsigned) drawable;
+}
+
+static int
+dri2_display_hash_table_compare(void *key1, void *key2)
+{
+ return (key1 - key2);
+}
+
struct native_display *
-x11_create_dri2_display(EGLNativeDisplayType dpy, struct drm_api *api)
+x11_create_dri2_display(EGLNativeDisplayType dpy,
+ struct native_event_handler *event_handler,
+ struct drm_api *api)
{
struct dri2_display *dri2dpy;
@@ -705,12 +839,8 @@ x11_create_dri2_display(EGLNativeDisplayType dpy, struct drm_api *api)
if (!dri2dpy)
return NULL;
+ dri2dpy->event_handler = event_handler;
dri2dpy->api = api;
- if (!dri2dpy->api) {
- _eglLog(_EGL_WARNING, "failed to create DRM API");
- free(dri2dpy);
- return NULL;
- }
dri2dpy->dpy = dpy;
if (!dri2dpy->dpy) {
@@ -734,7 +864,15 @@ x11_create_dri2_display(EGLNativeDisplayType dpy, struct drm_api *api)
return NULL;
}
+ dri2dpy->surfaces = util_hash_table_create(dri2_display_hash_table_hash,
+ dri2_display_hash_table_compare);
+ if (!dri2dpy->surfaces) {
+ dri2_display_destroy(&dri2dpy->base);
+ return NULL;
+ }
+
dri2dpy->base.destroy = dri2_display_destroy;
+ dri2dpy->base.get_param = dri2_display_get_param;
dri2dpy->base.get_configs = dri2_display_get_configs;
dri2dpy->base.is_pixmap_supported = dri2_display_is_pixmap_supported;
dri2dpy->base.create_window_surface = dri2_display_create_window_surface;
diff --git a/src/gallium/state_trackers/egl/x11/native_x11.c b/src/gallium/state_trackers/egl/x11/native_x11.c
index 55f0d4d308..c6eb17ab1a 100644
--- a/src/gallium/state_trackers/egl/x11/native_x11.c
+++ b/src/gallium/state_trackers/egl/x11/native_x11.c
@@ -70,7 +70,7 @@ native_create_probe(EGLNativeDisplayType dpy)
xscr = x11_screen_create(xdpy, scr);
if (xscr) {
if (x11_screen_support(xscr, X11_SCREEN_EXTENSION_DRI2)) {
- driver_name = x11_screen_probe_dri2(xscr);
+ driver_name = x11_screen_probe_dri2(xscr, NULL, NULL);
if (driver_name)
nprobe->data = strdup(driver_name);
}
@@ -126,7 +126,8 @@ native_get_name(void)
}
struct native_display *
-native_create_display(EGLNativeDisplayType dpy)
+native_create_display(EGLNativeDisplayType dpy,
+ struct native_event_handler *event_handler)
{
struct native_display *ndpy = NULL;
boolean force_sw;
@@ -136,21 +137,14 @@ native_create_display(EGLNativeDisplayType dpy)
force_sw = debug_get_bool_option("EGL_SOFTWARE", FALSE);
if (api && !force_sw) {
- ndpy = x11_create_dri2_display(dpy, api);
+ ndpy = x11_create_dri2_display(dpy, event_handler, api);
}
if (!ndpy) {
EGLint level = (force_sw) ? _EGL_INFO : _EGL_WARNING;
- boolean use_shm;
-
- /*
- * XXX st/mesa calls pipe_screen::update_buffer in st_validate_state.
- * When SHM is used, there is a good chance that the shared memory
- * segment is detached before the softpipe tile cache is flushed.
- */
- use_shm = FALSE;
- _eglLog(level, "use software%s fallback", (use_shm) ? " (SHM)" : "");
- ndpy = x11_create_ximage_display(dpy, use_shm);
+
+ _eglLog(level, "use software fallback");
+ ndpy = x11_create_ximage_display(dpy, event_handler);
}
return ndpy;
diff --git a/src/gallium/state_trackers/egl/x11/native_x11.h b/src/gallium/state_trackers/egl/x11/native_x11.h
index 622ddac5df..1566524926 100644
--- a/src/gallium/state_trackers/egl/x11/native_x11.h
+++ b/src/gallium/state_trackers/egl/x11/native_x11.h
@@ -29,9 +29,12 @@
#include "common/native.h"
struct native_display *
-x11_create_ximage_display(EGLNativeDisplayType dpy, boolean use_xshm);
+x11_create_ximage_display(EGLNativeDisplayType dpy,
+ struct native_event_handler *event_handler);
struct native_display *
-x11_create_dri2_display(EGLNativeDisplayType dpy, struct drm_api *api);
+x11_create_dri2_display(EGLNativeDisplayType dpy,
+ struct native_event_handler *event_handler,
+ struct drm_api *api);
#endif /* _NATIVE_X11_H_ */
diff --git a/src/gallium/state_trackers/egl/x11/native_ximage.c b/src/gallium/state_trackers/egl/x11/native_ximage.c
index 78675a1998..c6b16354f9 100644
--- a/src/gallium/state_trackers/egl/x11/native_ximage.c
+++ b/src/gallium/state_trackers/egl/x11/native_ximage.c
@@ -28,17 +28,19 @@
#include <sys/shm.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
-#include <X11/extensions/XShm.h>
#include "util/u_memory.h"
#include "util/u_math.h"
#include "util/u_format.h"
#include "pipe/p_compiler.h"
-#include "util/u_simple_screen.h"
#include "util/u_inlines.h"
-#include "softpipe/sp_winsys.h"
+#include "state_tracker/xlib_sw_winsys.h"
+#include "target-helpers/wrap_screen.h"
+#include "util/u_debug.h"
+#include "softpipe/sp_public.h"
+#include "llvmpipe/lp_public.h"
+#include "cell/ppu/cell_public.h"
#include "egllog.h"
-#include "sw_winsys.h"
#include "native_x11.h"
#include "x11_screen.h"
@@ -53,22 +55,18 @@ struct ximage_display {
Display *dpy;
boolean own_dpy;
+ struct native_event_handler *event_handler;
+
struct x11_screen *xscr;
int xscr_number;
- boolean use_xshm;
-
- struct pipe_winsys *winsys;
struct ximage_config *configs;
int num_configs;
};
struct ximage_buffer {
- XImage *ximage;
-
struct pipe_texture *texture;
- XShmSegmentInfo *shm_info;
- boolean xshm_attached;
+ struct xlib_drawable xdraw;
};
struct ximage_surface {
@@ -79,12 +77,13 @@ struct ximage_surface {
XVisualInfo visual;
struct ximage_display *xdpy;
- GC gc;
-
- unsigned int sequence_number;
+ unsigned int server_stamp;
+ unsigned int client_stamp;
int width, height;
struct ximage_buffer buffers[NUM_NATIVE_ATTACHMENTS];
uint valid_mask;
+
+ struct pipe_surface *draw_surface;
};
struct ximage_config {
@@ -118,18 +117,6 @@ ximage_surface_free_buffer(struct native_surface *nsurf,
struct ximage_buffer *xbuf = &xsurf->buffers[which];
pipe_texture_reference(&xbuf->texture, NULL);
-
- if (xbuf->shm_info) {
- if (xbuf->xshm_attached)
- XShmDetach(xsurf->xdpy->dpy, xbuf->shm_info);
- if (xbuf->shm_info->shmaddr != (void *) -1)
- shmdt(xbuf->shm_info->shmaddr);
- if (xbuf->shm_info->shmid != -1)
- shmctl(xbuf->shm_info->shmid, IPC_RMID, 0);
-
- xbuf->shm_info->shmaddr = (void *) -1;
- xbuf->shm_info->shmid = -1;
- }
}
static boolean
@@ -153,40 +140,25 @@ ximage_surface_alloc_buffer(struct native_surface *nsurf,
templ.depth0 = 1;
templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
- if (xbuf->shm_info) {
- struct pipe_buffer *pbuf;
- unsigned stride, size;
- void *addr = NULL;
-
- stride = util_format_get_stride(xsurf->color_format, xsurf->width);
- /* alignment should depend on visual? */
- stride = align(stride, 4);
- size = stride * xsurf->height;
-
- /* create and attach shm object */
- xbuf->shm_info->shmid = shmget(IPC_PRIVATE, size, 0755);
- if (xbuf->shm_info->shmid != -1) {
- xbuf->shm_info->shmaddr =
- shmat(xbuf->shm_info->shmid, NULL, 0);
- if (xbuf->shm_info->shmaddr != (void *) -1) {
- if (XShmAttach(xsurf->xdpy->dpy, xbuf->shm_info)) {
- addr = xbuf->shm_info->shmaddr;
- xbuf->xshm_attached = TRUE;
- }
- }
- }
-
- if (addr) {
- pbuf = screen->user_buffer_create(screen, addr, size);
- if (pbuf) {
- xbuf->texture =
- screen->texture_blanket(screen, &templ, &stride, pbuf);
- pipe_buffer_reference(&pbuf, NULL);
- }
+ if (xsurf->type != XIMAGE_SURFACE_TYPE_PBUFFER) {
+ switch (which) {
+ case NATIVE_ATTACHMENT_FRONT_LEFT:
+ case NATIVE_ATTACHMENT_FRONT_RIGHT:
+ templ.tex_usage |= PIPE_TEXTURE_USAGE_SCANOUT;
+ break;
+ case NATIVE_ATTACHMENT_BACK_LEFT:
+ case NATIVE_ATTACHMENT_BACK_RIGHT:
+ templ.tex_usage |= PIPE_TEXTURE_USAGE_DISPLAY_TARGET;
+ break;
+ default:
+ break;
}
}
- else {
- xbuf->texture = screen->texture_create(screen, &templ);
+ xbuf->texture = screen->texture_create(screen, &templ);
+ if (xbuf->texture) {
+ xbuf->xdraw.visual = xsurf->visual.visual;
+ xbuf->xdraw.depth = xsurf->visual.depth;
+ xbuf->xdraw.drawable = xsurf->drawable;
}
/* clean up the buffer if allocation failed */
@@ -216,24 +188,27 @@ ximage_surface_update_geometry(struct native_surface *nsurf)
ok = XGetGeometry(xsurf->xdpy->dpy, xsurf->drawable,
&root, &x, &y, &w, &h, &border, &depth);
- if (!ok) {
- w = xsurf->width;
- h = xsurf->height;
- }
-
- /* all buffers become invalid */
- if (xsurf->width != w || xsurf->height != h) {
+ if (ok && (xsurf->width != w || xsurf->height != h)) {
xsurf->width = w;
xsurf->height = h;
- xsurf->valid_mask = 0x0;
- xsurf->sequence_number++;
+ xsurf->server_stamp++;
updated = TRUE;
}
return updated;
}
+static void
+ximage_surface_notify_invalid(struct native_surface *nsurf)
+{
+ struct ximage_surface *xsurf = ximage_surface(nsurf);
+ struct ximage_display *xdpy = xsurf->xdpy;
+
+ xdpy->event_handler->invalid_surface(&xdpy->base,
+ &xsurf->base, xsurf->server_stamp);
+}
+
/**
* Update the buffers of the surface. It is a slow function due to the
* round-trip to the server.
@@ -247,37 +222,34 @@ ximage_surface_update_buffers(struct native_surface *nsurf, uint buffer_mask)
int att;
updated = ximage_surface_update_geometry(&xsurf->base);
- buffer_mask &= ~xsurf->valid_mask;
- /* all requested buffers are valid */
- if (!buffer_mask)
- return TRUE;
+ if (updated) {
+ /* all buffers become invalid */
+ xsurf->valid_mask = 0x0;
+ }
+ else {
+ buffer_mask &= ~xsurf->valid_mask;
+ /* all requested buffers are valid */
+ if (!buffer_mask) {
+ xsurf->client_stamp = xsurf->server_stamp;
+ return TRUE;
+ }
+ }
new_valid = 0x0;
for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
if (native_attachment_mask_test(buffer_mask, att)) {
- struct ximage_buffer *xbuf = &xsurf->buffers[att];
-
/* reallocate the texture */
if (!ximage_surface_alloc_buffer(&xsurf->base, att))
break;
- /* update ximage */
- if (xbuf->ximage) {
- xbuf->ximage->width = xsurf->width;
- xbuf->ximage->height = xsurf->height;
- }
-
new_valid |= (1 << att);
if (buffer_mask == new_valid)
break;
}
}
- if (new_valid) {
- xsurf->valid_mask |= new_valid;
- if (updated)
- xsurf->sequence_number++;
- }
+ xsurf->valid_mask |= new_valid;
+ xsurf->client_stamp = xsurf->server_stamp;
return (new_valid == buffer_mask);
}
@@ -289,43 +261,26 @@ ximage_surface_draw_buffer(struct native_surface *nsurf,
struct ximage_surface *xsurf = ximage_surface(nsurf);
struct ximage_buffer *xbuf = &xsurf->buffers[which];
struct pipe_screen *screen = xsurf->xdpy->base.screen;
- struct pipe_transfer *transfer;
+ struct pipe_surface *psurf;
if (xsurf->type == XIMAGE_SURFACE_TYPE_PBUFFER)
return TRUE;
- assert(xsurf->drawable && xbuf->ximage && xbuf->texture);
-
- transfer = screen->get_tex_transfer(screen, xbuf->texture,
- 0, 0, 0, PIPE_TRANSFER_READ, 0, 0, xsurf->width, xsurf->height);
- if (!transfer)
- return FALSE;
-
- xbuf->ximage->bytes_per_line = transfer->stride;
- xbuf->ximage->data = screen->transfer_map(screen, transfer);
- if (!xbuf->ximage->data) {
- screen->tex_transfer_destroy(transfer);
- return FALSE;
- }
-
+ assert(xsurf->drawable && xbuf->texture);
- if (xbuf->shm_info)
- XShmPutImage(xsurf->xdpy->dpy, xsurf->drawable, xsurf->gc,
- xbuf->ximage, 0, 0, 0, 0, xsurf->width, xsurf->height, False);
- else
- XPutImage(xsurf->xdpy->dpy, xsurf->drawable, xsurf->gc,
- xbuf->ximage, 0, 0, 0, 0, xsurf->width, xsurf->height);
+ psurf = xsurf->draw_surface;
+ if (!psurf || psurf->texture != xbuf->texture) {
+ pipe_surface_reference(&xsurf->draw_surface, NULL);
- xbuf->ximage->data = NULL;
- screen->transfer_unmap(screen, transfer);
+ psurf = screen->get_tex_surface(screen,
+ xbuf->texture, 0, 0, 0, PIPE_BUFFER_USAGE_CPU_READ);
+ if (!psurf)
+ return FALSE;
- /*
- * softpipe allows the pipe transfer to be re-used, but we don't want to
- * rely on that behavior.
- */
- screen->tex_transfer_destroy(transfer);
+ xsurf->draw_surface = psurf;
+ }
- XSync(xsurf->xdpy->dpy, FALSE);
+ screen->flush_frontbuffer(screen, psurf, &xbuf->xdraw);
return TRUE;
}
@@ -333,7 +288,16 @@ ximage_surface_draw_buffer(struct native_surface *nsurf,
static boolean
ximage_surface_flush_frontbuffer(struct native_surface *nsurf)
{
- return ximage_surface_draw_buffer(nsurf, NATIVE_ATTACHMENT_FRONT_LEFT);
+ struct ximage_surface *xsurf = ximage_surface(nsurf);
+ boolean ret;
+
+ ret = ximage_surface_draw_buffer(&xsurf->base,
+ NATIVE_ATTACHMENT_FRONT_LEFT);
+ /* force buffers to be updated in next validation call */
+ xsurf->server_stamp++;
+ ximage_surface_notify_invalid(&xsurf->base);
+
+ return ret;
}
static boolean
@@ -344,19 +308,21 @@ ximage_surface_swap_buffers(struct native_surface *nsurf)
boolean ret;
/* display the back buffer first */
- ret = ximage_surface_draw_buffer(nsurf, NATIVE_ATTACHMENT_BACK_LEFT);
+ ret = ximage_surface_draw_buffer(&xsurf->base,
+ NATIVE_ATTACHMENT_BACK_LEFT);
+ /* force buffers to be updated in next validation call */
+ xsurf->server_stamp++;
+ ximage_surface_notify_invalid(&xsurf->base);
xfront = &xsurf->buffers[NATIVE_ATTACHMENT_FRONT_LEFT];
xback = &xsurf->buffers[NATIVE_ATTACHMENT_BACK_LEFT];
- /* skip swapping so that the front buffer is allocated only when needed */
- if (!xfront->texture)
- return ret;
-
- xtmp = *xfront;
- *xfront = *xback;
- *xback = xtmp;
- xsurf->sequence_number++;
+ /* skip swapping unless there is a front buffer */
+ if (xfront->texture) {
+ xtmp = *xfront;
+ *xfront = *xback;
+ *xback = xtmp;
+ }
return ret;
}
@@ -368,11 +334,14 @@ ximage_surface_validate(struct native_surface *nsurf, uint attachment_mask,
{
struct ximage_surface *xsurf = ximage_surface(nsurf);
- if (!ximage_surface_update_buffers(&xsurf->base, attachment_mask))
- return FALSE;
+ if (xsurf->client_stamp != xsurf->server_stamp ||
+ (xsurf->valid_mask & attachment_mask) != attachment_mask) {
+ if (!ximage_surface_update_buffers(&xsurf->base, attachment_mask))
+ return FALSE;
+ }
if (seq_num)
- *seq_num = xsurf->sequence_number;
+ *seq_num = xsurf->client_stamp;
if (textures) {
int att;
@@ -408,18 +377,11 @@ ximage_surface_destroy(struct native_surface *nsurf)
struct ximage_surface *xsurf = ximage_surface(nsurf);
int i;
- for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) {
- struct ximage_buffer *xbuf = &xsurf->buffers[i];
+ pipe_surface_reference(&xsurf->draw_surface, NULL);
+
+ for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++)
ximage_surface_free_buffer(&xsurf->base, i);
- /* xbuf->shm_info is owned by xbuf->ximage? */
- if (xbuf->ximage) {
- XDestroyImage(xbuf->ximage);
- xbuf->ximage = NULL;
- }
- }
- if (xsurf->type != XIMAGE_SURFACE_TYPE_PBUFFER)
- XFreeGC(xsurf->xdpy->dpy, xsurf->gc);
free(xsurf);
}
@@ -432,7 +394,6 @@ ximage_display_create_surface(struct native_display *ndpy,
struct ximage_display *xdpy = ximage_display(ndpy);
struct ximage_config *xconf = ximage_config(nconf);
struct ximage_surface *xsurf;
- int i;
xsurf = CALLOC_STRUCT(ximage_surface);
if (!xsurf)
@@ -446,49 +407,8 @@ ximage_display_create_surface(struct native_display *ndpy,
if (xsurf->type != XIMAGE_SURFACE_TYPE_PBUFFER) {
xsurf->drawable = drawable;
xsurf->visual = *xconf->visual;
-
- xsurf->gc = XCreateGC(xdpy->dpy, xsurf->drawable, 0, NULL);
- if (!xsurf->gc) {
- free(xsurf);
- return NULL;
- }
-
- for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) {
- struct ximage_buffer *xbuf = &xsurf->buffers[i];
-
- if (xdpy->use_xshm) {
- xbuf->shm_info = calloc(1, sizeof(*xbuf->shm_info));
- if (xbuf->shm_info) {
- /* initialize shm info */
- xbuf->shm_info->shmid = -1;
- xbuf->shm_info->shmaddr = (void *) -1;
- xbuf->shm_info->readOnly = TRUE;
-
- xbuf->ximage = XShmCreateImage(xsurf->xdpy->dpy,
- xsurf->visual.visual,
- xsurf->visual.depth,
- ZPixmap, NULL,
- xbuf->shm_info,
- 0, 0);
- }
- }
- else {
- xbuf->ximage = XCreateImage(xsurf->xdpy->dpy,
- xsurf->visual.visual,
- xsurf->visual.depth,
- ZPixmap, 0, /* format, offset */
- NULL, /* data */
- 0, 0, /* size */
- 8, /* bitmap_pad */
- 0); /* bytes_per_line */
- }
-
- if (!xbuf->ximage) {
- XFreeGC(xdpy->dpy, xsurf->gc);
- free(xsurf);
- return NULL;
- }
- }
+ /* initialize the geometry */
+ ximage_surface_update_buffers(&xsurf->base, 0x0);
}
xsurf->base.destroy = ximage_surface_destroy;
@@ -547,13 +467,13 @@ choose_format(const XVisualInfo *vinfo)
/* TODO elaborate the formats */
switch (vinfo->depth) {
case 32:
- fmt = PIPE_FORMAT_A8R8G8B8_UNORM;
+ fmt = PIPE_FORMAT_B8G8R8A8_UNORM;
break;
case 24:
- fmt = PIPE_FORMAT_X8R8G8B8_UNORM;
+ fmt = PIPE_FORMAT_B8G8R8X8_UNORM;
break;
case 16:
- fmt = PIPE_FORMAT_R5G6B5_UNORM;
+ fmt = PIPE_FORMAT_B5G6R5_UNORM;
break;
default:
fmt = PIPE_FORMAT_NONE;
@@ -606,8 +526,8 @@ ximage_display_get_configs(struct native_display *ndpy, int *num_configs)
xconf->base.stencil_format = PIPE_FORMAT_NONE;
/* create the second config with depth/stencil buffer */
if (j == 1) {
- xconf->base.depth_format = PIPE_FORMAT_S8Z24_UNORM;
- xconf->base.stencil_format = PIPE_FORMAT_S8Z24_UNORM;
+ xconf->base.depth_format = PIPE_FORMAT_Z24S8_UNORM;
+ xconf->base.stencil_format = PIPE_FORMAT_Z24S8_UNORM;
mode->depthBits = 24;
mode->stencilBits = 8;
mode->haveDepthBuffer = TRUE;
@@ -655,13 +575,13 @@ ximage_display_is_pixmap_supported(struct native_display *ndpy,
depth = x11_drawable_get_depth(xdpy->xscr, (Drawable) pix);
switch (depth) {
case 32:
- fmt = PIPE_FORMAT_A8R8G8B8_UNORM;
+ fmt = PIPE_FORMAT_B8G8R8A8_UNORM;
break;
case 24:
- fmt = PIPE_FORMAT_X8R8G8B8_UNORM;
+ fmt = PIPE_FORMAT_B8G8R8X8_UNORM;
break;
case 16:
- fmt = PIPE_FORMAT_R5G6B5_UNORM;
+ fmt = PIPE_FORMAT_B5G6R5_UNORM;
break;
default:
fmt = PIPE_FORMAT_NONE;
@@ -671,6 +591,25 @@ ximage_display_is_pixmap_supported(struct native_display *ndpy,
return (fmt == nconf->color_format);
}
+static int
+ximage_display_get_param(struct native_display *ndpy,
+ enum native_param_type param)
+{
+ int val;
+
+ switch (param) {
+ case NATIVE_PARAM_USE_NATIVE_BUFFER:
+ /* private buffers are allocated */
+ val = FALSE;
+ break;
+ default:
+ val = 0;
+ break;
+ }
+
+ return val;
+}
+
static void
ximage_display_destroy(struct native_display *ndpy)
{
@@ -680,7 +619,6 @@ ximage_display_destroy(struct native_display *ndpy)
free(xdpy->configs);
xdpy->base.screen->destroy(xdpy->base.screen);
- free(xdpy->winsys);
x11_screen_destroy(xdpy->xscr);
if (xdpy->own_dpy)
@@ -688,8 +626,63 @@ ximage_display_destroy(struct native_display *ndpy)
free(xdpy);
}
+
+/* Helper function to build a subset of a driver stack consisting of
+ * one of the software rasterizers (cell, llvmpipe, softpipe) and the
+ * xlib winsys.
+ *
+ * This function could be shared, but currently causes headaches for
+ * the build systems, particularly scons if we try.
+ *
+ * Long term, want to avoid having global #defines for things like
+ * GALLIUM_LLVMPIPE, GALLIUM_CELL, etc. Scons already eliminates
+ * those #defines, so things that are painful for it now are likely to
+ * be painful for other build systems in the future.
+ */
+static struct pipe_screen *
+swrast_xlib_create_screen( Display *display )
+{
+ struct sw_winsys *winsys;
+ struct pipe_screen *screen = NULL;
+
+ /* Create the underlying winsys, which performs presents to Xlib
+ * drawables:
+ */
+ winsys = xlib_create_sw_winsys( display );
+ if (winsys == NULL)
+ return NULL;
+
+ /* Create a software rasterizer on top of that winsys. Use
+ * llvmpipe if it is available.
+ */
+#if defined(GALLIUM_LLVMPIPE)
+ if (screen == NULL &&
+ !debug_get_bool_option("GALLIUM_NO_LLVM", FALSE))
+ screen = llvmpipe_create_screen( winsys );
+#endif
+
+ if (screen == NULL)
+ screen = softpipe_create_screen( winsys );
+
+ if (screen == NULL)
+ goto fail;
+
+ /* Inject any wrapping layers we want to here:
+ */
+ return gallium_wrap_screen( screen );
+
+fail:
+ if (winsys)
+ winsys->destroy( winsys );
+
+ return NULL;
+}
+
+
+
struct native_display *
-x11_create_ximage_display(EGLNativeDisplayType dpy, boolean use_xshm)
+x11_create_ximage_display(EGLNativeDisplayType dpy,
+ struct native_event_handler *event_handler)
{
struct ximage_display *xdpy;
@@ -707,6 +700,8 @@ x11_create_ximage_display(EGLNativeDisplayType dpy, boolean use_xshm)
xdpy->own_dpy = TRUE;
}
+ xdpy->event_handler = event_handler;
+
xdpy->xscr_number = DefaultScreen(xdpy->dpy);
xdpy->xscr = x11_screen_create(xdpy->dpy, xdpy->xscr_number);
if (!xdpy->xscr) {
@@ -714,13 +709,10 @@ x11_create_ximage_display(EGLNativeDisplayType dpy, boolean use_xshm)
return NULL;
}
- xdpy->use_xshm =
- (use_xshm && x11_screen_support(xdpy->xscr, X11_SCREEN_EXTENSION_XSHM));
-
- xdpy->winsys = create_sw_winsys();
- xdpy->base.screen = softpipe_create_screen(xdpy->winsys);
+ xdpy->base.screen = swrast_xlib_create_screen(xdpy->dpy);
xdpy->base.destroy = ximage_display_destroy;
+ xdpy->base.get_param = ximage_display_get_param;
xdpy->base.get_configs = ximage_display_get_configs;
xdpy->base.is_pixmap_supported = ximage_display_is_pixmap_supported;
diff --git a/src/gallium/state_trackers/egl/x11/sw_winsys.c b/src/gallium/state_trackers/egl/x11/sw_winsys.c
deleted file mode 100644
index 33328aadf2..0000000000
--- a/src/gallium/state_trackers/egl/x11/sw_winsys.c
+++ /dev/null
@@ -1,231 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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, sub license, 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 (including the
- * next paragraph) 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
- *
- **************************************************************************/
-
-/**
- * Totally software-based winsys layer.
- * Note that the one winsys function that we can't implement here
- * is flush_frontbuffer().
- * Whoever uses this code will have to provide that.
- *
- * Authors: Brian Paul
- */
-
-
-#include "util/u_simple_screen.h"
-#include "pipe/p_state.h"
-#include "util/u_inlines.h"
-#include "util/u_format.h"
-#include "util/u_math.h"
-#include "util/u_memory.h"
-
-#include "sw_winsys.h"
-
-
-
-/** Subclass of pipe_winsys */
-struct sw_pipe_winsys
-{
- struct pipe_winsys Base;
- /* no extra fields for now */
-};
-
-
-/** subclass of pipe_buffer */
-struct sw_pipe_buffer
-{
- struct pipe_buffer Base;
- boolean UserBuffer; /** Is this a user-space buffer? */
- void *Data;
- void *Mapped;
-};
-
-
-/** cast wrapper */
-static INLINE struct sw_pipe_buffer *
-sw_pipe_buffer(struct pipe_buffer *b)
-{
- return (struct sw_pipe_buffer *) b;
-}
-
-
-static const char *
-get_name(struct pipe_winsys *pws)
-{
- return "software";
-}
-
-
-/** Create new pipe_buffer and allocate storage of given size */
-static struct pipe_buffer *
-buffer_create(struct pipe_winsys *pws,
- unsigned alignment,
- unsigned usage,
- unsigned size)
-{
- struct sw_pipe_buffer *buffer = CALLOC_STRUCT(sw_pipe_buffer);
- if (!buffer)
- return NULL;
-
- pipe_reference_init(&buffer->Base.reference, 1);
- buffer->Base.alignment = alignment;
- buffer->Base.usage = usage;
- buffer->Base.size = size;
-
- /* align to 16-byte multiple for Cell */
- buffer->Data = align_malloc(size, MAX2(alignment, 16));
-
- return &buffer->Base;
-}
-
-
-/**
- * Create buffer which wraps user-space data.
- */
-static struct pipe_buffer *
-user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes)
-{
- struct sw_pipe_buffer *buffer = CALLOC_STRUCT(sw_pipe_buffer);
- if (!buffer)
- return NULL;
-
- pipe_reference_init(&buffer->Base.reference, 1);
- buffer->Base.size = bytes;
- buffer->UserBuffer = TRUE;
- buffer->Data = ptr;
-
- return &buffer->Base;
-}
-
-
-static void *
-buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buf, unsigned flags)
-{
- struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf);
- buffer->Mapped = buffer->Data;
- return buffer->Mapped;
-}
-
-
-static void
-buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf)
-{
- struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf);
- buffer->Mapped = NULL;
-}
-
-
-static void
-buffer_destroy(struct pipe_buffer *buf)
-{
- struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf);
-
- if (buffer->Data && !buffer->UserBuffer) {
- align_free(buffer->Data);
- buffer->Data = NULL;
- }
-
- free(buffer);
-}
-
-
-static struct pipe_buffer *
-surface_buffer_create(struct pipe_winsys *winsys,
- unsigned width, unsigned height,
- enum pipe_format format,
- unsigned usage,
- unsigned tex_usage,
- unsigned *stride)
-{
- const unsigned alignment = 64;
- unsigned nblocksy;
-
- nblocksy = util_format_get_nblocksy(format, height);
- *stride = align(util_format_get_stride(format, width), alignment);
-
- return winsys->buffer_create(winsys, alignment,
- usage,
- *stride * nblocksy);
-}
-
-
-static void
-fence_reference(struct pipe_winsys *sws, struct pipe_fence_handle **ptr,
- struct pipe_fence_handle *fence)
-{
- /* no-op */
-}
-
-
-static int
-fence_signalled(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
- unsigned flag)
-{
- /* no-op */
- return 0;
-}
-
-
-static int
-fence_finish(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
- unsigned flag)
-{
- /* no-op */
- return 0;
-}
-
-
-/**
- * Create/return a new pipe_winsys object.
- */
-struct pipe_winsys *
-create_sw_winsys(void)
-{
- struct sw_pipe_winsys *ws = CALLOC_STRUCT(sw_pipe_winsys);
- if (!ws)
- return NULL;
-
- /* Fill in this struct with callbacks that pipe will need to
- * communicate with the window system, buffer manager, etc.
- */
- ws->Base.buffer_create = buffer_create;
- ws->Base.user_buffer_create = user_buffer_create;
- ws->Base.buffer_map = buffer_map;
- ws->Base.buffer_unmap = buffer_unmap;
- ws->Base.buffer_destroy = buffer_destroy;
-
- ws->Base.surface_buffer_create = surface_buffer_create;
-
- ws->Base.fence_reference = fence_reference;
- ws->Base.fence_signalled = fence_signalled;
- ws->Base.fence_finish = fence_finish;
-
- ws->Base.flush_frontbuffer = NULL; /* not implemented here! */
-
- ws->Base.get_name = get_name;
-
- return &ws->Base;
-}
diff --git a/src/gallium/state_trackers/egl/x11/sw_winsys.h b/src/gallium/state_trackers/egl/x11/sw_winsys.h
deleted file mode 100644
index f96c5a14b0..0000000000
--- a/src/gallium/state_trackers/egl/x11/sw_winsys.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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, sub license, 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 (including the
- * next paragraph) 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
- *
- **************************************************************************/
-
-
-#ifndef SW_WINSYS_H
-#define SW_WINSYS_H
-
-
-struct pipe_winsys;
-
-
-extern struct pipe_winsys *
-create_sw_winsys(void);
-
-
-#endif /* SW_WINSYS_H */
diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.c b/src/gallium/state_trackers/egl/x11/x11_screen.c
index d72bfc99d3..f409611484 100644
--- a/src/gallium/state_trackers/egl/x11/x11_screen.c
+++ b/src/gallium/state_trackers/egl/x11/x11_screen.c
@@ -39,6 +39,9 @@
#include "glxinit.h"
struct x11_screen {
+ /* dummy base class */
+ struct __GLXDRIdisplayRec base;
+
Display *dpy;
int number;
@@ -53,6 +56,9 @@ struct x11_screen {
char *dri_device;
int dri_fd;
+ x11_drawable_invalidate_buffers dri_invalidate_buffers;
+ void *dri_user_data;
+
XVisualInfo *visuals;
int num_visuals;
@@ -98,6 +104,8 @@ x11_screen_destroy(struct x11_screen *xscr)
Xfree(xscr->dri_device);
/* xscr->glx_dpy will be destroyed with the X display */
+ if (xscr->glx_dpy)
+ xscr->glx_dpy->dri2Display = NULL;
if (xscr->visuals)
XFree(xscr->visuals);
@@ -247,24 +255,25 @@ x11_screen_get_glx_visuals(struct x11_screen *xscr)
: NULL;
}
-static boolean
-x11_screen_is_driver_equal(struct x11_screen *xscr, const char *driver)
-{
- return (strcmp(xscr->dri_driver, driver) == 0);
-}
-
/**
* Probe the screen for the DRI2 driver name.
*/
const char *
-x11_screen_probe_dri2(struct x11_screen *xscr)
+x11_screen_probe_dri2(struct x11_screen *xscr, int *major, int *minor)
{
+ if (!x11_screen_init_dri2(xscr))
+ return NULL;
+
/* get the driver name and the device name */
if (!xscr->dri_driver) {
if (!DRI2Connect(xscr->dpy, RootWindow(xscr->dpy, xscr->number),
&xscr->dri_driver, &xscr->dri_device))
xscr->dri_driver = xscr->dri_device = NULL;
}
+ if (major)
+ *major = xscr->dri_major;
+ if (minor)
+ *minor = xscr->dri_minor;
return xscr->dri_driver;
}
@@ -274,21 +283,17 @@ x11_screen_probe_dri2(struct x11_screen *xscr)
* descriptor will be closed automatically when the screen is destoryed.
*/
int
-x11_screen_enable_dri2(struct x11_screen *xscr, const char *driver)
+x11_screen_enable_dri2(struct x11_screen *xscr,
+ x11_drawable_invalidate_buffers invalidate_buffers,
+ void *user_data)
{
if (xscr->dri_fd < 0) {
int fd;
drm_magic_t magic;
/* get the driver name and the device name first */
- if (!x11_screen_probe_dri2(xscr))
- return -1;
-
- if (!x11_screen_is_driver_equal(xscr, driver)) {
- _eglLog(_EGL_WARNING, "Driver mismatch: %s != %s",
- xscr->dri_driver, driver);
+ if (!x11_screen_probe_dri2(xscr, NULL, NULL))
return -1;
- }
fd = open(xscr->dri_device, O_RDWR);
if (fd < 0) {
@@ -310,6 +315,22 @@ x11_screen_enable_dri2(struct x11_screen *xscr, const char *driver)
return -1;
}
+ if (!x11_screen_init_glx(xscr)) {
+ _eglLog(_EGL_WARNING, "failed to initialize GLX");
+ close(fd);
+ return -1;
+ }
+ if (xscr->glx_dpy->dri2Display) {
+ _eglLog(_EGL_WARNING,
+ "display is already managed by another x11 screen");
+ close(fd);
+ return -1;
+ }
+
+ xscr->glx_dpy->dri2Display = (__GLXDRIdisplay *) xscr;
+ xscr->dri_invalidate_buffers = invalidate_buffers;
+ xscr->dri_user_data = user_data;
+
xscr->dri_fd = fd;
}
@@ -451,3 +472,20 @@ x11_context_modes_count(const __GLcontextModes *modes)
count++;
return count;
}
+
+/**
+ * This is called from src/glx/dri2.c.
+ */
+void
+dri2InvalidateBuffers(Display *dpy, XID drawable)
+{
+ __GLXdisplayPrivate *priv = __glXInitialize(dpy);
+ struct x11_screen *xscr = NULL;
+
+ if (priv && priv->dri2Display)
+ xscr = (struct x11_screen *) priv->dri2Display;
+ if (!xscr || !xscr->dri_invalidate_buffers)
+ return;
+
+ xscr->dri_invalidate_buffers(xscr, drawable, xscr->dri_user_data);
+}
diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.h b/src/gallium/state_trackers/egl/x11/x11_screen.h
index 5432858ac3..37e8d5a40e 100644
--- a/src/gallium/state_trackers/egl/x11/x11_screen.h
+++ b/src/gallium/state_trackers/egl/x11/x11_screen.h
@@ -48,6 +48,10 @@ struct x11_drawable_buffer {
struct x11_screen;
+typedef void (*x11_drawable_invalidate_buffers)(struct x11_screen *xscr,
+ Drawable drawable,
+ void *user_data);
+
struct x11_screen *
x11_screen_create(Display *dpy, int screen);
@@ -71,10 +75,12 @@ const __GLcontextModes *
x11_screen_get_glx_visuals(struct x11_screen *xscr);
const char *
-x11_screen_probe_dri2(struct x11_screen *xscr);
+x11_screen_probe_dri2(struct x11_screen *xscr, int *major, int *minor);
int
-x11_screen_enable_dri2(struct x11_screen *xscr, const char *driver);
+x11_screen_enable_dri2(struct x11_screen *xscr,
+ x11_drawable_invalidate_buffers invalidate_buffers,
+ void *user_data);
__GLcontextModes *
x11_context_modes_create(unsigned count);