2 * Copyright © 2019 Intel Corporation
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-util-egl.h"
25 #include "piglit-util-gl.h"
28 * @file egl-flush-external.c
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config
.supports_gl_es_version
= 20;
35 PIGLIT_GL_TEST_CONFIG_END
37 typedef EGLBoolean (EGLAPIENTRYP PFNEGLIMAGEFLUSHEXTERNALEXTPROC
) (EGLDisplay dpy
, EGLImage image
, const EGLAttribKHR
*attrib_list
);
38 typedef EGLBoolean (EGLAPIENTRYP PFNEGLIMAGEINVALIDATEEXTERNALEXTPROC
) (EGLDisplay dpy
, EGLImage image
, const EGLAttribKHR
*attrib_list
);
39 #define EGL_IMAGE_EXTERNAL_FLUSH_EXT 0x32A2
49 piglit_init(int argc
, char **argv
)
51 piglit_require_extension("GL_OES_EGL_image");
53 PFNEGLCREATEIMAGEKHRPROC peglCreateImageKHR
= NULL
;
54 peglCreateImageKHR
= (PFNEGLCREATEIMAGEKHRPROC
)
55 eglGetProcAddress("eglCreateImageKHR");
56 if (!peglCreateImageKHR
) {
57 fprintf(stderr
, "eglCreateImageKHR missing\n");
58 piglit_report_result(PIGLIT_SKIP
);
61 PFNEGLDESTROYIMAGEKHRPROC peglDestroyImageKHR
= NULL
;
62 peglDestroyImageKHR
= (PFNEGLDESTROYIMAGEKHRPROC
)
63 eglGetProcAddress("eglDestroyImageKHR");
64 if (!peglDestroyImageKHR
) {
65 fprintf(stderr
, "eglDestroyImageKHR missing\n");
66 piglit_report_result(PIGLIT_SKIP
);
69 /* Require EGL_MESA_platform_surfaceless extension. */
70 const char *exts
= eglQueryString(EGL_NO_DISPLAY
, EGL_EXTENSIONS
);
71 if (!strstr(exts
, "EGL_MESA_platform_surfaceless"))
72 piglit_report_result(PIGLIT_SKIP
);
77 dpy
= piglit_egl_get_default_display(EGL_PLATFORM_SURFACELESS_MESA
);
79 if (!eglInitialize(dpy
, &major
, &minor
))
80 piglit_report_result(PIGLIT_FAIL
);
82 piglit_require_egl_extension(dpy
, "EGL_MESA_configless_context");
83 piglit_require_egl_extension(dpy
, "EGL_EXT_image_flush_external");
85 PFNEGLIMAGEFLUSHEXTERNALEXTPROC peglImageFlushExternalEXT
= NULL
;
86 peglImageFlushExternalEXT
= (PFNEGLIMAGEFLUSHEXTERNALEXTPROC
)
87 eglGetProcAddress("eglImageFlushExternalEXT");
88 if (!peglImageFlushExternalEXT
) {
89 fprintf(stderr
, "eglImageFlushExternalEXT missing\n");
90 piglit_report_result(PIGLIT_FAIL
);
93 PFNEGLIMAGEINVALIDATEEXTERNALEXTPROC peglImageInvalidateExternalEXT
= NULL
;
94 peglImageInvalidateExternalEXT
= (PFNEGLIMAGEINVALIDATEEXTERNALEXTPROC
)
95 eglGetProcAddress("eglImageInvalidateExternalEXT");
96 if (!peglImageInvalidateExternalEXT
) {
97 fprintf(stderr
, "eglImageInvalidateExternalEXT missing\n");
98 piglit_report_result(PIGLIT_FAIL
);
101 EGLint ctx_attr
[] = { EGL_CONTEXT_CLIENT_VERSION
, 2, EGL_NONE
};
103 eglCreateContext(dpy
, EGL_NO_CONFIG_KHR
, EGL_NO_CONTEXT
, ctx_attr
);
104 if (ctx
== EGL_NO_CONTEXT
) {
105 fprintf(stderr
, "could not create EGL context\n");
106 piglit_report_result(PIGLIT_FAIL
);
109 eglMakeCurrent(dpy
, EGL_NO_SURFACE
, EGL_NO_SURFACE
, ctx
);
111 /* Create a texture. */
113 glGenTextures(1, &texture
);
114 glBindTexture(GL_TEXTURE_2D
, texture
);
116 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 256, 256, 0, GL_RGBA
,
117 GL_UNSIGNED_BYTE
, NULL
);
119 if (!piglit_check_gl_error(GL_NO_ERROR
))
120 piglit_report_result(PIGLIT_FAIL
);
122 /* Create EGLImage with EGL_IMAGE_EXTERNAL_FLUSH_EXT set. */
123 EGLint attribs
[] = { EGL_IMAGE_EXTERNAL_FLUSH_EXT
, EGL_TRUE
, EGL_NONE
};
124 EGLImageKHR egl_image
;
125 egl_image
= peglCreateImageKHR(dpy
, ctx
, EGL_GL_TEXTURE_2D
,
126 (EGLClientBuffer
) (intptr_t) texture
,
129 fprintf(stderr
, "failed to create ImageKHR\n");
130 piglit_report_result(PIGLIT_FAIL
);
133 EGLBoolean status
= EGL_FALSE
;
135 /* Call flush & invalidate with invalid parameters. */
136 const EGLAttribKHR bad_attrs
[] = { EGL_RED_SIZE
, EGL_GREEN_SIZE
};
138 status
= peglImageFlushExternalEXT(dpy
, egl_image
, bad_attrs
);
139 if (!piglit_check_egl_error(EGL_BAD_PARAMETER
))
140 piglit_report_result(PIGLIT_FAIL
);
141 if (status
== EGL_TRUE
) {
142 fprintf(stderr
, "expected EGL_FALSE but got 0x%x\n", status
);
143 piglit_report_result(PIGLIT_FAIL
);
146 status
= peglImageInvalidateExternalEXT(dpy
, egl_image
, bad_attrs
);
147 if (!piglit_check_egl_error(EGL_BAD_PARAMETER
))
148 piglit_report_result(PIGLIT_FAIL
);
149 if (status
== EGL_TRUE
) {
150 fprintf(stderr
, "expected EGL_FALSE but got 0x%x\n", status
);
151 piglit_report_result(PIGLIT_FAIL
);
154 /* Call flush & invalidate with proper parameters. */
155 const EGLAttribKHR good_attrs
[] = { EGL_NONE
, EGL_NONE
};
156 status
= peglImageFlushExternalEXT(dpy
, egl_image
, good_attrs
);
157 if (!piglit_check_egl_error(EGL_SUCCESS
))
158 piglit_report_result(PIGLIT_FAIL
);
160 status
= peglImageInvalidateExternalEXT(dpy
, egl_image
, good_attrs
);
161 if (!piglit_check_egl_error(EGL_SUCCESS
))
162 piglit_report_result(PIGLIT_FAIL
);
164 glDeleteTextures(1, &texture
);
165 peglDestroyImageKHR(dpy
, egl_image
);
167 eglMakeCurrent(dpy
, EGL_NO_SURFACE
, EGL_NO_SURFACE
, EGL_NO_CONTEXT
);
170 piglit_report_result(PIGLIT_PASS
);