From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Andreas Kling <kling@serenityos.org>
Date: Sat, 27 Mar 2021 22:05:09 +0100
Subject: [PATCH] Add Minerva platform support
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-Authored-By: Robin Burchell <robin+git@viroteck.net>
Co-Authored-By: tgsm <doodrabbit@hotmail.com>
Co-Authored-By: TheMorc <r.gracik@gmail.com>
Co-Authored-By: thatdutchguy <thatdutchguy@users.noreply.github.com>
Co-Authored-By: Oleg Sikorskiy <olegsik@gmail.com>
Co-Authored-By: Gunnar Beutner <gunnar@beutner.name>
Co-Authored-By: AnicJov <contact.andrija@gmail.com>
Co-Authored-By: Jelle Raaijmakers <jelle@gmta.nl>
Co-Authored-By: Kenneth Myhra <kennethmyhra@gmail.com>
Co-Authored-By: Stephan Unverwerth <s.unverwerth@gmx.de>
Co-Authored-By: Tim Schumacher <timschumi@gmx.de>
Co-Authored-By: circl <circl.lastname@gmail.com>
Co-Authored-By: kleines Filmröllchen <filmroellchen@serenityos.org>
Co-Authored-By: Linus Groh <mail@linusgroh.de>
Co-Authored-By: Tim Ledbetter <timledbetter@gmail.com>
Co-Authored-By: Refrag <R3FR4GYT@gmail.com>
Co-Authored-By: sdomi <ja@sdomi.pl>
---
CMakeLists.txt | 28 +-
build-scripts/config.sub | 3 +
cmake/sdlchecks.cmake | 20 +
include/SDL_config.h.cmake | 2 +
include/SDL_syswm.h | 3 +-
src/SDL_error.c | 7 +-
src/audio/SDL_audio.c | 3 +
src/audio/SDL_sysaudio.h | 1 +
src/audio/minerva/SDL_minervaaudio.cpp | 166 +++++
src/audio/minerva/SDL_minervaaudio.h | 38 +
src/stdlib/SDL_stdlib.c | 2 +-
src/video/SDL_sysvideo.h | 1 +
src/video/SDL_video.c | 7 +
src/video/minerva/SDL_minervaevents.cpp | 52 ++
src/video/minerva/SDL_minervaevents_c.h | 33 +
src/video/minerva/SDL_minervamessagebox.cpp | 47 ++
src/video/minerva/SDL_minervamessagebox.h | 38 +
src/video/minerva/SDL_minervamouse.cpp | 157 +++++
src/video/minerva/SDL_minervamouse.h | 39 ++
src/video/minerva/SDL_minervavideo.cpp | 659 ++++++++++++++++++
src/video/minerva/SDL_minervavideo.h | 101 +++
21 files changed, 1379 insertions(+), 28 deletions(-)
create mode 100644 src/audio/minerva/SDL_minervaaudio.cpp
create mode 100644 src/audio/minerva/SDL_minervaaudio.h
create mode 100644 src/video/minerva/SDL_minervaevents.cpp
create mode 100644 src/video/minerva/SDL_minervaevents_c.h
create mode 100644 src/video/minerva/SDL_minervamessagebox.cpp
create mode 100644 src/video/minerva/SDL_minervamessagebox.h
create mode 100644 src/video/minerva/SDL_minervamouse.cpp
create mode 100644 src/video/minerva/SDL_minervamouse.h
create mode 100644 src/video/minerva/SDL_minervavideo.cpp
create mode 100644 src/video/minerva/SDL_minervavideo.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 30ff00adf93878c328f534ca6a3acdd082d8f1dd..20a0d6bf23a2b665265c63fdcbf6958a6f2ae94d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,7 +6,7 @@ endif()
set(CMAKE_POLICY_DEFAULT_CMP0091 NEW)
cmake_minimum_required(VERSION 3.0.0...3.10)
-project(SDL2 C)
+project(SDL2 C CXX)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(SDL2_SUBPROJECT OFF)
@@ -34,6 +34,9 @@ set(PKGCONFIG_DEPENDS)
# etc. See https://github.com/libsdl-org/SDL/issues/4150
add_library(sdl-build-options INTERFACE)
+set(UNIX 1)
+set(VIDEO_WAYLAND OFF)
+
if(WINDOWS_STORE)
target_compile_definitions(sdl-build-options INTERFACE "-DSDL_BUILDING_WINRT=1" "WINAPI_FAMILY=WINAPI_FAMILY_APP")
target_compile_options(sdl-build-options INTERFACE "$<$<COMPILE_LANGUAGE:CXX>:-ZW>" "$<$<COMPILE_LANGUAGE:CXX>:-EHsc>")
@@ -438,7 +441,7 @@ set_option(SDL_LIBICONV "Prefer iconv() from libiconv, if available,
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)
@@ -1498,26 +1501,7 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
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()
+ CheckMinerva()
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 4aaae46f6f74428949f32922308f48bd1316e7c1..9491448493b88c7bd54e3fbfcb9e518de0667786 100755
--- a/build-scripts/config.sub
+++ b/build-scripts/config.sub
@@ -1633,6 +1633,9 @@ case $os in
os400*)
os=os400
;;
+ minerva*)
+ os=minerva
+ ;;
sunos5*)
os=`echo "$os" | sed -e 's|sunos5|solaris2|'`
;;
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index ac36cfa2d7ed1d9655ddbf9d9338d791f5f4dc23..1fbc636a4fcfa406b4615c010cbf167990c02985 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -809,6 +809,26 @@ macro(CheckDirectFB)
endif()
endmacro()
+# Requires:
+# - n/a
+macro(CheckMinerva)
+ message_warn("Configuring Minerva!")
+ set(HAVE_VIDEO_MINERVA TRUE)
+ set(HAVE_AUDIO_MINERVA TRUE)
+ set(HAVE_SDL_VIDEO TRUE)
+ set(HAVE_SDL_AUDIO TRUE)
+
+ set(CMAKE_CXX_FLAGS "-std=c++23 -fno-exceptions ${CMAKE_CXX_FLAGS}")
+ file(GLOB MINERVA_SOURCES ${SDL2_SOURCE_DIR}/src/video/minerva/*.cpp ${SDL2_SOURCE_DIR}/src/audio/minerva/*.cpp)
+ list(APPEND SOURCE_FILES ${MINERVA_SOURCES})
+ set(SDL_VIDEO_DRIVER_MINERVA 1)
+ set(SDL_AUDIO_DRIVER_MINERVA 1)
+ set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
+ set(HAVE_VIDEO_OPENGL TRUE)
+ set(SDL_VIDEO_OPENGL 1)
+ list(APPEND EXTRA_LIBS ipc gui gfx gl core coreminimal)
+endmacro(CheckMinerva)
+
# Requires:
# - n/a
macro(CheckVivante)
diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake
index ef014e7ddc4f1d33639d6f41b7eba038cfd938db..c0c4e49eda200e1b911248ac0464d60b99207e20 100644
--- a/include/SDL_config.h.cmake
+++ b/include/SDL_config.h.cmake
@@ -319,6 +319,7 @@
#cmakedefine SDL_AUDIO_DRIVER_PULSEAUDIO @SDL_AUDIO_DRIVER_PULSEAUDIO@
#cmakedefine SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC @SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC@
#cmakedefine SDL_AUDIO_DRIVER_QSA @SDL_AUDIO_DRIVER_QSA@
+#cmakedefine SDL_AUDIO_DRIVER_MINERVA @SDL_AUDIO_DRIVER_MINERVA@
#cmakedefine SDL_AUDIO_DRIVER_SNDIO @SDL_AUDIO_DRIVER_SNDIO@
#cmakedefine SDL_AUDIO_DRIVER_SNDIO_DYNAMIC @SDL_AUDIO_DRIVER_SNDIO_DYNAMIC@
#cmakedefine SDL_AUDIO_DRIVER_SUNAUDIO @SDL_AUDIO_DRIVER_SUNAUDIO@
@@ -412,6 +413,7 @@
#cmakedefine SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC @SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC@
#cmakedefine SDL_VIDEO_DRIVER_DUMMY @SDL_VIDEO_DRIVER_DUMMY@
#cmakedefine SDL_VIDEO_DRIVER_OFFSCREEN @SDL_VIDEO_DRIVER_OFFSCREEN@
+#cmakedefine SDL_VIDEO_DRIVER_MINERVA @SDL_VIDEO_DRIVER_MINERVA@
#cmakedefine SDL_VIDEO_DRIVER_WINDOWS @SDL_VIDEO_DRIVER_WINDOWS@
#cmakedefine SDL_VIDEO_DRIVER_WINRT @SDL_VIDEO_DRIVER_WINRT@
#cmakedefine SDL_VIDEO_DRIVER_WAYLAND @SDL_VIDEO_DRIVER_WAYLAND@
diff --git a/include/SDL_syswm.h b/include/SDL_syswm.h
index 18f6873299d111fbaf7a6efc69e6a060cfd3854b..8e96a8d23d55238ee10a85090c7b7b8745303819 100644
--- a/include/SDL_syswm.h
+++ b/include/SDL_syswm.h
@@ -148,7 +148,8 @@ typedef enum SDL_SYSWM_TYPE
SDL_SYSWM_OS2,
SDL_SYSWM_HAIKU,
SDL_SYSWM_KMSDRM,
- SDL_SYSWM_RISCOS
+ SDL_SYSWM_RISCOS,
+ SDL_SYSWM_MINERVA
} SDL_SYSWM_TYPE;
/**
diff --git a/src/SDL_error.c b/src/SDL_error.c
index db24b3bce6f7134dac7403f1c2c67cedef5ddef6..a78eb6693864885036e79b89a6c4992f3a525fb1 100644
--- a/src/SDL_error.c
+++ b/src/SDL_error.c
@@ -51,10 +51,9 @@ int SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
}
}
- if (SDL_LogGetPriority(SDL_LOG_CATEGORY_ERROR) <= SDL_LOG_PRIORITY_DEBUG) {
- /* If we are in debug mode, print out the error message */
- SDL_LogDebug(SDL_LOG_CATEGORY_ERROR, "%s", error->str);
- }
+ // # HACK(Minerva): show everything that's going on
+ dbgputstr(error->str, strlen(error->str));
+ dbgputstr("\n", 1);
}
return -1;
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 1ab847aa490eaeb714920cebd6cf02adc3a5124c..fc80d0b27b2c60ec2b789f90a2a01b77e4f51913 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -42,6 +42,9 @@ static SDL_AudioDevice *open_devices[16];
/* Available audio drivers */
static const AudioBootStrap *const bootstrap[] = {
+#ifdef SDL_AUDIO_DRIVER_MINERVA
+ &MINERVAAUDIO_bootstrap,
+#endif
#ifdef SDL_AUDIO_DRIVER_PULSEAUDIO
&PULSEAUDIO_bootstrap,
#endif
diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h
index 6e8de52915b1338a1b54eea3042c0d52d46deac6..e4496327048ed0e4986f28a9832fc91278e8d71f 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 MINERVAAUDIO_bootstrap;
#endif /* SDL_sysaudio_h_ */
diff --git a/src/audio/minerva/SDL_minervaaudio.cpp b/src/audio/minerva/SDL_minervaaudio.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..29fa1fcdb1bf018bae6129819648afccdf87c342
--- /dev/null
+++ b/src/audio/minerva/SDL_minervaaudio.cpp
@@ -0,0 +1,166 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2019 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, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_MINERVA
+# define AK_DONT_REPLACE_STD
+
+extern "C" {
+
+# include "SDL_audio.h"
+
+# include "../SDL_audio_c.h"
+# include "../SDL_audiodev_c.h"
+}
+
+# include <AK/Time.h>
+# include <LibAudio/ConnectionToServer.h>
+# include <LibAudio/SampleFormats.h>
+# include <time.h>
+# include "SDL_minervaaudio.h"
+
+static Array<Audio::Sample, Audio::AUDIO_BUFFER_SIZE> output_buffer {};
+static size_t output_buffer_samples_remaining { 0 };
+
+static void MINERVAAUDIO_CloseDevice(_THIS)
+{
+ dbgln("MINERVAAUDIO_CloseDevice");
+
+ struct SDL_PrivateAudioData* h = that->hidden;
+ if (h->client)
+ h->client->die();
+
+ SDL_free(that->hidden->mixbuf);
+ SDL_free(that->hidden);
+}
+
+static int MINERVAAUDIO_OpenDevice(_THIS, char const*)
+{
+ /* Initialize all variables that we clean on shutdown */
+ that->hidden = static_cast<struct SDL_PrivateAudioData*>(SDL_malloc(sizeof *that->hidden));
+ if (!that->hidden)
+ return SDL_OutOfMemory();
+ SDL_zerop(that->hidden);
+
+ that->spec.freq = 44100;
+ that->spec.format = AUDIO_S16LSB;
+ that->spec.channels = 2;
+ that->spec.samples = 1024;
+
+ /* Calculate the final parameters for this audio specification */
+ SDL_CalculateAudioSpec(&that->spec);
+
+ /* Allocate mixing buffer */
+ if (!that->iscapture) {
+ that->hidden->mixlen = that->spec.size;
+ that->hidden->mixbuf = (Uint8*)SDL_malloc(that->hidden->mixlen);
+ if (!that->hidden->mixbuf)
+ return SDL_OutOfMemory();
+ SDL_memset(that->hidden->mixbuf, that->spec.silence, that->spec.size);
+ }
+
+ /* We're ready to rock and roll. :-) */
+ return 0;
+}
+
+static void MINERVAAUDIO_PlayDevice(_THIS)
+{
+ struct SDL_PrivateAudioData* h = that->hidden;
+
+ // We need to create our audio connection and event loop here, in order to register them with SDL's audio thread
+ if (!h->event_loop)
+ h->event_loop = make<Core::EventLoop>();
+ if (!h->client)
+ h->client = MUST(Audio::ConnectionToServer::try_create());
+
+ h->client->async_start_playback();
+
+ auto convert_i16_to_double = [](i16 input) -> auto {
+ return (static_cast<double>(input) - NumericLimits<i16>::min()) / NumericLimits<u16>::max() * 2. - 1.;
+ };
+
+ auto const sleep_spec = Duration::from_nanoseconds(100).to_timespec();
+ auto input_buffer = reinterpret_cast<i16*>(h->mixbuf);
+ auto input_samples = h->mixlen / that->spec.channels / sizeof(i16);
+ size_t input_position = 0;
+
+ while (input_samples > 0) {
+ // Fill up the output buffer
+ auto const input_samples_to_process = min(input_samples, Audio::AUDIO_BUFFER_SIZE - output_buffer_samples_remaining);
+ for (size_t i = 0; i < input_samples_to_process; ++i) {
+ auto left = convert_i16_to_double(input_buffer[input_position]);
+ auto right = convert_i16_to_double(input_buffer[input_position + 1]);
+ output_buffer[output_buffer_samples_remaining + i] = Audio::Sample(left, right);
+ input_position += 2;
+ }
+ output_buffer_samples_remaining += input_samples_to_process;
+ input_samples -= input_samples_to_process;
+
+ // Stop if we don't have enough samples to fill a buffer
+ if (output_buffer_samples_remaining < Audio::AUDIO_BUFFER_SIZE)
+ break;
+
+ // Try to enqueue our output buffer
+ for (;;) {
+ auto enqueue_result = h->client->realtime_enqueue(output_buffer);
+ if (!enqueue_result.is_error())
+ break;
+ if (enqueue_result.error() != Audio::AudioQueue::QueueStatus::Full)
+ return;
+
+ nanosleep(&sleep_spec, nullptr);
+ }
+ output_buffer_samples_remaining = 0;
+ }
+
+ // Pump our event loop - should just be the IPC call to start playback
+ for (;;) {
+ auto number_of_events_pumped = h->event_loop->pump(Core::EventLoop::WaitMode::PollForEvents);
+ if (number_of_events_pumped == 0)
+ break;
+ }
+}
+
+static Uint8* MINERVAAUDIO_GetDeviceBuf(_THIS)
+{
+ return that->hidden->mixbuf;
+}
+
+static SDL_bool MINERVAAUDIO_Init(SDL_AudioDriverImpl* impl)
+{
+ /* Set the function pointers */
+ impl->OpenDevice = MINERVAAUDIO_OpenDevice;
+ impl->PlayDevice = MINERVAAUDIO_PlayDevice;
+ impl->GetDeviceBuf = MINERVAAUDIO_GetDeviceBuf;
+ impl->CloseDevice = MINERVAAUDIO_CloseDevice;
+
+ impl->AllowsArbitraryDeviceNames = SDL_TRUE;
+ impl->HasCaptureSupport = SDL_FALSE;
+ impl->OnlyHasDefaultOutputDevice = SDL_TRUE;
+
+ return SDL_TRUE; // this audio target is available.
+}
+
+AudioBootStrap MINERVAAUDIO_bootstrap = {
+ "minerva", "Minerva using AudioServer", MINERVAAUDIO_Init, SDL_FALSE
+};
+
+#endif
diff --git a/src/audio/minerva/SDL_minervaaudio.h b/src/audio/minerva/SDL_minervaaudio.h
new file mode 100644
index 0000000000000000000000000000000000000000..8d152ca843e732d2d5a8127fc191ca22ce690a83
--- /dev/null
+++ b/src/audio/minerva/SDL_minervaaudio.h
@@ -0,0 +1,38 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2019 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, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#pragma once
+
+#include "../SDL_sysaudio.h"
+#include <AK/OwnPtr.h>
+#include <AK/RefPtr.h>
+#include <LibAudio/ConnectionToServer.h>
+#include <LibCore/EventLoop.h>
+
+#define _THIS SDL_AudioDevice* that
+
+struct SDL_PrivateAudioData {
+ RefPtr<Audio::ConnectionToServer> client;
+ OwnPtr<Core::EventLoop> event_loop;
+ Uint8* mixbuf { nullptr };
+ size_t mixlen { 0 };
+};
diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c
index 2a930da2f5e77ea083690fc25fae45d79c8695de..cadafcf5d4f279593b283d58114a282bb01671d1 100644
--- a/src/stdlib/SDL_stdlib.c
+++ b/src/stdlib/SDL_stdlib.c
@@ -618,7 +618,7 @@ void *SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
#endif /* HAVE_MEMSET */
}
-#if defined(HAVE_CTYPE_H) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#if defined(HAVE_CTYPE_H) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && !defined(__minerva__)
int SDL_isblank(int x)
{
return isblank(x);
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 22bca8a222c929f27face7e77835d1f96c63c0c4..d7a6f5c450b4ee8952ed3887e50caf2f4408e027 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -485,6 +485,7 @@ extern VideoBootStrap OFFSCREEN_bootstrap;
extern VideoBootStrap NGAGE_bootstrap;
extern VideoBootStrap OS2DIVE_bootstrap;
extern VideoBootStrap OS2VMAN_bootstrap;
+extern VideoBootStrap MINERVAVIDEO_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 01023753c6e49967e33d4f402e2272040a31190d..fcf6e50737387094646101d30b81c4a30c625eb9 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -72,6 +72,9 @@
/* Available video drivers */
static VideoBootStrap *bootstrap[] = {
+#ifdef SDL_VIDEO_DRIVER_MINERVA
+ &MINERVAVIDEO_bootstrap,
+#endif
#ifdef SDL_VIDEO_DRIVER_COCOA
&COCOA_bootstrap,
#endif
@@ -4345,6 +4348,10 @@ void SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
}
}
#endif
+#if SDL_VIDEO_DRIVER_MINERVA
+#include "minerva/SDL_minervamessagebox.h"
+#endif
+
SDL_bool SDL_GetWindowWMInfo(SDL_Window * window, struct SDL_SysWMinfo *info)
{
diff --git a/src/video/minerva/SDL_minervaevents.cpp b/src/video/minerva/SDL_minervaevents.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..04cbf21ce74fb11e6713ba3a4beaad808751e80b
--- /dev/null
+++ b/src/video/minerva/SDL_minervaevents.cpp
@@ -0,0 +1,52 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2021 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, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_MINERVA
+#define AK_DONT_REPLACE_STD
+
+#include "../../events/SDL_events_c.h"
+
+#include "SDL_minervavideo.h"
+#include "SDL_minervaevents_c.h"
+#include "SDL_timer.h"
+
+#include <LibCore/EventLoop.h>
+
+void
+MINERVA_PumpEvents(_THIS)
+{
+ auto& loop = Core::EventLoop::current();
+ if (loop.was_exit_requested())
+ exit(0);
+
+ auto const event_loop_timeout_ms = SDL_GetTicks() + 100;
+ while (loop.pump(Core::EventLoop::WaitMode::PollForEvents) > 0) {
+ if (SDL_TICKS_PASSED(SDL_GetTicks(), event_loop_timeout_ms))
+ break;
+ }
+
+}
+
+
+#endif /* SDL_VIDEO_DRIVER_MINERVA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/minerva/SDL_minervaevents_c.h b/src/video/minerva/SDL_minervaevents_c.h
new file mode 100644
index 0000000000000000000000000000000000000000..89e9e919e319c701144da8f6d73bbb2ea519758d
--- /dev/null
+++ b/src/video/minerva/SDL_minervaevents_c.h
@@ -0,0 +1,33 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2019 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, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_minervaevents_c_h_
+#define SDL_minervaevents_c_h_
+
+#include "../../SDL_internal.h"
+
+#include "SDL_minervavideo.h"
+
+extern void MINERVA_PumpEvents(_THIS);
+
+#endif /* SDL_minervaevents_c_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/minerva/SDL_minervamessagebox.cpp b/src/video/minerva/SDL_minervamessagebox.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a0c7d0772be7198a521708abb9d69ef9cc413597
--- /dev/null
+++ b/src/video/minerva/SDL_minervamessagebox.cpp
@@ -0,0 +1,47 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2019 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, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+ */
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_MINERVA
+# define AK_DONT_REPLACE_STD
+
+# include "SDL_messagebox.h"
+# include "SDL_minervamessagebox.h"
+
+# include <LibGUI/Application.h>
+# include <LibGUI/MessageBox.h>
+# include <LibMain/Main.h>
+
+extern "C" int MINERVA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
+{
+ // From the docs: "[SDL_ShowMessageBox] may be called at any time, even before SDL_Init()."
+ AK::RefPtr<GUI::Application> app = GUI::Application::the();
+ if (app == nullptr)
+ app = MUST(GUI::Application::create(Main::Arguments {}));
+
+ GUI::MessageBox::show(nullptr, { messageboxdata->message, strlen(messageboxdata->message) }, { messageboxdata->title, strlen(messageboxdata->title) });
+ return 0;
+}
+
+#endif /* SDL_VIDEO_DRIVER_MINERVA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/minerva/SDL_minervamessagebox.h b/src/video/minerva/SDL_minervamessagebox.h
new file mode 100644
index 0000000000000000000000000000000000000000..34e607783310310ac8956bccf584b5ab12d45907
--- /dev/null
+++ b/src/video/minerva/SDL_minervamessagebox.h
@@ -0,0 +1,38 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2019 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, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_minervamessagebox_h_
+#define SDL_minervamessagebox_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int MINERVA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_minervamessagebox_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/minerva/SDL_minervamouse.cpp b/src/video/minerva/SDL_minervamouse.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..842ff899792544e5190efa738a31ccbd31e33b08
--- /dev/null
+++ b/src/video/minerva/SDL_minervamouse.cpp
@@ -0,0 +1,157 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2021 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, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_MINERVA
+#define AK_DONT_REPLACE_STD
+
+/*
+ * SDL includes:
+ */
+extern "C" {
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_touch_c.h"
+#include "../SDL_sysvideo.h"
+#include "SDL_events.h"
+}
+
+#include "SDL_minervamouse.h"
+#include "SDL_minervavideo.h"
+
+#include <LibGfx/StandardCursor.h>
+#include <LibGUI/ConnectionToWindowServer.h>
+
+struct MinervaCursorData final {
+ Gfx::StandardCursor cursor_type;
+};
+
+static SDL_Cursor*
+MINERVA_CreateSystemCursor(SDL_SystemCursor id)
+{
+ auto cursor = static_cast<SDL_Cursor*>(SDL_calloc(1, sizeof(SDL_Cursor)));
+ if (!cursor)
+ SDL_OutOfMemory();
+
+ auto cursor_data = static_cast<MinervaCursorData*>(SDL_calloc(1, sizeof(MinervaCursorData)));
+ if (!cursor_data)
+ SDL_OutOfMemory();
+ cursor->driverdata = static_cast<void*>(cursor_data);
+
+ switch(id)
+ {
+ case SDL_SYSTEM_CURSOR_ARROW: cursor_data->cursor_type = Gfx::StandardCursor::Arrow; break;
+ case SDL_SYSTEM_CURSOR_IBEAM: cursor_data->cursor_type = Gfx::StandardCursor::IBeam; break;
+ case SDL_SYSTEM_CURSOR_WAIT: cursor_data->cursor_type = Gfx::StandardCursor::Wait; break;
+ case SDL_SYSTEM_CURSOR_CROSSHAIR: cursor_data->cursor_type = Gfx::StandardCursor::Crosshair; break;
+ case SDL_SYSTEM_CURSOR_WAITARROW: cursor_data->cursor_type = Gfx::StandardCursor::Wait; break;
+ case SDL_SYSTEM_CURSOR_SIZENWSE: cursor_data->cursor_type = Gfx::StandardCursor::ResizeDiagonalTLBR; break;
+ case SDL_SYSTEM_CURSOR_SIZENESW: cursor_data->cursor_type = Gfx::StandardCursor::ResizeDiagonalBLTR; break;
+ case SDL_SYSTEM_CURSOR_SIZEWE: cursor_data->cursor_type = Gfx::StandardCursor::ResizeHorizontal; break;
+ case SDL_SYSTEM_CURSOR_SIZENS: cursor_data->cursor_type = Gfx::StandardCursor::ResizeVertical; break;
+ case SDL_SYSTEM_CURSOR_SIZEALL: cursor_data->cursor_type = Gfx::StandardCursor::Move; break;
+ case SDL_SYSTEM_CURSOR_NO: cursor_data->cursor_type = Gfx::StandardCursor::Disallowed; break;
+ case SDL_SYSTEM_CURSOR_HAND: cursor_data->cursor_type = Gfx::StandardCursor::Hand; break;
+ default:
+ SDL_assert(0);
+ return nullptr;
+ }
+ return cursor;
+}
+
+static SDL_Cursor*
+MINERVA_CreateDefaultCursor()
+{
+ return MINERVA_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
+}
+
+static void
+MINERVA_FreeCursor(SDL_Cursor* cursor)
+{
+ if (cursor->driverdata)
+ SDL_free(cursor->driverdata);
+ SDL_free(cursor);
+}
+
+static int
+MINERVA_ShowCursor(SDL_Cursor* cursor)
+{
+ auto focused_window = SDL_GetMouseFocus();
+ if (!focused_window)
+ return -1;
+
+ auto platform_window = MinervaPlatformWindow::from_sdl_window(focused_window);
+
+ // Hide the cursor
+ if (cursor == nullptr) {
+ platform_window->window()->set_cursor(Gfx::StandardCursor::Hidden);
+ return 0;
+ }
+
+ auto cursor_data = static_cast<MinervaCursorData*>(cursor->driverdata);
+ if (!cursor_data)
+ return -1;
+
+ platform_window->window()->set_cursor(cursor_data->cursor_type);
+ return 0;
+}
+
+static void
+MINERVA_WarpMouse(SDL_Window *window, int x, int y)
+{
+ auto platform_window = MinervaPlatformWindow::from_sdl_window(window);
+
+ auto window_position = platform_window->window()->position();
+ auto warp_position = Gfx::Point(x, y);
+
+ auto absolute_warp_position = window_position + warp_position;
+
+ GUI::ConnectionToWindowServer::the().async_set_global_cursor_position(absolute_warp_position);
+ SDL_SendMouseMotion(window, 0, 0, warp_position.x(), warp_position.y());
+}
+
+void
+MINERVA_InitMouse(_THIS)
+{
+ dbgln("MINERVA_InitMouse");
+
+ auto mouse = SDL_GetMouse();
+
+ mouse->CreateSystemCursor = MINERVA_CreateSystemCursor;
+ mouse->ShowCursor = MINERVA_ShowCursor;
+ mouse->FreeCursor = MINERVA_FreeCursor;
+ mouse->WarpMouse = MINERVA_WarpMouse;
+
+ // FIXME: implement below methods
+ //mouse->CreateCursor = ...;
+ //mouse->SetRelativeMouseMode = ...;
+
+ SDL_SetDefaultCursor(MINERVA_CreateDefaultCursor());
+}
+
+void
+MINERVA_QuitMouse(_THIS)
+{
+ dbgln("MINERVA_QuitMouse");
+}
+
+#endif /* SDL_VIDEO_DRIVER_MINERVA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/minerva/SDL_minervamouse.h b/src/video/minerva/SDL_minervamouse.h
new file mode 100644
index 0000000000000000000000000000000000000000..039f0361b3d1b248e218ea69495f58e52ad532c6
--- /dev/null
+++ b/src/video/minerva/SDL_minervamouse.h
@@ -0,0 +1,39 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2021 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, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#ifndef SDL_minervamouse_h_
+#define SDL_minervamouse_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void MINERVA_InitMouse(_THIS);
+extern void MINERVA_QuitMouse(_THIS);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_minervamouse_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/minerva/SDL_minervavideo.cpp b/src/video/minerva/SDL_minervavideo.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..64f956a456730cfd99998566810c04df64a1bfa0
--- /dev/null
+++ b/src/video/minerva/SDL_minervavideo.cpp
@@ -0,0 +1,659 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2019 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, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+ */
+extern "C" {
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_MINERVA
+# define AK_DONT_REPLACE_STD
+
+# include "../../events/SDL_events_c.h"
+# include "../SDL_pixels_c.h"
+# include "../SDL_sysvideo.h"
+# include "SDL_mouse.h"
+# include "SDL_syswm.h"
+# include "SDL_video.h"
+}
+
+# include "SDL_minervaevents_c.h"
+# include "SDL_minervamessagebox.h"
+# include "SDL_minervamouse.h"
+# include "SDL_minervavideo.h"
+
+# include <AK/Array.h>
+# include <Kernel/API/KeyCode.h>
+# include <LibCore/EventLoop.h>
+# include <LibGUI/Application.h>
+# include <LibGUI/Desktop.h>
+# include <LibGUI/Painter.h>
+# include <LibGUI/Widget.h>
+# include <LibGUI/Window.h>
+# include <LibGfx/Bitmap.h>
+# include <LibMain/Main.h>
+# include <dlfcn.h>
+
+static consteval AK::Array<SDL_Scancode, key_code_count> generate_scancode_map()
+{
+ auto map = AK::Array<SDL_Scancode, key_code_count>::from_repeated_value(SDL_SCANCODE_UNKNOWN);
+
+ // Below list is in order of Kernel/API/KeyCode.h; the shift modifier is applied by SDL
+ // and as such, unshifted scancodes must be used (e.g. dollar sign => 4).
+# define MAP_KEYCODE(A,B) map[to_underlying(KeyCode::Key_##A)] = SDL_SCANCODE_##B;
+ MAP_KEYCODE(Escape, ESCAPE);
+ MAP_KEYCODE(Tab, TAB);
+ MAP_KEYCODE(Backspace, BACKSPACE);
+ MAP_KEYCODE(Return, RETURN);
+ MAP_KEYCODE(Insert, INSERT);
+ MAP_KEYCODE(Delete, DELETE);
+ MAP_KEYCODE(PrintScreen, PRINTSCREEN);
+ MAP_KEYCODE(PauseBreak, PAUSE);
+ MAP_KEYCODE(SysRq, SYSREQ);
+ MAP_KEYCODE(Home, HOME);
+ MAP_KEYCODE(End, END);
+ MAP_KEYCODE(Left, LEFT);
+ MAP_KEYCODE(Up, UP);
+ MAP_KEYCODE(Right, RIGHT);
+ MAP_KEYCODE(Down, DOWN);
+ MAP_KEYCODE(PageUp, PAGEUP);
+ MAP_KEYCODE(PageDown, PAGEDOWN);
+ MAP_KEYCODE(LeftShift, LSHIFT);
+ MAP_KEYCODE(RightShift, RSHIFT);
+ MAP_KEYCODE(LeftControl, LCTRL);
+ MAP_KEYCODE(RightControl, RCTRL);
+ MAP_KEYCODE(LeftAlt, LALT);
+ MAP_KEYCODE(RightAlt, RALT);
+ MAP_KEYCODE(CapsLock, CAPSLOCK);
+ MAP_KEYCODE(NumLock, NUMLOCKCLEAR);
+ MAP_KEYCODE(ScrollLock, SCROLLLOCK);
+ MAP_KEYCODE(F1, F1);
+ MAP_KEYCODE(F2, F2);
+ MAP_KEYCODE(F3, F3);
+ MAP_KEYCODE(F4, F4);
+ MAP_KEYCODE(F5, F5);
+ MAP_KEYCODE(F6, F6);
+ MAP_KEYCODE(F7, F7);
+ MAP_KEYCODE(F8, F8);
+ MAP_KEYCODE(F9, F9);
+ MAP_KEYCODE(F10, F10);
+ MAP_KEYCODE(F11, F11);
+ MAP_KEYCODE(F12, F12);
+ MAP_KEYCODE(Space, SPACE);
+ MAP_KEYCODE(ExclamationPoint, 1);
+ MAP_KEYCODE(DoubleQuote, APOSTROPHE);
+ MAP_KEYCODE(Hashtag, 3);
+ MAP_KEYCODE(Dollar, 4);
+ MAP_KEYCODE(Percent, 5);
+ MAP_KEYCODE(Ampersand, 7);
+ MAP_KEYCODE(Apostrophe, APOSTROPHE);
+ MAP_KEYCODE(LeftParen, 9);
+ MAP_KEYCODE(RightParen, 0);
+ MAP_KEYCODE(Asterisk, 8);
+ MAP_KEYCODE(Plus, EQUALS);
+ MAP_KEYCODE(Comma, COMMA);
+ MAP_KEYCODE(Minus, MINUS);
+ MAP_KEYCODE(Period, PERIOD);
+ MAP_KEYCODE(Slash, SLASH);
+ MAP_KEYCODE(0, 0);
+ MAP_KEYCODE(1, 1);
+ MAP_KEYCODE(2, 2);
+ MAP_KEYCODE(3, 3);
+ MAP_KEYCODE(4, 4);
+ MAP_KEYCODE(5, 5);
+ MAP_KEYCODE(6, 6);
+ MAP_KEYCODE(7, 7);
+ MAP_KEYCODE(8, 8);
+ MAP_KEYCODE(9, 9);
+ MAP_KEYCODE(Colon, SEMICOLON);
+ MAP_KEYCODE(Semicolon, SEMICOLON);
+ MAP_KEYCODE(LessThan, COMMA);
+ MAP_KEYCODE(Equal, EQUALS);
+ MAP_KEYCODE(GreaterThan, PERIOD);
+ MAP_KEYCODE(QuestionMark, SLASH);
+ MAP_KEYCODE(A, A);
+ MAP_KEYCODE(B, B);
+ MAP_KEYCODE(C, C);
+ MAP_KEYCODE(D, D);
+ MAP_KEYCODE(E, E);
+ MAP_KEYCODE(F, F);
+ MAP_KEYCODE(G, G);
+ MAP_KEYCODE(H, H);
+ MAP_KEYCODE(I, I);
+ MAP_KEYCODE(J, J);
+ MAP_KEYCODE(K, K);
+ MAP_KEYCODE(L, L);
+ MAP_KEYCODE(M, M);
+ MAP_KEYCODE(N, N);
+ MAP_KEYCODE(O, O);
+ MAP_KEYCODE(P, P);
+ MAP_KEYCODE(Q, Q);
+ MAP_KEYCODE(R, R);
+ MAP_KEYCODE(S, S);
+ MAP_KEYCODE(T, T);
+ MAP_KEYCODE(U, U);
+ MAP_KEYCODE(V, V);
+ MAP_KEYCODE(W, W);
+ MAP_KEYCODE(X, X);
+ MAP_KEYCODE(Y, Y);
+ MAP_KEYCODE(Z, Z);
+ MAP_KEYCODE(LeftBracket, LEFTBRACKET);
+ MAP_KEYCODE(RightBracket, RIGHTBRACKET);
+ MAP_KEYCODE(Backslash, BACKSLASH);
+ MAP_KEYCODE(Circumflex, 6);
+ MAP_KEYCODE(Underscore, MINUS);
+ MAP_KEYCODE(LeftBrace, LEFTBRACKET);
+ MAP_KEYCODE(RightBrace, RIGHTBRACKET);
+ MAP_KEYCODE(Pipe, BACKSLASH);
+ MAP_KEYCODE(Tilde, GRAVE);
+ MAP_KEYCODE(Backtick, GRAVE);
+ MAP_KEYCODE(LeftSuper, LGUI);
+ MAP_KEYCODE(RightSuper, LGUI);
+ MAP_KEYCODE(BrowserSearch, AC_SEARCH);
+ MAP_KEYCODE(BrowserFavorites, AC_BOOKMARKS);
+ MAP_KEYCODE(BrowserHome, AC_HOME);
+ MAP_KEYCODE(PreviousTrack, AUDIOPREV);
+ MAP_KEYCODE(BrowserBack, AC_BACK);
+ MAP_KEYCODE(BrowserForward, AC_FORWARD);
+ MAP_KEYCODE(BrowserRefresh, AC_REFRESH);
+ MAP_KEYCODE(BrowserStop, AC_STOP);
+ MAP_KEYCODE(VolumeDown, VOLUMEDOWN);
+ MAP_KEYCODE(VolumeUp, VOLUMEUP);
+ // Unmapped: Wake
+ MAP_KEYCODE(Sleep, SLEEP);
+ MAP_KEYCODE(NextTrack, AUDIONEXT);
+ MAP_KEYCODE(MediaSelect, MEDIASELECT);
+ MAP_KEYCODE(Email, MAIL);
+ MAP_KEYCODE(MyComputer, COMPUTER);
+ MAP_KEYCODE(Power, POWER);
+ MAP_KEYCODE(Stop, STOP);
+ MAP_KEYCODE(LeftGUI, LGUI);
+ MAP_KEYCODE(Mute, MUTE);
+ MAP_KEYCODE(RightGUI, RGUI);
+ MAP_KEYCODE(Calculator, CALCULATOR);
+ // Unmapped: Apps
+ MAP_KEYCODE(PlayPause, AUDIOPLAY);
+ MAP_KEYCODE(Menu, APPLICATION);
+
+ return map;
+}
+
+static constexpr auto scancode_map = generate_scancode_map();
+
+/* Initialization/Query functions */
+static int MINERVA_VideoInit(_THIS);
+static int MINERVA_SetDisplayMode(_THIS, SDL_VideoDisplay* display,
+ SDL_DisplayMode* mode);
+static void MINERVA_VideoQuit(_THIS);
+
+/* MINERVA driver bootstrap functions */
+
+static int MINERVA_Available(void) { return (1); }
+
+static void MINERVA_DeleteDevice(SDL_VideoDevice* device)
+{
+ dbgln("MINERVA_DeleteDevice");
+ SDL_free(device);
+}
+
+extern int Minerva_CreateWindow(_THIS, SDL_Window* window);
+extern void Minerva_ShowWindow(_THIS, SDL_Window* window);
+extern void Minerva_HideWindow(_THIS, SDL_Window* window);
+extern void Minerva_SetWindowTitle(_THIS, SDL_Window* window);
+extern void Minerva_SetWindowSize(_THIS, SDL_Window* window);
+extern void Minerva_SetWindowFullscreen(_THIS, SDL_Window* window,
+ SDL_VideoDisplay* display,
+ SDL_bool fullscreen);
+extern void Minerva_SetWindowIcon(_THIS, SDL_Window* window, SDL_Surface* icon);
+extern void Minerva_DestroyWindow(_THIS, SDL_Window* window);
+extern SDL_bool Minerva_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info);
+extern int Minerva_CreateWindowFramebuffer(_THIS, SDL_Window* window,
+ Uint32* format, void** pixels,
+ int* pitch);
+extern int Minerva_UpdateWindowFramebuffer(_THIS, SDL_Window* window,
+ const SDL_Rect* rects,
+ int numrects);
+extern void Minerva_DestroyWindowFramebuffer(_THIS, SDL_Window* window);
+extern SDL_GLContext Minerva_GL_CreateContext(_THIS, SDL_Window* window);
+extern void Minerva_GL_DeleteContext(_THIS, SDL_GLContext context);
+extern void* Minerva_GL_GetProcAddress(_THIS, const char* proc);
+extern int Minerva_GL_LoadLibrary(_THIS, const char* path);
+extern int Minerva_GL_MakeCurrent(_THIS, SDL_Window* window, SDL_GLContext context);
+extern int Minerva_GL_SwapWindow(_THIS, SDL_Window* window);
+
+static SDL_VideoDevice* MINERVA_CreateDevice(void)
+{
+ SDL_VideoDevice* device;
+
+ /* Initialize all variables that we clean on shutdown */
+ device = (SDL_VideoDevice*)SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (!device) {
+ SDL_OutOfMemory();
+ return (0);
+ }
+ device->is_dummy = SDL_FALSE;
+
+ /* Set the function pointers */
+ device->VideoInit = MINERVA_VideoInit;
+ device->VideoQuit = MINERVA_VideoQuit;
+ device->SetDisplayMode = MINERVA_SetDisplayMode;
+ device->PumpEvents = MINERVA_PumpEvents;
+
+ device->CreateWindowFramebuffer = Minerva_CreateWindowFramebuffer;
+ device->UpdateWindowFramebuffer = Minerva_UpdateWindowFramebuffer;
+ device->DestroyWindowFramebuffer = Minerva_DestroyWindowFramebuffer;
+ device->CreateSDLWindow = Minerva_CreateWindow;
+ device->ShowWindow = Minerva_ShowWindow;
+ device->HideWindow = Minerva_HideWindow;
+ device->SetWindowTitle = Minerva_SetWindowTitle;
+ device->SetWindowSize = Minerva_SetWindowSize;
+ device->SetWindowFullscreen = Minerva_SetWindowFullscreen;
+ device->SetWindowIcon = Minerva_SetWindowIcon;
+ device->DestroyWindow = Minerva_DestroyWindow;
+ device->GetWindowWMInfo = Minerva_GetWindowWMInfo;
+
+ device->GL_CreateContext = Minerva_GL_CreateContext;
+ device->GL_DeleteContext = Minerva_GL_DeleteContext;
+ device->GL_GetProcAddress = Minerva_GL_GetProcAddress;
+ device->GL_LoadLibrary = Minerva_GL_LoadLibrary;
+ device->GL_MakeCurrent = Minerva_GL_MakeCurrent;
+ device->GL_SwapWindow = Minerva_GL_SwapWindow;
+
+ device->free = MINERVA_DeleteDevice;
+
+ Minerva_GL_LoadLibrary(device, nullptr);
+
+ return device;
+}
+
+VideoBootStrap MINERVAVIDEO_bootstrap = { "minerva", "SDL minerva video driver", MINERVA_CreateDevice, MINERVA_ShowMessageBox };
+
+static RefPtr<GUI::Application> g_app;
+
+int MINERVA_VideoInit(_THIS)
+{
+ dbgln("{}: Initialising SDL application", __FUNCTION__);
+
+ if (!g_app) {
+ g_app = MUST(GUI::Application::create(Main::Arguments {}));
+ g_app->set_quit_when_last_window_deleted(false);
+ }
+
+ MINERVA_InitMouse(_this);
+
+ // We only add the active desktop resolution until we properly support multiple
+ // fullscreen resolutions
+ auto desktop_rect = GUI::Desktop::the().rect();
+
+ SDL_DisplayMode mode;
+ mode.format = SDL_PIXELFORMAT_RGB888;
+ mode.w = desktop_rect.width();
+ mode.h = desktop_rect.height();
+ mode.refresh_rate = 60;
+ mode.driverdata = nullptr;
+
+ if (SDL_AddBasicVideoDisplay(&mode) < 0)
+ return -1;
+
+ SDL_AddDisplayMode(&_this->displays[0], &mode);
+
+ /* We're done! */
+ return 0;
+}
+
+static int MINERVA_SetDisplayMode(_THIS, SDL_VideoDisplay* display,
+ SDL_DisplayMode* mode)
+{
+ dbgln("MINERVA_SetDisplayMode");
+ return 0;
+}
+
+void MINERVA_VideoQuit(_THIS)
+{
+ dbgln("MINERVA_VideoQuit");
+ MINERVA_QuitMouse(_this);
+}
+
+MinervaSDLWidget::MinervaSDLWidget(SDL_Window* sdl_window)
+ : m_sdl_window(sdl_window)
+{
+}
+
+void MinervaSDLWidget::paint_event(GUI::PaintEvent& event)
+{
+ if (!m_buffer)
+ return;
+
+ GUI::Painter painter(*this);
+ painter.add_clip_rect(event.rect());
+ painter.blit(event.rect().location(), *m_buffer, event.rect());
+}
+
+void MinervaSDLWidget::resize_event(GUI::ResizeEvent&)
+{
+ SDL_SendWindowEvent(m_sdl_window, SDL_WINDOWEVENT_RESIZED, width(), height());
+}
+void MinervaSDLWidget::show_event(GUI::ShowEvent&)
+{
+ SDL_SendWindowEvent(m_sdl_window, SDL_WINDOWEVENT_SHOWN, 0, 0);
+}
+void MinervaSDLWidget::hide_event(GUI::HideEvent&)
+{
+ SDL_SendWindowEvent(m_sdl_window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
+}
+
+static int map_button(GUI::MouseButton button)
+{
+ switch (button) {
+ case GUI::MouseButton::Primary:
+ return SDL_BUTTON_LEFT;
+ case GUI::MouseButton::Middle:
+ return SDL_BUTTON_MIDDLE;
+ case GUI::MouseButton::Secondary:
+ return SDL_BUTTON_RIGHT;
+ case GUI::MouseButton::Forward:
+ return SDL_BUTTON_X1;
+ case GUI::MouseButton::Backward:
+ return SDL_BUTTON_X2;
+ }
+
+ VERIFY_NOT_REACHED();
+ return 0;
+}
+
+void MinervaSDLWidget::mousedown_event(GUI::MouseEvent& event)
+{
+ SDL_SendMouseMotion(m_sdl_window, 0, 0, event.x(), event.y());
+ SDL_SendMouseButton(m_sdl_window, 0, SDL_PRESSED, map_button(event.button()));
+}
+
+void MinervaSDLWidget::mousemove_event(GUI::MouseEvent& event)
+{
+ SDL_SendMouseMotion(m_sdl_window, 0, 0, event.x(), event.y());
+}
+
+void MinervaSDLWidget::mouseup_event(GUI::MouseEvent& event)
+{
+ SDL_SendMouseMotion(m_sdl_window, 0, 0, event.x(), event.y());
+ SDL_SendMouseButton(m_sdl_window, 0, SDL_RELEASED, map_button(event.button()));
+}
+
+void MinervaSDLWidget::mousewheel_event(GUI::MouseEvent& event)
+{
+ SDL_SendMouseMotion(m_sdl_window, 0, 0, event.x(), event.y());
+ SDL_SendMouseWheel(m_sdl_window, 0, (float)event.wheel_raw_delta_x(), -(float)event.wheel_raw_delta_y(), SDL_MOUSEWHEEL_NORMAL);
+}
+
+void MinervaSDLWidget::keydown_event(GUI::KeyEvent& event)
+{
+ SDL_SendKeyboardKey(SDL_PRESSED, scancode_map[event.key()]);
+ auto text = event.text();
+ if (!text.is_empty())
+ SDL_SendKeyboardText(text.characters());
+}
+
+void MinervaSDLWidget::keyup_event(GUI::KeyEvent& event)
+{
+ SDL_SendKeyboardKey(SDL_RELEASED, scancode_map[event.key()]);
+}
+
+void MinervaSDLWidget::enter_event(Core::Event&)
+{
+ SDL_SetMouseFocus(m_sdl_window);
+}
+
+void MinervaSDLWidget::leave_event(Core::Event&)
+{
+ SDL_SetMouseFocus(nullptr);
+}
+
+int Minerva_CreateWindow(_THIS, SDL_Window* window)
+{
+ dbgln("{}: Creating new window of size {}x{}", __FUNCTION__, window->w, window->h);
+
+ auto w = new MinervaPlatformWindow(window);
+ window->driverdata = w;
+ w->window()->set_double_buffering_enabled(false);
+ w->widget()->set_fill_with_background_color(false);
+ w->window()->set_main_widget(w->widget());
+ w->window()->on_close_request = [window] {
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_CLOSE, 0, 0);
+ return GUI::Window::CloseRequestDecision::StayOpen;
+ };
+ w->window()->on_active_window_change = [window](bool is_active_window) {
+ SDL_SetKeyboardFocus(is_active_window ? window : nullptr);
+ };
+ w->window()->on_input_preemption_change = [window](bool is_preempted) {
+ SDL_SetKeyboardFocus(is_preempted ? nullptr : window);
+ };
+ MINERVA_PumpEvents(_this);
+
+ return 0;
+}
+
+void Minerva_ShowWindow(_THIS, SDL_Window* window)
+{
+ MinervaPlatformWindow::from_sdl_window(window)->window()->show();
+}
+
+void Minerva_HideWindow(_THIS, SDL_Window* window)
+{
+ MinervaPlatformWindow::from_sdl_window(window)->window()->hide();
+}
+
+void Minerva_SetWindowTitle(_THIS, SDL_Window* window)
+{
+ MinervaPlatformWindow::from_sdl_window(window)->window()->set_title(window->title);
+}
+
+void Minerva_SetWindowSize(_THIS, SDL_Window* window)
+{
+ MinervaPlatformWindow::from_sdl_window(window)->window()->resize(window->w, window->h);
+}
+
+void Minerva_SetWindowFullscreen(_THIS, SDL_Window* window,
+ SDL_VideoDisplay* display,
+ SDL_bool fullscreen)
+{
+ dbgln("Attempting to set SDL Window fullscreen to {}", (bool)fullscreen);
+ MinervaPlatformWindow::from_sdl_window(window)->window()->set_fullscreen(fullscreen);
+}
+
+static Gfx::Color get_color_from_sdl_pixel(SDL_PixelFormat const& format, u32 pixel)
+{
+ u8 r = ((pixel & format.Rmask) >> format.Rshift) << format.Rloss;
+ u8 g = ((pixel & format.Gmask) >> format.Gshift) << format.Gloss;
+ u8 b = ((pixel & format.Bmask) >> format.Bshift) << format.Bloss;
+ u8 a = ((pixel & format.Amask) >> format.Ashift) << format.Aloss;
+ return {r, g, b, a};
+}
+
+static RefPtr<Gfx::Bitmap> create_bitmap_from_surface(SDL_Surface& icon)
+{
+ auto bitmap_or_error = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, {icon.w, icon.h});
+ if (bitmap_or_error.is_error())
+ return {};
+ auto bitmap = bitmap_or_error.release_value();
+
+ SDL_LockSurface(&icon);
+
+ auto const& pixel_format = *icon.format;
+ auto pixels = static_cast<u32*>(icon.pixels);
+ size_t offset = 0;
+ switch (pixel_format.format) {
+ case SDL_PIXELFORMAT_ARGB8888:
+ for (size_t y = 0; y < icon.h; ++y) {
+ for (size_t x = 0; x < icon.w; ++x) {
+ bitmap->set_pixel({x, y}, get_color_from_sdl_pixel(pixel_format, pixels[offset]));
+ ++offset;
+ }
+ }
+ break;
+ default:
+ warnln("Unable to convert SDL_Surface with format {} to bitmap", SDL_GetPixelFormatName(pixel_format.format));
+ }
+
+ SDL_UnlockSurface(&icon);
+
+ return bitmap;
+}
+
+void Minerva_SetWindowIcon(_THIS, SDL_Window* window, SDL_Surface* icon)
+{
+ auto minerva_window = MinervaPlatformWindow::from_sdl_window(window)->window();
+ if (!icon) {
+ minerva_window->set_icon(nullptr);
+ return;
+ }
+
+ auto icon_bitmap = create_bitmap_from_surface(*icon);
+ if (icon_bitmap)
+ minerva_window->set_icon(icon_bitmap);
+}
+
+void Minerva_DestroyWindow(_THIS, SDL_Window* window)
+{
+ auto platform_window = MinervaPlatformWindow::from_sdl_window(window);
+ delete platform_window;
+ window->driverdata = nullptr;
+}
+
+SDL_bool Minerva_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
+{
+ info->subsystem = SDL_SYSWM_MINERVA;
+ return SDL_TRUE;
+}
+
+int Minerva_CreateWindowFramebuffer(_THIS, SDL_Window* window, Uint32* format,
+ void** pixels, int* pitch)
+{
+ dbgln("{}: Creating a new framebuffer of size {}x{}", __FUNCTION__, window->w, window->h);
+ auto win = MinervaPlatformWindow::from_sdl_window(window);
+ *format = SDL_PIXELFORMAT_RGB888;
+ auto bitmap_or_error = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, {window->w, window->h});
+ if (bitmap_or_error.is_error())
+ return SDL_OutOfMemory();
+ win->widget()->m_buffer = bitmap_or_error.release_value();
+ *pitch = win->widget()->m_buffer->pitch();
+ *pixels = win->widget()->m_buffer->scanline(0);
+ return 0;
+}
+
+int Minerva_UpdateWindowFramebuffer(_THIS, SDL_Window* window,
+ const SDL_Rect* rects, int numrects)
+{
+ auto win = MinervaPlatformWindow::from_sdl_window(window);
+ for (int i = 0; i < numrects; i++) {
+ win->widget()->update(Gfx::IntRect(rects[i].x, rects[i].y, rects[i].w, rects[i].h));
+ }
+ MINERVA_PumpEvents(_this);
+
+ return 0;
+}
+
+void Minerva_DestroyWindowFramebuffer(_THIS, SDL_Window* window)
+{
+ auto widget = MinervaPlatformWindow::from_sdl_window(window)->widget();
+ if (!widget->m_buffer)
+ return;
+ dbgln("{}: Destroy framebuffer {}", __FUNCTION__, widget->m_buffer->size());
+ widget->m_buffer = nullptr;
+}
+
+SDL_GLContext Minerva_GL_CreateContext(_THIS, SDL_Window* window)
+{
+ auto platform_window = MinervaPlatformWindow::from_sdl_window(window);
+
+ Uint32 format;
+ void* pixels;
+ int pitch;
+ Minerva_CreateWindowFramebuffer(_this, window, &format, &pixels, &pitch);
+
+ auto gl_context_or_error = GL::create_context(*platform_window->widget()->m_buffer);
+ if (gl_context_or_error.is_error()) {
+ SDL_SetError("Failed to initialize the GL context");
+ return nullptr;
+ }
+ auto gl_context = gl_context_or_error.release_value();
+ auto minerva_gl_context = new MinervaGLContext(move(gl_context));
+ platform_window->set_minerva_gl_context(minerva_gl_context);
+ GL::make_context_current(&minerva_gl_context->gl_context());
+ return minerva_gl_context;
+}
+
+void Minerva_GL_DeleteContext(_THIS, SDL_GLContext context)
+{
+ auto platform_context = static_cast<MinervaGLContext*>(context);
+ delete platform_context;
+}
+
+int Minerva_GL_LoadLibrary(_THIS, const char* path)
+{
+ if (_this->gl_config.driver_loaded) {
+ SDL_SetError("OpenGL library is already loaded");
+ return -1;
+ }
+
+ _this->gl_config.dll_handle = dlopen("libgl.so.minerva", RTLD_LAZY | RTLD_LOCAL);
+ if (!_this->gl_config.dll_handle) {
+ dbgln("Could not load OpenGL library: {}", dlerror());
+ _this->gl_config.driver_loaded = SDL_FALSE;
+ return -1;
+ }
+
+ _this->gl_config.driver_loaded = SDL_TRUE;
+ return 0;
+}
+
+void* Minerva_GL_GetProcAddress(_THIS, const char* proc)
+{
+ if (!_this->gl_config.dll_handle) {
+ SDL_SetError("OpenGL library not available");
+ return nullptr;
+ }
+ auto* res = dlsym(_this->gl_config.dll_handle, proc);
+ dbgln("GetProcAddress: {} -> {}", proc, res);
+ return res;
+}
+
+int Minerva_GL_MakeCurrent(_THIS, SDL_Window* window, SDL_GLContext context)
+{
+ if (!window || !context)
+ return 0;
+
+ auto platform_window = MinervaPlatformWindow::from_sdl_window(window);
+ auto minerva_gl_context = static_cast<MinervaGLContext*>(context);
+ platform_window->set_minerva_gl_context(minerva_gl_context);
+ GL::make_context_current(&minerva_gl_context->gl_context());
+ return 0;
+}
+
+int Minerva_GL_SwapWindow(_THIS, SDL_Window* window)
+{
+ auto platform_window = MinervaPlatformWindow::from_sdl_window(window);
+ if (platform_window->minerva_gl_context())
+ platform_window->minerva_gl_context()->gl_context().present();
+
+ platform_window->widget()->repaint();
+ return 0;
+}
+
+#endif /* SDL_VIDEO_DRIVER_MINERVA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/minerva/SDL_minervavideo.h b/src/video/minerva/SDL_minervavideo.h
new file mode 100644
index 0000000000000000000000000000000000000000..f74e1bd981734caf023b77a9b9fa30c46be40e4c
--- /dev/null
+++ b/src/video/minerva/SDL_minervavideo.h
@@ -0,0 +1,101 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2019 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, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_minervavideo_h_
+#define SDL_minervavideo_h_
+
+#include "../SDL_sysvideo.h"
+
+#include <LibGL/GLContext.h>
+#include <LibGUI/Widget.h>
+#include <LibGUI/Window.h>
+
+class MinervaSDLWidget final : public GUI::Widget {
+ C_OBJECT(MinervaSDLWidget)
+public:
+ explicit MinervaSDLWidget(SDL_Window*);
+ RefPtr<Gfx::Bitmap> m_buffer;
+
+protected:
+ void paint_event(GUI::PaintEvent&) override;
+ void resize_event(GUI::ResizeEvent&) override;
+ void show_event(GUI::ShowEvent&) override;
+ void hide_event(GUI::HideEvent&) override;
+
+ void mousedown_event(GUI::MouseEvent&) override;
+ void mousemove_event(GUI::MouseEvent&) override;
+ void mouseup_event(GUI::MouseEvent&) override;
+ void mousewheel_event(GUI::MouseEvent&) override;
+
+ void keydown_event(GUI::KeyEvent& event) override;
+ void keyup_event(GUI::KeyEvent& event) override;
+
+ void enter_event(Core::Event&) override;
+ void leave_event(Core::Event&) override;
+
+private:
+ SDL_Window* m_sdl_window = nullptr;
+};
+
+class MinervaGLContext final {
+public:
+ explicit MinervaGLContext(NonnullOwnPtr<GL::GLContext> gl_context)
+ : m_gl_context(move(gl_context))
+ {
+ }
+
+ GL::GLContext& gl_context() { return *m_gl_context; }
+
+private:
+ NonnullOwnPtr<GL::GLContext> m_gl_context;
+};
+
+class MinervaPlatformWindow final {
+public:
+ explicit MinervaPlatformWindow(SDL_Window* sdl_window)
+ : m_window(MUST(GUI::Window::try_create()))
+ , m_widget(MUST(MinervaSDLWidget::try_create(sdl_window)))
+ {
+ m_window->resize(sdl_window->w, sdl_window->h);
+ m_window->set_resizable(false);
+ }
+
+ static MinervaPlatformWindow* from_sdl_window(SDL_Window* window)
+ {
+ return static_cast<MinervaPlatformWindow*>(window->driverdata);
+ }
+
+ MinervaGLContext* minerva_gl_context() { return m_minerva_gl_context; }
+ void set_minerva_gl_context(MinervaGLContext* minerva_gl_context) { m_minerva_gl_context = minerva_gl_context; }
+
+ NonnullRefPtr<GUI::Window> window() { return m_window; }
+ NonnullRefPtr<MinervaSDLWidget> widget() { return m_widget; }
+
+private:
+ MinervaGLContext* m_minerva_gl_context;
+ NonnullRefPtr<GUI::Window> m_window;
+ NonnullRefPtr<MinervaSDLWidget> m_widget;
+};
+
+#endif /* SDL_minervavideo_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */