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 f8f30d3d8fef42b8abac47b127f1daa9ca4ac80f (commit) via ee89ee1e6c2dd3cde4a5d6f986e09a543c6501fc (commit) via 5291a3ce26513aee909dd578fee1d715b9b992dd (commit) via 1f937a5b1a55b567c6e1b219b0afd3fa75be9678 (commit) via b99641b5107bd7ac383ccc8e809ed1d20689976d (commit) via 4bb000f1444cb139bc5c01a880660a1f4c86cde3 (commit) via 6308d59aa6b73e828afdecbd142051adf3071814 (commit) from 11237152b73f0794cd98e0de4c20ce180ac19535 (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/f8f30d3d8fef42b8abac47b127f1daa9ca4ac...
commit f8f30d3d8fef42b8abac47b127f1daa9ca4ac80f Author: Cyril Hrubis metan@ucw.cz Date: Sun Apr 7 00:27:09 2013 +0200
doc: Update python backend docs.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/doc/backends_python.txt b/doc/backends_python.txt index 512c1d1..e2b9096 100644 --- a/doc/backends_python.txt +++ b/doc/backends_python.txt @@ -36,15 +36,20 @@ The last parameter are bitflags. TODO: Export bitflags and add a list here.
[source,python] ------------------------------------------------------------------------------- +from sys import stderr import gfxprim.backends as backends
# This is a default init string backend_string = "X11:100x100"
# Initialize backend by init string - bk = backends.BackendInit(backend_string, "Window title", None) + bk = backends.BackendInit(backend_string, "Window title", stderr)
# Assert that inicialization was successful assert(bk)
------------------------------------------------------------------------------- + +Initialize the backend params by the 'backend_string'. The last parameter is a +file to print help or errors to. +
http://repo.or.cz/w/gfxprim.git/commit/ee89ee1e6c2dd3cde4a5d6f986e09a543c650...
commit ee89ee1e6c2dd3cde4a5d6f986e09a543c6501fc Author: Cyril Hrubis metan@ucw.cz Date: Sun Apr 7 00:25:24 2013 +0200
demos: py_simple: Pass the stderr as the last parameter.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/py_simple/backends.py b/demos/py_simple/backends.py index 83e4f74..6c53116 100755 --- a/demos/py_simple/backends.py +++ b/demos/py_simple/backends.py @@ -32,7 +32,7 @@ def main(): sys.exit(1)
# Create backend window - bk = backends.BackendInit(backend_string, "Backend Example", None) + bk = backends.BackendInit(backend_string, "Backend Example", sys.stderr) assert(bk)
redraw(bk)
http://repo.or.cz/w/gfxprim.git/commit/5291a3ce26513aee909dd578fee1d715b9b99...
commit 5291a3ce26513aee909dd578fee1d715b9b992dd Author: Cyril Hrubis metan@ucw.cz Date: Sun Apr 7 00:23:29 2013 +0200
pywrap: backends: Hack typemap for the BackendInit(..., FILE*)
The Python 3 no longer uses FILE * for file object so we hack around that by creating temporal FILE* from the underlying file descriptor.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/pylib/gfxprim/backends/backends.i b/pylib/gfxprim/backends/backends.i index d4b6b2c..f8ef6d4 100644 --- a/pylib/gfxprim/backends/backends.i +++ b/pylib/gfxprim/backends/backends.i @@ -32,14 +32,9 @@ ERROR_ON_NONZERO(GP_BackendResize);
%include "GP_Backend.h"
-ERROR_ON_NULL(GP_BackendInit); -%newobject GP_BackendInit; -%include "GP_BackendInit.h" - /* * Particular backends. */ - ERROR_ON_NULL(GP_BackendVirtualInit); %newobject GP_BackendVirtualInit; %include "GP_BackendVirtual.h" @@ -55,3 +50,37 @@ ERROR_ON_NULL(GP_BackendLinuxSDLInit); ERROR_ON_NULL(GP_BackendLinuxX11Init); %newobject GP_BackendX11Init; %include "GP_X11.h" + +/* + * Backend Init with a typemap for FILE* for the last parameter + * + * This is a ugly hack because Python 3 uses its own I/O buffers for file + * objects. + * + */ +%typemap(in) FILE* { + if ($input != Py_None) { + int fd = PyObject_AsFileDescriptor($input); + + if (fd < 0) { + PyErr_SetString(PyExc_TypeError, "$1_name must be a file type."); + return NULL; + } + + $1 = fdopen(fd, "w"); + } +} + +%exception GP_BackendInit { +$action + + //HACK: free the FILE* + free(arg3); + + if (result == NULL) + return PyErr_SetFromErrno(PyExc_OSError); +} + +%newobject GP_BackendInit; +%include "GP_BackendInit.h" +
http://repo.or.cz/w/gfxprim.git/commit/1f937a5b1a55b567c6e1b219b0afd3fa75be9...
commit 1f937a5b1a55b567c6e1b219b0afd3fa75be9678 Author: Cyril Hrubis metan@ucw.cz Date: Sat Apr 6 23:25:35 2013 +0200
doc: Start python backends docs.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/doc/Makefile b/doc/Makefile index 3e17452..cf80c1c 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -5,7 +5,7 @@ SOURCES=general.txt context.txt loaders.txt filters.txt basic_types.txt get_put_pixel.txt blits.txt progress_callback.txt text_api.txt event_queue.txt compilation.txt
-SOURCES+=core_python.txt gfx_python.txt loaders_python.txt +SOURCES+=core_python.txt gfx_python.txt loaders_python.txt backends_python.txt
EXAMPLE_SOURCES=$(wildcard example_*.txt)
diff --git a/doc/asciidoc.conf b/doc/asciidoc.conf index 9c351e6..4829c02 100644 --- a/doc/asciidoc.conf +++ b/doc/asciidoc.conf @@ -60,6 +60,7 @@ endif::disable-javascript[] <li><a href="core_python.html">Core</a></li> <li><a href="gfx_python.html">Gfx</a></li> <li><a href="loaders_python.html">Loaders</a></li> + <li><a href="backends_python.html">Backends</a></li> </ul> </div>
diff --git a/doc/backends_python.txt b/doc/backends_python.txt new file mode 100644 index 0000000..512c1d1 --- /dev/null +++ b/doc/backends_python.txt @@ -0,0 +1,50 @@ +Python Backends module +---------------------- + +The python binding maps mostly to the C API with the 'GP_' prefix stripped. + +Backend Initialization +~~~~~~~~~~~~~~~~~~~~~~ + +Instead of having one unified initialization interface each backend has it's +specific function and semantics but once backend is initialized the backend +structure provides unified API for controlling the drawing. + +There is however generic backend initialization function that takes a string +as a parameter that may contain backend-specific settings. + +[source,python] +------------------------------------------------------------------------------- +import gfxprim.backends as backends + + # Create 100x100 X11 window + bk = backends.BackendX11Init(None, x, y, w, h, "Window title", 0) + + # Assert that inicialization was successful + assert(bk) + +------------------------------------------------------------------------------- + +Creates a X11 window. First parameter is display string, pass 'None' for +default display. + +The 'x', 'y', 'w' and 'h' parameters describe the window geometry. The 'x' and +'y' are ignored by most of the window managers though. + +The last parameter are bitflags. TODO: Export bitflags and add a list here. + + +[source,python] +------------------------------------------------------------------------------- +import gfxprim.backends as backends + + # This is a default init string + backend_string = "X11:100x100" + + # Initialize backend by init string + bk = backends.BackendInit(backend_string, "Window title", None) + + # Assert that inicialization was successful + assert(bk) + +-------------------------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/b99641b5107bd7ac383ccc8e809ed1d206899...
commit b99641b5107bd7ac383ccc8e809ed1d20689976d Author: Cyril Hrubis metan@ucw.cz Date: Sat Apr 6 23:25:10 2013 +0200
demos: py_simple: Add BackendInit() example.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/py_simple/backends.py b/demos/py_simple/backends.py new file mode 100755 index 0000000..83e4f74 --- /dev/null +++ b/demos/py_simple/backends.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python + +import sys + +import gfxprim.core as core +import gfxprim.backends as backends +import gfxprim.gfx as gfx +import gfxprim.text as text +import gfxprim.input as input + +def redraw(bk): + c = bk.context + + black = c.RGBToPixel(0, 0, 0) + white = c.RGBToPixel(0xff, 0xff, 0xff) + + c.gfx.Fill(black) + + align = text.C.ALIGN_CENTER | text.C.VALIGN_CENTER + c.text.Text(None, c.w//2, c.h//2, align, white, black, "Hello World!") + + bk.Flip() + +def main(): + backend_string = "X11:100x100" + + if len(sys.argv) == 2: + backend_string = sys.argv[1] + + if len(sys.argv) > 2: + print("Usage: {} [backend init string]".format(sys.argv[0])) + sys.exit(1) + + # Create backend window + bk = backends.BackendInit(backend_string, "Backend Example", None) + assert(bk) + + redraw(bk) + + # Event loop + while True: + ev = bk.WaitEvent() + + input.EventDump(ev) + + if (ev.type == input.EV_KEY): + sys.exit(0) + elif (ev.type == input.EV_SYS): + if (ev.code == input.EV_SYS_QUIT): + sys.exit(0) + if (ev.code == input.EV_SYS_RESIZE): + bk.ResizeAck() + redraw(bk) + +if __name__ == '__main__': + main() diff --git a/demos/py_simple/x11_windows.py b/demos/py_simple/x11_windows.py index 04cfee2..bb656d3 100755 --- a/demos/py_simple/x11_windows.py +++ b/demos/py_simple/x11_windows.py @@ -17,7 +17,6 @@ def redraw(bk, id): c.gfx.Fill(black)
align = text.C.ALIGN_CENTER | text.C.VALIGN_CENTER - c.text.Text(None, c.w//2, c.h//2, align, white, black, "{} - {}x{}".format(id, c.w, c.h))
bk.Flip()
http://repo.or.cz/w/gfxprim.git/commit/4bb000f1444cb139bc5c01a880660a1f4c86c...
commit 4bb000f1444cb139bc5c01a880660a1f4c86cde3 Author: Cyril Hrubis metan@ucw.cz Date: Sat Apr 6 22:49:59 2013 +0200
backends: SDL: Fix resize.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/backends/GP_SDL.c b/libs/backends/GP_SDL.c index 2312564..a4599ac 100644 --- a/libs/backends/GP_SDL.c +++ b/libs/backends/GP_SDL.c @@ -45,7 +45,11 @@ static GP_Context context;
static uint32_t sdl_flags = SDL_SWSURFACE;
+/* To hold size from resize event */ +static unsigned int new_w, new_h; + /* Backend API funcitons */ +static struct GP_Backend backend;
static void sdl_flip(struct GP_Backend *self __attribute__((unused))) { @@ -73,15 +77,25 @@ static void sdl_update_rect(struct GP_Backend *self __attribute__((unused)), SDL_mutexV(mutex); }
+static void sdl_put_event(SDL_Event *ev) +{ + if (ev->type == SDL_VIDEORESIZE) { + new_w = ev->resize.w; + new_h = ev->resize.h; + } + + GP_InputDriverSDLEventPut(&backend.event_queue, ev); +} + static void sdl_poll(struct GP_Backend *self __attribute__((unused))) { SDL_Event ev;
SDL_mutexP(mutex); - + while (SDL_PollEvent(&ev)) - GP_InputDriverSDLEventPut(&self->event_queue, &ev); - + sdl_put_event(&ev); + SDL_mutexV(mutex); }
@@ -92,10 +106,10 @@ static void sdl_wait(struct GP_Backend *self __attribute__((unused))) SDL_mutexP(mutex);
SDL_WaitEvent(&ev); - GP_InputDriverSDLEventPut(&self->event_queue, &ev); + sdl_put_event(&ev);
while (SDL_PollEvent(&ev)) - GP_InputDriverSDLEventPut(&self->event_queue, &ev); + sdl_put_event(&ev);
SDL_mutexV(mutex); } @@ -147,24 +161,29 @@ static int sdl_set_attributes(struct GP_Backend *self, if (caption != NULL) SDL_WM_SetCaption(caption, caption);
- if (w != 0 && h != 0) { - sdl_surface = SDL_SetVideoMode(w, h, 0, sdl_flags); - context_from_surface(&context, sdl_surface); - - /* Send event that resize was finished */ + /* Send only resize event, the actual resize is done in resize_ack */ + if (w != 0 && h != 0) GP_EventQueuePushResize(&self->event_queue, w, h, NULL); - }
SDL_mutexV(mutex);
return 0; }
-static int sdl_resize_ack(struct GP_Backend *self) +static int sdl_resize_ack(struct GP_Backend *self __attribute__((unused))) { - GP_EventQueueSetScreenSize(&self->event_queue, - self->context->w, self->context->h); + GP_DEBUG(2, "Resizing the buffer to %ux%u", new_w, new_h); + + SDL_mutexP(mutex);
+ sdl_surface = SDL_SetVideoMode(new_w, new_h, 0, sdl_flags); + context_from_surface(backend.context, sdl_surface); + + GP_EventQueueSetScreenSize(&backend.event_queue, + backend.context->w, backend.context->h); + + SDL_mutexV(mutex); + return 0; }
http://repo.or.cz/w/gfxprim.git/commit/6308d59aa6b73e828afdecbd142051adf3071...
commit 6308d59aa6b73e828afdecbd142051adf3071814 Author: Cyril Hrubis metan@ucw.cz Date: Sat Apr 6 22:28:47 2013 +0200
libs: backends: Set errno to EINVAL if backend params are wrong.
This makes the python trace understandable.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/backends/GP_BackendInit.c b/libs/backends/GP_BackendInit.c index e9a809c..5ae1615 100644 --- a/libs/backends/GP_BackendInit.c +++ b/libs/backends/GP_BackendInit.c @@ -21,6 +21,7 @@ *****************************************************************************/
#include <string.h> +#include <errno.h>
#include "core/GP_Debug.h"
@@ -272,14 +273,21 @@ static GP_Backend *init_backend(const char *name, char *params, const char *caption, FILE *help) { int i = get_backend(name); + GP_Backend *ret;
if (i < 0) { GP_DEBUG(1, "Invalid backend name '%s'", name); print_help(help, "Invalid backend name"); + errno = EINVAL; return NULL; }
- return backend_inits[i](params, caption, help); + ret = backend_inits[i](params, caption, help); + + if (ret == NULL) + errno = EINVAL; + + return ret; }
GP_Backend *GP_BackendInit(const char *params, const char *caption, FILE *help)
-----------------------------------------------------------------------
Summary of changes: demos/py_simple/backends.py | 56 +++++++++++++++++++++++++++++++++++++ demos/py_simple/x11_windows.py | 1 - doc/Makefile | 2 +- doc/asciidoc.conf | 1 + doc/backends_python.txt | 55 ++++++++++++++++++++++++++++++++++++ libs/backends/GP_BackendInit.c | 10 ++++++- libs/backends/GP_SDL.c | 47 +++++++++++++++++++++--------- pylib/gfxprim/backends/backends.i | 39 ++++++++++++++++++++++--- 8 files changed, 189 insertions(+), 22 deletions(-) create mode 100755 demos/py_simple/backends.py create mode 100644 doc/backends_python.txt
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.