[PATCH 1/6] Introduce dixLookupFontable for "FONT or GC" parameters.

Jamey Sharp jamey at minilop.net
Sun Apr 25 03:35:33 PDT 2010


Signed-off-by: Jamey Sharp <jamey at minilop.net>
---
 Xext/xf86bigfont.c |   14 ++------------
 dix/dispatch.c     |   26 ++++----------------------
 dix/dixutils.c     |   18 ++++++++++++++++++
 glx/xfont.c        |   17 +++--------------
 include/dix.h      |    6 ++++++
 5 files changed, 33 insertions(+), 48 deletions(-)

diff --git a/Xext/xf86bigfont.c b/Xext/xf86bigfont.c
index a4eb3f6..68c5d52 100644
--- a/Xext/xf86bigfont.c
+++ b/Xext/xf86bigfont.c
@@ -427,18 +427,8 @@ ProcXF86BigfontQueryFont(
 	    return BadLength;
     }
 #endif
-    client->errorValue = stuff->id;		/* EITHER font or gc */
-    dixLookupResourceByType((pointer *)&pFont, stuff->id, RT_FONT,
-			    client, DixGetAttrAccess);
-    if (!pFont) {
-	GC *pGC;
-	dixLookupResourceByType((pointer *)&pGC, stuff->id, RT_GC,
-				client, DixGetAttrAccess);
-        if (!pGC)
-            return BadFont;    /* procotol spec says only error is BadFont */
-
-	pFont = pGC->font;
-    }
+    if (dixLookupFontable(&pFont, stuff->id, client, DixGetAttrAccess) != Success)
+	return BadFont;    /* procotol spec says only error is BadFont */
 
     pmax = FONTINKMAX(pFont);
     pmin = FONTINKMIN(pFont);
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 982c808..a2cffac 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1283,22 +1283,13 @@ ProcQueryFont(ClientPtr client)
 {
     xQueryFontReply	*reply;
     FontPtr pFont;
-    GC *pGC;
     int rc;
     REQUEST(xResourceReq);
     REQUEST_SIZE_MATCH(xResourceReq);
 
-    client->errorValue = stuff->id;		/* EITHER font or gc */
-    rc = dixLookupResourceByType((pointer *)&pFont, stuff->id, RT_FONT, client,
-				 DixGetAttrAccess);
-    if (rc == BadValue) {
-	rc = dixLookupResourceByType((pointer *)&pGC, stuff->id, RT_GC, client,
-				     DixGetAttrAccess);
-	if (rc == Success)
-	    pFont = pGC->font;
-    }
+    rc = dixLookupFontable(&pFont, stuff->id, client, DixGetAttrAccess);
     if (rc != Success)
-	return (rc == BadValue) ? BadFont: rc;
+	return rc;
 
     {
 	xCharInfo	*pmax = FONTINKMAX(pFont);
@@ -1339,24 +1330,15 @@ ProcQueryTextExtents(ClientPtr client)
 {
     xQueryTextExtentsReply reply;
     FontPtr pFont;
-    GC *pGC;
     ExtentInfoRec info;
     unsigned long length;
     int rc;
     REQUEST(xQueryTextExtentsReq);
     REQUEST_AT_LEAST_SIZE(xQueryTextExtentsReq);
         
-    client->errorValue = stuff->fid;		/* EITHER font or gc */
-    rc = dixLookupResourceByType((pointer *)&pFont, stuff->fid, RT_FONT, client,
-				 DixGetAttrAccess);
-    if (rc == BadValue) {
-	rc = dixLookupResourceByType((pointer *)&pGC, stuff->fid, RT_GC, client,
-			       DixGetAttrAccess);
-	if (rc == Success)
-	    pFont = pGC->font;
-    }
+    rc = dixLookupFontable(&pFont, stuff->fid, client, DixGetAttrAccess);
     if (rc != Success)
-	return (rc == BadValue) ? BadFont: rc;
+	return rc;
 
     length = client->req_len - bytes_to_int32(sizeof(xQueryTextExtentsReq));
     length = length << 1;
diff --git a/dix/dixutils.c b/dix/dixutils.c
index 8278d44..d610836 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -92,6 +92,7 @@ Author:  Adobe Systems Incorporated
 #include "windowstr.h"
 #include "dixstruct.h"
 #include "pixmapstr.h"
+#include "gcstruct.h"
 #include "scrnintstr.h"
 #define  XK_LATIN1
 #include <X11/keysymdef.h>
@@ -236,6 +237,23 @@ dixLookupGC(GCPtr *pGC, XID id, ClientPtr client, Mask access)
 }
 
 int
+dixLookupFontable(FontPtr *pFont, XID id, ClientPtr client, Mask access)
+{
+    int rc;
+    GC *pGC;
+    client->errorValue = id;		/* EITHER font or gc */
+    rc = dixLookupResourceByType((pointer *) pFont, id, RT_FONT, client, access);
+    if (rc != BadValue)
+	return rc;
+    rc = dixLookupResourceByType((pointer *) &pGC, id, RT_GC, client, access);
+    if (rc == BadValue)
+	return BadFont;
+    if (rc == Success)
+	*pFont = pGC->font;
+    return rc;
+}
+
+int
 dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client, Mask access)
 {
     pointer pRes;
diff --git a/glx/xfont.c b/glx/xfont.c
index b8b466d..e3c7f32 100644
--- a/glx/xfont.c
+++ b/glx/xfont.c
@@ -155,7 +155,6 @@ int __glXDisp_UseXFont(__GLXclientState *cl, GLbyte *pc)
     ClientPtr client = cl->client;
     xGLXUseXFontReq *req;
     FontPtr pFont;
-    GC *pGC;
     GLuint currentListIndex;
     __GLXcontext *cx;
     int error;
@@ -181,19 +180,9 @@ int __glXDisp_UseXFont(__GLXclientState *cl, GLbyte *pc)
     ** containing a font.
     */
 
-    error = dixLookupResourceByType((pointer *)&pFont,
-				    req->font, RT_FONT,
-				    client, DixReadAccess);
-    if (error != Success) {
-	error = dixLookupResourceByType((pointer *)&pGC,
-					req->font, RT_GC,
-					client, DixReadAccess);
-        if (error != Success) {
-	    client->errorValue = req->font;
-            return error == BadGC ? BadFont : error;
-	}
-	pFont = pGC->font;
-    }
+    error = dixLookupFontable(&pFont, req->font, client, DixReadAccess);
+    if (error != Success)
+	return error;
 
     return MakeBitmapsFromFont(pFont, req->first, req->count,
 				    req->listBase);
diff --git a/include/dix.h b/include/dix.h
index 6505fd0..9d05c40 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -198,6 +198,12 @@ extern _X_EXPORT int dixLookupGC(
     ClientPtr client,
     Mask access_mode);
 
+extern _X_EXPORT int dixLookupFontable(
+    FontPtr *result,
+    XID id,
+    ClientPtr client,
+    Mask access_mode);
+
 extern _X_EXPORT int dixLookupClient(
     ClientPtr *result,
     XID id,
-- 
1.7.0



More information about the xorg-devel mailing list