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 c3b33c14d2263d443554d1b3ac5f43430e148698 (commit) from 6722436c25bf3899cc2c3c2b44ed0382e04a7fff (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/c3b33c14d2263d443554d1b3ac5f43430e148...
commit c3b33c14d2263d443554d1b3ac5f43430e148698 Author: BlueBear jiri.bluebear.dluhos@gmail.com Date: Mon May 9 00:27:21 2011 +0200
First attempt on transparent backends.
diff --git a/core/GP.h b/core/GP.h index 8254d49..77ba1b0 100644 --- a/core/GP.h +++ b/core/GP.h @@ -65,4 +65,7 @@ #include "GP_TextMetric.h" #include "GP_Text.h"
+/* backends */ +#include "GP_Backend.h" + #endif /* GP_H */ diff --git a/core/GP.h b/core/GP_Backend.c similarity index 65% copy from core/GP.h copy to core/GP_Backend.c index 8254d49..f1cbce5 100644 --- a/core/GP.h +++ b/core/GP_Backend.c @@ -23,46 +23,56 @@ * * *****************************************************************************/
-#ifndef GP_H -#define GP_H +#include "GP.h" +#include "config.h"
-#include <stdint.h> +#include <string.h>
-/* basic definitions and structures */ -#include "GP_Common.h" -#include "GP_Transform.h" -#include "GP_Context.h" +/* The current backend. */ +static struct GP_Backend *current_backend = NULL;
-/* semi-public, low-level drawing API */ -#include "GP_WritePixel.h" +#ifdef GP_HAVE_SDL
-/* colors */ -#include "GP_Color.h" -#include "GP_Palette.h" +extern struct GP_Backend GP_SDL_backend;
-/* public drawing API */ -#include "GP_Fill.h" -#include "GP_GetPixel.h" -#include "GP_PutPixel.h" -#include "GP_HLine.h" -#include "GP_VLine.h" -#include "GP_Line.h" -#include "GP_LineTrack.h" -#include "GP_Rect.h" -#include "GP_FillRect.h" -#include "GP_Triangle.h" -#include "GP_Tetragon.h" -#include "GP_Circle.h" -#include "GP_FillCircle.h" -#include "GP_Ellipse.h" -#include "GP_FillEllipse.h" -#include "GP_Polygon.h" -#include "GP_Symbol.h" +#endif
-/* fonts */ -#include "GP_Font.h" -#include "GP_TextStyle.h" -#include "GP_TextMetric.h" -#include "GP_Text.h" +struct GP_Backend *GP_InitBackend(const char *name) +{ + if (current_backend) + return current_backend;
-#endif /* GP_H */ +#ifdef GP_HAVE_SDL + + 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(); +} diff --git a/core/GP.h b/core/GP_Backend.h similarity index 64% copy from core/GP.h copy to core/GP_Backend.h index 8254d49..afe7f67 100644 --- a/core/GP.h +++ b/core/GP_Backend.h @@ -23,46 +23,46 @@ * * *****************************************************************************/
-#ifndef GP_H -#define GP_H +#ifndef GP_BACKEND_H +#define GP_BACKEND_H
-#include <stdint.h> - -/* basic definitions and structures */ -#include "GP_Common.h" -#include "GP_Transform.h" #include "GP_Context.h"
-/* semi-public, low-level drawing API */ -#include "GP_WritePixel.h" +struct GP_Backend { + 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); +}; + +/* + * 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 is picked. + * + * Returns the backend structure, or NULL on failure. + */ +struct GP_Backend *GP_InitBackend(const char *name);
-/* colors */ -#include "GP_Color.h" -#include "GP_Palette.h" +/* + * Opens the backend video and returns its context. + */ +GP_Context *GP_OpenBackendVideo(int w, int h, int flags);
-/* public drawing API */ -#include "GP_Fill.h" -#include "GP_GetPixel.h" -#include "GP_PutPixel.h" -#include "GP_HLine.h" -#include "GP_VLine.h" -#include "GP_Line.h" -#include "GP_LineTrack.h" -#include "GP_Rect.h" -#include "GP_FillRect.h" -#include "GP_Triangle.h" -#include "GP_Tetragon.h" -#include "GP_Circle.h" -#include "GP_FillCircle.h" -#include "GP_Ellipse.h" -#include "GP_FillEllipse.h" -#include "GP_Polygon.h" -#include "GP_Symbol.h" +/* + * Returns a pointer to context that represents the backend's video. + */ +GP_Context *GP_GetBackendVideoContext(void);
-/* fonts */ -#include "GP_Font.h" -#include "GP_TextStyle.h" -#include "GP_TextMetric.h" -#include "GP_Text.h" +/* + * 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. + */ +void GP_UpdateBackendVideo(void);
-#endif /* GP_H */ +#endif diff --git a/core/GP_Backend_SDL.c b/core/GP_Backend_SDL.c new file mode 100644 index 0000000..17a3d20 --- /dev/null +++ b/core/GP_Backend_SDL.c @@ -0,0 +1,211 @@ +/***************************************************************************** + * 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-2010 Jiri "BlueBear" Dluhos * + * jiri.bluebear.dluhos@gmail.com * + * * + * Copyright (C) 2009-2010 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include "GP.h" +#include "config.h" + +#ifdef GP_HAVE_SDL + +#include <dlfcn.h> +#include <SDL/SDL.h> + +struct GP_Backend GP_SDL_backend; + +/* + * Checks whether pixel color component masks in the given surface are equal + * to specified. Returns nonzero if they match, zero otherwise. + */ +static int GP_SDL_CheckPixelMasks(SDL_Surface *surf, unsigned int rmask, + unsigned int gmask, unsigned int bmask, unsigned int amask) +{ + return (surf->format->Rmask == rmask + && surf->format->Gmask == gmask + && surf->format->Bmask == bmask + && surf->format->Ashift == amask); +} + +/* + * Detects the pixel type of the SDL surface. + * Returns the pixel type, or GP_PIXEL_UNKNOWN if the type was not recognized. + */ +static enum GP_PixelType GP_SDL_FindSurfacePixelType(SDL_Surface *surf) +{ + switch (surf->format->BytesPerPixel) { + case 1: + if (GP_SDL_CheckPixelMasks(surf, 0, 0, 0, 0)) { + return GP_PIXEL_PAL8; + } + break; + case 2: + if (GP_SDL_CheckPixelMasks(surf, 0x7c00, 0x03e0, 0x001f, 0)) { + return GP_PIXEL_RGB555; + } + if (GP_SDL_CheckPixelMasks(surf, 0xf800, 0x07e0, 0x001f, 0)) { + return GP_PIXEL_RGB565; + } + break; + case 3: + if (GP_SDL_CheckPixelMasks(surf, 0xff0000, 0xff00, 0xff, 0)) { + return GP_PIXEL_RGB888; + } + if (GP_SDL_CheckPixelMasks(surf, 0xff, 0xff00, 0xff0000, 0)) { + return GP_PIXEL_BGR888; + } + break; + case 4: + if (GP_SDL_CheckPixelMasks(surf, 0xff0000, 0xff00, 0xff, 0)) { + return GP_PIXEL_XRGB8888; + } + if (GP_SDL_CheckPixelMasks(surf, 0xff, 0xff00, 0xff0000, 0)) { + return GP_PIXEL_XBGR8888; + } + if (GP_SDL_CheckPixelMasks(surf, 0xff000000, 0xff0000, 0xff00, 0)) { + return GP_PIXEL_RGBX8888; + } + if (GP_SDL_CheckPixelMasks(surf, 0xff00, 0xff0000, 0xff000000, 0)) { + return GP_PIXEL_BGRX8888; + } + if (GP_SDL_CheckPixelMasks(surf, 0xff0000, 0xff00, 0xff, 0xff000000)) { + return GP_PIXEL_ARGB8888; + } + if (GP_SDL_CheckPixelMasks(surf, 0xff, 0xff00, 0xff0000, 0xff000000)) { + return GP_PIXEL_ABGR8888; + } + if (GP_SDL_CheckPixelMasks(surf, 0xff000000, 0xff0000, 0xff00, 0xff)) { + return GP_PIXEL_RGBA8888; + } + if (GP_SDL_CheckPixelMasks(surf, 0xff00, 0xff0000, 0xff000000, 0xff)) { + return GP_PIXEL_BGRA8888; + } + break; + + } + return GP_PIXEL_UNKNOWN; +} + +inline GP_RetCode GP_SDL_ContextFromSurface( + GP_Context *context, SDL_Surface *surf) +{ + GP_CHECK(context, "context is NULL"); + GP_CHECK(surf, "surface is NULL"); + + /* sanity checks on the SDL surface */ + if (surf->format->BytesPerPixel == 0 || surf->format->BytesPerPixel > 4) { + return GP_ENOIMPL; + } + enum GP_PixelType pixeltype = GP_SDL_FindSurfacePixelType(surf); + if (pixeltype == GP_PIXEL_UNKNOWN) { + return GP_ENOIMPL; + } + + /* basic structure and size */ + context->pixels = surf->pixels; + context->bpp = 8 * surf->format->BytesPerPixel; + context->pixel_type = pixeltype; + context->bytes_per_row = surf->pitch; + context->w = surf->w; + context->h = surf->h; + + /* orientation */ + context->axes_swap = 0; + context->x_swap = 0; + context->y_swap = 0; + + /* clipping */ + context->clip_h_min = surf->clip_rect.y; + context->clip_h_max = surf->clip_rect.y + surf->clip_rect.h - 1; + context->clip_w_min = surf->clip_rect.x; + context->clip_w_max = surf->clip_rect.x + surf->clip_rect.w - 1; + + return GP_ESUCCESS; +} + +static SDL_Surface *GP_SDL_display = NULL; +static GP_Context GP_SDL_context; + +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 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"); + + if (dyn_SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0) + return NULL; + + return &GP_SDL_backend; +} + +static GP_Context *GP_SDL_OpenVideoFn(int w, int h, int flags) +{ + 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; +} + +static GP_Context *GP_SDL_VideoContextFn(void) +{ + return &GP_SDL_context; +} + +static void GP_SDL_UpdateVideoFn(void) +{ + dyn_SDL_UpdateRect(GP_SDL_display, 0, 0, + GP_SDL_display->w, GP_SDL_display->h); +} + +struct GP_Backend GP_SDL_backend = { + "SDL", + GP_SDL_InitFn, + GP_SDL_ShutdownFn, + GP_SDL_OpenVideoFn, + GP_SDL_VideoContextFn, + GP_SDL_UpdateVideoFn +}; + +#endif /* GP_HAVE_SDL */ diff --git a/core/config.h b/core/config.h new file mode 100644 index 0000000..baac35b --- /dev/null +++ b/core/config.h @@ -0,0 +1,3 @@ + +#define GP_HAVE_SDL 1 +
-----------------------------------------------------------------------
Summary of changes: core/GP.h | 3 + core/{GP_LineTrack.c => GP_Backend.c} | 80 +++++++------- filters/GP_Rotate.h => core/GP_Backend.h | 46 +++++--- .../sdl/GP_SDL_Context.c => core/GP_Backend_SDL.c | 121 ++++++++++++++++---- core/config.h | 3 + 5 files changed, 173 insertions(+), 80 deletions(-) copy core/{GP_LineTrack.c => GP_Backend.c} (66%) copy filters/GP_Rotate.h => core/GP_Backend.h (65%) copy targets/sdl/GP_SDL_Context.c => core/GP_Backend_SDL.c (56%) create mode 100644 core/config.h
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.