242 lines
7.0 KiB
C
242 lines
7.0 KiB
C
#include "evas_engine.h"
|
|
|
|
static Evas_GL_X11_Window *_evas_gl_x11_window = NULL;
|
|
|
|
#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
|
|
static EGLContext context = EGL_NO_CONTEXT;
|
|
#else
|
|
// FIXME: this will only work for 1 display connection (glx land can have > 1)
|
|
static GLXContext context = NULL;
|
|
#endif
|
|
|
|
XVisualInfo *_evas_gl_x11_vi = NULL;
|
|
Colormap _evas_gl_x11_cmap = 0;
|
|
|
|
Evas_GL_X11_Window *
|
|
eng_window_new(Display *disp,
|
|
Window win,
|
|
int screen,
|
|
Visual *vis,
|
|
Colormap cmap,
|
|
int depth,
|
|
int w,
|
|
int h)
|
|
{
|
|
Evas_GL_X11_Window *gw;
|
|
int context_attrs[3];
|
|
int config_attrs[20];
|
|
int major_version, minor_version;
|
|
int num_config;
|
|
|
|
if (!_evas_gl_x11_vi) return NULL;
|
|
|
|
gw = calloc(1, sizeof(Evas_GL_X11_Window));
|
|
if (!gw) return NULL;
|
|
gw->disp = disp;
|
|
gw->win = win;
|
|
gw->screen = screen;
|
|
gw->visual = vis;
|
|
gw->colormap = cmap;
|
|
gw->depth = depth;
|
|
|
|
gw->visualinfo = _evas_gl_x11_vi;
|
|
|
|
// EGL / GLES
|
|
#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
|
|
context_attrs[0] = EGL_CONTEXT_CLIENT_VERSION;
|
|
context_attrs[1] = 2;
|
|
context_attrs[2] = EGL_NONE;
|
|
# if defined(GLES_VARIETY_S3C6410)
|
|
if (_evas_gles_x11_vi->depth == 16) // 16bpp
|
|
{
|
|
config_attrs[0] = EGL_SURFACE_TYPE;
|
|
config_attrs[1] = EGL_WINDOW_BIT;
|
|
config_attrs[2] = EGL_RENDERABLE_TYPE;
|
|
config_attrs[3] = EGL_OPENGL_ES2_BIT;
|
|
config_attrs[4] = EGL_RED_SIZE;
|
|
config_attrs[5] = 5;
|
|
config_attrs[6] = EGL_GREEN_SIZE;
|
|
config_attrs[7] = 6;
|
|
config_attrs[8] = EGL_BLUE_SIZE;
|
|
config_attrs[9] = 5;
|
|
config_attrs[10] = EGL_NONE;
|
|
}
|
|
else // 24/32bit. no one does 8bpp anymore. and 15bpp... dead
|
|
{
|
|
config_attrs[0] = EGL_SURFACE_TYPE;
|
|
config_attrs[1] = EGL_WINDOW_BIT;
|
|
config_attrs[2] = EGL_RENDERABLE_TYPE;
|
|
config_attrs[3] = EGL_OPENGL_ES2_BIT;
|
|
config_attrs[4] = EGL_RED_SIZE;
|
|
config_attrs[5] = 8;
|
|
config_attrs[6] = EGL_GREEN_SIZE;
|
|
config_attrs[7] = 8;
|
|
config_attrs[8] = EGL_BLUE_SIZE;
|
|
config_attrs[9] = 8;
|
|
config_attrs[10] = EGL_DEPTH_SIZE;
|
|
config_attrs[11] = 24;
|
|
config_attrs[12] = EGL_NONE;
|
|
}
|
|
# elif defined(GLES_VARIETY_SGX)
|
|
context_attrs[0] = EGL_CONTEXT_CLIENT_VERSION;
|
|
context_attrs[1] = 2;
|
|
context_attrs[2] = EGL_NONE;
|
|
|
|
config_attrs[0] = EGL_SURFACE_TYPE;
|
|
config_attrs[1] = EGL_WINDOW_BIT;
|
|
config_attrs[2] = EGL_RENDERABLE_TYPE;
|
|
config_attrs[3] = EGL_OPENGL_ES2_BIT;
|
|
config_attrs[4] = EGL_NONE;
|
|
# endif
|
|
gw->egl_disp= eglGetDisplay((EGLNativeDisplayType)(gw->disp));
|
|
if (!gw->egl_disp)
|
|
{
|
|
printf("Error: eglGetDisplay() fail.\n");
|
|
}
|
|
if (!eglInitialize(gw->egl_disp, &major_version, &minor_version))
|
|
{
|
|
printf("Error: eglInitialize() fail.\n");
|
|
}
|
|
eglBindAPI(EGL_OPENGL_ES_API);
|
|
if (eglGetError() != EGL_SUCCESS)
|
|
{
|
|
printf("Error: eglBindAPI() fail.\n");
|
|
}
|
|
if (!eglChooseConfig(gw->egl_disp, config_attrs, &gw->egl_config,
|
|
1, &num_config) || (num_config != 1))
|
|
{
|
|
printf("Error: eglChooseConfig() fail.\n");
|
|
}
|
|
gw->egl_surface[0] = eglCreateWindowSurface(gw->egl_disp, gw->egl_config,
|
|
(EGLNativeWindowType)gw->win,
|
|
NULL);
|
|
if (gw->egl_surface[0] == EGL_NO_SURFACE)
|
|
{
|
|
printf("Error: eglCreateWindowSurface() fail.\n", gw->win);
|
|
}
|
|
if (context == EGL_NO_CONTEXT)
|
|
context = eglCreateContext(gw->egl_disp, gw->egl_config, NULL,
|
|
context_attrs);
|
|
gw->egl_context[0] = context;
|
|
if (gw->egl_context[0] == EGL_NO_CONTEXT)
|
|
{
|
|
printf("Error: eglCreateContext() fail.\n");
|
|
}
|
|
if (eglMakeCurrent(gw->egl_disp,
|
|
gw->egl_surface[0],
|
|
gw->egl_surface[0],
|
|
gw->egl_context[0]) == EGL_FALSE)
|
|
{
|
|
printf("Error: eglMakeCurrent() fail.\n");
|
|
}
|
|
// GLX
|
|
#else
|
|
if (!context)
|
|
context = glXCreateContext(disp, gw->visualinfo, NULL, GL_TRUE);
|
|
gw->context = context;
|
|
glXMakeCurrent(gw->disp, gw->win, gw->context);
|
|
#endif
|
|
|
|
gw->gl_context = evas_gl_common_context_new();
|
|
if (!gw->gl_context)
|
|
{
|
|
free(gw);
|
|
return NULL;
|
|
}
|
|
evas_gl_common_context_resize(gw->gl_context, w, h);
|
|
return gw;
|
|
}
|
|
|
|
void
|
|
eng_window_free(Evas_GL_X11_Window *gw)
|
|
{
|
|
if (gw == _evas_gl_x11_window) _evas_gl_x11_window = NULL;
|
|
evas_gl_common_context_free(gw->gl_context);
|
|
#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
|
|
if (gw->egl_surface[0] != EGL_NO_SURFACE)
|
|
eglDestroySurface(gw->egl_disp, gw->egl_surface[0]);
|
|
#else
|
|
// FIXME: refcount context
|
|
// glXDestroyContext(gw->disp, gw->context);
|
|
#endif
|
|
free(gw);
|
|
}
|
|
|
|
void
|
|
eng_window_use(Evas_GL_X11_Window *gw)
|
|
{
|
|
if (_evas_gl_x11_window != gw)
|
|
{
|
|
_evas_gl_x11_window = gw;
|
|
// EGL / GLES
|
|
#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
|
|
if (eglMakeCurrent(gw->egl_disp,
|
|
gw->egl_surface[0],
|
|
gw->egl_surface[0],
|
|
gw->egl_context[0]) == EGL_FALSE)
|
|
{
|
|
printf("Error: eglMakeCurrent() failed!\n");
|
|
}
|
|
// GLX
|
|
#else
|
|
glXMakeCurrent(gw->disp, gw->win, gw->context);
|
|
#endif
|
|
}
|
|
evas_gl_common_context_use(gw->gl_context);
|
|
}
|
|
|
|
Visual *
|
|
eng_best_visual_get(Display *disp, int screen)
|
|
{
|
|
if (!disp) return NULL;
|
|
if (!_evas_gl_x11_vi)
|
|
{
|
|
// EGL / GLES
|
|
#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
|
|
int depth = DefaultDepth(disp, screen);
|
|
_evas_gl_x11_vi = calloc(1, sizeof(XVisualInfo));
|
|
XMatchVisualInfo(disp, screen, depth, TrueColor, _evas_gl_x11_vi);
|
|
// GLX
|
|
#else
|
|
int _evas_gl_x11_configuration[9] =
|
|
{
|
|
GLX_DOUBLEBUFFER,
|
|
GLX_RGBA,
|
|
GLX_RED_SIZE, 1,
|
|
GLX_GREEN_SIZE, 1,
|
|
GLX_BLUE_SIZE, 1,
|
|
None
|
|
};
|
|
_evas_gl_x11_vi = glXChooseVisual(disp, screen,
|
|
_evas_gl_x11_configuration);
|
|
#endif
|
|
}
|
|
if (!_evas_gl_x11_vi) return NULL;
|
|
return _evas_gl_x11_vi->visual;
|
|
}
|
|
|
|
Colormap
|
|
eng_best_colormap_get(Display *disp, int screen)
|
|
{
|
|
if (!disp) return 0;
|
|
if (!_evas_gl_x11_vi) eng_best_visual_get(disp, screen);
|
|
if (!_evas_gl_x11_vi) return 0;
|
|
if (!_evas_gl_x11_cmap)
|
|
{
|
|
_evas_gl_x11_cmap = XCreateColormap(disp,
|
|
RootWindow(disp, screen),
|
|
_evas_gl_x11_vi->visual,
|
|
0);
|
|
}
|
|
return _evas_gl_x11_cmap;
|
|
}
|
|
|
|
int
|
|
eng_best_depth_get(Display *disp, int screen)
|
|
{
|
|
if (!disp) return 0;
|
|
if (!_evas_gl_x11_vi) eng_best_visual_get(disp, screen);
|
|
if (!_evas_gl_x11_vi) return 0;
|
|
return _evas_gl_x11_vi->depth;
|
|
}
|