Squashed commit of the following:
[mesa.git] / src / gallium / state_trackers / egl / common / egl_g3d.c
index 5eabe10558a87795f48839b22e2b7f503442106d..efddf56cbf9a3f89c79264cab3ad4e659f881df1 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.
  */
 
 #include <assert.h>
@@ -236,7 +237,7 @@ egl_g3d_init_config(_EGLDriver *drv, _EGLDisplay *dpy,
    gconf->stvis.accum_format = PIPE_FORMAT_NONE;
    gconf->stvis.samples = 0;
 
-   gconf->stvis.render_buffer = (buffer_mask & ST_ATTACHMENT_BACK_LEFT) ?
+   gconf->stvis.render_buffer = (buffer_mask & ST_ATTACHMENT_BACK_LEFT_MASK) ?
       ST_ATTACHMENT_BACK_LEFT : ST_ATTACHMENT_FRONT_LEFT;
 
    api_mask = 0;
@@ -524,9 +525,6 @@ egl_g3d_create_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
    case EGL_PIXMAP_BIT:
       err = "eglCreatePixmapSurface";
       break;
-   case EGL_PBUFFER_BIT:
-      err = "eglCreatePBufferSurface";
-      break;
 #ifdef EGL_MESA_screen_surface
    case EGL_SCREEN_BIT_MESA:
       err = "eglCreateScreenSurface";
@@ -558,10 +556,6 @@ egl_g3d_create_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
       nsurf = gdpy->native->create_pixmap_surface(gdpy->native,
             arg->u.pix, gconf->native);
       break;
-   case EGL_PBUFFER_BIT:
-      nsurf = gdpy->native->create_pbuffer_surface(gdpy->native,
-            gconf->native, gsurf->base.Width, gsurf->base.Height);
-      break;
 #ifdef EGL_MESA_screen_surface
    case EGL_SCREEN_BIT_MESA:
       /* prefer back buffer (move to _eglInitSurface?) */
@@ -593,7 +587,7 @@ egl_g3d_create_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
 
    gsurf->stfbi = egl_g3d_create_st_framebuffer(&gsurf->base);
    if (!gsurf->stfbi) {
-      gsurf->native->destroy(gsurf->native);
+      nsurf->destroy(nsurf);
       free(gsurf);
       return NULL;
    }
@@ -636,12 +630,29 @@ static _EGLSurface *
 egl_g3d_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy,
                                _EGLConfig *conf, const EGLint *attribs)
 {
-   struct egl_g3d_create_surface_arg arg;
+   struct egl_g3d_config *gconf = egl_g3d_config(conf);
+   struct egl_g3d_surface *gsurf;
 
-   memset(&arg, 0, sizeof(arg));
-   arg.type = EGL_PBUFFER_BIT;
+   gsurf = CALLOC_STRUCT(egl_g3d_surface);
+   if (!gsurf) {
+      _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface");
+      return NULL;
+   }
 
-   return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs);
+   if (!_eglInitSurface(&gsurf->base, dpy, EGL_PBUFFER_BIT, conf, attribs)) {
+      free(gsurf);
+      return NULL;
+   }
+
+   gsurf->stvis = gconf->stvis;
+
+   gsurf->stfbi = egl_g3d_create_st_framebuffer(&gsurf->base);
+   if (!gsurf->stfbi) {
+      free(gsurf);
+      return NULL;
+   }
+
+   return &gsurf->base;
 }
 
 /**
@@ -656,9 +667,10 @@ destroy_surface(_EGLDisplay *dpy, _EGLSurface *surf)
    if (!dpy->Initialized)
       _eglLog(_EGL_FATAL, "destroy a surface with an unitialized display");
 
-   pipe_texture_reference(&gsurf->render_texture, NULL);
+   pipe_resource_reference(&gsurf->render_texture, NULL);
    egl_g3d_destroy_st_framebuffer(gsurf->stfbi);
-   gsurf->native->destroy(gsurf->native);
+   if (gsurf->native)
+      gsurf->native->destroy(gsurf->native);
    free(gsurf);
 }
 
@@ -775,9 +787,10 @@ egl_g3d_find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix)
  */
 static struct pipe_surface *
 get_pipe_surface(struct native_display *ndpy, struct native_surface *nsurf,
-                 enum native_attachment natt)
+                 enum native_attachment natt,
+                unsigned bind)
 {
-   struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
+   struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS];
    struct pipe_surface *psurf;
 
    textures[natt] = NULL;
@@ -786,8 +799,8 @@ get_pipe_surface(struct native_display *ndpy, struct native_surface *nsurf,
       return NULL;
 
    psurf = ndpy->screen->get_tex_surface(ndpy->screen, textures[natt],
-         0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE);
-   pipe_texture_reference(&textures[natt], NULL);
+         0, 0, 0, bind);
+   pipe_resource_reference(&textures[natt], NULL);
 
    return psurf;
 }
@@ -831,12 +844,13 @@ egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
          return EGL_FALSE;
    }
 
-   psurf = get_pipe_surface(gdpy->native, nsurf, NATIVE_ATTACHMENT_FRONT_LEFT);
+   psurf = get_pipe_surface(gdpy->native, nsurf, NATIVE_ATTACHMENT_FRONT_LEFT,
+                           PIPE_BIND_BLIT_DESTINATION);
    if (psurf) {
       struct pipe_surface *psrc;
 
       psrc = screen->get_tex_surface(screen, gsurf->render_texture,
-            0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ);
+            0, 0, 0, PIPE_BIND_BLIT_SOURCE);
       if (psrc) {
          gdpy->pipe->surface_copy(gdpy->pipe, psurf, 0, 0,
                psrc, 0, 0, psurf->width, psurf->height);
@@ -879,7 +893,9 @@ egl_g3d_wait_native(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine)
 
    if (ctx && ctx->DrawSurface) {
       struct egl_g3d_surface *gsurf = egl_g3d_surface(ctx->DrawSurface);
-      gsurf->native->wait(gsurf->native);
+
+      if (gsurf->native)
+         gsurf->native->wait(gsurf->native);
    }
 
    return EGL_TRUE;