Merge "Handle DPI on windows/linux." into main

GitOrigin-RevId: e19720a53a0be57ebe797376c4c45464375b7f8d
Change-Id: Ib3f2b3535fb3f6c5225c617bb551e1d9bab568c8
diff --git a/host/FrameBuffer.cpp b/host/FrameBuffer.cpp
index 54f78b9..61a3509 100644
--- a/host/FrameBuffer.cpp
+++ b/host/FrameBuffer.cpp
@@ -937,11 +937,11 @@
 
             if (m_displayVk) {
                 m_displaySurface =
-                    vk::createDisplaySurface(m_subWin, m_windowWidth, m_windowHeight);
+                    vk::createDisplaySurface(m_subWin, m_windowWidth * dpr, m_windowHeight * dpr);
             } else if (m_emulationGl) {
 #if GFXSTREAM_ENABLE_HOST_GLES
-                m_displaySurface = m_emulationGl->createWindowSurface(m_windowWidth,
-                                                                      m_windowHeight,
+                m_displaySurface = m_emulationGl->createWindowSurface(m_windowWidth * dpr,
+                                                                      m_windowHeight * dpr,
                                                                       m_subWin);
 #endif
             } else {
@@ -1004,9 +1004,9 @@
             {
                 auto watchdog = WATCHDOG_BUILDER(m_healthMonitor.get(), "Moving subwindow").build();
                 success = moveSubWindow(m_nativeWindow, m_subWin, m_x, m_y, m_windowWidth,
-                                        m_windowHeight);
+                                        m_windowHeight, dpr);
             }
-            m_displaySurface->updateSize(m_windowWidth, m_windowHeight);
+            m_displaySurface->updateSize(m_windowWidth * dpr, m_windowHeight * dpr);
         }
         // We are safe to unblock the PostWorker thread now, because we have completed all the
         // operations that could modify the state of the m_subWin. We need to unblock the PostWorker
diff --git a/host/NativeSubWindow.h b/host/NativeSubWindow.h
index aff117c..af79e07 100644
--- a/host/NativeSubWindow.h
+++ b/host/NativeSubWindow.h
@@ -67,7 +67,8 @@
                   int x,
                   int y,
                   int width,
-                  int height);
+                  int height,
+                  float dpr);
 
 #ifdef __cplusplus
 }
diff --git a/host/NativeSubWindow_android.cpp b/host/NativeSubWindow_android.cpp
index ec66154..12f148f 100644
--- a/host/NativeSubWindow_android.cpp
+++ b/host/NativeSubWindow_android.cpp
@@ -41,7 +41,8 @@
                   int x,
                   int y,
                   int width,
-                  int height) {
+                  int height,
+                  float dpr) {
     // moving windows not supported in Android; we can't create an actual sub window
     return true;
 }
diff --git a/host/NativeSubWindow_cocoa.m b/host/NativeSubWindow_cocoa.m
index 2b764fc..ac2c797 100644
--- a/host/NativeSubWindow_cocoa.m
+++ b/host/NativeSubWindow_cocoa.m
@@ -111,7 +111,8 @@
                   int x,
                   int y,
                   int width,
-                  int height) {
+                  int height,
+                  float dpr) {
     NSWindow *win = (NSWindow *)p_parent_window;
     if (!win) {
         return 0;
diff --git a/host/NativeSubWindow_qnx.cpp b/host/NativeSubWindow_qnx.cpp
index f983d32..1212863 100644
--- a/host/NativeSubWindow_qnx.cpp
+++ b/host/NativeSubWindow_qnx.cpp
@@ -116,7 +116,7 @@
 void destroySubWindow(EGLNativeWindowType win) { screen_destroy_window(win); }
 
 int moveSubWindow(FBNativeWindowType p_parent_window, EGLNativeWindowType p_sub_window, int x,
-                  int y, int width, int height) {
+                  int y, int width, int height, float dpr) {
     int pos[2] = {x, y};
     if (screen_set_window_property_iv(p_sub_window, SCREEN_PROPERTY_POSITION, pos)) {
         return 0;
diff --git a/host/NativeSubWindow_stub.cpp b/host/NativeSubWindow_stub.cpp
index 75a1ea8..b413a31 100644
--- a/host/NativeSubWindow_stub.cpp
+++ b/host/NativeSubWindow_stub.cpp
@@ -27,6 +27,6 @@
 void destroySubWindow(EGLNativeWindowType win) { return; }
 
 int moveSubWindow(FBNativeWindowType p_parent_window, EGLNativeWindowType p_sub_window, int x,
-                  int y, int width, int height) {
+                  int y, int width, int height, float dpr) {
     return 0;
 }
diff --git a/host/NativeSubWindow_win32.cpp b/host/NativeSubWindow_win32.cpp
index a5d7a1b..26ff662 100644
--- a/host/NativeSubWindow_win32.cpp
+++ b/host/NativeSubWindow_win32.cpp
@@ -15,6 +15,7 @@
 */
 #include "NativeSubWindow.h"
 
+#include <stdio.h>
 struct SubWindowUserData {
     SubWindowRepaintCallback repaint_callback;
     void* repaint_callback_param;
@@ -50,6 +51,12 @@
         RegisterClassA(&wc);
     }
 
+    // We assume size/pos are passed in as logical size/coordinates. Convert it to pixel
+    // coordinates.
+    x *= dpr;
+    y *= dpr;
+    width *= dpr;
+    height *= dpr;
     EGLNativeWindowType ret = CreateWindowExA(
                         WS_EX_NOPARENTNOTIFY,  // do not bother our parent window
                         className,
@@ -80,12 +87,13 @@
                   int x,
                   int y,
                   int width,
-                  int height) {
+                  int height,
+                  float dpr) {
     BOOL ret = MoveWindow(p_sub_window,
-                          x,
-                          y,
-                          width,
-                          height,
+                          x * dpr,
+                          y * dpr,
+                          width * dpr,
+                          height * dpr,
                           TRUE);
     return ret;
 }
diff --git a/host/NativeSubWindow_x11.cpp b/host/NativeSubWindow_x11.cpp
index 58f96fd..d660b3a 100644
--- a/host/NativeSubWindow_x11.cpp
+++ b/host/NativeSubWindow_x11.cpp
@@ -59,10 +59,10 @@
     wa.override_redirect = True;
     Window win = x11->XCreateWindow(s_display,
             p_window,
-            x,
-            y,
-            width,
-            height,
+            x * dpr,
+            y * dpr,
+            width * dpr,
+            height * dpr,
             0,
             CopyFromParent,
             CopyFromParent,
@@ -91,13 +91,19 @@
                   int x,
                   int y,
                   int width,
-                  int height) {
+                  int height,
+                  float dpr) {
     // This value is set during create, so if it is still null, simply
     // return because the global state is corrupted
     if (!s_display) {
         return false;
     }
 
+    x *= dpr;
+    y *= dpr;
+    width *= dpr;
+    height *= dpr;
+
     auto x11 = getX11Api();
 
     // Make sure something has changed, otherwise XIfEvent will block and