gallium: squash-merge of gallium screen context
[mesa.git] / src / gallium / state_trackers / egl / common / egl_g3d.c
index 6c8f3b9f79cd5c30dc3868f2acb5efa93e3b467e..424be4931177068bf70a9bee00cef07bf979356b 100644 (file)
  */
 
 #include <assert.h>
+#include <stdio.h>
 #include <string.h>
 #include "pipe/p_screen.h"
 #include "util/u_memory.h"
 #include "util/u_rect.h"
+#include "util/u_inlines.h"
 #include "egldriver.h"
 #include "eglcurrent.h"
 #include "eglconfigutil.h"
@@ -468,7 +470,7 @@ egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id)
       if (!gconf)
          continue;
 
-      _eglInitConfig(&gconf->base, id);
+      _eglInitConfig(&gconf->base, dpy, id);
 
       api_mask = get_mode_api_mask(&native_configs[i]->mode, gdrv->api_mask);
       if (!api_mask) {
@@ -631,7 +633,7 @@ egl_g3d_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
       return NULL;
    }
 
-   if (!_eglInitContext(drv, &gctx->base, conf, attribs)) {
+   if (!_eglInitContext(&gctx->base, dpy, conf, attribs)) {
       free(gctx);
       return NULL;
    }
@@ -643,8 +645,11 @@ egl_g3d_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
    }
 
    mode = &gconf->native->mode;
-   gctx->pipe =
-      gdpy->native->create_context(gdpy->native, (void *) &gctx->base);
+
+   gctx->pipe = gdpy->native->screen->create_context(
+      gdpy->native->screen,
+      (void *) &gctx->base);
+
    if (!gctx->pipe) {
       free(gctx);
       return NULL;
@@ -713,7 +718,7 @@ egl_g3d_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy,
       return NULL;
    }
 
-   if (!_eglInitSurface(drv, &gsurf->base, EGL_WINDOW_BIT, conf, attribs)) {
+   if (!_eglInitSurface(&gsurf->base, dpy, EGL_WINDOW_BIT, conf, attribs)) {
       free(gsurf);
       return NULL;
    }
@@ -753,7 +758,7 @@ egl_g3d_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy,
       return NULL;
    }
 
-   if (!_eglInitSurface(drv, &gsurf->base, EGL_PIXMAP_BIT, conf, attribs)) {
+   if (!_eglInitSurface(&gsurf->base, dpy, EGL_PIXMAP_BIT, conf, attribs)) {
       free(gsurf);
       return NULL;
    }
@@ -790,7 +795,7 @@ egl_g3d_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy,
       return NULL;
    }
 
-   if (!_eglInitSurface(drv, &gsurf->base, EGL_PBUFFER_BIT, conf, attribs)) {
+   if (!_eglInitSurface(&gsurf->base, dpy, EGL_PBUFFER_BIT, conf, attribs)) {
       free(gsurf);
       return NULL;
    }
@@ -1087,8 +1092,8 @@ egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
                        _EGLSurface *surf, EGLint buffer)
 {
    struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
-   _EGLContext *ctx = _eglGetAPIContext(EGL_OPENGL_ES_API);
-   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
+   _EGLContext *es1 = _eglGetAPIContext(EGL_OPENGL_ES_API);
+   struct egl_g3d_context *gctx;
    enum pipe_format target_format;
    int target;
 
@@ -1118,6 +1123,11 @@ egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
       return _eglError(EGL_BAD_MATCH, "eglBindTexImage");
    }
 
+   if (!es1)
+      return EGL_TRUE;
+   if (!gsurf->render_surface)
+      return EGL_FALSE;
+
    /* flush properly if the surface is bound */
    if (gsurf->base.CurrentContext) {
       gctx = egl_g3d_context(gsurf->base.CurrentContext);
@@ -1125,14 +1135,11 @@ egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
             PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
    }
 
-   if (gctx) {
-      if (!gsurf->render_surface)
-         return EGL_FALSE;
+   gctx = egl_g3d_context(es1);
+   gctx->stapi->st_bind_texture_surface(gsurf->render_surface,
+         target, gsurf->base.MipmapLevel, target_format);
 
-      gctx->stapi->st_bind_texture_surface(gsurf->render_surface,
-            target, gsurf->base.MipmapLevel, target_format);
-      gsurf->base.BoundToTexture = EGL_TRUE;
-   }
+   gsurf->base.BoundToTexture = EGL_TRUE;
 
    return EGL_TRUE;
 }
@@ -1180,7 +1187,7 @@ egl_g3d_create_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy,
       return NULL;
    }
 
-   if (!_eglInitSurface(drv, &gsurf->base,
+   if (!_eglInitSurface(&gsurf->base, dpy,
             EGL_SCREEN_BIT_MESA, conf, attribs)) {
       free(gsurf);
       return NULL;