ref: f5639c63e47ecd41fcd77039d821a80cfc75b938
parent: 66c514def603a3e4c4a7974477b1bcd98ac0b451
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Jan 30 13:52:06 EST 2019
devdraw: get rid of softscreen==0xa110c hack and make attachscreen() return Memdata* (from 9front)
--- a/gui-cocoa/screen.m
+++ b/gui-cocoa/screen.m
@@ -54,7 +54,7 @@
gscreen->clipr = ZR;
}
-uchar *
+Memdata*
attachscreen(Rectangle *r, ulong *chan, int *depth, int *width, int *softscreen)
{
*r = gscreen->clipr;
@@ -61,11 +61,10 @@
*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
+++ b/gui-osx/screen.c
@@ -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
+++ b/gui-win32/screen.c
@@ -98,7 +98,7 @@
gscreen->clipr = ZR;
}
-uchar*
+Memdata*
attachscreen(Rectangle *r, ulong *chan, int *depth, int *width, int *softscreen)
{
*r = gscreen->clipr;
@@ -105,11 +105,10 @@
*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
+++ b/gui-x11/x11.c
@@ -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
+++ b/kern/devdraw.c
@@ -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
+++ b/kern/screen.h
@@ -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);