egl/gbm: Fix EGL_DEFAULT_DISPLAY
[mesa.git] / src / gallium / state_trackers / egl / common / egl_g3d_st.c
index f4934982edbeebe0981177c2158e074aeac3bb99..b839f848d7b30defe101889fdc7a4c6e37c97ec6 100644 (file)
  * The above copyright notice and this permission notice shall be included
  * in all copies or substantial portions of the Software.
  *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *    Chia-I Wu <olv@lunarg.com>
  */
 
 #include "util/u_memory.h"
+#include "util/u_string.h"
 #include "util/u_inlines.h"
+#include "util/u_pointer.h"
 #include "util/u_dl.h"
+#include "egldriver.h"
 #include "eglimage.h"
 #include "eglmutex.h"
 
@@ -45,52 +49,13 @@ egl_g3d_st_manager(struct st_manager *smapi)
    return (struct egl_g3d_st_manager *) smapi;
 }
 
-struct st_api *
-egl_g3d_create_st_api(enum st_api_type api)
-{
-   const char *stmod_name;
-   struct util_dl_library *lib;
-   const struct st_module *mod;
-
-   switch (api) {
-   case ST_API_OPENGL:
-      stmod_name = ST_MODULE_OPENGL_SYMBOL;
-      break;
-   case ST_API_OPENGL_ES1:
-      stmod_name = ST_MODULE_OPENGL_ES1_SYMBOL;
-      break;
-   case ST_API_OPENGL_ES2:
-      stmod_name = ST_MODULE_OPENGL_ES2_SYMBOL;
-      break;
-   case ST_API_OPENVG:
-      stmod_name = ST_MODULE_OPENVG_SYMBOL;
-      break;
-   default:
-      stmod_name = NULL;
-      break;
-   }
-   if (!stmod_name)
-      return NULL;
-
-   mod = NULL;
-   lib = util_dl_open(NULL);
-   if (lib) {
-      mod = (const struct st_module *)
-         util_dl_get_proc_address(lib, stmod_name);
-      util_dl_close(lib);
-   }
-   if (!mod || mod->api != api)
-      return NULL;
-
-   return mod->create_api();
-}
-
 static boolean
 egl_g3d_st_manager_get_egl_image(struct st_manager *smapi,
-                                 struct st_egl_image *stimg)
+                                 void *egl_image,
+                                 struct st_egl_image *out)
 {
    struct egl_g3d_st_manager *gsmapi = egl_g3d_st_manager(smapi);
-   EGLImageKHR handle = (EGLImageKHR) stimg->egl_image;
+   EGLImageKHR handle = (EGLImageKHR) egl_image;
    _EGLImage *img;
    struct egl_g3d_image *gimg;
 
@@ -105,17 +70,23 @@ egl_g3d_st_manager_get_egl_image(struct st_manager *smapi,
 
    gimg = egl_g3d_image(img);
 
-   stimg->texture = NULL;
-   pipe_texture_reference(&stimg->texture, gimg->texture);
-   stimg->face = gimg->face;
-   stimg->level = gimg->level;
-   stimg->zslice = gimg->zslice;
+   out->texture = NULL;
+   pipe_resource_reference(&out->texture, gimg->texture);
+   out->level = gimg->level;
+   out->layer = gimg->layer;
 
    _eglUnlockMutex(&gsmapi->display->Mutex);
 
    return TRUE;
 }
 
+static int
+egl_g3d_st_manager_get_param(struct st_manager *smapi,
+                             enum st_manager_param param)
+{
+   return 0;
+}
+
 struct st_manager *
 egl_g3d_create_st_manager(_EGLDisplay *dpy)
 {
@@ -128,6 +99,7 @@ egl_g3d_create_st_manager(_EGLDisplay *dpy)
 
       gsmapi->base.screen = gdpy->native->screen;
       gsmapi->base.get_egl_image = egl_g3d_st_manager_get_egl_image;
+      gsmapi->base.get_param = egl_g3d_st_manager_get_param;
    }
 
    return &gsmapi->base;;
@@ -137,7 +109,7 @@ void
 egl_g3d_destroy_st_manager(struct st_manager *smapi)
 {
    struct egl_g3d_st_manager *gsmapi = egl_g3d_st_manager(smapi);
-   free(gsmapi);
+   FREE(gsmapi);
 }
 
 static boolean
@@ -147,15 +119,43 @@ egl_g3d_st_framebuffer_flush_front_pbuffer(struct st_framebuffer_iface *stfbi,
    return TRUE;
 }
 
-static boolean 
+static void
+pbuffer_reference_openvg_image(struct egl_g3d_surface *gsurf)
+{
+   /* TODO */
+}
+
+static void
+pbuffer_allocate_pbuffer_texture(struct egl_g3d_surface *gsurf)
+{
+   struct egl_g3d_display *gdpy =
+      egl_g3d_display(gsurf->base.Resource.Display);
+   struct pipe_screen *screen = gdpy->native->screen;
+   struct pipe_resource templ, *ptex;
+
+   memset(&templ, 0, sizeof(templ));
+   templ.target = PIPE_TEXTURE_2D;
+   templ.last_level = 0;
+   templ.width0 = gsurf->base.Width;
+   templ.height0 = gsurf->base.Height;
+   templ.depth0 = 1;
+   templ.array_size = 1;
+   templ.format = gsurf->stvis.color_format;
+   /* for rendering and binding to texture */
+   templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+
+   ptex = screen->resource_create(screen, &templ);
+   gsurf->render_texture = ptex;
+}
+
+static boolean
 egl_g3d_st_framebuffer_validate_pbuffer(struct st_framebuffer_iface *stfbi,
                                         const enum st_attachment_type *statts,
                                         unsigned count,
-                                        struct pipe_texture **out)
+                                        struct pipe_resource **out)
 {
    _EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private;
    struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
-   struct pipe_texture templ;
    unsigned i;
 
    for (i = 0; i < count; i++) {
@@ -165,23 +165,22 @@ egl_g3d_st_framebuffer_validate_pbuffer(struct st_framebuffer_iface *stfbi,
          continue;
 
       if (!gsurf->render_texture) {
-         struct egl_g3d_display *gdpy =
-            egl_g3d_display(gsurf->base.Resource.Display);
-         struct pipe_screen *screen = gdpy->native->screen;
-
-         memset(&templ, 0, sizeof(templ));
-         templ.target = PIPE_TEXTURE_2D;
-         templ.last_level = 0;
-         templ.width0 = gsurf->base.Width;
-         templ.height0 = gsurf->base.Height;
-         templ.depth0 = 1;
-         templ.format = gsurf->stvis.color_format;
-         templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
-
-         gsurf->render_texture = screen->texture_create(screen, &templ);
+         switch (gsurf->client_buffer_type) {
+         case EGL_NONE:
+            pbuffer_allocate_pbuffer_texture(gsurf);
+            break;
+         case EGL_OPENVG_IMAGE:
+            pbuffer_reference_openvg_image(gsurf);
+            break;
+         default:
+            break;
+         }
+
+         if (!gsurf->render_texture)
+            return FALSE;
       }
 
-      pipe_texture_reference(&out[i], gsurf->render_texture);
+      pipe_resource_reference(&out[i], gsurf->render_texture);
    }
 
    return TRUE;
@@ -194,18 +193,19 @@ egl_g3d_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi,
    _EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private;
    struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
 
-   return gsurf->native->flush_frontbuffer(gsurf->native);
+   return gsurf->native->present(gsurf->native,
+         NATIVE_ATTACHMENT_FRONT_LEFT, FALSE, 0);
 }
 
 static boolean 
 egl_g3d_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
                                 const enum st_attachment_type *statts,
                                 unsigned count,
-                                struct pipe_texture **out)
+                                struct pipe_resource **out)
 {
    _EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private;
    struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
-   struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
+   struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS];
    uint attachment_mask = 0;
    unsigned i;
 
@@ -240,7 +240,7 @@ egl_g3d_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
       return FALSE;
 
    for (i = 0; i < count; i++) {
-      struct pipe_texture *tex;
+      struct pipe_resource *tex;
       int natt;
 
       switch (statts[i]) {
@@ -265,7 +265,7 @@ egl_g3d_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
          tex = textures[natt];
 
          if (statts[i] == stfbi->visual->render_buffer)
-            pipe_texture_reference(&gsurf->render_texture, tex);
+            pipe_resource_reference(&gsurf->render_texture, tex);
 
          if (attachment_mask & (1 << natt)) {
             /* transfer the ownership to the caller */
@@ -274,7 +274,7 @@ egl_g3d_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
          }
          else {
             /* the attachment is listed more than once */
-            pipe_texture_reference(&out[i], tex);
+            pipe_resource_reference(&out[i], tex);
          }
       }
    }
@@ -293,6 +293,8 @@ egl_g3d_create_st_framebuffer(_EGLSurface *surf)
       return NULL;
 
    stfbi->visual = &gsurf->stvis;
+   p_atomic_set(&stfbi->stamp, 1);
+
    if (gsurf->base.Type != EGL_PBUFFER_BIT) {
       stfbi->flush_front = egl_g3d_st_framebuffer_flush_front;
       stfbi->validate = egl_g3d_st_framebuffer_validate;
@@ -309,5 +311,5 @@ egl_g3d_create_st_framebuffer(_EGLSurface *surf)
 void
 egl_g3d_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi)
 {
-   free(stfbi);
+   FREE(stfbi);
 }