1 // SPDX-FileCopyrightText: Copyright 2012 Intel Corporation
2 // SPDX-License-Identifier: BSD-2-Clause
6 #include "wcore_error.h"
7 #include "wcore_platform.h"
9 #include "wegl_display.h"
10 #include "wegl_imports.h"
11 #include "wegl_util.h"
12 #include "wegl_platform.h"
15 get_apis(struct wegl_display
*dpy
)
17 struct wegl_platform
*plat
= wegl_platform(dpy
->wcore
.platform
);
18 const char *apis
= plat
->eglQueryString(dpy
->egl
, EGL_CLIENT_APIS
);
20 // Our minimum requirement - EGL 1.2 ...
21 if (dpy
->major_version
!= 1 || dpy
->minor_version
< 2) {
22 wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM
,
23 "EGL 1.2 or later is required");
27 // ... plus working eglQueryString(EGL_CLIENT_APIS).
29 wegl_emit_error(plat
, "eglQueryString(EGL_CLIENT_APIS)");
33 // waffle_is_extension_in_string() resets the error state. That's ok,
34 // however, because if we've reached this point then no error should be
36 assert(wcore_error_get_code() == 0);
38 if (waffle_is_extension_in_string(apis
, "OpenGL_ES"))
39 dpy
->api_mask
|= WEGL_OPENGL_ES_API
;
41 // Check for "OpenGL" if we're running EGL 1.4 or later.
42 if (dpy
->major_version
== 1 && dpy
->minor_version
>= 4)
43 if (waffle_is_extension_in_string(apis
, "OpenGL"))
44 dpy
->api_mask
|= WEGL_OPENGL_API
;
50 get_extensions(struct wegl_display
*dpy
)
52 struct wegl_platform
*plat
= wegl_platform(dpy
->wcore
.platform
);
53 const char *extensions
= plat
->eglQueryString(dpy
->egl
, EGL_EXTENSIONS
);
56 wegl_emit_error(plat
, "eglQueryString(EGL_EXTENSIONS)");
60 // waffle_is_extension_in_string() resets the error state. That's ok,
61 // however, because if we've reached this point then no error should be
63 assert(wcore_error_get_code() == 0);
65 #define CHECK_EXTENSION(ext) \
66 dpy->ext = waffle_is_extension_in_string(extensions, "EGL_" #ext)
68 CHECK_EXTENSION(EXT_create_context_robustness
);
69 CHECK_EXTENSION(KHR_create_context
);
70 CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers
);
71 CHECK_EXTENSION(EXT_create_context_robustness
);
72 #undef CHECK_EXTENSION
77 /// On Linux, according to eglplatform.h, EGLNativeDisplayType and intptr_t
78 /// have the same size regardless of platform.
80 wegl_display_init(struct wegl_display
*dpy
,
81 struct wcore_platform
*wc_plat
,
84 struct wegl_platform
*plat
= wegl_platform(wc_plat
);
86 wcore_display_init(&dpy
->wcore
, wc_plat
);
88 if (wegl_platform_can_use_eglGetPlatformDisplay(plat
)) {
89 dpy
->egl
= plat
->eglGetPlatformDisplay(plat
->egl_platform
,
90 native_display
, NULL
);
92 wegl_emit_error(plat
, "eglGetPlatformDisplay");
95 } else if (wegl_platform_can_use_eglGetPlatformDisplayEXT(plat
)) {
96 dpy
->egl
= plat
->eglGetPlatformDisplayEXT(plat
->egl_platform
,
97 native_display
, NULL
);
99 wegl_emit_error(plat
, "eglGetPlatformDisplayEXT");
103 dpy
->egl
= plat
->eglGetDisplay((EGLNativeDisplayType
) native_display
);
105 wegl_emit_error(plat
, "eglGetDisplay");
111 plat
->eglInitialize(dpy
->egl
, &dpy
->major_version
, &dpy
->minor_version
);
113 wegl_emit_error(plat
, "eglInitialize");
121 ok
= get_extensions(dpy
);
128 wegl_display_teardown(dpy
);
133 wegl_display_teardown(struct wegl_display
*dpy
)
135 struct wegl_platform
*plat
= wegl_platform(dpy
->wcore
.platform
);
139 ok
= plat
->eglTerminate(dpy
->egl
);
141 wegl_emit_error(plat
, "eglTerminate");
148 wegl_display_supports_context_api(struct wcore_display
*wc_dpy
,
149 int32_t waffle_context_api
)
151 struct wegl_display
*dpy
= wegl_display(wc_dpy
);
153 switch (waffle_context_api
) {
154 case WAFFLE_CONTEXT_OPENGL
:
155 return !!(dpy
->api_mask
& WEGL_OPENGL_API
);
156 case WAFFLE_CONTEXT_OPENGL_ES1
:
157 case WAFFLE_CONTEXT_OPENGL_ES2
:
158 return !!(dpy
->api_mask
& WEGL_OPENGL_ES_API
);
159 case WAFFLE_CONTEXT_OPENGL_ES3
:
160 return !!(dpy
->api_mask
& WEGL_OPENGL_ES_API
) &&
161 dpy
->KHR_create_context
;