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 bcc7ec1a9edd6f0caf76bcce92eb0c4a827d99b1 (commit) via 2d381801266820dab9804fd1539d910bb3cfd352 (commit) from c80b947b60c5cb4af6b5498b070a33b5baa15e69 (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/bcc7ec1a9edd6f0caf76bcce92eb0c4a827d9...
commit bcc7ec1a9edd6f0caf76bcce92eb0c4a827d99b1 Author: Cyril Hrubis metan@ucw.cz Date: Tue May 8 21:53:37 2012 +0200
spiv: Make use of new backend fucntions.
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c index 7ecf094..da4a97b 100644 --- a/demos/spiv/spiv.c +++ b/demos/spiv/spiv.c @@ -108,7 +108,16 @@ static const char *img_name(const char *img_path) return &img_path[i+1]; }
- return NULL; + return img_path; +} + +static void set_caption(const char *path, float rat) +{ + char buf[256]; + + snprintf(buf, sizeof(buf), "Spiv ~ %s 1:%3.3f", img_name(path), rat); + + GP_BackendSetCaption(backend, buf); }
static void *image_loader(void *ptr) @@ -155,6 +164,19 @@ static void *image_loader(void *ptr) break; }
+ /* Try to resize window */ + /* + if (!GP_BackendResize(backend, img->w, img->h)) { + context = backend->context; + + GP_Blit_Raw(img, 0, 0, img->w, img->h, context, 0, 0); + GP_BackendFlip(backend); + set_caption(params->img_path, 1); + + return NULL; + } + */ + float rat = calc_img_size(img->w, img->h, w, h);
w = img->w; @@ -231,6 +253,8 @@ static void *image_loader(void *ptr)
cpu_timer_stop(&sum_timer);
+ set_caption(params->img_path, rat); + if (!params->show_info) { GP_BackendFlip(backend); return NULL;
http://repo.or.cz/w/gfxprim.git/commit/2d381801266820dab9804fd1539d910bb3cfd...
commit 2d381801266820dab9804fd1539d910bb3cfd352 Author: Cyril Hrubis metan@ucw.cz Date: Tue May 8 21:53:13 2012 +0200
backends: Add support for resize and caption on-the-fly.
diff --git a/include/backends/GP_Backend.h b/include/backends/GP_Backend.h index c83a411..1f8428e 100644 --- a/include/backends/GP_Backend.h +++ b/include/backends/GP_Backend.h @@ -72,7 +72,7 @@ typedef struct GP_Backend { * If display is buffered, this copies content * of context onto display. * - * If display is not buffered, this is no-op. + * If display is not buffered, this is no-op (set to NULL). */ void (*Flip)(struct GP_Backend *self);
@@ -82,13 +82,26 @@ typedef struct GP_Backend { * In contrast to flip operation, the context * must not change (this is intended for updating very small areas). * - * If display is not buffered, this is no-op. + * If display is not buffered, this is no-op (set to NULL). */ void (*UpdateRect)(struct GP_Backend *self, GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1);
/* + * Callback to change attributes. + * + * If w and h are zero, only caption is changed. + * + * If caption is NULL only w and h are changed. + * + * Use the inline wrappers instead. + */ + int (*SetAttributes)(struct GP_Backend *self, + uint32_t w, uint32_t h, + const char *caption); + + /* * Exits the backend. */ void (*Exit)(struct GP_Backend *self); @@ -146,4 +159,30 @@ static inline void GP_BackendPoll(GP_Backend *backend) backend->Poll(backend); }
+/* + * Sets backend caption, if supported. + * + * When setting caption is not possible/implemented non zero is returned. + */ +static inline int GP_BackendSetCaption(GP_Backend *backend, + const char *caption) +{ + if (backend->SetAttributes == NULL) + return 1; + + return backend->SetAttributes(backend, 0, 0, caption); +} + +/* + * Resize backend, if supported. + * + * When resizing is not possible/implemented non zero is returned. + * + * When the backend size matches the passed width and height, + * no action is done. + * + * Note that after calling this, the backend->context pointer may change. + */ +int GP_BackendResize(GP_Backend *backend, uint32_t w, uint32_t h); + #endif /* BACKENDS_GP_BACKEND_H */ diff --git a/libs/backends/GP_Backend.c b/libs/backends/GP_Backend.c index d878760..fc37449 100644 --- a/libs/backends/GP_Backend.c +++ b/libs/backends/GP_Backend.c @@ -40,3 +40,15 @@ void GP_BackendUpdateRect(GP_Backend *backend,
backend->UpdateRect(backend, x0, y0, x1, y1); } + + +int GP_BackendResize(GP_Backend *backend, uint32_t w, uint32_t h) +{ + if (backend->SetAttributes == NULL) + return 1; + + if (backend->context->w == w && backend->context->h == h) + return 0; + + return backend->SetAttributes(backend, w, h, NULL); +} diff --git a/libs/backends/GP_LinuxFB.c b/libs/backends/GP_LinuxFB.c index d0ad3c7..3a511c3 100644 --- a/libs/backends/GP_LinuxFB.c +++ b/libs/backends/GP_LinuxFB.c @@ -233,13 +233,14 @@ GP_Backend *GP_BackendLinuxFBInit(const char *path) fb->context.pixel_type = pixel_type;
/* update API */ - backend->name = "Linux FB"; - backend->context = &fb->context; - backend->Flip = fb_flip_noop; - backend->UpdateRect = fb_update_rect_noop; - backend->Exit = fb_exit; - backend->fd_list = NULL; - backend->Poll = NULL; + backend->name = "Linux FB"; + backend->context = &fb->context; + backend->Flip = fb_flip_noop; + backend->UpdateRect = fb_update_rect_noop; + backend->Exit = fb_exit; + backend->SetAttributes = NULL; + backend->fd_list = NULL; + backend->Poll = NULL;
return backend; err3: diff --git a/libs/backends/GP_SDL.c b/libs/backends/GP_SDL.c index 6a8d0d4..ae0e8c6 100644 --- a/libs/backends/GP_SDL.c +++ b/libs/backends/GP_SDL.c @@ -39,6 +39,8 @@ static SDL_Surface *sdl_surface; static SDL_mutex *mutex; static GP_Context context;
+static uint32_t sdl_flags = SDL_SWSURFACE; + /* Backend API funcitons */
static void sdl_flip(struct GP_Backend *self __attribute__((unused))) @@ -79,29 +81,6 @@ static void sdl_poll(struct GP_Backend *self __attribute__((unused))) SDL_mutexV(mutex); }
-static void sdl_exit(struct GP_Backend *self __attribute__((unused))); - -static struct GP_Backend backend = { - .name = "SDL", - .context = NULL, - .Flip = sdl_flip, - .UpdateRect = sdl_update_rect, - .Exit = sdl_exit, - .fd_list = NULL, - .Poll = sdl_poll, -}; - -static void sdl_exit(struct GP_Backend *self __attribute__((unused))) -{ - SDL_mutexP(mutex); - - SDL_Quit(); - - SDL_DestroyMutex(mutex); - - backend.context = NULL; -} - int context_from_surface(GP_Context *context, SDL_Surface *surf) { /* sanity checks on the SDL surface */ @@ -140,6 +119,49 @@ int context_from_surface(GP_Context *context, SDL_Surface *surf) return 0; }
+static int sdl_set_attributes(struct GP_Backend *self __attribute__((unused)), + uint32_t w, uint32_t h, + const char *caption) +{ + SDL_mutexP(mutex); + + 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); + } + + SDL_mutexV(mutex); + + return 0; +} + +static void sdl_exit(struct GP_Backend *self __attribute__((unused))); + +static struct GP_Backend backend = { + .name = "SDL", + .context = NULL, + .Flip = sdl_flip, + .UpdateRect = sdl_update_rect, + .SetAttributes = sdl_set_attributes, + .Exit = sdl_exit, + .fd_list = NULL, + .Poll = sdl_poll, +}; + +static void sdl_exit(struct GP_Backend *self __attribute__((unused))) +{ + SDL_mutexP(mutex); + + SDL_Quit(); + + SDL_DestroyMutex(mutex); + + backend.context = NULL; +} + GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp, uint8_t flags, const char *caption) { @@ -150,8 +172,6 @@ GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp, uint8_t flags, return NULL; }
- uint32_t sdl_flags = SDL_SWSURFACE; - if (flags & GP_SDL_FULLSCREEN) sdl_flags |= SDL_FULLSCREEN;
diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c index a19ea7b..f11cd6a 100644 --- a/libs/backends/GP_X11.c +++ b/libs/backends/GP_X11.c @@ -37,21 +37,23 @@ struct x11_priv { Window win; Visual *vis; XImage *img; - - GP_Context *context; };
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); XDestroyWindow(x11->dpy, x11->win); + /* I wonder if this is right sequence... */ + XUnlockDisplay(x11->dpy); XCloseDisplay(x11->dpy);
- GP_ContextFree(x11->context); - free(self); }
@@ -74,8 +76,8 @@ static void x11_update_rect(GP_Backend *self, GP_Coord x0, GP_Coord y0, 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; + unsigned int w = self->context->w; + unsigned int h = self->context->h;
GP_DEBUG(4, "Flipping context");
@@ -120,6 +122,60 @@ static void x11_poll(GP_Backend *self) XUnlockDisplay(x11->dpy); }
+static int x11_set_attributes(struct GP_Backend *self, + uint32_t w, uint32_t h, + const char *caption) +{ + struct x11_priv *x11 = GP_BACKEND_PRIV(self); + + XLockDisplay(x11->dpy); + + if (caption != NULL) + XmbSetWMProperties(x11->dpy, x11->win, caption, caption, + NULL, 0, NULL, NULL, NULL); + + if (w != 0 || h != 0) { + GP_Context *context; + XImage *img; + + if (w == 0) + w = self->context->w; + + if (h == 0) + h = self->context->h; + + /* Create new X image */ + img = XCreateImage(x11->dpy, x11->vis, 24, ZPixmap, 0, NULL, + w, h, 32, 0); + + /* Allocate new context */ + context = GP_ContextAlloc(w, h, GP_PIXEL_xRGB8888); + + if (context == NULL) { + XDestroyImage(img); + return 1; + } + + /* Free old image and context */ + GP_ContextFree(self->context); + x11->img->data = NULL; + XDestroyImage(x11->img); + + /* Swap the pointers */ + self->context = context; + img->data = (char*)self->context->pixels; + x11->img = img; + + /* Resize X11 window */ + XResizeWindow(x11->dpy, x11->win, w, h); + XFlush(x11->dpy); + } + + XUnlockDisplay(x11->dpy); + + return 0; +} + GP_Backend *GP_BackendX11Init(const char *display, int x, int y, unsigned int w, unsigned int h, const char *caption) @@ -137,9 +193,9 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
x11 = GP_BACKEND_PRIV(backend);
- x11->context = GP_ContextAlloc(w, h, GP_PIXEL_xRGB8888); + backend->context = GP_ContextAlloc(w, h, GP_PIXEL_xRGB8888);
- if (x11->context == NULL) + if (backend->context == NULL) goto err0; //TODO: Error checking @@ -159,7 +215,7 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y, x11->img = XCreateImage(x11->dpy, x11->vis, 24, ZPixmap, 0, NULL, w, h, 32, 0);
- x11->img->data = (char*)x11->context->pixels; + x11->img->data = (char*)backend->context->pixels;
x11->win = XCreateWindow(x11->dpy, DefaultRootWindow(x11->dpy), x, y, w, h, 0, CopyFromParent, @@ -201,13 +257,13 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
*/
- backend->name = "X11"; - backend->context = x11->context; - backend->Flip = x11_flip; - backend->UpdateRect = x11_update_rect; - backend->Exit = x11_exit; - backend->fd_list = NULL; - backend->Poll = x11_poll; + backend->name = "X11"; + backend->Flip = x11_flip; + backend->UpdateRect = x11_update_rect; + backend->Exit = x11_exit; + backend->fd_list = NULL; + backend->Poll = x11_poll; + backend->SetAttributes = x11_set_attributes;
return backend; //err3: @@ -215,7 +271,7 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y, err2: XCloseDisplay(x11->dpy); err1: - GP_ContextFree(x11->context); + GP_ContextFree(backend->context); err0: free(backend); return NULL;
-----------------------------------------------------------------------
Summary of changes: demos/spiv/spiv.c | 26 +++++++++++- include/backends/GP_Backend.h | 43 ++++++++++++++++++- libs/backends/GP_Backend.c | 12 +++++ libs/backends/GP_LinuxFB.c | 15 ++++--- libs/backends/GP_SDL.c | 70 ++++++++++++++++++++----------- libs/backends/GP_X11.c | 90 +++++++++++++++++++++++++++++++++-------- 6 files changed, 204 insertions(+), 52 deletions(-)
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.