From fd54564f78d4aeae2c39ada7502ec659c14b3eca Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 19 May 2007 08:27:35 -0600 Subject: Implement GLX_EXT_texture_from_pixmap. Could be done more efficiently... but works. --- src/mesa/drivers/x11/xm_api.c | 247 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 235 insertions(+), 12 deletions(-) (limited to 'src/mesa/drivers/x11/xm_api.c') diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index a07d0a90cf..edaa71508f 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.5.2 + * Version: 7.1 * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -72,6 +72,7 @@ #include "imports.h" #include "macros.h" #include "renderbuffer.h" +#include "teximage.h" #include "swrast/swrast.h" #include "swrast_setup/swrast_setup.h" #include "vbo/vbo.h" @@ -295,6 +296,19 @@ static GLboolean window_exists( XMesaDisplay *dpy, Window win ) #endif +static Status +get_drawable_size(Display *dpy, Drawable d, GLuint *width, GLuint *height) +{ + Window root; + Status stat; + int xpos, ypos; + unsigned int w, h, bw, depth; + stat = XGetGeometry(dpy, d, &root, &xpos, &ypos, &w, &h, &bw, &depth); + *width = w; + *height = h; + return stat; +} + /** * Return the size of the window (or pixmap) that corresponds to the @@ -310,22 +324,14 @@ xmesa_get_window_size(XMesaDisplay *dpy, XMesaBuffer b, *width = MIN2(b->frontxrb->drawable->width, MAX_WIDTH); *height = MIN2(b->frontxrb->drawable->height, MAX_HEIGHT); #else - Window root; Status stat; - int xpos, ypos; - unsigned int w, h, bw, depth; _glthread_LOCK_MUTEX(_xmesa_lock); XSync(b->xm_visual->display, 0); /* added for Chromium */ - stat = XGetGeometry(dpy, b->frontxrb->pixmap, &root, &xpos, &ypos, - &w, &h, &bw, &depth); + stat = get_drawable_size(dpy, b->frontxrb->pixmap, width, height); _glthread_UNLOCK_MUTEX(_xmesa_lock); - if (stat) { - *width = w; - *height = h; - } - else { + if (!stat) { /* probably querying a window that's recently been destroyed */ _mesa_warning(NULL, "XGetGeometry failed!\n"); *width = *height = 1; @@ -431,6 +437,11 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, b->swAlpha, vis->mesa_visual.numAuxBuffers > 0 ); + /* GLX_EXT_texture_from_pixmap */ + b->TextureTarget = 0; + b->TextureFormat = GLX_TEXTURE_FORMAT_NONE_EXT; + b->TextureMipmap = 0; + /* insert buffer into linked list */ b->Next = XMesaBufferList; XMesaBufferList = b; @@ -1673,6 +1684,67 @@ XMesaCreatePixmapBuffer(XMesaVisual v, XMesaPixmap p, XMesaColormap cmap) } +/** + * For GLX_EXT_texture_from_pixmap + */ +XMesaBuffer +XMesaCreatePixmapTextureBuffer(XMesaVisual v, XMesaPixmap p, + XMesaColormap cmap, + int format, int target, int mipmap) +{ + GET_CURRENT_CONTEXT(ctx); + XMesaBuffer b; + GLuint width, height; + + assert(v); + + b = create_xmesa_buffer((XMesaDrawable) p, PIXMAP, v, cmap); + if (!b) + return NULL; + + /* get pixmap size, update framebuffer/renderbuffer dims */ + get_drawable_size(v->display, p, &width, &height); + _mesa_resize_framebuffer(NULL, &(b->mesa_buffer), width, height); + + if (target == 0) { + /* examine dims */ + if (ctx->Extensions.ARB_texture_non_power_of_two) { + target = GLX_TEXTURE_2D_EXT; + } + else if ( _mesa_bitcount(width) == 1 + && _mesa_bitcount(height) == 1) { + /* power of two size */ + if (height == 1) { + target = GLX_TEXTURE_1D_EXT; + } + else { + target = GLX_TEXTURE_2D_EXT; + } + } + else if (ctx->Extensions.NV_texture_rectangle) { + target = GLX_TEXTURE_RECTANGLE_EXT; + } + else { + /* non power of two textures not supported */ + XMesaDestroyBuffer(b); + return 0; + } + } + + b->TextureTarget = target; + b->TextureFormat = format; + b->TextureMipmap = mipmap; + + if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode, + (XMesaDrawable) p, cmap)) { + xmesa_free_buffer(b); + return NULL; + } + + return b; +} + + XMesaBuffer XMesaCreatePBuffer(XMesaVisual v, XMesaColormap cmap, @@ -2254,3 +2326,154 @@ XMesaResizeBuffers( XMesaBuffer b ) xmesa_check_and_update_buffer_size(xmctx, b); } + +static GLint +xbuffer_to_renderbuffer(int buffer) +{ + assert(MAX_AUX_BUFFERS <= 4); + + switch (buffer) { + case GLX_FRONT_LEFT_EXT: + return BUFFER_FRONT_LEFT; + case GLX_FRONT_RIGHT_EXT: + return BUFFER_FRONT_RIGHT; + case GLX_BACK_LEFT_EXT: + return BUFFER_BACK_LEFT; + case GLX_BACK_RIGHT_EXT: + return BUFFER_BACK_RIGHT; + case GLX_AUX0_EXT: + return BUFFER_AUX0; + case GLX_AUX1_EXT: + return BUFFER_AUX1; + case GLX_AUX2_EXT: + return BUFFER_AUX2; + case GLX_AUX3_EXT: + return BUFFER_AUX3; + case GLX_AUX4_EXT: + case GLX_AUX5_EXT: + case GLX_AUX6_EXT: + case GLX_AUX7_EXT: + case GLX_AUX8_EXT: + case GLX_AUX9_EXT: + default: + /* BadValue error */ + return -1; + } +} + + +PUBLIC void +XMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer, + const int *attrib_list) +{ +#if 0 + GET_CURRENT_CONTEXT(ctx); + const GLuint unit = ctx->Texture.CurrentUnit; + struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; + struct gl_texture_object *texObj; +#endif + struct gl_renderbuffer *rb; + struct xmesa_renderbuffer *xrb; + GLint b; + XMesaImage *img; + GLboolean freeImg = GL_FALSE; + + b = xbuffer_to_renderbuffer(buffer); + if (b < 0) + return; + + if (drawable->TextureFormat == GLX_TEXTURE_FORMAT_NONE_EXT) + return; /* BadMatch error */ + + rb = drawable->mesa_buffer.Attachment[b].Renderbuffer; + if (!rb) { + /* invalid buffer */ + return; + } + xrb = xmesa_renderbuffer(rb); + +#if 0 + switch (drawable->TextureTarget) { + case GLX_TEXTURE_1D_EXT: + texObj = texUnit->Current1D; + break; + case GLX_TEXTURE_2D_EXT: + texObj = texUnit->Current2D; + break; + case GLX_TEXTURE_RECTANGLE_EXT: + texObj = texUnit->CurrentRect; + break; + default: + return; /* BadMatch error */ + } +#endif + + /* + * The following is a quick and simple way to implement + * BindTexImage. The better way is to write some new FetchTexel() + * functions which would extract texels from XImages. We'd still + * need to use XGetImage when texturing from a Pixmap (front buffer) + * but texturing from a back buffer (XImage) would avoid an image + * copy. + */ + + /* get XImage */ + if (xrb->pixmap) { + img = XGetImage(dpy, xrb->pixmap, 0, 0, rb->Width, rb->Height, + AllPlanes, ZPixmap ); + freeImg = GL_TRUE; + } + else if (xrb->ximage) { + img = xrb->ximage; + } + + /* store the XImage as a new texture image */ + if (img) { + GLenum format, type, intFormat; + if (img->bits_per_pixel == 32) { + format = GL_BGRA; + type = GL_UNSIGNED_BYTE; + intFormat = GL_RGBA; + } + else if (img->bits_per_pixel == 24) { + format = GL_BGR; + type = GL_UNSIGNED_BYTE; + intFormat = GL_RGB; + } + else if (img->bits_per_pixel == 16) { + format = GL_BGR; + type = GL_UNSIGNED_SHORT_5_6_5; + intFormat = GL_RGB; + } + else { + _mesa_problem(NULL, "Unexpected XImage format in XMesaBindTexImage"); + return; + } + if (drawable->TextureFormat == GLX_TEXTURE_FORMAT_RGBA_EXT) { + intFormat = GL_RGBA; + } + else if (drawable->TextureFormat == GLX_TEXTURE_FORMAT_RGB_EXT) { + intFormat = GL_RGB; + } + + _mesa_TexImage2D(GL_TEXTURE_2D, 0, intFormat, rb->Width, rb->Height, 0, + format, type, img->data); + + if (freeImg) { + XMesaDestroyImage(img); + } + } +} + + + +PUBLIC void +XMesaReleaseTexImage(Display *dpy, XMesaBuffer drawable, int buffer) +{ + const GLint b = xbuffer_to_renderbuffer(buffer); + if (b < 0) + return; + + /* no-op for now */ +} + -- cgit v1.2.3 From 24d965fab52f790188e5de6e67e7387809b1f145 Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Tue, 22 May 2007 13:56:30 +0200 Subject: Fix xserver build after recent XMesa changes. Only build tested. --- include/GL/xmesa.h | 4 ++-- include/GL/xmesa_x.h | 1 + include/GL/xmesa_xf86.h | 29 ++++++++++++++++++++++++++++- src/mesa/drivers/x11/xm_api.c | 20 ++++++++++---------- src/mesa/drivers/x11/xm_image.h | 7 ------- 5 files changed, 41 insertions(+), 20 deletions(-) (limited to 'src/mesa/drivers/x11/xm_api.c') diff --git a/include/GL/xmesa.h b/include/GL/xmesa.h index 2199b08cf0..98139af833 100644 --- a/include/GL/xmesa.h +++ b/include/GL/xmesa.h @@ -402,11 +402,11 @@ extern XMesaBuffer XMesaCreatePBuffer(XMesaVisual v, XMesaColormap cmap, * New in Mesa 7.1 */ extern void -XMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer, +XMesaBindTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer, const int *attrib_list); extern void -XMesaReleaseTexImage(Display *dpy, XMesaBuffer drawable, int buffer); +XMesaReleaseTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer); extern XMesaBuffer diff --git a/include/GL/xmesa_x.h b/include/GL/xmesa_x.h index 721d8b5107..865bab4313 100644 --- a/include/GL/xmesa_x.h +++ b/include/GL/xmesa_x.h @@ -66,6 +66,7 @@ typedef XColor XMesaColor; #define XMesaDrawPoints XDrawPoints #define XMesaDrawLine XDrawLine #define XMesaFillRectangle XFillRectangle +#define XMesaGetImage XGetImage #define XMesaPutImage XPutImage #define XMesaCopyArea XCopyArea diff --git a/include/GL/xmesa_xf86.h b/include/GL/xmesa_xf86.h index 0a15110f65..18908a133f 100644 --- a/include/GL/xmesa_xf86.h +++ b/include/GL/xmesa_xf86.h @@ -42,8 +42,15 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "scrnintstr.h" #include "pixmapstr.h" #include "gcstruct.h" +#include "servermd.h" -typedef struct _XMesaImageRec XMesaImage; + +typedef struct _XMesaImageRec { + int width, height; + char *data; + int bytes_per_line; /* Padded to 32 bits */ + int bits_per_pixel; +} XMesaImage; typedef ScreenRec XMesaDisplay; typedef PixmapPtr XMesaPixmap; @@ -120,6 +127,26 @@ do { \ (*__gc->ops->PolyFillRect)((DrawablePtr)__b, __gc, 1, __r); \ } while (0) +static _X_INLINE XMesaImage *XMesaGetImage(XMesaDisplay *dpy, PixmapPtr p, int x, + int y, unsigned int width, + unsigned int height, + unsigned long plane_mask, int format) +{ + XMesaImage *img = Xcalloc(sizeof(*img)); + + img->width = p->drawable.width; + img->height = p->drawable.height; + img->bits_per_pixel = p->drawable.bitsPerPixel; + img->bytes_per_line = PixmapBytePad(width, p->drawable.depth); + img->data = malloc(height * img->bytes_per_line); + + /* Assumes: Images are always in ZPixmap format */ + (*p->drawable.pScreen->GetImage)(&p->drawable, x, y, width, height, + plane_mask, ZPixmap, img->data); + + return img; +} + #define XMesaPutImage(__d,__b,__gc,__i,__sx,__sy,__x,__y,__w,__h) \ do { \ /* Assumes: Images are always in ZPixmap format */ \ diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index edaa71508f..cff64d17ad 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -63,6 +63,7 @@ #endif #include "glxheader.h" +#include "GL/glxtokens.h" #include "GL/xmesa.h" #include "xmesaP.h" #include "context.h" @@ -293,11 +294,9 @@ static GLboolean window_exists( XMesaDisplay *dpy, Window win ) XSetErrorHandler(old_handler); return WindowExistsFlag; } -#endif - static Status -get_drawable_size(Display *dpy, Drawable d, GLuint *width, GLuint *height) +get_drawable_size( XMesaDisplay *dpy, Drawable d, GLuint *width, GLuint *height ) { Window root; Status stat; @@ -308,6 +307,7 @@ get_drawable_size(Display *dpy, Drawable d, GLuint *width, GLuint *height) *height = h; return stat; } +#endif /** @@ -1703,7 +1703,7 @@ XMesaCreatePixmapTextureBuffer(XMesaVisual v, XMesaPixmap p, return NULL; /* get pixmap size, update framebuffer/renderbuffer dims */ - get_drawable_size(v->display, p, &width, &height); + xmesa_get_window_size(v->display, b, &width, &height); _mesa_resize_framebuffer(NULL, &(b->mesa_buffer), width, height); if (target == 0) { @@ -2363,7 +2363,7 @@ xbuffer_to_renderbuffer(int buffer) PUBLIC void -XMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer, +XMesaBindTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer, const int *attrib_list) { #if 0 @@ -2375,7 +2375,7 @@ XMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer, struct gl_renderbuffer *rb; struct xmesa_renderbuffer *xrb; GLint b; - XMesaImage *img; + XMesaImage *img = NULL; GLboolean freeImg = GL_FALSE; b = xbuffer_to_renderbuffer(buffer); @@ -2412,15 +2412,15 @@ XMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer, * The following is a quick and simple way to implement * BindTexImage. The better way is to write some new FetchTexel() * functions which would extract texels from XImages. We'd still - * need to use XGetImage when texturing from a Pixmap (front buffer) + * need to use GetImage when texturing from a Pixmap (front buffer) * but texturing from a back buffer (XImage) would avoid an image * copy. */ /* get XImage */ if (xrb->pixmap) { - img = XGetImage(dpy, xrb->pixmap, 0, 0, rb->Width, rb->Height, - AllPlanes, ZPixmap ); + img = XMesaGetImage(dpy, xrb->pixmap, 0, 0, rb->Width, rb->Height, ~0L, + ZPixmap); freeImg = GL_TRUE; } else if (xrb->ximage) { @@ -2468,7 +2468,7 @@ XMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer, PUBLIC void -XMesaReleaseTexImage(Display *dpy, XMesaBuffer drawable, int buffer) +XMesaReleaseTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer) { const GLint b = xbuffer_to_renderbuffer(buffer); if (b < 0) diff --git a/src/mesa/drivers/x11/xm_image.h b/src/mesa/drivers/x11/xm_image.h index 240ccee1af..2a5e0f3777 100644 --- a/src/mesa/drivers/x11/xm_image.h +++ b/src/mesa/drivers/x11/xm_image.h @@ -36,13 +36,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define XMESA_USE_PUTPIXEL_MACRO -struct _XMesaImageRec { - int width, height; - char *data; - int bytes_per_line; /* Padded to 32 bits */ - int bits_per_pixel; -}; - extern XMesaImage *XMesaCreateImage(int bitsPerPixel, int width, int height, char *data); extern void XMesaDestroyImage(XMesaImage *image); -- cgit v1.2.3 From e734369565c816dea47c3c8e2fde76fa09fd9e6c Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 25 May 2007 08:57:44 -0600 Subject: remove #include "GL/glxtokens.h" --- src/mesa/drivers/x11/xm_api.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/mesa/drivers/x11/xm_api.c') diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index cff64d17ad..eaa277db4a 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -63,7 +63,6 @@ #endif #include "glxheader.h" -#include "GL/glxtokens.h" #include "GL/xmesa.h" #include "xmesaP.h" #include "context.h" -- cgit v1.2.3