Skip to content

Commit cf5c6da

Browse files
committed
Harmony port: video vulkan library & disable version test
1 parent 83e1cf9 commit cf5c6da

File tree

6 files changed

+144
-1
lines changed

6 files changed

+144
-1
lines changed

.github/workflows/generic.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ jobs:
236236
${{ matrix.platform.source-cmd }}
237237
cmake --build build --config ${{ matrix.platform.cmake-build-type }} --verbose -- ${{ matrix.platform.cmake-build-arguments }}
238238
- name: 'Verify SDL_REVISION'
239-
if: ${{ !matrix.platform.no-cmake }}
239+
if: ${{ !matrix.platform.no-cmake && matrix.platform.platform != 'harmony' }}
240240
run: |
241241
echo "This should show us the SDL_REVISION"
242242
echo "Shared library:"

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,16 @@ elseif(OHOS)
15121512
sdl_link_dependency(OHOS_LIBS LIBS ace_napi.z hilog_ndk.z ace_ndk.z rawfile.z pixelmap_ndk.z)
15131513
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/core/ohos/*.c")
15141514

1515+
if(SDL_VIDEO)
1516+
set(SDL_VIDEO_DRIVER_OHOS 1)
1517+
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/ohos/*.c")
1518+
set(HAVE_SDL_VIDEO TRUE)
1519+
set(SDL_VULKAN ON)
1520+
set(HAVE_VULKAN ON)
1521+
set(SDL_VIDEO_VULKAN ON)
1522+
set(HAVE_RENDER_VULKAN TRUE)
1523+
endif()
1524+
15151525
set(SDL_LOADSO_DLOPEN 1)
15161526
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/loadso/dlopen/*.c")
15171527
set(HAVE_SDL_LOADSO TRUE)

src/video/SDL_sysvideo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ extern VideoBootStrap Emscripten_bootstrap;
542542
extern VideoBootStrap OFFSCREEN_bootstrap;
543543
extern VideoBootStrap QNX_bootstrap;
544544
extern VideoBootStrap OPENVR_bootstrap;
545+
extern VideoBootStrap OHOS_bootstrap;
545546

546547
extern bool SDL_UninitializedVideo(void);
547548
// Use SDL_OnVideoThread() sparingly, to avoid regressions in use cases that currently happen to work

src/video/ohos/SDL_ohosvideo.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "SDL_internal.h"
2+
#include "../SDL_sysvideo.h"
3+
4+
#ifdef SDL_VIDEO_DRIVER_OHOS
5+
#include "SDL_ohosvulkan.h"
6+
7+
bool OHOS_VideoInit(SDL_VideoDevice *_this)
8+
{
9+
return true;
10+
}
11+
void OHOS_VideoQuit(SDL_VideoDevice *_this)
12+
{
13+
}
14+
static SDL_VideoDevice *OHOS_CreateDevice(void)
15+
{
16+
SDL_VideoDevice *device;
17+
18+
device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice));
19+
if (!device) {
20+
return NULL;
21+
}
22+
23+
device->VideoInit = OHOS_VideoInit;
24+
device->VideoQuit = OHOS_VideoQuit;
25+
#ifdef SDL_VIDEO_VULKAN
26+
device->Vulkan_LoadLibrary = OHOS_Vulkan_LoadLibrary;
27+
device->Vulkan_UnloadLibrary = OHOS_Vulkan_UnloadLibrary;
28+
#endif
29+
30+
31+
return device;
32+
}
33+
VideoBootStrap OHOS_bootstrap = {
34+
"ohos", "OpenHarmony video driver",
35+
OHOS_CreateDevice,
36+
NULL,
37+
false
38+
};
39+
#endif

src/video/ohos/SDL_ohosvulkan.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include "SDL_ohosvulkan.h"
2+
#include "SDL_internal.h"
3+
#include "../khronos/vulkan/vulkan.h"
4+
5+
#ifdef SDL_VIDEO_DRIVER_OHOS
6+
7+
static int loadedCount = 0;
8+
bool OHOS_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
9+
{
10+
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
11+
if (_this->vulkan_config.loader_handle)
12+
{
13+
return SDL_SetError("Vulkan already loaded");
14+
}
15+
16+
/* Load the Vulkan loader library */
17+
if (!path)
18+
{
19+
path = SDL_getenv("SDL_VULKAN_LIBRARY");
20+
}
21+
if (!path)
22+
{
23+
path = "libvulkan.so";
24+
}
25+
_this->vulkan_config.loader_handle = SDL_LoadObject(path);
26+
if (!_this->vulkan_config.loader_handle)
27+
{
28+
return false;
29+
}
30+
SDL_strlcpy(_this->vulkan_config.loader_path, path,
31+
SDL_arraysize(_this->vulkan_config.loader_path));
32+
vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
33+
_this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
34+
if (!vkGetInstanceProcAddr)
35+
{
36+
goto fail;
37+
}
38+
_this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr;
39+
_this->vulkan_config.vkEnumerateInstanceExtensionProperties =
40+
(void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)(
41+
VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
42+
if (!_this->vulkan_config.vkEnumerateInstanceExtensionProperties)
43+
{
44+
goto fail;
45+
}
46+
loadedCount++;
47+
return true;
48+
49+
fail:
50+
SDL_UnloadObject(_this->vulkan_config.loader_handle);
51+
_this->vulkan_config.loader_handle = NULL;
52+
return false;
53+
}
54+
55+
void OHOS_Vulkan_UnloadLibrary(SDL_VideoDevice *_this)
56+
{
57+
if (loadedCount == 0)
58+
{
59+
return;
60+
}
61+
loadedCount--;
62+
if (_this->vulkan_config.loader_handle && loadedCount == 0) {
63+
SDL_UnloadObject(_this->vulkan_config.loader_handle);
64+
_this->vulkan_config.loader_handle = NULL;
65+
}
66+
}
67+
68+
/*bool OHOS_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, SDL_Window *window, unsigned *count,
69+
const char **names)
70+
{
71+
static const char *const extensionsForOHOS[] = {
72+
VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_OHOS_XCOMPONENT_EXTENSION_NAME
73+
};
74+
if (!_this->vulkan_config.loader_handle) {
75+
SDL_SetError("Vulkan is not loaded");
76+
return false;
77+
}
78+
return SDL_Vulkan_GetInstanceExtensions_Helper(
79+
count, names, SDL_arraysize(extensionsForOHOS), extensionsForOHOS);
80+
}*/
81+
82+
#endif

src/video/ohos/SDL_ohosvulkan.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef SDL_OHOSVULKAN_H
2+
#define SDL_OHOSVULKAN_H
3+
4+
#ifdef SDL_VIDEO_DRIVER_OHOS
5+
#include "../SDL_sysvideo.h"
6+
7+
bool OHOS_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path);
8+
void OHOS_Vulkan_UnloadLibrary(SDL_VideoDevice *_this);
9+
#endif
10+
11+
#endif

0 commit comments

Comments
 (0)