Module Name:    xsrc
Committed By:   macallan
Date:           Mon May 13 10:13:11 UTC 2024

Modified Files:
        xsrc/external/mit/xf86-video-suncg14/dist/src: cg14_accel.c
            cg14_driver.c

Log Message:
support 16bit colour
This requires kernel support, which was committed yesterday.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 \
    xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_accel.c
cvs rdiff -u -r1.21 -r1.22 \
    xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_driver.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_accel.c
diff -u xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_accel.c:1.32 xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_accel.c:1.33
--- xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_accel.c:1.32	Wed May 11 21:13:13 2022
+++ xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_accel.c	Mon May 13 10:13:10 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: cg14_accel.c,v 1.32 2022/05/11 21:13:13 macallan Exp $ */
+/* $NetBSD: cg14_accel.c,v 1.33 2024/05/13 10:13:10 macallan Exp $ */
 /*
  * Copyright (c) 2013 Michael Lorenz
  * All rights reserved.
@@ -68,6 +68,7 @@ int src_formats[] = {PICT_a8r8g8b8, PICT
 int tex_formats[] = {PICT_a8r8g8b8, PICT_a8b8g8r8, PICT_a8};
 
 static void CG14Copy32(PixmapPtr, int, int, int, int, int, int);
+static void CG14Copy16(PixmapPtr, int, int, int, int, int, int);
 static void CG14Copy8(PixmapPtr, int, int, int, int, int, int);
 
 static inline void
@@ -121,6 +122,9 @@ CG14PrepareCopy(PixmapPtr pSrcPixmap, Pi
 		case 8:
 			p->pExa->Copy = CG14Copy8;
 			break;
+		case 16:
+			p->pExa->Copy = CG14Copy16;
+			break;
 		case 32:
 			p->pExa->Copy = CG14Copy32;
 			break;
@@ -610,6 +614,13 @@ CG14Copy8_short_norop(Cg14Ptr p, int src
 }
 
 static void
+CG14Copy16(PixmapPtr pDstPixmap,
+         int srcX, int srcY, int dstX, int dstY, int w, int h)
+{
+	CG14Copy8(pDstPixmap, srcX << 1, srcY, dstX << 1, dstY, w << 1, h);
+}
+
+static void
 CG14Copy8(PixmapPtr pDstPixmap,
          int srcX, int srcY, int dstX, int dstY, int w, int h)
 {
@@ -896,10 +907,12 @@ CG14PrepareSolid(PixmapPtr pPixmap, int 
 			fg = 0xffffffff;
 			break;
 	}
-	/* repeat the colour in every sub byte if we're in 8 bit */
+	/* repeat the colour in every sub byte if we're in 8 or 16 bit */
 	if (pPixmap->drawable.bitsPerPixel == 8) {
 		fg |= fg << 8;
 		fg |= fg << 16;
+	} else if (pPixmap->drawable.bitsPerPixel == 16) {
+		fg |= fg << 16;
 	}
 	write_sx_reg(p, SX_QUEUED(8), fg);
 	write_sx_reg(p, SX_QUEUED(9), fg);
@@ -974,6 +987,90 @@ CG14Solid32(Cg14Ptr p, uint32_t start, u
 }
 
 static void
+CG14Solid16(Cg14Ptr p, uint32_t start, uint32_t pitch, int w, int h)
+{
+	int line, num, pre, cnt;
+	uint32_t ptr;
+
+	ENTER;
+	pre = start & 2;
+	if (pre != 0) pre = 1;
+
+	if (p->last_rop == 0xcc) {
+		/* simple fill */
+		for (line = 0; line < h; line++) {
+			ptr = start;
+			cnt = w;
+			if (pre) {
+				sxm(SX_STW, ptr, 8, 0);
+				ptr += 2;
+				cnt -= 1;
+				if (cnt == 0) goto next;
+			}
+			/* now do the aligned pixels in 32bit chunks */
+			if (ptr & 3) xf86Msg(X_ERROR, "%s %x\n", __func__, ptr);
+			while(cnt > 1) {
+				num = min(32, cnt >> 1);
+				sxm(SX_STS, ptr, 8, num - 1);
+				ptr += num << 2;
+				cnt -= num << 1;
+			}
+			if (cnt > 1) xf86Msg(X_ERROR, "%s cnt %d\n", __func__, cnt);
+			if (cnt > 0) {
+				sxm(SX_STW, ptr, 8, 0);
+			}
+next:
+			start += pitch;
+		}
+	} else if (p->last_rop == 0xaa) {
+		/* nothing to do here */
+		return;
+	} else {
+		/* alright, let's do actual ROP stuff */
+
+		/* first repeat the fill colour into 16 registers */
+		sxi(SX_SELECT_S, 8, 8, 10, 15);
+
+		for (line = 0; line < h; line++) {
+			ptr = start;
+			cnt = w;
+			pre = min(pre, cnt);
+			if (pre) {
+				sxm(SX_LDW, ptr, 26, 0);
+				sxi(SX_ROP, 10, 26, 42, 0);
+				sxm(SX_STW, ptr, 42, 0);
+				ptr += 2;
+				cnt -= 1;
+				if (cnt == 0) goto next2;
+			}
+			/* now do the aligned pixels in 32bit chunks */
+			if (ptr & 3) xf86Msg(X_ERROR, "%s %x\n", __func__, ptr);
+			while(cnt > 1) {
+				num = min(32, cnt >> 1);
+				sxm(SX_LD, ptr, 26, num - 1);
+				if (num <= 16) {
+					sxi(SX_ROP, 10, 26, 58, num - 1);
+				} else {
+					sxi(SX_ROP, 10, 26, 58, 15);
+					sxi(SX_ROP, 10, 42, 74, num - 17);
+				}
+				sxm(SX_ST, ptr, 58, num - 1);
+				ptr += num << 2;
+				cnt -= num << 1;
+			}
+			if (cnt > 1) xf86Msg(X_ERROR, "%s cnt %d\n", __func__, cnt);
+			if (cnt > 0) {
+				sxm(SX_LDW, ptr, 26, 0);
+				sxi(SX_ROP, 10, 26, 42, 0);
+				sxm(SX_STW, ptr, 42, 0);
+			}
+next2:
+			start += pitch;
+		}
+	}
+}
+
+static void
 CG14Solid8(Cg14Ptr p, uint32_t start, uint32_t pitch, int w, int h)
 {
 	int line, num, pre, cnt;
@@ -1078,6 +1175,10 @@ CG14Solid(PixmapPtr pPixmap, int x1, int
 			start = dstoff + (y1 * dstpitch) + (x1 << 2);
 			CG14Solid32(p, start, dstpitch, w, h);
 			break;
+		case 16:
+			start = dstoff + (y1 * dstpitch) + (x1 << 1);
+			CG14Solid16(p, start, dstpitch, w, h);
+			break;
 		case 8:
 			start = dstoff + (y1 * dstpitch) + x1;
 			CG14Solid8(p, start, dstpitch, w, h);

Index: xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_driver.c
diff -u xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_driver.c:1.21 xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_driver.c:1.22
--- xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_driver.c:1.21	Wed Apr 24 11:42:06 2024
+++ xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_driver.c	Mon May 13 10:13:10 2024
@@ -367,10 +367,12 @@ CG14PreInit(ScrnInfoPtr pScrn, int flags
     
     if (!xf86SetDepthBpp(pScrn, 0, 0, 0, Support24bppFb|Support32bppFb))
 		return FALSE;
+
     /* Check that the returned depth is one we support */
     switch (pScrn->depth) {
 	case 32:
 	case 24:
+	case 16:
 	case 8:
 	    /* OK */
 	    break;
@@ -405,15 +407,20 @@ CG14PreInit(ScrnInfoPtr pScrn, int flags
      * This must happen after pScrn->display has been set because
      * xf86SetWeight references it.
      */
-    if (pScrn->depth > 8) {
+    if (pScrn->depth > 16) {
 	rgb weight = {0, 0, 0};
 	rgb mask = {0xff, 0xff00, 0xff0000};
                                        
 	if (!xf86SetWeight(pScrn, weight, mask)) {
 	    return FALSE;
 	}
-    }
-                                                                           
+    } else if (pScrn->depth > 8) {
+  	rgb zeroes = {0, 0, 0};
+                                       
+	if (!xf86SetWeight(pScrn, zeroes, zeroes)) {
+	    return FALSE;
+	}
+    }                                                             
     if (!xf86SetDefaultVisual(pScrn, -1))
 	return FALSE;
     else if (pScrn->depth > 8) {
@@ -804,10 +811,10 @@ CG14WindowLinear(ScreenPtr pScreen, CARD
 {
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     Cg14Ptr pCg14 = GET_CG14_FROM_SCRN(pScrn);
-    int shift = (pScrn->bitsPerPixel > 8) ? 2 : 0;
+    int mul = (pScrn->bitsPerPixel >> 3);
 
-    *size = pCg14->width << shift;
-    return (CARD8 *)pCg14->fb + row * (pCg14->width << shift) + offset;
+    *size = pCg14->width * mul;
+    return (CARD8 *)pCg14->fb + row * (pCg14->width * mul) + offset;
 }
 
 /* Free up any per-generation data structures */
@@ -875,17 +882,27 @@ static void
 CG14InitCplane24(ScrnInfoPtr pScrn)
 {
   Cg14Ptr pCg14 = GET_CG14_FROM_SCRN(pScrn);
-  int size, bpp;
-              
+  int size, bpp = 0;
+
   size = pScrn->virtualX * pScrn->virtualY;
-  if (pScrn->bitsPerPixel > 8) {
-  	bpp = 32;
-  } else
-  	bpp = 8;
+  switch (pScrn->bitsPerPixel) {
+  	case 8:
+  	case 16:
+  	    bpp = pScrn->bitsPerPixel;
+  	    break;
+  	case 24:
+  	case 32:
+  	    bpp = 32;
+  	default:
+  	    xf86Msg(X_ERROR, "Unsupported depth %d\n", pScrn->bitsPerPixel);
+  }
+  if (bpp == 0) return;
   ioctl (pCg14->psdp->fd, CG14_SET_PIXELMODE, &bpp);
   memset (pCg14->fb, 0, size * (bpp >> 3));
   memset (pCg14->x32, 0, size);
+#ifndef __NetBSD__
   memset (pCg14->xlut, 0, 0x200);
+#endif
 }                                                  
 
 /*

Reply via email to