summaryrefslogtreecommitdiff
path: root/src/tests/ecore_wl2/ecore_wl2_tests_helper_egl.h
blob: 4446bc547faf4d90b6e4e58144e8aba9a1cacb0d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef ECORE_WL2_TEST_HELPER_EGL_H
# define ECORE_WL2_TEST_HELPER_EGL_H

#include <wayland-egl.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>

static Eina_Bool
_init_egl(Test_Data *td)
{
   eglBindAPI(EGL_OPENGL_API);
   EGLint num_config;

   EGLint attributes[] =
     {
        EGL_RED_SIZE, 8,
        EGL_GREEN_SIZE, 8,
        EGL_BLUE_SIZE, 8,
        EGL_NONE
     };

   td->egl_display =
     eglGetDisplay((EGLNativeDisplayType)ecore_wl2_display_get(td->display));

   if (!eglInitialize(td->egl_display, NULL, NULL))
     {
        ERR("Failed to initialize egl");
        eglTerminate(td->egl_display);
        return EINA_FALSE;
     }

   if (!eglChooseConfig(td->egl_display, attributes, &td->egl_conf,
                        1, &num_config))
     {
        ERR("Failed to choose egl config");
        eglTerminate(td->egl_display);
        return EINA_FALSE;
     }

   td->egl_context =
     eglCreateContext(td->egl_display, td->egl_conf, EGL_NO_CONTEXT, NULL);

   td->egl_window = wl_egl_window_create(td->surface, td->width, td->height);

   td->egl_surface =
     eglCreateWindowSurface(td->egl_display,
                            td->egl_conf, td->egl_window, NULL);

   eglMakeCurrent(td->egl_display, td->egl_surface,
                  td->egl_surface, td->egl_context);

   return EINA_TRUE;
}

static void
_term_egl(Test_Data *td)
{
   eglDestroySurface(td->egl_display, td->egl_surface);
   wl_egl_window_destroy(td->egl_window);
   eglDestroyContext(td->egl_display, td->egl_context);
   eglTerminate(td->egl_display);
}

#endif