need to update sdl

This commit is contained in:
2026-04-02 14:12:41 +02:00
parent 848b199201
commit 4d16e1cb4f
2038 changed files with 0 additions and 1011118 deletions
-41
View File
@@ -1,41 +0,0 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 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 defined(SDL_VIDEO_DRIVER_VIVANTE) && defined(SDL_VIDEO_OPENGL_EGL)
#include "SDL_vivanteopengles.h"
#include "SDL_vivantevideo.h"
// EGL implementation of SDL OpenGL support
bool VIVANTE_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
{
SDL_DisplayData *displaydata = SDL_GetDisplayDriverData(SDL_GetPrimaryDisplay());
return SDL_EGL_LoadLibrary(_this, path, displaydata->native_display, 0);
}
SDL_EGL_CreateContext_impl(VIVANTE)
SDL_EGL_SwapWindow_impl(VIVANTE)
SDL_EGL_MakeCurrent_impl(VIVANTE)
#endif // SDL_VIDEO_DRIVER_VIVANTE && SDL_VIDEO_OPENGL_EGL
-46
View File
@@ -1,46 +0,0 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 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_vivanteopengles_h_
#define SDL_vivanteopengles_h_
#if defined(SDL_VIDEO_DRIVER_VIVANTE) && defined(SDL_VIDEO_OPENGL_EGL)
#include "../SDL_sysvideo.h"
#include "../SDL_egl_c.h"
// OpenGLES functions
#define VIVANTE_GLES_GetAttribute SDL_EGL_GetAttribute
#define VIVANTE_GLES_GetProcAddress SDL_EGL_GetProcAddressInternal
#define VIVANTE_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
#define VIVANTE_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
#define VIVANTE_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
#define VIVANTE_GLES_DestroyContext SDL_EGL_DestroyContext
extern bool VIVANTE_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path);
extern SDL_GLContext VIVANTE_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
extern bool VIVANTE_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern bool VIVANTE_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
#endif // SDL_VIDEO_DRIVER_VIVANTE && SDL_VIDEO_OPENGL_EGL
#endif // SDL_vivanteopengles_h_
-49
View File
@@ -1,49 +0,0 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 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"
#ifdef SDL_VIDEO_DRIVER_VIVANTE
#include "SDL_vivanteplatform.h"
#ifdef VIVANTE_PLATFORM_GENERIC
bool VIVANTE_SetupPlatform(SDL_VideoDevice *_this)
{
return true;
}
char *VIVANTE_GetDisplayName(SDL_VideoDevice *_this)
{
return NULL;
}
void VIVANTE_UpdateDisplayScale(SDL_VideoDevice *_this)
{
}
void VIVANTE_CleanupPlatform(SDL_VideoDevice *_this)
{
}
#endif // VIVANTE_PLATFORM_GENERIC
#endif // SDL_VIDEO_DRIVER_VIVANTE
-45
View File
@@ -1,45 +0,0 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 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_vivanteplatform_h_
#define SDL_vivanteplatform_h_
#ifdef SDL_VIDEO_DRIVER_VIVANTE
#include "SDL_vivantevideo.h"
#ifdef CAVIUM
#define VIVANTE_PLATFORM_CAVIUM
#elif defined(MARVELL)
#define VIVANTE_PLATFORM_MARVELL
#else
#define VIVANTE_PLATFORM_GENERIC
#endif
extern bool VIVANTE_SetupPlatform(SDL_VideoDevice *_this);
extern char *VIVANTE_GetDisplayName(SDL_VideoDevice *_this);
extern void VIVANTE_UpdateDisplayScale(SDL_VideoDevice *_this);
extern void VIVANTE_CleanupPlatform(SDL_VideoDevice *_this);
#endif // SDL_VIDEO_DRIVER_VIVANTE
#endif // SDL_vivanteplatform_h_
-363
View File
@@ -1,363 +0,0 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 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"
#ifdef SDL_VIDEO_DRIVER_VIVANTE
// SDL internals
#include "../SDL_sysvideo.h"
#include "../../events/SDL_events_c.h"
#ifdef SDL_INPUT_LINUXEV
#include "../../core/linux/SDL_evdev.h"
#endif
#include "SDL_vivantevideo.h"
#include "SDL_vivanteplatform.h"
#include "SDL_vivanteopengles.h"
#include "SDL_vivantevulkan.h"
static void VIVANTE_Destroy(SDL_VideoDevice *device)
{
SDL_free(device->internal);
SDL_free(device);
}
static SDL_VideoDevice *VIVANTE_Create(void)
{
SDL_VideoDevice *device;
SDL_VideoData *data;
// Initialize SDL_VideoDevice structure
device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice));
if (!device) {
return NULL;
}
// Initialize internal data
data = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData));
if (!data) {
SDL_free(device);
return NULL;
}
device->internal = data;
// Setup amount of available displays
device->num_displays = 0;
// Set device free function
device->free = VIVANTE_Destroy;
// Setup all functions which we can handle
device->VideoInit = VIVANTE_VideoInit;
device->VideoQuit = VIVANTE_VideoQuit;
device->CreateSDLWindow = VIVANTE_CreateWindow;
device->SetWindowTitle = VIVANTE_SetWindowTitle;
device->SetWindowPosition = VIVANTE_SetWindowPosition;
device->SetWindowSize = VIVANTE_SetWindowSize;
device->ShowWindow = VIVANTE_ShowWindow;
device->HideWindow = VIVANTE_HideWindow;
device->DestroyWindow = VIVANTE_DestroyWindow;
#ifdef SDL_VIDEO_OPENGL_EGL
device->GL_LoadLibrary = VIVANTE_GLES_LoadLibrary;
device->GL_GetProcAddress = VIVANTE_GLES_GetProcAddress;
device->GL_UnloadLibrary = VIVANTE_GLES_UnloadLibrary;
device->GL_CreateContext = VIVANTE_GLES_CreateContext;
device->GL_MakeCurrent = VIVANTE_GLES_MakeCurrent;
device->GL_SetSwapInterval = VIVANTE_GLES_SetSwapInterval;
device->GL_GetSwapInterval = VIVANTE_GLES_GetSwapInterval;
device->GL_SwapWindow = VIVANTE_GLES_SwapWindow;
device->GL_DestroyContext = VIVANTE_GLES_DestroyContext;
#endif
#ifdef SDL_VIDEO_VULKAN
device->Vulkan_LoadLibrary = VIVANTE_Vulkan_LoadLibrary;
device->Vulkan_UnloadLibrary = VIVANTE_Vulkan_UnloadLibrary;
device->Vulkan_GetInstanceExtensions = VIVANTE_Vulkan_GetInstanceExtensions;
device->Vulkan_CreateSurface = VIVANTE_Vulkan_CreateSurface;
device->Vulkan_DestroySurface = VIVANTE_Vulkan_DestroySurface;
#endif
device->PumpEvents = VIVANTE_PumpEvents;
return device;
}
VideoBootStrap VIVANTE_bootstrap = {
"vivante",
"Vivante EGL Video Driver",
VIVANTE_Create,
NULL, // no ShowMessageBox implementation
false
};
/*****************************************************************************/
// SDL Video and Display initialization/handling functions
/*****************************************************************************/
static bool VIVANTE_AddVideoDisplays(SDL_VideoDevice *_this)
{
SDL_VideoData *videodata = _this->internal;
SDL_VideoDisplay display;
SDL_DisplayMode mode;
SDL_DisplayData *data;
int pitch = 0, bpp = 0;
unsigned long pixels = 0;
data = (SDL_DisplayData *)SDL_calloc(1, sizeof(SDL_DisplayData));
if (!data) {
return false;
}
SDL_zero(mode);
#ifdef SDL_VIDEO_DRIVER_VIVANTE_VDK
data->native_display = vdkGetDisplay(videodata->vdk_private);
vdkGetDisplayInfo(data->native_display, &mode.w, &mode.h, &pixels, &pitch,
&bpp);
#else
data->native_display = videodata->fbGetDisplayByIndex(0);
videodata->fbGetDisplayInfo(data->native_display, &mode.w, &mode.h,
&pixels, &pitch, &bpp);
#endif // SDL_VIDEO_DRIVER_VIVANTE_VDK
switch (bpp) {
default: // Is another format used?
case 32:
mode.format = SDL_PIXELFORMAT_ARGB8888;
break;
case 16:
mode.format = SDL_PIXELFORMAT_RGB565;
break;
}
// FIXME: How do we query refresh rate?
mode.refresh_rate = 60.0f;
SDL_zero(display);
display.name = VIVANTE_GetDisplayName(_this);
display.desktop_mode = mode;
display.internal = data;
if (SDL_AddVideoDisplay(&display, false) == 0) {
return false;
}
return true;
}
bool VIVANTE_VideoInit(SDL_VideoDevice *_this)
{
SDL_VideoData *videodata = _this->internal;
#ifdef SDL_VIDEO_DRIVER_VIVANTE_VDK
videodata->vdk_private = vdkInitialize();
if (!videodata->vdk_private) {
return SDL_SetError("vdkInitialize() failed");
}
#else
videodata->egl_handle = SDL_LoadObject("libEGL.so.1");
if (!videodata->egl_handle) {
videodata->egl_handle = SDL_LoadObject("libEGL.so");
if (!videodata->egl_handle) {
return false;
}
}
#define LOAD_FUNC(TYPE, NAME) \
videodata->NAME = (TYPE)SDL_LoadFunction(videodata->egl_handle, #NAME); \
if (!videodata->NAME) \
return false;
LOAD_FUNC(EGLNativeDisplayType (EGLAPIENTRY *)(void *), fbGetDisplay);
LOAD_FUNC(EGLNativeDisplayType (EGLAPIENTRY *)(int), fbGetDisplayByIndex);
LOAD_FUNC(void (EGLAPIENTRY *)(EGLNativeDisplayType, int *, int *), fbGetDisplayGeometry);
LOAD_FUNC(void (EGLAPIENTRY *)(EGLNativeDisplayType, int *, int *, unsigned long *, int *, int *), fbGetDisplayInfo);
LOAD_FUNC(void (EGLAPIENTRY *)(EGLNativeDisplayType), fbDestroyDisplay);
LOAD_FUNC(EGLNativeWindowType (EGLAPIENTRY *)(EGLNativeDisplayType, int, int, int, int), fbCreateWindow);
LOAD_FUNC(void (EGLAPIENTRY *)(EGLNativeWindowType, int *, int *, int *, int *), fbGetWindowGeometry);
LOAD_FUNC(void (EGLAPIENTRY *)(EGLNativeWindowType, int *, int *, int *, int *, int *, unsigned int *), fbGetWindowInfo);
LOAD_FUNC(void (EGLAPIENTRY *)(EGLNativeWindowType), fbDestroyWindow);
#endif
if (!VIVANTE_SetupPlatform(_this)) {
return false;
}
if (!VIVANTE_AddVideoDisplays(_this)) {
return false;
}
VIVANTE_UpdateDisplayScale(_this);
#ifdef SDL_INPUT_LINUXEV
if (!SDL_EVDEV_Init()) {
return false;
}
#endif
return true;
}
void VIVANTE_VideoQuit(SDL_VideoDevice *_this)
{
SDL_VideoData *videodata = _this->internal;
#ifdef SDL_INPUT_LINUXEV
SDL_EVDEV_Quit();
#endif
VIVANTE_CleanupPlatform(_this);
#ifdef SDL_VIDEO_DRIVER_VIVANTE_VDK
if (videodata->vdk_private) {
vdkExit(videodata->vdk_private);
videodata->vdk_private = NULL;
}
#else
if (videodata->egl_handle) {
SDL_UnloadObject(videodata->egl_handle);
videodata->egl_handle = NULL;
}
#endif
}
bool VIVANTE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
SDL_VideoData *videodata = _this->internal;
SDL_DisplayData *displaydata;
SDL_WindowData *data;
displaydata = SDL_GetDisplayDriverData(SDL_GetPrimaryDisplay());
// Allocate window internal data
data = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData));
if (!data) {
return false;
}
// Setup driver data for this window
window->internal = data;
SDL_PropertiesID props = SDL_GetWindowProperties(window);
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_VIVANTE_DISPLAY_POINTER, displaydata->native_display);
#ifdef SDL_VIDEO_DRIVER_VIVANTE_VDK
data->native_window = vdkCreateWindow(displaydata->native_display, window->x, window->y, window->w, window->h);
#else
data->native_window = videodata->fbCreateWindow(displaydata->native_display, window->x, window->y, window->w, window->h);
#endif
if (!data->native_window) {
return SDL_SetError("VIVANTE: Can't create native window");
}
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_VIVANTE_WINDOW_POINTER, data->native_window);
#ifdef SDL_VIDEO_OPENGL_EGL
if (window->flags & SDL_WINDOW_OPENGL) {
data->egl_surface = SDL_EGL_CreateSurface(_this, window, data->native_window);
if (data->egl_surface == EGL_NO_SURFACE) {
return SDL_SetError("VIVANTE: Can't create EGL surface");
}
} else {
data->egl_surface = EGL_NO_SURFACE;
}
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_VIVANTE_SURFACE_POINTER, data->egl_surface);
#endif
// Window has been successfully created
return true;
}
void VIVANTE_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
SDL_VideoData *videodata = _this->internal;
SDL_WindowData *data;
data = window->internal;
if (data) {
#ifdef SDL_VIDEO_OPENGL_EGL
if (data->egl_surface != EGL_NO_SURFACE) {
SDL_EGL_DestroySurface(_this, data->egl_surface);
}
#endif
if (data->native_window) {
#ifdef SDL_VIDEO_DRIVER_VIVANTE_VDK
vdkDestroyWindow(data->native_window);
#else
videodata->fbDestroyWindow(data->native_window);
#endif
}
SDL_free(data);
}
window->internal = NULL;
}
void VIVANTE_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window)
{
#ifdef SDL_VIDEO_DRIVER_VIVANTE_VDK
SDL_WindowData *data = window->internal;
vdkSetWindowTitle(data->native_window, window->title);
#endif
}
bool VIVANTE_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
{
// FIXME
return SDL_Unsupported();
}
void VIVANTE_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
{
// FIXME
}
void VIVANTE_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
#ifdef SDL_VIDEO_DRIVER_VIVANTE_VDK
SDL_WindowData *data = window->internal;
vdkShowWindow(data->native_window);
#endif
SDL_SetMouseFocus(window);
SDL_SetKeyboardFocus(window);
}
void VIVANTE_HideWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
#ifdef SDL_VIDEO_DRIVER_VIVANTE_VDK
SDL_WindowData *data = window->internal;
vdkHideWindow(data->native_window);
#endif
SDL_SetMouseFocus(NULL);
SDL_SetKeyboardFocus(NULL);
}
/*****************************************************************************/
// SDL event functions
/*****************************************************************************/
void VIVANTE_PumpEvents(SDL_VideoDevice *_this)
{
#ifdef SDL_INPUT_LINUXEV
SDL_EVDEV_Poll();
#endif
}
#endif // SDL_VIDEO_DRIVER_VIVANTE
-86
View File
@@ -1,86 +0,0 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 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_vivantevideo_h_
#define SDL_vivantevideo_h_
#include "../SDL_sysvideo.h"
// Set up definitions for Vivante EGL
#include <SDL3/SDL_egl.h>
#ifdef SDL_VIDEO_DRIVER_VIVANTE_VDK
#include <gc_vdk.h>
#else
#include <EGL/egl.h>
#endif
struct SDL_VideoData
{
#ifdef SDL_VIDEO_DRIVER_VIVANTE_VDK
vdkPrivate vdk_private;
#else
SDL_SharedObject *egl_handle; // EGL shared library handle
EGLNativeDisplayType(EGLAPIENTRY *fbGetDisplay)(void *context);
EGLNativeDisplayType(EGLAPIENTRY *fbGetDisplayByIndex)(int DisplayIndex);
void(EGLAPIENTRY *fbGetDisplayGeometry)(EGLNativeDisplayType Display, int *Width, int *Height);
void(EGLAPIENTRY *fbGetDisplayInfo)(EGLNativeDisplayType Display, int *Width, int *Height, unsigned long *Physical, int *Stride, int *bits_per_pixel);
void(EGLAPIENTRY *fbDestroyDisplay)(EGLNativeDisplayType Display);
EGLNativeWindowType(EGLAPIENTRY *fbCreateWindow)(EGLNativeDisplayType Display, int X, int Y, int Width, int Height);
void(EGLAPIENTRY *fbGetWindowGeometry)(EGLNativeWindowType Window, int *X, int *Y, int *Width, int *Height);
void(EGLAPIENTRY *fbGetWindowInfo)(EGLNativeWindowType Window, int *X, int *Y, int *Width, int *Height, int *bits_per_pixel, unsigned int *Offset);
void(EGLAPIENTRY *fbDestroyWindow)(EGLNativeWindowType Window);
#endif
};
struct SDL_DisplayData
{
EGLNativeDisplayType native_display;
};
struct SDL_WindowData
{
EGLNativeWindowType native_window;
EGLSurface egl_surface;
};
/****************************************************************************/
// SDL_VideoDevice functions declaration
/****************************************************************************/
// Display and window functions
bool VIVANTE_VideoInit(SDL_VideoDevice *_this);
void VIVANTE_VideoQuit(SDL_VideoDevice *_this);
bool VIVANTE_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
bool VIVANTE_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
bool VIVANTE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
void VIVANTE_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
bool VIVANTE_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);
void VIVANTE_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);
void VIVANTE_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window);
void VIVANTE_HideWindow(SDL_VideoDevice *_this, SDL_Window *window);
void VIVANTE_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
// Event functions
void VIVANTE_PumpEvents(SDL_VideoDevice *_this);
#endif // SDL_vivantevideo_h_
-153
View File
@@ -1,153 +0,0 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 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"
/*
* @author Wladimir J. van der Laan. Based on Jacob Lifshay's
* SDL_x11vulkan.c, Mark Callow's SDL_androidvulkan.c, and
* the FSL demo framework.
*/
#if defined(SDL_VIDEO_VULKAN) && defined(SDL_VIDEO_DRIVER_VIVANTE)
#include "../SDL_vulkan_internal.h"
#include "SDL_vivantevideo.h"
#include "SDL_vivantevulkan.h"
bool VIVANTE_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
{
VkExtensionProperties *extensions = NULL;
Uint32 i, extensionCount = 0;
bool hasSurfaceExtension = false;
bool hasDisplayExtension = false;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
if (_this->vulkan_config.loader_handle) {
return SDL_SetError("Vulkan already loaded");
}
// Load the Vulkan loader library
if (!path) {
path = SDL_GetHint(SDL_HINT_VULKAN_LIBRARY);
}
if (!path) {
// If no path set, try Vivante fb vulkan driver explicitly
path = "libvulkan-fb.so";
_this->vulkan_config.loader_handle = SDL_LoadObject(path);
if (!_this->vulkan_config.loader_handle) {
// If that couldn't be loaded, fall back to default name
path = "libvulkan.so";
_this->vulkan_config.loader_handle = SDL_LoadObject(path);
}
} else {
_this->vulkan_config.loader_handle = SDL_LoadObject(path);
}
if (!_this->vulkan_config.loader_handle) {
return false;
}
SDL_strlcpy(_this->vulkan_config.loader_path, path,
SDL_arraysize(_this->vulkan_config.loader_path));
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vivante: Loaded vulkan driver %s", path);
vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
_this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
if (!vkGetInstanceProcAddr) {
goto fail;
}
_this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr;
_this->vulkan_config.vkEnumerateInstanceExtensionProperties =
(void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)(
VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
if (!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) {
goto fail;
}
extensions = SDL_Vulkan_CreateInstanceExtensionsList(
(PFN_vkEnumerateInstanceExtensionProperties)
_this->vulkan_config.vkEnumerateInstanceExtensionProperties,
&extensionCount);
if (!extensions) {
goto fail;
}
for (i = 0; i < extensionCount; i++) {
if (SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) {
hasSurfaceExtension = true;
} else if (SDL_strcmp(VK_KHR_DISPLAY_EXTENSION_NAME, extensions[i].extensionName) == 0) {
hasDisplayExtension = true;
}
}
SDL_free(extensions);
if (!hasSurfaceExtension) {
SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_SURFACE_EXTENSION_NAME " extension");
goto fail;
} else if (!hasDisplayExtension) {
SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_DISPLAY_EXTENSION_NAME "extension");
goto fail;
}
return true;
fail:
SDL_UnloadObject(_this->vulkan_config.loader_handle);
_this->vulkan_config.loader_handle = NULL;
return false;
}
void VIVANTE_Vulkan_UnloadLibrary(SDL_VideoDevice *_this)
{
if (_this->vulkan_config.loader_handle) {
SDL_UnloadObject(_this->vulkan_config.loader_handle);
_this->vulkan_config.loader_handle = NULL;
}
}
char const * const *VIVANTE_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, Uint32 *count)
{
static const char *const extensionsForVivante[] = {
VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_DISPLAY_EXTENSION_NAME
};
if (count) {
*count = SDL_arraysize(extensionsForVivante);
}
return extensionsForVivante;
}
bool VIVANTE_Vulkan_CreateSurface(SDL_VideoDevice *_this,
SDL_Window *window,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,
VkSurfaceKHR *surface)
{
if (!_this->vulkan_config.loader_handle) {
return SDL_SetError("Vulkan is not loaded");
}
return SDL_Vulkan_Display_CreateSurface(_this->vulkan_config.vkGetInstanceProcAddr, instance, allocator, surface);
}
void VIVANTE_Vulkan_DestroySurface(SDL_VideoDevice *_this,
VkInstance instance,
VkSurfaceKHR surface,
const struct VkAllocationCallbacks *allocator)
{
if (_this->vulkan_config.loader_handle) {
SDL_Vulkan_DestroySurface_Internal(_this->vulkan_config.vkGetInstanceProcAddr, instance, surface, allocator);
}
}
#endif
-51
View File
@@ -1,51 +0,0 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 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"
/*
* @author Wladimir J. van der Laan. Based on Jacob Lifshay's
* SDL_x11vulkan.h and Mark Callow's SDL_vivantevulkan.h
*/
#ifndef SDL_vivantevulkan_h_
#define SDL_vivantevulkan_h_
#include "../SDL_vulkan_internal.h"
#include "../SDL_sysvideo.h"
#if defined(SDL_VIDEO_VULKAN) && defined(SDL_VIDEO_DRIVER_VIVANTE)
extern bool VIVANTE_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path);
extern void VIVANTE_Vulkan_UnloadLibrary(SDL_VideoDevice *_this);
extern char const * const *VIVANTE_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, Uint32 *count);
extern bool VIVANTE_Vulkan_CreateSurface(SDL_VideoDevice *_this,
SDL_Window *window,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,
VkSurfaceKHR *surface);
extern void VIVANTE_Vulkan_DestroySurface(SDL_VideoDevice *_this,
VkInstance instance,
VkSurfaceKHR surface,
const struct VkAllocationCallbacks *allocator);
#endif
#endif // SDL_vivantevulkan_h_