Test to create egl pbuffer surface, clear it with glClear, draw it to window and read written color back.
Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikk...@gmail.com> --- tests/all.py | 1 + tests/egl/CMakeLists.gl.txt | 2 + tests/egl/egl-create-pbuffer-surface.c | 135 +++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 tests/egl/egl-create-pbuffer-surface.c diff --git a/tests/all.py b/tests/all.py index 831af29..665c88b 100644 --- a/tests/all.py +++ b/tests/all.py @@ -4135,6 +4135,7 @@ egl14['eglQuerySurface EGL_BAD_SURFACE'] = plain_test('egl-query-surface --bad-s egl14['eglQuerySurface EGL_HEIGHT'] = plain_test('egl-query-surface --attr=EGL_HEIGHT') egl14['eglQuerySurface EGL_WIDTH'] = plain_test('egl-query-surface --attr=EGL_WIDTH') egl14['eglTerminate then unbind context'] = plain_test('egl-terminate-then-unbind-context') +egl14['eglCreatePbufferSurface and then glClear'] = plain_test('egl-create-pbuffer-surface') egl_nok_swap_region = {} spec['EGL_NOK_swap_region'] = egl_nok_swap_region diff --git a/tests/egl/CMakeLists.gl.txt b/tests/egl/CMakeLists.gl.txt index d7f17f6..b23b96e 100644 --- a/tests/egl/CMakeLists.gl.txt +++ b/tests/egl/CMakeLists.gl.txt @@ -20,6 +20,8 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") target_link_libraries(egl-create-surface pthread ${X11_X11_LIB}) piglit_add_executable (egl-query-surface egl-util.c egl-query-surface.c) target_link_libraries(egl-query-surface pthread ${X11_X11_LIB}) + piglit_add_executable (egl-create-pbuffer-surface egl-util.c egl-create-pbuffer-surface.c) + target_link_libraries(egl-create-pbuffer-surface pthread ${X11_X11_LIB}) ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") # vim: ft=cmake: diff --git a/tests/egl/egl-create-pbuffer-surface.c b/tests/egl/egl-create-pbuffer-surface.c new file mode 100644 index 0000000..34a82c3 --- /dev/null +++ b/tests/egl/egl-create-pbuffer-surface.c @@ -0,0 +1,135 @@ +/* + * Copyright © 2014 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Author: Juha-Pekka Heikkilä <juhapekka.heikk...@gmail.com> + */ + +/** @file egl-create-pbuffer-surface.c + * + * Test EGLCreatePBufferSurface behaviour. + */ + +#include <unistd.h> +#include "piglit-util-gl.h" +#include "egl-util.h" + +#define check_color(r, g, b, a, x_pos, y_pos) \ + eglMakeCurrent(state->egl_dpy, surf, surf, state->ctx); \ + glClearColor(r, g, b, a); \ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); \ + glFinish(); \ + eglMakeCurrent(state->egl_dpy, state->surf, state->surf, state->ctx); \ + piglit_draw_rect_tex(0, 0, 256, 256, 0, 0, 1, 1); \ + glReadPixels(x_pos, y_pos, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, \ + (void*)&pixelit ); \ + if (pixelit[0] != r*255 || \ + pixelit[1] != g*255 || \ + pixelit[2] != b*255 || \ + pixelit[3] != a*255 ) { \ + fprintf(stderr, "glReadPixels failed:\n"); \ + fprintf(stderr, " - Expected %d, %d, %d, %d\n", (int)(r*255), \ + (int)(g*255), (int)(b*255), (int)(a*255)); \ + fprintf(stderr, " - Received %d, %d, %d, %d\n", pixelit[0], \ + pixelit[1], pixelit[2], pixelit[3]); \ + rval = PIGLIT_FAIL; \ + } \ + eglSwapBuffers(state->egl_dpy, state->surf); + +static enum piglit_result +draw(struct egl_state *state) +{ + EGLSurface surf; + unsigned char pixelit[4]; + enum piglit_result rval = PIGLIT_PASS; + + const EGLint srfPbufferAttr[] = + { + EGL_WIDTH, 256, + EGL_HEIGHT, 256, + EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA, + EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, + EGL_LARGEST_PBUFFER, EGL_TRUE, + EGL_NONE + }; + + surf = eglCreatePbufferSurface(state->egl_dpy, state->cfg, + srfPbufferAttr); + + if (eglGetError() != EGL_SUCCESS || surf == EGL_NO_SURFACE) { + fprintf(stderr, "eglCreatePbufferSurface failed\n"); + piglit_report_result(PIGLIT_FAIL); + return PIGLIT_FAIL; + } + + if (!eglMakeCurrent(state->egl_dpy, surf, surf, state->ctx)) { + fprintf(stderr, "eglMakeCurrent() failed for pbuffer surface\n"); + piglit_report_result(PIGLIT_FAIL); + return PIGLIT_FAIL; + } + + glEnable(GL_TEXTURE_2D); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + if (!eglMakeCurrent(state->egl_dpy, + state->surf, state->surf, state->ctx)) { + fprintf(stderr, "eglMakeCurrent() failed\n"); + piglit_report_result(PIGLIT_FAIL); + return PIGLIT_FAIL; + } + + glEnable(GL_TEXTURE_2D); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + glClearColor(0.5, 0.0, 0.5, 1.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + eglBindTexImage(state->egl_dpy, surf, EGL_BACK_BUFFER); + + glViewport(0, 0, state->width, state->height); + piglit_ortho_projection(state->width, state->height, GL_FALSE); + + check_color(1.0, 0.0, 0.0, 0.0, 0, 0); + check_color(0.0, 1.0, 0.0, 0.0, 32, 32); + check_color(0.0, 0.0, 1.0, 0.0, 128, 128); + check_color(0.0, 0.0, 0.0, 1.0, 255, 255); + + piglit_report_result(rval); + return rval; +} + +int +main(int argc, char *argv[]) +{ + struct egl_test test; + + egl_init_test(&test); + test.draw = draw; + test.stop_on_failure = false; + + if (egl_util_run(&test, argc, argv) != PIGLIT_PASS) + return EXIT_FAILURE; + return EXIT_SUCCESS; +} -- 1.8.5.1 _______________________________________________ Piglit mailing list Piglit@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/piglit