This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via de77d6cd49f5ec5cb956161d1599c08fda673561 (commit) from 83d2379331b535cc28f96ac11c27ef3565cfebb3 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/de77d6cd49f5ec5cb956161d1599c08fda673...
commit de77d6cd49f5ec5cb956161d1599c08fda673561 Author: Cyril Hrubis metan@ucw.cz Date: Thu May 3 00:24:48 2012 +0200
backends: Initial Xlib backend, not yet fully working.
What is missing:
* Input driver * Pixel type detection * SHM Support * Reasonable Expose event handling
diff --git a/configure b/configure index fe0350a..6011867 100755 --- a/configure +++ b/configure @@ -187,10 +187,13 @@ if __name__ == '__main__': ["giflib", "Library to handle, display and manipulate GIF images", [header_exists, "gif_lib.h"], "", "-lgif"], + ["libX11", + "X11 library", + [header_exists, "X11/Xlib.h"], "", "-lX11"], ["freetype", "A high-quality and portable font engine", [header_exists, "ft2build.h"], "", "`freetype-config --libs`"]], cfg) - + parser = OptionParser();
# Enable disable libraries for linking diff --git a/include/backends/GP_Backends.h b/include/backends/GP_Backends.h index 0cd74f6..d9420e1 100644 --- a/include/backends/GP_Backends.h +++ b/include/backends/GP_Backends.h @@ -39,6 +39,7 @@ */ #include "backends/GP_LinuxFB.h" #include "backends/GP_SDL.h" +#include "backends/GP_X11.h"
/* * Simplified backend initalization. diff --git a/include/backends/GP_Backends.h b/include/backends/GP_X11.h similarity index 78% copy from include/backends/GP_Backends.h copy to include/backends/GP_X11.h index 0cd74f6..198e252 100644 --- a/include/backends/GP_Backends.h +++ b/include/backends/GP_X11.h @@ -20,29 +20,21 @@ * * *****************************************************************************/
-/* - - Catch all header for backends. - - */ - -#ifndef BACKENDS_GP_BACKENDS_H -#define BACKENDS_GP_BACKENDS_H +#ifndef BACKENDS_GP_X11_H +#define BACKENDS_GP_X11_H
-/* - * Base backend definitions. - */ -#include "backends/GP_Backend.h" - -/* - * Backends. - */ -#include "backends/GP_LinuxFB.h" -#include "backends/GP_SDL.h" +#include "GP_Backend.h"
/* - * Simplified backend initalization. + * Initalize X11 backend. + * + * The display may be NULL default display. The coordinates are position and + * geometry for newly created window. + * + * Upon failure NULL is returned. */ -#include "backends/GP_BackendInit.h" +GP_Backend *GP_BackendX11Init(const char *display, int x, int y, + unsigned int w, unsigned int h, + const char *caption);
-#endif /* BACKENDS_GP_BACKENDS_H */ +#endif /* BACKENDS_GP_X11_H */ diff --git a/libs/backends/GP_BackendInit.c b/libs/backends/GP_BackendInit.c index 48ff440..5f6a470 100644 --- a/libs/backends/GP_BackendInit.c +++ b/libs/backends/GP_BackendInit.c @@ -24,9 +24,8 @@
#include "core/GP_Debug.h"
-#include "backends/GP_LinuxFB.h" -#include "backends/GP_SDL.h" -#include "backends/GP_BackendInit.h" +#include "GP_Backends.h" +#include "GP_BackendInit.h"
static void backend_sdl_help(FILE *help, const char *err) { @@ -125,21 +124,49 @@ static GP_Backend *backend_fb_init(char *params, const char *caption, return GP_BackendLinuxFBInit(fb); }
+static void backend_x11_help(FILE *help, const char *err) +{ + if (help == NULL) + return; + + if (err != NULL) + fprintf(help, "ERROR: %sn", err); + + fprintf(help, "X11 backendn" + "-----------n" + "X11:WxHn"); +} + +static GP_Backend *backend_x11_init(char *params, const char *caption, + FILE *help) +{ + unsigned int w, h, n; + + if (sscanf(params, "%u%*[xX]%u%n", &w, &h, &n) == 2 && n == strlen(params)) + return GP_BackendX11Init(NULL, 0, 0, w, h, caption); + + backend_x11_help(help, "X11: Invalid parameters"); + return NULL; +} + static const char *backend_names[] = { "SDL", /* libSDL */ "FB", /* Linux Framebuffer */ + "X11", /* X11 window system */ NULL, };
static GP_Backend *(*backend_inits[])(char *, const char *, FILE *) = { backend_sdl_init, backend_fb_init, + backend_x11_init, NULL, };
static void (*backend_helps[])(FILE *help, const char *err) = { backend_sdl_help, backend_fb_help, + backend_x11_help, NULL, };
diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c new file mode 100644 index 0000000..30bd65d --- /dev/null +++ b/libs/backends/GP_X11.c @@ -0,0 +1,190 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +#include "GP_X11.h" +#include "core/GP_Debug.h" + +struct x11_priv { + Display *dpy; + int scr; + Window win; + Visual *vis; + XImage *img; + + GP_Context *context; +}; + +static void x11_exit(GP_Backend *self) +{ + struct x11_priv *x11 = GP_BACKEND_PRIV(self); + + x11->img->data = NULL; + XDestroyImage(x11->img); + XDestroyWindow(x11->dpy, x11->win); + XCloseDisplay(x11->dpy); + + GP_ContextFree(x11->context); + + free(self); +} + +static void x11_flip(GP_Backend *self) +{ + struct x11_priv *x11 = GP_BACKEND_PRIV(self); + unsigned int w = x11->context->w; + unsigned int h = x11->context->h; + + GP_DEBUG(3, "Flipping context"); + + XLockDisplay(x11->dpy); + + XPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr), + x11->img, 0, 0, 0, 0, w, h); + XFlush(x11->dpy); + + XUnlockDisplay(x11->dpy); +} + +static void x11_poll(GP_Backend *self) +{ + struct x11_priv *x11 = GP_BACKEND_PRIV(self); + XEvent ev; + + XLockDisplay(x11->dpy); + + while (XPending(x11->dpy)) { + XNextEvent(x11->dpy, &ev); + + switch (ev.type) { + case Expose: + x11_flip(self); + break; + case MapNotify: + GP_DEBUG(1, "Shown"); + break; + } + } + + XUnlockDisplay(x11->dpy); +} + +GP_Backend *GP_BackendX11Init(const char *display, int x, int y, + unsigned int w, unsigned int h, + const char *caption) +{ + GP_Backend *backend; + struct x11_priv *x11; + + GP_DEBUG(1, "Initalizing X11 display '%s'", display); + + backend = malloc(sizeof(GP_Backend) + + sizeof(struct x11_priv)); + + if (backend == NULL) + return NULL; + + x11 = GP_BACKEND_PRIV(backend); + + x11->context = GP_ContextAlloc(w, h, GP_PIXEL_xRGB8888); + + if (x11->context == NULL) + goto err0; + + //TODO: Error checking + XInitThreads(); + + x11->dpy = XOpenDisplay(display); + + if (x11->dpy == NULL) + goto err1; + + x11->scr = DefaultScreen(x11->dpy); + x11->vis = DefaultVisual(x11->dpy, x11->scr); + + GP_DEBUG(2, "Opening window '%s' %ix%i-%ux%u", + caption, x, y, w, h); + + x11->img = XCreateImage(x11->dpy, x11->vis, 24, ZPixmap, 0, NULL, + w, h, 32, 0); + + x11->img->data = (char*)x11->context->pixels; + + x11->win = XCreateWindow(x11->dpy, DefaultRootWindow(x11->dpy), + x, y, w, h, 0, CopyFromParent, + InputOutput, CopyFromParent, 0, NULL); + + if (x11->win == None) { + //TODO: Error message? + GP_DEBUG(1, "Failed to create window"); + goto err2; + } + + /* Select events */ + XSelectInput(x11->dpy, x11->win, StructureNotifyMask|ExposureMask); + + /* Set window caption */ + XmbSetWMProperties(x11->dpy, x11->win, caption, caption, + NULL, 0, NULL, NULL, NULL); + + /* Show window */ + XMapWindow(x11->dpy, x11->win); + XFlush(x11->dpy); + +/* + + enum GP_PixelType pixel_type; + pixel_type = GP_PixelRGBLookup(vscri.red.length, vscri.red.offset, + vscri.green.length, vscri.green.offset, + vscri.blue.length, vscri.blue.offset, + vscri.transp.length, vscri.transp.offset, + vscri.bits_per_pixel); + + if (pixel_type == GP_PIXEL_UNKNOWN) { + GP_DEBUG(1, "Unknown pixel typen"); + goto err3; + } + + +*/ + + backend->name = "X11"; + backend->context = x11->context; + backend->Flip = x11_flip; + backend->UpdateRect = NULL; + backend->Exit = x11_exit; + backend->fd_list = NULL; + backend->Poll = x11_poll; + + return backend; +//err3: +// XDestroyWindow(x11->dpy, x11->win); +err2: + XCloseDisplay(x11->dpy); +err1: + GP_ContextFree(x11->context); +err0: + free(backend); + return NULL; +}
-----------------------------------------------------------------------
Summary of changes: configure | 5 +- include/backends/GP_Backends.h | 1 + include/backends/{GP_LinuxFB.h => GP_X11.h} | 21 ++-- libs/backends/GP_BackendInit.c | 33 ++++- libs/backends/GP_X11.c | 190 +++++++++++++++++++++++++++ 5 files changed, 235 insertions(+), 15 deletions(-) copy include/backends/{GP_LinuxFB.h => GP_X11.h} (79%) create mode 100644 libs/backends/GP_X11.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.