Refactor windowing from egl to window_x11/window_wayland, yolo

This commit is contained in:
dec05eba
2024-12-08 02:17:41 +01:00
parent 655fd3756b
commit c259a19b9d
18 changed files with 801 additions and 534 deletions

View File

@@ -17,6 +17,7 @@ typedef enum {
typedef struct {
gsr_egl *egl;
Display *display;
bool track_cursor;
gsr_damage_track_type track_type;

View File

@@ -10,6 +10,8 @@
#include "vec2.h"
#include "defs.h"
typedef struct gsr_window gsr_window;
#ifdef _WIN64
typedef signed long long int khronos_intptr_t;
typedef unsigned long long int khronos_uintptr_t;
@@ -152,54 +154,11 @@ typedef int (*FUNC_eglQueryDisplayAttribEXT)(EGLDisplay dpy, int32_t attribute,
typedef const char* (*FUNC_eglQueryDeviceStringEXT)(void *device, int32_t name);
typedef int (*FUNC_eglQueryDmaBufModifiersEXT)(EGLDisplay dpy, int32_t format, int32_t max_modifiers, uint64_t *modifiers, int *external_only, int32_t *num_modifiers);
#define GSR_MAX_OUTPUTS 32
typedef struct {
char *name;
vec2i pos;
vec2i size;
uint32_t connector_id;
gsr_monitor_rotation rotation;
uint32_t monitor_identifier; /* crtc id */
} gsr_x11_output;
typedef struct {
Display *dpy;
Window window;
gsr_x11_output outputs[GSR_MAX_OUTPUTS];
int num_outputs;
XEvent xev;
} gsr_x11;
typedef struct {
uint32_t wl_name;
void *output;
vec2i pos;
vec2i size;
int32_t transform;
char *name;
} gsr_wayland_output;
typedef struct {
void *dpy;
void *window;
void *registry;
void *surface;
void *compositor;
gsr_wayland_output outputs[GSR_MAX_OUTPUTS];
int num_outputs;
} gsr_wayland;
typedef enum {
GSR_GL_CONTEXT_TYPE_EGL,
GSR_GL_CONTEXT_TYPE_GLX
} gsr_gl_context_type;
typedef enum {
GSR_DISPLAY_SERVER_X11,
GSR_DISPLAY_SERVER_WAYLAND
} gsr_display_server;
typedef struct gsr_egl gsr_egl;
struct gsr_egl {
void *egl_library;
@@ -207,6 +166,7 @@ struct gsr_egl {
void *gl_library;
gsr_gl_context_type context_type;
gsr_window *window;
EGLDisplay egl_display;
EGLSurface egl_surface;
@@ -218,8 +178,6 @@ struct gsr_egl {
gsr_gpu_info gpu_info;
gsr_x11 x11;
gsr_wayland wayland;
char card_path[128];
int32_t (*eglGetError)(void);
@@ -319,15 +277,10 @@ struct gsr_egl {
unsigned char (*glUnmapBuffer)(unsigned int target);
};
bool gsr_egl_load(gsr_egl *self, Display *dpy, bool wayland, bool is_monitor_capture);
bool gsr_egl_load(gsr_egl *self, gsr_window *window, bool is_monitor_capture);
void gsr_egl_unload(gsr_egl *self);
/* Returns true if an event is available */
bool gsr_egl_process_event(gsr_egl *self);
/* Does opengl swap with egl or glx, depending on which one is active */
void gsr_egl_swap_buffers(gsr_egl *self);
gsr_display_server gsr_egl_get_display_server(const gsr_egl *self);
XEvent* gsr_egl_get_event_data(gsr_egl *self);
#endif /* GSR_EGL_H */

View File

@@ -7,6 +7,8 @@
#include <stdbool.h>
#include <stdint.h>
#define CONNECTOR_TYPE_COUNTS 32
typedef struct AVCodecContext AVCodecContext;
typedef struct AVFrame AVFrame;
@@ -27,17 +29,26 @@ typedef struct {
bool found_monitor;
} get_monitor_by_name_userdata;
typedef struct {
int type;
int count;
int count_active;
} drm_connector_type_count;
double clock_get_monotonic_seconds(void);
bool generate_random_characters(char *buffer, int buffer_size, const char *alphabet, size_t alphabet_size);
bool generate_random_characters_standard_alphabet(char *buffer, int buffer_size);
typedef void (*active_monitor_callback)(const gsr_monitor *monitor, void *userdata);
void for_each_active_monitor_output_x11_not_cached(Display *display, active_monitor_callback callback, void *userdata);
void for_each_active_monitor_output_x11(const gsr_egl *egl, active_monitor_callback callback, void *userdata);
void for_each_active_monitor_output(const gsr_egl *egl, gsr_connection_type connection_type, active_monitor_callback callback, void *userdata);
bool get_monitor_by_name(const gsr_egl *egl, gsr_connection_type connection_type, const char *name, gsr_monitor *monitor);
gsr_monitor_rotation drm_monitor_get_display_server_rotation(const gsr_egl *egl, const gsr_monitor *monitor);
int get_connector_type_by_name(const char *name);
drm_connector_type_count* drm_connector_types_get_index(drm_connector_type_count *type_counts, int *num_type_counts, int connector_type);
uint32_t monitor_identifier_from_type_and_count(int monitor_type_index, int monitor_type_count);
bool gl_get_gpu_info(gsr_egl *egl, gsr_gpu_info *info);
bool gl_driver_version_greater_than(const gsr_egl *egl, int major, int minor, int patch);

37
include/window/window.h Normal file
View File

@@ -0,0 +1,37 @@
#ifndef GSR_WINDOW_H
#define GSR_WINDOW_H
#include "../utils.h"
#include <stdbool.h>
typedef union _XEvent XEvent;
typedef struct gsr_window gsr_window;
typedef enum {
GSR_DISPLAY_SERVER_X11,
GSR_DISPLAY_SERVER_WAYLAND
} gsr_display_server;
struct gsr_window {
void (*destroy)(gsr_window *self);
/* Returns true if an event is available */
bool (*process_event)(gsr_window *self);
XEvent* (*get_event_data)(gsr_window *self); /* can be NULL */
gsr_display_server (*get_display_server)(void);
void* (*get_display)(gsr_window *self);
void* (*get_window)(gsr_window *self);
void (*for_each_active_monitor_output_cached)(const gsr_window *self, active_monitor_callback callback, void *userdata);
void *priv;
};
void gsr_window_destroy(gsr_window *self);
/* Returns true if an event is available */
bool gsr_window_process_event(gsr_window *self);
XEvent* gsr_window_get_event_data(gsr_window *self);
gsr_display_server gsr_window_get_display_server(const gsr_window *self);
void* gsr_window_get_display(gsr_window *self);
void* gsr_window_get_window(gsr_window *self);
void gsr_window_for_each_active_monitor_output_cached(const gsr_window *self, active_monitor_callback callback, void *userdata);
#endif /* GSR_WINDOW_H */

View File

@@ -0,0 +1,8 @@
#ifndef GSR_WINDOW_WAYLAND_H
#define GSR_WINDOW_WAYLAND_H
#include "window.h"
gsr_window* gsr_window_wayland_create(void);
#endif /* GSR_WINDOW_WAYLAND_H */

View File

@@ -0,0 +1,10 @@
#ifndef GSR_WINDOW_X11_H
#define GSR_WINDOW_X11_H
#include "window.h"
typedef struct _XDisplay Display;
gsr_window* gsr_window_x11_create(Display *display);
#endif /* GSR_WINDOW_X11_H */