Skip to content

Commit d4039d3

Browse files
committed
Harmony port: entrypoint
1 parent 04e8042 commit d4039d3

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/core/ohos/SDL_ohos.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ void OHOS_UnlockPage()
139139
SDL_UnlockMutex(g_ohosPageMutex);
140140
}
141141

142+
int OHOS_FetchWidth()
143+
{
144+
return wid;
145+
}
146+
int OHOS_FetchHeight()
147+
{
148+
return hei;
149+
}
150+
142151
static napi_value minus(napi_env env, napi_callback_info info)
143152
{
144153
size_t argc = 2;

src/core/ohos/SDL_ohos.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ void OHOS_windowDataFill(SDL_Window* w);
1010
void OHOS_removeWindow(SDL_Window* w);
1111
void OHOS_LockPage();
1212
void OHOS_UnlockPage();
13+
int OHOS_FetchWidth();
14+
int OHOS_FetchHeight();
1315

1416
typedef struct SDL_VideoData {
1517
SDL_Rect textRect;

src/video/ohos/SDL_ohosvideo.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "SDL3/SDL_pixels.h"
2+
#include "SDL3/SDL_video.h"
13
#include "SDL_internal.h"
24
#include "../SDL_sysvideo.h"
35

@@ -9,6 +11,20 @@
911

1012
bool OHOS_VideoInit(SDL_VideoDevice *_this)
1113
{
14+
_this->num_displays = 1;
15+
SDL_DisplayMode mode;
16+
SDL_zero(mode);
17+
mode.format = SDL_PIXELFORMAT_RGBA32;
18+
mode.w = OHOS_FetchWidth();
19+
mode.h = OHOS_FetchHeight();
20+
mode.refresh_rate = 60;
21+
22+
SDL_DisplayID displayID = SDL_AddBasicVideoDisplay(&mode);
23+
if (displayID == 0) {
24+
return false;
25+
}
26+
_this->displays = SDL_calloc(1, sizeof(SDL_VideoDisplay*));
27+
_this->displays[0] = SDL_GetVideoDisplay(displayID);
1228
return true;
1329
}
1430
void OHOS_VideoQuit(SDL_VideoDevice *_this)
@@ -33,7 +49,6 @@ static SDL_VideoDevice *OHOS_CreateDevice(void)
3349
return NULL;
3450
}
3551

36-
device->num_displays = 1;
3752
device->internal = data;
3853
device->free = OHOS_DeviceFree;
3954

0 commit comments

Comments
 (0)