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 5d493cb045b66ed27d9136ea524b1e3184732451 (commit) via b651425751121eeb3e24b2c1feeb9925eae9a5ed (commit) via 58f4b69f1ea180d0a9bd2d04da82bb7597f6c714 (commit) via afe51107773719e6f475eaea52670f279af6fa79 (commit) via 46023cbd49dc926f7aea8db1916870df152e3bcc (commit) via 3c7c8c724642a31fae16904368b1b3967f92f347 (commit) via 60b3c510acc143fef8afbc5e9e583ad9bf19d2b2 (commit) via 4dea5a3fd0bbbeb2f47b1c4d700f11d46c1c2e61 (commit) via 651d7642bbdfc7ab54084817f133ec07e793e784 (commit) via 0a1d349310f6980622e3c1e8c2778aba4eb175bf (commit) from bcd8f5bd8906312aee47f6cbf16eba26f69ea1c3 (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/5d493cb045b66ed27d9136ea524b1e3184732...
commit 5d493cb045b66ed27d9136ea524b1e3184732451 Author: Cyril Hrubis metan@ucw.cz Date: Sun Aug 4 17:25:21 2013 +0200
spiv: Disable timers by default.
Timers are disabled by default and can be enabled with -t.
Timers prints cpu and wall time for certain operation into the stdout.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/spiv/cpu_timer.c b/demos/spiv/cpu_timer.c index 2071ada..e5b2fbc 100644 --- a/demos/spiv/cpu_timer.c +++ b/demos/spiv/cpu_timer.c @@ -35,8 +35,18 @@ static void to_time(int *sec, int *nsec, struct timespec *start, } }
+static int timers_disabled = 1; + +void cpu_timer_switch(int enable) +{ + timers_disabled = !enable; +} + void cpu_timer_start(struct cpu_timer *self, const char *name) { + if (timers_disabled) + return; + self->name = name;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &self->t_cpu_start); @@ -45,6 +55,9 @@ void cpu_timer_start(struct cpu_timer *self, const char *name)
void cpu_timer_stop(struct cpu_timer *self) { + if (timers_disabled) + return; + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &self->t_cpu_stop); clock_gettime(CLOCK_MONOTONIC, &self->t_real_stop);
diff --git a/demos/spiv/cpu_timer.h b/demos/spiv/cpu_timer.h index 1d8c8e7..733d27c 100644 --- a/demos/spiv/cpu_timer.h +++ b/demos/spiv/cpu_timer.h @@ -22,7 +22,7 @@
/*
- Simple timers to count cpu time. + Simple timers to count and print cpu time spend in particular codepath.
*/
@@ -40,6 +40,11 @@ struct cpu_timer { };
/* + * Enable/disable all timers. + */ +void cpu_timer_switch(int enable); + +/* * Inialize cpu timer. */ void cpu_timer_start(struct cpu_timer *self, const char *name); diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c index 514b35c..66284ba 100644 --- a/demos/spiv/spiv.c +++ b/demos/spiv/spiv.c @@ -677,7 +677,7 @@ int main(int argc, char *argv[])
GP_TIMER_DECLARE(timer, 0, 0, "Slideshow", timer_callback, ¶ms);
- while ((opt = getopt(argc, argv, "b:ce:fhIPs:r:z:0:1:2:3:4:5:6:7:8:9:")) != -1) { + while ((opt = getopt(argc, argv, "b:ce:fhIPr:s:tz:0:1:2:3:4:5:6:7:8:9:")) != -1) { switch (opt) { case 'I': params.show_info = 1; @@ -720,6 +720,9 @@ int main(int argc, char *argv[]) print_help(); exit(0); break; + case 't': + cpu_timer_switch(1); + break; case 'z': switch (optarg[0]) { case 'f': diff --git a/demos/spiv/spiv_help.c b/demos/spiv/spiv_help.c index 9e2d14b..c45de06 100644 --- a/demos/spiv/spiv_help.c +++ b/demos/spiv/spiv_help.c @@ -85,6 +85,9 @@ void print_help(void) printf(" -zw zoom is fixed to window size (currently default)n"); printf(" -b pass backend init string to backend initn"); printf(" pass -b help for more infon"); + printf(" -t enable timersn"); + printf(" if set timers that measure cpu and wall timen"); + printf(" of certain operations are printed into stdoutn"); puts("n"); printf("Actions:nn"); printf(" -1 'cmd' sets first actionn");
http://repo.or.cz/w/gfxprim.git/commit/b651425751121eeb3e24b2c1feeb9925eae9a...
commit b651425751121eeb3e24b2c1feeb9925eae9a5ed Author: Cyril Hrubis metan@ucw.cz Date: Sun Aug 4 17:21:29 2013 +0200
filters: GP_ResizeLinear.gen.c.t: Remove debug print
Remove forgotten debug printf.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/filters/GP_ResizeLinear.gen.c.t b/libs/filters/GP_ResizeLinear.gen.c.t index e01b2c2..b2bfc68 100644 --- a/libs/filters/GP_ResizeLinear.gen.c.t +++ b/libs/filters/GP_ResizeLinear.gen.c.t @@ -312,8 +312,6 @@ int GP_FilterResizeLinearLFInt_Raw(const GP_Context *src, GP_Context *dst, float x_rat = 1.00 * dst->w / src->w; float y_rat = 1.00 * dst->h / src->h;
- printf("%f %fn", x_rat, y_rat); - if (x_rat < 1.00 && y_rat < 1.00) {
GP_DEBUG(1, "Downscaling image %ux%u -> %ux%u %2.2f %2.2f",
http://repo.or.cz/w/gfxprim.git/commit/58f4b69f1ea180d0a9bd2d04da82bb7597f6c...
commit 58f4b69f1ea180d0a9bd2d04da82bb7597f6c714 Author: Cyril Hrubis metan@ucw.cz Date: Sun Jul 28 12:12:33 2013 +0200
input: KBD: Remove newline from debug message.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/input/GP_InputDriverKBD.c b/libs/input/GP_InputDriverKBD.c index d45a869..1c20fd9 100644 --- a/libs/input/GP_InputDriverKBD.c +++ b/libs/input/GP_InputDriverKBD.c @@ -69,7 +69,7 @@ void GP_InputDriverKBDEventPut(struct GP_EventQueue *event_queue, int press = !(ev & 0x80); int key;
- GP_DEBUG(2, "Press %i keycode %in", press, keycode); + GP_DEBUG(2, "Press %i keycode %i", press, keycode);
if (keycode > 0 && keycode <= GP_ARRAY_SIZE(keycode_table)) { key = keycode_table[keycode - 1];
http://repo.or.cz/w/gfxprim.git/commit/afe51107773719e6f475eaea52670f279af6f...
commit afe51107773719e6f475eaea52670f279af6fa79 Author: Cyril Hrubis metan@ucw.cz Date: Sun Jul 28 12:09:52 2013 +0200
core: GP_Common.h: Add stddef.h due to offsetof().
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/include/core/GP_Common.h b/include/core/GP_Common.h index 40b3c09..5de8546 100644 --- a/include/core/GP_Common.h +++ b/include/core/GP_Common.h @@ -30,6 +30,7 @@ #include <stdint.h> #include <stdlib.h> #include <unistd.h> +#include <stddef.h>
#ifndef __cplusplus
http://repo.or.cz/w/gfxprim.git/commit/46023cbd49dc926f7aea8db1916870df152e3...
commit 46023cbd49dc926f7aea8db1916870df152e3bcc Author: Cyril Hrubis metan@ucw.cz Date: Sun Jul 28 11:47:08 2013 +0200
backends: SDL: Avoid lockup in Wait.
Same story again. We cannot sleep in Wait while holding the mutex and we do not have a file descriptor to poll on so we need resort to polling.
We will need a better solution here.
One posibility is to add a init flag to all backends and resort to polling only if application needs thread safe backend.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/backends/GP_SDL.c b/libs/backends/GP_SDL.c index ab87c82..7fde309 100644 --- a/libs/backends/GP_SDL.c +++ b/libs/backends/GP_SDL.c @@ -103,15 +103,22 @@ static void sdl_wait(struct GP_Backend *self __attribute__((unused))) { SDL_Event ev;
- SDL_mutexP(mutex); + //SDL_WaitEvent(&ev); + //sdl_put_event(&ev);
- SDL_WaitEvent(&ev); - sdl_put_event(&ev); + for (;;) { + if (GP_EventQueueEventsQueued(&self->event_queue)) + return;
- while (SDL_PollEvent(&ev)) - sdl_put_event(&ev); + SDL_mutexP(mutex);
- SDL_mutexV(mutex); + while (SDL_PollEvent(&ev)) + sdl_put_event(&ev); + + SDL_mutexV(mutex); + + usleep(10000); + } }
static int context_from_surface(GP_Context *context, const SDL_Surface *surf)
http://repo.or.cz/w/gfxprim.git/commit/3c7c8c724642a31fae16904368b1b3967f92f...
commit 3c7c8c724642a31fae16904368b1b3967f92f347 Author: Cyril Hrubis metan@ucw.cz Date: Sat Jul 27 23:46:54 2013 +0200
input: KBD: Add mapping for few keys.
These are arrows, delete, left meta and sysrq.
Now works on your framebuffer too ;).
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/input/GP_InputDriverKBD.c b/libs/input/GP_InputDriverKBD.c index 020f45c..d45a869 100644 --- a/libs/input/GP_InputDriverKBD.c +++ b/libs/input/GP_InputDriverKBD.c @@ -52,10 +52,14 @@ static uint16_t keycode_table[] = { 0, 0, GP_KEY_F11, GP_KEY_F12, 0, 0, 0, 0, 0, 0, 0, GP_KEY_KP_ENTER, - GP_KEY_RIGHT_CTRL, GP_KEY_KP_ASTERISK, 0/*PRINT_SCREEN*/, GP_KEY_RIGHT_ALT, - 0, GP_KEY_HOME, 0, GP_KEY_PAGE_UP, - 0, 0, GP_KEY_END, 0, - GP_KEY_PAGE_DOWN, GP_KEY_INSERT, + GP_KEY_RIGHT_CTRL, GP_KEY_KP_ASTERISK, GP_KEY_SYSRQ, GP_KEY_RIGHT_ALT, + 0, GP_KEY_HOME, GP_KEY_UP, GP_KEY_PAGE_UP, + GP_KEY_LEFT, GP_KEY_RIGHT, GP_KEY_END, GP_KEY_DOWN, + GP_KEY_PAGE_DOWN, GP_KEY_INSERT, GP_KEY_DELETE, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + GP_KEY_LEFT_META, };
void GP_InputDriverKBDEventPut(struct GP_EventQueue *event_queue,
http://repo.or.cz/w/gfxprim.git/commit/60b3c510acc143fef8afbc5e9e583ad9bf19d...
commit 60b3c510acc143fef8afbc5e9e583ad9bf19d2b2 Author: Cyril Hrubis metan@ucw.cz Date: Sat Jul 27 20:13:08 2013 +0200
demos: Add backend resize ack to few demos
Add backend resize ack and system exit handling to linetest and shapetest and particle demo.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/c_simple/linetest.c b/demos/c_simple/linetest.c index 92aa194..1069a7e 100644 --- a/demos/c_simple/linetest.c +++ b/demos/c_simple/linetest.c @@ -96,6 +96,18 @@ void event_loop(void) pause_flag = !pause_flag; break; } + break; + case GP_EV_SYS: + switch(ev.code) { + case GP_EV_SYS_QUIT: + GP_BackendExit(win); + exit(0); + break; + case GP_EV_SYS_RESIZE: + GP_BackendResizeAck(win); + break; + } + break; } } } diff --git a/demos/c_simple/shapetest.c b/demos/c_simple/shapetest.c index 048496b..314be26 100644 --- a/demos/c_simple/shapetest.c +++ b/demos/c_simple/shapetest.c @@ -443,6 +443,11 @@ void event_loop(void) GP_BackendExit(backend); exit(0); break; + case GP_EV_SYS_RESIZE: + GP_BackendResizeAck(backend); + center_x = backend->context->w / 2; + center_y = backend->context->h / 2; + break; } break; } diff --git a/demos/particle/particle_demo.c b/demos/particle/particle_demo.c index 3f3cf5f..cc9a4a2 100644 --- a/demos/particle/particle_demo.c +++ b/demos/particle/particle_demo.c @@ -135,6 +135,22 @@ int main(int argc, char *argv[]) break; } break; + case GP_EV_SYS: + switch(ev.code) { + case GP_EV_SYS_QUIT: + GP_BackendExit(backend); + exit(0); + break; + case GP_EV_SYS_RESIZE: + GP_BackendResizeAck(backend); + space_destroy(space); + space = space_create(particles, + 10<<8, 10<<8, + (context->w - 10)<<8, + (context->h - 10)<<8); + break; + } + break; } }
http://repo.or.cz/w/gfxprim.git/commit/4dea5a3fd0bbbeb2f47b1c4d700f11d46c1c2...
commit 4dea5a3fd0bbbeb2f47b1c4d700f11d46c1c2e61 Author: Cyril Hrubis metan@ucw.cz Date: Sat Jul 27 14:05:01 2013 +0200
backends: Add basic AALib backend.
Unfortunately aalib is not thread safe nor it exposes file descriptor so we have to stick to polling as we need to be thread safe.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/configure b/configure index 7a3b93d..2d41ff4 100755 --- a/configure +++ b/configure @@ -39,7 +39,7 @@ def c_compiler_exists(cfg): cfg["CC"][0])
def python_version(cfg): - sys.stderr.write("Cddhecking for python-config Python version ... ") + sys.stderr.write("Checking for python-config Python version ... ")
if (cfg['PYTHON_CONFIG'][0] is ''): sys.stderr.write('NAn') @@ -330,6 +330,9 @@ if __name__ == '__main__': ["X_SHM", "MIT-SHM X Extension", [header_exists, "X11/extensions/XShm.h"], "", "-lXext", ["backends"]], + ["aalib", + "Portable ascii art GFX library", + [header_exists, "aalib.h"], "", "-laa", ["backends"]], ["freetype", "A high-quality and portable font engine", [header_exists, "ft2build.h"], "", "`freetype-config --libs`", ["core"]], diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c index 936cb14..514b35c 100644 --- a/demos/spiv/spiv.c +++ b/demos/spiv/spiv.c @@ -531,7 +531,7 @@ static void *image_loader(void *ptr) if (img == NULL) return NULL;
- image_cache_print(params->img_resized_cache); + //image_cache_print(params->img_resized_cache); update: update_display(params, img, orig_img); cpu_timer_stop(&sum_timer); diff --git a/include/backends/GP_Backends.h b/include/backends/GP_AALib.h similarity index 76% copy from include/backends/GP_Backends.h copy to include/backends/GP_AALib.h index 9d72fc7..f2849e4 100644 --- a/include/backends/GP_Backends.h +++ b/include/backends/GP_AALib.h @@ -16,35 +16,20 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
-/* - - Catch all header for backends. - - */ - -#ifndef BACKENDS_GP_BACKENDS_H -#define BACKENDS_GP_BACKENDS_H +#ifndef BACKENDS_GP_AALIB_H +#define BACKENDS_GP_AALIB_H
-/* - * Base backend definitions. - */ -#include "backends/GP_Backend.h" - -/* - * Backends. - */ -#include "backends/GP_LinuxFB.h" -#include "backends/GP_SDL.h" -#include "backends/GP_X11.h" -#include "backends/GP_BackendVirtual.h" +#include "GP_Backend.h"
/* - * Simplified backend initalization. + * Initalize AALib. + * + * TODO: add a way to pass aalib params */ -#include "backends/GP_BackendInit.h" +GP_Backend *GP_BackendAALibInit(void);
-#endif /* BACKENDS_GP_BACKENDS_H */ +#endif /* BACKENDS_GP_AALIB_H */ diff --git a/include/backends/GP_Backends.h b/include/backends/GP_Backends.h index 9d72fc7..db569a1 100644 --- a/include/backends/GP_Backends.h +++ b/include/backends/GP_Backends.h @@ -40,6 +40,7 @@ #include "backends/GP_LinuxFB.h" #include "backends/GP_SDL.h" #include "backends/GP_X11.h" +#include "backends/GP_AALib.h" #include "backends/GP_BackendVirtual.h"
/* diff --git a/libs/backends/GP_AALib.c b/libs/backends/GP_AALib.c new file mode 100644 index 0000000..bfcd946 --- /dev/null +++ b/libs/backends/GP_AALib.c @@ -0,0 +1,280 @@ +/***************************************************************************** + * 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-2013 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include <errno.h> + +#include "core/GP_Debug.h" +#include "core/GP_Context.h" +#include "backends/GP_AALib.h" +#include "input/GP_Input.h" + +#include "../config.h" + +#ifdef HAVE_AALIB + +#include <aalib.h> +#include <pthread.h> + +/* + * Guards AALib library calls. + * + * In case we run under X the underlying xcb connection is not initialized with + * XInitThreads() and thus not multithread safe. + */ +static pthread_mutex_t aalib_mutex = PTHREAD_MUTEX_INITIALIZER; + +struct aalib_priv { + aa_context *c; + GP_Context ctx; +}; + +/* ascii mapped keys */ +static const uint16_t keymap[] = { + 0, 0, 0, 0, + 0, 0, 0, GP_KEY_BACKSPACE, + GP_KEY_TAB, 0, 0, 0, + GP_KEY_ENTER, 0, 0, 0, + 0, 0, GP_KEY_PAUSE, 0, + 0, 0, 0, 0, + 0, 0, GP_KEY_ESC, 0, + 0, 0, 0, GP_KEY_SPACE, + 0, 0, 0, 0, + 0, 0, GP_KEY_APOSTROPHE, 0, + 0, 0, 0, GP_KEY_COMMA, + GP_KEY_MINUS, GP_KEY_DOT, GP_KEY_SLASH, GP_KEY_0, + GP_KEY_1, GP_KEY_2, GP_KEY_3, GP_KEY_4, + GP_KEY_5, GP_KEY_6, GP_KEY_7, GP_KEY_8, + GP_KEY_9, 0, GP_KEY_SEMICOLON, 0, + GP_KEY_EQUAL, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, GP_KEY_LEFT_BRACE, GP_KEY_BACKSLASH, + GP_KEY_RIGHT_BRACE, 0, 0, GP_KEY_GRAVE, + GP_KEY_A, GP_KEY_B, GP_KEY_C, GP_KEY_D, + GP_KEY_E, GP_KEY_F, GP_KEY_G, GP_KEY_H, + GP_KEY_I, GP_KEY_J, GP_KEY_K, GP_KEY_L, + GP_KEY_M, GP_KEY_N, GP_KEY_O, GP_KEY_P, + GP_KEY_Q, GP_KEY_R, GP_KEY_S, GP_KEY_T, + GP_KEY_U, GP_KEY_V, GP_KEY_W, GP_KEY_X, + GP_KEY_Y, GP_KEY_Z, 0, 0, + 0, 0, GP_KEY_DELETE, +}; + +/* special keys mapped from 300 to 305 */ +static const uint16_t keymap2[] = { + GP_KEY_UP, GP_KEY_DOWN, + GP_KEY_LEFT, GP_KEY_RIGHT, + GP_KEY_BACKSPACE, GP_KEY_ESC, +}; + +static void aalib_exit(GP_Backend *self) +{ + struct aalib_priv *aa = GP_BACKEND_PRIV(self); + + GP_DEBUG(1, "Closing AALib"); + aa_close(aa->c); +} + +static void aalib_flip(GP_Backend *self) +{ + struct aalib_priv *aa = GP_BACKEND_PRIV(self); + + GP_DEBUG(4, "Rendering and flipping screen"); + + aa_render(aa->c, &aa_defrenderparams, + 0, 0, aa_scrwidth(aa->c), aa_scrheight(aa->c)); + + pthread_mutex_lock(&aalib_mutex); + aa_flush(aa->c); + pthread_mutex_unlock(&aalib_mutex); +} + +static void aalib_update_rect(GP_Backend *self, GP_Coord x0, GP_Coord y0, + GP_Coord x1, GP_Coord y1) +{ + struct aalib_priv *aa = GP_BACKEND_PRIV(self); + + GP_DEBUG(4, "Updating rect %ix%i-%ix%i", x0, y0, x1, y1); + + /* + * TODO: Map screen coordinates to bitmap coordinates. + */ + int w = aa_scrwidth(aa->c); + int h = aa_scrheight(aa->c); + + aa_render(aa->c, &aa_defrenderparams, + 0, 0, w, h); + + pthread_mutex_lock(&aalib_mutex); + aa_flush(aa->c); + pthread_mutex_unlock(&aalib_mutex); +} + +static int aalib_resize_ack(GP_Backend *self) +{ + struct aalib_priv *aa = GP_BACKEND_PRIV(self); + + if (!aa_resize(aa->c)) { + GP_WARN("aa_resize() failed"); + return 1; + } + + int w = aa_imgwidth(aa->c); + int h = aa_imgheight(aa->c); + + GP_DEBUG(1, "Reinitializing Context %ix%i", w, h); + + GP_ContextInit(&aa->ctx, w, h, GP_PIXEL_G8, aa_image(aa->c)); + + return 0; +} + +static void parse_event(GP_Backend *self, int ev) +{ + unsigned int key; + + if (ev == 0) + return; + + if (ev == AA_RESIZE) { + GP_DEBUG(1, "Resize event"); + //TODO: Can we get the new size somehow? + GP_EventQueuePushResize(&self->event_queue, 0, 0, NULL); + return; + } + + if (ev <= (int)GP_ARRAY_SIZE(keymap)) { + key = keymap[ev - 1]; + } else { + if (ev >= 300 && ev <= 305) { + key = keymap2[ev - 300]; + } else { + GP_DEBUG(1, "Unhandled event %i", ev); + return; + } + } + + /* emulate keyup events */ + GP_EventQueuePushKey(&self->event_queue, key, 1, NULL); + GP_EventQueuePushKey(&self->event_queue, key, 0, NULL); +} + +static void aalib_poll(GP_Backend *self) +{ + struct aalib_priv *aa = GP_BACKEND_PRIV(self); + int key; + + pthread_mutex_lock(&aalib_mutex); + key = aa_getevent(aa->c, 0); + pthread_mutex_unlock(&aalib_mutex); + + parse_event(self, key); +} + +static void aalib_wait(GP_Backend *self) +{ + /* We cannot wait due to possible lockup, so we poll */ + for (;;) { + aalib_poll(self); + + if (GP_EventQueueEventsQueued(&self->event_queue)) + return; + + usleep(10000); + } +} + +GP_Backend *GP_BackendAALibInit(void) +{ + GP_Backend *backend; + struct aalib_priv *aa; + int w, h; + + backend = malloc(sizeof(GP_Backend) + sizeof(struct aalib_priv)); + + if (backend == NULL) + return NULL; + + aa = GP_BACKEND_PRIV(backend); + + GP_DEBUG(1, "Initializing aalib"); + + aa->c = aa_autoinit(&aa_defparams); + + if (!aa->c) { + GP_DEBUG(1, "Failed to initialize aalib"); + goto err1; + } + + GP_DEBUG(1, "AALib driver %s %s %ix%i", aa->c->driver->name, + aa->c->driver->shortname, + aa->c->params.width, aa->c->params.height); + + if (!aa_autoinitkbd(aa->c, 0)) { + GP_DEBUG(1, "Failed to initialize aalib keyboard"); + goto err2; + } + + w = aa_imgwidth(aa->c); + h = aa_imgheight(aa->c); + + GP_DEBUG(1, "Initializing Context %ix%i", w, h); + + GP_ContextInit(&aa->ctx, w, h, GP_PIXEL_G8, aa_image(aa->c)); + + /* update API */ + backend->name = "AALib"; + backend->context = &aa->ctx; + backend->Flip = aalib_flip; + backend->UpdateRect = aalib_update_rect; + backend->Exit = aalib_exit; + backend->SetAttributes = NULL; + backend->ResizeAck = aalib_resize_ack; + backend->Poll = aalib_poll; + backend->Wait = aalib_wait; + backend->fd = -1; + backend->timers = NULL; + + GP_EventQueueInit(&backend->event_queue, w, h, 0); + + return backend; +err2: + aa_close(aa->c); +err1: + free(backend); + return NULL; +} + +#else + +GP_Backend *GP_BackendAALibInit(void) +{ + GP_FATAL("AALib support not compiled in!"); + errno = ENOSYS; + return NULL; +} + +#endif /* HAVE_AALIB */ diff --git a/libs/backends/GP_BackendInit.c b/libs/backends/GP_BackendInit.c index 985c528..5a601a0 100644 --- a/libs/backends/GP_BackendInit.c +++ b/libs/backends/GP_BackendInit.c @@ -218,10 +218,35 @@ static GP_Backend *backend_x11_init(char *params, const char *caption, } }
+static void backend_aa_help(FILE *help, const char *err) +{ + if (help == NULL) + return; + + if (err != NULL) + fprintf(help, "ERROR: %sn", err); + + fprintf(help, "AALib backendn" + "--------------n" + "AAn"); +} + +static GP_Backend *backend_aa_init(char *params, const char *caption, + FILE *help) +{ + (void) help; + (void) caption; + (void) params; + + return GP_BackendAALibInit(); +} + + static const char *backend_names[] = { "SDL", /* libSDL */ "FB", /* Linux Framebuffer */ "X11", /* X11 window system */ + "AA", /* AALib */ NULL, };
@@ -229,6 +254,7 @@ static GP_Backend *(*backend_inits[])(char *, const char *, FILE *) = { backend_sdl_init, backend_fb_init, backend_x11_init, + backend_aa_init, NULL, };
@@ -236,6 +262,7 @@ static void (*backend_helps[])(FILE *help, const char *err) = { backend_sdl_help, backend_fb_help, backend_x11_help, + backend_aa_help, NULL, };
http://repo.or.cz/w/gfxprim.git/commit/651d7642bbdfc7ab54084817f133ec07e793e...
commit 651d7642bbdfc7ab54084817f133ec07e793e784 Author: Cyril Hrubis metan@ucw.cz Date: Sat Jul 27 13:43:50 2013 +0200
demos: c_simple, particle: Add -b (backend) option
This allows specifying backend init string with -b option.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/c_simple/linetest.c b/demos/c_simple/linetest.c index 8c91cf5..92aa194 100644 --- a/demos/c_simple/linetest.c +++ b/demos/c_simple/linetest.c @@ -100,9 +100,20 @@ void event_loop(void) } }
-int main(void) +int main(int argc, char *argv[]) { const char *backend_opts = "X11"; + int opt; + + while ((opt = getopt(argc, argv, "b:")) != -1) { + switch (opt) { + case 'b': + backend_opts = optarg; + break; + default: + fprintf(stderr, "Invalid paramter '%c'n", opt); + } + }
win = GP_BackendInit(backend_opts, "Line Test", stderr);
diff --git a/demos/c_simple/shapetest.c b/demos/c_simple/shapetest.c index 6444445..048496b 100644 --- a/demos/c_simple/shapetest.c +++ b/demos/c_simple/shapetest.c @@ -340,7 +340,7 @@ void event_loop(void) for (;;) { GP_BackendWaitEvent(backend, &ev);
- GP_EventDump(&ev); + //GP_EventDump(&ev);
shift_pressed = GP_EventGetKey(&ev, GP_KEY_LEFT_SHIFT) || GP_EventGetKey(&ev, GP_KEY_RIGHT_SHIFT); @@ -471,11 +471,20 @@ void print_instructions(void) printf(" 1/2/3 ............... choose shape variant (if applicable)n"); }
-int main(void) +int main(int argc, char *argv[]) { const char *backend_opts = "X11"; + int opt;
-// GP_SetDebugLevel(10); + while ((opt = getopt(argc, argv, "b:")) != -1) { + switch (opt) { + case 'b': + backend_opts = optarg; + break; + default: + fprintf(stderr, "Invalid paramter '%c'n", opt); + } + }
backend = GP_BackendInit(backend_opts, "Shapetest", stderr);
diff --git a/demos/c_simple/v4l2_show.c b/demos/c_simple/v4l2_show.c index a88a891..50ea514 100644 --- a/demos/c_simple/v4l2_show.c +++ b/demos/c_simple/v4l2_show.c @@ -40,9 +40,6 @@ int main(int argc, char *argv[]) int mode = 0; int opt;
- /* Turn on debug messages */ - //GP_SetDebugLevel(10); - while ((opt = getopt(argc, argv, "d:hH:W:l:")) != -1) { switch (opt) { case 'd': diff --git a/demos/particle/particle_demo.c b/demos/particle/particle_demo.c index 6fcc11d..3f3cf5f 100644 --- a/demos/particle/particle_demo.c +++ b/demos/particle/particle_demo.c @@ -64,12 +64,16 @@ int main(int argc, char *argv[]) const char *backend_opts = "X11"; int opt; int pause_flag = 0; + int particles = 160;
- while ((opt = getopt(argc, argv, "b:Ii:Ps:r:")) != -1) { + while ((opt = getopt(argc, argv, "b:n:")) != -1) { switch (opt) { case 'b': backend_opts = optarg; break; + case 'n': + particles = atoi(optarg); + break; default: fprintf(stderr, "Invalid paramter '%c'n", opt); } @@ -93,7 +97,7 @@ int main(int argc, char *argv[]) GP_BackendFlip(backend);
struct space *space; - space = space_create(160, 10<<8, 10<<8, (context->w - 10)<<8, (context->h - 10)<<8); + space = space_create(particles, 10<<8, 10<<8, (context->w - 10)<<8, (context->h - 10)<<8);
for (;;) { if (backend->Poll)
http://repo.or.cz/w/gfxprim.git/commit/0a1d349310f6980622e3c1e8c2778aba4eb17...
commit 0a1d349310f6980622e3c1e8c2778aba4eb175bf Author: Cyril Hrubis metan@ucw.cz Date: Sat Jul 20 19:44:45 2013 +0200
backends: Improve Linux FB backend.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/include/backends/GP_LinuxFB.h b/include/backends/GP_LinuxFB.h index 2dcc1c9..ee9498c 100644 --- a/include/backends/GP_LinuxFB.h +++ b/include/backends/GP_LinuxFB.h @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -25,6 +25,21 @@
#include "GP_Backend.h"
+enum GP_LinuxFBFlags { + /* + * Use KBD to get input events + */ + GP_FB_INPUT_KBD = 0x01, + /* + * Use shadow framebuffer for drawing. + */ + GP_FB_SHADOW = 0x02, + /* + * Allocate new console, if not set current is used. + */ + GP_FB_ALLOC_CON = 0x04, +}; + /* * Initalize framebuffer. * @@ -38,6 +53,6 @@ * * If flag is set, the konsole kbd is used to push events into event queue. */ -GP_Backend *GP_BackendLinuxFBInit(const char *path, int flag); +GP_Backend *GP_BackendLinuxFBInit(const char *path, int flags);
#endif /* BACKENDS_GP_FRAMEBUFFER_H */ diff --git a/libs/backends/GP_BackendInit.c b/libs/backends/GP_BackendInit.c index f0a20f1..985c528 100644 --- a/libs/backends/GP_BackendInit.c +++ b/libs/backends/GP_BackendInit.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -109,7 +109,7 @@ static void backend_fb_help(FILE *help, const char *err)
fprintf(help, "LinuxFB backendn" "--------------n" - "FB:[/dev/fbX]n"); + "FB:NO_SHADOW:USE_CON:[/dev/fbX]n"); }
static GP_Backend *backend_fb_init(char *params, const char *caption, @@ -123,7 +123,7 @@ static GP_Backend *backend_fb_init(char *params, const char *caption, if (params != NULL) fb = params;
- return GP_BackendLinuxFBInit(fb, 1); + return GP_BackendLinuxFBInit(fb, 3); }
static void backend_x11_help(FILE *help, const char *err) diff --git a/libs/backends/GP_LinuxFB.c b/libs/backends/GP_LinuxFB.c index 9f5c83c..8e96684 100644 --- a/libs/backends/GP_LinuxFB.c +++ b/libs/backends/GP_LinuxFB.c @@ -42,113 +42,147 @@ struct fb_priv { GP_Context context; uint32_t bsize; + void *fb_mem;
- int flag; + int flags;
/* console fd, nr and saved data */ int con_fd; int con_nr; int last_con_nr; int saved_kb_mode; + struct termios ts; + int restore_termios;
int fb_fd; char path[]; };
/* - * Allocates and switches to newly allocated console. + * Restore console and keyboard mode to whatever was there before. */ -static int allocate_console(struct fb_priv *fb, int flag) +static void exit_kbd(struct fb_priv *fb) { - struct vt_stat vts; - int fd, nr; - char buf[255]; - - /* allocate and switch to new console */ - GP_DEBUG(1, "Allocating new console"); - - fd = open("/dev/tty1", O_WRONLY); - - if (fd < 0) { - GP_DEBUG(1, "Opening console /dev/tty1 failed: %s", - strerror(errno)); - return -1; + if (ioctl(fb->con_fd, KDSKBMODE, fb->saved_kb_mode) < 0) { + GP_DEBUG(1, "Failed to ioctl KDSKBMODE (restore KBMODE)" + " /dev/tty%i: %s", fb->con_nr, + strerror(errno)); }
- if (ioctl(fd, VT_OPENQRY, &nr) < 0) { - GP_DEBUG(1, "Failed to ioctl VT_OPENQRY /dev/tty1: %s", - strerror(errno)); - close(fd); - return -1; + if (fb->restore_termios) { + if (tcsetattr(fb->con_fd, TCSANOW, &fb->ts) < 0) { + GP_WARN("Failed to tcsetattr() (restore termios): %s", + strerror(errno)); + } } +}
- GP_DEBUG(1, "Has been granted tty%i", nr); - - close(fd); - - snprintf(buf, sizeof(buf), "/dev/tty%i", nr); - fd = open(buf, O_RDWR | O_NONBLOCK); - - if (fd < 0) { - GP_DEBUG(1, "Opening console %s failed: %s", - buf, strerror(errno)); - return -1; +/* + * Save console mode and set the mode to raw. + */ +static int init_kbd(struct fb_priv *fb) +{ + struct termios t; + int fd = fb->con_fd; + + if (tcgetattr(fd, &fb->ts)) { + GP_WARN("Failed to tcgetattr(): %s", strerror(errno)); + fb->restore_termios = 0; + } else { + fb->restore_termios = 1; }
- if (ioctl(fd, VT_GETSTATE, &vts) == 0) - fb->last_con_nr = vts.v_active; - else - fb->last_con_nr = -1; + cfmakeraw(&t);
- if (ioctl(fd, VT_ACTIVATE, nr) < 0) { - GP_DEBUG(1, "Failed to ioctl VT_ACTIVATE %s: %s", - buf, strerror(errno)); + if (tcsetattr(fd, TCSANOW, &t) < 0) { + GP_DEBUG(1, "Failed to tcsetattr(): %s", + strerror(errno)); close(fd); return -1; }
- GP_DEBUG(1, "Waiting for tty%i to activate", nr); - - if (ioctl(fd, VT_WAITACTIVE, nr) < 0) { - GP_DEBUG(1, "Failed to ioctl VT_WAITACTIVE %s: %s", - buf, strerror(errno)); + if (ioctl(fd, KDGKBMODE, &fb->saved_kb_mode)) { + GP_DEBUG(1, "Failed to ioctl KDGKBMODE tty%i: %s", + fb->con_nr, strerror(errno)); close(fd); return -1; }
- /* turn off blinking cursor */ - if (ioctl(fd, KDSETMODE, KD_GRAPHICS) < 0) { - GP_DEBUG(1, "Failed to ioctl KDSETMODE %s: %s", - buf, strerror(errno)); + GP_DEBUG(2, "Previous keyboard mode was '%i'", + fb->saved_kb_mode); + + if (ioctl(fd, KDSKBMODE, K_MEDIUMRAW) < 0) { + GP_DEBUG(1, "Failed to ioctl KDSKBMODE tty%i: %s", + fb->con_nr, strerror(errno)); close(fd); return -1; }
- /* set keyboard to raw mode */ - if (flag) { - struct termios t; - cfmakeraw(&t); + return 0; +} + +/* + * Allocates and switches to newly allocated console. + */ +static int allocate_console(struct fb_priv *fb, int flags) +{ + struct vt_stat vts; + int fd, nr = -1; + char buf[255]; + const char *tty = "/dev/tty"; + + if (flags & GP_FB_ALLOC_CON) { + GP_DEBUG(1, "Allocating new console");
- if (tcsetattr(fd, TCSANOW, &t) < 0) { - GP_DEBUG(1, "Failed to tcsetattr(): %s", + fd = open("/dev/tty1", O_WRONLY); + + if (fd < 0) { + GP_DEBUG(1, "Opening console /dev/tty1 failed: %s", strerror(errno)); + return -1; + } + + if (ioctl(fd, VT_OPENQRY, &nr) < 0) { + GP_DEBUG(1, "Failed to ioctl VT_OPENQRY /dev/tty1: %s", + strerror(errno)); close(fd); return -1; }
- if (ioctl(fd, KDGKBMODE, &fb->saved_kb_mode)) { - GP_DEBUG(1, "Failed to ioctl KDGKBMODE %s: %s", - buf, strerror(errno)); + GP_DEBUG(1, "Has been granted tty%i", nr); + + close(fd); + + snprintf(buf, sizeof(buf), "/dev/tty%i", nr); + tty = buf; + } + + fd = open(tty, O_RDWR | O_NONBLOCK); + + if (fd < 0) { + GP_DEBUG(1, "Opening console %s failed: %s", + tty, strerror(errno)); + return -1; + } + + if (ioctl(fd, VT_GETSTATE, &vts) == 0) + fb->last_con_nr = vts.v_active; + else + fb->last_con_nr = -1; + + if (flags & GP_FB_ALLOC_CON) { + if (ioctl(fd, VT_ACTIVATE, nr) < 0) { + GP_DEBUG(1, "Failed to ioctl VT_ACTIVATE %s: %s", + tty, strerror(errno)); close(fd); return -1; }
- GP_DEBUG(2, "Previous keyboard mode was '%i'", - fb->saved_kb_mode); + GP_DEBUG(1, "Waiting for %s to activate", tty);
- if (ioctl(fd, KDSKBMODE, K_MEDIUMRAW) < 0) { - GP_DEBUG(1, "Failed to ioctl KDSKBMODE %s: %s", - buf, strerror(errno)); + if (ioctl(fd, VT_WAITACTIVE, nr) < 0) { + GP_DEBUG(1, "Failed to ioctl VT_WAITACTIVE %s: %s", + tty, strerror(errno)); close(fd); return -1; } @@ -157,6 +191,14 @@ static int allocate_console(struct fb_priv *fb, int flag) fb->con_nr = nr; fb->con_fd = fd;
+ /* turn off blinking cursor */ + if (ioctl(fd, KDSETMODE, KD_GRAPHICS) < 0) { + GP_DEBUG(1, "Failed to ioctl KDSETMODE %s: %s", + tty, strerror(errno)); + close(fd); + return -1; + } + return 0; }
@@ -190,20 +232,20 @@ static void fb_exit(GP_Backend *self) { struct fb_priv *fb = GP_BACKEND_PRIV(self);
+ if (fb->flags & GP_FB_SHADOW) + free(fb->context.pixels); + /* unmap framebuffer */ - munmap(fb->context.pixels, fb->bsize); + munmap(fb->fb_mem, fb->bsize); close(fb->fb_fd);
- /* reset keyboard */ - ioctl(fb->con_fd, KDSETMODE, KD_TEXT); + /* restore blinking cursor */ + if (ioctl(fb->con_fd, KDSETMODE, KD_TEXT)) + GP_WARN("Failed to ioctl KDSETMODE (restore KDMODE)");
/* restore keyboard mode */ - if (fb->flag) { - if (ioctl(fb->con_fd, KDSKBMODE, fb->saved_kb_mode) < 0) { - GP_DEBUG(1, "Failed to ioctl KDSKBMODE (restore KBMODE)" - " /dev/tty%i: %s", fb->con_nr, strerror(errno)); - } - } + if (fb->flags & GP_FB_INPUT_KBD) + exit_kbd(fb);
/* switch back console */ if (fb->last_con_nr != -1) @@ -213,7 +255,34 @@ static void fb_exit(GP_Backend *self) free(self); }
-GP_Backend *GP_BackendLinuxFBInit(const char *path, int flag) +static void fb_flip_shadow(GP_Backend *self) +{ + struct fb_priv *fb = GP_BACKEND_PRIV(self); + + GP_DEBUG(2, "Flipping buffer"); + + memcpy(fb->fb_mem, fb->context.pixels, fb->bsize); +} + +static void fb_update_rect_shadow(GP_Backend *self, GP_Coord x0, GP_Coord y0, + GP_Coord x1, GP_Coord y1) +{ + struct fb_priv *fb = GP_BACKEND_PRIV(self); + + GP_DEBUG(2, "Flipping buffer"); + + size_t size = ((x1 - x0) * fb->context.bpp) / 8; + + for (;y0 <= y1; y0++) { + void *src = GP_PIXEL_ADDR(&fb->context, x0, y0); + void *dst = (char*)fb->fb_mem + + y0 * fb->context.bytes_per_row + + (x0 * fb->context.bpp)/8; + memcpy(dst, src, size); + } +} + +GP_Backend *GP_BackendLinuxFBInit(const char *path, int flags) { GP_Backend *backend; struct fb_priv *fb; @@ -229,9 +298,14 @@ GP_Backend *GP_BackendLinuxFBInit(const char *path, int flag)
fb = GP_BACKEND_PRIV(backend);
- if (allocate_console(fb, flag)) + if (allocate_console(fb, flags & GP_FB_INPUT_KBD)) goto err1;
+ if (flags & GP_FB_INPUT_KBD) { + if (init_kbd(fb)) + goto err1; + } + /* open and mmap framebuffer */ GP_DEBUG(1, "Opening framebuffer '%s'", path);
@@ -261,7 +335,7 @@ GP_Backend *GP_BackendLinuxFBInit(const char *path, int flag) * Framebuffer is grayscale. */ if (vscri.grayscale) { - //TODO + GP_WARN("Grayscale not implemented!"); goto err3; }
@@ -277,19 +351,30 @@ GP_Backend *GP_BackendLinuxFBInit(const char *path, int flag) goto err3; }
- fb->context.pixels = mmap(NULL, fscri.smem_len, - PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, - fd, 0); + if (flags & GP_FB_SHADOW) { + fb->context.pixels = malloc(fscri.smem_len); + + if (!fb->context.pixels) { + GP_DEBUG(1, "Malloc failed :("); + goto err3; + } + } + + fb->fb_mem = mmap(NULL, fscri.smem_len, + PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0);
- if (fb->context.pixels == MAP_FAILED) { + if (fb->fb_mem == MAP_FAILED) { GP_DEBUG(1, "mmaping framebuffer failed: %s", strerror(errno)); - goto err3; + goto err4; }
fb->fb_fd = fd; - fb->bsize = fscri.smem_len; + fb->bsize = fscri.smem_len; strcpy(fb->path, path); - fb->flag = flag; + fb->flags = flags; + + if (!(flags & GP_FB_SHADOW)) + fb->context.pixels = fb->fb_mem;
fb->context.w = vscri.xres; fb->context.h = vscri.yres; @@ -302,22 +387,28 @@ GP_Backend *GP_BackendLinuxFBInit(const char *path, int flag) fb->context.bytes_per_row = fscri.line_length; fb->context.pixel_type = pixel_type;
+ int shadow = flags & GP_FB_SHADOW; + int kbd = flags & GP_FB_INPUT_KBD; + /* update API */ backend->name = "Linux FB"; backend->context = &fb->context; - backend->Flip = NULL; - backend->UpdateRect = NULL; + backend->Flip = shadow ? fb_flip_shadow : NULL; + backend->UpdateRect = shadow ? fb_update_rect_shadow : NULL; backend->Exit = fb_exit; backend->SetAttributes = NULL; backend->ResizeAck = NULL; - backend->Poll = flag ? fb_poll : NULL; - backend->Wait = flag ? fb_wait : NULL; + backend->Poll = kbd ? fb_poll : NULL; + backend->Wait = kbd ? fb_wait : NULL; backend->fd = fb->con_fd; backend->timers = NULL;
GP_EventQueueInit(&backend->event_queue, vscri.xres, vscri.yres, 0);
return backend; +err4: + if (flags & GP_FB_SHADOW) + free(fb->context.pixels); err3: close(fd); err2:
-----------------------------------------------------------------------
Summary of changes: configure | 5 +- demos/c_simple/linetest.c | 25 ++- demos/c_simple/shapetest.c | 20 ++- demos/c_simple/v4l2_show.c | 3 - demos/particle/particle_demo.c | 24 ++- demos/spiv/cpu_timer.c | 13 + demos/spiv/cpu_timer.h | 7 +- demos/spiv/spiv.c | 7 +- demos/spiv/spiv_help.c | 3 + .../version.c => include/backends/GP_AALib.h | 20 +- include/backends/GP_Backends.h | 1 + include/backends/GP_LinuxFB.h | 19 ++- include/core/GP_Common.h | 1 + libs/backends/GP_AALib.c | 280 ++++++++++++++++++++ libs/backends/GP_BackendInit.c | 33 ++- libs/backends/GP_LinuxFB.c | 261 ++++++++++++------ libs/backends/GP_SDL.c | 19 +- libs/filters/GP_ResizeLinear.gen.c.t | 2 - libs/input/GP_InputDriverKBD.c | 14 +- 19 files changed, 630 insertions(+), 127 deletions(-) copy demos/c_simple/version.c => include/backends/GP_AALib.h (88%) create mode 100644 libs/backends/GP_AALib.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.