st/egl: Move the copy context to the native display structure
authorThomas Hellstrom <thellstrom@vmware.com>
Thu, 24 Feb 2011 11:59:41 +0000 (12:59 +0100)
committerThomas Hellstrom <thellstrom@vmware.com>
Tue, 1 Mar 2011 09:36:18 +0000 (10:36 +0100)
This makes it usable also for native helpers.
Also add inline functions to access the context and to
uninit the native display structure.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
src/gallium/state_trackers/egl/common/egl_g3d.c
src/gallium/state_trackers/egl/common/egl_g3d.h
src/gallium/state_trackers/egl/common/egl_g3d_api.c
src/gallium/state_trackers/egl/common/native.h
src/gallium/state_trackers/egl/drm/native_drm.c
src/gallium/state_trackers/egl/fbdev/native_fbdev.c
src/gallium/state_trackers/egl/gdi/native_gdi.c
src/gallium/state_trackers/egl/wayland/native_wayland.c
src/gallium/state_trackers/egl/x11/native_ximage.c

index 6107df48822dab0b98ef2b8ba49bd02f0723789c..e60a56074dd57a5dbec4945482d869495f6ad7a9 100644 (file)
@@ -455,9 +455,6 @@ egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy)
 
    _eglReleaseDisplayResources(drv, dpy);
 
-   if (gdpy->pipe)
-      gdpy->pipe->destroy(gdpy->pipe);
-
    if (dpy->Configs) {
       _eglDestroyArray(dpy->Configs, egl_g3d_free_config);
       dpy->Configs = NULL;
index 9873fee6ec28a573eae2aac02659365bc8b54c3b..301db3128ff16da79902a17d9676075af0eec372 100644 (file)
@@ -56,7 +56,6 @@ struct egl_g3d_display {
 
    const struct egl_g3d_loader *loader;
    struct st_manager *smapi;
-   struct pipe_context *pipe;
 };
 
 struct egl_g3d_context {
index c9f94a3c498a83fe6db188ee36f79f848fe144f3..2068256dff285581753ee0379f31a7a258f01a2e 100644 (file)
@@ -640,6 +640,7 @@ egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
    _EGLContext *ctx = _eglGetCurrentContext();
    struct native_surface *nsurf;
    struct pipe_resource *ptex;
+   struct pipe_context *pipe;
 
    if (!gsurf->render_texture)
       return EGL_TRUE;
@@ -655,22 +656,18 @@ egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
             PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
    }
 
-   /* create a pipe context to copy surfaces */
-   if (!gdpy->pipe) {
-      gdpy->pipe =
-         gdpy->native->screen->context_create(gdpy->native->screen, NULL);
-      if (!gdpy->pipe)
-         return EGL_FALSE;
-   }
+   pipe = ndpy_get_copy_context(gdpy->native);
+   if (!pipe)
+      return EGL_FALSE;
 
    ptex = get_pipe_resource(gdpy->native, nsurf, NATIVE_ATTACHMENT_FRONT_LEFT);
    if (ptex) {
       struct pipe_box src_box;
 
       u_box_origin_2d(ptex->width0, ptex->height0, &src_box);
-      gdpy->pipe->resource_copy_region(gdpy->pipe, ptex, 0, 0, 0, 0,
+      pipe->resource_copy_region(pipe, ptex, 0, 0, 0, 0,
             gsurf->render_texture, 0, &src_box);
-      gdpy->pipe->flush(gdpy->pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
+      pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
       nsurf->present(nsurf, NATIVE_ATTACHMENT_FRONT_LEFT, FALSE, 0);
 
       pipe_resource_reference(&ptex, NULL);
index 42889075a3970b61cf1337f2d82282076147ff52..9246f8c32a42f4ce45db7c2afe2811f2d76dfe4d 100644 (file)
@@ -141,6 +141,11 @@ struct native_display {
     */
    struct pipe_screen *screen;
 
+   /**
+    * Context used for copy operations.
+    */
+   struct pipe_context *pipe;
+
    /**
     * Available for caller's use.
     */
@@ -223,6 +228,29 @@ native_attachment_mask_test(uint mask, enum native_attachment att)
    return !!(mask & (1 << att));
 }
 
+/**
+ * Get the display copy context
+ */
+static INLINE struct pipe_context *
+ndpy_get_copy_context(struct native_display *ndpy)
+{
+   if (!ndpy->pipe)
+      ndpy->pipe = ndpy->screen->context_create(ndpy->screen, NULL);
+   return ndpy->pipe;
+}
+
+/**
+ * Free display screen and context resources
+ */
+static INLINE void
+ndpy_uninit(struct native_display *ndpy)
+{
+   if (ndpy->pipe)
+      ndpy->pipe->destroy(ndpy->pipe);
+   if (ndpy->screen)
+      ndpy->screen->destroy(ndpy->screen);
+}
+
 struct native_platform {
    const char *name;
 
index 6932f30a6a4b1bc11f1b6fe68737ec8ab125535b..cdbb304c5eeee2ac28f5c8d11b682146f3cc79db 100644 (file)
@@ -124,8 +124,7 @@ drm_display_destroy(struct native_display *ndpy)
 
    drm_display_fini_modeset(&drmdpy->base);
 
-   if (drmdpy->base.screen)
-      drmdpy->base.screen->destroy(drmdpy->base.screen);
+   ndpy_uninit(ndpy);
 
    if (drmdpy->fd >= 0)
       close(drmdpy->fd);
index a1e91ba701cdb9fd522ea393e5f5ec42b39af930..4a96039ac39580f58dc342c8ffe415e8db767b2a 100644 (file)
@@ -320,7 +320,7 @@ fbdev_display_destroy(struct native_display *ndpy)
 {
    struct fbdev_display *fbdpy = fbdev_display(ndpy);
 
-   fbdpy->base.screen->destroy(fbdpy->base.screen);
+   ndpy_uninit(&fbdpy->base);
    close(fbdpy->fd);
    FREE(fbdpy);
 }
index 3cc4aefa937af1b04df90e796bff847fb6d255f1..3c2475f84d810fbf41441e9ec501e0b4cfaaf694 100644 (file)
@@ -363,7 +363,7 @@ gdi_display_destroy(struct native_display *ndpy)
    if (gdpy->configs)
       FREE(gdpy->configs);
 
-   gdpy->base.screen->destroy(gdpy->base.screen);
+   ndpy_uninit(ndpy);
 
    FREE(gdpy);
 }
index d4d5f9c2ebb00591f9cc0324887dee8c512afdf7..b10fc54adb8033159d6e55b77445cde137bf7308 100644 (file)
@@ -137,8 +137,7 @@ wayland_display_destroy(struct native_display *ndpy)
    if (display->config)
       FREE(display->config);
 
-   if (display->base.screen)
-      display->base.screen->destroy(display->base.screen);
+   ndpy_uninit(ndpy);
 
    FREE(display);
 }
index d4f4dd04df4ef6f600405d7cf8f074f35fb968e1..8e32c6ff0c49b0bcdd9ac1ac9ec434c6631375ef 100644 (file)
@@ -476,7 +476,7 @@ ximage_display_destroy(struct native_display *ndpy)
    if (xdpy->configs)
       FREE(xdpy->configs);
 
-   xdpy->base.screen->destroy(xdpy->base.screen);
+   ndpy_uninit(ndpy);
 
    x11_screen_destroy(xdpy->xscr);
    if (xdpy->own_dpy)