diff options
Diffstat (limited to 'generic/tkZinc.c')
-rw-r--r-- | generic/tkZinc.c | 268 |
1 files changed, 76 insertions, 192 deletions
diff --git a/generic/tkZinc.c b/generic/tkZinc.c index 793d2a9..e4a5f8f 100644 --- a/generic/tkZinc.c +++ b/generic/tkZinc.c @@ -61,14 +61,11 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " #include <string.h> #include <math.h> #include <X11/Xatom.h> -#ifdef SHM -#include <sys/shm.h> -#include <X11/extensions/XShm.h> -#endif #ifdef GLX #include <GL/glx.h> #endif +/*#define PRINT_CONFIG*/ #if 0 typedef struct TagSearch { @@ -128,7 +125,7 @@ static unsigned char dither4x4[4][4] = { { 3, 11, 1, 9 }, { 15, 7, 13, 5 } }; -static unsigned char bitmaps[NUM_ALPHA_STEPS][8]; +static unsigned char bitmaps[NUM_ALPHA_STEPS][32][4]; static ZnBool inited = False; static Tk_Uid all_uid; @@ -376,75 +373,6 @@ ZnNeedRedisplay(WidgetInfo *wi) /* *---------------------------------------------------------------------- * - * CreateSharedImageBuffer -- - * - *---------------------------------------------------------------------- - */ -#ifdef LIBART -#ifdef SHM -void -CreateSharedImageBuffer(WidgetInfo *wi) -{ - /* - * Allocate a shared image to be used as the back buffer. - * The sequence is extracted from gdk image. - */ - wi->draw_buffer_im = XShmCreateImage(wi->dpy, Tk_Visual(wi->win), Tk_Depth(wi->win), - ZPixmap, NULL, &wi->x_shm_info, - wi->width, wi->height); - if (wi->draw_buffer_im == NULL) { - ZnWarning("XShmCreateImage failed, unable to use local rendering"); - wi->render = False; - } - else { - wi->x_shm_info.shmid = shmget(IPC_PRIVATE, - wi->draw_buffer_im->bytes_per_line * - wi->draw_buffer_im->height, - IPC_CREAT | 0777); - if (wi->x_shm_info.shmid == -1) { - XDestroyImage(wi->draw_buffer_im); - wi->draw_buffer_im = NULL; - ZnWarning("shmget failed, unable to use local rendering"); - wi->render = False; - } - else { - wi->x_shm_info.readOnly = False; - wi->x_shm_info.shmaddr = shmat(wi->x_shm_info.shmid, 0, 0); - wi->draw_buffer_im->data = wi->x_shm_info.shmaddr; - if (wi->x_shm_info.shmaddr == (char *) -1) { - shmctl(wi->x_shm_info.shmid, IPC_RMID, 0); - XDestroyImage(wi->draw_buffer_im); - wi->draw_buffer_im = NULL; - ZnWarning("shmat failed, unable to use local rendering"); - wi->render = False; - } - else { - wi->buf.buf = ZnMalloc(wi->draw_buffer_im->bytes_per_line * - wi->draw_buffer_im->height * 3); - wi->buf.rowstride = wi->draw_buffer_im->bytes_per_line * 3; - wi->buf.ox = wi->buf.oy = 0; - wi->buf.cx = wi->width; - wi->buf.cy = wi->height; - XShmAttach(wi->dpy, &wi->x_shm_info); - XSync(wi->dpy, False); - /* We mark the segment as destroyed so that when - * the last process detaches, it will be deleted. - * There is a small possibility of leaking if - * we die in XShmAttach. In theory, a signal handler - * could be set up. - */ - shmctl(wi->x_shm_info.shmid, IPC_RMID, 0); - } - } - } -} -#endif -#endif - - -/* - *---------------------------------------------------------------------- - * * ZincObjCmd -- * * This procedure is invoked to process the "zinc" Tcl @@ -452,7 +380,6 @@ CreateSharedImageBuffer(WidgetInfo *wi) * *---------------------------------------------------------------------- */ - int ZincObjCmd(ClientData client_data, /* Main window associated with * interpreter. */ @@ -464,7 +391,7 @@ ZincObjCmd(ClientData client_data, /* Main window associated with WidgetInfo *wi; Tk_Window tkwin; unsigned int num; - int major_op, minor_op, first_err, first_evt; + int major_op, first_err, first_evt; if (!inited) { InitZinc(interp); @@ -493,32 +420,20 @@ ZincObjCmd(ClientData client_data, /* Main window associated with wi->interp = interp; wi->dpy = Tk_Display(tkwin); wi->screen = Tk_Screen(tkwin); - wi->has_glx = False; #ifdef GLX if (glXQueryExtension(wi->dpy, &first_err, &first_evt)) { + int minor_op; if (glXQueryVersion(wi->dpy, &major_op, &minor_op)) { - if ((major_op == 1) && (minor_op >= 2)) { -#if 0 + if ((major_op == 1) && (minor_op >= 1)) { +#if 1 printf("GLX version %d.%d\n", major_op, minor_op); - printf("OpenGL version %s\n", (char *) glGetString(GL_VERSION)); - printf(" moteur de rendu : %s\n", (char *) glGetString(GL_RENDERER)); - printf(" fabriquant : %s\n", (char *) glGetString(GL_VENDOR)); - printf(" extensions présentes : %s\n", (char *) glGetString(GL_EXTENSIONS)); -#endif +#endif wi->has_glx = True; } } } #endif - wi->has_x_shm = False; -#ifdef SHM - if (XQueryExtension(wi->dpy, "MIT-SHM", &major_op, &first_evt, &first_err)) { - ZnBool pixmaps; - if (XShmQueryVersion(wi->dpy, &major_op, &minor_op, &pixmaps) == True) { - wi->has_x_shm = True; - } - } -#endif + #ifdef SHAPE wi->has_x_shape = XQueryExtension(wi->dpy, "SHAPE", &major_op, &first_evt, &first_err); @@ -581,9 +496,6 @@ ZincObjCmd(ClientData client_data, /* Main window associated with #endif wi->gc = 0; wi->draw_buffer = 0; -#ifdef LIBART - wi->draw_buffer_im = 0; -#endif wi->events_flags = 0; wi->pick_aperture = 0; wi->new_item = wi->current_item = ZN_NO_ITEM; @@ -596,8 +508,11 @@ ZincObjCmd(ClientData client_data, /* Main window associated with wi->work_item_list = NULL; wi->work_pts = ZnListNew(8, sizeof(ZnPoint)); +#ifdef GLX + wi->work_doubles = ZnListNew(8, sizeof(double)); +#endif wi->work_xpts = ZnListNew(8, sizeof(XPoint)); - + /* * Text management init. */ @@ -654,18 +569,16 @@ ZincObjCmd(ClientData client_data, /* Main window associated with * Allocate double buffer pixmap/image. */ if (wi->render) { -#ifdef LIBART -#ifdef SHM - CreateSharedImageBuffer(wi); -#endif -#endif #ifdef GLX if (wi->has_glx) { +#ifdef PRINT_CONFIG int val; +#endif int attribs[] = { GLX_RGBA, GLX_DOUBLEBUFFER, - GLX_BUFFER_SIZE, 16, - GLX_STENCIL_SIZE, 1, + GLX_BUFFER_SIZE, 32, + GLX_STENCIL_SIZE, 8, + GLX_ALPHA_SIZE, 8, None }; wi->gl_visual = glXChooseVisual(wi->dpy, XScreenNumberOfScreen(wi->screen), attribs); @@ -674,32 +587,34 @@ ZincObjCmd(ClientData client_data, /* Main window associated with wi->render = False; } else { - printf("Visual is 0x%x, ", (int) wi->gl_visual->visualid); - glXGetConfig(wi->dpy, wi->gl_visual, GLX_RGBA, &val); - printf("RGBA %d, ", val); - glXGetConfig(wi->dpy, wi->gl_visual, GLX_DOUBLEBUFFER, &val); - printf("Double Buffer %d, ", val); - glXGetConfig(wi->dpy, wi->gl_visual, GLX_STENCIL_SIZE, &val); - printf("Stencil %d, ", val); - glXGetConfig(wi->dpy, wi->gl_visual, GLX_BUFFER_SIZE, &val); - printf("depth %d, ", val); - glXGetConfig(wi->dpy, wi->gl_visual, GLX_RED_SIZE, &val); - printf("red %d, ", val); - glXGetConfig(wi->dpy, wi->gl_visual, GLX_GREEN_SIZE, &val); - printf("green %d, ", val); - glXGetConfig(wi->dpy, wi->gl_visual, GLX_BLUE_SIZE, &val); - printf("blue %d, ", val); - glXGetConfig(wi->dpy, wi->gl_visual, GLX_ALPHA_SIZE, &val); - printf("alpha %d\n", val); wi->gl_context = glXCreateContext(wi->dpy, wi->gl_visual, NULL, True); if (!wi->gl_context) { printf("No glx context\n"); wi->render = False; } else { - printf("Context: %d\n", glXIsDirect(wi->dpy, wi->gl_context)); +#if PRINT_CONFIG + printf(" Visual : 0x%x, ", (int) wi->gl_visual->visualid); + glXGetConfig(wi->dpy, wi->gl_visual, GLX_RGBA, &val); + printf("RGBA : %d, ", val); + glXGetConfig(wi->dpy, wi->gl_visual, GLX_DOUBLEBUFFER, &val); + printf("Double Buffer : %d, ", val); + glXGetConfig(wi->dpy, wi->gl_visual, GLX_STENCIL_SIZE, &val); + printf("Stencil : %d, ", val); + glXGetConfig(wi->dpy, wi->gl_visual, GLX_BUFFER_SIZE, &val); + printf("depth : %d, ", val); + glXGetConfig(wi->dpy, wi->gl_visual, GLX_RED_SIZE, &val); + printf("red : %d, ", val); + glXGetConfig(wi->dpy, wi->gl_visual, GLX_GREEN_SIZE, &val); + printf("green : %d, ", val); + glXGetConfig(wi->dpy, wi->gl_visual, GLX_BLUE_SIZE, &val); + printf("blue : %d, ", val); + glXGetConfig(wi->dpy, wi->gl_visual, GLX_ALPHA_SIZE, &val); + printf("alpha : %d\n", val); + printf(" Direct Rendering: %d\n", glXIsDirect(wi->dpy, wi->gl_context)); +#endif Tk_SetWindowVisual(wi->win, wi->gl_visual->visual, - 16, + 24, XCreateColormap(wi->dpy, RootWindowOfScreen(wi->screen), wi->gl_visual->visual, AllocNone)); } @@ -3045,7 +2960,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ Tcl_WrongNumArgs(interp, 1, args, "currentpart"); goto error; } - if (wi->current_item->class->Part != NULL) { + if ((wi->current_item != ZN_NO_ITEM) && (wi->current_item->class->Part != NULL)) { l = NULL; wi->current_item->class->Part(wi->current_item, &l, &wi->current_part); Tcl_SetObjResult(interp, l); @@ -4317,35 +4232,6 @@ Configure(Tcl_Interp *interp,/* Used for error reporting. */ return ZN_ERROR; } -#ifdef LIBART - if (flags & TK_CONFIG_ARGV_ONLY) { - /* - * Do not allow modification of the rendering scheme after - * the widget creation. - */ - wi->render = render; - } - else { - Visual *visual; - int depth; - /* - * Turn off local rendering if shared memory is not supported. - * or if we cannot use the chosen visual, we cannot work with - * any visuals, only true color, 16, 24, 32 bits, and perhaps 15 bits - * and direct color (to be checked). - */ - wi->render = wi->render && wi->has_x_shm; - if (wi->render) { - visual = Tk_Visual(wi->win); - depth = Tk_Depth(wi->win); - if (((visual->class != TrueColor) && (visual->class != DirectColor)) || - ((depth != 16) && (depth != 24) && (depth != 32))) { - wi->render = False; - } - } - } -#endif - /* * Maintain the pick aperture within meaningful bounds. */ @@ -4555,7 +4441,21 @@ Event(ClientData client_data, /* Information about widget. */ wi->realized = True; #ifdef GLX if (wi->render) { + GLfloat r[2]; + glXMakeCurrent(wi->dpy, ZnWindowId(wi->win), wi->gl_context); + /*glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, r);*/ + glGetFloatv(GL_SMOOTH_LINE_WIDTH_RANGE, r); + wi->max_line_width = r[1]; + /*glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, r);*/ + glGetFloatv(GL_SMOOTH_POINT_SIZE_RANGE, r); + wi->max_point_width = r[1]; +#if PRINT_CONFIG + printf("OpenGL version %s\n", (char *) glGetString(GL_VERSION)); + printf(" Moteur de rendu : %s, ", (char *) glGetString(GL_RENDERER)); + printf(" Fabriquant : %s\n", (char *) glGetString(GL_VENDOR)); + printf(" Extensions présentes : %s\n", (char *) glGetString(GL_EXTENSIONS)); +#endif } #endif /* @@ -4651,20 +4551,6 @@ Event(ClientData client_data, /* Information about widget. */ /* * Reallocate the double buffer pixmap/image. */ - if (wi->render) { -#ifdef LIBART -#ifdef SHM - /* Free the image and allocate a bigger one. */ - XShmDetach(wi->dpy, &wi->x_shm_info); - XDestroyImage(wi->draw_buffer_im); - wi->draw_buffer_im = NULL; - shmdt(wi->x_shm_info.shmaddr); - shmctl(wi->x_shm_info.shmid, IPC_RMID, 0); - ZnFree(wi->buf.buf); - CreateSharedImageBuffer(wi); -#endif -#endif - } if (!wi->render) { XFreePixmap(wi->dpy, wi->draw_buffer); wi->draw_buffer = XCreatePixmap(wi->dpy, RootWindowOfScreen(wi->screen), @@ -5439,17 +5325,6 @@ Destroy(char *mem_ptr) /* Info about the widget. */ if (wi->draw_buffer) { XFreePixmap(wi->dpy, wi->draw_buffer); } -#ifdef LIBART -#ifdef SHM - if (wi->draw_buffer_im) { - XShmDetach(wi->dpy, &wi->x_shm_info); - XDestroyImage(wi->draw_buffer_im); - shmdt(wi->x_shm_info.shmaddr); - shmctl(wi->x_shm_info.shmid, IPC_RMID, 0); - ZnFree(wi->buf.buf); - } -#endif -#endif #ifdef GLX if (wi->gl_context) { glXDestroyContext(wi->dpy, wi->gl_context); @@ -5470,8 +5345,11 @@ Destroy(char *mem_ptr) /* Info about the widget. */ ITEM_P.FreeClipStack(wi); ZnListFree(wi->work_pts); +#ifdef GLX + ZnListFree(wi->work_doubles); +#endif ZnListFree(wi->work_xpts); - + FreeChrono(wi->total_draw_chrono); FreeChrono(wi->this_draw_chrono); @@ -5562,12 +5440,6 @@ Redisplay(ClientData client_data) /* Information about the widget. */ if (!IsEmptyBBox(&merge)) { BBox2XRect(&merge, &r); if (wi->render) { -#ifdef LIBART -#ifdef SHM - XPutImage(wi->dpy, ZnWindowId(wi->win), wi->gc, wi->draw_buffer_im, - r.x, r.y, r.x+wi->inset, r.y+wi->inset, r.width, r.height); -#endif -#endif #ifdef GLX /* Switch the GL buffers. */ glXSwapBuffers(wi->dpy, ZnWindowId(wi->win)); @@ -6513,8 +6385,7 @@ InitZinc(Tcl_Interp *interp) { for (i = 0; i < NUM_ALPHA_STEPS; i++) { for (y = 0; y < 4; y++) { - bitmaps[i][y] = 0; - bitmaps[i][y+4] = 0; + bitmaps[i][y][0] = 0; for (x = 0; x < 4; x++) { /* * Use the dither4x4 matrix to determine if this bit is on @@ -6525,15 +6396,28 @@ InitZinc(Tcl_Interp *interp) { * mirror the pattern in x & y to make an 8x8 bitmap. */ if (bit) { - bitmaps[i][y] |= (1 << x); - bitmaps[i][y] |= (1 << (4 + x)); - bitmaps[i][4+y] |= (1 << x); - bitmaps[i][4+y] |= (1 << (4 + x)); + bitmaps[i][y][0] |= (1 << x); + bitmaps[i][y][0] |= (1 << (4 + x)); } } + bitmaps[i][y][1] = bitmaps[i][y][2] = bitmaps[i][y][3] = bitmaps[i][y][0]; + bitmaps[i][y+4][0] = bitmaps[i][y+4][1] = bitmaps[i][y][0]; + bitmaps[i][y+4][2] = bitmaps[i][y+4][3] = bitmaps[i][y][0]; + bitmaps[i][y+8][0] = bitmaps[i][y+8][1] = bitmaps[i][y][0]; + bitmaps[i][y+8][2] = bitmaps[i][y+8][3] = bitmaps[i][y][0]; + bitmaps[i][y+12][0] = bitmaps[i][y+12][1] = bitmaps[i][y][0]; + bitmaps[i][y+12][2] = bitmaps[i][y+12][3] = bitmaps[i][y][0]; + bitmaps[i][y+16][0] = bitmaps[i][y+16][1] = bitmaps[i][y][0]; + bitmaps[i][y+16][2] = bitmaps[i][y+16][3] = bitmaps[i][y][0]; + bitmaps[i][y+20][0] = bitmaps[i][y+20][1] = bitmaps[i][y][0]; + bitmaps[i][y+20][2] = bitmaps[i][y+20][3] = bitmaps[i][y][0]; + bitmaps[i][y+24][0] = bitmaps[i][y+24][1] = bitmaps[i][y][0]; + bitmaps[i][y+24][2] = bitmaps[i][y+24][3] = bitmaps[i][y][0]; + bitmaps[i][y+28][0] = bitmaps[i][y+28][1] = bitmaps[i][y][0]; + bitmaps[i][y+28][2] = bitmaps[i][y+28][3] = bitmaps[i][y][0]; } sprintf(name, "AlphaStipple%d", i); - Tk_DefineBitmap(interp, Tk_GetUid(name), (char *) bitmaps[i], 8, 8); + Tk_DefineBitmap(interp, Tk_GetUid(name), (char *) bitmaps[i], 32, 32); } /* |