aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/egl/common
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2011-06-25 15:48:24 +0900
committerChia-I Wu <[email protected]>2011-06-25 16:23:21 +0900
commit7c4e9dcdceec1112c91206619fe8b0885be99a79 (patch)
treeceee00b84d4d07ee06f62a14678e1b508a4e4ff1 /src/gallium/state_trackers/egl/common
parent73df31eedd0f33c8a9907855cb247c8f87964c48 (diff)
st/egl: clean up eglCopyBuffers
Add copy_to_pixmap method to native_display and use it for eglCopyBuffers.
Diffstat (limited to 'src/gallium/state_trackers/egl/common')
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d_api.c44
-rw-r--r--src/gallium/state_trackers/egl/common/native.h11
-rw-r--r--src/gallium/state_trackers/egl/common/native_helper.c41
-rw-r--r--src/gallium/state_trackers/egl/common/native_helper.h5
4 files changed, 59 insertions, 42 deletions
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_api.c b/src/gallium/state_trackers/egl/common/egl_g3d_api.c
index 1d49c30a61e..cd1c355b94e 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d_api.c
+++ b/src/gallium/state_trackers/egl/common/egl_g3d_api.c
@@ -602,21 +602,6 @@ egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
gsurf->base.SwapInterval);
}
-/**
- * Get the pipe surface of the given attachment of the native surface.
- */
-static struct pipe_resource *
-get_pipe_resource(struct native_display *ndpy, struct native_surface *nsurf,
- enum native_attachment natt)
-{
- struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS];
-
- textures[natt] = NULL;
- nsurf->validate(nsurf, 1 << natt, NULL, textures, NULL, NULL);
-
- return textures[natt];
-}
-
static EGLBoolean
egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
EGLNativePixmapType target)
@@ -624,43 +609,18 @@ egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
_EGLContext *ctx = _eglGetCurrentContext();
- struct native_surface *nsurf;
- struct pipe_resource *ptex;
- struct pipe_context *pipe;
if (!gsurf->render_texture)
return EGL_TRUE;
- nsurf = gdpy->native->create_pixmap_surface(gdpy->native, target, NULL);
- if (!nsurf)
- return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers");
-
/* flush if the surface is current */
if (ctx && ctx->DrawSurface == &gsurf->base) {
struct egl_g3d_context *gctx = egl_g3d_context(ctx);
gctx->stctxi->flush(gctx->stctxi, ST_FLUSH_FRONT, NULL);
}
- 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);
- pipe->resource_copy_region(pipe, ptex, 0, 0, 0, 0,
- gsurf->render_texture, 0, &src_box);
- pipe->flush(pipe, NULL);
- nsurf->present(nsurf, NATIVE_ATTACHMENT_FRONT_LEFT, FALSE, 0);
-
- pipe_resource_reference(&ptex, NULL);
- }
-
- nsurf->destroy(nsurf);
-
- return EGL_TRUE;
+ return gdpy->native->copy_to_pixmap(gdpy->native,
+ target, gsurf->render_texture);
}
static EGLBoolean
diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h
index c0b8385cc6b..8d0125750e4 100644
--- a/src/gallium/state_trackers/egl/common/native.h
+++ b/src/gallium/state_trackers/egl/common/native.h
@@ -180,11 +180,22 @@ struct native_display {
*
* This function is usually called to find a config that supports a given
* pixmap. Thus, it is usually called with the same pixmap in a row.
+ *
+ * TODO should be get_pixmap_format() and return the pipe format of the
+ * pixmap.
*/
boolean (*is_pixmap_supported)(struct native_display *ndpy,
EGLNativePixmapType pix,
const struct native_config *nconf);
+ /**
+ * Copy the contents of the resource to the pixmap's front-left attachment.
+ * This is used to implement eglCopyBuffers. Required unless no config has
+ * pixmap_bit set.
+ */
+ boolean (*copy_to_pixmap)(struct native_display *ndpy,
+ EGLNativePixmapType pix,
+ struct pipe_resource *src);
/**
* Create a window surface. Required unless no config has window_bit set.
diff --git a/src/gallium/state_trackers/egl/common/native_helper.c b/src/gallium/state_trackers/egl/common/native_helper.c
index 25857308c5a..6f2097c61a6 100644
--- a/src/gallium/state_trackers/egl/common/native_helper.c
+++ b/src/gallium/state_trackers/egl/common/native_helper.c
@@ -368,6 +368,47 @@ resource_surface_wait(struct resource_surface *rsurf)
while (resource_surface_throttle(rsurf));
}
+boolean
+native_display_copy_to_pixmap(struct native_display *ndpy,
+ EGLNativePixmapType pix,
+ struct pipe_resource *src)
+{
+ struct pipe_context *pipe;
+ struct native_surface *nsurf;
+ struct pipe_resource *dst;
+ struct pipe_resource *tmp[NUM_NATIVE_ATTACHMENTS];
+ const enum native_attachment natt = NATIVE_ATTACHMENT_FRONT_LEFT;
+
+ pipe = ndpy_get_copy_context(ndpy);
+ if (!pipe)
+ return FALSE;
+
+ nsurf = ndpy->create_pixmap_surface(ndpy, pix, NULL);
+ if (!nsurf)
+ return FALSE;
+
+ /* get the texutre */
+ tmp[natt] = NULL;
+ nsurf->validate(nsurf, 1 << natt, NULL, tmp, NULL, NULL);
+ dst = tmp[natt];
+
+ if (dst && dst->format == src->format) {
+ struct pipe_box src_box;
+
+ u_box_origin_2d(src->width0, src->height0, &src_box);
+ pipe->resource_copy_region(pipe, dst, 0, 0, 0, 0, src, 0, &src_box);
+ pipe->flush(pipe, NULL);
+ nsurf->present(nsurf, natt, FALSE, 0);
+ }
+
+ if (dst)
+ pipe_resource_reference(&dst, NULL);
+
+ nsurf->destroy(nsurf);
+
+ return TRUE;
+}
+
#include "state_tracker/drm_driver.h"
struct pipe_resource *
drm_display_import_native_buffer(struct native_display *ndpy,
diff --git a/src/gallium/state_trackers/egl/common/native_helper.h b/src/gallium/state_trackers/egl/common/native_helper.h
index f4d10991f65..e8d91ccb02a 100644
--- a/src/gallium/state_trackers/egl/common/native_helper.h
+++ b/src/gallium/state_trackers/egl/common/native_helper.h
@@ -106,6 +106,11 @@ resource_surface_flush(struct resource_surface *rsurf,
void
resource_surface_wait(struct resource_surface *rsurf);
+boolean
+native_display_copy_to_pixmap(struct native_display *ndpy,
+ EGLNativePixmapType pix,
+ struct pipe_resource *src);
+
struct pipe_resource *
drm_display_import_native_buffer(struct native_display *ndpy,
struct native_buffer *nbuf);