2 * Copyright © 2017 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-context-priority.c
30 * EGL API tests for IMG_context_priority extension:
31 * https://www.khronos.org/registry/EGL/extensions/IMG/EGL_IMG_context_priority.txt
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config
.supports_gl_compat_version
= 10;
38 PIGLIT_GL_TEST_CONFIG_END
48 check_priority(EGLDisplay dpy
, EGLContext ctx
, EGLint
*expected
)
52 eglQueryContext(dpy
, ctx
, EGL_CONTEXT_PRIORITY_LEVEL_IMG
, &value
);
54 if (status
== EGL_FALSE
) {
55 fprintf(stderr
, "eglQueryContext failed\n");
56 piglit_report_result(PIGLIT_FAIL
);
59 if (expected
&& value
!= *expected
) {
60 fprintf(stderr
, "%s fail: value 0x%x, expected 0x%x\n",
61 __func__
, value
, *expected
);
62 piglit_report_result(PIGLIT_FAIL
);
68 create_context(EGLDisplay dpy
, EGLint
*attr
)
71 eglCreateContext(dpy
, EGL_NO_CONFIG_KHR
, EGL_NO_CONTEXT
, attr
);
73 if (ctx
== EGL_NO_CONTEXT
) {
74 fprintf(stderr
, "could not create EGL context, attr 0x%x\n", attr
[1]);
75 piglit_report_result(PIGLIT_FAIL
);
81 piglit_init(int argc
, char **argv
)
87 EGLint attr
[] = { EGL_NONE
, EGL_NONE
, EGL_NONE
};
90 /* Supported priority levels from extension spec. */
92 EGL_CONTEXT_PRIORITY_HIGH_IMG
,
93 EGL_CONTEXT_PRIORITY_MEDIUM_IMG
,
94 EGL_CONTEXT_PRIORITY_LOW_IMG
97 dpy
= piglit_egl_get_default_display(EGL_NONE
);
99 ok
= eglInitialize(dpy
, &major
, &minor
);
101 piglit_report_result(PIGLIT_FAIL
);
104 piglit_require_egl_extension(dpy
, "EGL_IMG_context_priority");
105 piglit_require_egl_extension(dpy
, "EGL_MESA_configless_context");
107 ctx
= create_context(dpy
, attr
);
109 /* Verify default priority level. */
110 expect
= EGL_CONTEXT_PRIORITY_MEDIUM_IMG
;
111 check_priority(dpy
, ctx
, &expect
);
112 eglDestroyContext(dpy
, ctx
);
114 /* Verify that invalid priority level fails. */
115 attr
[0] = EGL_CONTEXT_PRIORITY_LEVEL_IMG
;
116 attr
[1] = EGL_TRANSPARENT_RED_VALUE
;
118 ctx
= eglCreateContext(dpy
, EGL_NO_CONFIG_KHR
, EGL_NO_CONTEXT
, attr
);
120 if (ctx
!= EGL_NO_CONTEXT
) {
121 fprintf(stderr
, "should fail with invalid parameter\n");
122 piglit_report_result(PIGLIT_FAIL
);
125 /* Verify that creating a context with each defined priority level
126 * succeeds, also print what we asked and which priority level we got.
128 for (unsigned i
= 0; i
< ARRAY_SIZE(levels
); i
++) {
130 ctx
= create_context(dpy
, attr
);
131 fprintf(stderr
, "passed hint 0x%x, context created has 0x%x priority\n",
132 levels
[i
], check_priority(dpy
, ctx
, NULL
));
134 eglDestroyContext(dpy
, ctx
);
137 piglit_report_result(PIGLIT_PASS
);