Files
kaizen/external/SDL/test/testnativewayland.c
T
iris 00cc9309cb Squashed 'external/ircolib/' changes from ce3cd726c..de6e324bd
de6e324bd separate emu thread
10d3daf86 Roms List improvements
95d202f37 Let's make the rom list process on a separate thread so the emulator doesnt take ages to load.
fc306967f Wow the ROM Header was just completely busted. Game list view works now
bad1691ee fuck this shit
2b59e5f46 game list in progress
d26417b83 remappable inputs in progress
ac4af8106 input
e72abc240 update readme
430139dc9 Qt6 frontend
3080d4d45 Fix this small bug too
08cd13b85 Cop0 unused functions do not actually pose a threat (as per manual). They don't do anything, so shall we.
61bb4fb44 make idle loop detection a little more specific with where the load goes
b037de4c3 SAZDFsdff
12e81e73e need to figure out why n64-systemtest loops indefinitely at some address that appears to be valid (i think it's me not invalidating the cache properly)
204f0e13b idle skipping seems to work!
cb8bb634a sdkfjlasdf
58e5c89c1 Fix compilation issue on my machine (no idea)
24fb2898e attempting more serious idle skipping
214719577 Place rsp.Step inside cached interpreter. Gains about 3 more fps
bb97dcc23 mmmmm
920b77d38 wjkhasdfjhkasdf
430ccdab4 it's a start...
4f42a673a Cached interpreter plays Mario 64. Start looking into RSP as well
c9a030787 idle skipping works!
5fbda03ce new idea
366637aba Idle skipping... maybe?
609fa2fb0 Cache instructions implemented but broken lmao. Commented out for now
e140a6d12 - Stop using inheritance for CPU, instead use composition. - Introduce KAIZEN_JIT_ENABLED optional define instead of relying on __aarch64__ and the like. - More cache work
68e613057 prep cache impl
811b4d809 fix clang format
fda755f7d idk
d5024ebbf small MI refactor in preparation of (eventually) implementing the RDRAM interface properly
694b45341 Merge commit '206dcdedf195fb320913584180edb12c7731e396' as 'external/SDL'
206dcdedf Squashed 'external/SDL/' content from commit 4d17b99d0a
4d16e1cb4 need to update sdl
848b19920 Fix compilation error
db61b5299 Merge commit 'e94a94559f28e49678fbcf72199a5258137b0fe9' as 'external/imgui'
e94a94559 Squashed 'external/imgui/' content from commit 02e9b8cac
52edb3757 need to update imgui
c1a705e86 Emulate weird JALR behaviour
4b4c32f4b Fix exception for "unusable COP1" in 4 instructions i missed accidentally (again)
df5828142 Bug putting 0s in the log everywhere
f8b580048 Make isviewer a sink to file
8241e9735 Fix exception for "unusable COP1" in 4 instructions i missed accidentally
b29715f20 small changes
d9a620bc1 make use of my new small utility library
0d1aa938e Add 'external/ircolib/' from commit 'ce3cd726c8df8388d554abf8bb55d55020eb4450'
e64eb40b3 Fuck git

git-subtree-dir: external/ircolib
git-subtree-split: de6e324bde
2026-06-15 11:56:38 +02:00

227 lines
7.3 KiB
C

/*
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
#include "testnative.h"
#ifdef TEST_NATIVE_WAYLAND
#include <SDL3/SDL.h>
#include <wayland-client.h>
#include <xdg-shell-client-protocol.h>
static void *native_userdata_ptr = (void *)0xBAADF00D;
static const char *native_surface_tag = "SDL_NativeSurfaceTag";
static void *CreateWindowWayland(int w, int h);
static void DestroyWindowWayland(void *window);
NativeWindowFactory WaylandWindowFactory = {
"wayland",
CreateWindowWayland,
DestroyWindowWayland
};
/* Encapsulated in a struct to silence shadow variable warnings */
static struct _state
{
struct wl_display *wl_display;
struct wl_registry *wl_registry;
struct wl_compositor *wl_compositor;
struct xdg_wm_base *xdg_wm_base;
struct wl_surface *wl_surface;
struct xdg_surface *xdg_surface;
struct xdg_toplevel *xdg_toplevel;
} state;
static void xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial)
{
xdg_surface_ack_configure(state.xdg_surface, serial);
}
static const struct xdg_surface_listener xdg_surface_listener = {
.configure = xdg_surface_configure,
};
static void xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height, struct wl_array *states)
{
/* NOP */
}
static void xdg_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel)
{
SDL_Event event;
SDL_zero(event);
event.type = SDL_EVENT_QUIT;
SDL_PushEvent(&event);
}
static void xdg_toplevel_configure_bounds(void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height)
{
/* NOP */
}
static void xdg_toplevel_wm_capabilities(void *data, struct xdg_toplevel *xdg_toplevel, struct wl_array *capabilities)
{
/* NOP */
}
static const struct xdg_toplevel_listener xdg_toplevel_listener = {
.configure = xdg_toplevel_configure,
.close = xdg_toplevel_close,
.configure_bounds = xdg_toplevel_configure_bounds,
.wm_capabilities = xdg_toplevel_wm_capabilities
};
static void xdg_wm_base_ping(void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial)
{
xdg_wm_base_pong(state.xdg_wm_base, serial);
}
static const struct xdg_wm_base_listener xdg_wm_base_listener = {
.ping = xdg_wm_base_ping,
};
static void registry_global(void *data, struct wl_registry *wl_registry, uint32_t name, const char *interface, uint32_t version)
{
if (SDL_strcmp(interface, wl_compositor_interface.name) == 0) {
state.wl_compositor = wl_registry_bind(state.wl_registry, name, &wl_compositor_interface, SDL_min(version, 4));
} else if (SDL_strcmp(interface, xdg_wm_base_interface.name) == 0) {
state.xdg_wm_base = wl_registry_bind(state.wl_registry, name, &xdg_wm_base_interface, 1);
xdg_wm_base_add_listener(state.xdg_wm_base, &xdg_wm_base_listener, NULL);
}
}
static void registry_global_remove(void *data, struct wl_registry *wl_registry, uint32_t name)
{
/* NOP */
}
static const struct wl_registry_listener wl_registry_listener = {
.global = registry_global,
.global_remove = registry_global_remove,
};
static void *CreateWindowWayland(int w, int h)
{
/* Export the display object from SDL and use it to create a registry object,
* which will enumerate the wl_compositor and xdg_wm_base protocols.
*/
state.wl_display = SDL_GetPointerProperty(SDL_GetGlobalProperties(), SDL_PROP_GLOBAL_VIDEO_WAYLAND_WL_DISPLAY_POINTER, NULL);
if (!state.wl_display) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid 'wl_display' object!");
goto error;
}
state.wl_registry = wl_display_get_registry(state.wl_display);
wl_registry_add_listener(state.wl_registry, &wl_registry_listener, NULL);
/* Roundtrip to enumerate registry objects. */
wl_display_roundtrip(state.wl_display);
/* Protocol sanity check */
if (!state.wl_compositor) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "'wl_compositor' protocol not found!");
goto error;
}
if (!state.xdg_wm_base) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "'xdg_wm_base' protocol not found!");
goto error;
}
/* Crate the backing wl_surface for the window. */
state.wl_surface = wl_compositor_create_surface(state.wl_compositor);
/* Set the native tag and userdata values, which should be the same at exit. */
wl_proxy_set_tag((struct wl_proxy *)state.wl_surface, &native_surface_tag);
wl_surface_set_user_data(state.wl_surface, native_userdata_ptr);
/* Create the xdg_surface from the wl_surface. */
state.xdg_surface = xdg_wm_base_get_xdg_surface(state.xdg_wm_base, state.wl_surface);
xdg_surface_add_listener(state.xdg_surface, &xdg_surface_listener, NULL);
/* Create the xdg_toplevel from the xdg_surface. */
state.xdg_toplevel = xdg_surface_get_toplevel(state.xdg_surface);
xdg_toplevel_add_listener(state.xdg_toplevel, &xdg_toplevel_listener, NULL);
xdg_toplevel_set_title(state.xdg_toplevel, "Native Wayland Window");
/* Return the wl_surface to be wrapped in an SDL_Window. */
return state.wl_surface;
error:
if (state.xdg_toplevel) {
xdg_toplevel_destroy(state.xdg_toplevel);
state.xdg_toplevel = NULL;
}
if (state.xdg_surface) {
xdg_surface_destroy(state.xdg_surface);
state.xdg_surface = NULL;
}
if (state.wl_surface) {
wl_surface_destroy(state.wl_surface);
state.wl_surface = NULL;
}
if (state.xdg_wm_base) {
xdg_wm_base_destroy(state.xdg_wm_base);
state.xdg_wm_base = NULL;
}
if (state.wl_compositor) {
wl_compositor_destroy(state.wl_compositor);
state.wl_compositor = NULL;
}
if (state.wl_registry) {
wl_registry_destroy(state.wl_registry);
state.wl_registry = NULL;
}
return NULL;
}
static void DestroyWindowWayland(void *window)
{
if (state.xdg_toplevel) {
xdg_toplevel_destroy(state.xdg_toplevel);
state.xdg_toplevel = NULL;
}
if (state.xdg_surface) {
xdg_surface_destroy(state.xdg_surface);
state.xdg_surface = NULL;
}
if (state.wl_surface) {
/* Surface sanity check; these should be unmodified. */
if (wl_proxy_get_tag((struct wl_proxy *)state.wl_surface) != &native_surface_tag) {
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "The wl_surface tag was modified, this indicates a problem inside of SDL.");
}
if (wl_surface_get_user_data(state.wl_surface) != native_userdata_ptr) {
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "The wl_surface user data was modified, this indicates a problem inside of SDL.");
}
wl_surface_destroy(state.wl_surface);
state.wl_surface = NULL;
}
if (state.xdg_wm_base) {
xdg_wm_base_destroy(state.xdg_wm_base);
state.xdg_wm_base = NULL;
}
if (state.wl_compositor) {
wl_compositor_destroy(state.wl_compositor);
state.wl_compositor = NULL;
}
if (state.wl_registry) {
wl_registry_destroy(state.wl_registry);
state.wl_registry = NULL;
}
}
#endif