From: Adrián Arroyo Calle <adrian.arroyoca...@gmail.com> --- src/egl/drivers/haiku/egl_haiku.cpp | 175 +++++++++++++++++------------------ src/egl/main/eglapi.c | 2 + 2 files changed, 87 insertions(+), 90 deletions(-)
diff --git a/src/egl/drivers/haiku/egl_haiku.cpp b/src/egl/drivers/haiku/egl_haiku.cpp index eaee11e..a35ddda 100644 --- a/src/egl/drivers/haiku/egl_haiku.cpp +++ b/src/egl/drivers/haiku/egl_haiku.cpp @@ -37,10 +37,16 @@ extern "C" { #include "egllog.h" #include "eglsurface.h" #include "eglimage.h" +#include "egltypedefs.h" } #include <InterfaceKit.h> +#include <OpenGLKit.h> + +#define CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T)) + +_EGL_DRIVER_STANDARD_TYPECASTS(haiku_egl) struct haiku_egl_driver { @@ -58,6 +64,11 @@ struct haiku_egl_context { _EGLContext ctx; }; +struct haiku_egl_surface +{ + _EGLSurface surf; + BGLView* gl; +}; /*static void swrastCreateDrawable(struct dri2_egl_display * dri2_dpy, struct dri2_egl_surface * dri2_surf, @@ -138,9 +149,20 @@ haiku_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, void *native_window, const EGLint *attrib_list) { - //BWindow* win=new BWindow(BRect(100,100,500,500),NULL); - //win->Show(); - return NULL; + struct haiku_egl_surface* surface; + surface=(struct haiku_egl_surface*)calloc(1,sizeof (*surface)); + _eglInitSurface(&surface->surf, disp, EGL_WINDOW_BIT, conf, attrib_list); + (&surface->surf)->SwapInterval = 1; + _eglLog(_EGL_DEBUG, "Creating window"); + //BWindow* win=new BWindow(BRect(100,100,500,500),"EGL",B_TITLED_WINDOW,0); + BWindow* win=(BWindow*)native_window; + _eglLog(_EGL_DEBUG, "Creating GL view"); + surface->gl=new BGLView(win->Bounds(),"OpenGL",B_FOLLOW_ALL_SIDES,0,BGL_RGB | BGL_DOUBLE | BGL_ALPHA); + _eglLog(_EGL_DEBUG, "Adding GL"); + win->AddChild(surface->gl); + _eglLog(_EGL_DEBUG, "Showing window"); + win->Show(); + return &surface->surf; } static _EGLSurface * @@ -167,67 +189,52 @@ static EGLBoolean haiku_add_configs_for_visuals(_EGLDisplay *dpy) { printf("Adding configs\n"); - /*EGLint config_attrs[] = { - EGL_NATIVE_VISUAL_ID, 0, - EGL_NATIVE_VISUAL_TYPE, 0, - EGL_NONE - }; - static const unsigned int rgb_masks[4] = { 0xff0000, 0xff00, 0xff, 0 }; - dri2_add_config(dpy,dri2_dpy->driver_configs[0],1, - EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT | - EGL_SWAP_BEHAVIOR_PRESERVED_BIT,config_attrs,rgb_masks);*/ - struct haiku_egl_config* conf; - conf=(struct haiku_egl_config*)calloc(1,sizeof (*conf)); - _eglInitConfig(&conf->base, dpy, 1); + struct haiku_egl_config conf, *final; + //conf=CALLOC_STRUCT(haiku_egl_config); + memset(&conf, 0, sizeof(conf)); + _eglInitConfig(&conf.base, dpy, 1); _eglLog(_EGL_DEBUG,"Config inited\n"); - _eglSetConfigKey(&conf->base, EGL_RED_SIZE ,8); - _eglSetConfigKey(&conf->base, EGL_BLUE_SIZE ,8); - _eglSetConfigKey(&conf->base, EGL_GREEN_SIZE ,8); - _eglSetConfigKey(&conf->base, EGL_LUMINANCE_SIZE ,0); - _eglSetConfigKey(&conf->base, EGL_ALPHA_SIZE ,8); - _eglSetConfigKey(&conf->base, EGL_COLOR_BUFFER_TYPE ,EGL_RGB_BUFFER); - EGLint r = (_eglGetConfigKey(&conf->base, EGL_RED_SIZE) - + _eglGetConfigKey(&conf->base, EGL_GREEN_SIZE) - + _eglGetConfigKey(&conf->base, EGL_BLUE_SIZE) - + _eglGetConfigKey(&conf->base, EGL_ALPHA_SIZE)); - _eglSetConfigKey(&conf->base, EGL_BUFFER_SIZE, r); - _eglSetConfigKey(&conf->base, EGL_CONFIG_CAVEAT, EGL_NONE); - _eglSetConfigKey(&conf->base, EGL_CONFIG_ID, 1); - _eglSetConfigKey(&conf->base, EGL_BIND_TO_TEXTURE_RGB ,EGL_FALSE); - _eglSetConfigKey(&conf->base, EGL_BIND_TO_TEXTURE_RGBA ,EGL_FALSE); - _eglSetConfigKey(&conf->base, EGL_STENCIL_SIZE ,0); - _eglSetConfigKey(&conf->base, EGL_TRANSPARENT_TYPE ,EGL_NONE); - _eglSetConfigKey(&conf->base, EGL_NATIVE_RENDERABLE ,EGL_TRUE); // Let's say yes - _eglSetConfigKey(&conf->base, EGL_NATIVE_VISUAL_ID ,0); // No visual - _eglSetConfigKey(&conf->base, EGL_NATIVE_VISUAL_TYPE ,EGL_NONE); // No visual - _eglSetConfigKey(&conf->base, EGL_RENDERABLE_TYPE ,0x8); - _eglSetConfigKey(&conf->base, EGL_SAMPLE_BUFFERS ,0); // TODO: How to get the right value ? - _eglSetConfigKey(&conf->base, EGL_SAMPLES ,_eglGetConfigKey(&conf->base, EGL_SAMPLE_BUFFERS) == 0 ? 0 : 0); - _eglSetConfigKey(&conf->base, EGL_DEPTH_SIZE ,24); // TODO: How to get the right value ? - _eglSetConfigKey(&conf->base, EGL_LEVEL ,0); - _eglSetConfigKey(&conf->base, EGL_MAX_PBUFFER_WIDTH ,0); // TODO: How to get the right value ? - _eglSetConfigKey(&conf->base, EGL_MAX_PBUFFER_HEIGHT ,0); // TODO: How to get the right value ? - _eglSetConfigKey(&conf->base, EGL_MAX_PBUFFER_PIXELS ,0); // TODO: How to get the right value ? - _eglSetConfigKey(&conf->base, EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT); - - //base.RenderableType = dpy->ClientAPIs; - //base.Conformant = dpy->ClientAPIs; + _eglSetConfigKey(&conf.base, EGL_RED_SIZE ,8); + _eglSetConfigKey(&conf.base, EGL_BLUE_SIZE ,8); + _eglSetConfigKey(&conf.base, EGL_GREEN_SIZE ,8); + _eglSetConfigKey(&conf.base, EGL_LUMINANCE_SIZE ,0); + _eglSetConfigKey(&conf.base, EGL_ALPHA_SIZE ,8); + _eglSetConfigKey(&conf.base, EGL_COLOR_BUFFER_TYPE ,EGL_RGB_BUFFER); + EGLint r = (_eglGetConfigKey(&conf.base, EGL_RED_SIZE) + + _eglGetConfigKey(&conf.base, EGL_GREEN_SIZE) + + _eglGetConfigKey(&conf.base, EGL_BLUE_SIZE) + + _eglGetConfigKey(&conf.base, EGL_ALPHA_SIZE)); + _eglSetConfigKey(&conf.base, EGL_BUFFER_SIZE, r); + _eglSetConfigKey(&conf.base, EGL_CONFIG_CAVEAT, EGL_NONE); + _eglSetConfigKey(&conf.base, EGL_CONFIG_ID, 1); + _eglSetConfigKey(&conf.base, EGL_BIND_TO_TEXTURE_RGB ,EGL_FALSE); + _eglSetConfigKey(&conf.base, EGL_BIND_TO_TEXTURE_RGBA ,EGL_FALSE); + _eglSetConfigKey(&conf.base, EGL_STENCIL_SIZE ,0); + _eglSetConfigKey(&conf.base, EGL_TRANSPARENT_TYPE ,EGL_NONE); + _eglSetConfigKey(&conf.base, EGL_NATIVE_RENDERABLE ,EGL_TRUE); // Let's say yes + _eglSetConfigKey(&conf.base, EGL_NATIVE_VISUAL_ID ,0); // No visual + _eglSetConfigKey(&conf.base, EGL_NATIVE_VISUAL_TYPE ,EGL_NONE); // No visual + _eglSetConfigKey(&conf.base, EGL_RENDERABLE_TYPE ,0x8); + _eglSetConfigKey(&conf.base, EGL_SAMPLE_BUFFERS ,0); // TODO: How to get the right value ? + _eglSetConfigKey(&conf.base, EGL_SAMPLES ,_eglGetConfigKey(&conf.base, EGL_SAMPLE_BUFFERS) == 0 ? 0 : 0); + _eglSetConfigKey(&conf.base, EGL_DEPTH_SIZE ,24); // TODO: How to get the right value ? + _eglSetConfigKey(&conf.base, EGL_LEVEL ,0); + _eglSetConfigKey(&conf.base, EGL_MAX_PBUFFER_WIDTH ,0); // TODO: How to get the right value ? + _eglSetConfigKey(&conf.base, EGL_MAX_PBUFFER_HEIGHT ,0); // TODO: How to get the right value ? + _eglSetConfigKey(&conf.base, EGL_MAX_PBUFFER_PIXELS ,0); // TODO: How to get the right value ? + _eglSetConfigKey(&conf.base, EGL_SURFACE_TYPE, EGL_WINDOW_BIT /*| EGL_PIXMAP_BIT | EGL_PBUFFER_BIT*/); - //base->MinSwapInterval = dri2_dpy->min_swap_interval; - //base->MaxSwapInterval = dri2_dpy->max_swap_interval; printf("Config configurated\n"); - if (!_eglValidateConfig(&conf->base, EGL_FALSE)) { + if (!_eglValidateConfig(&conf.base, EGL_FALSE)) { _eglLog(_EGL_DEBUG, "HAIKU: failed to validate config"); return EGL_FALSE; } printf("Validated config\n"); - /*conf =(struct dri2_egl_config*) malloc(sizeof *conf); - memcpy(&conf->base, &base, sizeof base); - conf->base.ConfigID = base.ConfigID; - base.ConfigID = EGL_DONT_CARE;*/ - //base->SurfaceType = EGL_DONT_CARE; - _eglLinkConfig(&conf->base); + final=CALLOC_STRUCT(haiku_egl_config); + memcpy(final, &conf, sizeof(conf)); + + _eglLinkConfig(&final->base); if (!_eglGetArraySize(dpy->Configs)) { _eglLog(_EGL_WARNING, "HAIKU: failed to create any config"); return EGL_FALSE; @@ -242,25 +249,8 @@ EGLBoolean init_haiku(_EGLDriver *drv, _EGLDisplay *dpy) { _eglLog(_EGL_DEBUG,"\nINITIALIZING HAIKU\n"); - _EGLDisplay* egl_dpy; - /*struct dri2_egl_display_vtbl dri2_haiku_display_vtbl; - struct dri2_egl_display *dri2_dpy; - - dri2_haiku_display_vtbl.authenticate = NULL; - dri2_haiku_display_vtbl.create_window_surface = dri2_haiku_create_window_surface; - dri2_haiku_display_vtbl.create_pixmap_surface = dri2_haiku_create_pixmap_surface; - dri2_haiku_display_vtbl.create_pbuffer_surface = dri2_haiku_create_pbuffer_surface; - dri2_haiku_display_vtbl.destroy_surface = dri2_haiku_destroy_surface; - dri2_haiku_display_vtbl.create_image = NULL; - dri2_haiku_display_vtbl.swap_interval = dri2_fallback_swap_interval; - dri2_haiku_display_vtbl.swap_buffers = NULL; - dri2_haiku_display_vtbl.swap_buffers_region = dri2_fallback_swap_buffers_region; - dri2_haiku_display_vtbl.post_sub_buffer = dri2_fallback_post_sub_buffer; - dri2_haiku_display_vtbl.copy_buffers = NULL; - dri2_haiku_display_vtbl.query_buffer_age = dri2_fallback_query_buffer_age, - dri2_haiku_display_vtbl.create_wayland_buffer_from_image = dri2_fallback_create_wayland_buffer_from_image; - dri2_haiku_display_vtbl.get_sync_values = dri2_fallback_get_sync_values; - */ + //_EGLDisplay* egl_dpy; + printf("INITIALIZING HAIKU\n"); _eglSetLogProc(haiku_log); @@ -309,18 +299,6 @@ init_haiku(_EGLDriver *drv, _EGLDisplay *dpy) _eglLog(_EGL_DEBUG, "Initialization finished"); return EGL_TRUE; - - cleanup_configs: - _eglCleanupDisplay(dpy); - //dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); - cleanup_driver: - //dlclose(dri2_dpy->driver); - cleanup_conn: - //free(dri2_dpy->driver_name); - cleanup_dpy: - //free(dri2_dpy); - - return EGL_FALSE; } extern "C" @@ -356,6 +334,23 @@ EGLBoolean haiku_make_current(_EGLDriver* drv, _EGLDisplay* dpy, _EGLSurface *dsurf, _EGLSurface *rsurf, _EGLContext *ctx) { + struct haiku_egl_context* cont=haiku_egl_context(ctx); + struct haiku_egl_surface* surf=haiku_egl_surface(dsurf); + _EGLContext *old_ctx; + _EGLSurface *old_dsurf, *old_rsurf; + _eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf); + //cont->ctx.DrawSurface=&surf->surf; + surf->gl->LockGL(); + return EGL_TRUE; +} + +extern "C" +EGLBoolean +haiku_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) +{ + struct haiku_egl_surface* surface=haiku_egl_surface(surf); + surface->gl->SwapBuffers(); + //gl->Render(); return EGL_TRUE; } @@ -391,9 +386,9 @@ _eglBuiltInDriverHaiku(const char *args) driver->API.WaitNative = dri2_wait_native; driver->API.BindTexImage = dri2_bind_tex_image; driver->API.ReleaseTexImage = dri2_release_tex_image; - driver->API.SwapInterval = dri2_swap_interval; - driver->API.SwapBuffers = dri2_swap_buffers; - driver->API.SwapBuffersWithDamageEXT = dri2_swap_buffers_with_damage; + driver->API.SwapInterval = dri2_swap_interval;*/ + driver->base.API.SwapBuffers = haiku_swap_buffers; + /*driver->API.SwapBuffersWithDamageEXT = dri2_swap_buffers_with_damage; driver->API.SwapBuffersRegionNOK = dri2_swap_buffers_region; driver->API.PostSubBufferNV = dri2_post_sub_buffer; driver->API.CopyBuffers = dri2_copy_buffers, diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 511848f..db44a26 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -821,9 +821,11 @@ eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); /* surface must be bound to current context in EGL 1.4 */ + #ifndef _EGL_BUILT_IN_DRIVER_HAIKU if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || surf != ctx->DrawSurface) RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); + #endif ret = drv->API.SwapBuffers(drv, disp, surf); -- 1.7.1 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev