-
Notifications
You must be signed in to change notification settings - Fork 2.2k
HarmonyOS Port (Stage 2) #13064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
HarmonyOS Port (Stage 2) #13064
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fa8da8a
OpenHarmony port (log & thread)
Jack253-png 2859912
OpenHarmony port (action test)
Jack253-png b7fcd9b
OpenHarmony port (action test)
Jack253-png 9cb240f
OpenHarmony port (action test)
Jack253-png f10ec1a
OpenHarmony port (action test)
Jack253-png 7a214e8
OpenHarmony port (action test)
Jack253-png 8249547
OpenHarmony port (action test)
Jack253-png 307e48f
OpenHarmony port (action test)
Jack253-png 14d2bea
OpenHarmony port (action test)
Jack253-png 4cf4c58
OpenHarmony port (action test)
Jack253-png 4fc0897
OpenHarmony Port
Jack253-png 2713a02
OpenHarmony Port (Core registry)
Jack253-png bd2aa48
OpenHarmony Port (napi call)
Jack253-png 7ad39dd
OpenHarmony Port (mutex)
Jack253-png a253bef
OpenHarmony Port (video/vulkan)
Jack253-png d0e215b
OpenHarmony Port (video/vulkan)
Jack253-png bec7d94
OpenHarmony Port (video/vulkan)
Jack253-png 6908eda
OpenHarmony Port (video/vulkan)
Jack253-png 823b6ac
OpenHarmony Port (video/vulkan)
Jack253-png File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: 'Setup Harmony toolchain' | ||
inputs: | ||
version: | ||
description: 'Harmony version' | ||
default: '5.0.0-Release' | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- uses: actions/cache/restore@v4 | ||
id: restore-cache | ||
with: | ||
path: /opt/native | ||
key: harmony-${{ inputs.version }} | ||
|
||
- name: Download Harmony toolchain | ||
if: ${{ !steps.restore-cache.outputs.cache-hit }} | ||
shell: bash | ||
run: | | ||
wget https://repo.huaweicloud.com/openharmony/os/${{ inputs.version }}/ohos-sdk-windows_linux-public.tar.gz | ||
tar -zxvf ohos-sdk-windows_linux-public.tar.gz | ||
mkdir -p /opt | ||
|
||
unzip linux/native*.zip -d /opt | ||
- uses: actions/cache/save@v4 | ||
if: ${{ !steps.restore-cache.outputs.cache-hit }} | ||
with: | ||
path: /opt/native | ||
key: harmony-${{ inputs.version }} | ||
- name: 'Set output vars' | ||
id: final | ||
shell: bash | ||
run: | | ||
echo "HARMONY_NATIVE_SDK=/opt/native" >> $GITHUB_OUTPUT |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,10 @@ | |
#include <android/log.h> | ||
#endif | ||
|
||
#ifdef SDL_PLATFORM_OHOS | ||
#include <hilog/log.h> | ||
#endif | ||
|
||
#include "stdlib/SDL_vacopy.h" | ||
|
||
// The size of the stack buffer to use for rendering log messages. | ||
|
@@ -120,6 +124,18 @@ static int SDL_android_priority[] = { | |
SDL_COMPILE_TIME_ASSERT(android_priority, SDL_arraysize(SDL_android_priority) == SDL_LOG_PRIORITY_COUNT); | ||
#endif // SDL_PLATFORM_ANDROID | ||
|
||
#ifdef SDL_PLATFORM_OHOS | ||
static int SDL_ohos_priority[] = { | ||
LOG_DEBUG, | ||
LOG_DEBUG, | ||
LOG_DEBUG, | ||
LOG_INFO, | ||
LOG_WARN, | ||
LOG_ERROR, | ||
LOG_FATAL | ||
}; | ||
#endif | ||
|
||
static void SDLCALL SDL_LoggingChanged(void *userdata, const char *name, const char *oldValue, const char *hint) | ||
{ | ||
SDL_ResetLogPriorities(); | ||
|
@@ -569,6 +585,20 @@ static const char *GetCategoryPrefix(int category) | |
} | ||
#endif // SDL_PLATFORM_ANDROID | ||
|
||
#ifdef SDL_PLATFORM_OHOS | ||
static const char * | ||
GetCategoryPrefix(int category) | ||
Comment on lines
+589
to
+590
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can just re-use the Android category prefix helper function -> |
||
{ | ||
if (category < SDL_LOG_CATEGORY_RESERVED2) { | ||
return SDL_category_names[category]; | ||
} | ||
if (category < SDL_LOG_CATEGORY_CUSTOM) { | ||
return "RESERVED"; | ||
} | ||
return "CUSTOM"; | ||
} | ||
#endif | ||
|
||
void SDL_LogMessageV(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) | ||
{ | ||
char *message = NULL; | ||
|
@@ -751,6 +781,13 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority | |
SDL_snprintf(tag, SDL_arraysize(tag), "SDL/%s", GetCategoryPrefix(category)); | ||
__android_log_write(SDL_android_priority[priority], tag, message); | ||
} | ||
#elif defined(SDL_PLATFORM_OHOS) | ||
{ | ||
char tag[32]; | ||
|
||
SDL_snprintf(tag, SDL_arraysize(tag), "SDL/%s", GetCategoryPrefix(category)); | ||
OH_LOG_Print(LOG_APP, SDL_ohos_priority[priority], 0, tag, "%{public}s", message); | ||
} | ||
#elif defined(SDL_PLATFORM_APPLE) && (defined(SDL_VIDEO_DRIVER_COCOA) || defined(SDL_VIDEO_DRIVER_UIKIT)) | ||
/* Technically we don't need Cocoa/UIKit, but that's where this function is defined for now. | ||
*/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#include "SDL_ohos.h" | ||
#include "SDL_internal.h" | ||
|
||
#ifdef SDL_PLATFORM_OHOS | ||
|
||
#define OHOS_DELAY_FIFTY 50 | ||
#define OHOS_DELAY_TEN 10 | ||
#define OHOS_START_ARGS_INDEX 2 | ||
#define OHOS_INDEX_ARG0 0 | ||
#define OHOS_INDEX_ARG1 1 | ||
#define OHOS_INDEX_ARG2 2 | ||
#define OHOS_INDEX_ARG3 3 | ||
#define OHOS_INDEX_ARG4 4 | ||
#define OHOS_INDEX_ARG5 5 | ||
#define OHOS_INDEX_ARG6 6 | ||
|
||
#include "napi/native_api.h" | ||
#include <ace/xcomponent/native_interface_xcomponent.h> | ||
|
||
OHNativeWindow *nativeWindow; | ||
SDL_WindowData *windowData; | ||
SDL_DisplayOrientation displayOrientation; | ||
static OH_NativeXComponent_Callback callback; | ||
static OH_NativeXComponent_MouseEvent_Callback mouseCallback; | ||
|
||
void SDL_OHOS_SetDisplayOrientation(int orientation) | ||
{ | ||
displayOrientation = (SDL_DisplayOrientation)orientation; | ||
} | ||
|
||
SDL_DisplayOrientation SDL_OHOS_GetDisplayOrientation() | ||
{ | ||
return displayOrientation; | ||
} | ||
|
||
static napi_value add(napi_env env, napi_callback_info info) | ||
{ | ||
size_t argc = 2; | ||
napi_value args[2] = { NULL }; | ||
|
||
napi_get_cb_info(env, info, &argc, args, NULL, NULL); | ||
|
||
napi_valuetype valuetype0; | ||
napi_typeof(env, args[0], &valuetype0); | ||
|
||
napi_valuetype valuetype1; | ||
napi_typeof(env, args[1], &valuetype1); | ||
|
||
double value0; | ||
napi_get_value_double(env, args[0], &value0); | ||
|
||
double value1; | ||
napi_get_value_double(env, args[1], &value1); | ||
|
||
napi_value sum; | ||
napi_create_double(env, value0 + value1, &sum); | ||
|
||
return sum; | ||
} | ||
|
||
static void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window) | ||
{ | ||
nativeWindow = (OHNativeWindow *)window; | ||
} | ||
static void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window) {} | ||
static void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window) {} | ||
static void onKeyEvent(OH_NativeXComponent *component, void *window) {} | ||
static void onNativeTouch(OH_NativeXComponent *component, void *window) {} | ||
static void onNativeMouse(OH_NativeXComponent *component, void *window) {} | ||
static void OnDispatchTouchEventCB(OH_NativeXComponent *component, void *window) {} | ||
void OnHoverEvent(OH_NativeXComponent *component, bool isHover) {} | ||
void OnFocusEvent(OH_NativeXComponent *component, void *window) {} | ||
void OnBlurEvent(OH_NativeXComponent *component, void *window) {} | ||
|
||
static napi_value SDL_OHOS_NAPI_Init(napi_env env, napi_value exports) | ||
{ | ||
napi_property_descriptor desc[] = { | ||
{ "add", NULL, add, NULL, NULL, NULL, napi_default, NULL } | ||
}; | ||
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); | ||
|
||
napi_value exportInstance = NULL; | ||
if (napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance) != napi_ok) { | ||
return exports; | ||
} | ||
OH_NativeXComponent *nativeXComponent; | ||
if (napi_unwrap(env, exportInstance, (void **)(&nativeXComponent)) != napi_ok) { | ||
return exports; | ||
} | ||
|
||
callback.OnSurfaceCreated = OnSurfaceCreatedCB; | ||
callback.OnSurfaceChanged = OnSurfaceChangedCB; | ||
callback.OnSurfaceDestroyed = OnSurfaceDestroyedCB; | ||
callback.DispatchTouchEvent = onNativeTouch; | ||
OH_NativeXComponent_RegisterCallback(nativeXComponent, &callback); | ||
|
||
mouseCallback.DispatchMouseEvent = OnDispatchTouchEventCB; | ||
mouseCallback.DispatchMouseEvent = onNativeMouse; | ||
mouseCallback.DispatchHoverEvent = OnHoverEvent; | ||
OH_NativeXComponent_RegisterMouseEventCallback(nativeXComponent, &mouseCallback); | ||
|
||
OH_NativeXComponent_RegisterKeyEventCallback(nativeXComponent, onKeyEvent); | ||
OH_NativeXComponent_RegisterFocusEventCallback(nativeXComponent, OnFocusEvent); | ||
OH_NativeXComponent_RegisterBlurEventCallback(nativeXComponent, OnBlurEvent); | ||
|
||
return exports; | ||
} | ||
|
||
napi_module OHOS_NAPI_Module = { | ||
.nm_version = 1, | ||
.nm_flags = 0, | ||
.nm_filename = NULL, | ||
.nm_register_func = SDL_OHOS_NAPI_Init, | ||
.nm_modname = "SDL3", | ||
.nm_priv = ((void *)0), | ||
.reserved = { 0 }, | ||
}; | ||
|
||
__attribute__((constructor)) void RegisterEntryModule(void) | ||
{ | ||
napi_module_register(&OHOS_NAPI_Module); | ||
} | ||
|
||
#endif /* SDL_PLATFORM_OHOS */ | ||
|
||
/* vi: set ts=4 sw=4 expandtab: */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef SDL_OHOS_H | ||
#define SDL_OHOS_H | ||
|
||
#include "SDL3/SDL_mutex.h" | ||
#include "video/SDL_sysvideo.h" | ||
#include <native_window/external_window.h> | ||
|
||
void SDL_OHOS_SetDisplayOrientation(int orientation); | ||
SDL_DisplayOrientation SDL_OHOS_GetDisplayOrientation(); | ||
extern OHNativeWindow *nativeWindow; | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.