1 // SPDX-FileCopyrightText: Copyright 2014 Emil Velikov
2 // SPDX-License-Identifier: BSD-2-Clause
8 #include "wcore_platform.h"
9 #include "wcore_util.h"
11 #include "wegl_imports.h"
13 struct wegl_platform
{
14 struct wcore_platform wcore
;
16 // An EGL_PLATFORM_* enum, such as EGL_PLATFORM_GBM_KHR.
19 /// @brief Value of EGLConfig attribute EGL_SURFACE_TYPE
21 /// When calling eglChooseConfig, Waffle sets the EGL_SURFACE_TYPE attribute
22 /// to this value. Since most Waffle EGL platforms call
23 /// eglCreatePlatformWindowSurface() from waffle_window_create(),
24 /// wegl_platform_init() initializes this to EGL_WINDOW_BIT.
26 /// This field exists because not all EGL platforms support EGL_WINDOW_BIT;
27 /// namely, Mesa's "surfaceless" platform.
28 EGLint egl_surface_type_mask
;
30 // EGL function pointers
33 // See https://www.khronos.org/registry/egl/extensions/EXT/EGL_EXT_client_extensions.txt
34 const char *client_extensions
;
36 EGLBoolean (*eglMakeCurrent
)(EGLDisplay dpy
, EGLSurface draw
,
37 EGLSurface read
, EGLContext ctx
);
38 __eglMustCastToProperFunctionPointerType
39 (*eglGetProcAddress
)(const char *procname
);
42 EGLDisplay (*eglGetPlatformDisplay
)(EGLenum platform
, void *native_display
,
43 const EGLAttrib
*attrib_list
);
46 EGLDisplay (*eglGetDisplay
)(EGLNativeDisplayType display_id
);
47 EGLBoolean (*eglInitialize
)(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
);
48 const char * (*eglQueryString
)(EGLDisplay dpy
, EGLint name
);
49 EGLint (*eglGetError
)(void);
50 EGLBoolean (*eglTerminate
)(EGLDisplay dpy
);
53 EGLBoolean (*eglChooseConfig
)(EGLDisplay dpy
, const EGLint
*attrib_list
,
54 EGLConfig
*configs
, EGLint config_size
,
58 EGLBoolean (*eglBindAPI
)(EGLenum api
);
59 EGLContext (*eglCreateContext
)(EGLDisplay dpy
, EGLConfig config
,
60 EGLContext share_context
,
61 const EGLint
*attrib_list
);
62 EGLBoolean (*eglDestroyContext
)(EGLDisplay dpy
, EGLContext ctx
);
65 EGLBoolean (*eglGetConfigAttrib
)(EGLDisplay dpy
, EGLConfig config
,
66 EGLint attribute
, EGLint
*value
);
67 EGLSurface (*eglCreateWindowSurface
)(EGLDisplay dpy
, EGLConfig config
,
68 EGLNativeWindowType win
,
69 const EGLint
*attrib_list
);
70 EGLSurface (*eglCreatePbufferSurface
)(EGLDisplay dpy
, EGLConfig config
,
71 const EGLint
*attrib_list
);
72 EGLBoolean (*eglDestroySurface
)(EGLDisplay dpy
, EGLSurface surface
);
73 EGLBoolean (*eglSwapBuffers
)(EGLDisplay dpy
, EGLSurface surface
);
75 // EGL_EXT_platform_display
76 EGLDisplay (*eglGetPlatformDisplayEXT
)(EGLenum platform
, void *native_display
,
77 const EGLint
*attrib_list
);
79 // EGL_EXT_image_dma_buf_import_modifiers
80 EGLBoolean (*eglQueryDmaBufFormatsEXT
)(EGLDisplay dpy
,
84 EGLBoolean (*eglQueryDmaBufModifiersEXT
)(EGLDisplay dpy
, EGLint format
,
86 EGLuint64KHR
*modifiers
,
87 EGLBoolean
*external_only
,
88 EGLint
*num_modifiers
);
91 DEFINE_CONTAINER_CAST_FUNC(wegl_platform
,
93 struct wcore_platform
,
97 wegl_platform_teardown(struct wegl_platform
*self
);
100 wegl_platform_init(struct wegl_platform
*self
, EGLenum egl_platform
);
103 // Can eglGetPlatformDisplay can be used for this platform?
105 // True if libEGL exposes the eglGetPlatformDisplay function; and if EGL
106 // supports the needed platform extension.
108 wegl_platform_can_use_eglGetPlatformDisplay(const struct wegl_platform
*plat
);
110 // Can eglGetPlatformDisplayEXT can be used for this platform?
112 // True if libEGL exposes the eglGetPlatformDisplayEXT function; and if EGL
113 // supports the needed platform extension.
115 wegl_platform_can_use_eglGetPlatformDisplayEXT(const struct wegl_platform
*plat
);