xserver: Branch 'wip/jeremyhu-debug-more-mainline' - 10 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jan 3 08:37:43 UTC 2023


Rebased ref, commits from common ancestor:
commit d531bb5a4a9b99a1391bcb2bf0516bc9a21c7678
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Wed Dec 14 23:46:42 2022 -0800

    XQuartz debugging
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    (cherry picked from commit 7ea888380aca2e681a4abc6f3266bf30dc7c1ea1)

diff --git a/fb/fbpict.c b/fb/fbpict.c
index 9797447b4..2b50d88be 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -290,6 +290,13 @@ create_bits_picture(PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
     fbGetDrawablePixmap(pict->pDrawable, pixmap, *xoff, *yoff);
     fbGetPixmapBitsData(pixmap, bits, stride, bpp);
 
+    ErrorF("=== create_bits_picture ===\n");
+    xorg_backtrace();
+
+    ErrorF("    fbGetDrawable: pDrawable %p (%d,%d %dx%d): bits base: %p stride: %u bpp: %d xoff: %d yoff: %d\n",
+           pict->pDrawable, pict->pDrawable->x, pict->pDrawable->y, pict->pDrawable->width, pict->pDrawable->height,
+           bits, stride, bpp, *xoff, *yoff);
+
     image = pixman_image_create_bits((pixman_format_code_t) pict->format,
                                      pixmap->drawable.width,
                                      pixmap->drawable.height, (uint32_t *) bits,
diff --git a/fb/fbscreen.c b/fb/fbscreen.c
index 4ab807ab5..e698f5288 100644
--- a/fb/fbscreen.c
+++ b/fb/fbscreen.c
@@ -26,6 +26,8 @@
 
 #include "fb.h"
 
+extern unsigned long RootlessWID(WindowPtr pWindow);
+
 Bool
 fbCloseScreen(ScreenPtr pScreen)
 {
@@ -87,6 +89,12 @@ _fbGetWindowPixmap(WindowPtr pWindow)
 void
 _fbSetWindowPixmap(WindowPtr pWindow, PixmapPtr pPixmap)
 {
+    ErrorF("_fbSetWindowPixmap: window=%p (%lu) pixmap=%p bits=%p (%d,%d %dx%d %d)\n",
+           pWindow, RootlessWID(pWindow), pPixmap, pPixmap->devPrivate.ptr,
+           pPixmap->drawable.x, pPixmap->drawable.y, pPixmap->drawable.width,
+           pPixmap->drawable.height, pPixmap->drawable.bitsPerPixel);
+
+    xorg_backtrace();
     dixSetPrivate(&pWindow->devPrivates, fbGetWinPrivateKey(pWindow), pPixmap);
 }
 
diff --git a/hw/xquartz/bundle/X11.sh b/hw/xquartz/bundle/X11.sh
index 3b8b6799c..3b314a159 100755
--- a/hw/xquartz/bundle/X11.sh
+++ b/hw/xquartz/bundle/X11.sh
@@ -2,10 +2,23 @@
 
 set "$(dirname "$0")"/X11.bin "${@}"
 
+if [ ! -f "${HOME}/Library/Preferences/org.xquartz.X11.plist" ] ; then
+    # Try migrating preferences
+    if [ -f "${HOME}/Library/Preferences/org.macosforge.xquartz.X11.plist" ] ; then
+        cp "${HOME}/Library/Preferences/org.macosforge.xquartz.X11.plist" "${HOME}/Library/Preferences/org.xquartz.X11.plist"
+    elif [ -f "${HOME}/Library/Preferences/org.x.X11.plist" ] ; then
+        cp "${HOME}/Library/Preferences/org.x.X11.plist" "${HOME}/Library/Preferences/org.xquartz.X11.plist"
+    elif [ -f "${HOME}/Library/Preferences/com.apple.X11.plist" ] ; then
+        cp "${HOME}/Library/Preferences/com.apple.X11.plist" "${HOME}/Library/Preferences/org.xquartz.X11.plist"
+    fi
+fi
+
 if [ -x ~/.x11run ]; then
 	exec ~/.x11run "${@}"
 fi
 
+export DYLD_LIBRARY_PATH=/tmp/Xplugin.dst/usr/lib
+
 case $(basename "${SHELL}") in
 	bash)          exec -l "${SHELL}" --login -c 'exec "${@}"' - "${@}" ;;
 	ksh|sh|zsh)    exec -l "${SHELL}" -c 'exec "${@}"' - "${@}" ;;
diff --git a/hw/xquartz/xpr/xprAppleWM.c b/hw/xquartz/xpr/xprAppleWM.c
index 126661766..cdcf465f9 100644
--- a/hw/xquartz/xpr/xprAppleWM.c
+++ b/hw/xquartz/xpr/xprAppleWM.c
@@ -129,6 +129,9 @@ xprFrameDraw(WindowPtr pWin,
     if (wid == 0)
         return BadWindow;
 
+     ErrorF("=== xp_frame_draw %d ===\n", (int)x_cvt_vptr_to_uint(wid));
+     xorg_backtrace();
+
     if (xp_frame_draw(wid, class, attr, outer, inner,
                       title_len, title_bytes) != Success) {
         return BadValue;
diff --git a/hw/xquartz/xpr/xprFrame.c b/hw/xquartz/xpr/xprFrame.c
index 57d16d42f..300604766 100644
--- a/hw/xquartz/xpr/xprFrame.c
+++ b/hw/xquartz/xpr/xprFrame.c
@@ -45,6 +45,8 @@
 
 #include <dispatch/dispatch.h>
 
+#define DEBUG_XP_LOCK_WINDOW 1
+
 #define DEFINE_ATOM_HELPER(func, atom_name)                      \
     static Atom func(void) {                                       \
         static int generation;                                      \
@@ -353,15 +355,20 @@ xprStartDrawing(RootlessFrameID wid, char **pixelData, int *bytesPerRow)
     xorg_backtrace();
 #endif
 
-    err = xp_lock_window(x_cvt_vptr_to_uint(
-                             wid), NULL, NULL, data, rowbytes, NULL);
+    xp_box out_box;
+    err = xp_lock_window(x_cvt_vptr_to_uint(wid), NULL, NULL, data, rowbytes, &out_box);
     if (err != Success)
         FatalError("Could not lock window %d for drawing (%d).",
-                   (int)x_cvt_vptr_to_uint(
-                       wid), (int)err);
+                   (int)x_cvt_vptr_to_uint(wid), (int)err);
 
 #ifdef DEBUG_XP_LOCK_WINDOW
-    ErrorF("  bits: %p\n", *data);
+    ErrorF("  bits: %p box: (%d,%d %d,%d) rowbytes: %u\n", *data, (int)out_box.x1, (int)out_box.y1, (int)out_box.x2, (int)out_box.y2, *rowbytes);
+    char *bytes = *data;
+    ErrorF("  bytes[0] = %d\n", bytes[0]);
+
+    int size = (out_box.y2 - out_box.y1) * (*rowbytes);
+    ErrorF("  size = %d\n", size);
+    ErrorF("  bytes[%d] = %d\n", size-1, bytes[size-1]);
 #endif
 
     *pixelData = data[0];
diff --git a/include/meson.build b/include/meson.build
index 6c1c1dcd4..49d4e8bc2 100644
--- a/include/meson.build
+++ b/include/meson.build
@@ -33,6 +33,9 @@ cc.compiles('''
     #ifndef CLOCK_MONOTONIC
     #error CLOCK_MONOTONIC not defined
     #endif
+    #ifdef __x86_64__
+    #error "x86_64 needs to support 10.9+, so disabling"
+    #endif
 ''',
     name: 'CLOCK_MONOTONIC') ? '1' : false)
 
@@ -150,7 +153,14 @@ conf_data.set('HAVE_GETPEERUCRED', cc.has_function('getpeerucred') ? '1' : false
 conf_data.set('HAVE_GETPROGNAME', cc.has_function('getprogname') ? '1' : false)
 conf_data.set('HAVE_GETZONEID', cc.has_function('getzoneid') ? '1' : false)
 conf_data.set('HAVE_MEMFD_CREATE', cc.has_function('memfd_create') ? '1' : false)
-conf_data.set('HAVE_MKOSTEMP', cc.has_function('mkostemp') ? '1' : false)
+#conf_data.set('HAVE_MKOSTEMP', cc.has_function('mkostemp') ? '1' : false)
+conf_data.set('HAVE_MKOSTEMP', cc.has_function('mkostemp') and
+cc.compiles('''
+    #ifdef __x86_64__
+    #error "x86_64 needs to support 10.9+, so disabling"
+    #endif
+''',
+    name: 'HAVE_MKOSTEMP') ? '1' : false)
 conf_data.set('HAVE_MMAP', cc.has_function('mmap') ? '1' : false)
 conf_data.set('HAVE_OPEN_DEVICE', cc.has_function('open_device') ? '1' : false)
 conf_data.set('HAVE_POLL', cc.has_function('poll') ? '1' : false)
diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index 48e6af673..20a27557b 100644
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -41,6 +41,8 @@
 #include    "damage.h"
 #include    "damagestr.h"
 
+extern unsigned long RootlessWID(WindowPtr pWindow);
+
 #define wrap(priv, real, mem, func) {\
     priv->mem = real->mem; \
     real->mem = func; \
@@ -1550,10 +1552,20 @@ damageSetWindowPixmap(WindowPtr pWindow, PixmapPtr pPixmap)
     DamagePtr pDamage;
     ScreenPtr pScreen = pWindow->drawable.pScreen;
 
+    ErrorF("damageSetWindowPixmap(%p %lu, %p %p) (%d,%d %dx%d %d)\n",
+           pWindow, RootlessWID(pWindow), pPixmap, pPixmap->devPrivate.ptr,
+           pPixmap->drawable.x, pPixmap->drawable.y, pPixmap->drawable.width,
+           pPixmap->drawable.height, pPixmap->drawable.bitsPerPixel);
+
     damageScrPriv(pScreen);
 
     if ((pDamage = damageGetWinPriv(pWindow))) {
         PixmapPtr pOldPixmap = (*pScreen->GetWindowPixmap) (pWindow);
+
+        ErrorF("pOldPixmap: %p %p (%d,%d %dx%d %d)\n", pOldPixmap, pOldPixmap->devPrivate.ptr,
+               pOldPixmap->drawable.x, pOldPixmap->drawable.y, pOldPixmap->drawable.width,
+               pOldPixmap->drawable.height, pOldPixmap->drawable.bitsPerPixel);
+
         DamagePtr *pPrev = getPixmapDamageRef(pOldPixmap);
 
         while (pDamage) {
diff --git a/miext/rootless/rootlessCommon.c b/miext/rootless/rootlessCommon.c
index 44c2c3789..5c3b94e86 100644
--- a/miext/rootless/rootlessCommon.c
+++ b/miext/rootless/rootlessCommon.c
@@ -188,22 +188,33 @@ RootlessStartDrawing(WindowPtr pWindow)
                                    top->drawable.bitsPerPixel,
                                    winRec->bytesPerRow, winRec->pixelData);
 
-        RL_DEBUG_MSG("GetScratchPixmapHeader gave us %p %p (%d,%d %dx%d %d) for wid=%lu\n",
-                     winRec->pixmap, winRec->pixmap->devPrivate.ptr, winRec->pixmap->drawable.x,
-                     winRec->pixmap->drawable.y, winRec->pixmap->drawable.width, winRec->pixmap->drawable.height,
-                     winRec->pixmap->drawable.bitsPerPixel, RootlessWID(pWindow));
+//        RL_DEBUG_MSG("GetScratchPixmapHeader gave us pixmap=%p bits=%p (drawable: %d,%d @ %d,%d %dx%d %d bpp) for window=%p (%d,%d %dx%d) wid=%lu (winrec: %dx%d))\n",
+//                     winRec->pixmap, winRec->pixmap->devPrivate.ptr, winRec->pixmap->drawable.x,
+//                     winRec->pixmap->drawable.y, winRec->pixmap->drawable.screen_x, winRec->pixmap->drawable.screen_y,
+//                     winRec->pixmap->drawable.width, winRec->pixmap->drawable.height, winRec->pixmap->drawable.bitsPerPixel,
+//                     pWindow->drawable.x, pWindow->drawable.y, pWindow->drawable.width, pWindow->drawable.height,
+//                     RootlessWID(pWindow), winRec->width, winRec->height);
 
         SetPixmapBaseToScreen(winRec->pixmap,
                               top->drawable.x - bw, top->drawable.y - bw);
 
-        RL_DEBUG_MSG("After SetPixmapBaseToScreen(%d %d %d): %p (%d,%d %dx%d %d) for wid=%lu\n",
-                     top->drawable.x, top->drawable.y, bw, winRec->pixmap->devPrivate.ptr, winRec->pixmap->drawable.x,
-                     winRec->pixmap->drawable.y, winRec->pixmap->drawable.width, winRec->pixmap->drawable.height,
-                     winRec->pixmap->drawable.bitsPerPixel, RootlessWID(pWindow));
+        RL_DEBUG_MSG("After GetScratchPixmapHeader + SetPixmapBaseToScreen(x:%d y:%d bw: %d): pixmap=%p (@ %d,%d) bits=%p (drawable: %d,%d %dx%d %d bpp) for window=%p (drawable: %d,%d %dx%d) wid=%lu (winrec: %dx%d))\n",
+                     top->drawable.x, top->drawable.y, bw,
+                     winRec->pixmap, winRec->pixmap->screen_x, winRec->pixmap->screen_y,
+                     winRec->pixmap->devPrivate.ptr, winRec->pixmap->drawable.x, winRec->pixmap->drawable.y,
+                     winRec->pixmap->drawable.width, winRec->pixmap->drawable.height, winRec->pixmap->drawable.bitsPerPixel,
+                     pWindow, pWindow->drawable.x, pWindow->drawable.y, pWindow->drawable.width, pWindow->drawable.height,
+                     RootlessWID(pWindow), winRec->width, winRec->height);
 
         winRec->is_drawing = TRUE;
     } else {
-        RL_DEBUG_MSG("Skipped call to xprStartDrawing (wid: %lu) because winRec->is_drawing says we already did.\n", RootlessWID(pWindow));
+        RL_DEBUG_MSG("Skipped call to xprStartDrawing (wid: %lu) because winRec->is_drawing says we already did. pixmap=%p (@ %d,%d) bits=%p (drawable: %d,%d %dx%d %d bpp) for window=%p (%d,%d %dx%d) wid=%lu (winrec: %dx%d))\n",
+                     RootlessWID(pWindow),
+                     winRec->pixmap, winRec->pixmap->screen_x, winRec->pixmap->screen_y,
+                     winRec->pixmap->devPrivate.ptr, winRec->pixmap->drawable.x, winRec->pixmap->drawable.y,
+                     winRec->pixmap->drawable.width, winRec->pixmap->drawable.height, winRec->pixmap->drawable.bitsPerPixel,
+                     pWindow, pWindow->drawable.x, pWindow->drawable.y, pWindow->drawable.width, pWindow->drawable.height,
+                     RootlessWID(pWindow), winRec->width, winRec->height);
     }
 
     curPixmap = pScreen->GetWindowPixmap(pWindow);
diff --git a/miext/rootless/rootlessConfig.h b/miext/rootless/rootlessConfig.h
index 80c2f6d8a..1d8b4abdf 100644
--- a/miext/rootless/rootlessConfig.h
+++ b/miext/rootless/rootlessConfig.h
@@ -34,7 +34,7 @@
 #ifndef _ROOTLESSCONFIG_H
 #define _ROOTLESSCONFIG_H
 
-/*# define ROOTLESSDEBUG*/
+#define ROOTLESSDEBUG
 
 #define ROOTLESS_PROTECT_ALPHA TRUE
 #define ROOTLESS_REDISPLAY_DELAY 10
diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index 4b8a5b077..fe0b39c2f 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -803,9 +803,8 @@ StartFrameResize(WindowPtr pWin, Bool gravity,
     rect.x2 = min(oldX2, newX2);
     rect.y2 = min(oldY2, newY2);
 
-    RL_DEBUG_MSG("RESIZE TOPLEVEL WINDOW with gravity %i ", gravity);
-    RL_DEBUG_MSG("%d %d %d %d %d   %d %d %d %d %d\n",
-                 oldX, oldY, oldW, oldH, oldBW, newX, newY, newW, newH, newBW);
+    RL_DEBUG_MSG("RESIZE TOPLEVEL WINDOW with gravity %i %d,%d %dx%d bw:%d -> %d,%d %dx%d bw:%d\n",
+                 gravity, oldX, oldY, oldW, oldH, oldBW, newX, newY, newW, newH, newBW);
 
     RootlessRedisplay(pWin);
 
commit c57acd92d58ef8a6aaabe23ea9f83e39930d091c
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Tue Jun 14 11:03:31 2022 -0700

    Revert "os/WaitFor: Check timers on every iteration"
    
    Workaround a performance issue that this introduces in XQuartz
    
    Fixes: https://github.com/XQuartz/XQuartz/issues/166
    This reverts commit ac7a4bf44c68c5f323375974b208d4530fb5b60f.
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/os/WaitFor.c b/os/WaitFor.c
index ff1d376e9..8f93845e0 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -192,11 +192,12 @@ WaitForSomething(Bool are_ready)
             ProcessWorkQueue();
         }
 
-        timeout = check_timers();
         are_ready = clients_are_ready();
 
         if (are_ready)
             timeout = 0;
+        else
+            timeout = check_timers();
 
         BlockHandler(&timeout);
         if (NewOutputPending)
commit 8f8d6c1a70be6b46142d19fbc8c395a8dcbdb401
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sun Sep 11 02:19:19 2016 -0700

    randr: Initialize RandR even if there are currently no screens attached
    
    Failure to do so causes an overvlow in RRClientCallback().
    
    =================================================================
    ==41262==ERROR: AddressSanitizer: global-buffer-overflow on address 0x000103ccfbc8 at pc 0x0001034f32b9 bp 0x7000035a94c0 sp 0x7000035a94b8
    WRITE of size 4 at 0x000103ccfbc8 thread T6
        #0 0x1034f32b8 in RRClientCallback randr.c:72
        #1 0x1038c75e3 in _CallCallbacks dixutils.c:737
        #2 0x10388f406 in CallCallbacks callback.h:83
        #3 0x1038bc49a in NextAvailableClient dispatch.c:3562
        #4 0x103ad094c in AllocNewConnection connection.c:777
        #5 0x103ad1695 in EstablishNewConnections connection.c:863
        #6 0x1038c6630 in ProcessWorkQueue dixutils.c:523
        #7 0x103ab2dbf in WaitForSomething WaitFor.c:175
        #8 0x103880836 in Dispatch dispatch.c:411
        #9 0x1038c2141 in dix_main main.c:301
        #10 0x1032ac75a in server_thread quartzStartup.c:66
        #11 0x7fffc5f16aaa in _pthread_body (libsystem_pthread.dylib+0x3aaa)
        #12 0x7fffc5f169f6 in _pthread_start (libsystem_pthread.dylib+0x39f6)
        #13 0x7fffc5f161fc in thread_start (libsystem_pthread.dylib+0x31fc)
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    (cherry picked from commit f9235000d67a61b0de951598146b4b5e0032384e)

diff --git a/randr/randr.c b/randr/randr.c
index 6d02c2577..a8e4d1514 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -414,9 +414,6 @@ RRExtensionInit(void)
 {
     ExtensionEntry *extEntry;
 
-    if (RRNScreens == 0)
-        return;
-
     if (!dixRegisterPrivateKey(&RRClientPrivateKeyRec, PRIVATE_CLIENT,
                                sizeof(RRClientRec) +
                                screenInfo.numScreens * sizeof(RRTimesRec)))
commit 6a005c775856ea3491ee4eb336062f5bc0bcd607
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sun Sep 11 02:47:00 2016 -0700

    glx: Initialize glx even if there are currently no screens attached
    
    Failure to do so causes an overvlow in glxClientCallback
    
    Application Specific Information:
    X.Org X Server 1.18.99.1 Build Date: 20160911
    =================================================================
    ==52118==ERROR: AddressSanitizer: SEGV on unknown address 0x000102b27b80 (pc 0x000103433245 bp 0x70000de67c20 sp 0x70000de67c00 T6)
        #0 0x103433244 in __asan::asan_free(void*, __sanitizer::BufferedStackTrace*, __asan::AllocType) (libclang_rt.asan_osx_dynamic.dylib+0x3244)
        #1 0x10347aeee in wrap_free (libclang_rt.asan_osx_dynamic.dylib+0x4aeee)
        #2 0x102e6a5ed in glxClientCallback glxext.c:301
        #3 0x102b672a3 in _CallCallbacks dixutils.c:737
        #4 0x102b2f0c6 in CallCallbacks callback.h:83
        #5 0x102b5c15a in NextAvailableClient dispatch.c:3562
        #6 0x102d7060c in AllocNewConnection connection.c:777
        #7 0x102d71355 in EstablishNewConnections connection.c:863
        #8 0x102b662f0 in ProcessWorkQueue dixutils.c:523
        #9 0x102d52a7f in WaitForSomething WaitFor.c:175
        #10 0x102b204f6 in Dispatch dispatch.c:411
        #11 0x102b61e01 in dix_main main.c:301
        #12 0x10254c42a in server_thread quartzStartup.c:66
        #13 0x7fffc5f16aaa in _pthread_body (libsystem_pthread.dylib+0x3aaa)
        #14 0x7fffc5f169f6 in _pthread_start (libsystem_pthread.dylib+0x39f6)
        #15 0x7fffc5f161fc in thread_start (libsystem_pthread.dylib+0x31fc)
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    (cherry picked from commit 1d2293101fca46c9a68c553f1be8e815c40de69a)

diff --git a/glx/glxext.c b/glx/glxext.c
index 99f866104..9a0493388 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -281,24 +281,6 @@ GlxPushProvider(__GLXprovider * provider)
     __glXProviderStack = provider;
 }
 
-static Bool
-checkScreenVisuals(void)
-{
-    int i, j;
-
-    for (i = 0; i < screenInfo.numScreens; i++) {
-        ScreenPtr screen = screenInfo.screens[i];
-        for (j = 0; j < screen->numVisuals; j++) {
-            if ((screen->visuals[j].class == TrueColor ||
-                 screen->visuals[j].class == DirectColor) &&
-                screen->visuals[j].nplanes > 12)
-                return TRUE;
-        }
-    }
-
-    return FALSE;
-}
-
 static void
 GetGLXDrawableBytes(void *value, XID id, ResourceSizePtr size)
 {
@@ -472,10 +454,6 @@ static Bool
 xorgGlxServerPreInit(const ExtensionEntry *extEntry)
 {
     if (glxGeneration != serverGeneration) {
-        /* Mesa requires at least one True/DirectColor visual */
-        if (!checkScreenVisuals())
-            return FALSE;
-
         __glXContextRes = CreateNewResourceType((DeleteType) ContextGone,
                                                 "GLXContext");
         __glXDrawableRes = CreateNewResourceType((DeleteType) DrawableGone,
commit 6dc88cd74b7d6d7c3f81e05654ef63fd25f6a8f0
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Thu Dec 22 08:37:10 2022 -0800

    Set thread priorities to user interactive or user initiated as appropriate
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index dd96e89f7..752ddc3f6 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -735,6 +735,9 @@ create_thread(void *(*func)(void *), void *arg)
     pthread_attr_init(&attr);
     pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+    if (&pthread_attr_set_qos_class_np) {
+        pthread_attr_set_qos_class_np(&attr, QOS_CLASS_USER_INITIATED, 0);
+    }
     pthread_create(&tid, &attr, func, arg);
     pthread_attr_destroy(&attr);
 
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index fd87e968b..15c1bc5d8 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -129,6 +129,9 @@ create_thread(void *(*func)(void *), void *arg)
     pthread_attr_init(&attr);
     pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+    if (&pthread_attr_set_qos_class_np) {
+        pthread_attr_set_qos_class_np(&attr, QOS_CLASS_USER_INITIATED, 0);
+    }
     pthread_create(&tid, &attr, func, arg);
     pthread_attr_destroy(&attr);
 
diff --git a/hw/xquartz/quartzStartup.c b/hw/xquartz/quartzStartup.c
index 732eba983..9137edb66 100644
--- a/hw/xquartz/quartzStartup.c
+++ b/hw/xquartz/quartzStartup.c
@@ -74,6 +74,9 @@ create_thread(void *func, void *arg)
     pthread_attr_init(&attr);
     pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+    if (&pthread_attr_set_qos_class_np) {
+        pthread_attr_set_qos_class_np(&attr, QOS_CLASS_USER_INTERACTIVE, 0);
+    }
     pthread_create(&tid, &attr, func, arg);
     pthread_attr_destroy(&attr);
 
diff --git a/os/inputthread.c b/os/inputthread.c
index 3469cfc1c..bd0a8335f 100644
--- a/os/inputthread.c
+++ b/os/inputthread.c
@@ -479,6 +479,12 @@ InputThreadInit(void)
     if (pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM) != 0)
         ErrorF("input-thread: error setting thread scope\n");
 
+#ifdef __APPLE__
+    if (&pthread_attr_set_qos_class_np) {
+        pthread_attr_set_qos_class_np(&attr, QOS_CLASS_USER_INTERACTIVE, 0);
+    }
+#endif
+
     DebugF("input-thread: creating thread\n");
     pthread_create(&inputThreadInfo->thread, &attr,
                    &InputThreadDoWork, NULL);
commit cffc8aec42346531bbf4819da8a7b237dc9d5c0f
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sun Jan 1 10:57:46 2023 -0800

    rootless: Use screen_x and screen_y instead of pixmap pointer hacks
    
    This updates rootless to treat pixmaps consistently with COMPOSITE,
    using the screen_x and screen_y values rather than doing hacky math.
    
    This will allow for proper bounds checking on a given PixmapRec.
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 210df75c6..d9aa18858 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -2187,7 +2187,7 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
             PixmapPtr pPix = (*pDraw->pScreen->GetWindowPixmap) (pWin);
 
             pBoundingDraw = &pPix->drawable;
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
             relx -= pPix->screen_x;
             rely -= pPix->screen_y;
 #endif
diff --git a/exa/exa.c b/exa/exa.c
index b16875845..42047fa2d 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -125,7 +125,7 @@ exaGetDrawablePixmap(DrawablePtr pDrawable)
 void
 exaGetDrawableDeltas(DrawablePtr pDrawable, PixmapPtr pPixmap, int *xp, int *yp)
 {
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
     if (pDrawable->type == DRAWABLE_WINDOW) {
         *xp = -pPixmap->screen_x;
         *yp = -pPixmap->screen_y;
diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index e632331da..2a31bd3c7 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -963,7 +963,7 @@ exaCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
     RegionInit(&rgnDst, NullBox, 0);
 
     RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
     if (pPixmap->screen_x || pPixmap->screen_y)
         RegionTranslate(&rgnDst, -pPixmap->screen_x, -pPixmap->screen_y);
 #endif
diff --git a/fb/fb.h b/fb/fb.h
index 8ab050d0f..08143a0d4 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -441,7 +441,7 @@ typedef struct {
 #define __fbPixDrawableX(pPix)	((pPix)->drawable.x)
 #define __fbPixDrawableY(pPix)	((pPix)->drawable.y)
 
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
 #define __fbPixOffXWin(pPix)	(__fbPixDrawableX(pPix) - (pPix)->screen_x)
 #define __fbPixOffYWin(pPix)	(__fbPixDrawableY(pPix) - (pPix)->screen_y)
 #else
diff --git a/fb/fbpixmap.c b/fb/fbpixmap.c
index af5d7bec0..89e3370a6 100644
--- a/fb/fbpixmap.c
+++ b/fb/fbpixmap.c
@@ -76,7 +76,7 @@ fbCreatePixmap(ScreenPtr pScreen, int width, int height, int depth,
     fbInitializeDrawable(&pPixmap->drawable);
 #endif
 
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
     pPixmap->screen_x = 0;
     pPixmap->screen_y = 0;
 #endif
diff --git a/fb/fbwindow.c b/fb/fbwindow.c
index fca871d62..df33af948 100644
--- a/fb/fbwindow.c
+++ b/fb/fbwindow.c
@@ -116,7 +116,7 @@ fbCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
 
     RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
 
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
     if (pPixmap->screen_x || pPixmap->screen_y)
         RegionTranslate(&rgnDst, -pPixmap->screen_x, -pPixmap->screen_y);
 #endif
diff --git a/glamor/glamor_copy.c b/glamor/glamor_copy.c
index 1ab2be6c0..fa2d783a1 100644
--- a/glamor/glamor_copy.c
+++ b/glamor/glamor_copy.c
@@ -781,7 +781,7 @@ glamor_copy_window(WindowPtr window, DDXPointRec old_origin, RegionPtr src_regio
 
     RegionIntersect(&dst_region, &window->borderClip, src_region);
 
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
     if (pixmap->screen_x || pixmap->screen_y)
         RegionTranslate(&dst_region, -pixmap->screen_x, -pixmap->screen_y);
 #endif
diff --git a/glamor/glamor_pixmap.c b/glamor/glamor_pixmap.c
index 9aa169cdc..2c8cc3ba0 100644
--- a/glamor/glamor_pixmap.c
+++ b/glamor/glamor_pixmap.c
@@ -39,7 +39,7 @@ void
 glamor_get_drawable_deltas(DrawablePtr drawable, PixmapPtr pixmap,
                            int *x, int *y)
 {
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
     if (drawable->type == DRAWABLE_WINDOW) {
         *x = -pixmap->screen_x;
         *y = -pixmap->screen_y;
diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index 3397bb50c..8cedb7a26 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -872,7 +872,7 @@ DrawablePtr DRI2UpdatePrime(DrawablePtr pDraw, DRI2BufferPtr pDest)
         return NULL;
 
     pPriv->prime_secondary_pixmap = spix;
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
     spix->screen_x = mpix->screen_x;
     spix->screen_y = mpix->screen_y;
 #endif
@@ -963,7 +963,7 @@ DRI2CanFlip(DrawablePtr pDraw)
 
     /* Does the window match the pixmap exactly? */
     if (pDraw->x != 0 || pDraw->y != 0 ||
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
         pDraw->x != pWinPixmap->screen_x || pDraw->y != pWinPixmap->screen_y ||
 #endif
         pDraw->width != pWinPixmap->drawable.width ||
diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c
index 8d1b742ef..ee29cad0b 100644
--- a/hw/xfree86/drivers/modesetting/dri2.c
+++ b/hw/xfree86/drivers/modesetting/dri2.c
@@ -287,7 +287,7 @@ ms_dri2_copy_region2(ScreenPtr screen, DrawablePtr drawable, RegionPtr pRegion,
     }
 
     if (translate && drawable->type == DRAWABLE_WINDOW) {
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
         PixmapPtr pixmap = get_drawable_pixmap(drawable);
         off_x = -pixmap->screen_x;
         off_y = -pixmap->screen_y;
diff --git a/hw/xwayland/xwayland-present.c b/hw/xwayland/xwayland-present.c
index 99e476b2f..49784de12 100644
--- a/hw/xwayland/xwayland-present.c
+++ b/hw/xwayland/xwayland-present.c
@@ -797,7 +797,7 @@ xwl_present_execute(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
                 PixmapPtr old_pixmap = screen->GetWindowPixmap(window);
 
                 /* Replace window pixmap with flip pixmap */
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
                 vblank->pixmap->screen_x = old_pixmap->screen_x;
                 vblank->pixmap->screen_y = old_pixmap->screen_y;
 #endif
diff --git a/hw/xwin/winmultiwindowwindow.c b/hw/xwin/winmultiwindowwindow.c
index 5b9b74e3d..47c19d04b 100644
--- a/hw/xwin/winmultiwindowwindow.c
+++ b/hw/xwin/winmultiwindowwindow.c
@@ -1071,7 +1071,7 @@ winCreatePixmapMultiwindow(ScreenPtr pScreen, int width, int height, int depth,
     pPixmap->refcnt = 1;
     pPixmap->devPrivate.ptr = NULL; // later set to pbBits
     pPixmap->primary_pixmap = NULL;
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
     pPixmap->screen_x = 0;
     pPixmap->screen_y = 0;
 #endif
diff --git a/include/pixmapstr.h b/include/pixmapstr.h
index faf54fa4d..54fc26508 100644
--- a/include/pixmapstr.h
+++ b/include/pixmapstr.h
@@ -78,7 +78,7 @@ typedef struct _Pixmap {
     int refcnt;
     int devKind;                /* This is the pitch of the pixmap, typically width*bpp/8. */
     DevUnion devPrivate;        /* When !NULL, devPrivate.ptr points to the raw pixel data. */
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
     short screen_x;
     short screen_y;
 #endif
diff --git a/mi/miexpose.c b/mi/miexpose.c
index e54b18b30..6b6938a75 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -461,7 +461,7 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
         tile_x_off = pWin->drawable.x;
         tile_y_off = pWin->drawable.y;
 
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
         draw_x_off = pixmap->screen_x;
         draw_y_off = pixmap->screen_y;
         tile_x_off -= draw_x_off;
diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index f3ae4ebbc..48e6af673 100644
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -142,7 +142,7 @@ damageRegionAppend(DrawablePtr pDrawable, RegionPtr pRegion, Bool clip,
     RegionRec pixClip;
     int draw_x, draw_y;
 
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
     int screen_x = 0, screen_y = 0;
 #endif
 
@@ -150,7 +150,7 @@ damageRegionAppend(DrawablePtr pDrawable, RegionPtr pRegion, Bool clip,
     if (!RegionNotEmpty(pRegion))
         return;
 
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
     /*
      * When drawing to a pixmap which is storing window contents,
      * the region presented is in pixmap relative coordinates which
@@ -201,7 +201,7 @@ damageRegionAppend(DrawablePtr pDrawable, RegionPtr pRegion, Bool clip,
 
         draw_x = pDamage->pDrawable->x;
         draw_y = pDamage->pDrawable->y;
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
         /*
          * Need to move everyone to screen coordinates
          * XXX what about off-screen pixmaps with non-zero x/y?
@@ -274,7 +274,7 @@ damageRegionAppend(DrawablePtr pDrawable, RegionPtr pRegion, Bool clip,
         if (pDamageRegion == pRegion && (draw_x || draw_y))
             RegionTranslate(pDamageRegion, draw_x, draw_y);
     }
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
     if (screen_x || screen_y)
         RegionTranslate(pRegion, -screen_x, -screen_y);
 #endif
diff --git a/miext/rootless/rootlessCommon.h b/miext/rootless/rootlessCommon.h
index d9a4d05e9..40400b395 100644
--- a/miext/rootless/rootlessCommon.h
+++ b/miext/rootless/rootlessCommon.h
@@ -226,20 +226,10 @@ extern RegionRec rootlessHugeRoot;
  *  Can't access the bits before the first word of the drawable's data in
  *  rootless mode, so make sure our base address is always 32-bit aligned.
  */
-#define SetPixmapBaseToScreen(pix, _x, _y) {                                \
-    PixmapPtr   _pPix = (PixmapPtr) (pix);                                  \
-    _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) -              \
-                            ((int)(_x) * _pPix->drawable.bitsPerPixel/8 +   \
-                             (int)(_y) * _pPix->devKind);                   \
-    if (_pPix->drawable.bitsPerPixel != FB_UNIT) {                          \
-        size_t _diff = ((size_t) _pPix->devPrivate.ptr) &               \
-                         (FB_UNIT / CHAR_BIT - 1);                          \
-        _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) -          \
-                                _diff;                                      \
-        _pPix->drawable.x = _diff /                                         \
-                            (_pPix->drawable.bitsPerPixel / CHAR_BIT);      \
-    }                                                                       \
-}
+#define SetPixmapBaseToScreen(pix, _x, _y) do { \
+    pix->screen_x = _x; \
+    pix->screen_y = _y; \
+} while(0)
 
 // Returns TRUE if this window is visible inside a frame
 // (e.g. it is visible and has a top-level or root parent)
diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index 12dd41eea..4b8a5b077 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -653,6 +653,9 @@ RootlessCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
     BoxPtr extents;
     int area;
 
+    PixmapPtr pPixmap = fbGetWindowPixmap(pWin);
+    DrawablePtr pDrawable = &pPixmap->drawable;
+
     RL_DEBUG_MSG("copywindowFB start (win %p (%lu)) ", pWin, RootlessWID(pWin));
 
     SCREEN_UNWRAP(pScreen, CopyWindow);
@@ -664,6 +667,10 @@ RootlessCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
     RegionNull(&rgnDst);
     RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
 
+    if (pPixmap->screen_x || pPixmap->screen_y) {
+        RegionTranslate(&rgnDst, -pPixmap->screen_x, -pPixmap->screen_y);
+    }
+
     extents = RegionExtents(&rgnDst);
     area = (extents->x2 - extents->x1) * (extents->y2 - extents->y1);
 
@@ -686,9 +693,6 @@ RootlessCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
             goto out;
         }
 
-        /* Move region to window local coords */
-        RegionTranslate(&rgnDst, -winRec->x, -winRec->y);
-
         RootlessStopDrawing(pWin, FALSE);
 
         SCREENREC(pScreen)->imp->CopyWindow(winRec->wid,
@@ -698,11 +702,10 @@ RootlessCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
     else {
         RootlessStartDrawing(pWin);
 
-        miCopyRegion((DrawablePtr) pWin, (DrawablePtr) pWin,
+        miCopyRegion(pDrawable, pDrawable,
                      0, &rgnDst, dx, dy, fbCopyWindowProc, 0, 0);
 
-        /* prgnSrc has been translated to dst position */
-        RootlessDamageRegion(pWin, prgnSrc);
+        RootlessDamageRegion(pWin, &rgnDst);
     }
 
  out:
diff --git a/present/present_scmd.c b/present/present_scmd.c
index 46fd9a1fd..200ded348 100644
--- a/present/present_scmd.c
+++ b/present/present_scmd.c
@@ -137,7 +137,7 @@ present_check_flip(RRCrtcPtr            crtc,
 
     /* Does the window match the pixmap exactly? */
     if (window->drawable.x != 0 || window->drawable.y != 0 ||
-#ifdef COMPOSITE
+#if defined(COMPOSITE) || defined(ROOTLESS)
         window->drawable.x != pixmap->screen_x || window->drawable.y != pixmap->screen_y ||
 #endif
         window->drawable.width != pixmap->drawable.width ||
commit 6725b1b0b014936bea7a9f0478331d283e59b8b9
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Tue Jan 3 00:26:25 2023 -0800

    rootless: Dead code removal (FinishFrameResize, gResizeDeathPix, et al)
    
    These are no longer necessary since we require the implementation to
    preserve the window contents on resize.
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index a216de11b..12dd41eea 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -620,18 +620,6 @@ RootlessRestackWindow(WindowPtr pWin, WindowPtr pOldNextSib)
     RL_DEBUG_MSG("restackwindow end\n");
 }
 
-/*
- * Specialized window copy procedures
- */
-
-// Globals needed during window resize and move.
-static void *gResizeDeathBits = NULL;
-static int gResizeDeathCount = 0;
-static PixmapPtr gResizeDeathPix[2] = { NULL, NULL };
-
-static BoxRec gResizeDeathBounds[2];
-static CopyWindowProcPtr gResizeOldCopyWindowProc = NULL;
-
 /*
  * RootlessNoCopyWindow
  *  CopyWindow() that doesn't do anything. For MoveWindow() of
@@ -649,74 +637,6 @@ RootlessNoCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
     RegionTranslate(prgnSrc, -dx, -dy);
 }
 
-/*
- * RootlessResizeCopyWindow
- *  CopyWindow used during ResizeWindow for gravity moves. Based on
- *  fbCopyWindow. The original always draws on the root pixmap, which
- *  we don't have. Instead, draw on the parent window's pixmap.
- *  Resize version: the old location's pixels are in gResizeCopyWindowSource.
- */
-static void
-RootlessResizeCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
-                         RegionPtr prgnSrc)
-{
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    RegionRec rgnDst;
-    int dx, dy;
-
-    RL_DEBUG_MSG("resizecopywindowFB start (win %p (%lu)) ", pWin, RootlessWID(pWin));
-
-    /* Don't unwrap pScreen->CopyWindow.
-       The bogus rewrap with RootlessCopyWindow causes a crash if
-       CopyWindow is called again during the same resize. */
-
-    if (gResizeDeathCount == 0)
-        return;
-
-    RootlessStartDrawing(pWin);
-
-    dx = ptOldOrg.x - pWin->drawable.x;
-    dy = ptOldOrg.y - pWin->drawable.y;
-    RegionTranslate(prgnSrc, -dx, -dy);
-    RegionNull(&rgnDst);
-    RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
-
-    if (gResizeDeathCount == 1) {
-        /* Simple case, we only have a single source pixmap. */
-
-        miCopyRegion(&gResizeDeathPix[0]->drawable,
-                     &pScreen->GetWindowPixmap(pWin)->drawable, 0,
-                     &rgnDst, dx, dy, fbCopyWindowProc, 0, 0);
-    }
-    else {
-        int i;
-        RegionRec clip, clipped;
-
-        /* More complex case, N source pixmaps (usually two). So we
-           intersect the destination with each source and copy those bits. */
-
-        for (i = 0; i < gResizeDeathCount; i++) {
-            RegionInit(&clip, gResizeDeathBounds + 0, 1);
-            RegionNull(&clipped);
-            RegionIntersect(&rgnDst, &clip, &clipped);
-
-            miCopyRegion(&gResizeDeathPix[i]->drawable,
-                         &pScreen->GetWindowPixmap(pWin)->drawable, 0,
-                         &clipped, dx, dy, fbCopyWindowProc, 0, 0);
-
-            RegionUninit(&clipped);
-            RegionUninit(&clip);
-        }
-    }
-
-    /* Don't update - resize will update everything */
-    RegionUninit(&rgnDst);
-
-    fbValidateDrawable(&pWin->drawable);
-
-    RL_DEBUG_MSG("resizecopywindowFB end\n");
-}
-
 /*
  * RootlessCopyWindow
  *  Update *new* location of window. Old location is redrawn with
@@ -886,48 +806,6 @@ StartFrameResize(WindowPtr pWin, Bool gravity,
 
     RootlessRedisplay(pWin);
 
-    /* If gravity is true, then we need to have a way of recovering all
-       the original bits in the window for when X rearranges the contents
-       based on the various gravity settings. The obvious way is to just
-       snapshot the entire backing store before resizing it, but that
-       it slow on large windows.
-
-       So the optimization here is to use the implementation's resize
-       weighting options (if available) to allow us to reason about what
-       is left in the backing store after the resize. We can then only
-       copy what won't be there after the resize, and do a two-stage copy
-       operation.
-
-       Most of these optimizations are only applied when the top-left
-       corner of the window is fixed, since that's the common case. They
-       could probably be extended with some thought. */
-
-    gResizeDeathCount = 0;
-
-    if (gravity) {
-        RootlessStartDrawing(pWin);
-
-        gResizeDeathBits = xallocarray(winRec->bytesPerRow, winRec->height);
-
-        memcpy(gResizeDeathBits, winRec->pixelData,
-               winRec->bytesPerRow * winRec->height);
-
-        gResizeDeathBounds[0] = (BoxRec) {
-        oldX, oldY, oldX2, oldY2};
-        gResizeDeathPix[0]
-            = GetScratchPixmapHeader(pScreen, winRec->width,
-                                     winRec->height,
-                                     winRec->win->drawable.depth,
-                                     winRec->win->drawable.bitsPerPixel,
-                                     winRec->bytesPerRow,
-                                     (void *) gResizeDeathBits);
-
-        SetPixmapBaseToScreen(gResizeDeathPix[0], oldX, oldY);
-        gResizeDeathCount = 1;
-    }
-
-    RootlessStopDrawing(pWin, FALSE);
-
     winRec->x = newX;
     winRec->y = newY;
     winRec->width = newW;
@@ -939,83 +817,10 @@ StartFrameResize(WindowPtr pWin, Bool gravity,
                                          newY + SCREEN_TO_GLOBAL_Y,
                                          newW, newH, weight);
 
-    RootlessStartDrawing(pWin);
-
-    /* Use custom CopyWindow when moving gravity bits around
-       ResizeWindow assumes the old window contents are in the same
-       pixmap, but here they're in deathPix instead. */
-
-    if (gravity) {
-        gResizeOldCopyWindowProc = pScreen->CopyWindow;
-        pScreen->CopyWindow = RootlessResizeCopyWindow;
-    }
-
-    /* If we can't rely on the window server preserving the bits we
-       need in the position we need, copy the pixels in the
-       intersection from src to dst. ResizeWindow assumes these pixels
-       are already present when making gravity adjustments. pWin
-       currently has new-sized pixmap but is in old position.
-
-       FIXME: border width change! (?) */
-
-    if (gravity && weight == RL_GRAVITY_NONE) {
-        PixmapPtr src, dst;
-
-        assert(gResizeDeathCount == 1);
-
-        src = gResizeDeathPix[0];
-        dst = pScreen->GetWindowPixmap(pWin);
-
-        RL_DEBUG_MSG("Resize copy rect %d %d %d %d\n",
-                     rect.x1, rect.y1, rect.x2, rect.y2);
-
-        /* rect is the intersection of the old location and new location */
-        if (BOX_NOT_EMPTY(rect) && src != NULL && dst != NULL) {
-            /* The window drawable still has the old frame position, which
-               means that DST doesn't actually point at the origin of our
-               physical backing store when adjusted by the drawable.x,y
-               position. So sneakily adjust it temporarily while copying.. */
-
-            ((PixmapPtr) dst)->devPrivate.ptr = winRec->pixelData;
-            SetPixmapBaseToScreen(dst, newX, newY);
-
-            fbCopyWindowProc(&src->drawable, &dst->drawable, NULL,
-                             &rect, 1, 0, 0, FALSE, FALSE, 0, 0);
-
-            ((PixmapPtr) dst)->devPrivate.ptr = winRec->pixelData;
-            SetPixmapBaseToScreen(dst, oldX, oldY);
-        }
-    }
-}
-
-static void
-FinishFrameResize(WindowPtr pWin, Bool gravity, int oldX, int oldY,
-                  unsigned int oldW, unsigned int oldH, unsigned int oldBW,
-                  int newX, int newY, unsigned int newW, unsigned int newH,
-                  unsigned int newBW)
-{
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    RootlessWindowRec *winRec = WINREC(pWin);
-    int i;
-
-    /* Redraw everything. FIXME: there must be times when we don't need
-       to do this. Perhaps when top-left weighting and no gravity? */
-
-    RootlessDamageRect(pWin, -newBW, -newBW, newW, newH);
-
-    for (i = 0; i < 2; i++) {
-        if (gResizeDeathPix[i] != NULL) {
-            FreeScratchPixmapHeader(gResizeDeathPix[i]);
-            gResizeDeathPix[i] = NULL;
-        }
-    }
-
-    free(gResizeDeathBits);
-    gResizeDeathBits = NULL;
-
-    if (gravity) {
-        pScreen->CopyWindow = gResizeOldCopyWindowProc;
-    }
+    /* FIXME: border width change. If the borderwidth reduces, the implementation
+     *        will have placed the window contents in the wrong location, and we
+     *        will no longer have access to the bits to adjust.
+     */
 }
 
 /*
@@ -1088,11 +893,6 @@ RootlessMoveWindow(WindowPtr pWin, int x, int y, WindowPtr pSib, VTKind kind)
                                                x + SCREEN_TO_GLOBAL_X,
                                                y + SCREEN_TO_GLOBAL_Y);
         }
-        else {
-            FinishFrameResize(pWin, FALSE,
-                              oldX, oldY, oldW, oldH, oldBW,
-                              newX, newY, newW, newH, newBW);
-        }
     }
 
     RL_DEBUG_MSG("movewindow end\n");
@@ -1142,12 +942,6 @@ RootlessResizeWindow(WindowPtr pWin, int x, int y,
         pScreen->ResizeWindow(pWin, x, y, w, h, pSib);
         SCREEN_WRAP(pScreen, ResizeWindow);
         NORMAL_ROOT(pWin);
-
-        if (winRec) {
-            FinishFrameResize(pWin, TRUE,
-                              oldX, oldY, oldW, oldH, oldBW,
-                              newX, newY, newW, newH, newBW);
-        }
     }
     else {
         /* Special case for resizing the root window */
@@ -1335,12 +1129,6 @@ RootlessChangeBorderWidth(WindowPtr pWin, unsigned int width)
         pWin->drawable.pScreen->ChangeBorderWidth(pWin, width);
         SCREEN_WRAP(pWin->drawable.pScreen, ChangeBorderWidth);
         NORMAL_ROOT(pWin);
-
-        if (winRec) {
-            FinishFrameResize(pWin, FALSE,
-                              oldX, oldY, oldW, oldH, oldBW,
-                              newX, newY, newW, newH, newBW);
-        }
     }
 
     RL_DEBUG_MSG("change border width end\n");
commit 910af012f970da99aec992438756ec6c2886f13d
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Tue Jan 3 00:13:12 2023 -0800

    rootless: Dead code removal (resize_after in StartFrameResize / FinishFrameResize)
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index ce8b22b3d..a216de11b 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -854,14 +854,13 @@ ResizeWeighting(int oldX1, int oldY1, int oldX2, int oldY2, int oldBW,
  *  saved and the implementation is told to change the window size.
  *  (x,y,w,h) is outer frame of window (outside border)
  */
-static Bool
+static void
 StartFrameResize(WindowPtr pWin, Bool gravity,
                  int oldX, int oldY, int oldW, int oldH, int oldBW,
                  int newX, int newY, int newW, int newH, int newBW)
 {
     ScreenPtr pScreen = pWin->drawable.pScreen;
     RootlessWindowRec *winRec = WINREC(pWin);
-    Bool resize_after = FALSE;
 
     BoxRec rect;
     int oldX2, newX2;
@@ -935,15 +934,10 @@ StartFrameResize(WindowPtr pWin, Bool gravity,
     winRec->height = newH;
     winRec->borderWidth = newBW;
 
-    /* Unless both dimensions are getting smaller, Resize the frame
-       before doing gravity repair */
-
-    if (!resize_after) {
-        SCREENREC(pScreen)->imp->ResizeFrame(winRec->wid, pScreen,
-                                             newX + SCREEN_TO_GLOBAL_X,
-                                             newY + SCREEN_TO_GLOBAL_Y,
-                                             newW, newH, weight);
-    }
+    SCREENREC(pScreen)->imp->ResizeFrame(winRec->wid, pScreen,
+                                         newX + SCREEN_TO_GLOBAL_X,
+                                         newY + SCREEN_TO_GLOBAL_Y,
+                                         newW, newH, weight);
 
     RootlessStartDrawing(pWin);
 
@@ -992,37 +986,18 @@ StartFrameResize(WindowPtr pWin, Bool gravity,
             SetPixmapBaseToScreen(dst, oldX, oldY);
         }
     }
-
-    return resize_after;
 }
 
 static void
 FinishFrameResize(WindowPtr pWin, Bool gravity, int oldX, int oldY,
                   unsigned int oldW, unsigned int oldH, unsigned int oldBW,
                   int newX, int newY, unsigned int newW, unsigned int newH,
-                  unsigned int newBW, Bool resize_now)
+                  unsigned int newBW)
 {
     ScreenPtr pScreen = pWin->drawable.pScreen;
     RootlessWindowRec *winRec = WINREC(pWin);
     int i;
 
-    RootlessStopDrawing(pWin, FALSE);
-
-    if (resize_now) {
-        unsigned int weight;
-
-        /* We didn't resize anything earlier, so do it now, now that
-           we've finished gravitating the bits. */
-
-        weight = ResizeWeighting(oldX, oldY, oldW, oldH, oldBW,
-                                 newX, newY, newW, newH, newBW);
-
-        SCREENREC(pScreen)->imp->ResizeFrame(winRec->wid, pScreen,
-                                             newX + SCREEN_TO_GLOBAL_X,
-                                             newY + SCREEN_TO_GLOBAL_Y,
-                                             newW, newH, weight);
-    }
-
     /* Redraw everything. FIXME: there must be times when we don't need
        to do this. Perhaps when top-left weighting and no gravity? */
 
@@ -1057,7 +1032,6 @@ RootlessMoveWindow(WindowPtr pWin, int x, int y, WindowPtr pSib, VTKind kind)
     int oldX = 0, oldY = 0, newX = 0, newY = 0;
     unsigned int oldW = 0, oldH = 0, oldBW = 0;
     unsigned int newW = 0, newH = 0, newBW = 0;
-    Bool resize_after = FALSE;
     RegionRec saveRoot;
 
     RL_DEBUG_MSG("movewindow start \n");
@@ -1084,9 +1058,9 @@ RootlessMoveWindow(WindowPtr pWin, int x, int y, WindowPtr pSib, VTKind kind)
             newW = pWin->drawable.width + 2 * newBW;
             newH = pWin->drawable.height + 2 * newBW;
 
-            resize_after = StartFrameResize(pWin, FALSE,
-                                            oldX, oldY, oldW, oldH, oldBW,
-                                            newX, newY, newW, newH, newBW);
+            StartFrameResize(pWin, FALSE,
+                             oldX, oldY, oldW, oldH, oldBW,
+                             newX, newY, newW, newH, newBW);
         }
     }
 
@@ -1115,8 +1089,9 @@ RootlessMoveWindow(WindowPtr pWin, int x, int y, WindowPtr pSib, VTKind kind)
                                                y + SCREEN_TO_GLOBAL_Y);
         }
         else {
-            FinishFrameResize(pWin, FALSE, oldX, oldY, oldW, oldH, oldBW,
-                              newX, newY, newW, newH, newBW, resize_after);
+            FinishFrameResize(pWin, FALSE,
+                              oldX, oldY, oldW, oldH, oldBW,
+                              newX, newY, newW, newH, newBW);
         }
     }
 
@@ -1139,7 +1114,6 @@ RootlessResizeWindow(WindowPtr pWin, int x, int y,
     ScreenPtr pScreen = pWin->drawable.pScreen;
     int oldX = 0, oldY = 0, newX = 0, newY = 0;
     unsigned int oldW = 0, oldH = 0, oldBW = 0, newW = 0, newH = 0, newBW = 0;
-    Bool resize_after = FALSE;
     RegionRec saveRoot;
 
     RL_DEBUG_MSG("resizewindow start (win %p (%lu)) ", pWin, RootlessWID(pWin));
@@ -1158,9 +1132,9 @@ RootlessResizeWindow(WindowPtr pWin, int x, int y,
             newW = w + 2 * newBW;
             newH = h + 2 * newBW;
 
-            resize_after = StartFrameResize(pWin, TRUE,
-                                            oldX, oldY, oldW, oldH, oldBW,
-                                            newX, newY, newW, newH, newBW);
+            StartFrameResize(pWin, TRUE,
+                             oldX, oldY, oldW, oldH, oldBW,
+                             newX, newY, newW, newH, newBW);
         }
 
         HUGE_ROOT(pWin);
@@ -1170,8 +1144,9 @@ RootlessResizeWindow(WindowPtr pWin, int x, int y,
         NORMAL_ROOT(pWin);
 
         if (winRec) {
-            FinishFrameResize(pWin, TRUE, oldX, oldY, oldW, oldH, oldBW,
-                              newX, newY, newW, newH, newBW, resize_after);
+            FinishFrameResize(pWin, TRUE,
+                              oldX, oldY, oldW, oldH, oldBW,
+                              newX, newY, newW, newH, newBW);
         }
     }
     else {
@@ -1328,7 +1303,6 @@ void
 RootlessChangeBorderWidth(WindowPtr pWin, unsigned int width)
 {
     RegionRec saveRoot;
-    Bool resize_after = FALSE;
 
     RL_DEBUG_MSG("change border width ");
 
@@ -1351,9 +1325,9 @@ RootlessChangeBorderWidth(WindowPtr pWin, unsigned int width)
             newW = pWin->drawable.width + 2 * newBW;
             newH = pWin->drawable.height + 2 * newBW;
 
-            resize_after = StartFrameResize(pWin, FALSE,
-                                            oldX, oldY, oldW, oldH, oldBW,
-                                            newX, newY, newW, newH, newBW);
+            StartFrameResize(pWin, FALSE,
+                             oldX, oldY, oldW, oldH, oldBW,
+                             newX, newY, newW, newH, newBW);
         }
 
         HUGE_ROOT(pWin);
@@ -1363,8 +1337,9 @@ RootlessChangeBorderWidth(WindowPtr pWin, unsigned int width)
         NORMAL_ROOT(pWin);
 
         if (winRec) {
-            FinishFrameResize(pWin, FALSE, oldX, oldY, oldW, oldH, oldBW,
-                              newX, newY, newW, newH, newBW, resize_after);
+            FinishFrameResize(pWin, FALSE,
+                              oldX, oldY, oldW, oldH, oldBW,
+                              newX, newY, newW, newH, newBW);
         }
     }
 
commit ea331f11354bd0fa5b36f8b26fe8413339f10c5a
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Mon Jan 2 18:59:49 2023 -0800

    rootless: Remove the special case for northwest gravity in StartFrameResize
    
    I don't see a reason why we would want to preserve pixels that are going to
    not be visible anyways.  The rootless implementation already handles
    preserving the relevant bits for us.
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index d84e27358..ce8b22b3d 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -861,7 +861,7 @@ StartFrameResize(WindowPtr pWin, Bool gravity,
 {
     ScreenPtr pScreen = pWin->drawable.pScreen;
     RootlessWindowRec *winRec = WINREC(pWin);
-    Bool need_window_source = FALSE, resize_after = FALSE;
+    Bool resize_after = FALSE;
 
     BoxRec rect;
     int oldX2, newX2;
@@ -905,119 +905,7 @@ StartFrameResize(WindowPtr pWin, Bool gravity,
 
     gResizeDeathCount = 0;
 
-    if (gravity && weight == RL_GRAVITY_NORTH_WEST) {
-        unsigned int code = 0;
-
-        /* Top left corner is anchored. We never need to copy the
-           entire window. */
-
-        need_window_source = TRUE;
-
-        /* These comparisons were chosen to avoid setting bits when the sizes
-           are the same. (So the fastest case automatically gets taken when
-           dimensions are unchanging.) */
-
-        if (newW < oldW)
-            code |= WIDTH_SMALLER;
-        if (newH < oldH)
-            code |= HEIGHT_SMALLER;
-
-        if (((code ^ (code >> 1)) & 1) == 0) {
-            /* Both dimensions are either getting larger, or both
-               are getting smaller. No need to copy anything. */
-
-            if (code == (WIDTH_SMALLER | HEIGHT_SMALLER)) {
-                /* Since the window is getting smaller, we can do gravity
-                   repair on it with its current size, then resize it
-                   afterwards. */
-
-                resize_after = TRUE;
-            }
-
-            gResizeDeathCount = 1;
-        }
-        else {
-            unsigned int copy_rowbytes, Bpp;
-            unsigned int copy_rect_width, copy_rect_height;
-            BoxRec copy_rect;
-
-            /* We can get away with a partial copy. 'rect' is the
-               intersection between old and new bounds, so copy
-               everything to the right of or below the intersection. */
-
-            RootlessStartDrawing(pWin);
-
-            if (code == WIDTH_SMALLER) {
-                copy_rect.x1 = rect.x2;
-                copy_rect.y1 = rect.y1;
-                copy_rect.x2 = oldX2;
-                copy_rect.y2 = oldY2;
-            }
-            else if (code == HEIGHT_SMALLER) {
-                copy_rect.x1 = rect.x1;
-                copy_rect.y1 = rect.y2;
-                copy_rect.x2 = oldX2;
-                copy_rect.y2 = oldY2;
-            }
-            else
-                OsAbort();
-
-            Bpp = winRec->win->drawable.bitsPerPixel / 8;
-            copy_rect_width = copy_rect.x2 - copy_rect.x1;
-            copy_rect_height = copy_rect.y2 - copy_rect.y1;
-            copy_rowbytes = ((copy_rect_width * Bpp) + 31) & ~31;
-            gResizeDeathBits = xallocarray(copy_rowbytes, copy_rect_height);
-
-            if (copy_rect_width * copy_rect_height >
-                rootless_CopyBytes_threshold &&
-                SCREENREC(pScreen)->imp->CopyBytes) {
-                SCREENREC(pScreen)->imp->CopyBytes(copy_rect_width * Bpp,
-                                                   copy_rect_height,
-                                                   ((char *) winRec->pixelData)
-                                                   +
-                                                   ((copy_rect.y1 -
-                                                     oldY) *
-                                                    winRec->bytesPerRow)
-                                                   + (copy_rect.x1 -
-                                                      oldX) * Bpp,
-                                                   winRec->bytesPerRow,
-                                                   gResizeDeathBits,
-                                                   copy_rowbytes);
-            }
-            else {
-                fbBlt((FbBits *) (winRec->pixelData
-                                  +
-                                  ((copy_rect.y1 - oldY) * winRec->bytesPerRow)
-                                  + (copy_rect.x1 - oldX) * Bpp),
-                      winRec->bytesPerRow / sizeof(FbBits), 0,
-                      (FbBits *) gResizeDeathBits,
-                      copy_rowbytes / sizeof(FbBits), 0, copy_rect_width * Bpp,
-                      copy_rect_height, GXcopy, FB_ALLONES, Bpp, 0, 0);
-            }
-
-            gResizeDeathBounds[1] = copy_rect;
-            gResizeDeathPix[1]
-                = GetScratchPixmapHeader(pScreen, copy_rect_width,
-                                         copy_rect_height,
-                                         winRec->win->drawable.depth,
-                                         winRec->win->drawable.bitsPerPixel,
-                                         winRec->bytesPerRow,
-                                         (void *) gResizeDeathBits);
-
-            SetPixmapBaseToScreen(gResizeDeathPix[1],
-                                  copy_rect.x1, copy_rect.y1);
-
-            gResizeDeathCount = 2;
-        }
-    }
-    else if (gravity) {
-        /* The general case. Just copy everything. */
-        need_window_source = TRUE;
-    }
-
-    /* If necessary, create a source pixmap pointing at the current
-       window bits. */
-    if (need_window_source) {
+    if (gravity) {
         RootlessStartDrawing(pWin);
 
         gResizeDeathBits = xallocarray(winRec->bytesPerRow, winRec->height);
commit f46c838008145f3c1269c5973e6a4aea18c5e787
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Mon Jan 2 23:52:36 2023 -0800

    rootless: Use RL_GRAVITY_NORTH_WEST for min/max/zoom resizing
    
    If none of the four corners is fixed, we can use RL_GRAVITY_NORTH_WEST weighting
    for the operation to let the implementation presetve the window bits for us.
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index 5e371e0d1..d84e27358 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -845,7 +845,7 @@ ResizeWeighting(int oldX1, int oldY1, int oldX2, int oldY2, int oldBW,
     else if (newX2 == oldX2 && newY1 == oldY1)
         return RL_GRAVITY_NORTH_EAST;
     else
-        return RL_GRAVITY_NONE;
+        return RL_GRAVITY_NORTH_WEST;
 }
 
 /*


More information about the xorg-commit mailing list