2 * Copyright © 2016 Broadcom
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include "piglit-framework-gl/piglit_drm_dma_buf.h"
26 #include "sample_common.h"
27 #include "image_common.h"
32 * Creates two EGL images from an ARGB8888 dmabuf, samples each one,
33 * destroys one, then tests that the other can still be sampled.
35 * This gets at a common refcounting bug in drivers: GEM returns the
36 * same handle for a given BO re-opened through dmabuf on the same
37 * device fd, but that GEM handle is not refcounted. The userspace
38 * driver needs to be sure that it's doing handle refcounting itself.
41 PIGLIT_GL_TEST_CONFIG_BEGIN
43 config
.supports_gl_es_version
= 20;
44 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
;
46 PIGLIT_GL_TEST_CONFIG_END
51 static int fourcc
= fourcc_code('A', 'R', '2', '4');
53 const unsigned char src
[] = {
54 0x00, 0x00, 0xff, 0xff,
55 0x00, 0xff, 0x00, 0xff,
56 0xff, 0x00, 0x00, 0xff,
57 0xff, 0xff, 0xff, 0xff
59 enum piglit_result res
;
60 struct piglit_dma_buf
*buf
;
61 EGLImageKHR img1
, img2
;
63 /* Scale up factor for drawing the texture to the screen. */
65 int y_spacing
= h
* scale
+ 5;
69 res
= piglit_create_dma_buf(w
, h
, fourcc
, src
, &buf
);
70 if (res
!= PIGLIT_PASS
)
73 res
= egl_image_for_dma_buf_fd(buf
, dup(buf
->fd
), fourcc
, &img1
);
74 if (res
!= PIGLIT_PASS
)
77 res
= egl_image_for_dma_buf_fd(buf
, dup(buf
->fd
), fourcc
, &img2
);
78 if (res
!= PIGLIT_PASS
)
83 res
= texture_for_egl_image(img1
, &tex1
);
84 if (res
!= PIGLIT_PASS
)
87 res
= texture_for_egl_image(img2
, &tex2
);
88 if (res
!= PIGLIT_PASS
)
93 w
* scale
, h
* scale
);
96 w
* scale
, h
* scale
);
98 glDeleteTextures(1, &tex2
);
99 eglDestroyImageKHR(eglGetCurrentDisplay(), img2
);
103 w
* scale
, h
* scale
);
105 expected
= piglit_rgbw_image_ubyte(w
* scale
, h
* scale
, false);
107 for (i
= 0; i
< 3; i
++) {
108 if (!piglit_probe_image_ubyte(0,
110 w
* scale
, h
* scale
,
111 GL_RGBA
, expected
)) {
118 piglit_present_results();
124 piglit_init(int argc
, char **argv
)
126 EGLDisplay egl_dpy
= eglGetCurrentDisplay();
128 piglit_require_egl_extension(egl_dpy
, "EGL_EXT_image_dma_buf_import");
129 piglit_require_extension("GL_OES_EGL_image_external");