- _eglBindContext(&ctx, &dsurf, &rsurf);
-
- return EGL_FALSE;
- }
-}
-
-/**
- * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
- */
-static _EGLSurface *
-dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
- _EGLConfig *conf, EGLNativeWindowType window,
- const EGLint *attrib_list)
-{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- struct dri2_egl_config *dri2_conf = dri2_egl_config(conf);
- struct dri2_egl_surface *dri2_surf;
- xcb_get_geometry_cookie_t cookie;
- xcb_get_geometry_reply_t *reply;
- xcb_screen_iterator_t s;
- xcb_generic_error_t *error;
-
- dri2_surf = malloc(sizeof *dri2_surf);
- if (!dri2_surf) {
- _eglError(EGL_BAD_ALLOC, "dri2_create_surface");
- return NULL;
- }
-
- if (!_eglInitSurface(&dri2_surf->base, disp, type, conf, attrib_list))
- goto cleanup_surf;
-
- dri2_surf->region = XCB_NONE;
- if (type == EGL_PBUFFER_BIT) {
- dri2_surf->drawable = xcb_generate_id(dri2_dpy->conn);
- s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
- xcb_create_pixmap(dri2_dpy->conn,
- _eglGetConfigKey(conf, EGL_BUFFER_SIZE),
- dri2_surf->drawable, s.data->root,
- dri2_surf->base.Width, dri2_surf->base.Height);
- } else {
- dri2_surf->drawable = window;
- }
-
- dri2_surf->dri_drawable =
- (*dri2_dpy->dri2->createNewDrawable) (dri2_dpy->dri_screen,
- dri2_conf->dri_config, dri2_surf);
- if (dri2_surf->dri_drawable == NULL) {
- _eglError(EGL_BAD_ALLOC, "dri2->createNewDrawable");
- goto cleanup_pixmap;
- }
-
- xcb_dri2_create_drawable (dri2_dpy->conn, dri2_surf->drawable);
-
- if (type != EGL_PBUFFER_BIT) {
- cookie = xcb_get_geometry (dri2_dpy->conn, dri2_surf->drawable);
- reply = xcb_get_geometry_reply (dri2_dpy->conn, cookie, &error);
- if (reply == NULL || error != NULL) {
- _eglError(EGL_BAD_ALLOC, "xcb_get_geometry");
- free(error);
- goto cleanup_dri_drawable;
- }
-
- dri2_surf->base.Width = reply->width;
- dri2_surf->base.Height = reply->height;
- free(reply);
- }
-
- return &dri2_surf->base;
-
- cleanup_dri_drawable:
- dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
- cleanup_pixmap:
- if (type == EGL_PBUFFER_BIT)
- xcb_free_pixmap(dri2_dpy->conn, dri2_surf->drawable);
- cleanup_surf:
- free(dri2_surf);
-
- return NULL;
-}
-
-/**
- * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
- */
-static _EGLSurface *
-dri2_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
- _EGLConfig *conf, EGLNativeWindowType window,
- const EGLint *attrib_list)
-{
- return dri2_create_surface(drv, disp, EGL_WINDOW_BIT, conf,
- window, attrib_list);
-}
-
-static _EGLSurface *
-dri2_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *disp,
- _EGLConfig *conf, EGLNativePixmapType pixmap,
- const EGLint *attrib_list)
-{
- return dri2_create_surface(drv, disp, EGL_PIXMAP_BIT, conf,
- pixmap, attrib_list);
-}
-
-static _EGLSurface *
-dri2_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *disp,
- _EGLConfig *conf, const EGLint *attrib_list)
-{
- return dri2_create_surface(drv, disp, EGL_PBUFFER_BIT, conf,
- XCB_WINDOW_NONE, attrib_list);
-}
-
-static EGLBoolean
-dri2_copy_region(_EGLDriver *drv, _EGLDisplay *disp,
- _EGLSurface *draw, xcb_xfixes_region_t region)
-{
- struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv);
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw);
- _EGLContext *ctx;
- xcb_dri2_copy_region_cookie_t cookie;
-
- if (dri2_drv->glFlush) {
- ctx = _eglGetCurrentContext();
- if (ctx && ctx->DrawSurface == &dri2_surf->base)
- dri2_drv->glFlush();
- }
-
- (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable);
-
-#if 0
- /* FIXME: Add support for dri swapbuffers, that'll give us swap
- * interval and page flipping (at least for fullscreen windows) as
- * well as the page flip event. Unless surface->SwapBehavior is
- * EGL_BUFFER_PRESERVED. */
-#if __DRI2_FLUSH_VERSION >= 2
- if (pdraw->psc->f)
- (*pdraw->psc->f->flushInvalidate)(pdraw->driDrawable);
-#endif
-#endif
-
- if (!dri2_surf->have_fake_front)
- return EGL_TRUE;
-
- cookie = xcb_dri2_copy_region_unchecked(dri2_dpy->conn,
- dri2_surf->drawable,
- region,
- XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT,
- XCB_DRI2_ATTACHMENT_BUFFER_FAKE_FRONT_LEFT);
- free(xcb_dri2_copy_region_reply(dri2_dpy->conn, cookie, NULL));
-
- return EGL_TRUE;
-}