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 c2f10f3f488c6f32fb2c516153689a1fcc317ff0 (commit) via 76df7a3b73ab206fcb98801c38c0d5507af80c9e (commit) via 0aef2153ab52e46219ddb032d5c0920903d4f7ee (commit) via bef941cfec1236983582823bf2d0b45b7c5a2d10 (commit) from cfc171705f4af25d48d768ed3b5e89e1ef668393 (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/c2f10f3f488c6f32fb2c516153689a1fcc317...
commit c2f10f3f488c6f32fb2c516153689a1fcc317ff0 Author: Cyril Hrubis metan@ucw.cz Date: Fri May 18 20:16:07 2012 +0200
spiv: Add option to use pixel type emulation for backend.
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c index 5d0dcab..2062015 100644 --- a/demos/spiv/spiv.c +++ b/demos/spiv/spiv.c @@ -34,6 +34,7 @@
#include <GP.h> #include <backends/GP_Backends.h> +#include <backends/GP_BackendVirtual.h> #include <input/GP_InputDriverLinux.h>
#include "cpu_timer.h" @@ -382,8 +383,9 @@ int main(int argc, char *argv[]) int sleep_sec = -1; struct loader_params params = {NULL, 0, 0, 0, .img = NULL}; int opt, debug_level = 0; + GP_PixelType emul_type = GP_PIXEL_UNKNOWN;
- while ((opt = getopt(argc, argv, "b:cd:Ii:Ps:r:")) != -1) { + while ((opt = getopt(argc, argv, "b:cd:e:Ii:Ps:r:")) != -1) { switch (opt) { case 'I': params.show_info = 1; @@ -403,6 +405,14 @@ int main(int argc, char *argv[]) case 'd': debug_level = atoi(optarg); break; + case 'e': + emul_type = GP_PixelTypeByName(optarg); + + if (emul_type == GP_PIXEL_UNKNOWN) { + fprintf(stderr, "Invalid pixel type '%s'n", optarg); + return 1; + } + break; case 'r': if (!strcmp(optarg, "90")) rotate = 90; @@ -437,6 +447,9 @@ int main(int argc, char *argv[])
init_backend(backend_opts);
+ if (emul_type != GP_PIXEL_UNKNOWN) + backend = GP_BackendVirtualInit(backend, emul_type, GP_BACKEND_CALL_EXIT); + context = backend->context;
GP_EventSetScreenSize(context->w, context->h);
http://repo.or.cz/w/gfxprim.git/commit/76df7a3b73ab206fcb98801c38c0d5507af80...
commit 76df7a3b73ab206fcb98801c38c0d5507af80c9e Author: Cyril Hrubis metan@ucw.cz Date: Fri May 18 20:13:16 2012 +0200
core: Add GP_PixelTypeByName().
diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h index c8d82e4..8fb84a2 100644 --- a/include/core/GP_Pixel.h +++ b/include/core/GP_Pixel.h @@ -19,7 +19,7 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * * Copyright (C) 2011 Tomas Gavenciak gavento@ucw.cz * * * @@ -159,6 +159,11 @@ static inline void GP_PixelPrint(GP_Pixel pixel, GP_PixelType type) }
/* + * Returns pixel type for passed human-readable name (e.g. RGB888). + */ +GP_PixelType GP_PixelTypeByName(const char *name); + +/* * Match pixel type to known pixel types. * * Returns either valid PixelType or GP_PIXEL_UNKNOWN diff --git a/libs/core/GP_Pixel.c b/libs/core/GP_Pixel.c index bedaf14..b14d5b0 100644 --- a/libs/core/GP_Pixel.c +++ b/libs/core/GP_Pixel.c @@ -19,7 +19,7 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -56,6 +56,17 @@ static int match(const GP_PixelTypeChannel *channel, GP_Pixel mask) return (chmask == mask); }
+GP_PixelType GP_PixelTypeByName(const char *name) +{ + unsigned int i; + + for (i = 0; i < GP_PIXEL_MAX; i++) + if (!strcasecmp(name, GP_PixelTypes[i].name)) + return i; + + return GP_PIXEL_UNKNOWN; +} + GP_PixelType GP_PixelRGBMatch(GP_Pixel rmask, GP_Pixel gmask, GP_Pixel bmask, GP_Pixel amask, uint8_t bits_per_pixel)
http://repo.or.cz/w/gfxprim.git/commit/0aef2153ab52e46219ddb032d5c0920903d4f...
commit 0aef2153ab52e46219ddb032d5c0920903d4f7ee Author: Cyril Hrubis metan@ucw.cz Date: Fri May 18 20:00:26 2012 +0200
backends: Add virtual emulation backend for testing.
diff --git a/include/backends/GP_BackendVirtual.h b/include/backends/GP_BackendVirtual.h new file mode 100644 index 0000000..a050dc3 --- /dev/null +++ b/include/backends/GP_BackendVirtual.h @@ -0,0 +1,48 @@ +/***************************************************************************** + * 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 * + * * + *****************************************************************************/ + +/* + + Virtual backend, could emulate backed with any pixel type on the top of + initalized backend. Useful for testing. + + */ + +#ifndef BACKENDS_GP_BACKEND_VIRTUAL_H +#define BACKENDS_GP_BACKEND_VIRTUAL_H + +#include "GP_Backend.h" + +enum GP_BackendVirtFlags { + /* + * If set virtual backend exit calls 'parent' Exit as well. + */ + GP_BACKEND_CALL_EXIT = 0x01, +}; + +/* + * Create an virtual backend on the top of the existing backend. + */ +GP_Backend *GP_BackendVirtualInit(GP_Backend *backend, + GP_PixelType pixel_type, int flags); + +#endif /* BACKENDS_GP_BACKEND_VIRTUAL_H */ diff --git a/libs/backends/GP_BackendVirtual.c b/libs/backends/GP_BackendVirtual.c new file mode 100644 index 0000000..b28c3cb --- /dev/null +++ b/libs/backends/GP_BackendVirtual.c @@ -0,0 +1,145 @@ +/***************************************************************************** + * 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 <string.h> + +#include "core/GP_Context.h" +#include "core/GP_Blit.h" +#include "core/GP_Debug.h" + +#include "GP_BackendVirtual.h" + +struct virt_priv { + /* Original backend */ + GP_Backend *backend; + + int flags; +}; + +static void virt_flip(GP_Backend *self) +{ + struct virt_priv *virt = GP_BACKEND_PRIV(self); + + /* Convert and copy the buffer */ + GP_Blit(self->context, 0, 0, self->context->w, self->context->h, + virt->backend->context, 0, 0); + + /* Call blit on original backend */ + virt->backend->Flip(virt->backend); +} + +static void virt_update_rect(GP_Backend *self, GP_Coord x0, GP_Coord y0, + GP_Coord x1, GP_Coord y1) +{ + struct virt_priv *virt = GP_BACKEND_PRIV(self); + + /* Convert and copy the buffer */ + GP_BlitXYXY(self->context, x0, y0, x1, y1, + virt->backend->context, x0, y0); + + /* Call blit on original backend */ + virt->backend->UpdateRect(virt->backend, x0, y0, x1, y1); +} + +static int virt_set_attributes(struct GP_Backend *self, + uint32_t w, uint32_t h, + const char *caption) +{ + struct virt_priv *virt = GP_BACKEND_PRIV(self); + int ret; + + ret = virt->backend->SetAttributes(virt->backend, w, h, caption); + + if (ret) + return ret; + + /* If backend was resized, update our buffer as well */ + if (h != 0 && w != 0) + GP_ContextResize(self->context, w, h); + + return 0; +} + +static void virt_poll(GP_Backend *self) +{ + struct virt_priv *virt = GP_BACKEND_PRIV(self); + + virt->backend->Poll(virt->backend); +} + +static void virt_exit(GP_Backend *self) +{ + struct virt_priv *virt = GP_BACKEND_PRIV(self); + + GP_ContextFree(self->context); + + if (virt->flags & GP_BACKEND_CALL_EXIT) + virt->backend->Exit(virt->backend); + + free(self); +} + +GP_Backend *GP_BackendVirtualInit(GP_Backend *backend, + GP_PixelType pixel_type, int flags) +{ + GP_Backend *self; + struct virt_priv *virt; + + self = malloc(sizeof(GP_Backend) + + sizeof(struct virt_priv)); + + if (self == NULL) { + GP_DEBUG(1, "Malloc failed :("); + return NULL; + } + + memset(self, 0, sizeof(GP_Backend)); + + /* Create new buffer with different context type */ + self->context = GP_ContextAlloc(backend->context->w, backend->context->h, + pixel_type); + + if (self->context == NULL) + goto err0; + + virt = GP_BACKEND_PRIV(self); + virt->backend = backend; + virt->flags = flags; + + /* Initalize new backend */ + self->name = "Virtual Backend"; + self->Flip = virt_flip; + self->UpdateRect = virt_update_rect; + self->Exit = virt_exit; + + if (backend->Poll) + self->Poll = virt_poll; + + if (backend->SetAttributes) + self->SetAttributes = virt_set_attributes; + + return self; + +err0: + free(self); + return NULL; +}
http://repo.or.cz/w/gfxprim.git/commit/bef941cfec1236983582823bf2d0b45b7c5a2...
commit bef941cfec1236983582823bf2d0b45b7c5a2d10 Author: Cyril Hrubis metan@ucw.cz Date: Fri May 18 18:51:31 2012 +0200
backends: X11: More error checking and pixel matching.
The XImage interface is _strange_ I did best effort to match reasonable pixel type. Still not sure if this will actually work on unexpected xserver configurations.
diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c index af98a67..1c5dd91 100644 --- a/libs/backends/GP_X11.c +++ b/libs/backends/GP_X11.c @@ -34,23 +34,28 @@ struct x11_priv { Display *dpy; int scr; + Screen *scr_ptr; + int scr_depth; Window win; Visual *vis; + XImage *img;
int resized_flag; };
+static void destroy_ximage(GP_Backend *self); + +static int resize_ximage(GP_Backend *self, int w, int h); + static void x11_exit(GP_Backend *self) { struct x11_priv *x11 = GP_BACKEND_PRIV(self); XLockDisplay(x11->dpy); - - GP_ContextFree(self->context);
- x11->img->data = NULL; - XDestroyImage(x11->img); + destroy_ximage(self); + XDestroyWindow(x11->dpy, x11->win); /* I wonder if this is right sequence... */ XUnlockDisplay(x11->dpy); @@ -148,8 +153,6 @@ static int x11_set_attributes(struct GP_Backend *self, }
if (w != 0 || h != 0) { - XImage *img; - if (w == 0) w = self->context->w; @@ -157,30 +160,14 @@ static int x11_set_attributes(struct GP_Backend *self, h = self->context->h; GP_DEBUG(3, "Setting window size to %ux%u", w, h); - - /* Create new X image */ - img = XCreateImage(x11->dpy, x11->vis, 24, ZPixmap, 0, NULL, - w, h, 32, 0); - - /* Allocate new context */ - - if (GP_ContextResize(self->context, w, h)) { - XDestroyImage(img); + + if (resize_ximage(self, w, h)) return 1; - } - - /* Free old image */ - x11->img->data = NULL; - XDestroyImage(x11->img); - - /* Swap the pointers */ - img->data = (char*)self->context->pixels; - x11->img = img;
/* Resize X11 window */ XResizeWindow(x11->dpy, x11->win, w, h); XFlush(x11->dpy); - + x11->resized_flag = 1; } @@ -189,6 +176,90 @@ static int x11_set_attributes(struct GP_Backend *self, return 0; }
+static int create_ximage(GP_Backend *self, GP_Size w, GP_Size h) +{ + struct x11_priv *x11 = GP_BACKEND_PRIV(self); + int depth; + enum GP_PixelType pixel_type; + + /* + * Eh, the XImage supports either 8, 16 or 32 bit pixels + * + * Do best effor on selecting appropriate pixel type + */ + for (depth = 8; depth <= 32; depth<<=1) { + pixel_type = GP_PixelRGBMatch(x11->vis->red_mask, + x11->vis->green_mask, + x11->vis->blue_mask, + 0x0, depth); + + if (pixel_type != GP_PIXEL_UNKNOWN) + break; + } + + if (pixel_type == GP_PIXEL_UNKNOWN) { + GP_DEBUG(1, "Unknown pixel type"); + return 1; + } + + self->context = GP_ContextAlloc(w, h, pixel_type); + + if (self->context == NULL) + return 1; + + x11->img = XCreateImage(x11->dpy, x11->vis, x11->scr_depth, ZPixmap, 0, + NULL, w, h, depth, 0); + + if (x11->img == NULL) { + GP_DEBUG(1, "Failed to create XImage"); + GP_ContextFree(self->context); + return 1; + } + + x11->img->data = (char*)self->context->pixels; + return 0; +} + +static void destroy_ximage(GP_Backend *self) +{ + struct x11_priv *x11 = GP_BACKEND_PRIV(self); + + GP_ContextFree(self->context); + x11->img->data = NULL; + XDestroyImage(x11->img); +} + +static int resize_ximage(GP_Backend *self, int w, int h) +{ + struct x11_priv *x11 = GP_BACKEND_PRIV(self); + XImage *img; + + /* Create new X image */ + img = XCreateImage(x11->dpy, x11->vis, x11->scr_depth, ZPixmap, 0, NULL, + w, h, x11->img->bitmap_pad, 0); + + if (img == NULL) { + GP_DEBUG(2, "XCreateImage failed"); + return 1; + } + + /* Resize context */ + if (GP_ContextResize(self->context, w, h)) { + XDestroyImage(img); + return 1; + } + + /* Free old image */ + x11->img->data = NULL; + XDestroyImage(x11->img); + + /* Swap the pointers */ + img->data = (char*)self->context->pixels; + x11->img = img; + + return 0; +} + GP_Backend *GP_BackendX11Init(const char *display, int x, int y, unsigned int w, unsigned int h, const char *caption) @@ -197,6 +268,11 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y, struct x11_priv *x11;
GP_DEBUG(1, "Initalizing X11 display '%s'", display); + + if (!XInitThreads()) { + GP_DEBUG(2, "XInitThreads failed"); + return NULL; + }
backend = malloc(sizeof(GP_Backend) + sizeof(struct x11_priv)); @@ -206,30 +282,24 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
x11 = GP_BACKEND_PRIV(backend);
- backend->context = GP_ContextAlloc(w, h, GP_PIXEL_xRGB8888); - - if (backend->context == NULL) - goto err0; - - //TODO: Error checking - XInitThreads(); - x11->dpy = XOpenDisplay(display);
if (x11->dpy == NULL) - goto err1; + goto err0;
x11->scr = DefaultScreen(x11->dpy); x11->vis = DefaultVisual(x11->dpy, x11->scr); + x11->scr_ptr = DefaultScreenOfDisplay(x11->dpy); + x11->scr_depth = DefaultDepthOfScreen(x11->scr_ptr); + + GP_DEBUG(2, "Have Visual id %i, depth %u", (int)x11->vis->visualid, x11->scr_depth); + + if (create_ximage(backend, w, h)) + goto err1; 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*)backend->context->pixels; - x11->win = XCreateWindow(x11->dpy, DefaultRootWindow(x11->dpy), x, y, w, h, 0, CopyFromParent, InputOutput, CopyFromParent, 0, NULL); @@ -257,22 +327,6 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y, x11->resized_flag = 0;
-/* - 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->Flip = x11_flip; backend->UpdateRect = x11_update_rect; @@ -281,14 +335,11 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y, backend->Poll = x11_poll; backend->SetAttributes = x11_set_attributes;
- return backend; -//err3: -// XDestroyWindow(x11->dpy, x11->win); err2: - XCloseDisplay(x11->dpy); + destroy_ximage(backend); err1: - GP_ContextFree(backend->context); + XCloseDisplay(x11->dpy); err0: free(backend); return NULL;
-----------------------------------------------------------------------
Summary of changes: demos/spiv/spiv.c | 15 ++- include/backends/{GP_X11.h => GP_BackendVirtual.h} | 32 +++-- include/core/GP_Pixel.h | 7 +- libs/backends/GP_BackendVirtual.c | 145 +++++++++++++++++ libs/backends/GP_X11.c | 171 +++++++++++++------- libs/core/GP_Pixel.c | 13 ++- 6 files changed, 308 insertions(+), 75 deletions(-) copy include/backends/{GP_X11.h => GP_BackendVirtual.h} (74%) create mode 100644 libs/backends/GP_BackendVirtual.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.