code: plan9front

Download patch

ref: 744053268d196e8c282d20243600fb33d4df0028
parent: cff0ebade5fb37b3d5614ae9ff76513e4b0e4640
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Dec 5 15:11:33 EST 2022

imx8: a simple softscreen

--- a/sys/src/9/imx8/lcd.c
+++ b/sys/src/9/imx8/lcd.c
@@ -12,7 +12,7 @@
 #include	<cursor.h>
 #include	"screen.h"
 
-extern Memimage *gscreen;
+extern u8int *fbraw;
 
 /* system reset controller registers */
 enum {
@@ -504,8 +504,8 @@
 	wr(lcdif, LCDIF_VDCTRL4,
 		sm(mode->hactive, VDCTRL4_DOTCLK_H_VALID_DATA_CNT));
 
-	wr(lcdif, LCDIF_CUR_BUF, PADDR(gscreen->data->bdata));
-	wr(lcdif, LCDIF_NEXT_BUF, PADDR(gscreen->data->bdata));
+	wr(lcdif, LCDIF_CUR_BUF, PADDR(fbraw));
+	wr(lcdif, LCDIF_NEXT_BUF, PADDR(fbraw));
 
 	wr(lcdif, LCDIF_CTRL_SET, CTRL_DOTCLK_MODE);
 
--- a/sys/src/9/imx8/screen.c
+++ b/sys/src/9/imx8/screen.c
@@ -16,6 +16,7 @@
 };
 
 Memimage *gscreen;
+u8int *fbraw;
 
 static Memdata xgdata;
 static Memimage xgscreen;
@@ -125,15 +126,15 @@
 	xgscreen.clipr = xgscreen.r;
 	xgscreen.depth = depth;
 	xgscreen.width = wordsperline(xgscreen.r, xgscreen.depth);
-	xgdata.bdata = fbmemalloc(xgscreen.width*sizeof(ulong)*height);
+	xgdata.bdata = malloc(xgscreen.width*sizeof(ulong)*height);
 	xgdata.ref = 1;
 
 	xgscreen.data = &xgdata;
-
 	gscreen = &xgscreen;
-
 	conf.monitor = 1;
 
+	fbraw = fbmemalloc(xgscreen.width*sizeof(ulong)*height);
+
 	memimageinit();
 	memdefont = getmemdefont();
 	screenwin();
@@ -145,12 +146,26 @@
 }
 
 void
-flushmemscreen(Rectangle)
+flushmemscreen(Rectangle r)
 {
+	int pitch, n, y;
+	ulong *d, *s;
+
+	if(rectclip(&r, xgscreen.r)){
+		s = wordaddr(&xgscreen, r.min);
+		d = (ulong*)fbraw + (s - wordaddr(&xgscreen, xgscreen.r.min));
+		n = bytesperline(r, xgscreen.depth);
+		pitch = wordsperline(xgscreen.r, xgscreen.depth);
+		for(y = 0; y < Dy(r); y++){
+			memmove(d, s, n);
+			d += pitch;
+			s += pitch;
+		}
+	}
 }
 
 Memdata*
-attachscreen(Rectangle *r, ulong *chan, int* d, int *width, int *softscreen)
+attachscreen(Rectangle *r, ulong *chan, int *d, int *width, int *softscreen)
 {
 	if(gscreen == nil)
 		return nil;
@@ -159,7 +174,7 @@
 	*d = gscreen->depth;
 	*chan = gscreen->chan;
 	*width = gscreen->width;
-	*softscreen = 0;
+	*softscreen = 1;
 
 	gscreen->data->ref++;
 	return gscreen->data;