[<<] [<] Page 1 of 1 [>] [>>] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
Patch for Shared Memory Pixmaps
From: "David T Eger" ####@####.#### Date: 9 Aug 2001 15:45:54 -0000 Message-Id: <OF290A2E8B.6BC65C16-ON85256AA3.00559065@raleigh.ibm.com> I've made a modification to nano-X to support the following mode of interaction: + User program shmget()s and shmat()s a portion of shared memory to use as a pixmap in the same format as the screen (i.e. if the screen is 16bpp, this buffer is 16bpp) + User program sends GrNewPixmap the shm id of this region. + nano-X shmat()s the region, and uses it later on with Pixmap functions One problem is that to support this patch, the format of GrNewPixmap changes, possibly breaking a number of programs. It goes from: < GR_WINDOW_ID GrNewPixmap(GR_SIZE width, GR_SIZE height, void * addr); ---- > GR_WINDOW_ID GrNewPixmap(GR_SIZE width, GR_SIZE height, int shmid); and the default of "No, this isn't shared memory, just a regular old Pixmap request" goes from addr=0 to shmid=-1, since shmget() specifies -1 as the invalid value for the id of a System V shared memory region. Is this useful? Is it the same intent as the FIXME comments for shared memory? Should I clean it up and post it somewhere? -David | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
Re: [nanogui] Patch for Shared Memory Pixmaps
From: "Greg Haerr" ####@####.#### Date: 9 Aug 2001 15:52:33 -0000 Message-Id: <04e301c120ea$f8269a00$3aba46a6@xmission.com> : and the default of "No, this isn't shared memory, just a regular old Pixmap : request" goes from addr=0 to shmid=-1, since shmget() specifies -1 as the : invalid value for the id of a System V shared memory region. : : Is this useful? Is it the same intent as the FIXME comments for shared : memory? Should I clean it up and post it somewhere? David, This sounds great! I definitely suggest cleaning it up, and sending me the patch. I need to think a bit about whether to change the old API, or use the old one. I'm thinking that perhaps one answer is an address and a flags argument, which can indicate the type of memory that is being passed to GrNewPixmap. Then, we add an additional server call that allows memory to be mapped in-between processes, so that either the server or client can draw into it. This idea fits with the new client-side framebuffer mapping that I've implemented for pre9. Perhaps the same server call could be used to map shared framebuffer memory as well as pixmap memory. Nonetheless, I need to think about this a bit. Regards, Greg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
Re: [nanogui] Patch for Shared Memory Pixmaps
From: Jordan Crouse ####@####.#### Date: 9 Aug 2001 15:55:18 -0000 Message-Id: <01080909552802.01574@cosmic> I would add a new client function called GrNewSharedPixmap() and keep the old GrNewPixmap() (for compatibility), and then just have them both make the same server call with different paremeters. That would allow programs to maintain compatibility, while at the same time saving you the effort of writing two different server calls. And of course, throw a #ifdef HAVE_SHAREDMEM_SUPPORT around all the shared memory calls to avoid any issues with less capable libcs. Jordan On Thursday 09 August 2001 09:45, David T Eger mentioned: > I've made a modification to nano-X to support the following mode of > interaction: > > + User program shmget()s and shmat()s a portion of shared memory to use as > a pixmap in the same format as the screen (i.e. if the screen is 16bpp, > this buffer is 16bpp) > + User program sends GrNewPixmap the shm id of this region. > + nano-X shmat()s the region, and uses it later on with Pixmap functions > > One problem is that to support this patch, the format of GrNewPixmap > changes, possibly breaking a number of programs. It goes from: > > < GR_WINDOW_ID GrNewPixmap(GR_SIZE width, GR_SIZE height, void * addr); > ---- > > > GR_WINDOW_ID GrNewPixmap(GR_SIZE width, GR_SIZE height, int shmid); > > and the default of "No, this isn't shared memory, just a regular old Pixmap > request" goes from addr=0 to shmid=-1, since shmget() specifies -1 as the > invalid value for the id of a System V shared memory region. > > Is this useful? Is it the same intent as the FIXME comments for shared > memory? Should I clean it up and post it somewhere? > > -David > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: ####@####.#### > For additional commands, e-mail: ####@####.#### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
Re: Patch for Shared Memory Pixmaps
From: David T Eger ####@####.#### Date: 14 Aug 2001 05:41:28 -0000 Message-Id: <Pine.SOL.4.21.0108140134150.24767-100000@oscar.cc.gatech.edu> Sorry about the wait. Been busy cleaning up a Framebuffer driver. Here's the patch. I haven't differentiated GrNewPixmap() into separate functions (as Jordan suggested) from the standard code for several reasons: (1) If we really do link statically and pass a pointer, then isn't the client/server X model sort of misplaced? (2) 0 is not an invalid SHM key, however -1 is an invalid SHM key, and also an invalid pointer. We will never have a one byte pixmap at the end of memory (3) I'm too lazy to rewrite it right now. -David Eger diff -u -r microwin/src/contrib/speedtst/speed.c microwin-shm/src/contrib/speedtst/speed.c --- microwin/src/contrib/speedtst/speed.c Thu Jun 21 01:32:39 2001 +++ microwin-shm/src/contrib/speedtst/speed.c Tue Aug 14 00:17:42 2001 @@ -60,6 +60,7 @@ window = XCreateSimpleWindow(display, RootWindow(display, screenNum), 0, 0 , 639, 479, 0, fgColor, bgColor); +#error Broken by change in GrNewPixmap API src_pixmap = XCreatePixmap(display, window, 320, 240, 16); XMapRaised(display, window); gcValues.background = bgColor; diff -u -r microwin/src/demos/nanox/Makefile microwin-shm/src/demos/nanox/Makefile --- microwin/src/demos/nanox/Makefile Thu Jun 21 01:32:40 2001 +++ microwin-shm/src/demos/nanox/Makefile Tue Aug 14 00:17:42 2001 @@ -58,12 +58,12 @@ t1demo.o \ ftdemo.o \ logfont.o \ - slider.o \ ntetris.o \ launcher.o \ nsaver.o \ getselection.o \ setselection.o +# slider.o \ TARGETS = $(TOP)/bin/demo $(TOP)/bin/move $(TOP)/bin/landmine \ $(TOP)/bin/world $(TOP)/bin/nxclock $(TOP)/bin/nxterm \ @@ -71,8 +71,9 @@ $(TOP)/bin/npanel $(TOP)/bin/nterm \ $(TOP)/bin/demo2 $(TOP)/bin/demo5 $(TOP)/bin/demo6 \ $(TOP)/bin/t1demo $(TOP)/bin/ftdemo $(TOP)/bin/logfont \ - $(TOP)/bin/slider $(TOP)/bin/ntetris $(TOP)/bin/launcher \ + $(TOP)/bin/ntetris $(TOP)/bin/launcher \ $(TOP)/bin/nsaver $(TOP)/bin/getselection $(TOP)/bin/setselection +# $(TOP)/bin/slider endif all: default $(TARGETS) diff -u -r microwin/src/demos/nanox/demo5.c microwin-shm/src/demos/nanox/demo5.c --- microwin/src/demos/nanox/demo5.c Thu Jun 21 01:32:40 2001 +++ microwin-shm/src/demos/nanox/demo5.c Tue Aug 14 00:17:42 2001 @@ -75,7 +75,7 @@ w4 = GrNewWindow(GR_ROOT_WINDOW_ID, 350, 20, 200, 150, 5, BLACK, WHITE); w5 = GrNewWindow(GR_ROOT_WINDOW_ID, 11, 143, 209, 100, 1, BLUE, GREEN); - p1 = GrNewPixmap(200,200,0); + p1 = GrNewPixmap(200,200,-1); GrSelectEvents(w1, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_EXPOSURE | diff -u -r microwin/src/demos/nanox/demo6.c microwin-shm/src/demos/nanox/demo6.c --- microwin/src/demos/nanox/demo6.c Thu Jun 21 01:32:40 2001 +++ microwin-shm/src/demos/nanox/demo6.c Tue Aug 14 00:17:42 2001 @@ -114,7 +114,7 @@ #ifdef USE_PIXMAPS /* Create the pixmap to store the picture in */ - pmap = GrNewPixmap(width, height, NULL); + pmap = GrNewPixmap(width, height, -1); #endif /* Create a graphics context */ diff -u -r microwin/src/demos/nanox/launcher.c microwin-shm/src/demos/nanox/launcher.c --- microwin/src/demos/nanox/launcher.c Thu Jun 21 01:32:40 2001 +++ microwin-shm/src/demos/nanox/launcher.c Tue Aug 14 00:17:42 2001 @@ -524,7 +524,7 @@ GrGetImageInfo(back_image, &imageinfo); if(!(state->background_pixmap = GrNewPixmap( imageinfo.width, - imageinfo.height, NULL))) { + imageinfo.height, -1))) { fprintf(stderr, "Couldn't allocate pixmap " "for background image\n"); } else { diff -u -r microwin/src/demos/nanox/slider.c microwin-shm/src/demos/nanox/slider.c --- microwin/src/demos/nanox/slider.c Thu Jun 21 01:32:40 2001 +++ microwin-shm/src/demos/nanox/slider.c Tue Aug 14 00:17:42 2001 @@ -44,6 +44,8 @@ static void MoveTile(); static void DrawTile(); +#error Broken by change in GrNewPixmap API + int main(int argc,char **argv) { diff -u -r microwin/src/include/nano-X.h microwin-shm/src/include/nano-X.h --- microwin/src/include/nano-X.h Wed Jul 4 14:11:02 2001 +++ microwin-shm/src/include/nano-X.h Tue Aug 14 00:17:42 2001 @@ -234,6 +234,9 @@ #define GR_ERROR_SCREEN_ERROR 11 #define GR_ERROR_UNMAPPED_FOCUS_WINDOW 12 #define GR_ERROR_BAD_DRAWING_MODE 13 +#ifdef HAVE_SHAREDMEM +#define GR_ERROR_BAD_SHM 14 +#endif /* Event types. * Mouse motion is generated for every motion of the mouse, and is used to @@ -527,7 +530,8 @@ "Clipping overflow\n", \ "Screen error\n", \ "Unmapped focus window: %d\n", \ - "Bad drawing mode gc: %d\n" + "Bad drawing mode gc: %d\n", \ + "Bad Shared Memory ID\n" extern char *nxErrorStrings[]; @@ -541,7 +545,7 @@ GR_WINDOW_ID GrNewWindow(GR_WINDOW_ID parent, GR_COORD x, GR_COORD y, GR_SIZE width, GR_SIZE height, GR_SIZE bordersize, GR_COLOR background, GR_COLOR bordercolor); -GR_WINDOW_ID GrNewPixmap(GR_SIZE width, GR_SIZE height, void * addr); +GR_WINDOW_ID GrNewPixmap(GR_SIZE width, GR_SIZE height, int shm_id); GR_WINDOW_ID GrNewInputWindow(GR_WINDOW_ID parent, GR_COORD x, GR_COORD y, GR_SIZE width, GR_SIZE height); void GrDestroyWindow(GR_WINDOW_ID wid); diff -u -r microwin/src/nanox/client.c microwin-shm/src/nanox/client.c --- microwin/src/nanox/client.c Wed Jul 4 15:10:32 2001 +++ microwin-shm/src/nanox/client.c Tue Aug 14 00:18:37 2001 @@ -958,9 +958,8 @@ * copied into a window using a GrCopyArea call) of the specified width and * height. */ -/* FIXME: Add support for shared memory... */ GR_WINDOW_ID -GrNewPixmap(GR_SIZE width, GR_SIZE height, void *addr) +GrNewPixmap(GR_SIZE width, GR_SIZE height, int shmid) { nxNewPixmapReq *req; GR_WINDOW_ID wid; @@ -968,6 +967,7 @@ req = AllocReq(NewPixmap); req->width = width; req->height = height; + req->shmid = shmid; if(GrTypedReadBlock(&wid, sizeof(wid), GrNumNewPixmap) == -1) return 0; return wid; diff -u -r microwin/src/nanox/nxproto.h microwin-shm/src/nanox/nxproto.h --- microwin/src/nanox/nxproto.h Wed Jul 4 15:22:09 2001 +++ microwin-shm/src/nanox/nxproto.h Tue Aug 14 00:19:04 2001 @@ -598,7 +598,7 @@ UINT16 length; INT16 width; INT16 height; -/* FIXME: Add support for passing shared memory info */ + int shmid; } nxNewPixmapReq; #define GrNumCopyArea 51 diff -u -r microwin/src/nanox/nxutil.c microwin-shm/src/nanox/nxutil.c --- microwin/src/nanox/nxutil.c Thu Jun 21 01:32:42 2001 +++ microwin-shm/src/nanox/nxutil.c Tue Aug 14 00:17:42 2001 @@ -181,7 +181,7 @@ GR_GC_ID gc; GR_BITMAP * buf; - pid = GrNewPixmap(width, height, NULL); + pid = GrNewPixmap(width, height, -1); if (pid) { gc = GrNewGC(); GrSetGCForeground(gc, foreground); diff -u -r microwin/src/nanox/srvfunc.c microwin-shm/src/nanox/srvfunc.c --- microwin/src/nanox/srvfunc.c Wed Jul 4 15:10:33 2001 +++ microwin-shm/src/nanox/srvfunc.c Tue Aug 14 00:17:42 2001 @@ -9,6 +9,11 @@ #include <stdlib.h> #include <string.h> #define MWINCLUDECOLORS +#ifdef HAVE_SHAREDMEM +#include <sys/types.h> +#include <sys/shm.h> +#endif +#include <errno.h> #include "serv.h" static int nextid = GR_ROOT_WINDOW_ID + 1; @@ -238,7 +243,13 @@ /* deallocate pixmap memory*/ if (psd->flags & PSF_ADDRMALLOC) free(psd->addr); - +#ifdef HAVE_SHAREDMEM + else if(psd->flags & PSF_ADDRSHAREDMEM){ + EPRINTF("Detaching from Shared Pixmap at 0x%08x\n",psd->addr); + shmdt(psd->addr); + } +#endif + /* deallocate mem gc*/ psd->FreeMemGC(psd); @@ -441,7 +452,7 @@ ) { int oldx = wp->x; int oldy = wp->y; - GR_WINDOW_ID pixid = GrNewPixmap(wp->width, wp->height,NULL); + GR_WINDOW_ID pixid = GrNewPixmap(wp->width, wp->height,-1); GR_GC_ID gc = GrNewGC(); GR_WINDOW * stopwp = wp; int X, Y, W, H; @@ -1370,12 +1381,15 @@ * for offscreen drawing */ GR_WINDOW_ID -GrNewPixmap(GR_SIZE width, GR_SIZE height, void * pixels) +GrNewPixmap(GR_SIZE width, GR_SIZE height, int shmid) { GR_PIXMAP *pp; PSD psd; int size, linelen, bpp, planes; - + void * pixels = NULL; + + /*DPRINTF("nano-X: GrNewPixmap(%d, %d, %d) called\n", width, height, shmid);*/ + if (width <= 0 || height <= 0) { /* no error for now, server will desynchronize w/app*/ /*GsError(GR_ERROR_BAD_WINDOW_SIZE, 0);*/ @@ -1403,9 +1417,22 @@ GdCalcMemGCAlloc(psd, width, height, 0, 0, &size, &linelen); /* Allocate space for pixel values */ - if (!pixels) { + if (shmid == -1) { + /*DPRINTF("nano-X: Looks as though the user is passing a standard pixmap\n");*/ pixels = calloc(size, 1); psd->flags |= PSF_ADDRMALLOC; + } else { +#if HAVE_SHAREDMEM + if(! (pixels = shmat(shmid,NULL,SHM_RDONLY))) { + EPRINTF("nano-X: request for shared memory pixmap failed on shmat %d\n", errno); + GsError(GR_ERROR_BAD_SHM, pp->id); + psd->FreeMemGC(psd); + return 0; + } + /*DPRINTF("nano-X: Successfully Attached to Shared Memory Pixmap at 0x%08x\n", pixels);*/ + /* shared memory opened successfully */ + psd->flags |= PSF_ADDRSHAREDMEM; +#endif } if (!pixels) { free(pp); diff -u -r microwin/src/nanox/srvnet.c microwin-shm/src/nanox/srvnet.c --- microwin/src/nanox/srvnet.c Tue Jul 3 12:13:43 2001 +++ microwin-shm/src/nanox/srvnet.c Tue Aug 14 00:19:29 2001 @@ -105,10 +105,14 @@ nxNewPixmapReq *req = r; GR_WINDOW_ID wid; - /* FIXME: Add support for passing info about shared memory - * segment - */ - wid = GrNewPixmap(req->width, req->height, 0); +#ifdef HAVE_SHAREDMEM + wid = GrNewPixmap(req->width, req->height, req->shmid); +#else + if(req->shmid == -1) { + wid = GrNewPixmap(req->width, req->height, req->shmid); + } + else wid = 0; +#endif GsWriteType(current_fd,GrNumNewPixmap); GsWrite(current_fd, &wid, sizeof(wid)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
Re: [nanogui] Re: Patch for Shared Memory Pixmaps
From: Jordan Crouse ####@####.#### Date: 14 Aug 2001 14:25:20 -0000 Message-Id: <01081408253501.01580@cosmic> So what happens if I compile this patch into one of my existing programs and run it as is? (I am famous for using lots of pixmaps).. Will it crash, or will it work as advertised? Jordan On Monday 13 August 2001 23:41, David T Eger mentioned: > Sorry about the wait. Been busy cleaning up a Framebuffer driver. > Here's the patch. I haven't differentiated GrNewPixmap() into separate > functions (as Jordan suggested) from the standard code for several > reasons: > > (1) If we really do link statically and pass a pointer, then isn't the > client/server X model sort of misplaced? > (2) 0 is not an invalid SHM key, however -1 is an invalid SHM key, and > also an invalid pointer. We will never have a one byte pixmap at the end > of memory > (3) I'm too lazy to rewrite it right now. > > -David Eger > > > diff -u -r microwin/src/contrib/speedtst/speed.c > microwin-shm/src/contrib/speedtst/speed.c --- > microwin/src/contrib/speedtst/speed.c Thu Jun 21 01:32:39 2001 +++ > microwin-shm/src/contrib/speedtst/speed.c Tue Aug 14 00:17:42 2001 @@ -60,6 > +60,7 @@ > window = XCreateSimpleWindow(display, RootWindow(display, screenNum), > 0, 0 , 639, 479, 0, > fgColor, bgColor); > +#error Broken by change in GrNewPixmap API > src_pixmap = XCreatePixmap(display, window, 320, 240, 16); > XMapRaised(display, window); > gcValues.background = bgColor; > diff -u -r microwin/src/demos/nanox/Makefile > microwin-shm/src/demos/nanox/Makefile --- > microwin/src/demos/nanox/Makefile Thu Jun 21 01:32:40 2001 > +++ microwin-shm/src/demos/nanox/Makefile Tue Aug 14 00:17:42 2001 > @@ -58,12 +58,12 @@ > t1demo.o \ > ftdemo.o \ > logfont.o \ > - slider.o \ > ntetris.o \ > launcher.o \ > nsaver.o \ > getselection.o \ > setselection.o > +# slider.o \ > > TARGETS = $(TOP)/bin/demo $(TOP)/bin/move $(TOP)/bin/landmine \ > $(TOP)/bin/world $(TOP)/bin/nxclock $(TOP)/bin/nxterm \ > @@ -71,8 +71,9 @@ > $(TOP)/bin/npanel $(TOP)/bin/nterm \ > $(TOP)/bin/demo2 $(TOP)/bin/demo5 $(TOP)/bin/demo6 \ > $(TOP)/bin/t1demo $(TOP)/bin/ftdemo $(TOP)/bin/logfont \ > - $(TOP)/bin/slider $(TOP)/bin/ntetris $(TOP)/bin/launcher \ > + $(TOP)/bin/ntetris $(TOP)/bin/launcher \ > $(TOP)/bin/nsaver $(TOP)/bin/getselection $(TOP)/bin/setselection > +# $(TOP)/bin/slider > endif > > all: default $(TARGETS) > diff -u -r microwin/src/demos/nanox/demo5.c > microwin-shm/src/demos/nanox/demo5.c --- > microwin/src/demos/nanox/demo5.c Thu Jun 21 01:32:40 2001 > +++ microwin-shm/src/demos/nanox/demo5.c Tue Aug 14 00:17:42 2001 > @@ -75,7 +75,7 @@ > w4 = GrNewWindow(GR_ROOT_WINDOW_ID, 350, 20, 200, 150, 5, BLACK, WHITE); > w5 = GrNewWindow(GR_ROOT_WINDOW_ID, 11, 143, 209, 100, 1, BLUE, GREEN); > > - p1 = GrNewPixmap(200,200,0); > + p1 = GrNewPixmap(200,200,-1); > > GrSelectEvents(w1, GR_EVENT_MASK_BUTTON_DOWN | > GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_EXPOSURE | > diff -u -r microwin/src/demos/nanox/demo6.c > microwin-shm/src/demos/nanox/demo6.c --- > microwin/src/demos/nanox/demo6.c Thu Jun 21 01:32:40 2001 > +++ microwin-shm/src/demos/nanox/demo6.c Tue Aug 14 00:17:42 2001 > @@ -114,7 +114,7 @@ > > #ifdef USE_PIXMAPS > /* Create the pixmap to store the picture in */ > - pmap = GrNewPixmap(width, height, NULL); > + pmap = GrNewPixmap(width, height, -1); > #endif > > /* Create a graphics context */ > diff -u -r microwin/src/demos/nanox/launcher.c > microwin-shm/src/demos/nanox/launcher.c --- > microwin/src/demos/nanox/launcher.c Thu Jun 21 01:32:40 2001 > +++ microwin-shm/src/demos/nanox/launcher.c Tue Aug 14 00:17:42 2001 > @@ -524,7 +524,7 @@ > GrGetImageInfo(back_image, &imageinfo); > if(!(state->background_pixmap = GrNewPixmap( > imageinfo.width, > - imageinfo.height, NULL))) { > + imageinfo.height, -1))) { > fprintf(stderr, "Couldn't allocate pixmap " > "for background image\n"); > } else { > diff -u -r microwin/src/demos/nanox/slider.c > microwin-shm/src/demos/nanox/slider.c --- > microwin/src/demos/nanox/slider.c Thu Jun 21 01:32:40 2001 > +++ microwin-shm/src/demos/nanox/slider.c Tue Aug 14 00:17:42 2001 > @@ -44,6 +44,8 @@ > static void MoveTile(); > static void DrawTile(); > > +#error Broken by change in GrNewPixmap API > + > int > main(int argc,char **argv) > { > diff -u -r microwin/src/include/nano-X.h microwin-shm/src/include/nano-X.h > --- microwin/src/include/nano-X.h Wed Jul 4 14:11:02 2001 > +++ microwin-shm/src/include/nano-X.h Tue Aug 14 00:17:42 2001 > @@ -234,6 +234,9 @@ > #define GR_ERROR_SCREEN_ERROR 11 > #define GR_ERROR_UNMAPPED_FOCUS_WINDOW 12 > #define GR_ERROR_BAD_DRAWING_MODE 13 > +#ifdef HAVE_SHAREDMEM > +#define GR_ERROR_BAD_SHM 14 > +#endif > > /* Event types. > * Mouse motion is generated for every motion of the mouse, and is used to > @@ -527,7 +530,8 @@ > "Clipping overflow\n", \ > "Screen error\n", \ > "Unmapped focus window: %d\n", \ > - "Bad drawing mode gc: %d\n" > + "Bad drawing mode gc: %d\n", \ > + "Bad Shared Memory ID\n" > > extern char *nxErrorStrings[]; > > @@ -541,7 +545,7 @@ > GR_WINDOW_ID GrNewWindow(GR_WINDOW_ID parent, GR_COORD x, GR_COORD y, > GR_SIZE width, GR_SIZE height, GR_SIZE bordersize, > GR_COLOR background, GR_COLOR bordercolor); > -GR_WINDOW_ID GrNewPixmap(GR_SIZE width, GR_SIZE height, void * addr); > +GR_WINDOW_ID GrNewPixmap(GR_SIZE width, GR_SIZE height, int shm_id); > GR_WINDOW_ID GrNewInputWindow(GR_WINDOW_ID parent, GR_COORD x, GR_COORD y, > GR_SIZE width, GR_SIZE height); > void GrDestroyWindow(GR_WINDOW_ID wid); > diff -u -r microwin/src/nanox/client.c microwin-shm/src/nanox/client.c > --- microwin/src/nanox/client.c Wed Jul 4 15:10:32 2001 > +++ microwin-shm/src/nanox/client.c Tue Aug 14 00:18:37 2001 > @@ -958,9 +958,8 @@ > * copied into a window using a GrCopyArea call) of the specified width > and * height. > */ > -/* FIXME: Add support for shared memory... */ > GR_WINDOW_ID > -GrNewPixmap(GR_SIZE width, GR_SIZE height, void *addr) > +GrNewPixmap(GR_SIZE width, GR_SIZE height, int shmid) > { > nxNewPixmapReq *req; > GR_WINDOW_ID wid; > @@ -968,6 +967,7 @@ > req = AllocReq(NewPixmap); > req->width = width; > req->height = height; > + req->shmid = shmid; > if(GrTypedReadBlock(&wid, sizeof(wid), GrNumNewPixmap) == -1) > return 0; > return wid; > diff -u -r microwin/src/nanox/nxproto.h microwin-shm/src/nanox/nxproto.h > --- microwin/src/nanox/nxproto.h Wed Jul 4 15:22:09 2001 > +++ microwin-shm/src/nanox/nxproto.h Tue Aug 14 00:19:04 2001 > @@ -598,7 +598,7 @@ > UINT16 length; > INT16 width; > INT16 height; > -/* FIXME: Add support for passing shared memory info */ > + int shmid; > } nxNewPixmapReq; > > #define GrNumCopyArea 51 > diff -u -r microwin/src/nanox/nxutil.c microwin-shm/src/nanox/nxutil.c > --- microwin/src/nanox/nxutil.c Thu Jun 21 01:32:42 2001 > +++ microwin-shm/src/nanox/nxutil.c Tue Aug 14 00:17:42 2001 > @@ -181,7 +181,7 @@ > GR_GC_ID gc; > GR_BITMAP * buf; > > - pid = GrNewPixmap(width, height, NULL); > + pid = GrNewPixmap(width, height, -1); > if (pid) { > gc = GrNewGC(); > GrSetGCForeground(gc, foreground); > diff -u -r microwin/src/nanox/srvfunc.c microwin-shm/src/nanox/srvfunc.c > --- microwin/src/nanox/srvfunc.c Wed Jul 4 15:10:33 2001 > +++ microwin-shm/src/nanox/srvfunc.c Tue Aug 14 00:17:42 2001 > @@ -9,6 +9,11 @@ > #include <stdlib.h> > #include <string.h> > #define MWINCLUDECOLORS > +#ifdef HAVE_SHAREDMEM > +#include <sys/types.h> > +#include <sys/shm.h> > +#endif > +#include <errno.h> > #include "serv.h" > > static int nextid = GR_ROOT_WINDOW_ID + 1; > @@ -238,7 +243,13 @@ > /* deallocate pixmap memory*/ > if (psd->flags & PSF_ADDRMALLOC) > free(psd->addr); > - > +#ifdef HAVE_SHAREDMEM > + else if(psd->flags & PSF_ADDRSHAREDMEM){ > + EPRINTF("Detaching from Shared Pixmap at 0x%08x\n",psd->addr); > + shmdt(psd->addr); > + } > +#endif > + > /* deallocate mem gc*/ > psd->FreeMemGC(psd); > > @@ -441,7 +452,7 @@ > ) { > int oldx = wp->x; > int oldy = wp->y; > - GR_WINDOW_ID pixid = GrNewPixmap(wp->width, wp->height,NULL); > + GR_WINDOW_ID pixid = GrNewPixmap(wp->width, wp->height,-1); > GR_GC_ID gc = GrNewGC(); > GR_WINDOW * stopwp = wp; > int X, Y, W, H; > @@ -1370,12 +1381,15 @@ > * for offscreen drawing > */ > GR_WINDOW_ID > -GrNewPixmap(GR_SIZE width, GR_SIZE height, void * pixels) > +GrNewPixmap(GR_SIZE width, GR_SIZE height, int shmid) > { > GR_PIXMAP *pp; > PSD psd; > int size, linelen, bpp, planes; > - > + void * pixels = NULL; > + > + /*DPRINTF("nano-X: GrNewPixmap(%d, %d, %d) called\n", width, height, > shmid);*/ + > if (width <= 0 || height <= 0) { > /* no error for now, server will desynchronize w/app*/ > /*GsError(GR_ERROR_BAD_WINDOW_SIZE, 0);*/ > @@ -1403,9 +1417,22 @@ > GdCalcMemGCAlloc(psd, width, height, 0, 0, &size, &linelen); > > /* Allocate space for pixel values */ > - if (!pixels) { > + if (shmid == -1) { > + /*DPRINTF("nano-X: Looks as though the user is passing a standard > pixmap\n");*/ pixels = calloc(size, 1); > psd->flags |= PSF_ADDRMALLOC; > + } else { > +#if HAVE_SHAREDMEM > + if(! (pixels = shmat(shmid,NULL,SHM_RDONLY))) { > + EPRINTF("nano-X: request for shared memory pixmap failed on shmat > %d\n", errno); + GsError(GR_ERROR_BAD_SHM, pp->id); > + psd->FreeMemGC(psd); > + return 0; > + } > + /*DPRINTF("nano-X: Successfully Attached to Shared Memory Pixmap at > 0x%08x\n", pixels);*/ + /* shared memory opened successfully */ > + psd->flags |= PSF_ADDRSHAREDMEM; > +#endif > } > if (!pixels) { > free(pp); > diff -u -r microwin/src/nanox/srvnet.c microwin-shm/src/nanox/srvnet.c > --- microwin/src/nanox/srvnet.c Tue Jul 3 12:13:43 2001 > +++ microwin-shm/src/nanox/srvnet.c Tue Aug 14 00:19:29 2001 > @@ -105,10 +105,14 @@ > nxNewPixmapReq *req = r; > GR_WINDOW_ID wid; > > - /* FIXME: Add support for passing info about shared memory > - * segment > - */ > - wid = GrNewPixmap(req->width, req->height, 0); > +#ifdef HAVE_SHAREDMEM > + wid = GrNewPixmap(req->width, req->height, req->shmid); > +#else > + if(req->shmid == -1) { > + wid = GrNewPixmap(req->width, req->height, req->shmid); > + } > + else wid = 0; > +#endif > > GsWriteType(current_fd,GrNumNewPixmap); > GsWrite(current_fd, &wid, sizeof(wid)); > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: ####@####.#### > For additional commands, e-mail: ####@####.#### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
Re: [nanogui] Re: Patch for Shared Memory Pixmaps
From: David Eger ####@####.#### Date: 14 Aug 2001 15:21:19 -0000 Message-Id: <Pine.LNX.4.33.0108141016190.295-100000@su13.eastnet.gatech.edu> I have used this patch, and it has worked. But then, there are a couple of caveats; you will have to change some code. (1) The passed parameter is no longer a pointer. It is a shmid. Pointers will not work. So you need to actually do System V memory calls in your user code to get a new Sys V ShM area and use it. (2) If you are NOT using ShM Pixmaps, then yes, you need to change the third argument of GrNewPixmap from 0 to -1. Yes, it's a pain. Yes, I see your point. (2) The pixmap currently MUST be the same bit depth as the framebuffer. Other than that, it should be golden. If you have problems, let me know. -David On Tue, 14 Aug 2001, Jordan Crouse wrote: > So what happens if I compile this patch into one of my existing programs and > run it as is? (I am famous for using lots of pixmaps).. Will it crash, or > will it work as advertised? > > Jordan > > On Monday 13 August 2001 23:41, David T Eger mentioned: > > Sorry about the wait. Been busy cleaning up a Framebuffer driver. > > Here's the patch. I haven't differentiated GrNewPixmap() into separate > > functions (as Jordan suggested) from the standard code for several > > reasons: > > > > (1) If we really do link statically and pass a pointer, then isn't the > > client/server X model sort of misplaced? > > (2) 0 is not an invalid SHM key, however -1 is an invalid SHM key, and > > also an invalid pointer. We will never have a one byte pixmap at the end > > of memory > > (3) I'm too lazy to rewrite it right now. > > > > -David Eger > > [ snip ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[<<] [<] Page 1 of 1 [>] [>>] |