fix missing width/height error
[mesa.git] / src / mesa / drivers / x11 / xm_api.c
index 1a784c5fd85416a5494015f17a29087a2e083c19..47c19c87a7f32bba6162058d514e5cba0ed213d7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.1
+ * Version:  6.3
  *
  * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
@@ -220,28 +220,6 @@ static int check_for_xshm( XMesaDisplay *display )
 #endif
 
 
-/*
- * Return the width and height of the given drawable.
- */
-static void get_drawable_size( XMesaDisplay *dpy, XMesaDrawable d,
-                               unsigned int *width, unsigned int *height)
-{
-#ifdef XFree86Server
-    (void) dpy;
-    *width = d->width;
-    *height = d->height;
-#else
-   Window root;
-   int x, y;
-   unsigned int bw, depth;
-
-   _glthread_LOCK_MUTEX(_xmesa_lock);
-   XGetGeometry( dpy, d, &root, &x, &y, width, height, &bw, &depth );
-   _glthread_UNLOCK_MUTEX(_xmesa_lock);
-#endif
-}
-
-
 /*
  * Apply gamma correction to an intensity value in [0..max].  Return the
  * new intensity value.
@@ -476,11 +454,16 @@ static GLboolean alloc_shm_back_buffer( XMesaBuffer b )
    GC gc;
    int (*old_handler)( XMesaDisplay *, XErrorEvent * );
 
-   b->backimage = XShmCreateImage( b->xm_visual->display,
-                                   b->xm_visual->visinfo->visual,
-                                   b->xm_visual->visinfo->depth,
-                                  ZPixmap, NULL, &b->shminfo,
-                                  b->width, b->height );
+   if (b->mesa_buffer.Width == 0 || b->mesa_buffer.Height == 0) {
+      /* this will be true the first time we're called on 'b' */
+      return GL_FALSE;
+   }
+
+   b->backimage = XShmCreateImage(b->xm_visual->display,
+                                  b->xm_visual->visinfo->visual,
+                                  b->xm_visual->visinfo->depth,
+                                  ZPixmap, NULL, &b->shminfo,
+                                  b->mesa_buffer.Width, b->mesa_buffer.Height);
    if (b->backimage == NULL) {
       _mesa_warning(NULL, "alloc_back_buffer: Shared memory error (XShmCreateImage), disabling.");
       b->shm = 0;
@@ -606,7 +589,8 @@ void xmesa_alloc_back_buffer( XMesaBuffer b )
       {
         /* Allocate a regular XImage for the back buffer. */
         b->backimage = XMesaCreateImage(b->xm_visual->BitsPerPixel,
-                                        b->width, b->height, NULL);
+                                        b->mesa_buffer.Width,
+                                         b->mesa_buffer.Height, NULL);
 #else
       if (b->shm==0 || alloc_shm_back_buffer(b)==GL_FALSE) {
         /* Allocate a regular XImage for the back buffer. */
@@ -614,7 +598,9 @@ void xmesa_alloc_back_buffer( XMesaBuffer b )
                                       b->xm_visual->visinfo->visual,
                                       GET_VISUAL_DEPTH(b->xm_visual),
                                      ZPixmap, 0,   /* format, offset */
-                                     NULL, b->width, b->height,
+                                     NULL,
+                                      b->mesa_buffer.Width,
+                                      b->mesa_buffer.Height,
                                      8, 0 );  /* pad, bytes_per_line */
 #endif
         if (!b->backimage) {
@@ -638,7 +624,8 @@ void xmesa_alloc_back_buffer( XMesaBuffer b )
       }
       /* Allocate new back pixmap */
       b->backpixmap = XMesaCreatePixmap( b->xm_visual->display, b->frontbuffer,
-                                        b->width, b->height,
+                                        b->mesa_buffer.Width,
+                                         b->mesa_buffer.Height,
                                         GET_VISUAL_DEPTH(b->xm_visual) );
       b->backimage = NULL;
       /* update other references to backpixmap */
@@ -794,8 +781,6 @@ noFaultXAllocColor( int client,
 static GLboolean setup_grayscale( int client, XMesaVisual v,
                                   XMesaBuffer buffer, XMesaColormap cmap )
 {
-   (void) DitherValues;                /* Muffle compiler */
-
    if (GET_VISUAL_DEPTH(v)<4 || GET_VISUAL_DEPTH(v)>16) {
       return GL_FALSE;
    }
@@ -1250,12 +1235,6 @@ static GLboolean initialize_visual_and_buffer( int client,
    if (b && window) {
       /* Do window-specific initializations */
 
-      /* Window dimensions */
-      unsigned int w, h;
-      get_drawable_size( v->display, window, &w, &h );
-      b->width = w;
-      b->height = h;
-
       b->frontbuffer = window;
 
       /* Setup for single/double buffering */
@@ -1343,6 +1322,8 @@ static GLboolean initialize_visual_and_buffer( int client,
                                   32,                   /*bitmap_pad*/
                                   0                     /*bytes_per_line*/ );
 #endif
+      if (!b->rowimage)
+         return GL_FALSE;
    }
 
    return GL_TRUE;
@@ -1667,6 +1648,14 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list )
    _mesa_enable_1_3_extensions(mesaCtx);
    _mesa_enable_1_4_extensions(mesaCtx);
    _mesa_enable_1_5_extensions(mesaCtx);
+   _mesa_enable_2_0_extensions(mesaCtx);
+#if SWTC
+    if (c->Mesa_DXTn) {
+       _mesa_enable_extension(c, "GL_EXT_texture_compression_s3tc");
+       _mesa_enable_extension(c, "GL_S3_s3tc");
+    }
+    _mesa_enable_extension(c, "GL_3DFX_texture_compression_FXT1");
+#endif
 
    /* finish up xmesa context initializations */
    c->swapbytes = CHECK_BYTE_ORDER(v) ? GL_FALSE : GL_TRUE;
@@ -1839,8 +1828,14 @@ XMesaBuffer XMesaCreateWindowBuffer2( XMesaVisual v, XMesaWindow w,
 
        /* [dBorca] we should take an envvar for `fxMesaSelectCurrentBoard'!!! */
        hw = fxMesaSelectCurrentBoard(0);
+
+       /* if these fail, there's a new bug somewhere */
+       ASSERT(b->mesa_buffer.Width > 0);
+       ASSERT(b->mesa_buffer.Height > 0);
+
        if ((hw == GR_SSTTYPE_VOODOO) || (hw == GR_SSTTYPE_Voodoo2)) {
-         b->FXctx = fxMesaCreateBestContext(0, b->width, b->height, attribs);
+         b->FXctx = fxMesaCreateBestContext(0, b->mesa_buffer.Width,
+                                            b->mesa_buffer.Height, attribs);
          if ((v->undithered_pf!=PF_Index) && (b->backimage)) {
           b->FXisHackUsable = b->FXctx ? GL_TRUE : GL_FALSE;
           if (b->FXctx && (fxEnvVar[0]=='w' || fxEnvVar[0]=='W')) {
@@ -1857,7 +1852,8 @@ XMesaBuffer XMesaCreateWindowBuffer2( XMesaVisual v, XMesaWindow w,
           b->FXctx = fxMesaCreateContext(w, GR_RESOLUTION_NONE,
                                          GR_REFRESH_75Hz, attribs);
          else
-          b->FXctx = fxMesaCreateBestContext(0, b->width, b->height, attribs);
+          b->FXctx = fxMesaCreateBestContext(0, b->mesa_buffer.Width,
+                                              b->mesa_buffer.Height, attribs);
          b->FXisHackUsable = GL_FALSE;
          b->FXwindowHack = GL_FALSE;
        }
@@ -2098,13 +2094,6 @@ GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer,
                           &drawBuffer->mesa_buffer,
                           &readBuffer->mesa_buffer);
 
-      if (c->mesa.Viewport.Width == 0) {
-        /* initialize viewport to window size */
-        _mesa_Viewport( 0, 0, drawBuffer->width, drawBuffer->height );
-        c->mesa.Scissor.Width = drawBuffer->width;
-        c->mesa.Scissor.Height = drawBuffer->height;
-      }
-
       if (c->xm_visual->mesa_visual.rgbMode) {
          /*
           * Must recompute and set these pixel values because colormap
@@ -2276,10 +2265,10 @@ static void FXgetImage( XMesaBuffer b )
    XGetGeometry( b->xm_visual->display, b->frontbuffer,
                  &root, &xpos, &ypos, &width, &height, &bw, &depth);
 #endif
-   if (b->width != width || b->height != height) {
-      b->width = MIN2((int)width, b->FXctx->width);
-      b->height = MIN2((int)height, b->FXctx->height);
-      if (b->width & 1)
+   if (b->mesa_buffer.Width != width || b->mesa_buffer.Height != height) {
+      b->mesa_buffer.Width = MIN2((int)width, b->FXctx->width);
+      b->mesa_buffer.Height = MIN2((int)height, b->FXctx->height);
+      if (b->mesa_buffer.Width & 1)
          b->width--;  /* prevent odd width */
       xmesa_alloc_back_buffer( b );
    }
@@ -2289,28 +2278,28 @@ static void FXgetImage( XMesaBuffer b )
    if (b->xm_visual->undithered_pf==PF_5R6G5B) {
       /* Special case: 16bpp RGB */
       grLfbReadRegion( GR_BUFFER_FRONTBUFFER,       /* src buffer */
-                       0, b->FXctx->height - b->height,  /*pos*/
-                       b->width, b->height,         /* size */
-                       b->width * sizeof(GLushort), /* stride */
+                       0, b->FXctx->height - b->mesa_buffer.Height,  /*pos*/
+                       b->mesa_buffer.Width, b->mesa_buffer.Height,  /* size */
+                       b->mesa_buffer.Width * sizeof(GLushort), /* stride */
                        b->backimage->data);         /* dest buffer */
    }
    else if (b->xm_visual->dithered_pf==PF_Dither
            && GET_VISUAL_DEPTH(b->xm_visual)==8) {
       /* Special case: 8bpp RGB */
-      for (y=0;y<b->height;y++) {
+      for (y=0;y<b->mesa_buffer.Height;y++) {
          GLubyte *ptr = (GLubyte*) b->backimage->data
                         + b->backimage->bytes_per_line * y;
          XDITHER_SETUP(y);
 
          /* read row from 3Dfx frame buffer */
          grLfbReadRegion( GR_BUFFER_FRONTBUFFER,
-                          0, b->FXctx->height-(b->height-y),
-                          b->width, 1,
+                          0, b->FXctx->height-(b->mesa_buffer.Height-y),
+                          b->mesa_buffer.Width, 1,
                           0,
                           pixbuf );
 
          /* write to XImage back buffer */
-         for (x=0;x<b->width;x++) {
+         for (x=0;x<b->mesa_buffer.Width;x++) {
             GLubyte r = (pixbuf[x] & 0xf800) >> 8;
             GLubyte g = (pixbuf[x] & 0x07e0) >> 3;
             GLubyte b = (pixbuf[x] & 0x001f) << 3;
@@ -2320,16 +2309,16 @@ static void FXgetImage( XMesaBuffer b )
    }
    else {
       /* General case: slow! */
-      for (y=0;y<b->height;y++) {
+      for (y=0;y<b->mesa_buffer.Height;y++) {
          /* read row from 3Dfx frame buffer */
          grLfbReadRegion( GR_BUFFER_FRONTBUFFER,
-                          0, b->FXctx->height-(b->height-y),
-                          b->width, 1,
+                          0, b->FXctx->height-(b->mesa_buffer.Height-y),
+                          b->mesa_buffer.Width, 1,
                           0,
                           pixbuf );
 
          /* write to XImage back buffer */
-         for (x=0;x<b->width;x++) {
+         for (x=0;x<b->mesa_buffer.Width;x++) {
             XMesaPutPixel(b->backimage,x,y,
                          xmesa_color_to_pixel(xmesa,
                                               (pixbuf[x] & 0xf800) >> 8,
@@ -2378,7 +2367,8 @@ void XMesaSwapBuffers( XMesaBuffer b )
            XShmPutImage( b->xm_visual->display, b->frontbuffer,
                          b->swapgc,
                          b->backimage, 0, 0,
-                         0, 0, b->width, b->height, False );
+                         0, 0, b->mesa_buffer.Width, b->mesa_buffer.Height,
+                          False );
             /*_glthread_UNLOCK_MUTEX(_xmesa_lock);*/
         }
         else
@@ -2388,7 +2378,7 @@ void XMesaSwapBuffers( XMesaBuffer b )
             XMesaPutImage( b->xm_visual->display, b->frontbuffer,
                           b->swapgc,
                           b->backimage, 0, 0,
-                          0, 0, b->width, b->height );
+                          0, 0, b->mesa_buffer.Width, b->mesa_buffer.Height );
             /*_glthread_UNLOCK_MUTEX(_xmesa_lock);*/
          }
       }
@@ -2399,7 +2389,7 @@ void XMesaSwapBuffers( XMesaBuffer b )
                        b->backpixmap,   /* source drawable */
                        b->frontbuffer,  /* dest. drawable */
                        b->swapgc,
-                       0, 0, b->width, b->height,  /* source region */
+                       0, 0, b->mesa_buffer.Width, b->mesa_buffer.Height,
                        0, 0                 /* dest region */
                      );
          /*_glthread_UNLOCK_MUTEX(_xmesa_lock);*/
@@ -2426,7 +2416,7 @@ void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height )
       _mesa_notifySwapBuffers(ctx);
 
    if (b->db_state) {
-      int yTop = b->height - y - height;
+      int yTop = b->mesa_buffer.Height - y - height;
 #ifdef FX
       if (b->FXctx) {
          fxMesaSwapBuffers();