Skip to content

Commit 7b2cfdf

Browse files
committed
I have trust issues
1 parent c84ac2b commit 7b2cfdf

5 files changed

Lines changed: 55 additions & 4 deletions

File tree

‎project/lib/sdl/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,14 @@ public static boolean sendMessage(int command, int param) {
13421342
return mSingleton.sendCommand(command, param);
13431343
}
13441344

1345+
public static boolean isInMultiWindowModeJNI() {
1346+
if (mSingleton == null || !mHasMultiWindow) {
1347+
return false;
1348+
}
1349+
1350+
return mSingleton.isInMultiWindowMode();
1351+
}
1352+
13451353
/**
13461354
* This method is called by SDL using JNI.
13471355
*/

‎project/lib/sdl/src/video/SDL_video.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6037,6 +6037,10 @@ bool SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
60376037

60386038
SDL_ClearError();
60396039

6040+
#if SDL_PLATFORM_IOS
6041+
SDL_Log("SDL_ShowMessageBox: \"%s\" - \"%s\"", messageboxdata->title, messageboxdata->message);
6042+
#endif
6043+
60406044
if (_this && _this->ShowMessageBox) {
60416045
result = _this->ShowMessageBox(_this, messageboxdata, buttonID);
60426046
} else {

‎project/lib/sdl/src/video/android/SDL_androidvideo.c‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,20 @@ void Android_VideoQuit(SDL_VideoDevice *_this)
199199
Android_QuitTouch();
200200
}
201201

202+
float Android_GetDrawScale(void)
203+
{
204+
const char *scale_hint = SDL_GetHint("SDL_ANDROID_DRAW_SCALE");
205+
206+
float scale = scale_hint && !(Android_JNI_IsInMultiWindowMode() || SDL_IsDeXMode() || SDL_IsChromebook()) ? (float)atof(scale_hint) : 1.0;
207+
208+
return scale < 0.5 ? 0.5 : scale > 1.0 ? 1.0 : scale;
209+
}
210+
211+
bool Android_ShouldUseDrawScale(float scale)
212+
{
213+
return scale >= 0.5 && scale < 1.0 && !(Android_JNI_IsInMultiWindowMode() || SDL_IsDeXMode() || SDL_IsChromebook());
214+
}
215+
202216
void Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, float density, float rate)
203217
{
204218
Android_SurfaceWidth = surfaceWidth;
@@ -296,8 +310,22 @@ void Android_SendResize(SDL_Window *window)
296310
}
297311

298312
if (window) {
299-
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, Android_SurfaceWidth, Android_SurfaceHeight);
300-
}
313+
float scale = Android_GetDrawScale();
314+
SDL_WindowData *data = (SDL_WindowData *)window->internal;
315+
ANativeWindow* nw = (ANativeWindow*)data->native_window;
316+
int32_t format_wanted = ANativeWindow_getFormat(nw);
317+
318+
if (Android_ShouldUseDrawScale(scale))
319+
{
320+
ANativeWindow_setBuffersGeometry(nw, (int)(Android_SurfaceWidth * scale), (int)(Android_SurfaceHeight * scale), format_wanted);
321+
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, (int)(Android_SurfaceWidth * scale), (int)(Android_SurfaceHeight * scale));
322+
}
323+
else
324+
{
325+
ANativeWindow_setBuffersGeometry(nw, 0, 0, format_wanted);
326+
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, Android_SurfaceWidth, Android_SurfaceHeight);
327+
}
328+
}
301329
}
302330

303331
void Android_SetWindowSafeAreaInsets(int left, int right, int top, int bottom)

‎project/lib/sdl/src/video/android/SDL_androidvideo.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "../SDL_sysvideo.h"
2727

2828
// Called by the JNI layer when the screen changes size or format
29+
extern float Android_GetDrawScale();
30+
extern bool Android_ShouldUseDrawScale(float scale);
2931
extern void Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, float density, float rate);
3032
extern void Android_SetFormat(int format_wanted, int format_got);
3133
extern void Android_SetOrientation(SDL_DisplayOrientation orientation);

‎project/lib/sdl/src/video/android/SDL_androidwindow.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,20 @@ bool Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Proper
5353
// Set orientation
5454
Android_JNI_SetOrientation(window->w, window->h, window->flags & SDL_WINDOW_RESIZABLE, SDL_GetHint(SDL_HINT_ORIENTATIONS));
5555

56+
/* Adjust the resolution based on the configured draw scale */
57+
float scale = Android_GetDrawScale();
58+
5659
// Adjust the window data to match the screen
5760
window->x = 0;
5861
window->y = 0;
59-
window->w = Android_SurfaceWidth;
60-
window->h = Android_SurfaceHeight;
62+
63+
if (Android_ShouldUseDrawScale(scale)) {
64+
window->w = (int)(Android_SurfaceWidth * scale);
65+
window->h = (int)(Android_SurfaceHeight * scale);
66+
} else {
67+
window->w = Android_SurfaceWidth;
68+
window->h = Android_SurfaceHeight;
69+
}
6170

6271
// One window, it always has focus
6372
SDL_SetMouseFocus(window);

0 commit comments

Comments
 (0)