this is the start of something inteteresting. it is the start of using

egl with software rendering only (no gl just egl). ie get access to
buffer and do swaps etc. etc. etc. it's meant to be totally dynamic -
ie dlopen libEGL if u have it and then start checking if it can do
this thing so it doesnt add any dependencies at all.



SVN revision: 77043
This commit is contained in:
Carsten Haitzler 2012-09-25 05:44:43 +00:00
parent 45d4f2a3f2
commit 06fa0ad166
3 changed files with 290 additions and 3 deletions

View File

@ -3,7 +3,9 @@ MAINTAINERCLEANFILES = Makefile.in
if BUILD_ENGINE_SOFTWARE_X11
SOFTWARE_X11_SOURCES = evas_engine.c
SOFTWARE_X11_SOURCES = \
evas_engine.c \
evas_x_egl.c
if BUILD_ENGINE_SOFTWARE_XLIB
@ -25,7 +27,7 @@ evas_xlib_buffer.c \
evas_xlib_color.c \
evas_xlib_main.c
SOFTWARE_X11_LIBADD = @FREETYPE_LIBS@ @EVAS_GENERAL_LIBS@ @evas_engine_software_xlib_libs@
SOFTWARE_X11_LIBADD = @FREETYPE_LIBS@ @EVAS_GENERAL_LIBS@ @evas_engine_software_xlib_libs@ @dlopen_libs@
endif
@ -49,7 +51,7 @@ evas_xcb_buffer.c \
evas_xcb_color.c \
evas_xcb_main.c
SOFTWARE_X11_LIBADD = @FREETYPE_LIBS@ @PIXMAN_LIBS@ @EVAS_GENERAL_LIBS@ @evas_engine_software_xcb_libs@
SOFTWARE_X11_LIBADD = @FREETYPE_LIBS@ @PIXMAN_LIBS@ @EVAS_GENERAL_LIBS@ @evas_engine_software_xcb_libs@ @dlopen_libs@
endif

View File

@ -15,6 +15,8 @@
# include "evas_xcb_xdefaults.h"
#endif
#include "evas_x_egl.h"
int _evas_engine_soft_x11_log_dom = -1;
/* function tables - filled in later (func and parent func) */
@ -63,6 +65,38 @@ static void eng_output_idle_flush(void *data);
/* internal engine routines */
#ifdef BUILD_ENGINE_SOFTWARE_XLIB
static void *
_output_egl_setup(int w, int h, int rot, Display *disp, Drawable draw,
Visual *vis, Colormap cmap, int depth, int debug,
int grayscale, int max_colors, Pixmap mask,
int shape_dither, int destination_alpha)
{
Render_Engine *re;
if (!(re = calloc(1, sizeof(Render_Engine)))) return NULL;
// _egl_x_disp_get()
// then
// _egl_x_disp_init()
// then
// _egl_x_disp_choose_config()
// then
// _egl_x_win_surf_new()
//
// and on cleaup
//
// _egl_x_win_surf_free()
//
// to access pixels
//
// _egl_x_map_surf()
//
// to give back pixels
//
// _egl_x_unmap_surf()
return re;
}
static void *
_output_xlib_setup(int w, int h, int rot, Display *disp, Drawable draw,
Visual *vis, Colormap cmap, int depth, int debug,

View File

@ -0,0 +1,251 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef EVAS_CSERVE2
#include "evas_cs2_private.h"
#endif
#include "evas_common.h"
#include "evas_macros.h"
#include "evas_x_egl.h"
#ifdef HAVE_DLSYM
# include <dlfcn.h> /* dlopen,dlclose,etc */
#else
# undef BUILD_ENGINE_SOFTWARE_XLIB
#endif
#ifdef BUILD_ENGINE_SOFTWARE_XLIB
#define EGL_SURFACE_TYPE 0x3033
#define EGL_WINDOW_BIT 0x0004
#define EGL_RENDERABLE_TYPE 0x3040
#define EGL_ALPHA_SIZE 0x3021
#define EGL_BLUE_SIZE 0x3022
#define EGL_GREEN_SIZE 0x3023
#define EGL_RED_SIZE 0x3024
#define EGL_DEPTH_SIZE 0x3025
#define EGL_STENCIL_SIZE 0x3026
#define EGL_SURFACE_TYPE 0x3033
#define EGL_NONE 0x3038
#define EGL_FALSE 0
#define EGL_TRUE 1
#define EGL_NATIVE_BIT 0x0010
#define EGL_LOCK_SURFACE_BIT_KHR 0x0080
#define EGL_OPTIMAL_FORMAT_BIT_KHR 0x0100
#define EGL_MATCH_FORMAT_KHR 0x3043
#define EGL_FORMAT_RGB_565_EXACT_KHR 0x30C0
#define EGL_FORMAT_RGB_565_KHR 0x30C1
#define EGL_FORMAT_RGBA_8888_EXACT_KHR 0x30C2
#define EGL_FORMAT_RGBA_8888_KHR 0x30C3
#define EGL_MAP_PRESERVE_PIXELS_KHR 0x30C4
#define EGL_LOCK_USAGE_HINT_KHR 0x30C5
#define EGL_READ_SURFACE_BIT_KHR 0x0001
#define EGL_WRITE_SURFACE_BIT_KHR 0x0002
#define EGL_BITMAP_POINTER_KHR 0x30C6
#define EGL_BITMAP_PITCH_KHR 0x30C7
#define EGL_BITMAP_ORIGIN_KHR 0x30C8
#define EGL_BITMAP_PIXEL_RED_OFFSET_KHR 0x30C9
#define EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR 0x30CA
#define EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR 0x30CB
#define EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR 0x30CC
#define EGL_BITMAP_PIXEL_LUMINANCE_OFFSET_KHR 0x30CD
#define EGL_LOWER_LEFT_KHR 0x30CE
#define EGL_UPPER_LEFT_KHR 0x30CF
static int egl_found = -1;
static void *egl_lib = NULL;
static struct {
void * (*GetProcAddress) (const char *name);
void * (*GetDisplay) (void *d);
unsigned int (*Initialize) (void *ed, int *vmaj, int *vmin);
unsigned int (*Terminate) (void *ed);
const char * (*QueryString) (void *ed, int name);
unsigned int (*ChooseConfig) (void *ed, int *attr, void **configs, int config_size, int *num_config);
unsigned int (*GetConfigAttrib) (void *ed, void *config, int attr, int *val);
unsigned int (*QuerySurface) (void *ed, void *surf, int attr, int *val);
void * (*CreateWindowSurface) (void *ed, void *config, Window win, int *attr);
unsigned int (*DestroySurface) (void *ed, void *surf);
unsigned int (*LockSurface) (void *ed, void *surf, int *attr);
unsigned int (*UnlockSurface) (void *ed, void *surf);
} egl;
static int
_egl_find(void)
{
if (egl_found == 0) return 0;
if (!egl_lib) egl_lib = dlopen("libEGL.so.1", RTLD_NOW | RTLD_LOCAL);
if (!egl_lib)
{
egl_found = 0;
return 0;
}
if (!(egl.GetProcAddress = dlsym(egl_lib, "eglGetProcAddress"))) goto err;
#define SYM(x, y) if (!(egl.x = egl.GetProcAddress(y))) goto err
// core syms used
SYM(GetDisplay , "eglGetDisplay");
SYM(Initialize, "eglInitialize");
SYM(Terminate, "eglTerminate");
SYM(QueryString, "eglQueryString");
SYM(ChooseConfig, "eglChooseConfig");
SYM(UnlockSurface, "eglGetConfigAttrib");
SYM(QuerySurface, "eglQuerySurface");
SYM(CreateWindowSurface, "eglCreateWindowSurface");
SYM(DestroySurface, "eglDestroySurface");
#undef SYM
#define SYM(x, y) egl.x = egl.GetProcAddress(y)
// extns
SYM(LockSurface, "eglLockSurface");
if (!egl.LockSurface) SYM(LockSurface, "eglLockSurfaceKHR");
SYM(UnlockSurface, "eglUnlockSurface");
if (!egl.UnlockSurface) SYM(UnlockSurface, "eglUnlockSurfaceKHR");
if (!egl.LockSurface) goto err;
if (!egl.UnlockSurface) goto err;
egl_found = 1;
return 1;
err:
if (egl_lib) dlclose(egl_lib);
egl_lib = NULL;
return 0;
}
#endif
void *
_egl_x_disp_get(void *d)
{
#ifdef BUILD_ENGINE_SOFTWARE_XLIB
if (!_egl_find()) return NULL;
return egl.GetDisplay(d);
#else
return NULL;
#endif
}
int
_egl_x_disp_init(void *ed)
{
#ifdef BUILD_ENGINE_SOFTWARE_XLIB
int vmaj = 0, vmin = 0;
if (!_egl_find()) return 0;
if (!egl.Initialize(ed, &vmaj, &vmin)) return 0;
return 1;
#else
return 0;
#endif
}
void *
_egl_x_disp_choose_config(void *ed)
{
#ifdef BUILD_ENGINE_SOFTWARE_XLIB
int config_attrs[40], n = 0, num_config = 0;
void *eglconfig = NULL;
if (!_egl_find()) return NULL;
config_attrs[n++] = EGL_SURFACE_TYPE;
config_attrs[n++] = EGL_WINDOW_BIT;
config_attrs[n++] = EGL_RENDERABLE_TYPE;
config_attrs[n++] = EGL_NATIVE_BIT;
config_attrs[n++] = EGL_RED_SIZE;
config_attrs[n++] = 8;
config_attrs[n++] = EGL_GREEN_SIZE;
config_attrs[n++] = 8;
config_attrs[n++] = EGL_BLUE_SIZE;
config_attrs[n++] = 8;
config_attrs[n++] = EGL_ALPHA_SIZE;
config_attrs[n++] = 8;
config_attrs[n++] = EGL_DEPTH_SIZE;
config_attrs[n++] = 0;
config_attrs[n++] = EGL_STENCIL_SIZE;
config_attrs[n++] = 0;
config_attrs[n++] = EGL_SURFACE_TYPE;
config_attrs[n++] = EGL_LOCK_SURFACE_BIT_KHR;
config_attrs[n++] = EGL_MATCH_FORMAT_KHR;
config_attrs[n++] = EGL_FORMAT_RGBA_8888_KHR;
config_attrs[n++] = EGL_NONE;
if (!egl.ChooseConfig(ed, config_attrs, &eglconfig, 1, &num_config))
return NULL;
return eglconfig;
#else
return NULL;
#endif
}
void *
_egl_x_win_surf_new(void *ed, Window win, void *config)
{
#ifdef BUILD_ENGINE_SOFTWARE_XLIB
if (!_egl_find()) return NULL;
return egl.CreateWindowSurface(ed, config, win, NULL);
#else
return NULL;
#endif
}
void
_egl_x_win_surf_free(void *ed, void *surf)
{
#ifdef BUILD_ENGINE_SOFTWARE_XLIB
if (!_egl_find()) return;
egl.DestroySurface(ed, surf);
#endif
}
void *
_egl_x_map_surf(void *ed, void *surf, int *stride)
{
#ifdef BUILD_ENGINE_SOFTWARE_XLIB
int config_attrs[40], n = 0;
void *ptr = NULL;
int pitch = 0, origin = 0;
int r_offset = 0, g_offset = 0, b_offset = 0, a_offset = 0;
if (!_egl_find()) return NULL;
config_attrs[n++] = EGL_MAP_PRESERVE_PIXELS_KHR;
config_attrs[n++] = EGL_TRUE;
config_attrs[n++] = EGL_LOCK_USAGE_HINT_KHR;
config_attrs[n++] = EGL_READ_SURFACE_BIT_KHR | EGL_WRITE_SURFACE_BIT_KHR;
config_attrs[n++] = EGL_NONE;
if (!egl.LockSurface(ed, surf, config_attrs)) return NULL;
if (!egl.QuerySurface(ed, surf, EGL_BITMAP_POINTER_KHR, (int *)&ptr)) goto err;
if (!egl.QuerySurface(ed, surf, EGL_BITMAP_PITCH_KHR, &pitch)) goto err;
if (!egl.QuerySurface(ed, surf, EGL_BITMAP_ORIGIN_KHR, &origin)) goto err;
if (!egl.QuerySurface(ed, surf, EGL_BITMAP_PIXEL_RED_OFFSET_KHR, &r_offset)) goto err;
if (!egl.QuerySurface(ed, surf, EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR, &g_offset)) goto err;
if (!egl.QuerySurface(ed, surf, EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR, &b_offset)) goto err;
if (!egl.QuerySurface(ed, surf, EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR, &a_offset)) goto err;
if (!ptr) goto err;
if (pitch <= 0) goto err;
// need to check rgb offset matiching sw pixel fmt
// do we add origin to ptr?
// is pitch in bytes?
*stride = pitch;
return ptr;
err:
egl.UnlockSurface(ed, surf);
return NULL;
#else
return NULL;
#endif
}
void
_egl_x_unmap_surf(void *ed, void *surf)
{
#ifdef BUILD_ENGINE_SOFTWARE_XLIB
egl.UnlockSurface(ed, surf);
#endif
}