xserver/hw/kdrive/ati ati.c, 1.15, 1.16 ati.h, 1.9, 1.10 ati_cursor.c, 1.3, 1.4 ati_draw.c, 1.18, 1.19 ati_draw.h, 1.6, 1.7

Eric Anholt <xserver-commit-u7BhqnqprCWvj1b/[email protected]>
Newsgroups gmane.comp.freedesktop.xserver.cvs
Message-ID <[email protected]>
Committed by: anholt

Update of /cvs/xserver/xserver/hw/kdrive/ati
In directory pdx:/tmp/cvs-serv20297/hw/kdrive/ati

Modified Files:
	ati.c ati.h ati_cursor.c ati_draw.c ati_draw.h 
Log Message:
Use the offscreen memory manager as much as possible to do the
reservation of memory at startup.  Do some drive-by cleanups while I'm
here (sorry!).


Index: ati.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/ati/ati.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- ati.c	28 Jun 2004 00:48:51 -0000	1.15
+++ ati.c	19 Jul 2004 07:53:53 -0000	1.16
@@ -291,24 +291,15 @@
 static void
 ATISetOffscreen (KdScreenInfo *screen)
 {
+#if defined(USE_DRI) && defined(GLXEXT)
 	ATICardInfo(screen);
 	ATIScreenInfo *atis = (ATIScreenInfo *)screen->driver;
-	int screen_size = screen->fb[0].byteStride * screen->height;
-#if defined(USE_DRI) && defined(GLXEXT)
 	int l;
 #endif
+	int screen_size = screen->fb[0].byteStride * screen->height;
 
 	screen->off_screen_base = screen_size;
 
-	if (atic->is_radeon)
-		atis->cursor.cursor_size = ATI_CURSOR_HEIGHT * ATI_CURSOR_WIDTH * 4;
-	else
-		atis->cursor.cursor_size = ATI_CURSOR_HEIGHT * ATI_CURSOR_PITCH * 3;
-
-	atis->cursor.offset = screen->off_screen_base;
-
-	screen->off_screen_base += atis->cursor.cursor_size;
-
 #if defined(USE_DRI) && defined(GLXEXT)
 	/* Reserve a static area for the back buffer the same size as the
 	 * visible screen.  XXX: This would be better initialized in ati_dri.c
@@ -357,22 +348,6 @@
 		atis->textureSize = 0;
 	}
 #endif /* USE_DRI && GLXEXT */
-
-	/* Reserve a scratch area.  It'll be used for storing glyph data during
-	 * Composite operations, because glyphs aren't in real pixmaps and thus
-	 * can't be migrated.
-	 */
-	atis->scratch_size = 131072;	/* big enough for 128x128@32bpp */
-	if (screen->off_screen_base + atis->scratch_size <= screen->memory_size)
-	{
-		atis->scratch_offset = screen->off_screen_base;
-		screen->off_screen_base += atis->scratch_size;
-		atis->scratch_next = atis->scratch_offset;
-	}
-	else 
-	{
-		atis->scratch_size = 0;
-	}
 }
 
 static Bool
@@ -574,6 +549,9 @@
 ATIDisable(ScreenPtr pScreen)
 {
 	KdScreenPriv(pScreen);
+#if defined(USE_DRI) && defined(GLXEXT)
+	ATIScreenInfo(pScreenPriv);
+#endif /* USE_DRI && GLXEXT */
 	ATICardInfo(pScreenPriv);
 
 	ATIUnmapReg(pScreenPriv->card, atic);
@@ -605,8 +583,6 @@
 {
 	int bits;
 
-	if (!val)
-		return 1;
 	for (bits = 0; val != 0; val >>= 1, ++bits)
 		;
 	return bits - 1;

Index: ati.h
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/ati/ati.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- ati.h	28 Jun 2004 00:48:51 -0000	1.9
+++ ati.h	19 Jul 2004 07:53:54 -0000	1.10
@@ -162,10 +162,7 @@
 	Bool		has_cursor;
 	CursorPtr	pCursor;
 	Pixel		source, mask;
-	KdOffscreenArea	*area;
-	CARD32		offset;
-	
-	int		cursor_size;
+	KdOffscreenArea *area;
 } ATICursor;
 
 typedef struct _ATIPortPriv {
@@ -213,12 +210,10 @@
 	ATICardInfo *atic;
 	KdScreenInfo *screen;
 
-	void (*save_blockhandler)(int screen, pointer blockData,
-	    pointer timeout, pointer readmask);
-
 	int		scratch_offset;
 	int		scratch_next;
 	int		scratch_size;
+	KdOffscreenArea *scratch_area;
 
 	ATICursor	cursor;
 

Index: ati_cursor.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/ati/ati_cursor.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ati_cursor.c	28 Jun 2004 00:48:51 -0000	1.3
+++ ati_cursor.c	19 Jul 2004 07:53:54 -0000	1.4
@@ -63,7 +63,8 @@
 	    (xoff << 16) | yoff);
 	MMIO_OUT32(mmio, ATI_REG_CUR_HORZ_VERT_POSN, ATI_CUR_LOCK |
 	    (x << 16) | y);
-	MMIO_OUT32(mmio, ATI_REG_CUR_OFFSET, (pCurPriv->offset + yoff * stride));
+	MMIO_OUT32(mmio, ATI_REG_CUR_OFFSET, (pCurPriv->area->offset + yoff *
+	    stride));
 }
 
 static void
@@ -163,7 +164,7 @@
 
 	/* Stick new image into cursor memory */
 	ram = (CARD32 *)(pScreenPriv->screen->memory_base +
-	    pCurPriv->offset);
+	    pCurPriv->area->offset);
 	mskLine = (CARD32 *)bits->mask;
 	srcLine = (CARD32 *)bits->source;
 
@@ -261,7 +262,7 @@
 
 	/* Stick new image into cursor memory */
 	ram = (CARD32 *)(pScreenPriv->screen->memory_base +
-	    pCurPriv->offset);
+	    pCurPriv->area->offset);
 	if (pCursor->bits->argb)
 	{
 		srcLine = pCursor->bits->argb;
@@ -445,6 +446,16 @@
 	}
 }
 
+static void
+ATICursorSave(ScreenPtr pScreen, KdOffscreenArea *area)
+{
+	KdScreenPriv(pScreen);
+	ATIScreenInfo(pScreenPriv);
+	ATICursor *pCurPriv = &atis->cursor;
+
+	pCurPriv->area = NULL;
+}
+
 void
 ATICursorEnable(ScreenPtr pScreen)
 {
@@ -456,6 +467,19 @@
 	if (!pCurPriv->has_cursor)
 		return;
 
+	if (pCurPriv->area == NULL) {
+		if (atic->is_radeon)
+			pCurPriv->area = KdOffscreenAlloc(pScreen,
+			    ATI_CURSOR_HEIGHT * ATI_CURSOR_WIDTH * 4,
+			    1, TRUE, ATICursorSave, atis);
+		else
+			pCurPriv->area = KdOffscreenAlloc(pScreen,
+			    ATI_CURSOR_HEIGHT * ATI_CURSOR_PITCH * 2,
+			    1, TRUE, ATICursorSave, atis);
+	}
+	if (pCurPriv->area == NULL)
+		FatalError("Couldn't allocate offscreen memory for cursor.\n");
+
 	if (pCurPriv->pCursor) {
 		int x, y;
 
@@ -495,7 +519,7 @@
 
 	pCurPriv->has_cursor = FALSE;
 
-	if (pCurPriv->cursor_size == 0)
+	if (pCurPriv->area == NULL)
 		return FALSE;
 
 	if (atic->reg_base == NULL)

Index: ati_draw.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/ati/ati_draw.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- ati_draw.c	28 Jun 2004 00:48:51 -0000	1.18
+++ ati_draw.c	19 Jul 2004 07:53:54 -0000	1.19
@@ -91,6 +91,7 @@
 	 * issues.
 	 */
 	/*if (!atic->is_radeon) {
+		char *mmio = atic->reg_base;
 		ATIWaitIdle(atis);
 		MMIO_OUT32(mmio, R128_REG_PC_GUI_MODE,
 		    R128_PC_BYPASS_EN);
@@ -615,23 +616,23 @@
 	    atis->kaa.offscreenPitch - 1) & ~(atis->kaa.offscreenPitch - 1);
 
 	size = dst_pitch * pSrc->drawable.height;
-	if (size > atis->scratch_size)
+	if (size > atis->scratch_area->size)
 		ATI_FALLBACK(("Pixmap too large for scratch (%d,%d)\n",
 		    pSrc->drawable.width, pSrc->drawable.height));
 
 	atis->scratch_next = (atis->scratch_next +
 	    atis->kaa.offscreenByteAlign - 1) &
 	    ~(atis->kaa.offscreenByteAlign - 1);
-	if (atis->scratch_next + size > atis->scratch_offset +
-	    atis->scratch_size) {
+	if (atis->scratch_next + size > atis->scratch_area->offset +
+	    atis->scratch_area->size) {
 		/* Only sync when we've used all of the scratch area. */
 		KdCheckSync(pSrc->drawable.pScreen);
-		atis->scratch_next = atis->scratch_offset;
+		atis->scratch_next = atis->scratch_area->offset;
 	}
 	memcpy(pDst, pSrc, sizeof(*pDst));
 	pDst->devKind = dst_pitch;
-	pDst->devPrivate.ptr = atis->scratch_next +
-	    pScreenPriv->screen->memory_base;
+	pDst->devPrivate.ptr = pScreenPriv->screen->memory_base +
+	    atis->scratch_next;
 	atis->scratch_next += size;
 
 	src = pSrc->devPrivate.ptr;
@@ -662,7 +663,7 @@
 }
 
 static void
-ATIBlockHandler (pointer blockData, OSTimePtr timeout, pointer readmask)
+ATIBlockHandler(pointer blockData, OSTimePtr timeout, pointer readmask)
 {
 	ScreenPtr pScreen = (ScreenPtr) blockData;
 	KdScreenPriv(pScreen);
@@ -675,7 +676,7 @@
 }
 
 static void
-ATIWakeupHandler (pointer blockData, int result, pointer readmask)
+ATIWakeupHandler(pointer blockData, int result, pointer readmask)
 {
 }
 
@@ -685,7 +686,6 @@
 	KdScreenPriv(pScreen);
 	ATIScreenInfo(pScreenPriv);
 	ATICardInfo(pScreenPriv);
-	int align_scratch;
 
 	ErrorF("Screen: %d/%d depth/bpp\n", pScreenPriv->screen->fb[0].depth,
 	    pScreenPriv->screen->fb[0].bitsPerPixel);
@@ -719,19 +719,21 @@
 		atis->kaa.offscreenPitch = 32;
 	}
 
-	/* Align the scratch area to what offscreenByteAlign requires. */
-	align_scratch = (atis->scratch_offset +
-	    atis->kaa.offscreenByteAlign - 1) &
-	    ~(atis->kaa.offscreenByteAlign - 1);
-	atis->scratch_size -= align_scratch - atis->scratch_offset;
-	atis->scratch_offset = align_scratch;
-
 	if (!kaaDrawInit(pScreen, &atis->kaa))
 		return FALSE;
 
 	return TRUE;
 }
 
+static void
+ATIScratchSave(ScreenPtr pScreen, KdOffscreenArea *area)
+{
+	KdScreenPriv(pScreen);
+	ATIScreenInfo(pScreenPriv);
+
+	atis->scratch_area = NULL;
+}
+
 void
 ATIDrawEnable(ScreenPtr pScreen)
 {
@@ -780,7 +782,18 @@
 	}
 
 	atis->kaa.UploadToScreen = ATIUploadToScreen;
-	atis->kaa.UploadToScratch = ATIUploadToScratch;
+
+	/* Reserve a scratch area.  It'll be used for storing glyph data during
+	 * Composite operations, because glyphs aren't in real pixmaps and thus
+	 * can't be migrated.
+	 */
+	atis->scratch_area = KdOffscreenAlloc(pScreen, 131072,
+	    atis->kaa.offscreenByteAlign, TRUE, ATIScratchSave, atis);
+	if (atis->scratch_area != NULL) {
+		atis->scratch_next = atis->scratch_area->offset;
+		atis->kaa.UploadToScratch = ATIUploadToScratch;
+	} else
+		atis->kaa.UploadToScratch = NULL;
 
 	RegisterBlockAndWakeupHandlers (ATIBlockHandler, ATIWakeupHandler,
 				       pScreen);
@@ -791,10 +804,10 @@
 void
 ATIDrawDisable(ScreenPtr pScreen)
 {
-	ATIDMATeardown(pScreen);
-
 	RemoveBlockAndWakeupHandlers (ATIBlockHandler, ATIWakeupHandler,
 				      pScreen);
+
+	ATIDMATeardown(pScreen);
 }
 
 void

Index: ati_draw.h
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/ati/ati_draw.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ati_draw.h	17 May 2004 20:18:02 -0000	1.6
+++ ati_draw.h	19 Jul 2004 07:53:54 -0000	1.7
@@ -89,10 +89,11 @@
 ATIWaitIdle(ATIScreenInfo *atis);
 
 #if 0
-#define ATI_FALLBACK(x)		\
-do {				\
-	ErrorF x;		\
-	return FALSE;		\
+#define ATI_FALLBACK(x)			\
+do {					\
+	ErrorF("%s: ", __FUNCTION__);	\
+	ErrorF x;			\
+	return FALSE;			\
 } while (0)
 #else
 #define ATI_FALLBACK(x) return FALSE
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.