st/egl: Enable extensions before adding configs.
[mesa.git] / src / gallium / state_trackers / egl / common / egl_g3d.c
index 8a73e81d4ac0d94c432162e0a4bf642ea768d707..d769d253ac5c727834f0bd1947ca8d88239eeec4 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"
@@ -526,12 +528,6 @@ static void
 egl_g3d_update_buffer(struct pipe_screen *screen, void *context_private)
 {
    struct egl_g3d_context *gctx = egl_g3d_context(context_private);
-
-   /**
-    * It is likely that the surface has changed when this function is called.
-    * Set force_validate to skip an unnecessary check.
-    */
-   gctx->force_validate = EGL_TRUE;
    egl_g3d_validate_context(gctx->base.Resource.Display, &gctx->base);
 }
 
@@ -591,19 +587,19 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy,
    egl_g3d_init_st(&gdrv->base);
    dpy->ClientAPIsMask = gdrv->api_mask;
 
-   if (egl_g3d_add_configs(drv, dpy, 1) == 1) {
-      _eglError(EGL_NOT_INITIALIZED, "eglInitialize(unable to add configs)");
-      goto fail;
-   }
-
 #ifdef EGL_MESA_screen_surface
-   /* enable MESA_screen_surface */
+   /* enable MESA_screen_surface before adding (and validating) configs */
    if (gdpy->native->modeset) {
       dpy->Extensions.MESA_screen_surface = EGL_TRUE;
       egl_g3d_add_screens(drv, dpy);
    }
 #endif
 
+   if (egl_g3d_add_configs(drv, dpy, 1) == 1) {
+      _eglError(EGL_NOT_INITIALIZED, "eglInitialize(unable to add configs)");
+      goto fail;
+   }
+
    *major = 1;
    *minor = 4;
 
@@ -643,8 +639,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->context_create(
+      gdpy->native->screen,
+      (void *) &gctx->base);
+
    if (!gctx->pipe) {
       free(gctx);
       return NULL;
@@ -1087,8 +1086,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 +1117,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 +1129,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;
 }