[PATCH 0/1] MR10511: wineandroid: remove redundant backend DPI scaling
This removes manual DPI scaling from wineandroid.drv. Wine now appears to handle DPI and window sizing correctly on its own, and applying an additional scale factor in the Android backend results in double scaling. This leads to oversized windows and mismatched input coordinates. By dropping the backend scaling and relying directly on Wine-provided window sizes, rendering and input behavior become consistent. <details> <summary>Screenshots</summary> Before (double scaling): {width=708 height=600} After (correct scaling): {width=708 height=600} </details> -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10511
From: Twaik Yont <9674930+twaik@users.noreply.github.com> Remove manual scaling from wineandroid.drv. Wine now handles DPI and window sizing correctly, and applying an additional scale factor in the Android backend leads to double scaling and incorrect input coordinates. Rely on Wine-provided window sizes directly. Signed-off-by: Twaik Yont <9674930+twaik@users.noreply.github.com> --- dlls/wineandroid.drv/WineActivity.java | 47 ++++++++------------------ dlls/wineandroid.drv/android.h | 4 +-- dlls/wineandroid.drv/device.c | 16 ++++----- dlls/wineandroid.drv/window.c | 7 ++-- 4 files changed, 25 insertions(+), 49 deletions(-) diff --git a/dlls/wineandroid.drv/WineActivity.java b/dlls/wineandroid.drv/WineActivity.java index 2eee16b2dc1..fd73ff009bf 100644 --- a/dlls/wineandroid.drv/WineActivity.java +++ b/dlls/wineandroid.drv/WineActivity.java @@ -338,7 +338,6 @@ protected class WineWindow protected int hwnd; protected int owner; protected int style; - protected float scale; protected boolean visible; protected Rect visible_rect; protected Rect client_rect; @@ -351,7 +350,7 @@ protected class WineWindow protected WineWindowGroup window_group; protected WineWindowGroup client_group; - public WineWindow( int w, WineWindow parent, float scale ) + public WineWindow( int w, WineWindow parent ) { Log.i( LOGTAG, String.format( "create hwnd %08x", w )); hwnd = w; @@ -360,7 +359,6 @@ public WineWindow( int w, WineWindow parent, float scale ) visible = false; visible_rect = client_rect = new Rect( 0, 0, 0, 0 ); this.parent = parent; - this.scale = scale; children = new ArrayList<WineWindow>(); win_map.put( w, this ); if (parent != null) parent.children.add( this ); @@ -410,10 +408,7 @@ public void destroy_window_groups() public View create_whole_view() { if (window_group == null) create_window_groups(); - window_group.create_view( false ).layout( 0, 0, - Math.round( (visible_rect.right - visible_rect.left) * scale ), - Math.round( (visible_rect.bottom - visible_rect.top) * scale )); - window_group.set_scale( scale ); + window_group.create_view( false ).layout( 0, 0, visible_rect.right - visible_rect.left, visible_rect.bottom - visible_rect.top ); return window_group; } @@ -510,11 +505,10 @@ public void pos_changed( int flags, int insert_after, int owner, int style, client_rect.bottom - visible_rect.top ); } - public void set_parent( WineWindow new_parent, float scale ) + public void set_parent( WineWindow new_parent ) { Log.i( LOGTAG, String.format( "set parent hwnd %08x parent %08x -> %08x", hwnd, parent.hwnd, new_parent.hwnd )); - this.scale = scale; if (window_group != null) { if (visible) remove_view_from_parent(); @@ -572,8 +566,8 @@ else if (surftex != window_surftex) public void get_event_pos( MotionEvent event, int[] pos ) { - pos[0] = Math.round( event.getX() * scale + window_group.getLeft() ); - pos[1] = Math.round( event.getY() * scale + window_group.getTop() ); + pos[0] = Math.round( event.getX() + window_group.getLeft() ); + pos[1] = Math.round( event.getY() + window_group.getTop() ); } } @@ -596,10 +590,6 @@ protected class WineWindowGroup extends ViewGroup /* wrapper for layout() making sure that the view is not empty */ public void set_layout( int left, int top, int right, int bottom ) { - left *= win.scale; - top *= win.scale; - right *= win.scale; - bottom *= win.scale; if (right <= left + 1) right = left + 2; if (bottom <= top + 1) bottom = top + 2; layout( left, top, right, bottom ); @@ -611,15 +601,6 @@ protected void onLayout( boolean changed, int left, int top, int right, int bott if (content_view != null) content_view.layout( 0, 0, right - left, bottom - top ); } - public void set_scale( float scale ) - { - if (content_view == null) return; - content_view.setPivotX( 0 ); - content_view.setPivotY( 0 ); - content_view.setScaleX( scale ); - content_view.setScaleY( scale ); - } - public WineView create_view( boolean is_client ) { if (content_view != null) return content_view; @@ -765,7 +746,7 @@ protected class TopView extends ViewGroup public TopView( Context context ) { super( context ); - message_window = new WineWindow( WineWindow.HWND_MESSAGE, null, 1.0f ); + message_window = new WineWindow( WineWindow.HWND_MESSAGE, null ); message_window.create_window_groups(); } @@ -798,12 +779,12 @@ public void create_desktop_view() wine_config_changed( getResources().getConfiguration().densityDpi ); } - public void create_window( int hwnd, boolean is_desktop, boolean opengl, int parent, float scale, int pid ) + public void create_window( int hwnd, boolean is_desktop, boolean opengl, int parent, int pid ) { WineWindow win = get_window( hwnd ); if (win == null) { - win = new WineWindow( hwnd, is_desktop ? null : get_window( parent ), scale ); + win = new WineWindow( hwnd, is_desktop ? null : get_window( parent ) ); win.create_window_groups(); if (win.parent == desktop_window) win.create_whole_view(); if (is_desktop) @@ -822,11 +803,11 @@ public void destroy_window( int hwnd ) if (win != null) win.destroy(); } - public void set_window_parent( int hwnd, int parent, float scale, int pid ) + public void set_window_parent( int hwnd, int parent, int pid ) { WineWindow win = get_window( hwnd ); if (win == null) return; - win.set_parent( get_window( parent ), scale ); + win.set_parent( get_window( parent ) ); if (win.parent == desktop_window) win.create_whole_view(); } @@ -855,9 +836,9 @@ public void createDesktopView() runOnUiThread( new Runnable() { public void run() { create_desktop_view(); }} ); } - public void createWindow( final int hwnd, final boolean is_desktop, final boolean opengl, final int parent, final float scale, final int pid ) + public void createWindow( final int hwnd, final boolean is_desktop, final boolean opengl, final int parent, final int pid ) { - runOnUiThread( new Runnable() { public void run() { create_window( hwnd, is_desktop, opengl, parent, scale, pid ); }} ); + runOnUiThread( new Runnable() { public void run() { create_window( hwnd, is_desktop, opengl, parent, pid ); }} ); } public void destroyWindow( final int hwnd ) @@ -865,9 +846,9 @@ public void destroyWindow( final int hwnd ) runOnUiThread( new Runnable() { public void run() { destroy_window( hwnd ); }} ); } - public void setParent( final int hwnd, final int parent, final float scale, final int pid ) + public void setParent( final int hwnd, final int parent, final int pid ) { - runOnUiThread( new Runnable() { public void run() { set_window_parent( hwnd, parent, scale, pid ); }} ); + runOnUiThread( new Runnable() { public void run() { set_window_parent( hwnd, parent, pid ); }} ); } public void setCursor( final int id, final int width, final int height, diff --git a/dlls/wineandroid.drv/android.h b/dlls/wineandroid.drv/android.h index 16d60911174..1a0f5f751ba 100644 --- a/dlls/wineandroid.drv/android.h +++ b/dlls/wineandroid.drv/android.h @@ -62,13 +62,13 @@ extern UINT ANDROID_OpenGLInit( UINT version, const struct opengl_funcs *opengl_ extern void start_android_device(void); extern void register_native_window( HWND hwnd, struct ANativeWindow *win, BOOL client ); -extern struct ANativeWindow *create_ioctl_window( HWND hwnd, BOOL opengl, float scale ); +extern struct ANativeWindow *create_ioctl_window( HWND hwnd, BOOL opengl ); extern struct ANativeWindow *grab_ioctl_window( struct ANativeWindow *window ); extern void release_ioctl_window( struct ANativeWindow *window ); extern void destroy_ioctl_window( HWND hwnd, BOOL opengl ); extern int ioctl_window_pos_changed( HWND hwnd, const struct window_rects *rects, UINT style, UINT flags, HWND after, HWND owner ); -extern int ioctl_set_window_parent( HWND hwnd, HWND parent, float scale ); +extern int ioctl_set_window_parent( HWND hwnd, HWND parent ); extern int ioctl_set_capture( HWND hwnd ); extern int ioctl_set_cursor( int id, int width, int height, int hotspotx, int hotspoty, const unsigned int *bits ); diff --git a/dlls/wineandroid.drv/device.c b/dlls/wineandroid.drv/device.c index 8ae0172a57f..e55467b1066 100644 --- a/dlls/wineandroid.drv/device.c +++ b/dlls/wineandroid.drv/device.c @@ -131,7 +131,6 @@ struct ioctl_android_create_window { struct ioctl_header hdr; int parent; - float scale; BOOL is_desktop; }; @@ -204,7 +203,6 @@ struct ioctl_android_set_window_parent { struct ioctl_header hdr; int parent; - float scale; }; struct ioctl_android_set_capture @@ -745,10 +743,10 @@ static NTSTATUS createWindow_ioctl( void *data, DWORD in_size, DWORD out_size, U TRACE( "hwnd %08x opengl %u parent %08x\n", res->hdr.hwnd, res->hdr.opengl, res->parent ); - if (!(object = load_java_method( &method, "createWindow", "(IZZIFI)V" ))) return STATUS_NOT_SUPPORTED; + if (!(object = load_java_method( &method, "createWindow", "(IZZII)V" ))) return STATUS_NOT_SUPPORTED; wrap_java_call(); - (*jni_env)->CallVoidMethod( jni_env, object, method, res->hdr.hwnd, res->is_desktop, res->hdr.opengl, res->parent, res->scale, pid ); + (*jni_env)->CallVoidMethod( jni_env, object, method, res->hdr.hwnd, res->is_desktop, res->hdr.opengl, res->parent, pid ); unwrap_java_call(); return STATUS_SUCCESS; } @@ -1048,10 +1046,10 @@ static NTSTATUS setWindowParent_ioctl( void *data, DWORD in_size, DWORD out_size TRACE( "hwnd %08x parent %08x\n", res->hdr.hwnd, res->parent ); - if (!(object = load_java_method( &method, "setParent", "(IIFI)V" ))) return STATUS_NOT_SUPPORTED; + if (!(object = load_java_method( &method, "setParent", "(III)V" ))) return STATUS_NOT_SUPPORTED; wrap_java_call(); - (*jni_env)->CallVoidMethod( jni_env, object, method, res->hdr.hwnd, res->parent, res->scale, pid ); + (*jni_env)->CallVoidMethod( jni_env, object, method, res->hdr.hwnd, res->parent, pid ); unwrap_java_call(); return STATUS_SUCCESS; } @@ -1537,7 +1535,7 @@ static int perform( ANativeWindow *window, int operation, ... ) return android_ioctl( IOCTL_PERFORM, &perf, sizeof(perf), NULL, NULL ); } -struct ANativeWindow *create_ioctl_window( HWND hwnd, BOOL opengl, float scale ) +struct ANativeWindow *create_ioctl_window( HWND hwnd, BOOL opengl ) { struct ioctl_android_create_window req; struct native_win_wrapper *win = calloc( 1, sizeof(*win) ); @@ -1566,7 +1564,6 @@ struct ANativeWindow *create_ioctl_window( HWND hwnd, BOOL opengl, float scale ) req.hdr.hwnd = HandleToLong( win->hwnd ); req.hdr.opengl = win->opengl; req.parent = get_ioctl_win_parent( NtUserGetAncestor( hwnd, GA_PARENT )); - req.scale = scale; req.is_desktop = hwnd == desktop_window; android_ioctl( IOCTL_CREATE_WINDOW, &req, sizeof(req), NULL, NULL ); @@ -1621,14 +1618,13 @@ int ioctl_window_pos_changed( HWND hwnd, const struct window_rects *rects, return android_ioctl( IOCTL_WINDOW_POS_CHANGED, &req, sizeof(req), NULL, NULL ); } -int ioctl_set_window_parent( HWND hwnd, HWND parent, float scale ) +int ioctl_set_window_parent( HWND hwnd, HWND parent ) { struct ioctl_android_set_window_parent req; req.hdr.hwnd = HandleToLong( hwnd ); req.hdr.opengl = FALSE; req.parent = get_ioctl_win_parent( parent ); - req.scale = scale; return android_ioctl( IOCTL_SET_WINDOW_PARENT, &req, sizeof(req), NULL, NULL ); } diff --git a/dlls/wineandroid.drv/window.c b/dlls/wineandroid.drv/window.c index 41439c2f697..97eb3004ba8 100644 --- a/dlls/wineandroid.drv/window.c +++ b/dlls/wineandroid.drv/window.c @@ -99,8 +99,7 @@ static struct android_win_data *alloc_win_data( HWND hwnd ) if ((data = calloc( 1, sizeof(*data) ))) { data->hwnd = hwnd; - data->window = create_ioctl_window( hwnd, FALSE, - (float)NtUserGetWinMonitorDpi( hwnd, MDT_RAW_DPI ) / NtUserGetDpiForWindow( hwnd )); + data->window = create_ioctl_window( hwnd, FALSE ); pthread_mutex_lock( &win_data_mutex ); win_data_context[context_idx(hwnd)] = data; } @@ -1105,7 +1104,7 @@ void ANDROID_SetParent( HWND hwnd, HWND parent, HWND old_parent ) TRACE( "win %p parent %p -> %p\n", hwnd, old_parent, parent ); data->parent = (parent == NtUserGetDesktopWindow()) ? 0 : parent; - ioctl_set_window_parent( hwnd, parent, (float)NtUserGetWinMonitorDpi( hwnd, MDT_RAW_DPI ) / NtUserGetDpiForWindow( hwnd )); + ioctl_set_window_parent( hwnd, parent ); release_win_data( data ); } @@ -1214,7 +1213,7 @@ ANativeWindow *get_client_window( HWND hwnd ) ANativeWindow *client; if (!(data = get_win_data( hwnd ))) return NULL; - if (!data->client) data->client = create_ioctl_window( hwnd, TRUE, 1.0f ); + if (!data->client) data->client = create_ioctl_window( hwnd, TRUE ); client = grab_ioctl_window( data->client ); release_win_data( data ); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10511
participants (1)
-
Twaik Yont -
Twaik Yont (@twaik)