// Native surface smoke test. // Verifies that process-private surface handles can be created, mapped, queried, presented, and closed. #include #include #include #include #define SURFACE_W 64u #define SURFACE_H 48u static void print(const char* s) { SYS_WRITE_CONSOLE_REQUEST req = { SysSvFromCstr(s) }; SysWriteConsole(&req); } static void print_u64(uint64_t v) { char buf[32]; int i = 0; if (v == 0) { print("0"); return; } while (v && i < (int)sizeof(buf)) { buf[i++] = (char)('0' + (v % 10)); v /= 10; } while (i--) { char c = buf[i]; SYS_WRITE_CONSOLE_REQUEST req = { SysSvFromParts(&c, 1) }; SysWriteConsole(&req); } } static void exit_now(int code) { while (true) SysExitProcess(code); } static void fail(const char* msg) { print("surface_smoke: "); print(msg); print("\n"); exit_now(1); } static void fail_status(const char* what, uint32_t status) { print("surface_smoke: "); print(what); print(" failed status="); print_u64(status); print("\n"); exit_now(1); } int main(void) { print("surface_smoke: start\n"); uint32_t surface = 0; SYS_CREATE_SURFACE_REQUEST req; memset(&req, 0, sizeof(req)); req.Size = sizeof(req); req.Width = SURFACE_W; req.Height = SURFACE_H; req.Format = SYS_SURFACE_FORMAT_XRGB8888; req.Flags = SYS_SURFACE_FLAG_NONE; req.HandleOut = &surface; uint32_t s = SysCreateSurface(&req); if (s != NTLSTATUS_SUCCESS) fail_status("create surface", s); if (!surface) fail("surface handle is zero"); void* base = 0; uint32_t pitch = 0; s = SysMapSurface(surface, &base, &pitch); if (s != NTLSTATUS_SUCCESS) fail_status("map surface", s); if (!base || pitch < SURFACE_W * sizeof(uint32_t)) fail("invalid mapping"); SYS_SURFACE_DESC desc; memset(&desc, 0, sizeof(desc)); s = SysQuerySurface(surface, &desc); if (s != NTLSTATUS_SUCCESS) fail_status("query surface", s); if (desc.Width != SURFACE_W || desc.Height != SURFACE_H) fail("query dimensions mismatch"); if (desc.PitchBytes != pitch || desc.Format != SYS_SURFACE_FORMAT_XRGB8888) fail("query metadata mismatch"); if (desc.Base != base) fail("query base mismatch"); uint8_t* rows = (uint8_t*)base; for (uint32_t y = 0; y < SURFACE_H; ++y) { uint32_t* row = (uint32_t*)(rows + (size_t)y * pitch); for (uint32_t x = 0; x < SURFACE_W; ++x) row[x] = 0x00202020u + ((x & 0xffu) << 16) + ((y & 0xffu) << 8); } DISPLAY_RECT rect = { 0, 0, (int32_t)SURFACE_W, (int32_t)SURFACE_H }; s = SysPresentSurface(surface, &rect, 1); if (s != NTLSTATUS_SUCCESS) fail_status("present surface", s); s = SysPresentSurface(surface, 0, 0); if (s != NTLSTATUS_SUCCESS) fail_status("present full surface", s); SysCloseHandle(surface); print("surface_smoke: PASS\n"); exit_now(0); return 0; }