fixed mem leak in XFreeFontInfo() call
[mesa.git] / src / mesa / drivers / x11 / xfonts.c
index e69f71224f9713ef5be1ba22bf313151aa77a928..3aa17fec849409a3750490d13983aa6b9555dcb2 100644 (file)
@@ -1,10 +1,10 @@
-/* $Id: xfonts.c,v 1.5 1999/12/12 17:04:50 brianp Exp $ */
+/* $Id: xfonts.c,v 1.14 2001/04/26 19:28:02 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  3.3
+ * Version:  3.5
  *
- * Copyright (C) 1999  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2000  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"),
@@ -29,6 +29,9 @@
  * Copyright (C) 1995 Thorsten.Ohl @ Physik.TH-Darmstadt.de
  */
 
+#ifdef __VMS
+#include <GL/vms_x_fix.h>
+#endif
 
 #ifdef HAVE_CONFIG_H
 #include "conf.h"
 #include <X11/Xutil.h>
 #include "GL/gl.h"
 #include "GL/glx.h"
-#include "GL/xmesa.h"
 #include "context.h"
 #include "mem.h"
-#include "xmesaP.h"
+#include "xfonts.h"
+
 
 /* Some debugging info.  */
 
@@ -177,10 +180,10 @@ fill_bitmap (Display *dpy, Window win, GC gc,
  * determine if a given glyph is valid and return the
  * corresponding XCharStruct.
  */
-static XCharStruct *isvalid(XFontStruct *fs, int which)
+static XCharStruct *isvalid(XFontStruct *fs, unsigned int which)
 {
   unsigned int  rows,pages;
-  int           byte1,byte2;
+  unsigned int byte1 = 0,byte2 = 0;
   int           i,valid = 1;
 
   rows = fs->max_byte1 - fs->min_byte1 + 1;
@@ -221,7 +224,6 @@ static XCharStruct *isvalid(XFontStruct *fs, int which)
 
 void Fake_glXUseXFont( Font font, int first, int count, int listbase )
 {
-  XMesaContext CC;
   Display *dpy;
   Window win;
   Pixmap pixmap;
@@ -229,26 +231,23 @@ void Fake_glXUseXFont( Font font, int first, int count, int listbase )
   XGCValues values;
   unsigned long valuemask;
   XFontStruct *fs;
-
   GLint swapbytes, lsbfirst, rowlength;
   GLint skiprows, skippixels, alignment;
-
   unsigned int max_width, max_height, max_bm_width, max_bm_height;
   GLubyte *bm;
-
   int i;
 
-  CC = XMesaGetCurrentContext();
-  dpy = CC->display;
-  win = CC->xm_buffer->frontbuffer;
+  dpy = glXGetCurrentDisplay();
+  if (!dpy)
+     return;  /* I guess glXMakeCurrent wasn't called */
+  win = RootWindow(dpy, DefaultScreen(dpy));
 
   fs = XQueryFont (dpy, font);
-  if (!fs)
-    {
-      gl_error (CC->gl_ctx, GL_INVALID_VALUE,
-                "Couldn't get font structure information");
+  if (!fs) {
+      _mesa_error(NULL, GL_INVALID_VALUE,
+               "Couldn't get font structure information");
       return;
-    }
+  }
 
   /* Allocate a bitmap that can fit all characters.  */
   max_width = fs->max_bounds.rbearing - fs->min_bounds.lbearing;
@@ -259,11 +258,11 @@ void Fake_glXUseXFont( Font font, int first, int count, int listbase )
   bm = (GLubyte *) MALLOC((max_bm_width * max_bm_height) * sizeof 
 (GLubyte));
   if (!bm) {
-      XFreeFontInfo( NULL, fs, 0 );
-      gl_error (CC->gl_ctx, GL_OUT_OF_MEMORY,
+      XFreeFontInfo( NULL, fs, 1 );
+      _mesa_error(NULL, GL_OUT_OF_MEMORY,
                 "Couldn't allocate bitmap in glXUseXFont()");
       return;
-    }
+  }
 
 #if 0
   /* get the page info */
@@ -373,8 +372,8 @@ bm_height);
       glEndList ();
     }
 
-  free (bm);
-  XFreeFontInfo( NULL, fs, 0 );
+  FREE(bm);
+  XFreeFontInfo( NULL, fs, 1 );
   XFreeGC (dpy, gc);
 
   /* Restore saved packing modes.  */
@@ -385,14 +384,3 @@ bm_height);
   glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels);
   glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
 }
-
-void xmesa_xfonts_dummy( void )
-{
-   /* silence unused var warnings */
-   (void) kernel8;
-   (void) DitherValues;
-   (void) HPCR_DRGB;
-   (void) kernel1;
-}
-
-/* The End. */