diff options
author | Eric Anholt <eric@anholt.net> | 2016-07-25 13:46:30 -0700 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2016-08-18 16:21:51 -0700 |
commit | f1668a1a81acaaa52a18a48f4a92407d1a4edc05 (patch) | |
tree | 59478dd5b11b3e817813d78c257d98a219ac19a0 | |
parent | d17eadb218876f1f24f0e3481eed4e29260f06fb (diff) |
sample_common: Factor out image creation for a dmabuf fd.
I need to reuse this part, without the destruction, for refcounting
tests.
Reviewed-by: Rob Clark <robdclark@gmail.com>
-rw-r--r-- | tests/spec/ext_image_dma_buf_import/sample_common.c | 40 | ||||
-rw-r--r-- | tests/spec/ext_image_dma_buf_import/sample_common.h | 4 |
2 files changed, 34 insertions, 10 deletions
diff --git a/tests/spec/ext_image_dma_buf_import/sample_common.c b/tests/spec/ext_image_dma_buf_import/sample_common.c index 7373cd4c5..370baa426 100644 --- a/tests/spec/ext_image_dma_buf_import/sample_common.c +++ b/tests/spec/ext_image_dma_buf_import/sample_common.c @@ -110,9 +110,9 @@ sample_and_destroy_img(unsigned w, unsigned h, EGLImageKHR img) return PIGLIT_PASS; } -static enum piglit_result -sample_buffer(void *buf, int fd, int fourcc, unsigned w, unsigned h, - unsigned stride, unsigned offset) +enum piglit_result +egl_image_for_dma_buf_fd(int fd, int fourcc, int w, int h, + unsigned stride, unsigned offset, EGLImageKHR *out_img) { EGLint error; EGLImageKHR img; @@ -170,10 +170,9 @@ sample_buffer(void *buf, int fd, int fourcc, unsigned w, unsigned h, } img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT, - EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr); - - /* Release the creator side of the buffer. */ - piglit_destroy_dma_buf(buf); + EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, + attr); + *out_img = img; error = eglGetError(); @@ -185,9 +184,6 @@ sample_buffer(void *buf, int fd, int fourcc, unsigned w, unsigned h, printf("eglCreateImageKHR() failed: %s 0x%x\n", piglit_get_egl_error_name(error), error); - /* Close the descriptor also, EGL does not have ownership */ - close(fd); - return PIGLIT_FAIL; } @@ -196,6 +192,30 @@ sample_buffer(void *buf, int fd, int fourcc, unsigned w, unsigned h, return PIGLIT_FAIL; } + *out_img = img; + return PIGLIT_PASS; +} + +static enum piglit_result +sample_buffer(void *buf, int fd, int fourcc, unsigned w, unsigned h, + unsigned stride, unsigned offset) +{ + enum piglit_result res; + EGLImageKHR img; + + res = egl_image_for_dma_buf_fd(fd, fourcc, w, h, stride, offset, &img); + + /* Release the creator side of the buffer. */ + piglit_destroy_dma_buf(buf); + + if (!img) { + /* Close the descriptor also, EGL does not have ownership */ + close(fd); + } + + if (res != PIGLIT_PASS) + return res; + return sample_and_destroy_img(w, h, img); } diff --git a/tests/spec/ext_image_dma_buf_import/sample_common.h b/tests/spec/ext_image_dma_buf_import/sample_common.h index 8559e9fe5..7160b816c 100644 --- a/tests/spec/ext_image_dma_buf_import/sample_common.h +++ b/tests/spec/ext_image_dma_buf_import/sample_common.h @@ -35,4 +35,8 @@ enum piglit_result dma_buf_create_and_sample_32bpp(unsigned w, unsigned h, unsigned cpp, int fourcc, const unsigned char *src); +enum piglit_result +egl_image_for_dma_buf_fd(int fd, int fourcc, int w, int h, + unsigned stride, unsigned offset, EGLImageKHR *out_img); + #endif /* SAMPLE_COMMON_H */ |