Gfxprim
Threads by month
- ----- 2026 -----
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
January 2012
- 2 participants
- 41 discussions
[repo.or.cz] gfxprim.git branch master updated: c5d3e2a62fabfd142f86d47f51e313680d363ea3
by metan 21 Jan '12
by metan 21 Jan '12
21 Jan '12
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 c5d3e2a62fabfd142f86d47f51e313680d363ea3 (commit)
from bccb0491d955bfbd1c0cb8d9ca7add8c886c50fe (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/c5d3e2a62fabfd142f86d47f51e313680d36…
commit c5d3e2a62fabfd142f86d47f51e313680d363ea3
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jan 21 21:59:13 2012 +0100
demos: fbshow add more timers.
diff --git a/demos/fbshow/Makefile b/demos/fbshow/Makefile
index 6b04464..74d83fb 100644
--- a/demos/fbshow/Makefile
+++ b/demos/fbshow/Makefile
@@ -9,5 +9,7 @@ LDLIBS+=-lGP -lGP_backends -lSDL -L$(TOPDIR)/build/
APPS=fbshow
+fbshow: cpu_timer.o
+
include $(TOPDIR)/include.mk
include $(TOPDIR)/app.mk
diff --git a/demos/fbshow/cpu_timer.c b/demos/fbshow/cpu_timer.c
new file mode 100644
index 0000000..88455eb
--- /dev/null
+++ b/demos/fbshow/cpu_timer.c
@@ -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(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include <stdio.h>
+#include "cpu_timer.h"
+
+void cpu_timer_start(struct cpu_timer *self, const char *name)
+{
+ self->name = name;
+ clock_gettime(CLOCK_THREAD_CPUTIME_ID, &self->t_start);
+}
+
+void cpu_timer_stop(struct cpu_timer *self)
+{
+ clock_gettime(CLOCK_THREAD_CPUTIME_ID, &self->t_stop);
+
+ int sec;
+ int nsec;
+
+ if (self->t_stop.tv_nsec < self->t_start.tv_nsec) {
+ sec = self->t_stop.tv_sec - self->t_start.tv_sec - 1;
+ nsec = self->t_stop.tv_nsec + 1000000000 - self->t_start.tv_nsec;
+ } else {
+ sec = self->t_stop.tv_sec - self->t_start.tv_sec;
+ nsec = self->t_stop.tv_nsec - self->t_start.tv_nsec;
+ }
+
+ printf("TIMER '%s' %i.%09i secn", self->name, sec, nsec);
+}
diff --git a/demos/fbshow/cpu_timer.h b/demos/fbshow/cpu_timer.h
new file mode 100644
index 0000000..1b41144
--- /dev/null
+++ b/demos/fbshow/cpu_timer.h
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * 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(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+ /*
+
+ Simple timers to count cpu time.
+
+ */
+
+#ifndef __CPU_TIMER_H__
+#define __CPU_TIMER_H__
+
+#include <time.h>
+
+struct cpu_timer {
+ struct timespec t_start;
+ struct timespec t_stop;
+ const char *name;
+};
+
+/*
+ * Inialize cpu timer.
+ */
+void cpu_timer_start(struct cpu_timer *self, const char *name);
+
+/*
+ * Stops cpu timer and prints result.
+ */
+void cpu_timer_stop(struct cpu_timer *self);
+
+#endif /* __CPU_TIMER_H__ */
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index f7ab61f..4d9f6bc 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -35,6 +35,8 @@
#include <backends/GP_Backends.h>
#include <input/GP_InputDriverLinux.h>
+#include "cpu_timer.h"
+
static GP_Pixel black_pixel;
static GP_Pixel white_pixel;
@@ -106,40 +108,14 @@ static const char *img_name(const char *img_path)
return NULL;
}
-#include <time.h>
-
-static struct timespec t_start;
-static struct timespec t_stop;
-static const char *t_name;
-
-static void timer_start(const char *name)
-{
- t_name = name;
- clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t_start);
-}
-
-static void timer_stop(void)
-{
- clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t_stop);
-
- int sec;
- int nsec;
-
- if (t_stop.tv_nsec < t_start.tv_nsec) {
- sec = t_stop.tv_sec - t_start.tv_sec - 1;
- nsec = t_stop.tv_nsec + 1000000000 - t_start.tv_nsec;
- } else {
- sec = t_stop.tv_sec - t_start.tv_sec;
- nsec = t_stop.tv_nsec - t_start.tv_nsec;
- }
-
- printf("TIMER '%s' %i.%09i secn", t_name, sec, nsec);
-}
-
static void *image_loader(void *ptr)
{
struct loader_params *params = ptr;
GP_ProgressCallback callback = {.callback = image_loader_callback};
+ struct cpu_timer timer;
+ struct cpu_timer sum_timer;
+
+ cpu_timer_start(&sum_timer, "sum");
show_progress = params->show_progress || params->show_progress_once;
params->show_progress_once = 0;
@@ -149,7 +125,8 @@ static void *image_loader(void *ptr)
GP_Context *img = NULL;
callback.priv = "Loading image";
-
+
+ cpu_timer_start(&timer, "Loading");
if (GP_LoadImage(params->img_path, &img, &callback) != 0) {
GP_Fill(context, black_pixel);
GP_Text(context, NULL, context->w/2, context->h/2,
@@ -157,7 +134,8 @@ static void *image_loader(void *ptr)
"Failed to load image :(");
return NULL;
}
-
+ cpu_timer_stop(&timer);
+
GP_Size w, h;
switch (rotate) {
@@ -189,16 +167,18 @@ static void *image_loader(void *ptr)
GP_Context *ret;
if (rat < 1) {
- timer_start("blur");
+ cpu_timer_start(&timer, "Blur");
callback.priv = "Blurring Image";
if (GP_FilterGaussianBlur(img, img, 0.5/rat, 0.5/rat, &callback) == NULL)
return NULL;
- timer_stop();
+ cpu_timer_stop(&timer);
}
+ cpu_timer_start(&timer, "Resampling");
callback.priv = "Resampling Image";
ret = GP_FilterResize(img, NULL, GP_INTERP_CUBIC_INT, img->w * rat, img->h * rat, &callback);
GP_ContextFree(img);
+ cpu_timer_stop(&timer);
if (ret == NULL)
return NULL;
@@ -240,6 +220,8 @@ static void *image_loader(void *ptr)
GP_FillRectXYWH(context, ret->w+cx, 0, cx, context->h, black_pixel);
GP_FillRectXYWH(context, 0, ret->h+cy, context->w, cy, black_pixel);
+ cpu_timer_stop(&sum_timer);
+
if (!params->show_info) {
GP_BackendFlip(backend);
return NULL;
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/Makefile | 2 +
.../GP_Backends.h => demos/fbshow/cpu_timer.c | 37 ++++++++------
.../GP_Backends.h => demos/fbshow/cpu_timer.h | 29 +++++++----
demos/fbshow/fbshow.c | 50 ++++++-------------
4 files changed, 57 insertions(+), 61 deletions(-)
copy include/backends/GP_Backends.h => demos/fbshow/cpu_timer.c (71%)
copy include/backends/GP_Backends.h => demos/fbshow/cpu_timer.h (80%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: bccb0491d955bfbd1c0cb8d9ca7add8c886c50fe
by metan 21 Jan '12
by metan 21 Jan '12
21 Jan '12
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 bccb0491d955bfbd1c0cb8d9ca7add8c886c50fe (commit)
via 6f7a48cf329d250dea4f2c4a34cf9f0e84c78c39 (commit)
via 76102f7788b5e16a479e7b3543dbac60b60eae0b (commit)
via b369dc80bc0313dd846091ab433f265af1b2b081 (commit)
from 2f32bbb6ab45e8648e9f1023b1ed7ca167f1a4a1 (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/bccb0491d955bfbd1c0cb8d9ca7add8c886c…
commit bccb0491d955bfbd1c0cb8d9ca7add8c886c50fe
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jan 21 21:39:59 2012 +0100
filters: blur fix includes.
diff --git a/libs/filters/GP_Linear.c b/libs/filters/GP_Linear.c
index 2d2970d..06145f6 100644
--- a/libs/filters/GP_Linear.c
+++ b/libs/filters/GP_Linear.c
@@ -22,10 +22,10 @@
#include <math.h>
-#include <GP_Context.h>
-#include <GP_GetPutPixel.h>
+#include <core/GP_Context.h>
+#include <core/GP_GetPutPixel.h>
-#include <GP_Debug.h>
+#include <core/GP_Debug.h>
#include <GP_Linear.h>
http://repo.or.cz/w/gfxprim.git/commit/6f7a48cf329d250dea4f2c4a34cf9f0e84c7…
commit 6f7a48cf329d250dea4f2c4a34cf9f0e84c78c39
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jan 21 21:15:01 2012 +0100
demos: fbshow do low pass filter only when rat < 1
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index 6c38216..f7ab61f 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -188,11 +188,13 @@ static void *image_loader(void *ptr)
GP_Context *ret;
- timer_start("blur");
- callback.priv = "Blurring Image";
- if (GP_FilterGaussianBlur(img, img, 0.5/rat, 0.5/rat, &callback) == NULL)
- return NULL;
- timer_stop();
+ if (rat < 1) {
+ timer_start("blur");
+ callback.priv = "Blurring Image";
+ if (GP_FilterGaussianBlur(img, img, 0.5/rat, 0.5/rat, &callback) == NULL)
+ return NULL;
+ timer_stop();
+ }
callback.priv = "Resampling Image";
ret = GP_FilterResize(img, NULL, GP_INTERP_CUBIC_INT, img->w * rat, img->h * rat, &callback);
http://repo.or.cz/w/gfxprim.git/commit/76102f7788b5e16a479e7b3543dbac60b60e…
commit 76102f7788b5e16a479e7b3543dbac60b60eae0b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jan 21 20:11:29 2012 +0100
demos: fbshow implement thread time counter.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index c7363fd..6c38216 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -106,6 +106,36 @@ static const char *img_name(const char *img_path)
return NULL;
}
+#include <time.h>
+
+static struct timespec t_start;
+static struct timespec t_stop;
+static const char *t_name;
+
+static void timer_start(const char *name)
+{
+ t_name = name;
+ clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t_start);
+}
+
+static void timer_stop(void)
+{
+ clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t_stop);
+
+ int sec;
+ int nsec;
+
+ if (t_stop.tv_nsec < t_start.tv_nsec) {
+ sec = t_stop.tv_sec - t_start.tv_sec - 1;
+ nsec = t_stop.tv_nsec + 1000000000 - t_start.tv_nsec;
+ } else {
+ sec = t_stop.tv_sec - t_start.tv_sec;
+ nsec = t_stop.tv_nsec - t_start.tv_nsec;
+ }
+
+ printf("TIMER '%s' %i.%09i secn", t_name, sec, nsec);
+}
+
static void *image_loader(void *ptr)
{
struct loader_params *params = ptr;
@@ -158,10 +188,12 @@ static void *image_loader(void *ptr)
GP_Context *ret;
+ timer_start("blur");
callback.priv = "Blurring Image";
if (GP_FilterGaussianBlur(img, img, 0.5/rat, 0.5/rat, &callback) == NULL)
return NULL;
-
+ timer_stop();
+
callback.priv = "Resampling Image";
ret = GP_FilterResize(img, NULL, GP_INTERP_CUBIC_INT, img->w * rat, img->h * rat, &callback);
GP_ContextFree(img);
http://repo.or.cz/w/gfxprim.git/commit/b369dc80bc0313dd846091ab433f265af1b2…
commit b369dc80bc0313dd846091ab433f265af1b2b081
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jan 21 19:32:05 2012 +0100
filters: Speed up the blur filter.
diff --git a/libs/filters/GP_Linear.c b/libs/filters/GP_Linear.c
index da15f11..2d2970d 100644
--- a/libs/filters/GP_Linear.c
+++ b/libs/filters/GP_Linear.c
@@ -144,6 +144,7 @@ int GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
float kernel_sum = 0;
GP_Coord x, y;
uint32_t i;
+ GP_Pixel pix;
GP_DEBUG(1, "Horizontal linear convolution kernel width %i image %ux%u",
kw, src->w, src->h);
@@ -154,7 +155,6 @@ int GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
/* do linear convolution */
for (y = 0; y < (GP_Coord)dst->h; y++) {
- GP_Pixel pix;
uint32_t R[kw], G[kw], B[kw];
/* prefill the buffer on the start */
@@ -346,6 +346,13 @@ int GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
#define MUL 1024
+#define CLAMP(val) do { + if (val > 255) + val = 255; + if (val < 0) + val = 0; +} while (0)
+
int GP_FilterHLinearConvolutionInt_Raw(const GP_Context *src, GP_Context *dst,
float kernel[], uint32_t kw,
GP_ProgressCallback *callback)
@@ -353,8 +360,9 @@ int GP_FilterHLinearConvolutionInt_Raw(const GP_Context *src, GP_Context *dst,
int32_t kernel_sum = 0;
GP_Coord x, y;
uint32_t i;
- int ikernel[kw];
-
+ int32_t ikernel[kw];
+ uint32_t size = dst->w + kw;
+
for (i = 0; i < kw; i++)
ikernel[i] = kernel[i] * MUL + 0.5;
@@ -367,16 +375,19 @@ int GP_FilterHLinearConvolutionInt_Raw(const GP_Context *src, GP_Context *dst,
/* do linear convolution */
for (y = 0; y < (GP_Coord)dst->h; y++) {
- GP_Pixel pix;
- uint32_t R[kw], G[kw], B[kw];
+ uint8_t R[size], G[size], B[size];
- /* prefill the buffer on the start */
- for (i = 0; i < kw - 1; i++) {
+ /* Fetch the whole row */
+ for (i = 0; i < size; i++) {
+ GP_Pixel pix;
int cx = i - kw/2;
if (cx < 0)
cx = 0;
-
+
+ if (cx >= (int)src->w)
+ cx = src->w - 1;
+
pix = GP_GetPixel_Raw_24BPP(src, cx, y);
R[i] = GP_Pixel_GET_R_RGB888(pix);
@@ -384,63 +395,28 @@ int GP_FilterHLinearConvolutionInt_Raw(const GP_Context *src, GP_Context *dst,
B[i] = GP_Pixel_GET_B_RGB888(pix);
}
- int idx = kw - 1;
-
for (x = 0; x < (GP_Coord)dst->w; x++) {
- float r = 0, g = 0, b = 0;
-
- int cx = x + kw/2;
-
- if (cx >= (int)src->w)
- cx = src->w - 1;
-
- pix = GP_GetPixel_Raw_24BPP(src, cx, y);
+ int32_t r = 0, g = 0, b = 0;
- R[idx] = GP_Pixel_GET_R_RGB888(pix);
- G[idx] = GP_Pixel_GET_G_RGB888(pix);
- B[idx] = GP_Pixel_GET_B_RGB888(pix);
-
/* count the pixel value from neighbours weighted by kernel */
for (i = 0; i < kw; i++) {
- int k;
-
- if ((int)i < idx + 1)
- k = kw - idx - 1 + i;
- else
- k = i - idx - 1;
-
- r += R[i] * ikernel[k];
- g += G[i] * ikernel[k];
- b += B[i] * ikernel[k];
+ r += R[i + x] * ikernel[i];
+ g += G[i + x] * ikernel[i];
+ b += B[i + x] * ikernel[i];
}
-
+
/* normalize the result */
- r /= kernel_sum;
- g /= kernel_sum;
- b /= kernel_sum;
+ r = (r + MUL/2) / kernel_sum;
+ g = (g + MUL/2) / kernel_sum;
+ b = (b + MUL/2) / kernel_sum;
/* and clamp just to be extra sure */
- if (r > 255)
- r = 255;
- if (r < 0)
- r = 0;
- if (g > 255)
- g = 255;
- if (g < 0)
- g = 0;
- if (b > 255)
- b = 255;
- if (b < 0)
- b = 0;
+ CLAMP(r);
+ CLAMP(g);
+ CLAMP(b);
- pix = GP_Pixel_CREATE_RGB888((uint32_t)r, (uint32_t)g, (uint32_t)b);
-
- GP_PutPixel_Raw_24BPP(dst, x, y, pix);
-
- idx++;
-
- if (idx >= (int)kw)
- idx = 0;
+ GP_PutPixel_Raw_24BPP(dst, x, y,
+ GP_Pixel_CREATE_RGB888(r, g, b));
}
if (GP_ProgressCallbackReport(callback, y, dst->h, dst->w))
@@ -459,6 +435,7 @@ int GP_FilterVLinearConvolutionInt_Raw(const GP_Context *src, GP_Context *dst,
GP_Coord x, y;
uint32_t i;
int32_t ikernel[kh];
+ uint32_t size = dst->h + kh;
for (i = 0; i < kh; i++)
ikernel[i] = kernel[i] * MUL + 0.5;
@@ -472,16 +449,20 @@ int GP_FilterVLinearConvolutionInt_Raw(const GP_Context *src, GP_Context *dst,
/* do linear convolution */
for (x = 0; x < (GP_Coord)dst->w; x++) {
- GP_Pixel pix;
- uint32_t R[kh], G[kh], B[kh];
+ uint8_t R[size], G[size], B[size];
- /* prefill the buffer on the start */
- for (i = 0; i < kh - 1; i++) {
+ /* Fetch the whole column */
+ for (i = 0; i < size; i++) {
+ GP_Pixel pix;
+
int cy = i - kh/2;
if (cy < 0)
cy = 0;
+ if (cy >= (int)src->h)
+ cy = src->h - 1;
+
pix = GP_GetPixel_Raw_24BPP(src, x, cy);
R[i] = GP_Pixel_GET_R_RGB888(pix);
@@ -489,63 +470,28 @@ int GP_FilterVLinearConvolutionInt_Raw(const GP_Context *src, GP_Context *dst,
B[i] = GP_Pixel_GET_B_RGB888(pix);
}
- int idx = kh - 1;
-
for (y = 0; y < (GP_Coord)dst->h; y++) {
int32_t r = 0, g = 0, b = 0;
-
- int cy = y + kh/2;
-
- if (cy >= (int)src->h)
- cy = src->h - 1;
-
- pix = GP_GetPixel_Raw_24BPP(src, x, cy);
-
- R[idx] = GP_Pixel_GET_R_RGB888(pix);
- G[idx] = GP_Pixel_GET_G_RGB888(pix);
- B[idx] = GP_Pixel_GET_B_RGB888(pix);
/* count the pixel value from neighbours weighted by kernel */
for (i = 0; i < kh; i++) {
- int k;
-
- if ((int)i < idx + 1)
- k = kh - idx - 1 + i;
- else
- k = i - idx - 1;
-
- r += R[i] * ikernel[k];
- g += G[i] * ikernel[k];
- b += B[i] * ikernel[k];
+ r += R[y + i] * ikernel[i];
+ g += G[y + i] * ikernel[i];
+ b += B[y + i] * ikernel[i];
}
/* normalize the result */
- r /= kernel_sum;
- g /= kernel_sum;
- b /= kernel_sum;
+ r = (r + MUL/2) / kernel_sum;
+ g = (g + MUL/2) / kernel_sum;
+ b = (b + MUL/2) / kernel_sum;
/* and clamp just to be extra sure */
- if (r > 255)
- r = 255;
- if (r < 0)
- r = 0;
- if (g > 255)
- g = 255;
- if (g < 0)
- g = 0;
- if (b > 255)
- b = 255;
- if (b < 0)
- b = 0;
-
- pix = GP_Pixel_CREATE_RGB888((uint32_t)r, (uint32_t)g, (uint32_t)b);
+ CLAMP(r);
+ CLAMP(g);
+ CLAMP(b);
- GP_PutPixel_Raw_24BPP(dst, x, y, pix);
-
- idx++;
-
- if (idx >= (int)kh)
- idx = 0;
+ GP_PutPixel_Raw_24BPP(dst, x, y,
+ GP_Pixel_CREATE_RGB888(r, g, b));
}
if (GP_ProgressCallbackReport(callback, x, dst->w, dst->h))
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/fbshow.c | 42 +++++++++++-
libs/filters/GP_Linear.c | 164 +++++++++++++++------------------------------
2 files changed, 93 insertions(+), 113 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 2f32bbb6ab45e8648e9f1023b1ed7ca167f1a4a1
by metan 21 Jan '12
by metan 21 Jan '12
21 Jan '12
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 2f32bbb6ab45e8648e9f1023b1ed7ca167f1a4a1 (commit)
from ea35af9019e34da61945dd72615c57d3e303a743 (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/2f32bbb6ab45e8648e9f1023b1ed7ca167f1…
commit 2f32bbb6ab45e8648e9f1023b1ed7ca167f1a4a1
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jan 21 17:50:30 2012 +0100
input: Fix ascii mapping table.
diff --git a/libs/input/GP_Event.c b/libs/input/GP_Event.c
index 022e744..01afef2 100644
--- a/libs/input/GP_Event.c
+++ b/libs/input/GP_Event.c
@@ -266,7 +266,7 @@ void GP_EventPushAbs(uint32_t x, uint32_t y, uint32_t pressure,
static char keys_to_ascii[] = {
0x00, 0x1b, '1', '2', '3', '4', '5', '6', '7', '8',
'9', '0', '-', '=', 0x08, 't', 'q', 'w', 'e', 'r',
- 't', 'y', 'u', 'i', 'o', 'p', '(', ')', 'n', 0x00,
+ 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 'n', 0x00,
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
''', '`', 0x00, '\', 'z', 'x', 'c', 'v', 'b', 'n',
'm', ',', '.', '/', 0x00, '*', 0x00, ' ', 0x00, 0x00,
@@ -278,7 +278,7 @@ static char keys_to_ascii[] = {
static char keys_to_ascii_s[] = {
0x00, 0x1b, '!', '@', '#', '$', '%', '^', '&', '*',
'(', ')', '_', '+', 0x08, 't', 'Q', 'W', 'E', 'R',
- 'T', 'Y', 'U', 'I', 'O', 'P', '(', ')', 'n', 0x00,
+ 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 'n', 0x00,
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':',
'"', '~', 0x00, '|', 'Z', 'X', 'C', 'V', 'B', 'N',
'M', '<', '>', '?', 0x00, '*', 0x00, ' ', 0x00, 0x00,
-----------------------------------------------------------------------
Summary of changes:
libs/input/GP_Event.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: ea35af9019e34da61945dd72615c57d3e303a743
by metan 21 Jan '12
by metan 21 Jan '12
21 Jan '12
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 ea35af9019e34da61945dd72615c57d3e303a743 (commit)
via 0f58139e80e4a6da1385034144d9f67e146ff6b8 (commit)
from 36f12d07e7626a423264eca355c4000fc392dbf6 (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/ea35af9019e34da61945dd72615c57d3e303…
commit ea35af9019e34da61945dd72615c57d3e303a743
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jan 21 17:42:13 2012 +0100
input: Add rough key even ascii conversion.
diff --git a/libs/input/GP_Event.c b/libs/input/GP_Event.c
index 129f1ee..022e744 100644
--- a/libs/input/GP_Event.c
+++ b/libs/input/GP_Event.c
@@ -263,6 +263,47 @@ void GP_EventPushAbs(uint32_t x, uint32_t y, uint32_t pressure,
event_put(&cur_state);
}
+static char keys_to_ascii[] = {
+ 0x00, 0x1b, '1', '2', '3', '4', '5', '6', '7', '8',
+ '9', '0', '-', '=', 0x08, 't', 'q', 'w', 'e', 'r',
+ 't', 'y', 'u', 'i', 'o', 'p', '(', ')', 'n', 0x00,
+ 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
+ ''', '`', 0x00, '\', 'z', 'x', 'c', 'v', 'b', 'n',
+ 'm', ',', '.', '/', 0x00, '*', 0x00, ' ', 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, '7', '8', '9', '-', '4', '5', '6', '+', '1',
+ '2', '3', '0', '.'
+};
+
+static char keys_to_ascii_s[] = {
+ 0x00, 0x1b, '!', '@', '#', '$', '%', '^', '&', '*',
+ '(', ')', '_', '+', 0x08, 't', 'Q', 'W', 'E', 'R',
+ 'T', 'Y', 'U', 'I', 'O', 'P', '(', ')', 'n', 0x00,
+ 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':',
+ '"', '~', 0x00, '|', 'Z', 'X', 'C', 'V', 'B', 'N',
+ 'M', '<', '>', '?', 0x00, '*', 0x00, ' ', 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, '7', '8', '9', '-', '4', '5', '6', '+', '1',
+ '2', '3', '0', '.'
+};
+
+/*
+ * Fills key ascii value accordingly to keys pressed.
+ */
+static void key_to_ascii(GP_Event *ev)
+{
+ ev->val.key.ascii = 0;
+
+ if (GP_EventGetKey(ev, GP_KEY_LEFT_SHIFT) ||
+ GP_EventGetKey(ev, GP_KEY_RIGHT_SHIFT)) {
+ if (ev->val.key.key < sizeof(keys_to_ascii_s))
+ ev->val.key.ascii = keys_to_ascii_s[ev->val.key.key];
+ } else {
+ if (ev->val.key.key < sizeof(keys_to_ascii))
+ ev->val.key.ascii = keys_to_ascii[ev->val.key.key];
+ }
+}
+
void GP_EventPushKey(uint32_t key, uint8_t code, struct timeval *time)
{
switch (code) {
@@ -283,7 +324,7 @@ void GP_EventPushKey(uint32_t key, uint8_t code, struct timeval *time)
cur_state.type = GP_EV_KEY;
cur_state.code = code;
cur_state.val.key.key = key;
- //TODO cur_state.val.key.ascii
+ key_to_ascii(&cur_state);
set_time(time);
http://repo.or.cz/w/gfxprim.git/commit/0f58139e80e4a6da1385034144d9f67e146f…
commit 0f58139e80e4a6da1385034144d9f67e146ff6b8
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jan 17 19:40:13 2012 +0100
text: Fix glyph metric computation.
Fix GP_TextWidth() count correctly for
the first and last letter in the string.
+ Far more fixes and edhancements.
diff --git a/include/text/GP_Font.h b/include/text/GP_Font.h
index 0bce212..3612873 100644
--- a/include/text/GP_Font.h
+++ b/include/text/GP_Font.h
@@ -173,6 +173,21 @@ static inline unsigned int GP_FontMaxWidth(const GP_FontFace *font)
return font->max_glyph_width;
}
+static inline unsigned int GP_FontMaxAdvanceX(const GP_FontFace *font)
+{
+ return font->max_glyph_advance;
+}
+
+static inline const char *GP_FontFamily(const GP_FontFace *font)
+{
+ return font->family_name;
+}
+
+static inline const char *GP_FontStyle(const GP_FontFace *font)
+{
+ return font->style_name;
+}
+
/*
* Returns glyph count for charset.
*/
diff --git a/libs/text/GP_DefaultFont.c b/libs/text/GP_DefaultFont.c
index d2faa49..52b6608 100644
--- a/libs/text/GP_DefaultFont.c
+++ b/libs/text/GP_DefaultFont.c
@@ -219,8 +219,8 @@ static int8_t default_console_glyphs[] = {
};
struct GP_FontFace GP_DefaultConsoleFont = {
- .family_name = "gfxprim",
- .style_name = "mono",
+ .family_name = "Gfxprim",
+ .style_name = "Mono",
.charset = GP_CHARSET_7BIT,
.ascend = 9,
.descend = 2,
@@ -425,8 +425,8 @@ static uint8_t default_proportional_glyphs[] = {
};
struct GP_FontFace GP_DefaultProportionalFont = {
- .family_name = "gfxprim",
- .style_name = "proportional",
+ .family_name = "Gfxprim",
+ .style_name = "Proportional",
.charset = GP_CHARSET_7BIT,
.ascend = 9,
.descend = 2,
diff --git a/libs/text/GP_TextMetric.c b/libs/text/GP_TextMetric.c
index 737d61d..45371fe 100644
--- a/libs/text/GP_TextMetric.c
+++ b/libs/text/GP_TextMetric.c
@@ -38,84 +38,96 @@ static const GP_GlyphBitmap *get_glyph(const GP_TextStyle *style, int c)
return glyph;
}
-static unsigned int get_pixel_multiplier(const GP_TextStyle *style)
+static unsigned int multiply_width(const GP_TextStyle *style, unsigned int w)
{
- return style->pixel_xmul + style->pixel_xspace;
+ return w * style->pixel_xmul + (w - 1) * style->pixel_xspace;
}
/*
- * Returns glyph width from the basepoint to the end of the glyph bitmap.
+ * Returns glyph advance.
*/
-static unsigned int glyph_width(const GP_TextStyle *style, int c)
+static unsigned int glyph_advance_x(const GP_TextStyle *style, int ch)
{
- unsigned int pixel_multiplier = get_pixel_multiplier(style);
- const GP_GlyphBitmap *glyph = get_glyph(style, c);
+ const GP_GlyphBitmap *glyph = get_glyph(style, ch);
- return (glyph->width + glyph->bearing_x) * pixel_multiplier;
+ return multiply_width(style, glyph->advance_x);
}
/*
- * Returns size of the glyph but doesn't count bearing.
- *
- * Note that the bearing may be negative (typical case is letter 'j' or most of
- * the italic glyphs). So in order not to draw out of the text bouding box,
- * first glyph ignores bearing_x and draws beginning of the glyph bitmap on the
- * starting basepoint.
- *
+ * Return maximal glyph advance for a character from str.
*/
-static unsigned int first_glyph_width(const GP_TextStyle *style, int c)
+static unsigned int max_glyph_advance_x(const GP_TextStyle *style,
+ const char *str)
{
- unsigned int pixel_multiplier = get_pixel_multiplier(style);
- const GP_GlyphBitmap *glyph = get_glyph(style, c);
+ unsigned int max = 0, i;
- return glyph->width * pixel_multiplier;
+ for (i = 0; str[i] != '0'; i++)
+ max = GP_MAX(max, glyph_advance_x(style, str[i]));
+
+ return max;
}
/*
- * Returns space that is added after the glyph.
- *
- * Eg. the advance minus glyph width.
- *
- * TODO: kerning
+ * Returns _SINGLE_ glyph size, not including the bearing_x and including space
+ * occupied by the glyph bitmap if the bitmap width overflows glyph advance_x.
*/
-static unsigned int glyph_space(const GP_TextStyle *style, char ch)
+static unsigned int glyph_width(const GP_TextStyle *style, int c)
{
- unsigned int pixel_multiplier = get_pixel_multiplier(style);
- const GP_GlyphBitmap *glyph = get_glyph(style, ch);
+ unsigned int size, advance;
- return (glyph->advance_x - glyph->width - glyph->bearing_x)
- * pixel_multiplier + style->char_xspace;
+ const GP_GlyphBitmap *glyph = get_glyph(style, c);
+
+ advance = multiply_width(style, glyph->advance_x - glyph->bearing_x);
+ size = multiply_width(style, glyph->width);
+
+ return (size > advance) ? size : advance;
}
/*
- * Returns maximal character width for a given string.
+ * Returns size occupied by the last glyph. Here we take advance_x into account.
*/
-static unsigned int max_glyph_width(const GP_TextStyle *style, const char *str)
+static unsigned int last_glyph_width(const GP_TextStyle *style, int c)
{
- unsigned int max = 0, i;
-
- for (i = 0; str[i] != '0'; i++)
- max = GP_MAX(max, glyph_width(style, str[i]));
+ unsigned int size, advance;
+
+ const GP_GlyphBitmap *glyph = get_glyph(style, c);
+
+ advance = multiply_width(style, glyph->advance_x);
+ size = multiply_width(style, glyph->width + glyph->bearing_x);
- return max;
+ return (size > advance) ? size : advance;
}
/*
- * Return maximal character space after an glyph.
+ * Returns first glyph width, that is and advance minus the bearing_x.
*/
-static unsigned int max_glyph_space(const GP_TextStyle *style, const char *str)
+static unsigned int first_glyph_width(const GP_TextStyle *style, int c)
{
- unsigned int max = 0, i;
-
- for (i = 0; str[i] != '0'; i++)
- max = GP_MAX(max, glyph_space(style, str[i]));
+ const GP_GlyphBitmap *glyph = get_glyph(style, c);
- return max;
+ return multiply_width(style, glyph->advance_x - glyph->bearing_x);
}
+/*
+ * Returns text width.
+ *
+ * There are two problems with text width it's start and it's end.
+ *
+ * At the start the first letter may have bearing_x negative, making it
+ * overflow out of the bouding box and even in case it's possitive the returned
+ * size would be slightly bigger. This one is easy to fix.
+ *
+ * The end of the string is problematic too, some of the glyphs may have
+ * advance smaller than sum of the bitmap width and bearing_x that way we would
+ * return slightly less than is the actuall size of the text bouding box. The
+ * other problem is that the advance is usually grater than the glyph space (as
+ * the exact size of the glyph itself without advance before and space after is
+ * not known), so we likely return some more pixels than is needed, but that's
+ * the joy of life.
+ */
unsigned int GP_TextWidth(const GP_TextStyle *style, const char *str)
{
- unsigned int i, len = 0;
+ unsigned int i, len;
if (style == NULL)
style = &GP_DefaultStyle;
@@ -123,93 +135,85 @@ unsigned int GP_TextWidth(const GP_TextStyle *style, const char *str)
if (str == NULL || str[0] == '0')
return 0;
- len += first_glyph_width(style, str[0]);
-
- if (str[1] == '0')
- return len;
-
- len += glyph_space(style, str[0]);
+ /* special case, one letter */
+ if (str[1] == '0') {
+ return glyph_width(style, str[0]);
+ }
- for (i = 1; str[i] != '0'; i++) {
- len += glyph_width(style, str[i]);
+ /* first letter */
+ len = first_glyph_width(style, str[0]) + style->char_xspace;
+
+ /* middle letters */
+ for (i = 1; str[i+1] != '0'; i++)
+ len += glyph_advance_x(style, str[i]) + style->char_xspace;
- if (str[i+1] != '0')
- len += glyph_space(style, str[i]);
- }
+ /* last letter */
+ len += last_glyph_width(style, str[i]);
return len;
}
+/*
+ * Return max advance now. We will do something better maybe.
+ */
GP_Size GP_TextMaxWidth(const GP_TextStyle *style, unsigned int len)
{
- unsigned int glyph_width;
- //TODO: !
- unsigned int space_width = style->char_xspace;
-
if (style == NULL)
style = &GP_DefaultStyle;
- glyph_width = style->font->max_glyph_width
- * (style->pixel_xmul + style->pixel_xspace);
-
if (len == 0)
return 0;
- return len * glyph_width + (len - 1) * space_width;
+ return multiply_width(style, len * style->font->max_glyph_advance) +
+ (len - 1) * style->char_xspace;
}
+/*
+ * Here too.
+ */
GP_Size GP_TextMaxStrWidth(const GP_TextStyle *style, const char *str,
unsigned int len)
{
- unsigned int space_width;
- unsigned int glyph_width;
-
if (style == NULL)
style = &GP_DefaultStyle;
- space_width = max_glyph_space(style, str);
-
if (len == 0 || str == NULL)
return 0;
- glyph_width = max_glyph_width(style, str);
+ return len * max_glyph_advance_x(style, str) +
+ (len - 1) * style->char_xspace;
+}
+
+/* Ascend, Descend, Height -- far easier */
- return len * glyph_width + (len - 1) * space_width;
+static unsigned int multiply_height(const GP_TextStyle *style, unsigned int h)
+{
+ return h * style->pixel_ymul + (h - 1) * style->pixel_yspace;
}
GP_Size GP_TextHeight(const GP_TextStyle *style)
{
- unsigned int h;
-
if (style == NULL)
style = &GP_DefaultStyle;
+
+ unsigned int height = style->font->ascend + style->font->descend;
- h = style->font->ascend + style->font->descend;
-
- return h * style->pixel_ymul +
- (h - 1) * style->pixel_yspace;
+ return multiply_height(style, height);
}
GP_Size GP_TextAscent(const GP_TextStyle *style)
{
- unsigned int h;
-
if (style == NULL)
style = &GP_DefaultStyle;
- h = style->font->ascend;
- return h * style->pixel_ymul + (h - 1) * style->pixel_yspace;
+ return multiply_height(style, style->font->ascend);
}
GP_Size GP_TextDescent(const GP_TextStyle *style)
{
- unsigned int h;
-
if (style == NULL)
style = &GP_DefaultStyle;
- h = style->font->descend;
-
- return h * style->pixel_ymul + (h - 1) * style->pixel_yspace;
+ return multiply_height(style, style->font->descend);
}
diff --git a/tests/SDL/fonttest.c b/tests/SDL/fonttest.c
index ec9f93a..2fdf194 100644
--- a/tests/SDL/fonttest.c
+++ b/tests/SDL/fonttest.c
@@ -83,9 +83,12 @@ static void print_character_metadata(const GP_FontFace *font, int c)
static void print_font_properties(const GP_FontFace *font)
{
- fprintf(stderr, "Font properties:n");
+ fprintf(stderr, "Font '%s %s' properties:n",
+ GP_FontFamily(font), GP_FontStyle(font));
fprintf(stderr, " Height: ascend: %d, descend: %dn",
GP_FontAscend(font), GP_FontDescend(font));
+ fprintf(stderr, " Max advance_x: %un",
+ GP_FontMaxAdvanceX(font));
fprintf(stderr, " Glyph bitmap format: %sn",
glyph_bitmap_format_name(font->glyph_bitmap_format));
fprintf(stderr, " Bounding box width: %d, heigth: %dn",
@@ -155,9 +158,13 @@ void redraw_screen(void)
style.pixel_ymul = 2;
style.pixel_yspace = 1;
- GP_Text(&context, &style, 34, SPACING*i + 44, align,
+ GP_Text(&context, &style, 34, SPACING * i + 44, align,
white_pixel, black_pixel, test_string);
+ GP_RectXYWH(&context, 33, SPACING * i + 43,
+ GP_TextWidth(&style, test_string) + 1,
+ GP_TextHeight(&style) + 1, dark_gray_pixel);
+
style.pixel_xmul = 4;
style.pixel_ymul = 2;
style.pixel_xspace = 1;
-----------------------------------------------------------------------
Summary of changes:
include/text/GP_Font.h | 15 ++++
libs/input/GP_Event.c | 43 +++++++++++-
libs/text/GP_DefaultFont.c | 8 +-
libs/text/GP_TextMetric.c | 172 ++++++++++++++++++++++---------------------
tests/SDL/fonttest.c | 11 +++-
5 files changed, 158 insertions(+), 91 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 36f12d07e7626a423264eca355c4000fc392dbf6
by metan 17 Jan '12
by metan 17 Jan '12
17 Jan '12
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
discards 7bc428fa520fa1091b43319121322378951a347d (commit)
via 36f12d07e7626a423264eca355c4000fc392dbf6 (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (7bc428fa520fa1091b43319121322378951a347d)
N -- N -- N (36f12d07e7626a423264eca355c4000fc392dbf6)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
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/36f12d07e7626a423264eca355c4000fc392…
commit 36f12d07e7626a423264eca355c4000fc392dbf6
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jan 17 12:25:28 2012 +0100
backends: Add options for SDL fulscreen && docs.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index fe8a372..c7363fd 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -278,7 +278,12 @@ static void init_backend(const char *backend_opts)
if (!strcmp(backend_opts, "SDL")) {
fprintf(stderr, "Initalizing SDL backendn");
- backend = GP_BackendSDLInit(800, 600, 0);
+ backend = GP_BackendSDLInit(800, 600, 0, 0);
+ }
+
+ if (!strcmp(backend_opts, "SDL:FS")) {
+ fprintf(stderr, "Initalizing SDL fullscreenn");
+ backend = GP_BackendSDLInit(0, 0, 0, GP_SDL_FULLSCREEN);
}
if (backend == NULL) {
diff --git a/include/backends/GP_SDL.h b/include/backends/GP_SDL.h
index 2b3541b..bd553b9 100644
--- a/include/backends/GP_SDL.h
+++ b/include/backends/GP_SDL.h
@@ -26,11 +26,37 @@
#include <stdint.h>
#include "GP_Backend.h"
+enum GP_BackendSDLFlags {
+ GP_SDL_FULLSCREEN = 0x01,
+ GP_SDL_RESIZABLE = 0x02,
+};
+
/*
* Initalize SDL as drawing backend.
*
+ * * SDL doesn't expose file descriptors.
+ *
+ * * The backend is thread safe (the critical parts are guarded with a mutex)
+ *
+ * * The backend is singleton, you can't have two SDL backends running at the
+ * same time.
+ *
+ * * When backend is allready initalized, this function ignores it's parameters
+ * and returns pointer to allready initalized SDL backend.
+ *
+ * * The SDL backends (upon calling GP_BackendPoll()) feeds keyboard and mouse
+ * events into global GP event queue (see input/GP_Event.h).
+ *
+ *
+ * The parameters w h and bpp are directly passed to SDL_SetVideoMode().
+ *
+ * * If w, h and/or bpp are set to zero, SDL tries to do best fit.
+ *
+ * * The GP_BackendSDLFlags are converted into SDL equivalents.
+ *
* Upon failure, or if SDL wasn't compiled in, NULL is returned.
*/
-GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp);
+GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h,
+ uint8_t bpp, uint8_t flags);
#endif /* BACKENDS_GP_SDL_H */
diff --git a/libs/backends/GP_SDL.c b/libs/backends/GP_SDL.c
index f50cfed..feabc9b 100644
--- a/libs/backends/GP_SDL.c
+++ b/libs/backends/GP_SDL.c
@@ -28,6 +28,7 @@
#include "core/GP_Debug.h"
#include "input/GP_InputDriverSDL.h"
#include "GP_Backend.h"
+#include "GP_SDL.h"
#ifdef HAVE_LIBSDL
@@ -60,15 +61,6 @@ static void sdl_update_rect(struct GP_Backend *self __attribute__((unused)),
SDL_mutexV(mutex);
}
-static void sdl_exit(struct GP_Backend *self __attribute__((unused)))
-{
- SDL_mutexP(mutex);
-
- SDL_Quit();
-
- SDL_DestroyMutex(mutex);
-}
-
static void sdl_poll(struct GP_Backend *self __attribute__((unused)))
{
SDL_Event ev;
@@ -81,6 +73,8 @@ 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,
@@ -91,6 +85,17 @@ static struct GP_Backend backend = {
.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 */
@@ -129,7 +134,7 @@ int context_from_surface(GP_Context *context, SDL_Surface *surf)
return 0;
}
-GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp)
+GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp, uint8_t flags)
{
/* SDL not yet initalized */
if (backend.context == NULL) {
@@ -138,7 +143,15 @@ GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp)
return NULL;
}
- sdl_surface = SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE|SDL_DOUBLEBUF);
+ uint32_t sdl_flags = SDL_SWSURFACE;
+
+ if (flags & GP_SDL_FULLSCREEN)
+ sdl_flags |= SDL_FULLSCREEN;
+
+ if (flags & GP_SDL_RESIZABLE)
+ sdl_flags |= SDL_RESIZABLE;
+
+ sdl_surface = SDL_SetVideoMode(w, h, bpp, sdl_flags);
if (sdl_surface == NULL) {
GP_DEBUG(1, "ERROR: SDL_SetVideoMode: %s", SDL_GetError());
-----------------------------------------------------------------------
Summary of changes:
libs/backends/GP_SDL.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 7bc428fa520fa1091b43319121322378951a347d
by metan 17 Jan '12
by metan 17 Jan '12
17 Jan '12
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 7bc428fa520fa1091b43319121322378951a347d (commit)
from b549f66c9fc9e0ccb125692a7a2570bbe2016cdc (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/7bc428fa520fa1091b43319121322378951a…
commit 7bc428fa520fa1091b43319121322378951a347d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jan 17 12:25:28 2012 +0100
backends: Add options for SDL fulscreen && docs.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index fe8a372..c7363fd 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -278,7 +278,12 @@ static void init_backend(const char *backend_opts)
if (!strcmp(backend_opts, "SDL")) {
fprintf(stderr, "Initalizing SDL backendn");
- backend = GP_BackendSDLInit(800, 600, 0);
+ backend = GP_BackendSDLInit(800, 600, 0, 0);
+ }
+
+ if (!strcmp(backend_opts, "SDL:FS")) {
+ fprintf(stderr, "Initalizing SDL fullscreenn");
+ backend = GP_BackendSDLInit(0, 0, 0, GP_SDL_FULLSCREEN);
}
if (backend == NULL) {
diff --git a/include/backends/GP_SDL.h b/include/backends/GP_SDL.h
index 2b3541b..bd553b9 100644
--- a/include/backends/GP_SDL.h
+++ b/include/backends/GP_SDL.h
@@ -26,11 +26,37 @@
#include <stdint.h>
#include "GP_Backend.h"
+enum GP_BackendSDLFlags {
+ GP_SDL_FULLSCREEN = 0x01,
+ GP_SDL_RESIZABLE = 0x02,
+};
+
/*
* Initalize SDL as drawing backend.
*
+ * * SDL doesn't expose file descriptors.
+ *
+ * * The backend is thread safe (the critical parts are guarded with a mutex)
+ *
+ * * The backend is singleton, you can't have two SDL backends running at the
+ * same time.
+ *
+ * * When backend is allready initalized, this function ignores it's parameters
+ * and returns pointer to allready initalized SDL backend.
+ *
+ * * The SDL backends (upon calling GP_BackendPoll()) feeds keyboard and mouse
+ * events into global GP event queue (see input/GP_Event.h).
+ *
+ *
+ * The parameters w h and bpp are directly passed to SDL_SetVideoMode().
+ *
+ * * If w, h and/or bpp are set to zero, SDL tries to do best fit.
+ *
+ * * The GP_BackendSDLFlags are converted into SDL equivalents.
+ *
* Upon failure, or if SDL wasn't compiled in, NULL is returned.
*/
-GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp);
+GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h,
+ uint8_t bpp, uint8_t flags);
#endif /* BACKENDS_GP_SDL_H */
diff --git a/libs/backends/GP_SDL.c b/libs/backends/GP_SDL.c
index f50cfed..7bf7cb0 100644
--- a/libs/backends/GP_SDL.c
+++ b/libs/backends/GP_SDL.c
@@ -28,6 +28,7 @@
#include "core/GP_Debug.h"
#include "input/GP_InputDriverSDL.h"
#include "GP_Backend.h"
+#include "GP_SDL.h"
#ifdef HAVE_LIBSDL
@@ -60,15 +61,6 @@ static void sdl_update_rect(struct GP_Backend *self __attribute__((unused)),
SDL_mutexV(mutex);
}
-static void sdl_exit(struct GP_Backend *self __attribute__((unused)))
-{
- SDL_mutexP(mutex);
-
- SDL_Quit();
-
- SDL_DestroyMutex(mutex);
-}
-
static void sdl_poll(struct GP_Backend *self __attribute__((unused)))
{
SDL_Event ev;
@@ -81,6 +73,8 @@ 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,
@@ -91,6 +85,17 @@ static struct GP_Backend backend = {
.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 */
@@ -129,7 +134,7 @@ int context_from_surface(GP_Context *context, SDL_Surface *surf)
return 0;
}
-GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp)
+GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp, uint8_t flags)
{
/* SDL not yet initalized */
if (backend.context == NULL) {
@@ -138,7 +143,15 @@ GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp)
return NULL;
}
- sdl_surface = SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE|SDL_DOUBLEBUF);
+ uint32_t sdl_flags = SDL_SWSURFACE;
+
+ if (flags & GP_SDL_FULLSCREEN)
+ sdl_flags |= SDL_FULLSCREEN;
+
+ if (flags & GP_SDL_RESIZEABLE)
+ sdl_flags |= SDL_RESIZABLE;
+
+ sdl_surface = SDL_SetVideoMode(w, h, bpp, sdl_flags);
if (sdl_surface == NULL) {
GP_DEBUG(1, "ERROR: SDL_SetVideoMode: %s", SDL_GetError());
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/fbshow.c | 7 ++++++-
include/backends/GP_SDL.h | 28 +++++++++++++++++++++++++++-
libs/backends/GP_SDL.c | 35 ++++++++++++++++++++++++-----------
3 files changed, 57 insertions(+), 13 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: b549f66c9fc9e0ccb125692a7a2570bbe2016cdc
by metan 17 Jan '12
by metan 17 Jan '12
17 Jan '12
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 b549f66c9fc9e0ccb125692a7a2570bbe2016cdc (commit)
from 4d4ca995c2d6ae58d85863cae26c4369d5bd0967 (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/b549f66c9fc9e0ccb125692a7a2570bbe201…
commit b549f66c9fc9e0ccb125692a7a2570bbe2016cdc
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jan 17 11:59:23 2012 +0100
backends: Make the SDL backend thread safe.
The SDL_Flip, SDL_UpdateRect, SDL_Poll and SDL_Quit
are not thread safe. If these clash while running on
xserver, asynchronous communication is detected and
the connection is aborted. Fix that by guarding these
by a mutex.
diff --git a/libs/backends/GP_SDL.c b/libs/backends/GP_SDL.c
index 0a97ada..f50cfed 100644
--- a/libs/backends/GP_SDL.c
+++ b/libs/backends/GP_SDL.c
@@ -32,39 +32,53 @@
#ifdef HAVE_LIBSDL
#include <SDL/SDL.h>
+#include <SDL/SDL_mutex.h>
static SDL_Surface *sdl_surface;
+static SDL_mutex *mutex;
static GP_Context context;
/* Backend API funcitons */
static void sdl_flip(struct GP_Backend *self __attribute__((unused)))
{
- SDL_LockSurface(sdl_surface);
+ SDL_mutexP(mutex);
+
SDL_Flip(sdl_surface);
context.pixels = sdl_surface->pixels;
- SDL_UnlockSurface(sdl_surface);
+
+ SDL_mutexV(mutex);
}
static void sdl_update_rect(struct GP_Backend *self __attribute__((unused)),
GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2)
{
- SDL_LockSurface(sdl_surface);
+ SDL_mutexP(mutex);
+
SDL_UpdateRect(sdl_surface, x1, y1, x2, y2);
- SDL_UnlockSurface(sdl_surface);
+
+ SDL_mutexV(mutex);
}
static void sdl_exit(struct GP_Backend *self __attribute__((unused)))
{
+ SDL_mutexP(mutex);
+
SDL_Quit();
+
+ SDL_DestroyMutex(mutex);
}
static void sdl_poll(struct GP_Backend *self __attribute__((unused)))
{
SDL_Event ev;
+ SDL_mutexP(mutex);
+
while (SDL_PollEvent(&ev))
GP_InputDriverSDLEventPut(&ev);
+
+ SDL_mutexV(mutex);
}
static struct GP_Backend backend = {
@@ -132,6 +146,8 @@ GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp)
return NULL;
}
+ mutex = SDL_CreateMutex();
+
if (context_from_surface(&context, sdl_surface)) {
GP_DEBUG(1, "ERROR: Failed to match pixel_type");
SDL_Quit();
-----------------------------------------------------------------------
Summary of changes:
libs/backends/GP_SDL.c | 24 ++++++++++++++++++++----
1 files changed, 20 insertions(+), 4 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 4d4ca995c2d6ae58d85863cae26c4369d5bd0967
by metan 15 Jan '12
by metan 15 Jan '12
15 Jan '12
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 4d4ca995c2d6ae58d85863cae26c4369d5bd0967 (commit)
via 357771c22372e5584d8c0e9126e7877783784073 (commit)
via 4c798878c771c9306afdffb5416ca817f625d8cd (commit)
from 89f781e8da4907c3e34db57714777601227a3719 (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/4d4ca995c2d6ae58d85863cae26c4369d5bd…
commit 4d4ca995c2d6ae58d85863cae26c4369d5bd0967
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jan 15 19:16:09 2012 +0100
demos: Port fbshow to SDL backend.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index fb3baeb..fe8a372 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -38,8 +38,8 @@
static GP_Pixel black_pixel;
static GP_Pixel white_pixel;
-static GP_Backend *backend;
-static GP_Context *context;
+static GP_Backend *backend = NULL;
+static GP_Context *context = NULL;
/* image loader thread */
static int abort_flag = 0;
@@ -73,6 +73,8 @@ static int image_loader_callback(GP_ProgressCallback *self)
size = GP_TextWidth(NULL, buf);
+ GP_BackendFlip(backend);
+
return 0;
}
@@ -204,8 +206,10 @@ static void *image_loader(void *ptr)
GP_FillRectXYWH(context, ret->w+cx, 0, cx, context->h, black_pixel);
GP_FillRectXYWH(context, 0, ret->h+cy, context->w, cy, black_pixel);
- if (!params->show_info)
+ if (!params->show_info) {
+ GP_BackendFlip(backend);
return NULL;
+ }
GP_Size th = GP_TextHeight(NULL);
@@ -227,6 +231,8 @@ static void *image_loader(void *ptr)
GP_Print(context, NULL, 10, 14 + 2 * th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
white_pixel, black_pixel, "%s", img_name(params->img_path));
+ GP_BackendFlip(backend);
+
return NULL;
}
@@ -253,23 +259,44 @@ static void show_image(struct loader_params *params)
}
}
-static void sighandler(int signo __attribute__((unused)))
+static void sighandler(int signo)
{
if (backend != NULL)
GP_BackendExit(backend);
+
+ fprintf(stderr, "Got signal %in", signo);
exit(1);
}
+static void init_backend(const char *backend_opts)
+{
+ if (!strcmp(backend_opts, "fb")) {
+ fprintf(stderr, "Initalizing framebuffer backendn");
+ backend = GP_BackendLinuxFBInit("/dev/fb0");
+ }
+
+ if (!strcmp(backend_opts, "SDL")) {
+ fprintf(stderr, "Initalizing SDL backendn");
+ backend = GP_BackendSDLInit(800, 600, 0);
+ }
+
+ if (backend == NULL) {
+ fprintf(stderr, "Failed to initalize backend '%s'n", backend_opts);
+ exit(1);
+ }
+}
+
int main(int argc, char *argv[])
{
GP_InputDriverLinux *drv = NULL;
- char *input_dev = NULL;
+ const char *input_dev = NULL;
+ const char *backend_opts = "fb";
int sleep_sec = -1;
struct loader_params params = {NULL, 0, 0, 0};
int opt;
- while ((opt = getopt(argc, argv, "Ii:Ps:r:")) != -1) {
+ while ((opt = getopt(argc, argv, "b:Ii:Ps:r:")) != -1) {
switch (opt) {
case 'I':
params.show_info = 1;
@@ -290,6 +317,9 @@ int main(int argc, char *argv[])
rotate = 180;
else if (!strcmp(optarg, "270"))
rotate = 270;
+ case 'b':
+ backend_opts = optarg;
+ break;
default:
fprintf(stderr, "Invalid paramter '%c'n", opt);
}
@@ -297,9 +327,7 @@ int main(int argc, char *argv[])
GP_SetDebugLevel(10);
- if (input_dev == NULL) {
- sleep_sec = 1;
- } else {
+ if (input_dev != NULL) {
drv = GP_InputDriverLinuxOpen(input_dev);
if (drv == NULL) {
@@ -314,12 +342,7 @@ int main(int argc, char *argv[])
signal(SIGBUS, sighandler);
signal(SIGABRT, sighandler);
- backend = GP_BackendLinuxFBInit("/dev/fb0");
-
- if (backend == NULL) {
- fprintf(stderr, "Failed to initalize framebuffern");
- return 1;
- }
+ init_backend(backend_opts);
context = backend->context;
@@ -329,25 +352,26 @@ int main(int argc, char *argv[])
white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, context);
GP_Fill(context, black_pixel);
+ GP_BackendFlip(backend);
int argf = optind;
int argn = argf;
-
+
params.show_progress_once = 1;
params.img_path = argv[argf];
show_image(¶ms);
- /* Initalize select */
- fd_set rfds;
- FD_ZERO(&rfds);
- FD_SET(drv->fd, &rfds);
- struct timeval tv = {.tv_sec = sleep_sec, .tv_usec = 0};
- struct timeval *tvp = sleep_sec != -1 ? &tv : NULL;
-
for (;;) {
int ret;
if (drv != NULL) {
+ /* Initalize select */
+ fd_set rfds;
+ FD_ZERO(&rfds);
+ FD_SET(drv->fd, &rfds);
+ struct timeval tv = {.tv_sec = sleep_sec, .tv_usec = 0};
+ struct timeval *tvp = sleep_sec != -1 ? &tv : NULL;
+
ret = select(drv->fd + 1, &rfds, NULL, NULL, tvp);
tv.tv_sec = sleep_sec;
@@ -371,16 +395,23 @@ int main(int argc, char *argv[])
FD_SET(drv->fd, &rfds);
} else {
- sleep(sleep_sec);
-
- argn++;
- if (argn >= argc)
- argn = argf;
+ if (sleep_sec != -1) {
+ sleep(sleep_sec);
+
+ argn++;
+ if (argn >= argc)
+ argn = argf;
- params.img_path = argv[argn];
- show_image(¶ms);
+ params.img_path = argv[argn];
+ show_image(¶ms);
+ }
}
+ if (backend->Poll)
+ GP_BackendPoll(backend);
+
+ usleep(1000);
+
/* Read and parse events */
GP_Event ev;
http://repo.or.cz/w/gfxprim.git/commit/357771c22372e5584d8c0e9126e787778378…
commit 357771c22372e5584d8c0e9126e7877783784073
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jan 15 19:15:52 2012 +0100
backends: Fix SDL backend, seems to be working now.
diff --git a/include/backends/GP_SDL.h b/include/backends/GP_SDL.h
index b6f0fab..2b3541b 100644
--- a/include/backends/GP_SDL.h
+++ b/include/backends/GP_SDL.h
@@ -31,6 +31,6 @@
*
* Upon failure, or if SDL wasn't compiled in, NULL is returned.
*/
-GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint16_t bpp);
+GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp);
#endif /* BACKENDS_GP_SDL_H */
diff --git a/libs/backends/GP_SDL.c b/libs/backends/GP_SDL.c
index 4083f09..0a97ada 100644
--- a/libs/backends/GP_SDL.c
+++ b/libs/backends/GP_SDL.c
@@ -26,6 +26,7 @@
#include "../../config.h"
#include "core/GP_Debug.h"
+#include "input/GP_InputDriverSDL.h"
#include "GP_Backend.h"
#ifdef HAVE_LIBSDL
@@ -33,18 +34,24 @@
#include <SDL/SDL.h>
static SDL_Surface *sdl_surface;
+static GP_Context context;
/* Backend API funcitons */
static void sdl_flip(struct GP_Backend *self __attribute__((unused)))
{
+ SDL_LockSurface(sdl_surface);
SDL_Flip(sdl_surface);
+ context.pixels = sdl_surface->pixels;
+ SDL_UnlockSurface(sdl_surface);
}
static void sdl_update_rect(struct GP_Backend *self __attribute__((unused)),
GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2)
{
+ SDL_LockSurface(sdl_surface);
SDL_UpdateRect(sdl_surface, x1, y1, x2, y2);
+ SDL_UnlockSurface(sdl_surface);
}
static void sdl_exit(struct GP_Backend *self __attribute__((unused)))
@@ -56,9 +63,8 @@ static void sdl_poll(struct GP_Backend *self __attribute__((unused)))
{
SDL_Event ev;
- if (SDL_PollEvent(&ev)) {
- printf("SDL EVENT!n");
- }
+ while (SDL_PollEvent(&ev))
+ GP_InputDriverSDLEventPut(&ev);
}
static struct GP_Backend backend = {
@@ -109,28 +115,30 @@ int context_from_surface(GP_Context *context, SDL_Surface *surf)
return 0;
}
-GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint16_t bpp)
+GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp)
{
/* SDL not yet initalized */
- if (backend.context != NULL) {
+ if (backend.context == NULL) {
if (SDL_Init(SDL_INIT_VIDEO)) {
GP_DEBUG(1, "ERROR: SDL_Init: %s", SDL_GetError());
return NULL;
}
- sdl_surface = SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE);
+ sdl_surface = SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE|SDL_DOUBLEBUF);
if (sdl_surface == NULL) {
GP_DEBUG(1, "ERROR: SDL_SetVideoMode: %s", SDL_GetError());
SDL_Quit();
return NULL;
}
-
- if (context_from_surface(backend.context, sdl_surface)) {
+
+ if (context_from_surface(&context, sdl_surface)) {
GP_DEBUG(1, "ERROR: Failed to match pixel_type");
SDL_Quit();
return NULL;
}
+
+ backend.context = &context;
}
return &backend;
http://repo.or.cz/w/gfxprim.git/commit/4c798878c771c9306afdffb5416ca817f625…
commit 4c798878c771c9306afdffb5416ca817f625d8cd
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jan 15 19:15:35 2012 +0100
build: Add -ggdb by default.
diff --git a/configure b/configure
index 3f479be..7d0ffd6 100755
--- a/configure
+++ b/configure
@@ -147,7 +147,7 @@ if __name__ == '__main__':
# Dictionary for default configuration parameters
#
cfg = {'CC' : ['gcc', 'Path/name of the C compiler'],
- 'CFLAGS' : ['-W -Wall -Wextra -fPIC -O2', 'C compiler flags'],
+ 'CFLAGS' : ['-W -Wall -Wextra -fPIC -O2 -ggdb', 'C compiler flags'],
'PYTHON_BIN' : ['python', 'Path/name of python interpreter'],
'include_path': ['/usr/include', 'Path to the system headers']}
-----------------------------------------------------------------------
Summary of changes:
configure | 2 +-
demos/fbshow/fbshow.c | 91 ++++++++++++++++++++++++++++++---------------
include/backends/GP_SDL.h | 2 +-
libs/backends/GP_SDL.c | 24 ++++++++----
4 files changed, 79 insertions(+), 40 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 89f781e8da4907c3e34db57714777601227a3719
by metan 15 Jan '12
by metan 15 Jan '12
15 Jan '12
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 89f781e8da4907c3e34db57714777601227a3719 (commit)
from 713e4f3f13172cb63b59ac501b54992a2309b314 (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/89f781e8da4907c3e34db57714777601227a…
commit 89f781e8da4907c3e34db57714777601227a3719
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jan 15 17:40:47 2012 +0100
backends: Added support for overall backend API.
diff --git a/build/get_objs.sh b/build/get_objs.sh
index 834fd77..3519b01 100755
--- a/build/get_objs.sh
+++ b/build/get_objs.sh
@@ -1,7 +1,7 @@
#!/bin/sh
TOPDIR=..
-LIBDIRS="core gfx text loaders filters backends input"
+LIBDIRS="core gfx text loaders filters input"
for i in $LIBDIRS; do
OBJECTS=`echo $TOPDIR/libs/$i/*.o`;
diff --git a/demos/fbshow/Makefile b/demos/fbshow/Makefile
index 08f9234..6b04464 100644
--- a/demos/fbshow/Makefile
+++ b/demos/fbshow/Makefile
@@ -5,7 +5,7 @@ CSOURCES=$(shell echo *.c)
INCLUDE=
CFLAGS+=-pthread
LDFLAGS+=-pthread
-LDLIBS+=-lGP -L$(TOPDIR)/build/
+LDLIBS+=-lGP -lGP_backends -lSDL -L$(TOPDIR)/build/
APPS=fbshow
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index 3943ffc..fb3baeb 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -32,13 +32,14 @@
#include <pthread.h>
#include <GP.h>
-#include <backends/GP_Framebuffer.h>
+#include <backends/GP_Backends.h>
#include <input/GP_InputDriverLinux.h>
static GP_Pixel black_pixel;
static GP_Pixel white_pixel;
-static GP_Framebuffer *fb = NULL;
+static GP_Backend *backend;
+static GP_Context *context;
/* image loader thread */
static int abort_flag = 0;
@@ -60,7 +61,7 @@ static int image_loader_callback(GP_ProgressCallback *self)
snprintf(buf, sizeof(buf), "%s ... %-3.1f%%",
(const char*)self->priv, self->percentage);
- GP_Context *c = &fb->context;
+ GP_Context *c = context;
int align = GP_ALIGN_CENTER|GP_VALIGN_ABOVE;
@@ -118,8 +119,8 @@ static void *image_loader(void *ptr)
callback.priv = "Loading image";
if (GP_LoadImage(params->img_path, &img, &callback) != 0) {
- GP_Fill(&fb->context, black_pixel);
- GP_Text(&fb->context, NULL, fb->context.w/2, fb->context.h/2,
+ GP_Fill(context, black_pixel);
+ GP_Text(context, NULL, context->w/2, context->h/2,
GP_ALIGN_CENTER|GP_VALIGN_CENTER, black_pixel, white_pixel,
"Failed to load image :(");
return NULL;
@@ -131,13 +132,13 @@ static void *image_loader(void *ptr)
case 0:
case 180:
default:
- w = fb->context.w;
- h = fb->context.h;
+ w = context->w;
+ h = context->h;
break;
case 90:
case 270:
- w = fb->context.h;
- h = fb->context.w;
+ w = context->h;
+ h = context->w;
break;
}
@@ -155,9 +156,9 @@ static void *image_loader(void *ptr)
GP_Context *ret;
-// callback.priv = "Blurring Image";
-// if (GP_FilterGaussianBlur(img, img, 0.3/rat, 0.3/rat, &callback) == NULL)
-// return NULL;
+ callback.priv = "Blurring Image";
+ if (GP_FilterGaussianBlur(img, img, 0.5/rat, 0.5/rat, &callback) == NULL)
+ return NULL;
callback.priv = "Resampling Image";
ret = GP_FilterResize(img, NULL, GP_INTERP_CUBIC_INT, img->w * rat, img->h * rat, &callback);
@@ -191,39 +192,39 @@ static void *image_loader(void *ptr)
if (img == NULL)
return NULL;
- uint32_t cx = (fb->context.w - ret->w)/2;
- uint32_t cy = (fb->context.h - ret->h)/2;
+ uint32_t cx = (context->w - ret->w)/2;
+ uint32_t cy = (context->h - ret->h)/2;
- GP_Blit(ret, 0, 0, ret->w, ret->h, &fb->context, cx, cy);
+ GP_Blit(ret, 0, 0, ret->w, ret->h, context, cx, cy);
GP_ContextFree(ret);
/* clean up the rest of the display */
- GP_FillRectXYWH(&fb->context, 0, 0, cx, fb->context.h, black_pixel);
- GP_FillRectXYWH(&fb->context, 0, 0, fb->context.w, cy, black_pixel);
- GP_FillRectXYWH(&fb->context, ret->w+cx, 0, cx, fb->context.h, black_pixel);
- GP_FillRectXYWH(&fb->context, 0, ret->h+cy, fb->context.w, cy, black_pixel);
+ GP_FillRectXYWH(context, 0, 0, cx, context->h, black_pixel);
+ GP_FillRectXYWH(context, 0, 0, context->w, cy, black_pixel);
+ GP_FillRectXYWH(context, ret->w+cx, 0, cx, context->h, black_pixel);
+ GP_FillRectXYWH(context, 0, ret->h+cy, context->w, cy, black_pixel);
if (!params->show_info)
return NULL;
GP_Size th = GP_TextHeight(NULL);
- GP_Print(&fb->context, NULL, 11, 11, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
+ GP_Print(context, NULL, 11, 11, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
black_pixel, white_pixel, "%ux%u", w, h);
- GP_Print(&fb->context, NULL, 10, 10, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
+ GP_Print(context, NULL, 10, 10, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
white_pixel, black_pixel, "%ux%u", w, h);
- GP_Print(&fb->context, NULL, 11, 13 + th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
+ GP_Print(context, NULL, 11, 13 + th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
black_pixel, white_pixel, "1:%3.3f", rat);
- GP_Print(&fb->context, NULL, 10, 12 + th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
+ GP_Print(context, NULL, 10, 12 + th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
white_pixel, black_pixel, "1:%3.3f", rat);
- GP_Print(&fb->context, NULL, 11, 15 + 2 * th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
+ GP_Print(context, NULL, 11, 15 + 2 * th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
black_pixel, white_pixel, "%s", img_name(params->img_path));
- GP_Print(&fb->context, NULL, 10, 14 + 2 * th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
+ GP_Print(context, NULL, 10, 14 + 2 * th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
white_pixel, black_pixel, "%s", img_name(params->img_path));
return NULL;
@@ -247,15 +248,15 @@ static void show_image(struct loader_params *params)
if (ret) {
fprintf(stderr, "Failed to start thread: %sn", strerror(ret));
- GP_FramebufferExit(fb);
+ GP_BackendExit(backend);
exit(1);
}
}
static void sighandler(int signo __attribute__((unused)))
{
- if (fb != NULL)
- GP_FramebufferExit(fb);
+ if (backend != NULL)
+ GP_BackendExit(backend);
exit(1);
}
@@ -313,19 +314,21 @@ int main(int argc, char *argv[])
signal(SIGBUS, sighandler);
signal(SIGABRT, sighandler);
- fb = GP_FramebufferInit("/dev/fb0");
+ backend = GP_BackendLinuxFBInit("/dev/fb0");
- if (fb == NULL) {
+ if (backend == NULL) {
fprintf(stderr, "Failed to initalize framebuffern");
return 1;
}
+
+ context = backend->context;
+
+ GP_EventSetScreenSize(context->w, context->h);
- GP_EventSetScreenSize(fb->context.w, fb->context.h);
-
- black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, &fb->context);
- white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, &fb->context);
+ black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, context);
+ white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, context);
- GP_Fill(&fb->context, black_pixel);
+ GP_Fill(context, black_pixel);
int argf = optind;
int argn = argf;
@@ -351,7 +354,7 @@ int main(int argc, char *argv[])
switch (ret) {
case -1:
- GP_FramebufferExit(fb);
+ GP_BackendExit(backend);
return 0;
break;
case 0:
@@ -411,7 +414,7 @@ int main(int argc, char *argv[])
case GP_KEY_ESC:
case GP_KEY_ENTER:
case GP_KEY_Q:
- GP_FramebufferExit(fb);
+ GP_BackendExit(backend);
return 0;
break;
case GP_KEY_RIGHT:
@@ -443,7 +446,7 @@ int main(int argc, char *argv[])
}
}
- GP_FramebufferExit(fb);
+ GP_BackendExit(backend);
return 0;
}
diff --git a/demos/grinder/Makefile b/demos/grinder/Makefile
index 377d008..c77d449 100644
--- a/demos/grinder/Makefile
+++ b/demos/grinder/Makefile
@@ -2,7 +2,7 @@ TOPDIR=../..
CSOURCES=$(shell echo *.c)
-INCLUDE=core gfx SDL backends
+INCLUDE=core gfx SDL
LDLIBS+=-lGP -L$(TOPDIR)/build/
APPS=grinder
diff --git a/include/backends/GP_Backend.h b/include/backends/GP_Backend.h
index db771cd..2e36bb9 100644
--- a/include/backends/GP_Backend.h
+++ b/include/backends/GP_Backend.h
@@ -19,74 +19,134 @@
* Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
* <jiri.bluebear.dluhos(a)gmail.com> *
* *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
-#ifndef GP_BACKEND_H
-#define GP_BACKEND_H
+/*
-#include "core/GP_Context.h"
+ The GP_Backend is overall structure for API for managing
+ connection/mmaped memory/... to xserver window/framebuffer/... .
+
+ In contrast to other graphics libraries we do not try to create overall
+ initalization interface that would match specialities for every possible
+ backend. Rather than that we are trying to create API that is the same
+ for all backends, once initalization is done.
+
+ So once you initalize, for example, framebuffer driver, the GP_Backend
+ structure is returned, which then could be used with generic code for
+ backend drawing.
-/*
- * Types of events provided by the backend.
*/
-enum GP_BackendEventType {
- GP_BACKEND_EVENT_NONE = 0,
- GP_BACKEND_EVENT_UPDATE_VIDEO = 1, /* video redraw is needed */
- GP_BACKEND_EVENT_QUIT_REQUEST = 2, /* user requests quitting */
-};
+
+#ifndef BACKENDS_GP_BACKEND_H
+#define BACKENDS_GP_BACKEND_H
+
+#include "core/GP_Context.h"
+
+struct GP_Backend;
/*
- * Structure describing an event reported by a backend.
+ * Linked list of file descriptors with callbacks.
*/
-struct GP_BackendEvent {
- enum GP_BackendEventType type;
-};
+typedef struct GP_BackendFD {
+ int fd;
+ void (*Callback)(struct GP_BackendFD *self, struct GP_Backend *backend);
+ struct GP_BackendFD *next;
+} GP_BackendFD;
-/* Describes a backend and holds all its API functions. */
-struct GP_Backend {
+typedef struct GP_Backend {
+ /*
+ * Backend name.
+ */
const char *name;
- struct GP_Backend *(*init_fn)(void);
- void (*shutdown_fn)(void);
- GP_Context *(*open_video_fn)(int w, int h, int flags);
- GP_Context *(*video_context_fn)(void);
- void (*update_video_fn)(void);
- int (*get_event_fn)(struct GP_BackendEvent *event);
-};
-/*
- * Attempts to initialize a backend.
- *
- * If name is specified, only that backend is tried; if name is NULL,
- * all known backends are tried and the first usable one is picked.
- *
- * Returns the backend structure, or NULL on failure.
- */
-struct GP_Backend *GP_InitBackend(const char *name);
+ /*
+ * Pointer to context app should draw to.
+ *
+ * This MAY change upon a flip operation.
+ */
+ GP_Context *context;
+
+ /*
+ * If display is buffered, this copies content
+ * of context onto display.
+ *
+ * If display is not buffered, this is no-op.
+ */
+ void (*Flip)(struct GP_Backend *self);
+
+ /*
+ * Updates display rectangle.
+ *
+ * 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.
+ */
+ void (*UpdateRect)(struct GP_Backend *self,
+ GP_Coord x1, GP_Coord y1,
+ GP_Coord x2, GP_Coord y2);
+
+ /*
+ * Exits the backend.
+ */
+ void (*Exit)(struct GP_Backend *self);
+
+ /*
+ * Linked List of file descriptors with callbacks to poll.
+ *
+ * May be NULL.
+ */
+ GP_BackendFD *fd_list;
+
+ /*
+ * Some of the backends doesn't expose file descriptor
+ * (for example SDL is broken that way).
+ *
+ * In that case the fd_list is NULL and this function
+ * is non NULL.
+ */
+ void (*Poll)(struct GP_Backend *self);
+
+ /* Backed private data */
+ char priv[];
+} GP_Backend;
+
+#define GP_BACKEND_PRIV(backend) ((void*)(backend)->priv)
/*
- * Opens the backend video and returns its context.
+ * Calls backend->Flip().
*/
-GP_Context *GP_OpenBackendVideo(int w, int h, int flags);
+static inline void GP_BackendFlip(GP_Backend *backend)
+{
+ backend->Flip(backend);
+}
/*
- * Returns a pointer to context that represents the backend's video.
+ * Calls backend->UpdateRect().
*/
-GP_Context *GP_GetBackendVideoContext(void);
+static inline void GP_BackendUpdateRect(GP_Backend *backend,
+ GP_Coord x1, GP_Coord y1,
+ GP_Coord x2, GP_Coord y2)
+{
+ backend->UpdateRect(backend, x1, y1, x2, y2);
+}
/*
- * Calls the backend to update its video to reflect new changes.
- * If the backend uses double buffering, this causes a buffer flip.
- * If the backend uses direct-to-screen drawing, this call
- * has no effect.
+ * Calls backend->Exit().
*/
-void GP_UpdateBackendVideo(void);
+static inline void GP_BackendExit(GP_Backend *backend)
+{
+ backend->Exit(backend);
+}
/*
- * Reads the first pending backend event.
- * Returns 0 if no events were pending, 1 on success.
+ * Polls backend, the events are filled into event queue.
*/
-int GP_GetBackendEvent(struct GP_BackendEvent *event);
+static inline void GP_BackendPoll(GP_Backend *backend)
+{
+ backend->Poll(backend);
+}
-#endif /* GP_BACKEND_H */
+#endif /* BACKENDS_GP_BACKEND_H */
diff --git a/include/backends/GP_Framebuffer.h b/include/backends/GP_Backends.h
similarity index 76%
copy from include/backends/GP_Framebuffer.h
copy to include/backends/GP_Backends.h
index 010ed7f..284e2d7 100644
--- a/include/backends/GP_Framebuffer.h
+++ b/include/backends/GP_Backends.h
@@ -16,33 +16,28 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
-#ifndef GP_FRAMEBUFFER_H
-#define GP_FRAMEBUFFER_H
+/*
+
+ Catch all header for backends.
-#include "core/GP_Context.h"
+ */
-typedef struct GP_Framebuffer {
- GP_Context context;
- uint32_t bsize;
- int con_fd;
- int con_nr;
- int last_con_nr;
- int fb_fd;
- char path[];
-} GP_Framebuffer;
+#ifndef BACKENDS_GP_BACKENDS_H
+#define BACKENDS_GP_BACKENDS_H
/*
- * Initalize framebuffer.
+ * Base backend definitions.
*/
-GP_Framebuffer *GP_FramebufferInit(const char *path);
+#include "GP_Backend.h"
/*
- * Deinitalize framebuffer.
+ * Backends.
*/
-void GP_FramebufferExit(GP_Framebuffer *fb);
+#include "GP_LinuxFB.h"
+#include "GP_SDL.h"
-#endif /* GP_FRAMEBUFFER_H */
+#endif /* BACKENDS_GP_BACKENDS_H */
diff --git a/libs/backends/GP_Backend.c b/include/backends/GP_LinuxFB.h
similarity index 52%
rename from libs/backends/GP_Backend.c
rename to include/backends/GP_LinuxFB.h
index f705264..1fac9a4 100644
--- a/libs/backends/GP_Backend.c
+++ b/include/backends/GP_LinuxFB.h
@@ -16,72 +16,26 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
-#include "core/GP_Core.h"
-#include "GP_Backend.h"
-#include "../../config.h"
+#ifndef BACKENDS_GP_FRAMEBUFFER_H
+#define BACKENDS_GP_FRAMEBUFFER_H
-#include <string.h>
+#include "GP_Backend.h"
/*
- * The currently active backend (NULL if none).
+ * Initalize framebuffer.
+ *
+ * The path should point to framebuffer device eg. "/dev/fb0" for first
+ * framebuffer device.
+ *
+ * The GP_Backend structure is allocated and returned, the resources are
+ * deinitalized and the structure is freed by backed->Exit(backend); call.
+ *
+ * Upon failure NULL is returned.
*/
-static struct GP_Backend *current_backend = NULL;
-
-#ifdef HAVE_LIBSDL
-
-extern struct GP_Backend GP_SDL_backend;
-
-#endif
-
-struct GP_Backend *GP_InitBackend(const char *name)
-{
- if (current_backend)
- return current_backend;
-
-#ifdef HAVE_LIBSDL
-
- if (!name || strcasecmp(name, "sdl") == 0) {
- current_backend = GP_SDL_backend.init_fn();
- return current_backend;
- }
-
-#endif
-
- return NULL;
-}
-
-struct GP_Backend *GP_GetCurrentBackend(void)
-{
- return current_backend;
-}
-
-GP_Context *GP_OpenBackendVideo(int w, int h, int flags)
-{
- GP_CHECK(current_backend, "no current backend");
- return current_backend->open_video_fn(w, h, flags);
-}
-
-struct GP_Context *GP_GetBackendVideoContext(void)
-{
- GP_CHECK(current_backend, "no current backend");
- return current_backend->video_context_fn();
-}
-
-void GP_UpdateBackendVideo(void)
-{
- GP_CHECK(current_backend, "no current backend");
- return current_backend->update_video_fn();
-}
+GP_Backend *GP_BackendLinuxFBInit(const char *path);
-int GP_GetBackendEvent(struct GP_BackendEvent *event)
-{
- GP_CHECK(current_backend, "no current backend");
- return current_backend->get_event_fn(event);
-}
+#endif /* BACKENDS_GP_FRAMEBUFFER_H */
diff --git a/include/backends/GP_Framebuffer.h b/include/backends/GP_SDL.h
similarity index 76%
rename from include/backends/GP_Framebuffer.h
rename to include/backends/GP_SDL.h
index 010ed7f..b6f0fab 100644
--- a/include/backends/GP_Framebuffer.h
+++ b/include/backends/GP_SDL.h
@@ -16,33 +16,21 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
-#ifndef GP_FRAMEBUFFER_H
-#define GP_FRAMEBUFFER_H
+#ifndef BACKENDS_GP_SDL_H
+#define BACKENDS_GP_SDL_H
-#include "core/GP_Context.h"
-
-typedef struct GP_Framebuffer {
- GP_Context context;
- uint32_t bsize;
- int con_fd;
- int con_nr;
- int last_con_nr;
- int fb_fd;
- char path[];
-} GP_Framebuffer;
-
-/*
- * Initalize framebuffer.
- */
-GP_Framebuffer *GP_FramebufferInit(const char *path);
+#include <stdint.h>
+#include "GP_Backend.h"
/*
- * Deinitalize framebuffer.
+ * Initalize SDL as drawing backend.
+ *
+ * Upon failure, or if SDL wasn't compiled in, NULL is returned.
*/
-void GP_FramebufferExit(GP_Framebuffer *fb);
+GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint16_t bpp);
-#endif /* GP_FRAMEBUFFER_H */
+#endif /* BACKENDS_GP_SDL_H */
diff --git a/libs/backends/GP_Framebuffer.c b/libs/backends/GP_LinuxFB.c
similarity index 80%
rename from libs/backends/GP_Framebuffer.c
rename to libs/backends/GP_LinuxFB.c
index 4eae632..d0ad3c7 100644
--- a/libs/backends/GP_Framebuffer.c
+++ b/libs/backends/GP_LinuxFB.c
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -33,12 +33,22 @@
#include <linux/vt.h>
#include "core/GP_Debug.h"
-#include "GP_Framebuffer.h"
+#include "GP_LinuxFB.h"
+
+struct fb_priv {
+ GP_Context context;
+ uint32_t bsize;
+ int con_fd;
+ int con_nr;
+ int last_con_nr;
+ int fb_fd;
+ char path[];
+};
/*
* Allocates and switches to newly allocated console.
*/
-static int allocate_console(struct GP_Framebuffer *fb)
+static int allocate_console(struct fb_priv *fb)
{
struct vt_stat vts;
int fd, nr;
@@ -104,16 +114,57 @@ static int allocate_console(struct GP_Framebuffer *fb)
return 0;
}
-GP_Framebuffer *GP_FramebufferInit(const char *path)
+/* Backend API callbacks */
+
+static void fb_flip_noop(GP_Backend *self __attribute__((unused)))
+{
+
+}
+
+static void fb_update_rect_noop(GP_Backend *self __attribute__((unused)),
+ GP_Coord x1 __attribute__((unused)),
+ GP_Coord y1 __attribute__((unused)),
+ GP_Coord x2 __attribute__((unused)),
+ GP_Coord y2 __attribute__((unused)))
+{
+
+}
+
+static void fb_exit(GP_Backend *self)
+{
+ struct fb_priv *fb = GP_BACKEND_PRIV(self);
+
+ /* unmap framebuffer */
+ munmap(fb->context.pixels, fb->bsize);
+ close(fb->fb_fd);
+
+ /* reset keyboard */
+ ioctl(fb->con_fd, KDSETMODE, KD_TEXT);
+
+ /* switch back console */
+ if (fb->last_con_nr != -1)
+ ioctl(fb->con_fd, VT_ACTIVATE, fb->last_con_nr);
+
+ close(fb->con_fd);
+ free(self);
+}
+
+GP_Backend *GP_BackendLinuxFBInit(const char *path)
{
- GP_Framebuffer *fb = malloc(sizeof (GP_Framebuffer) + strlen(path) + 1);
+ GP_Backend *backend;
+ struct fb_priv *fb;
struct fb_fix_screeninfo fscri;
struct fb_var_screeninfo vscri;
int fd;
+
+ backend = malloc(sizeof(GP_Backend) +
+ sizeof(struct fb_priv) + strlen(path) + 1);
- if (fb == NULL)
+ if (backend == NULL)
return NULL;
+ fb = GP_BACKEND_PRIV(backend);
+
if (allocate_console(fb))
goto err1;
@@ -181,7 +232,16 @@ GP_Framebuffer *GP_FramebufferInit(const char *path)
fb->context.bytes_per_row = fscri.line_length;
fb->context.pixel_type = pixel_type;
- return fb;
+ /* 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;
+
+ return backend;
err3:
close(fd);
err2:
@@ -194,23 +254,6 @@ err2:
if (fb->last_con_nr != -1)
ioctl(fb->con_fd, VT_ACTIVATE, fb->last_con_nr);
err1:
- free(fb);
+ free(backend);
return NULL;
}
-
-void GP_FramebufferExit(GP_Framebuffer *fb)
-{
- /* unmap framebuffer */
- munmap(fb->context.pixels, fb->bsize);
- close(fb->fb_fd);
-
- /* reset keyboard */
- ioctl(fb->con_fd, KDSETMODE, KD_TEXT);
-
- /* switch back console */
- if (fb->last_con_nr != -1)
- ioctl(fb->con_fd, VT_ACTIVATE, fb->last_con_nr);
-
- close(fb->con_fd);
- free(fb);
-}
diff --git a/libs/backends/GP_Backend_SDL.c b/libs/backends/GP_SDL.c
similarity index 50%
rename from libs/backends/GP_Backend_SDL.c
rename to libs/backends/GP_SDL.c
index 3b16d00..4083f09 100644
--- a/libs/backends/GP_Backend_SDL.c
+++ b/libs/backends/GP_SDL.c
@@ -19,42 +19,71 @@
* Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
* <jiri.bluebear.dluhos(a)gmail.com> *
* *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
-#include "GP_Backend.h"
#include "../../config.h"
+#include "core/GP_Debug.h"
+#include "GP_Backend.h"
+
#ifdef HAVE_LIBSDL
-#include <dlfcn.h>
#include <SDL/SDL.h>
-struct GP_Backend GP_SDL_backend;
-static SDL_Surface *GP_SDL_display = NULL;
-static GP_Context GP_SDL_context;
+static SDL_Surface *sdl_surface;
+
+/* Backend API funcitons */
+
+static void sdl_flip(struct GP_Backend *self __attribute__((unused)))
+{
+ SDL_Flip(sdl_surface);
+}
-/* Functions from the SDL library, dynamically loaded in GP_SDL_InitFn(). */
-static void (*dyn_SDL_Quit)(void);
-static int (*dyn_SDL_Init)(int);
-static SDL_Surface *(*dyn_SDL_SetVideoMode)(int, int, int, uint32_t);
-static void (*dyn_SDL_UpdateRect)(SDL_Surface *, int, int, int, int);
-static int (*dyn_SDL_WaitEvent)(SDL_Event *);
+static void sdl_update_rect(struct GP_Backend *self __attribute__((unused)),
+ GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2)
+{
+ SDL_UpdateRect(sdl_surface, x1, y1, x2, y2);
+}
-/* User callbacks. */
-static void (*GP_SDL_update_video_callback)(void) = NULL;
+static void sdl_exit(struct GP_Backend *self __attribute__((unused)))
+{
+ SDL_Quit();
+}
-inline GP_RetCode GP_SDL_ContextFromSurface(
- GP_Context *context, SDL_Surface *surf)
+static void sdl_poll(struct GP_Backend *self __attribute__((unused)))
{
- GP_CHECK(context, "context is NULL");
- GP_CHECK(surf, "surface is NULL");
+ SDL_Event ev;
+ if (SDL_PollEvent(&ev)) {
+ printf("SDL EVENT!n");
+ }
+}
+
+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,
+};
+
+int context_from_surface(GP_Context *context, SDL_Surface *surf)
+{
/* sanity checks on the SDL surface */
- if (surf->format->BytesPerPixel == 0 || surf->format->BytesPerPixel > 4)
- return GP_ENOIMPL;
-
+ if (surf->format->BytesPerPixel == 0) {
+ GP_DEBUG(1, "ERROR: Surface->BytesPerPixel == 0");
+ return 1;
+ }
+
+ if (surf->format->BytesPerPixel > 4) {
+ GP_DEBUG(1, "ERROR: Surface->BytesPerPixel > 4");
+ return 1;
+ }
+
enum GP_PixelType pixeltype = GP_PixelRGBMatch(surf->format->Rmask,
surf->format->Gmask,
surf->format->Bmask,
@@ -62,7 +91,7 @@ inline GP_RetCode GP_SDL_ContextFromSurface(
surf->format->BitsPerPixel);
if (pixeltype == GP_PIXEL_UNKNOWN)
- return GP_ENOIMPL;
+ return 1;
/* basic structure and size */
context->pixels = surf->pixels;
@@ -77,87 +106,41 @@ inline GP_RetCode GP_SDL_ContextFromSurface(
context->x_swap = 0;
context->y_swap = 0;
- return GP_ESUCCESS;
-}
-
-static void GP_SDL_ShutdownFn(void)
-{
- dyn_SDL_Quit();
-}
-
-static struct GP_Backend *GP_SDL_InitFn(void)
-{
- void *library = dlopen("libSDL.so", RTLD_LAZY);
- if (!library)
- return NULL;
-
- dyn_SDL_Init = dlsym(library, "SDL_Init");
- dyn_SDL_Quit = dlsym(library, "SDL_Quit");
- dyn_SDL_UpdateRect = dlsym(library, "SDL_UpdateRect");
- dyn_SDL_SetVideoMode = dlsym(library, "SDL_SetVideoMode");
- dyn_SDL_WaitEvent = dlsym(library, "SDL_WaitEvent");
-
- if (dyn_SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0)
- return NULL;
-
- return &GP_SDL_backend;
+ return 0;
}
-static GP_Context *GP_SDL_OpenVideoFn(int w, int h, int flags)
+GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint16_t bpp)
{
- GP_SDL_display = dyn_SDL_SetVideoMode(w, h, 0,
- SDL_SWSURFACE|SDL_DOUBLEBUF);
-
- if (GP_SDL_display == NULL)
- return NULL;
-
- GP_RetCode retcode = GP_SDL_ContextFromSurface(
- &GP_SDL_context, GP_SDL_display);
- if (retcode != GP_ESUCCESS)
- return NULL;
-
- return &GP_SDL_context;
-}
+ /* SDL not yet initalized */
+ if (backend.context != NULL) {
+ if (SDL_Init(SDL_INIT_VIDEO)) {
+ GP_DEBUG(1, "ERROR: SDL_Init: %s", SDL_GetError());
+ return NULL;
+ }
+
+ sdl_surface = SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE);
+
+ if (sdl_surface == NULL) {
+ GP_DEBUG(1, "ERROR: SDL_SetVideoMode: %s", SDL_GetError());
+ SDL_Quit();
+ return NULL;
+ }
+
+ if (context_from_surface(backend.context, sdl_surface)) {
+ GP_DEBUG(1, "ERROR: Failed to match pixel_type");
+ SDL_Quit();
+ return NULL;
+ }
+ }
-static GP_Context *GP_SDL_VideoContextFn(void)
-{
- return &GP_SDL_context;
+ return &backend;
}
-static void GP_SDL_UpdateVideoFn(void)
-{
- dyn_SDL_UpdateRect(GP_SDL_display, 0, 0,
- GP_SDL_display->w, GP_SDL_display->h);
-}
+#else
-static int GP_SDL_GetEventFn(struct GP_BackendEvent *event)
+GP_Backend *GP_BackendSDLInit(void)
{
- SDL_Event sdl_event;
-
- if (dyn_SDL_WaitEvent(&sdl_event) == 0)
- return 0;
-
- switch (sdl_event.type) {
- case SDL_VIDEOEXPOSE:
- event->type = GP_BACKEND_EVENT_UPDATE_VIDEO;
- return 1;
- case SDL_QUIT:
- event->type = GP_BACKEND_EVENT_QUIT_REQUEST;
- return 1;
- }
-
- /* for the time being, unknown events are simply ignored */
- return 0;
+ return NULL;
}
-struct GP_Backend GP_SDL_backend = {
- .name = "SDL",
- .init_fn = GP_SDL_InitFn,
- .shutdown_fn = GP_SDL_ShutdownFn,
- .open_video_fn = GP_SDL_OpenVideoFn,
- .video_context_fn = GP_SDL_VideoContextFn,
- .update_video_fn = GP_SDL_UpdateVideoFn,
- .get_event_fn = GP_SDL_GetEventFn,
-};
-
#endif /* HAVE_LIBSDL */
diff --git a/libs/backends/Makefile b/libs/backends/Makefile
index da08bb7..60bbdaf 100644
--- a/libs/backends/Makefile
+++ b/libs/backends/Makefile
@@ -1,5 +1,6 @@
TOPDIR=../..
CSOURCES=$(shell ls *.c)
LIBNAME=backends
+BUILDLIB=yes
include $(TOPDIR)/include.mk
include $(TOPDIR)/lib.mk
diff --git a/tests/SDL/sierpinsky.c b/tests/SDL/sierpinsky.c
index 04ad559..5d1e0f9 100644
--- a/tests/SDL/sierpinsky.c
+++ b/tests/SDL/sierpinsky.c
@@ -41,7 +41,7 @@
#define sgn(x) ((x)>0 ? 1 : -1)
SDL_Surface *display;
-GP_Context *context;
+GP_Context *context, ctx;
SDL_TimerID timer;
@@ -109,7 +109,7 @@ static void draw(int x, int y, int l, int iter)
sierpinsky(x2, y2, x3, y3, iter/60%6);
sierpinsky(x3, y3, x1, y1, iter/60%6);
- GP_UpdateBackendVideo();
+ SDL_Flip(display);
}
int paused = 0;
@@ -137,16 +137,6 @@ int main(void)
{
SDL_Event ev;
- if (!GP_InitBackend("SDL")) {
- fprintf(stderr, "error: could not initialize backendn");
- return 2;
- }
- if (!GP_OpenBackendVideo(DISPLAY_W, DISPLAY_H, 0)) {
- fprintf(stderr, "error: could not open videon");
- return 2;
- }
-
-/*
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
return -1;
@@ -157,11 +147,9 @@ int main(void)
return -1;
}
- GP_SDL_ContextFromSurface(&context, display);
-*/
+ GP_SDL_ContextFromSurface(&ctx, display);
- display = SDL_GetVideoSurface();
- context = GP_GetBackendVideoContext();
+ context = &ctx;
black = GP_ColorToContextPixel(GP_COL_BLACK, context);
blue = GP_ColorToContextPixel(GP_COL_BLUE, context);
diff --git a/tests/core/Makefile b/tests/core/Makefile
index 56955b9..9cef404 100644
--- a/tests/core/Makefile
+++ b/tests/core/Makefile
@@ -2,7 +2,7 @@ TOPDIR=../..
LIBNAME=core
TESTSUITE=core_suite
-LDLIBS+=-lGP -L$(TOPDIR)/build/ -lcheck -lm -ldl
+LDLIBS+=-lGP -L$(TOPDIR)/build/ -lcheck -lm -lSDL
GENSOURCES+=GP_Convert.test.gen.c GP_WritePixel.test.gen.c GP_MixPixels.test.gen.c
diff --git a/tests/drivers/Makefile b/tests/drivers/Makefile
index afba820..dcf4129 100644
--- a/tests/drivers/Makefile
+++ b/tests/drivers/Makefile
@@ -2,7 +2,7 @@ TOPDIR=../..
CSOURCES=$(shell echo *.c)
-LDLIBS+=-lGP -lGP_SDL -lSDL -L$(TOPDIR)/build/
+LDLIBS+=-lGP -lGP_backends -lSDL -L$(TOPDIR)/build/
APPS=$(CSOURCES:.c=)
diff --git a/tests/drivers/framebuffer_test.c b/tests/drivers/framebuffer_test.c
index c2595d2..29cdb3a 100644
--- a/tests/drivers/framebuffer_test.c
+++ b/tests/drivers/framebuffer_test.c
@@ -16,15 +16,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
/*
- Framebuffer test.
-
- 1. Draw to the framebuffer
+ Backend test.
+
+ 1. Draw to the backend
2. Sleep
3. Exit
@@ -33,7 +33,7 @@
#include <math.h>
#include <GP.h>
-#include <backends/GP_Framebuffer.h>
+#include <backends/GP_Backends.h>
static void draw(GP_Context *context, int x, int y, int l)
{
@@ -57,18 +57,21 @@ static void draw(GP_Context *context, int x, int y, int l)
int main(void)
{
- GP_Framebuffer *fb;
+ GP_Backend *backend;
+ GP_Context *context;
GP_TextStyle style;
GP_SetDebugLevel(10);
- fb = GP_FramebufferInit("/dev/fb0");
+ backend = GP_BackendLinuxFBInit("/dev/fb0");
- if (fb == NULL) {
+ if (backend == NULL) {
fprintf(stderr, "Failed to initalize framebuffern");
return 1;
}
+ context = backend->context;
+
GP_DefaultTextStyle(&style);
style.pixel_xspace = 2;
@@ -76,24 +79,26 @@ int main(void)
GP_Pixel gray, black;
- gray = GP_RGBToContextPixel(200, 200, 200, &fb->context);
- black = GP_RGBToContextPixel(0, 0, 0, &fb->context);
+ gray = GP_RGBToContextPixel(200, 200, 200, context);
+ black = GP_RGBToContextPixel(0, 0, 0, context);
const char *text = "Framebuffer test";
- GP_Fill(&fb->context, gray);
- GP_Line(&fb->context, 0, 0, fb->context.w, fb->context.h, black);
- GP_Line(&fb->context, 0, fb->context.h, fb->context.w, 0, black);
- GP_Text(&fb->context, &style,
- (fb->context.w - GP_TextWidth(&style, text))/2,
+ GP_Fill(context, gray);
+ GP_Line(context, 0, 0, context->w, context->h, black);
+ GP_Line(context, 0, context->h, context->w, 0, black);
+ GP_Text(context, &style,
+ (context->w - GP_TextWidth(&style, text))/2,
16, GP_ALIGN_RIGHT|GP_VALIGN_BELOW, black, gray, text);
- draw(&fb->context, fb->context.w / 2, 2.00 * fb->context.h / 3, 60);
+ draw(context, context->w / 2, 2.00 * context->h / 3, 60);
+
+ GP_BackendFlip(backend);
sleep(10);
- GP_FramebufferExit(fb);
+ GP_BackendExit(backend);
return 0;
}
diff --git a/tests/drivers/sierpinsky.c b/tests/drivers/sierpinsky.c
deleted file mode 100644
index c113e1e..0000000
--- a/tests/drivers/sierpinsky.c
+++ /dev/null
@@ -1,143 +0,0 @@
-/*****************************************************************************
- * 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-2011 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-/*
-
- Simple test for triangle drawing runtime.
-
- */
-
-#include <GP.h>
-#include <backends/GP_Framebuffer.h>
-
-#include <math.h>
-
-#define TIMER_TICK 50
-#define DISPLAY_W 640
-#define DISPLAY_H 480
-#define sqr(x) ((x)*(x))
-#define sgn(x) ((x)>0 ? 1 : -1)
-
-int iter, l, way = 1;
-
-GP_Pixel black, blue, gray;
-
-static void sierpinsky(GP_Context *context, GP_Pixel pixel, float x1, float y1, float x4, float y4, int iter)
-{
- float x2, y2, x3, y3, x5, y5;
-
- if (iter <= 0) {
- GP_Line(context, x1, y1, x4, y4, black);
- return;
- }
-
- x2 = floor((2*x1 + x4)/3);
- y2 = floor((2*y1 + y4)/3);
-
- x3 = floor((2*x4 + x1)/3);
- y3 = floor((2*y4 + y1)/3);
-
- x5 = (x1+x4)/2 + (y2 - y3)*sqrt(3.00/4);
- y5 = (y1+y4)/2 + (x3 - x2)*sqrt(3.00/4);
-
- GP_FillTriangle(context, x2, y2, x3, y3, x5, y5, pixel);
-
- sierpinsky(context, pixel, x1, y1, x2, y2, iter - 1);
- sierpinsky(context, pixel, x2, y2, x5, y5, iter - 1);
- sierpinsky(context, pixel, x5, y5, x3, y3, iter - 1);
- sierpinsky(context, pixel, x3, y3, x4, y4, iter - 1);
-}
-
-static void draw(GP_Context *context, int x, int y, int l, int iter)
-{
- float x1, y1, x2, y2, x3, y3;
- int w = context->w;
- int h = context->h;
-
- l = ((w < h ? w : h) - 20)/(5 - 1.00*iter/120);
-
- x1 = sin(1.00 * iter/57) * l + x;
- y1 = cos(1.00 * iter/57) * l + y;
-
- x2 = sin(1.00 * (iter+120)/57) * l + x;
- y2 = cos(1.00 * (iter+120)/57) * l + y;
-
- x3 = sin(1.00 * (iter+240)/57) * l + x;
- y3 = cos(1.00 * (iter+240)/57) * l + y;
-
- GP_Fill(context, gray);
-
- GP_FillTriangle(context, x1, y1, x2, y2, x3, y3, blue);
-
- sierpinsky(context, blue, x1, y1, x2, y2, iter/60%6);
- sierpinsky(context, blue, x2, y2, x3, y3, iter/60%6);
- sierpinsky(context, blue, x3, y3, x1, y1, iter/60%6);
-}
-
-static void redraw(GP_Context *context)
-{
- iter += 2 * way;
-
- if (iter + 2 * way > 350)
- way *= -1;
-
- if (iter < 2 * way)
- way *= 1;
-
-
- draw(context, context->w/2, context->h/2, l, iter);
-}
-
-int main(void)
-{
- GP_Framebuffer *fb;
- GP_Context *context;
- int i;
-
- GP_SetDebugLevel(10);
-
- fb = GP_FramebufferInit("/dev/fb0");
-
- if (fb == NULL) {
- fprintf(stderr, "failed to initalize framebuffern");
- return 1;
- }
-
- context = &fb->context;
-
- gray = GP_ColorToContextPixel(GP_COL_GRAY_LIGHT, context);
- blue = GP_ColorToContextPixel(GP_COL_BLUE, context);
- black = GP_ColorToContextPixel(GP_COL_BLACK, context);
-
- iter = 0;
- draw(context, context->w/2, context->h/2, l, iter);
-
- for (i = 0; i < 300; i++) {
- redraw(context);
- usleep(10000);
- }
-
- GP_FramebufferExit(fb);
-
- return 0;
-}
-
-----------------------------------------------------------------------
Summary of changes:
build/get_objs.sh | 2 +-
demos/fbshow/Makefile | 2 +-
demos/fbshow/fbshow.c | 81 +++++-----
demos/grinder/Makefile | 2 +-
include/backends/GP_Backend.h | 152 ++++++++++++-----
.../GP_InputDriverSDL.h => backends/GP_Backends.h} | 20 ++-
.../backends/{GP_Framebuffer.h => GP_LinuxFB.h} | 35 ++---
.../GP_InputDriverSDL.h => backends/GP_SDL.h} | 21 +--
libs/backends/GP_Backend.c | 87 ----------
libs/backends/{GP_Framebuffer.c => GP_LinuxFB.c} | 93 ++++++++---
libs/backends/{GP_Backend_SDL.c => GP_SDL.c} | 173 +++++++++-----------
libs/backends/Makefile | 1 +
tests/SDL/sierpinsky.c | 20 +--
tests/core/Makefile | 2 +-
tests/drivers/Makefile | 2 +-
tests/drivers/framebuffer_test.c | 39 +++--
tests/drivers/sierpinsky.c | 143 ----------------
17 files changed, 361 insertions(+), 514 deletions(-)
copy include/{input/GP_InputDriverSDL.h => backends/GP_Backends.h} (83%)
rename include/backends/{GP_Framebuffer.h => GP_LinuxFB.h} (75%)
copy include/{input/GP_InputDriverSDL.h => backends/GP_SDL.h} (82%)
delete mode 100644 libs/backends/GP_Backend.c
rename libs/backends/{GP_Framebuffer.c => GP_LinuxFB.c} (80%)
rename libs/backends/{GP_Backend_SDL.c => GP_SDL.c} (50%)
delete mode 100644 tests/drivers/sierpinsky.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 713e4f3f13172cb63b59ac501b54992a2309b314
by metan 14 Jan '12
by metan 14 Jan '12
14 Jan '12
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 713e4f3f13172cb63b59ac501b54992a2309b314 (commit)
from 03dc78a368cf8724cfaf79b6e149bdbe2d709205 (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/713e4f3f13172cb63b59ac501b54992a2309…
commit 713e4f3f13172cb63b59ac501b54992a2309b314
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jan 14 22:44:23 2012 +0100
input: Fix typos in comment.
diff --git a/include/input/GP_Event.h b/include/input/GP_Event.h
index cb412f1..db4166c 100644
--- a/include/input/GP_Event.h
+++ b/include/input/GP_Event.h
@@ -24,7 +24,7 @@
Gfxprim event layer.
- Events are lowlever interfaace to input devices (human interface).
+ Events are lowlevel interface to input devices (human interface).
- Events are notifications that something has changed, eg. button pressed
- Each event carries some information about global state
-----------------------------------------------------------------------
Summary of changes:
include/input/GP_Event.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0