X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fegl%2Fdrivers%2Fhaiku%2Fegl_haiku.cpp;h=ac598827c5f01c21c9b82004b874d4773388c652;hb=ad61d4f14619ce43c5f558fc2ce5ac1267a95e25;hp=36e1277a2e0fe74a6a0ef19163181ad2fc236ce4;hpb=ed9dcdf927b9badd1325130b6b88ad26b04d2ec1;p=mesa.git diff --git a/src/egl/drivers/haiku/egl_haiku.cpp b/src/egl/drivers/haiku/egl_haiku.cpp index 36e1277a2e0..ac598827c5f 100644 --- a/src/egl/drivers/haiku/egl_haiku.cpp +++ b/src/egl/drivers/haiku/egl_haiku.cpp @@ -27,9 +27,9 @@ #include #include -#include "loader.h" #include "eglconfig.h" #include "eglcontext.h" +#include "egldevice.h" #include "egldisplay.h" #include "egldriver.h" #include "eglcurrent.h" @@ -42,8 +42,6 @@ #include -#define CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T)) - #ifdef DEBUG # define TRACE(x...) printf("egl_haiku: " x) # define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__) @@ -57,15 +55,6 @@ _EGL_DRIVER_STANDARD_TYPECASTS(haiku_egl) -struct haiku_egl_driver -{ - _EGLDriver base; - - void *handle; - _EGLProc (*get_proc_address)(const char *procname); - void (*glFlush)(void); -}; - struct haiku_egl_config { _EGLConfig base; @@ -83,52 +72,28 @@ struct haiku_egl_surface }; -static void -haiku_log(EGLint level, const char *msg) -{ - switch (level) { - case _EGL_DEBUG: - fprintf(stderr,"%s", msg); - break; - case _EGL_INFO: - fprintf(stderr,"%s", msg); - break; - case _EGL_WARNING: - fprintf(stderr,"%s", msg); - break; - case _EGL_FATAL: - fprintf(stderr,"%s", msg); - break; - default: - break; - } -} - - /** - * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). + * Called via eglCreateWindowSurface(), drv->CreateWindowSurface(). */ static _EGLSurface * -haiku_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type, - _EGLConfig *conf, void *native_surface, const EGLint *attrib_list) -{ - return NULL; -} - - -/** - * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). - */ -static _EGLSurface * -haiku_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp, +haiku_create_window_surface(const _EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, void *native_window, const EGLint *attrib_list) { CALLED(); struct haiku_egl_surface* surface; - surface = (struct haiku_egl_surface*)calloc(1,sizeof (*surface)); + surface = (struct haiku_egl_surface*) calloc(1, sizeof (*surface)); + if (!surface) { + _eglError(EGL_BAD_ALLOC, "haiku_create_window_surface"); + return NULL; + } + + if (!_eglInitSurface(&surface->surf, disp, EGL_WINDOW_BIT, + conf, attrib_list, native_window)) { + free(surface); + return NULL; + } - _eglInitSurface(&surface->surf, disp, EGL_WINDOW_BIT, conf, attrib_list); (&surface->surf)->SwapInterval = 1; TRACE("Creating window\n"); @@ -148,7 +113,7 @@ haiku_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp, static _EGLSurface * -haiku_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *disp, +haiku_create_pixmap_surface(const _EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, void *native_pixmap, const EGLint *attrib_list) { return NULL; @@ -156,7 +121,7 @@ haiku_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *disp, static _EGLSurface * -haiku_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *disp, +haiku_create_pbuffer_surface(const _EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, const EGLint *attrib_list) { return NULL; @@ -164,85 +129,98 @@ haiku_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *disp, static EGLBoolean -haiku_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) +haiku_destroy_surface(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) { + if (_eglPutSurface(surf)) { + // XXX: detach haiku_egl_surface::gl from the native window and destroy it + free(surf); + } return EGL_TRUE; } static EGLBoolean -haiku_add_configs_for_visuals(_EGLDisplay *dpy) +haiku_add_configs_for_visuals(_EGLDisplay *disp) { CALLED(); struct haiku_egl_config* conf; - conf = CALLOC_STRUCT(haiku_egl_config); + conf = (struct haiku_egl_config*) calloc(1, sizeof (*conf)); + if (!conf) + return _eglError(EGL_BAD_ALLOC, "haiku_add_configs_for_visuals"); - _eglInitConfig(&conf->base, dpy, 1); + _eglInitConfig(&conf->base, disp, 1); TRACE("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*/); + conf->base.RedSize = 8; + conf->base.BlueSize = 8; + conf->base.GreenSize = 8; + conf->base.LuminanceSize = 0; + conf->base.AlphaSize = 8; + conf->base.ColorBufferType = EGL_RGB_BUFFER; + conf->base.BufferSize = conf->base.RedSize + + conf->base.GreenSize + + conf->base.BlueSize + + conf->base.AlphaSize; + conf->base.ConfigCaveat = EGL_NONE; + conf->base.ConfigId = 1; + conf->base.BindToTextureRGB = EGL_FALSE; + conf->base.BindToTextureRGBA = EGL_FALSE; + conf->base.StencilSize = 0; + conf->base.TransparentType = EGL_NONE; + conf->base.NativeRenderable = EGL_TRUE; // Let's say yes + conf->base.NativeVisualID = 0; // No visual + conf->base.NativeVisualType = EGL_NONE; // No visual + conf->base.RenderableType = 0x8; + conf->base.SampleBuffers = 0; // TODO: How to get the right value ? + conf->base.Samples = conf->base.SampleBuffers == 0 ? 0 : 0; + conf->base.DepthSize = 24; // TODO: How to get the right value ? + conf->base.Level = 0; + conf->base.MaxPbufferWidth = 0; // TODO: How to get the right value ? + conf->base.MaxPbufferHeight = 0; // TODO: How to get the right value ? + conf->base.MaxPbufferPixels = 0; // TODO: How to get the right value ? + conf->base.SurfaceType = EGL_WINDOW_BIT /*| EGL_PIXMAP_BIT | EGL_PBUFFER_BIT*/; TRACE("Config configuated\n"); if (!_eglValidateConfig(&conf->base, EGL_FALSE)) { _eglLog(_EGL_DEBUG, "Haiku: failed to validate config"); - return EGL_FALSE; + goto cleanup; } TRACE("Validated config\n"); - + _eglLinkConfig(&conf->base); - if (!_eglGetArraySize(dpy->Configs)) { + if (!_eglGetArraySize(disp->Configs)) { _eglLog(_EGL_WARNING, "Haiku: failed to create any config"); - return EGL_FALSE; + goto cleanup; } TRACE("Config successfull\n"); - + return EGL_TRUE; + +cleanup: + free(conf); + return EGL_FALSE; } + extern "C" EGLBoolean -init_haiku(_EGLDriver *drv, _EGLDisplay *dpy) +init_haiku(_EGLDisplay *disp) { + _EGLDevice *dev; CALLED(); - _eglSetLogProc(haiku_log); - - loader_set_logger(_eglLog); + dev = _eglAddDevice(-1, true); + if (!dev) { + _eglError(EGL_NOT_INITIALIZED, "DRI2: failed to find EGLDevice"); + return EGL_FALSE; + } + disp->Device = dev; TRACE("Add configs\n"); - haiku_add_configs_for_visuals(dpy); + if (!haiku_add_configs_for_visuals(disp)) + return EGL_FALSE; - dpy->Version = 14; - TRACE("Initialization finished\n"); return EGL_TRUE; @@ -251,7 +229,7 @@ init_haiku(_EGLDriver *drv, _EGLDisplay *dpy) extern "C" EGLBoolean -haiku_terminate(_EGLDriver* drv,_EGLDisplay* dpy) +haiku_terminate(const _EGLDriver* drv,_EGLDisplay *disp) { return EGL_TRUE; } @@ -259,43 +237,60 @@ haiku_terminate(_EGLDriver* drv,_EGLDisplay* dpy) extern "C" _EGLContext* -haiku_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, +haiku_create_context(const _EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, _EGLContext *share_list, const EGLint *attrib_list) { CALLED(); struct haiku_egl_context* context; - context=(struct haiku_egl_context*)calloc(1,sizeof (*context)); + context = (struct haiku_egl_context*) calloc(1, sizeof (*context)); + if (!context) { + _eglError(EGL_BAD_ALLOC, "haiku_create_context"); + return NULL; + } if (!_eglInitContext(&context->ctx, disp, conf, attrib_list)) - ERROR("ERROR creating context"); + goto cleanup; TRACE("Context created\n"); return &context->ctx; + +cleanup: + free(context); + return NULL; } extern "C" EGLBoolean -haiku_destroy_context(_EGLDriver* drv, _EGLDisplay *disp, _EGLContext* ctx) +haiku_destroy_context(const _EGLDriver* drv, _EGLDisplay *disp, _EGLContext* ctx) { - ctx=NULL; + struct haiku_egl_context* context = haiku_egl_context(ctx); + + if (_eglPutContext(ctx)) { + // XXX: teardown the context ? + free(context); + ctx = NULL; + } return EGL_TRUE; } extern "C" EGLBoolean -haiku_make_current(_EGLDriver* drv, _EGLDisplay* dpy, _EGLSurface *dsurf, - _EGLSurface *rsurf, _EGLContext *ctx) +haiku_make_current(const _EGLDriver* drv, _EGLDisplay *disp, _EGLSurface *dsurf, + _EGLSurface *rsurf, _EGLContext *ctx) { CALLED(); - struct haiku_egl_context* cont=haiku_egl_context(ctx); - struct haiku_egl_surface* surf=haiku_egl_surface(dsurf); + 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); + _EGLSurface *old_dsurf, *old_rsurf; + + if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) + return EGL_FALSE; + //cont->ctx.DrawSurface=&surf->surf; surf->gl->LockGL(); return EGL_TRUE; @@ -304,9 +299,10 @@ haiku_make_current(_EGLDriver* drv, _EGLDisplay* dpy, _EGLSurface *dsurf, extern "C" EGLBoolean -haiku_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) +haiku_swap_buffers(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) { - struct haiku_egl_surface* surface=haiku_egl_surface(surf); + struct haiku_egl_surface* surface = haiku_egl_surface(surf); + surface->gl->SwapBuffers(); //gl->Render(); return EGL_TRUE; @@ -314,42 +310,15 @@ haiku_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) extern "C" -void -haiku_unload(_EGLDriver* drv) -{ - -} - - -/** - * This is the main entrypoint into the driver, called by libEGL. - * Create a new _EGLDriver object and init its dispatch table. - */ -extern "C" -_EGLDriver* -_eglBuiltInDriverHaiku(const char *args) -{ - CALLED(); - - struct haiku_egl_driver* driver; - driver=(struct haiku_egl_driver*)calloc(1,sizeof(*driver)); - _eglInitDriverFallbacks(&driver->base); - driver->base.API.Initialize = init_haiku; - driver->base.API.Terminate = haiku_terminate; - driver->base.API.CreateContext = haiku_create_context; - driver->base.API.DestroyContext = haiku_destroy_context; - driver->base.API.MakeCurrent = haiku_make_current; - driver->base.API.CreateWindowSurface = haiku_create_window_surface; - driver->base.API.CreatePixmapSurface = haiku_create_pixmap_surface; - driver->base.API.CreatePbufferSurface = haiku_create_pbuffer_surface; - driver->base.API.DestroySurface = haiku_destroy_surface; - - driver->base.API.SwapBuffers = haiku_swap_buffers; - - driver->base.Name = "Haiku"; - driver->base.Unload = haiku_unload; - - TRACE("API Calls defined\n"); - - return &driver->base; -} +const _EGLDriver _eglDriver = { + .Initialize = init_haiku, + .Terminate = haiku_terminate, + .CreateContext = haiku_create_context, + .DestroyContext = haiku_destroy_context, + .MakeCurrent = haiku_make_current, + .CreateWindowSurface = haiku_create_window_surface, + .CreatePixmapSurface = haiku_create_pixmap_surface, + .CreatePbufferSurface = haiku_create_pbuffer_surface, + .DestroySurface = haiku_destroy_surface, + .SwapBuffers = haiku_swap_buffers, +};