Files
reims-vgpu/guest/kext/tests/surface_test.cpp
T
Anees Iqbal f731b42226 🐛 Lock a backing-less surface at its shape in the scanout
WindowServer keeps one IOAccel surface for a display and reshapes it to each
update's dirty rectangle before it locks it. Measured on a macOS 26 guest
(fbt20): the whole 3840x2400 display first, then 320x56 at 1760,2160 (the
login window's password field) about 120 times a second. The kext answered a
lock only for the whole display, so every partial update failed with
kIOReturnNoMemory and WindowServer retried it every frame.

A surface with no backing on framebuffer 0 now locks wherever its shape lies
inside the display: at the shape's first pixel in the scanout, rows the
scanout's apart (RgfxSurfacePlace.hpp, tested natively). The scanout's
mapping in the task is kept across shapes, and made again only when a mode
moves the scanout, instead of each reshape. Flush (0xa, two scalars) of such
a surface succeeds, with nothing to copy, since its pixels are already the
display's; WindowServer called it, and the kext had refused it.
2026-11-05 21:58:31 -08:00

51 lines
2.3 KiB
C++

// The placement rule of RgfxSurfacePlace.hpp, built natively: a surface with no backing is the
// scanout's pixels under its shape, where the shape lies wholly inside the scanout.
#include <cstdio>
#include "RgfxSurfacePlace.hpp"
static int g_checks = 0, g_failed = 0;
#define CHECK(e) \
do { \
g_checks++; \
if (!(e)) { \
g_failed++; \
std::fprintf(stderr, "%s:%d: CHECK(%s) failed\n", __FILE__, __LINE__, #e); \
} \
} while (0)
int main()
{
const uint32_t width = 3840, height = 2400, rowBytes = 3840 * 4;
uint64_t at = 1;
// The whole display: its first pixel.
CHECK(rgfxSurfaceInScanout(0, 0, 3840, 2400, width, height, rowBytes, &at) && at == 0);
// A dirty rectangle (the login window's password field): its top-left pixel.
CHECK(rgfxSurfaceInScanout(1760, 2160, 320, 56, width, height, rowBytes, &at));
CHECK(at == 2160ull * rowBytes + 1760ull * 4);
// Rows longer than the display's pixels: placed by the rows.
CHECK(rgfxSurfaceInScanout(1, 1, 1, 1, width, height, rowBytes + 256, &at));
CHECK(at == rowBytes + 256 + 4);
// Touching the far edges is inside.
CHECK(rgfxSurfaceInScanout(3839, 2399, 1, 1, width, height, rowBytes, &at));
// Outside, partly outside, empty, or rows too short for the display: nowhere.
at = 7;
CHECK(!rgfxSurfaceInScanout(-1, 0, 10, 10, width, height, rowBytes, &at));
CHECK(!rgfxSurfaceInScanout(0, -1, 10, 10, width, height, rowBytes, &at));
CHECK(!rgfxSurfaceInScanout(3800, 0, 41, 10, width, height, rowBytes, &at));
CHECK(!rgfxSurfaceInScanout(0, 2390, 10, 11, width, height, rowBytes, &at));
CHECK(!rgfxSurfaceInScanout(0, 0, 0, 10, width, height, rowBytes, &at));
CHECK(!rgfxSurfaceInScanout(0, 0, 10, -2, width, height, rowBytes, &at));
CHECK(!rgfxSurfaceInScanout(0, 0, 10, 10, width, height, rowBytes - 4, &at));
CHECK(at == 7);
if (g_failed) {
std::fprintf(stderr, "surface_test: %d of %d checks failed\n", g_failed, g_checks);
return 1;
}
std::printf("surface_test: OK (%d checks)\n", g_checks);
return 0;
}