--- /mnt/git/branch/heads/plan9/tree/src/surface/plan9.c Wed Jan 29 13:58:39 2020 +++ src/surface/plan9.c Wed Feb 5 14:13:38 2020 @@ -31,8 +31,15 @@ #include #include -static Image *SrvImage=NULL; /* Global copy of drawstate->srvimg */ - /* that is used by eresized() */ +static bool inited; +static int gwidth; +static int gheight; +static bool perform_resize; + +static unsigned char * +create_local_image(int bytes); +Image * +create_draw_image(int width, int height, ulong chan); /* * A 'drawstate' contain all information about the @@ -86,20 +93,75 @@ static int plan9_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format) { + if(!inited) { + fprintf(stderr, "INITING display!\n"); + if (initdraw(0, 0, "netsurf-fb") < 0){ + fprintf(stderr, "initdraw failed\n"); + return -1; + } + inited=true; + } //fprintf(stderr, "DBG: plan9_set_geometry(%d,%d) - check p9copy()!\n", // width, height); - - if (nsfb->surface_priv != NULL) - return -1; /* if were already initialised fail */ nsfb->width = width; nsfb->height = height; nsfb->format = format; + gwidth=width; + gheight=height; + /* select default sw plotters for format */ select_plotters(nsfb); nsfb->plotter_fns->copy = p9copy; /* empty function */ + drawstate_t *drawstate = nsfb->surface_priv; + + /* sanity check bpp. */ + if ((nsfb->bpp != 32) && (nsfb->bpp != 16) && (nsfb->bpp != 8)) + return -1; + + if (drawstate == NULL) + drawstate = calloc(1, sizeof(drawstate_t)); + if (drawstate == NULL) + return -1; /* no memory */ + + /* create local framebuffer data storage */ + drawstate->imagebytes = + (nsfb->bpp * nsfb->width * nsfb->height) >> 3; + + if(drawstate->localimage) free(drawstate->localimage); + drawstate->localimage = calloc(1, drawstate->imagebytes); //create_local_image(drawstate->imagebytes); + if(drawstate->updateimage) free(drawstate->updateimage); + drawstate->updateimage = calloc(1, drawstate->imagebytes); //create_local_image(drawstate->imagebytes); + + if (drawstate->localimage == NULL || drawstate->updateimage == NULL){ + fprintf(stderr, "Unable to allocate memory " + "for local framebuffer images\n"); + free(drawstate); + return -1; + //drawshutdown(); /* to call this? */ + } + + /* crate a draw image on server side */ + drawstate->srvimage = create_draw_image(nsfb->width, + nsfb->height, XRGB32); + + if (drawstate->srvimage == NULL){ + fprintf(stderr, "Unable to create an image " + "on the display server\n"); + free(drawstate->localimage); + free(drawstate->updateimage); + free(drawstate); + return -1; + //drawshutdown(); /* to call this? */ + } + + /* ensure plotting information is stored */ + nsfb->surface_priv = drawstate; + nsfb->ptr = drawstate->localimage; + nsfb->linelen = (nsfb->width * nsfb->bpp) / 8; + return 0; } @@ -107,12 +169,9 @@ plan9_set_geometry(nsfb_t *nsfb, int wid void eresized(int new) /* callback also called by libdraw */ { + perform_resize=true; if (new && getwindow(display, Refmesg) < 0) fprintf(stderr,"can't reattach to window"); - - if(SrvImage != NULL) - draw(screen, screen->r, SrvImage, nil, ZP); - flushimage(display, 1); } /* create_local_image() @@ -166,65 +225,7 @@ create_draw_image(int width, int height, static int plan9_initialise(nsfb_t *nsfb) { - drawstate_t *drawstate = nsfb->surface_priv; - -// fprintf(stderr, "DBG: plan9_initialise()\n"); - - if (drawstate != NULL) - return -1; /* already initialised */ - - /* sanity check bpp. */ - if ((nsfb->bpp != 32) && (nsfb->bpp != 16) && (nsfb->bpp != 8)) - return -1; - - drawstate = calloc(1, sizeof(drawstate_t)); - if (drawstate == NULL) - return -1; /* no memory */ - - /* initialise the draw graphics in Plan 9 */ - - if (initdraw(0, 0, "netsurf-fb") < 0){ - fprintf(stderr, "initdraw failed\n"); - return -1; - } einit(Emouse|Ekeyboard); - - /* create local framebuffer data storage */ - - drawstate->imagebytes = - (nsfb->bpp * nsfb->width * nsfb->height) >> 3; - - drawstate->localimage = create_local_image(drawstate->imagebytes); - drawstate->updateimage = create_local_image(drawstate->imagebytes); - - if (drawstate->localimage == NULL || drawstate->updateimage == NULL){ - fprintf(stderr, "Unable to allocate memory " - "for local framebuffer images\n"); - free(drawstate); - return -1; - //drawshutdown(); /* to call this? */ - } - - /* crate a draw image on server side */ - drawstate->srvimage = create_draw_image(nsfb->width, - nsfb->height, XRGB32); - SrvImage = drawstate->srvimage; /* global copy for eresized() */ - - if (drawstate->srvimage == NULL){ - fprintf(stderr, "Unable to create an image " - "on the display server\n"); - free(drawstate->localimage); - free(drawstate->updateimage); - free(drawstate); - return -1; - //drawshutdown(); /* to call this? */ - } - - /* ensure plotting information is stored */ - nsfb->surface_priv = drawstate; - nsfb->ptr = drawstate->localimage; - nsfb->linelen = (nsfb->width * nsfb->bpp) / 8; - eresized(0); /* first drawing */ return 0; } @@ -385,6 +386,16 @@ trans_plan9_event(nsfb_t *nsfb, nsfb_eve nsevent->type = NSFB_EVENT_KEY_UP; button_changes++; } + if(evp->mouse.buttons & 8) { + nsevent->value.keycode = NSFB_KEY_MOUSE_4; + nsevent->type = NSFB_EVENT_KEY_DOWN; + button_changes++; + } + if(evp->mouse.buttons & 16) { + nsevent->value.keycode = NSFB_KEY_MOUSE_5; + nsevent->type = NSFB_EVENT_KEY_DOWN; + button_changes++; + } /* save new button status, for next event to compare with */ drawstate->mousebuttons = evp->mouse.buttons; @@ -432,6 +443,16 @@ debug_event(nsfb_event_t *nsevent, Event static bool plan9_input(nsfb_t *nsfb, nsfb_event_t *nsevent, int timeout) { + if(perform_resize) { + perform_resize=false; + int w = screen->r.max.x - screen->r.min.x; + int h = screen->r.max.y - screen->r.min.y; + fprintf(stderr, "RESIZE_EVENT.\n"); + nsevent->type = NSFB_EVENT_RESIZE; + nsevent->value.resize.w = w; + nsevent->value.resize.h = h; + return true; + } drawstate_t *drawstate = nsfb->surface_priv; // static int once = 0; /* ensure etimer() is only called once */ int e; /* type of event */