/** * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). */ static EGLSurface xlib_eglCreateWindowSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list) { struct xlib_egl_driver *xdrv = xlib_egl_driver(drv); _EGLDisplay *disp = _eglLookupDisplay(dpy); _EGLConfig *conf = _eglLookupConfig(drv, dpy, config); struct xlib_egl_surface *surf; __GLcontextModes visual; uint width, height; surf = CALLOC_STRUCT(xlib_egl_surface); if (!surf) return EGL_NO_SURFACE; /* Let EGL lib init the common stuff */ if (!_eglInitSurface(drv, dpy, &surf->Base, EGL_WINDOW_BIT, config, attrib_list)) { free(surf); return EGL_NO_SURFACE; } _eglSaveSurface(&surf->Base); /* * Now init the Xlib and gallium stuff */ surf->Win = (Window) window; /* The X window ID */ surf->Dpy = disp->Xdpy; /* The X display */ surf->Gc = XCreateGC(surf->Dpy, surf->Win, 0, NULL); surf->winsys = xdrv->winsys; _eglConfigToContextModesRec(conf, &visual); get_drawable_size(surf->Dpy, surf->Win, &width, &height); get_drawable_visual_info(surf->Dpy, surf->Win, &surf->VisInfo); surf->Base.Width = width; surf->Base.Height = height; /* Create GL statetracker framebuffer */ surf->Framebuffer = st_create_framebuffer(&visual, choose_color_format(&visual), choose_depth_format(&visual), choose_stencil_format(&visual), width, height, (void *) surf); st_resize_framebuffer(surf->Framebuffer, width, height); return _eglGetSurfaceHandle(&surf->Base); }
/** * Called via eglCreateContext(), drv->API.CreateContext(). */ static EGLContext xlib_eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list) { struct xlib_egl_driver *xdrv = xlib_egl_driver(drv); _EGLConfig *conf = _eglLookupConfig(drv, dpy, config); struct xlib_egl_context *ctx; struct st_context *share_ctx = NULL; /* XXX fix */ __GLcontextModes visual; ctx = CALLOC_STRUCT(xlib_egl_context); if (!ctx) return EGL_NO_CONTEXT; /* let EGL lib init the common stuff */ if (!_eglInitContext(drv, dpy, &ctx->Base, config, attrib_list)) { free(ctx); return EGL_NO_CONTEXT; } /* API-dependent context creation */ switch (ctx->Base.ClientAPI) { case EGL_OPENVG_API: case EGL_OPENGL_ES_API: _eglLog(_EGL_DEBUG, "Create Context for ES version %d\n", ctx->Base.ClientVersion); /* fall-through */ case EGL_OPENGL_API: /* create a softpipe context */ ctx->pipe = softpipe_create(xdrv->screen, xdrv->winsys, NULL); /* Now do xlib / state tracker inits here */ _eglConfigToContextModesRec(conf, &visual); ctx->Context = st_create_context(ctx->pipe, &visual, share_ctx); break; default: _eglError(EGL_BAD_MATCH, "eglCreateContext(unsupported API)"); free(ctx); return EGL_NO_CONTEXT; } _eglSaveContext(&ctx->Base); return _eglGetContextHandle(&ctx->Base); }
static EGLSurface fbCreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) { fbSurface *surf; surf = (fbSurface *) calloc(1, sizeof(fbSurface)); if (!surf) { return EGL_NO_SURFACE; } if (_eglInitPbufferSurface(&surf->Base, drv, dpy, config, attrib_list) == EGL_NO_SURFACE) { free(surf); return EGL_NO_SURFACE; } /* create software-based pbuffer */ { GLcontext *ctx = NULL; /* this _should_ be OK */ GLvisual vis; _EGLConfig *conf = _eglLookupConfig(drv, dpy, config); assert(conf); /* bad config should be caught earlier */ _eglConfigToContextModesRec(conf, &vis); surf->mesa_framebuffer = _mesa_create_framebuffer(&vis); _mesa_add_soft_renderbuffers(surf->mesa_framebuffer, GL_TRUE, /* color bufs */ vis.haveDepthBuffer, vis.haveStencilBuffer, vis.haveAccumBuffer, GL_FALSE, /* alpha */ GL_FALSE /* aux */ ); /* set pbuffer/framebuffer size */ _mesa_resize_framebuffer(ctx, surf->mesa_framebuffer, surf->Base.Width, surf->Base.Height); } return surf->Base.Handle; }
/** * Create a drawing surface which can be directly displayed on a screen. */ static EGLSurface fbCreateScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLConfig cfg, const EGLint *attrib_list) { _EGLConfig *config = _eglLookupConfig(drv, dpy, cfg); fbDisplay *display = Lookup_fbDisplay(dpy); fbSurface *surface; EGLSurface surf; GLvisual vis; GLcontext *ctx = NULL; /* this should be OK */ int origin, bytesPerPixel; int width, height, stride; surface = (fbSurface *) malloc(sizeof(*surface)); if (!surface) { return EGL_NO_SURFACE; } /* init base class, error check, etc. */ surf = _eglInitScreenSurface(&surface->Base, drv, dpy, cfg, attrib_list); if (surf == EGL_NO_SURFACE) { free(surface); return EGL_NO_SURFACE; } /* convert EGLConfig to GLvisual */ _eglConfigToContextModesRec(config, &vis); /* create Mesa framebuffer */ surface->mesa_framebuffer = _mesa_create_framebuffer(&vis); if (!surface->mesa_framebuffer) { free(surface); _eglRemoveSurface(&surface->Base); return EGL_NO_SURFACE; } width = surface->Base.Width; height = surface->Base.Height; bytesPerPixel = vis.rgbBits / 8; stride = width * bytesPerPixel; origin = 0; /* front color renderbuffer */ { driRenderbuffer *drb = driNewRenderbuffer(GL_RGBA, display->pFB, bytesPerPixel, origin, stride, NULL); fbSetSpanFunctions(drb, &vis); _mesa_add_renderbuffer(surface->mesa_framebuffer, BUFFER_FRONT_LEFT, &drb->Base); } /* back color renderbuffer */ if (vis.doubleBufferMode) { GLubyte *backBuf = _mesa_malloc(stride * height); driRenderbuffer *drb = driNewRenderbuffer(GL_RGBA, backBuf, bytesPerPixel, origin, stride, NULL); fbSetSpanFunctions(drb, &vis); _mesa_add_renderbuffer(surface->mesa_framebuffer, BUFFER_BACK_LEFT, &drb->Base); } /* other renderbuffers- software based */ _mesa_add_soft_renderbuffers(surface->mesa_framebuffer, GL_FALSE, /* color */ vis.haveDepthBuffer, vis.haveStencilBuffer, vis.haveAccumBuffer, GL_FALSE, /* alpha */ GL_FALSE /* aux */); _mesa_resize_framebuffer(ctx, surface->mesa_framebuffer, width, height); return surf; }
static EGLContext fbCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list) { GLcontext *ctx; _EGLConfig *conf; fbContext *c; _EGLDisplay *disp = _eglLookupDisplay(dpy); struct dd_function_table functions; GLvisual vis; int i; conf = _eglLookupConfig(drv, dpy, config); if (!conf) { _eglError(EGL_BAD_CONFIG, "eglCreateContext"); return EGL_NO_CONTEXT; } for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { switch (attrib_list[i]) { /* no attribs defined for now */ default: _eglError(EGL_BAD_ATTRIBUTE, "eglCreateContext"); return EGL_NO_CONTEXT; } } c = (fbContext *) calloc(1, sizeof(fbContext)); if (!c) return EGL_NO_CONTEXT; _eglInitContext(&c->Base); c->Base.Display = disp; c->Base.Config = conf; c->Base.DrawSurface = EGL_NO_SURFACE; c->Base.ReadSurface = EGL_NO_SURFACE; /* generate handle and insert into hash table */ _eglSaveContext(&c->Base); assert(c->Base.Handle); /* Init default driver functions then plug in our FBdev-specific functions */ _mesa_init_driver_functions(&functions); init_core_functions(&functions); _eglConfigToContextModesRec(conf, &vis); ctx = c->glCtx = _mesa_create_context(&vis, NULL, &functions, (void *)c); if (!c->glCtx) { _mesa_free(c); return GL_FALSE; } /* Create module contexts */ _swrast_CreateContext( ctx ); _vbo_CreateContext( ctx ); _tnl_CreateContext( ctx ); _swsetup_CreateContext( ctx ); _swsetup_Wakeup( ctx ); /* use default TCL pipeline */ { TNLcontext *tnl = TNL_CONTEXT(ctx); tnl->Driver.RunPipeline = _tnl_run_pipeline; } _mesa_enable_sw_extensions(ctx); return c->Base.Handle; }