shithub: riscv

Download patch

ref: cefc849a9521c9d5ba85d5aa88526d0f4b059db9
parent: 8e1218acebcb87bcf16e6bca5b5f213ff2a1df3a
author: cinap_lenrek <[email protected]>
date: Wed Jan 30 13:22:52 EST 2019

devdraw: get rid of softscreen==0xa110c hack and make attachscreen() return Memdata*

all screen implementations use a Memimage* internally
for the framebuffer, so we can return a shared reference
to its Memdata structure in attachscreen() instead of
a framebuffer data pointer.

this eleminates the softscreen == 0xa110c hack as we
always use shared Memdata* now.

--- a/sys/src/9/bcm/screen.c
+++ b/sys/src/9/bcm/screen.c
@@ -171,9 +171,12 @@
 {
 }
 
-uchar*
+Memdata*
 attachscreen(Rectangle *r, ulong *chan, int* d, int *width, int *softscreen)
 {
+	if(gscreen == nil)
+		return nil;
+
 	*r = gscreen->r;
 	*d = gscreen->depth;
 	*chan = gscreen->chan;
@@ -180,7 +183,8 @@
 	*width = gscreen->width;
 	*softscreen = 0;
 
-	return gscreen->data->bdata;
+	gscreen->data->ref++;
+	return gscreen->data;
 }
 
 void
--- a/sys/src/9/bcm/screen.h
+++ b/sys/src/9/bcm/screen.h
@@ -26,7 +26,7 @@
 /* screen.c */
 extern void	blankscreen(int);
 extern void	flushmemscreen(Rectangle);
-extern uchar*	attachscreen(Rectangle*, ulong*, int*, int*, int*);
+extern Memdata*	attachscreen(Rectangle*, ulong*, int*, int*, int*);
 extern void	cursoron(void);
 extern void	cursoroff(void);
 extern void	setcursor(Cursor*);
--- a/sys/src/9/omap/screen.c
+++ b/sys/src/9/omap/screen.c
@@ -436,15 +436,20 @@
 /*
  * export screen to devdraw
  */
-uchar*
-attachscreen(Rectangle *r, ulong *chan, int *d, int *width, int *softscreen)
+Memdata*
+attachscreen(Rectangle *r, ulong *chan, int* d, int *width, int *softscreen)
 {
+	if(gscreen == nil)
+		return nil;
+
 	*r = gscreen->r;
 	*d = gscreen->depth;
 	*chan = gscreen->chan;
 	*width = gscreen->width;
 	*softscreen = (landscape == 0);
-	return (uchar *)gscreen->data->bdata;
+
+	gscreen->data->ref++;
+	return gscreen->data;
 }
 
 void
--- a/sys/src/9/omap/screen.h
+++ b/sys/src/9/omap/screen.h
@@ -23,7 +23,7 @@
 extern void	mouseredraw(void);
 
 /* screen.c */
-extern uchar* attachscreen(Rectangle*, ulong*, int*, int*, int*);
+extern Memdata* attachscreen(Rectangle*, ulong*, int*, int*, int*);
 extern void	flushmemscreen(Rectangle);
 extern void	cursoron(void);
 extern void	cursoroff(void);
--- a/sys/src/9/pc/screen.c
+++ b/sys/src/9/pc/screen.c
@@ -124,7 +124,7 @@
 	return 0;
 }
 
-uchar*
+Memdata*
 attachscreen(Rectangle* r, ulong* chan, int* d, int* width, int *softscreen)
 {
 	VGAscr *scr;
@@ -137,18 +137,10 @@
 	*chan = scr->gscreen->chan;
 	*d = scr->gscreen->depth;
 	*width = scr->gscreen->width;
-	if(scr->gscreendata->allocd){
-		/*
-		 * we use a memimage as softscreen. devdraw will create its own
-		 * screen image on the backing store of that image. when our gscreen
-		 * and devdraws screenimage gets freed, the imagedata will
-		 * be released.
-		 */
-		*softscreen = 0xa110c;
-		scr->gscreendata->ref++;
-	} else
-		*softscreen = scr->useflush ? 1 : 0;
-	return scr->gscreendata->bdata;
+	*softscreen = (scr->gscreendata->allocd || scr->useflush) ? 1 : 0;
+
+	scr->gscreendata->ref++;
+	return scr->gscreendata;
 }
 
 void
--- a/sys/src/9/pc/screen.h
+++ b/sys/src/9/pc/screen.h
@@ -138,7 +138,7 @@
 extern int		hwblank;	/* use hw blanking */
 extern int		panning;	/* use virtual screen panning */
 extern void addvgaseg(char*, ulong, ulong);
-extern uchar* attachscreen(Rectangle*, ulong*, int*, int*, int*);
+extern Memdata* attachscreen(Rectangle*, ulong*, int*, int*, int*);
 extern void	flushmemscreen(Rectangle);
 extern void	cursoron(void);
 extern void	cursoroff(void);
--- a/sys/src/9/port/devdraw.c
+++ b/sys/src/9/port/devdraw.c
@@ -918,33 +918,14 @@
 	Memdata *md;
 	Memimage *i;
 	Rectangle r;
-	uchar *data;
 
-	if((data = attachscreen(&r, &chan, &depth, &width, &sdraw.softscreen)) == nil)
+	if((md = attachscreen(&r, &chan, &depth, &width, &sdraw.softscreen)) == nil)
 		return nil;
-	if(sdraw.softscreen == 0xa110c){
-		/* hack: softscreen is memimage. */
-		md = *((Memdata**)(data - sizeof(ulong) - sizeof(Memdata*)));
-
-		assert(md->bdata == data);
-		assert(md->ref > 1);
-		assert(md->allocd);
-
-		if((i = allocmemimaged(r, chan, md)) == nil){
-			md->ref--;
-			return nil;
-		}
-	}else{
-		if((md = malloc(sizeof *md)) == nil)
-			return nil;
-		md->allocd = 1;
-		md->base = nil;
-		md->bdata = data;
-		md->ref = 1;
-		if((i = allocmemimaged(r, chan, md)) == nil){
+	assert(md->ref > 0);
+	if((i = allocmemimaged(r, chan, md)) == nil){
+		if(--md->ref == 0 && md->allocd)
 			free(md);
-			return nil;
-		}
+		return nil;
 	}
 	i->width = width;
 	i->clipr = r;
--- a/sys/src/9/sgi/screen.c
+++ b/sys/src/9/sgi/screen.c
@@ -600,19 +600,20 @@
 	mouseaccelerate(3);
 }
 
-uchar*
+Memdata*
 attachscreen(Rectangle *r, ulong *chan, int* d, int *width, int *softscreen)
 {
+	if(gscreen == nil)
+		return nil;
+
 	*r = gscreen->r;
 	*d = gscreen->depth;
 	*chan = gscreen->chan;
 	*width = gscreen->width;
+	*softscreen = 1;
 
-	/* make devdraw use gscreen->data */
-	*softscreen = 0xa110c;
 	gscreen->data->ref++;
-
-	return gscreen->data->bdata;
+	return gscreen->data;
 }
 
 void
--- a/sys/src/9/sgi/screen.h
+++ b/sys/src/9/sgi/screen.h
@@ -26,7 +26,7 @@
 /* screen.c */
 extern void	blankscreen(int);
 extern void	flushmemscreen(Rectangle);
-extern uchar*	attachscreen(Rectangle*, ulong*, int*, int*, int*);
+extern Memdata*	attachscreen(Rectangle*, ulong*, int*, int*, int*);
 extern void	cursoron(void);
 extern void	cursoroff(void);
 extern void	setcursor(Cursor*);
--- a/sys/src/9/zynq/screen.c
+++ b/sys/src/9/zynq/screen.c
@@ -65,7 +65,7 @@
 	conf.monitor = 1;
 }
 
-uchar*
+Memdata*
 attachscreen(Rectangle *r, ulong *chan, int* d, int *width, int *softscreen)
 {
 	if(gscreen == nil)
@@ -75,12 +75,10 @@
 	*d = gscreen->depth;
 	*chan = gscreen->chan;
 	*width = gscreen->width;
+	*softscreen = 1;
 
-	/* make devdraw use gscreen->data */
-	*softscreen = 0xa110c;
 	gscreen->data->ref++;
-
-	return gscreen->data->bdata;
+	return gscreen->data;
 }
 
 void
--- a/sys/src/9/zynq/screen.h
+++ b/sys/src/9/zynq/screen.h
@@ -26,7 +26,7 @@
 /* screen.c */
 extern void	blankscreen(int);
 extern void	flushmemscreen(Rectangle);
-extern uchar*	attachscreen(Rectangle*, ulong*, int*, int*, int*);
+extern Memdata*	attachscreen(Rectangle*, ulong*, int*, int*, int*);
 extern void	cursoron(void);
 extern void	cursoroff(void);
 extern void	setcursor(Cursor*);
--- a/sys/src/cmd/vnc/devdraw.c
+++ b/sys/src/cmd/vnc/devdraw.c
@@ -925,33 +925,14 @@
 	Memdata *md;
 	Memimage *i;
 	Rectangle r;
-	uchar *data;
 
-	if((data = attachscreen(&r, &chan, &depth, &width, &sdraw.softscreen)) == nil)
+	if((md = attachscreen(&r, &chan, &depth, &width, &sdraw.softscreen)) == nil)
 		return nil;
-	if(sdraw.softscreen == 0xa110c){
-		/* hack: softscreen is memimage. */
-		md = *((Memdata**)(data - sizeof(ulong) - sizeof(Memdata*)));
-
-		assert(md->bdata == data);
-		assert(md->ref > 1);
-		assert(md->allocd);
-
-		if((i = allocmemimaged(r, chan, md)) == nil){
-			md->ref--;
-			return nil;
-		}
-	}else{
-		if((md = malloc(sizeof *md)) == nil)
-			return nil;
-		md->allocd = 1;
-		md->base = nil;
-		md->bdata = data;
-		md->ref = 1;
-		if((i = allocmemimaged(r, chan, md)) == nil){
+	assert(md->ref > 0);
+	if((i = allocmemimaged(r, chan, md)) == nil){
+		if(--md->ref == 0 && md->allocd)
 			free(md);
-			return nil;
-		}
+		return nil;
 	}
 	i->width = width;
 	i->clipr = r;
--- a/sys/src/cmd/vnc/screen.c
+++ b/sys/src/cmd/vnc/screen.c
@@ -126,7 +126,7 @@
 	qunlock(&drawlock);
 }
 
-uchar*
+Memdata*
 attachscreen(Rectangle* r, ulong* chan, int* d, int* width, int *softscreen)
 {
 	*r = gscreen->clipr;
@@ -135,7 +135,8 @@
 	*width = gscreen->width;
 	*softscreen = 1;
 
-	return gscreen->data->bdata;
+	gscreen->data->ref++;
+	return gscreen->data;
 }
 
 void
--- a/sys/src/cmd/vnc/screen.h
+++ b/sys/src/cmd/vnc/screen.h
@@ -29,7 +29,7 @@
 void		screeninit(int x, int y, char *chanstr);
 void		screenwin(void);
 void		absmousetrack(int x, int y, int b, ulong msec);
-uchar		*attachscreen(Rectangle*, ulong*, int*, int*, int*);
+Memdata*	attachscreen(Rectangle*, ulong*, int*, int*, int*);
 void		deletescreenimage(void);
 void		resetscreenimage(void);