Multiple display update for X11 driver.
Untested.
This commit is contained in:
parent
d22bc07e7a
commit
75ed684275
2 changed files with 103 additions and 75 deletions
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#if GFX_USE_GDISP
|
#if GFX_USE_GDISP
|
||||||
|
|
||||||
#define GDISP_LLD_DECLARATIONS
|
#define GDISP_DRIVER_VMT GDISPVMT_X11
|
||||||
#include "gdisp/lld/gdisp_lld.h"
|
#include "gdisp/lld/gdisp_lld.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,6 +35,8 @@
|
||||||
#define GDISP_SCREEN_WIDTH 640
|
#define GDISP_SCREEN_WIDTH 640
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define GDISP_FLG_READY (GDISP_FLG_DRIVER<<0)
|
||||||
|
|
||||||
#if GINPUT_NEED_MOUSE
|
#if GINPUT_NEED_MOUSE
|
||||||
/* Include mouse support code */
|
/* Include mouse support code */
|
||||||
#include "ginput/lld/mouse.h"
|
#include "ginput/lld/mouse.h"
|
||||||
|
@ -45,24 +47,37 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
Display *dis;
|
static bool_t initdone;
|
||||||
int scr;
|
static Display *dis;
|
||||||
Window win;
|
static int scr;
|
||||||
Pixmap pix;
|
static XEvent evt;
|
||||||
XEvent evt;
|
static Colormap cmap;
|
||||||
GC gc;
|
static XVisualInfo vis;
|
||||||
Colormap cmap;
|
static int depth;
|
||||||
XVisualInfo vis;
|
static XContext cxt;
|
||||||
int depth;
|
|
||||||
#if GINPUT_NEED_MOUSE
|
#if GINPUT_NEED_MOUSE
|
||||||
coord_t mousex, mousey;
|
coord_t mousex, mousey;
|
||||||
uint16_t mousebuttons;
|
uint16_t mousebuttons;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void ProcessEvent(void) {
|
typedef struct xPriv {
|
||||||
|
Pixmap pix;
|
||||||
|
GC gc;
|
||||||
|
Window win;
|
||||||
|
} xPriv;
|
||||||
|
|
||||||
|
static void ProcessEvent(GDisplay *g, xPriv *priv) {
|
||||||
switch(evt.type) {
|
switch(evt.type) {
|
||||||
|
case MapNotify:
|
||||||
|
XSelectInput(dis, evt.xmap.window, StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
|
||||||
|
g->flags |= GDISP_FLG_READY;
|
||||||
|
break;
|
||||||
|
case UnmapNotify:
|
||||||
|
XCloseDisplay(dis);
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
case Expose:
|
case Expose:
|
||||||
XCopyArea(dis, pix, win, gc,
|
XCopyArea(dis, pix, evt.xexpose.window, priv->gc,
|
||||||
evt.xexpose.x, evt.xexpose.y,
|
evt.xexpose.x, evt.xexpose.y,
|
||||||
evt.xexpose.width, evt.xexpose.height,
|
evt.xexpose.width, evt.xexpose.height,
|
||||||
evt.xexpose.x, evt.xexpose.y);
|
evt.xexpose.x, evt.xexpose.y);
|
||||||
|
@ -108,13 +123,15 @@ static void ProcessEvent(void) {
|
||||||
/* this is the X11 thread which keeps track of all events */
|
/* this is the X11 thread which keeps track of all events */
|
||||||
static DECLARE_THREAD_STACK(waXThread, 1024);
|
static DECLARE_THREAD_STACK(waXThread, 1024);
|
||||||
static DECLARE_THREAD_FUNCTION(ThreadX, arg) {
|
static DECLARE_THREAD_FUNCTION(ThreadX, arg) {
|
||||||
|
GDisplay *g;
|
||||||
(void)arg;
|
(void)arg;
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
gfxSleepMilliseconds(100);
|
gfxSleepMilliseconds(100);
|
||||||
while(XPending(dis)) {
|
while(XPending(dis)) {
|
||||||
XNextEvent(dis, &evt);
|
XNextEvent(dis, &evt);
|
||||||
ProcessEvent();
|
XFindContext(ev.xany.display, ev.xany.window, cxt, (XPointer*)&g);
|
||||||
|
ProcessEvent(g, (xPriv *)g->priv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -128,50 +145,76 @@ static int FatalXIOError(Display *d) {
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
LLDSPEC bool_t gdisp_lld_init(GDISPDriver *g) {
|
LLDSPEC bool_t gdisp_lld_init(GDisplay *g, unsigned display) {
|
||||||
XSizeHints *pSH;
|
XSizeHints *pSH;
|
||||||
XSetWindowAttributes xa;
|
XSetWindowAttributes xa;
|
||||||
XTextProperty WindowTitle;
|
XTextProperty WindowTitle;
|
||||||
char * WindowTitleText;
|
char * WindowTitleText;
|
||||||
gfxThreadHandle hth;
|
xPriv *priv;
|
||||||
|
|
||||||
#if GFX_USE_OS_LINUX || GFX_USE_OS_OSX
|
if (!initdone) {
|
||||||
XInitThreads();
|
gfxThreadHandle hth;
|
||||||
#endif
|
|
||||||
|
|
||||||
dis = XOpenDisplay(NULL);
|
initdone = TRUE;
|
||||||
scr = DefaultScreen(dis);
|
#if GFX_USE_OS_LINUX || GFX_USE_OS_OSX
|
||||||
|
XInitThreads();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if GDISP_FORCE_24BIT
|
dis = XOpenDisplay(NULL);
|
||||||
if (!XMatchVisualInfo(dis, scr, 24, TrueColor, &vis)) {
|
scr = DefaultScreen(dis);
|
||||||
fprintf(stderr, "Your display has no TrueColor mode\n");
|
cxt = XUniqueContext();
|
||||||
|
XSetIOErrorHandler(FatalXIOError);
|
||||||
|
|
||||||
|
#if GDISP_FORCE_24BIT
|
||||||
|
if (!XMatchVisualInfo(dis, scr, 24, TrueColor, &vis)) {
|
||||||
|
fprintf(stderr, "Your display has no TrueColor mode\n");
|
||||||
|
XCloseDisplay(dis);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
cmap = XCreateColormap(dis, RootWindow(dis, scr),
|
||||||
|
vis.visual, AllocNone);
|
||||||
|
#else
|
||||||
|
vis.visual = CopyFromParent;
|
||||||
|
vis.depth = DefaultDepth(dis, scr);
|
||||||
|
cmap = DefaultColormap(dis, scr);
|
||||||
|
#endif
|
||||||
|
fprintf(stderr, "Running GFX Window in %d bit color\n", vis.depth);
|
||||||
|
|
||||||
|
if (!(hth = gfxThreadCreate(waXThread, sizeof(waXThread), HIGH_PRIORITY, ThreadX, 0))) {
|
||||||
|
fprintf(stderr, "Cannot start X Thread\n");
|
||||||
XCloseDisplay(dis);
|
XCloseDisplay(dis);
|
||||||
return FALSE;
|
exit(0);
|
||||||
}
|
}
|
||||||
cmap = XCreateColormap(dis, RootWindow(dis, scr),
|
#if GFX_USE_OS_LINUX || GFX_USE_OS_OSX
|
||||||
vis.visual, AllocNone);
|
pthread_detach(hth);
|
||||||
#else
|
#endif
|
||||||
vis.visual = CopyFromParent;
|
gfxThreadClose(hth);
|
||||||
vis.depth = DefaultDepth(dis, scr);
|
}
|
||||||
cmap = DefaultColormap(dis, scr);
|
|
||||||
#endif
|
g->priv = gfxAlloc(sizeof(xPriv));
|
||||||
fprintf(stderr, "Running GFX Window in %d bit color\n", vis.depth);
|
priv = (xPriv *)g->priv;
|
||||||
|
|
||||||
xa.colormap = cmap;
|
xa.colormap = cmap;
|
||||||
xa.border_pixel = 0xFFFFFF;
|
xa.border_pixel = 0xFFFFFF;
|
||||||
xa.background_pixel = 0x000000;
|
xa.background_pixel = 0x000000;
|
||||||
|
|
||||||
win = XCreateWindow(dis, RootWindow(dis, scr), 16, 16,
|
priv->win = XCreateWindow(dis, RootWindow(dis, scr), 16, 16,
|
||||||
GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT,
|
GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT,
|
||||||
0, vis.depth, InputOutput, vis.visual,
|
0, vis.depth, InputOutput, vis.visual,
|
||||||
CWBackPixel|CWColormap|CWBorderPixel, &xa);
|
CWBackPixel|CWColormap|CWBorderPixel, &xa);
|
||||||
XSync(dis, TRUE);
|
XSync(dis, TRUE);
|
||||||
|
|
||||||
WindowTitleText = "GFX";
|
XSaveContext(dis, win, cxt, (XPointer)g);
|
||||||
XStringListToTextProperty(&WindowTitleText, 1, &WindowTitle);
|
|
||||||
XSetWMName(dis, win, &WindowTitle);
|
{
|
||||||
XSetWMIconName(dis, win, &WindowTitle);
|
char buf[132];
|
||||||
XSync(dis, TRUE);
|
sprintf(buf, "uGFX - %u", display+1);
|
||||||
|
WindowTitleText = buf;
|
||||||
|
XStringListToTextProperty(&WindowTitleText, 1, &WindowTitle);
|
||||||
|
XSetWMName(dis, win, &WindowTitle);
|
||||||
|
XSetWMIconName(dis, win, &WindowTitle);
|
||||||
|
XSync(dis, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
pSH = XAllocSizeHints();
|
pSH = XAllocSizeHints();
|
||||||
pSH->flags = PSize | PMinSize | PMaxSize;
|
pSH->flags = PSize | PMinSize | PMaxSize;
|
||||||
|
@ -181,34 +224,22 @@ LLDSPEC bool_t gdisp_lld_init(GDISPDriver *g) {
|
||||||
XFree(pSH);
|
XFree(pSH);
|
||||||
XSync(dis, TRUE);
|
XSync(dis, TRUE);
|
||||||
|
|
||||||
pix = XCreatePixmap(dis, win,
|
priv->pix = XCreatePixmap(dis, win,
|
||||||
GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT, vis.depth);
|
GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT, vis.depth);
|
||||||
XSync(dis, TRUE);
|
XSync(dis, TRUE);
|
||||||
|
|
||||||
gc = XCreateGC(dis, win, 0, 0);
|
priv->gc = XCreateGC(dis, win, 0, 0);
|
||||||
XSetBackground(dis, gc, BlackPixel(dis, scr));
|
XSetBackground(dis, gc, BlackPixel(dis, scr));
|
||||||
XSync(dis, TRUE);
|
XSync(dis, TRUE);
|
||||||
|
|
||||||
XSelectInput(dis, win, StructureNotifyMask);
|
XSelectInput(dis, win, StructureNotifyMask);
|
||||||
XMapWindow(dis, win);
|
XMapWindow(dis, win);
|
||||||
do { XNextEvent(dis, &evt); } while (evt.type != MapNotify);
|
|
||||||
|
|
||||||
/* start the X11 thread */
|
// Wait for the window creation to complete (for safety)
|
||||||
XSetIOErrorHandler(FatalXIOError);
|
while(!(((volatile GDisplay *)g)->flags & GDISP_FLG_READY))
|
||||||
XSelectInput(dis, win,
|
gfxSleepMilliseconds(100);
|
||||||
ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
|
|
||||||
|
|
||||||
if (!(hth = gfxThreadCreate(waXThread, sizeof(waXThread), HIGH_PRIORITY, ThreadX, 0))) {
|
/* Initialise the GDISP structure to match */
|
||||||
fprintf(stderr, "Cannot start X Thread\n");
|
|
||||||
XCloseDisplay(dis);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
#if GFX_USE_OS_LINUX || GFX_USE_OS_OSX
|
|
||||||
pthread_detach(hth);
|
|
||||||
#endif
|
|
||||||
gfxThreadClose(hth);
|
|
||||||
|
|
||||||
/* Initialise the GDISP structure to match */
|
|
||||||
g->g.Orientation = GDISP_ROTATE_0;
|
g->g.Orientation = GDISP_ROTATE_0;
|
||||||
g->g.Powermode = powerOn;
|
g->g.Powermode = powerOn;
|
||||||
g->g.Backlight = 100;
|
g->g.Backlight = 100;
|
||||||
|
@ -220,29 +251,31 @@ LLDSPEC bool_t gdisp_lld_init(GDISPDriver *g) {
|
||||||
|
|
||||||
LLDSPEC void gdisp_lld_draw_pixel(GDISPDriver *g)
|
LLDSPEC void gdisp_lld_draw_pixel(GDISPDriver *g)
|
||||||
{
|
{
|
||||||
|
xPriv priv = (xPriv *)g->priv;
|
||||||
XColor col;
|
XColor col;
|
||||||
|
|
||||||
col.red = RED_OF(g->p.color) << 8;
|
col.red = RED_OF(g->p.color) << 8;
|
||||||
col.green = GREEN_OF(g->p.color) << 8;
|
col.green = GREEN_OF(g->p.color) << 8;
|
||||||
col.blue = BLUE_OF(g->p.color) << 8;
|
col.blue = BLUE_OF(g->p.color) << 8;
|
||||||
XAllocColor(dis, cmap, &col);
|
XAllocColor(dis, cmap, &col);
|
||||||
XSetForeground(dis, gc, col.pixel);
|
XSetForeground(dis, priv->gc, col.pixel);
|
||||||
XDrawPoint(dis, pix, gc, (int)g->p.x, (int)g->p.y );
|
XDrawPoint(dis, priv->pix, priv->gc, (int)g->p.x, (int)g->p.y );
|
||||||
XDrawPoint(dis, win, gc, (int)g->p.x, (int)g->p.y );
|
XDrawPoint(dis, priv->win, priv->gc, (int)g->p.x, (int)g->p.y );
|
||||||
XFlush(dis);
|
XFlush(dis);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GDISP_HARDWARE_FILLS
|
#if GDISP_HARDWARE_FILLS
|
||||||
LLDSPEC void gdisp_lld_fill_area(GDISPDriver *g) {
|
LLDSPEC void gdisp_lld_fill_area(GDISPDriver *g) {
|
||||||
|
xPriv priv = (xPriv *)g->priv;
|
||||||
XColor col;
|
XColor col;
|
||||||
|
|
||||||
col.red = RED_OF(g->p.color) << 8;
|
col.red = RED_OF(g->p.color) << 8;
|
||||||
col.green = GREEN_OF(g->p.color) << 8;
|
col.green = GREEN_OF(g->p.color) << 8;
|
||||||
col.blue = BLUE_OF(g->p.color) << 8;
|
col.blue = BLUE_OF(g->p.color) << 8;
|
||||||
XAllocColor(dis, cmap, &col);
|
XAllocColor(dis, cmap, &col);
|
||||||
XSetForeground(dis, gc, col.pixel);
|
XSetForeground(dis, priv->gc, col.pixel);
|
||||||
XFillRectangle(dis, pix, gc, g->p.x, g->p.y, g->p.cx, g->p.cy);
|
XFillRectangle(dis, priv->pix, priv->gc, g->p.x, g->p.y, g->p.cx, g->p.cy);
|
||||||
XFillRectangle(dis, win, gc, g->p.x, g->p.y, g->p.cx, g->p.cy);
|
XFillRectangle(dis, priv->win, priv->gc, g->p.x, g->p.y, g->p.cx, g->p.cy);
|
||||||
XFlush(dis);
|
XFlush(dis);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -262,10 +295,11 @@ LLDSPEC void gdisp_lld_draw_pixel(GDISPDriver *g)
|
||||||
|
|
||||||
#if GDISP_HARDWARE_PIXELREAD
|
#if GDISP_HARDWARE_PIXELREAD
|
||||||
LLDSPEC color_t gdisp_lld_get_pixel_color(GDISPDriver *g) {
|
LLDSPEC color_t gdisp_lld_get_pixel_color(GDISPDriver *g) {
|
||||||
|
xPriv priv = (xPriv *)g->priv;
|
||||||
XColor color;
|
XColor color;
|
||||||
XImage *img;
|
XImage *img;
|
||||||
|
|
||||||
img = XGetImage (dis, pix, g->p.x, g->p.y, 1, 1, AllPlanes, XYPixmap);
|
img = XGetImage (dis, priv->pix, g->p.x, g->p.y, 1, 1, AllPlanes, XYPixmap);
|
||||||
color.pixel = XGetPixel (img, 0, 0);
|
color.pixel = XGetPixel (img, 0, 0);
|
||||||
XFree(img);
|
XFree(img);
|
||||||
XQueryColor(dis, cmap, &color);
|
XQueryColor(dis, cmap, &color);
|
||||||
|
@ -275,12 +309,14 @@ LLDSPEC void gdisp_lld_draw_pixel(GDISPDriver *g)
|
||||||
|
|
||||||
#if GDISP_NEED_SCROLL && GDISP_HARDWARE_SCROLL
|
#if GDISP_NEED_SCROLL && GDISP_HARDWARE_SCROLL
|
||||||
LLDSPEC void gdisp_lld_vertical_scroll(GDISPDriver *g) {
|
LLDSPEC void gdisp_lld_vertical_scroll(GDISPDriver *g) {
|
||||||
|
xPriv priv = (xPriv *)g->priv;
|
||||||
|
|
||||||
if (g->p.y1 > 0) {
|
if (g->p.y1 > 0) {
|
||||||
XCopyArea(dis, pix, pix, gc, g->p.x, g->p.y+g->p.y1, g->p.cx, g->p.cy-g->p.y1, g->p.x, g->p.y);
|
XCopyArea(dis, priv->pix, priv->pix, priv->gc, g->p.x, g->p.y+g->p.y1, g->p.cx, g->p.cy-g->p.y1, g->p.x, g->p.y);
|
||||||
XCopyArea(dis, pix, win, gc, g->p.x, g->p.y, g->p.cx, g->p.cy-g->p.y1, g->p.x, g->p.y);
|
XCopyArea(dis, priv->pix, priv->win, priv->gc, g->p.x, g->p.y, g->p.cx, g->p.cy-g->p.y1, g->p.x, g->p.y);
|
||||||
} else {
|
} else {
|
||||||
XCopyArea(dis, pix, pix, gc, g->p.x, g->p.y, g->p.cx, g->p.cy+g->p.y1, g->p.x, g->p.y-g->p.y1);
|
XCopyArea(dis, priv->pix, priv->pix, priv->gc, g->p.x, g->p.y, g->p.cx, g->p.cy+g->p.y1, g->p.x, g->p.y-g->p.y1);
|
||||||
XCopyArea(dis, pix, win, gc, g->p.x, g->p.y-g->p.y1, g->p.cx, g->p.cy+g->p.y1, g->p.x, g->p.y-g->p.y1);
|
XCopyArea(dis, priv->pix, priv->win, priv->gc, g->p.x, g->p.y-g->p.y1, g->p.cx, g->p.cy+g->p.y1, g->p.x, g->p.y-g->p.y1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -22,14 +22,6 @@
|
||||||
/* Driver hardware support. */
|
/* Driver hardware support. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
#ifndef GDISP_DRIVER_COUNT_X11
|
|
||||||
#define GDISP_DRIVER_COUNT_X11 1
|
|
||||||
#endif
|
|
||||||
#define GDISP_DRIVER_COUNT GDISP_DRIVER_COUNT_X11
|
|
||||||
|
|
||||||
#define GDISP_DRIVER_NAME "Linux emulator - X11"
|
|
||||||
#define GDISP_DRIVER_STRUCT GDISP_X11
|
|
||||||
|
|
||||||
#define GDISP_HARDWARE_DRAWPIXEL TRUE
|
#define GDISP_HARDWARE_DRAWPIXEL TRUE
|
||||||
#define GDISP_HARDWARE_FILLS TRUE
|
#define GDISP_HARDWARE_FILLS TRUE
|
||||||
#define GDISP_HARDWARE_BITFILLS FALSE
|
#define GDISP_HARDWARE_BITFILLS FALSE
|
||||||
|
|
Loading…
Add table
Reference in a new issue