summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2008-11-09 00:24:25 -0500
committerKristian Høgsberg <krh@redhat.com>2008-11-09 00:24:25 -0500
commit7b68def4ae0546cba961a66d1acc9ad083cdaeb3 (patch)
treeee625c841eefae5c1722f5737aef5570b589b426
parentdad063d68f6f5b6103740ebd63205c2aa4f66aba (diff)
Add an eglReadBuffer function to read out pixel data.
-rw-r--r--eagle.h3
-rw-r--r--intel.c35
2 files changed, 38 insertions, 0 deletions
diff --git a/eagle.h b/eagle.h
index a47a23b..bd2f2a9 100644
--- a/eagle.h
+++ b/eagle.h
@@ -235,6 +235,9 @@ extern EGLBoolean eglCopyNativeBuffers(EGLDisplay display,
EGLSurface src, GLenum srcBuffer,
int32_t x, int32_t y, int32_t width, int32_t height);
+extern void *eglReadBuffer(EGLDisplay display,
+ EGLSurface surface, GLenum buffer, GLuint *stride);
+
extern EGLBoolean eglDestroySurface(EGLDisplay display,
EGLSurface surface);
diff --git a/intel.c b/intel.c
index 1cac601..d0af60e 100644
--- a/intel.c
+++ b/intel.c
@@ -373,6 +373,8 @@ eglCreateSurfaceForName(EGLDisplay display, EGLConfig config,
return &nativeSurface->base;
}
+#ifdef __DRI_COPY_BUFFER
+
EGLBoolean
eglCopyNativeBuffers(EGLDisplay display,
EGLSurface dst, GLenum dstBuffer, int32_t dst_x, int32_t dst_y,
@@ -405,3 +407,36 @@ eglCopyNativeBuffers(EGLDisplay display,
srcDRIBuffer,
x, y, width, height);
}
+
+#endif
+
+void *
+eglReadBuffer(EGLDisplay display,
+ EGLSurface surface, GLenum buffer, GLuint *stride)
+{
+ EGLSurfaceNative nativeSurface = (EGLSurfaceNative) surface;
+ struct drm_i915_gem_pread pread;
+ void *data;
+
+ *stride = surface->buffers[0].pitch;
+ pread.handle = nativeSurface->handles[0];
+ pread.pad = 0;
+ pread.offset = 0;
+ pread.size = *stride * nativeSurface->height;
+
+ data = malloc(pread.size);
+ if (data == NULL) {
+ fprintf(stderr, "swap buffers malloc failed\n");
+ return NULL;
+ }
+
+ pread.data_ptr = (long) data;
+
+ if (ioctl(display->fd, DRM_IOCTL_I915_GEM_PREAD, &pread)) {
+ fprintf(stderr, "gem pread failed\n");
+ free(data);
+ return NULL;
+ }
+
+ return data;
+}