This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsdl2.patch
554 lines (544 loc) · 17.4 KB
/
sdl2.patch
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8f9ab39..27ece01 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,6 +2,10 @@ if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
message(FATAL_ERROR "Prevented in-tree build. Please create a build directory outside of the SDL source code and run \"cmake -S ${CMAKE_SOURCE_DIR} -B .\" from there")
endif()
+# duckOS stuff
+set(UNIX 1)
+set(VIDEO_WAYLAND OFF)
+
# MSVC runtime library flags are selected by an abstraction.
set(CMAKE_POLICY_DEFAULT_CMP0091 NEW)
@@ -426,11 +430,11 @@ dep_option(SDL_DIRECTFB_SHARED "Dynamically load directfb support" ON "SDL_D
set_option(SDL_DUMMYVIDEO "Use dummy video driver" ON)
dep_option(SDL_IBUS "Enable IBus support" ON ${UNIX_SYS} OFF)
set_option(SDL_SYSTEM_ICONV "Use iconv() from system-installed libraries" ${SDL_SYSTEM_ICONV_DEFAULT})
-set_option(SDL_LIBICONV "Prefer iconv() from libiconv, if available, over libc version" OFF)
+set_option(SDL_LIBICONV "Prefer iconv() from libiconv, if available, over libc version" ON)
set_option(SDL_OPENGL "Include OpenGL support" ON)
set_option(SDL_OPENGLES "Include OpenGL ES support" ON)
set_option(SDL_PTHREADS "Use POSIX threads for multi-threading" ${SDL_PTHREADS_ENABLED_BY_DEFAULT})
-dep_option(SDL_PTHREADS_SEM "Use pthread semaphores" ON "SDL_PTHREADS" OFF)
+dep_option(SDL_PTHREADS_SEM "Use pthread semaphores" OFF "SDL_PTHREADS" OFF)
dep_option(SDL_OSS "Support the OSS audio API" ON "UNIX_SYS OR RISCOS" OFF)
set_option(SDL_ALSA "Support the ALSA audio API" ${UNIX_SYS})
dep_option(SDL_ALSA_SHARED "Dynamically load ALSA audio support" ON "SDL_ALSA" OFF)
@@ -1469,61 +1473,19 @@ elseif(EMSCRIPTEN)
CheckLibUnwind()
elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
- if(SDL_AUDIO)
- if(SYSV5 OR SOLARIS OR HPUX)
- set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
- file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
- list(APPEND SOURCE_FILES ${SUN_AUDIO_SOURCES})
- set(HAVE_SDL_AUDIO TRUE)
- elseif(NETBSD)
- set(SDL_AUDIO_DRIVER_NETBSD 1)
- file(GLOB NETBSD_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/netbsd/*.c)
- list(APPEND SOURCE_FILES ${NETBSD_AUDIO_SOURCES})
- set(HAVE_SDL_AUDIO TRUE)
- elseif(AIX)
- set(SDL_AUDIO_DRIVER_PAUDIO 1)
- file(GLOB AIX_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/paudio/*.c)
- list(APPEND SOURCE_FILES ${AIX_AUDIO_SOURCES})
- set(HAVE_SDL_AUDIO TRUE)
- elseif(QNX)
- set(SDL_AUDIO_DRIVER_QSA 1)
- file(GLOB QSA_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/qsa/*.c)
- list(APPEND SOURCE_FILES ${QSA_AUDIO_SOURCES})
- list(APPEND EXTRA_LIBS asound)
- set(HAVE_SDL_AUDIO TRUE)
- endif()
- CheckOSS()
- CheckALSA()
- CheckJACK()
- CheckPipewire()
- CheckPulseAudio()
- CheckESD()
- CheckARTS()
- CheckNAS()
- CheckSNDIO()
- CheckFusionSound()
- endif()
-
- if(SDL_VIDEO)
- # Need to check for Raspberry PI first and add platform specific compiler flags, otherwise the test for GLES fails!
- CheckRPI()
- CheckX11()
- CheckDirectFB()
- # Need to check for EGL first because KMSDRM and Wayland depends on it.
- CheckEGL()
- CheckKMSDRM()
- CheckGLX()
- CheckOpenGL()
- CheckOpenGLES()
- CheckWayland()
- CheckVivante()
- # FIXME: implement CheckVulkan()
- if(SDL_VULKAN)
- set(SDL_VIDEO_VULKAN 1)
- set(HAVE_VULKAN TRUE)
- endif()
- CheckQNXScreen()
- endif()
+ # duckOS overrides
+ message_warn("Using duckOS overrides!")
+ set(HAVE_VIDEO_DUCKOS TRUE)
+ set(HAVE_AUDIO_DUCKOS TRUE)
+ set(HAVE_SDL_VIDEO TRUE)
+ set(HAVE_SDL_AUDIO TRUE)
+ file(GLOB DUCKOS_SOURCES ${SDL2_SOURCE_DIR}/src/video/duckos/*.cpp ${SDL2_SOURCE_DIR}/src/audio/duckos/*.cpp)
+ set(SOURCE_FILES ${SOURCE_FILES} ${DUCKOS_SOURCES})
+ set(SDL_VIDEO_DRIVER_DUCKOS 1)
+ set(SDL_AUDIO_DRIVER_DUCKOS 1)
+ set(HAVE_VIDEO_OPENGL FALSE)
+ set(SDL_VIDEO_OPENGL 0)
+ list(APPEND EXTRA_LIBS duck sound ui graphics iconv pond)
if(UNIX)
file(GLOB CORE_UNIX_SOURCES ${SDL2_SOURCE_DIR}/src/core/unix/*.c)
diff --git a/build-scripts/config.sub b/build-scripts/config.sub
index 2c6a07a..62da7f1 100755
--- a/build-scripts/config.sub
+++ b/build-scripts/config.sub
@@ -1483,6 +1483,9 @@ case $os in
dicos*)
os=dicos
;;
+ duckos*)
+ os=duckos
+ ;;
pikeos*)
# Until real need of OS specific support for
# particular features comes up, bare metal
diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake
index ffcafd8..7a1818c 100644
--- a/include/SDL_config.h.cmake
+++ b/include/SDL_config.h.cmake
@@ -329,6 +329,7 @@
#cmakedefine SDL_AUDIO_DRIVER_PSP @SDL_AUDIO_DRIVER_PSP@
#cmakedefine SDL_AUDIO_DRIVER_PS2 @SDL_AUDIO_DRIVER_PS2@
#cmakedefine SDL_AUDIO_DRIVER_N3DS @SDL_AUDIO_DRIVER_N3DS@
+#cmakedefine SDL_AUDIO_DRIVER_DUCKOS @SDL_AUDIO_DRIVER_DUCKOS@
/* Enable various input drivers */
#cmakedefine SDL_INPUT_LINUXEV @SDL_INPUT_LINUXEV@
@@ -455,6 +456,7 @@
#cmakedefine SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM @SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM@
#cmakedefine SDL_VIDEO_DRIVER_VITA @SDL_VIDEO_DRIVER_VITA@
#cmakedefine SDL_VIDEO_DRIVER_N3DS @SDL_VIDEO_DRIVER_N3DS@
+#cmakedefine SDL_VIDEO_DRIVER_DUCKOS @SDL_VIDEO_DRIVER_DUCKOS@
#cmakedefine SDL_VIDEO_RENDER_D3D @SDL_VIDEO_RENDER_D3D@
#cmakedefine SDL_VIDEO_RENDER_D3D11 @SDL_VIDEO_RENDER_D3D11@
diff --git a/include/SDL_syswm.h b/include/SDL_syswm.h
index 7b8bd6e..015b61a 100644
--- a/include/SDL_syswm.h
+++ b/include/SDL_syswm.h
@@ -148,7 +148,8 @@ typedef enum
SDL_SYSWM_OS2,
SDL_SYSWM_HAIKU,
SDL_SYSWM_KMSDRM,
- SDL_SYSWM_RISCOS
+ SDL_SYSWM_RISCOS,
+ SDL_SYSWM_DUCKOS
} SDL_SYSWM_TYPE;
/**
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 96586fe..adc13f6 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -134,6 +134,9 @@ static const AudioBootStrap *const bootstrap[] = {
#endif
#ifdef SDL_AUDIO_DRIVER_DUMMY
&DUMMYAUDIO_bootstrap,
+#endif
+#ifdef SDL_AUDIO_DRIVER_DUCKOS
+ &DUCKOSAUDIO_bootstrap,
#endif
NULL
};
diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h
index d569ba7..6d8d93f 100644
--- a/src/audio/SDL_sysaudio.h
+++ b/src/audio/SDL_sysaudio.h
@@ -209,6 +209,7 @@ extern AudioBootStrap VITAAUD_bootstrap;
extern AudioBootStrap N3DSAUDIO_bootstrap;
extern AudioBootStrap EMSCRIPTENAUDIO_bootstrap;
extern AudioBootStrap OS2AUDIO_bootstrap;
+extern AudioBootStrap DUCKOSAUDIO_bootstrap;
#endif /* SDL_sysaudio_h_ */
diff --git a/src/audio/duckos/SDL_duckosaudio.cpp b/src/audio/duckos/SDL_duckosaudio.cpp
new file mode 100644
index 0000000..27be7c2
--- /dev/null
+++ b/src/audio/duckos/SDL_duckosaudio.cpp
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/* Copyright © 2016-2024 Byteduck */
+
+
+extern "C" {
+#include "../../SDL_internal.h"
+
+#ifdef SDL_AUDIO_DRIVER_DUCKOS
+
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "../SDL_sysaudio.h"
+
+ static SDL_bool DUCKOSAUDIO_Init(SDL_AudioDriverImpl *impl) {
+ return SDL_FALSE;
+ }
+
+ AudioBootStrap DUCKOSAUDIO_bootstrap = {
+ "duckOS", "duckOS libsound driver", DUCKOSAUDIO_Init, SDL_FALSE
+ };
+
+#endif
+}
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 344efec..ea9ceca 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -484,6 +484,7 @@ extern VideoBootStrap OFFSCREEN_bootstrap;
extern VideoBootStrap NGAGE_bootstrap;
extern VideoBootStrap OS2DIVE_bootstrap;
extern VideoBootStrap OS2VMAN_bootstrap;
+extern VideoBootStrap DUCKOSVIDEO_bootstrap;
/* Use SDL_OnVideoThread() sparingly, to avoid regressions in use cases that currently happen to work */
extern SDL_bool SDL_OnVideoThread(void);
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index ee723a5..412c7f4 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -136,6 +136,9 @@ static VideoBootStrap *bootstrap[] = {
#ifdef SDL_VIDEO_DRIVER_NGAGE
&NGAGE_bootstrap,
#endif
+#ifdef SDL_VIDEO_DRIVER_DUCKOS
+ &DUCKOSVIDEO_bootstrap,
+#endif
#ifdef SDL_VIDEO_DRIVER_OFFSCREEN
&OFFSCREEN_bootstrap,
#endif
diff --git a/src/video/duckos/SDL_duckos_window.cpp b/src/video/duckos/SDL_duckos_window.cpp
new file mode 100644
index 0000000..5c903ac
--- /dev/null
+++ b/src/video/duckos/SDL_duckos_window.cpp
@@ -0,0 +1,80 @@
+#include "../../SDL_internal.h"
+
+#ifdef SDL_VIDEO_DRIVER_DUCKOS
+
+#include <libui/libui.h>
+#include "SDL_duckos_window.h"
+
+extern "C" {
+#include "SDL_video.h"
+#include "SDL_mouse.h"
+#include "../SDL_sysvideo.h"
+#include "../SDL_pixels_c.h"
+#include "../../events/SDL_events_c.h"
+#include "SDL_hints.h"
+};
+
+SDLLibUIWindow::SDLLibUIWindow(SDL_Window* sdl_window):
+ m_sdl_window(sdl_window), m_libui_window(UI::Window::make())
+{
+ m_widget = SDLLibUIWidget::make(sdl_window);
+ m_libui_window->set_contents(m_widget);
+ m_libui_window->on_close = [&] () {
+ SDL_SendWindowEvent(m_sdl_window, SDL_WINDOWEVENT_CLOSE, 0, 0);
+ };
+ m_libui_window->resize({sdl_window->w, sdl_window->h});
+ m_libui_window->set_resizable(false);
+ // TODO: Focus change?
+ UI::update(0);
+}
+
+SDLLibUIWidget::SDLLibUIWidget(SDL_Window* sdl_window): m_sdl_window(sdl_window) {
+ set_sizing_mode(UI::FILL);
+}
+
+void SDLLibUIWidget::do_repaint(const UI::DrawContext& ctx) {
+ if (m_framebuffer)
+ ctx.framebuffer().copy(*m_framebuffer, ctx.rect(), {0, 0});
+}
+
+bool SDLLibUIWidget::on_mouse_button(Pond::MouseButtonEvent evt) {
+ int changed_buttons = evt.old_buttons ^ evt.new_buttons;
+ if (changed_buttons & POND_MOUSE1)
+ SDL_SendMouseButton(m_sdl_window, 0, (evt.new_buttons & POND_MOUSE1) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_LEFT);
+ if (changed_buttons & POND_MOUSE2)
+ SDL_SendMouseButton(m_sdl_window, 0, (evt.new_buttons & POND_MOUSE2) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_RIGHT);
+ if (changed_buttons & POND_MOUSE3)
+ SDL_SendMouseButton(m_sdl_window, 0, (evt.new_buttons & POND_MOUSE3) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_MIDDLE);
+ return true;
+}
+
+bool SDLLibUIWidget::on_mouse_move(Pond::MouseMoveEvent evt) {
+ SDL_SetMouseFocus(m_sdl_window);
+ SDL_SendMouseMotion(m_sdl_window, 0, 0, evt.new_pos.x, evt.new_pos.y);
+ return true;
+}
+
+void SDLLibUIWidget::on_mouse_leave(Pond::MouseLeaveEvent evt) {
+ SDL_SetMouseFocus(nullptr);
+}
+
+bool SDLLibUIWidget::on_mouse_scroll(Pond::MouseScrollEvent evt) {
+ SDL_SendMouseWheel(m_sdl_window, 0, 0, (float) -evt.scroll, SDL_MOUSEWHEEL_NORMAL);
+ return true;
+}
+
+bool SDLLibUIWidget::on_keyboard(Pond::KeyEvent evt) {
+ // TODO: Gotta map scancodes...
+// if (KBD_ISPRESSED(evt)) {
+// SDL_SendKeyboardKey(SDL_PRESSED, evt.scancode, evt.key);
+// if (evt.character) {
+// char str[2] = {(char) evt.character, 0};
+// SDL_SendKeyboardText(str);
+// }
+// } else {
+// SDL_SendKeyboardKeyAndKeycode(SDL_RELEASED, evt.scancode, evt.key);
+// }
+ return true;
+}
+
+#endif
diff --git a/src/video/duckos/SDL_duckos_window.h b/src/video/duckos/SDL_duckos_window.h
new file mode 100644
index 0000000..027c385
--- /dev/null
+++ b/src/video/duckos/SDL_duckos_window.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <libui/Window.h>
+
+extern "C" {
+#include "../SDL_sysvideo.h"
+}
+
+class SDLLibUIWidget: public UI::Widget {
+public:
+ WIDGET_DEF(SDLLibUIWidget);
+ SDLLibUIWidget(SDL_Window* sdl_window);
+
+ void do_repaint(const UI::DrawContext &ctx) override;
+ bool on_mouse_button(Pond::MouseButtonEvent evt) override;
+ bool on_mouse_move(Pond::MouseMoveEvent evt) override;
+ void on_mouse_leave(Pond::MouseLeaveEvent evt) override;
+ bool on_mouse_scroll(Pond::MouseScrollEvent evt) override;
+ bool on_keyboard(Pond::KeyEvent evt) override;
+
+ Duck::Ptr<Gfx::Framebuffer> m_framebuffer;
+ SDL_Window* m_sdl_window;
+};
+
+class SDLLibUIWindow {
+public:
+ SDLLibUIWindow(SDL_Window* sdl_window);
+
+ SDL_Window* m_sdl_window;
+ Duck::Ptr<UI::Window> m_libui_window;
+ Duck::Ptr<SDLLibUIWidget> m_widget;
+};
\ No newline at end of file
diff --git a/src/video/duckos/SDL_duckosvideo.cpp b/src/video/duckos/SDL_duckosvideo.cpp
new file mode 100644
index 0000000..e7c793a
--- /dev/null
+++ b/src/video/duckos/SDL_duckosvideo.cpp
@@ -0,0 +1,189 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/* Copyright © 2016-2024 Byteduck */
+
+#include "../../SDL_internal.h"
+
+#ifdef SDL_VIDEO_DRIVER_DUCKOS
+
+#include <libui/libui.h>
+#include "SDL_duckos_window.h"
+
+extern "C" {
+#include "SDL_video.h"
+#include "SDL_mouse.h"
+#include "../SDL_sysvideo.h"
+#include "../SDL_pixels_c.h"
+#include "../../events/SDL_events_c.h"
+#include "SDL_hints.h"
+
+static bool __sdl_libui_inited = false;
+
+static SDL_Cursor* DUCKOS_CreateSystemCursor(SDL_SystemCursor id) {
+ auto* curs = (SDL_Cursor*) SDL_calloc(1, sizeof(SDL_Cursor));
+ if (!curs)
+ SDL_OutOfMemory();
+ return curs;
+}
+
+static SDL_Cursor* DUCKOS_CreateDefaultCursor() {
+ return DUCKOS_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
+}
+
+static void DUCKOS_FreeCursor(SDL_Cursor* cursor) {
+ SDL_free(cursor);
+}
+
+static int DUCKOS_ShowCursor(SDL_Cursor* cursor) {
+ // TODO
+ return 0;
+}
+
+static void DUCKOS_WarpMouse(SDL_Window* window, int x, int y) {
+ // TODO
+}
+
+static void DUCKOS_MouseInit(_THIS) {
+ auto mouse = SDL_GetMouse();
+ mouse->CreateSystemCursor = DUCKOS_CreateSystemCursor;
+ mouse->ShowCursor = DUCKOS_ShowCursor;
+ mouse->FreeCursor = DUCKOS_FreeCursor;
+ mouse->WarpMouse = DUCKOS_WarpMouse;
+ SDL_SetDefaultCursor(DUCKOS_CreateDefaultCursor());
+}
+
+static int DUCKOS_VideoInit(_THIS) {
+ if (!__sdl_libui_inited) {
+ __sdl_libui_inited = true;
+ UI::init(nullptr, nullptr);
+ }
+
+ DUCKOS_MouseInit(_this);
+
+ if (!UI::pond_context)
+ return -1;
+
+ auto disp_dims = UI::pond_context->get_display_dimensions();
+ SDL_DisplayMode mode;
+ mode.format = SDL_PIXELFORMAT_RGB888;
+ mode.w = disp_dims.width;
+ mode.h = disp_dims.height;
+ mode.refresh_rate = 60;
+ mode.driverdata = nullptr;
+
+ if (SDL_AddBasicVideoDisplay(&mode) < 0)
+ return -1;
+
+ SDL_AddDisplayMode(&_this->displays[0], &mode);
+ return 0;
+}
+
+static void DUCKOS_VideoQuit(_THIS) {
+
+}
+
+static int DUCKOS_SetDisplayMode(_THIS, SDL_VideoDisplay* disp, SDL_DisplayMode* mode) {
+ return 0;
+}
+
+static void DUCKOS_PumpEvents(_THIS) {
+ UI::update(0);
+}
+
+static int DUCKOS_CreateWindowFramebuffer(_THIS, SDL_Window* window, Uint32* format, void** pixels, int* pitch) {
+ auto driverwindow = (SDLLibUIWindow*) window->driverdata;
+ auto fb = Duck::Ptr<Gfx::Framebuffer>(new Gfx::Framebuffer(window->w, window->h));
+ driverwindow->m_widget->m_framebuffer = fb;
+ *pitch = sizeof(uint32_t) * fb->width;
+ *pixels = fb->data;
+ *format = SDL_PIXELFORMAT_RGB888;
+ return 0;
+}
+
+static int DUCKOS_UpdateWindowFramebuffer(_THIS, SDL_Window* window, const SDL_Rect* rects, int numrects) {
+ auto driverwindow = (SDLLibUIWindow*) window->driverdata;
+ driverwindow->m_widget->repaint();
+ UI::update(0);
+ return 0;
+}
+
+static void DUCKOS_DestroyWindowFramebuffer(_THIS, SDL_Window* window) {
+ auto driverwindow = (SDLLibUIWindow*) window->driverdata;
+ driverwindow->m_widget->m_framebuffer.reset();
+}
+
+static void DUCKOS_DeleteDevice(_THIS) {
+ SDL_free(_this);
+}
+
+static int DUCKOS_CreateWindow(_THIS, SDL_Window* window) {
+ auto driverwindow = new SDLLibUIWindow(window);
+ window->driverdata = driverwindow;
+ return 0;
+}
+
+static void DUCKOS_DestroyWindow(_THIS, SDL_Window* window) {
+ auto driverwindow = (SDLLibUIWindow*) window->driverdata;
+ delete driverwindow;
+ window->driverdata = nullptr;
+}
+
+static void DUCKOS_ShowWindow(_THIS, SDL_Window* window) {
+ auto driverwindow = (SDLLibUIWindow*) window->driverdata;
+ driverwindow->m_libui_window->show();
+}
+
+static void DUCKOS_HideWindow(_THIS, SDL_Window* window) {
+ auto driverwindow = (SDLLibUIWindow*) window->driverdata;
+ driverwindow->m_libui_window->hide();
+}
+
+static void DUCKOS_SetWindowTitle(_THIS, SDL_Window* window) {
+ auto driverwindow = (SDLLibUIWindow*) window->driverdata;
+ driverwindow->m_libui_window->set_title(window->title);
+}
+
+static void DUCKOS_SetWindowSize(_THIS, SDL_Window* window) {
+ auto driverwindow = (SDLLibUIWindow*) window->driverdata;
+ driverwindow->m_libui_window->resize({window->w, window->h});
+}
+
+static void DUCKOS_SetWindowIcon(_THIS, SDL_Window* window, SDL_Surface* icon) {
+ auto driverwindow = (SDLLibUIWindow*) window->driverdata;
+ // TODO
+}
+
+static SDL_VideoDevice* DUCKOS_CreateDevice() {
+ auto* dev = (SDL_VideoDevice*) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (!dev) {
+ SDL_OutOfMemory();
+ return nullptr;
+ }
+
+ // hack??? idk
+ SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "false");
+
+ dev->is_dummy = SDL_FALSE;
+ dev->VideoInit = DUCKOS_VideoInit;
+ dev->VideoQuit = DUCKOS_VideoQuit;
+ dev->SetDisplayMode = DUCKOS_SetDisplayMode;
+ dev->PumpEvents = DUCKOS_PumpEvents;
+ dev->CreateWindowFramebuffer = DUCKOS_CreateWindowFramebuffer;
+ dev->UpdateWindowFramebuffer = DUCKOS_UpdateWindowFramebuffer;
+ dev->DestroyWindowFramebuffer = DUCKOS_DestroyWindowFramebuffer;
+ dev->CreateSDLWindow = DUCKOS_CreateWindow;
+ dev->DestroyWindow = DUCKOS_DestroyWindow;
+ dev->ShowWindow = DUCKOS_ShowWindow;
+ dev->HideWindow = DUCKOS_HideWindow;
+ dev->SetWindowTitle = DUCKOS_SetWindowTitle;
+ dev->SetWindowSize = DUCKOS_SetWindowSize;
+ dev->SetWindowIcon = DUCKOS_SetWindowIcon;
+ dev->free = DUCKOS_DeleteDevice;
+
+ return dev;
+}
+
+VideoBootStrap DUCKOSVIDEO_bootstrap = {"duckOS", "SDL duckOS libui video driver", DUCKOS_CreateDevice, NULL};
+
+}
+
+#endif
\ No newline at end of file