shithub: drawterm

Download patch

ref: f5639c63e47ecd41fcd77039d821a80cfc75b938
parent: 66c514def603a3e4c4a7974477b1bcd98ac0b451
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Jan 30 12:52:06 EST 2019

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

--- a/gui-cocoa/screen.m	Wed Jan 30 05:38:08 2019
+++ b/gui-cocoa/screen.m	Wed Jan 30 12:52:06 2019
@@ -54,18 +54,17 @@
 	gscreen->clipr = ZR;
 }
 
-uchar *
+Memdata*
 attachscreen(Rectangle *r, ulong *chan, int *depth, int *width, int *softscreen)
 {
 	*r = gscreen->clipr;
 	*chan = gscreen->chan;
 	*depth = gscreen->depth;
 	*width = gscreen->width;
+	*softscreen = 1;
 
-	*softscreen = 0xa110c;
 	gscreen->data->ref++;
-
-	return gscreen->data->bdata;
+	return gscreen->data;
 }
 
 char *
--- a/gui-osx/screen.c	Wed Jan 30 05:38:08 2019
+++ b/gui-osx/screen.c	Wed Jan 30 12:52:06 2019
@@ -564,7 +564,7 @@
 		gscreen->width*sizeof(ulong));
 }
 
-uchar*
+Memdata*
 attachscreen(Rectangle *r, ulong *chan, int *depth, int *width, int *softscreen)
 {
 	*r = gscreen->r;
@@ -573,7 +573,8 @@
 	*width = gscreen->width;
 	*softscreen = 1;
 
-	return gscreen->data->bdata;
+	gscreen->data->ref++;
+	return gscreen->data;
 }
 
 // PAL - no palette handling.  Don't intend to either.
--- a/gui-win32/screen.c	Wed Jan 30 05:38:08 2019
+++ b/gui-win32/screen.c	Wed Jan 30 12:52:06 2019
@@ -98,18 +98,17 @@
 	gscreen->clipr = ZR;
 }
 
-uchar*
+Memdata*
 attachscreen(Rectangle *r, ulong *chan, int *depth, int *width, int *softscreen)
 {
 	*r = gscreen->clipr;
 	*chan = gscreen->chan;
 	*depth = gscreen->depth;
 	*width = gscreen->width;
+	*softscreen = 1;
 
-	*softscreen = 0xa110c;
 	gscreen->data->ref++;
-
-	return gscreen->data->bdata;
+	return gscreen->data;
 }
 
 void
--- a/gui-x11/x11.c	Wed Jan 30 05:38:08 2019
+++ b/gui-x11/x11.c	Wed Jan 30 12:52:06 2019
@@ -185,7 +185,7 @@
 	USED(chan);
 }
 
-uchar*
+Memdata*
 attachscreen(Rectangle *r, ulong *chan, int *depth, int *width, int *softscreen)
 {
 	*r = gscreen->clipr;
@@ -194,7 +194,8 @@
 	*width = gscreen->width;
 	*softscreen = 1;
 
-	return gscreen->data->bdata;
+	gscreen->data->ref++;
+	return gscreen->data;
 }
 
 static int
--- a/kern/devdraw.c	Wed Jan 30 05:38:08 2019
+++ b/kern/devdraw.c	Wed Jan 30 12:52:06 2019
@@ -916,33 +916,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/kern/screen.h	Wed Jan 30 05:38:08 2019
+++ b/kern/screen.h	Wed Jan 30 12:52:06 2019
@@ -50,7 +50,7 @@
 void	setcursor(void);
 void	mouseset(Point);
 void	flushmemscreen(Rectangle);
-uchar*	attachscreen(Rectangle*, ulong*, int*, int*, int*);
+Memdata*attachscreen(Rectangle*, ulong*, int*, int*, int*);
 void	deletescreenimage(void);
 void	resetscreenimage(void);