@@ -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+
202216void 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
303331void Android_SetWindowSafeAreaInsets (int left , int right , int top , int bottom )
0 commit comments