11  i_video: Video Mode & Frame Rendering

This tour covers video mode and frame rendering in linuxdoom’s i_video module.
It includes the interface in i_video.h and the X11 implementation in i_video.c, covering SHM setup, palette handling, frame updates, screen reading, and event polling.


11.0.1 πŸ“„ File: i_video.h (lines 37–46)

Main video interface:
- Initialize/shutdown graphics
- Set palette
- Update frames


11.0.2 πŸ“„ File: i_video.h (lines 49–54)

Additional routines: - I_WaitVBL: wait for vertical retrace
- I_ReadScreen: copy screen buffer
- I_BeginRead, I_EndRead: stubbed framebuffer reads


11.0.3 πŸ“„ File: i_video.c (lines 692–702)

I_InitGraphics sets up scaling flags, signal handlers, and computes window size.


11.0.4 πŸ“„ File: i_video.c (lines 775–783)

Checks for MIT‐SHM extension and a local X connection before enabling shared memory rendering.


11.0.5 πŸ“„ File: i_video.c (lines 855–863)

Creates a shared memory XImage using XShmCreateImage.


11.0.6 πŸ“„ File: i_video.c (lines 887–893)

Attaches the SHM segment to the process and to the X server.


11.0.7 πŸ“„ File: i_video.c (lines 896–903)

Fallback to XCreateImage with malloc if SHM is unavailable.


11.0.8 πŸ“„ File: i_video.c (lines 910–914)

Assigns screen buffer to screens[0] or allocates a 320Γ—200 buffer if scaling is enabled.


11.0.9 πŸ“„ File: i_video.c (lines 164–176)

I_ShutdownGraphics detaches and unmaps shared memory, nulls out image data.


11.0.10 πŸ“„ File: i_video.c (lines 582–585)

I_SetPalette updates colormap by calling UploadNewPalette.


11.0.11 πŸ“„ File: i_video.c (lines 551–556)

Initializes the XColor array with pixel indices and RGB flags.


11.0.12 πŸ“„ File: i_video.c (lines 563–571)

Gamma-corrects and stores the full palette via XStoreColors.


11.0.13 πŸ“„ File: i_video.c (lines 342–347)

I_UpdateNoBlit is a stub (no-op) in X11 β€” for platforms with buffer flips.


11.0.14 πŸ“„ File: i_video.c (lines 483–492)

I_FinishUpdate uses XShmPutImage and waits for ShmCompletion event if using SHM.


11.0.15 πŸ“„ File: i_video.c (lines 507–514)

Otherwise, uses XPutImage and XSync to render frame without SHM.


11.0.16 πŸ“„ File: i_system.c (lines 126–136)

I_WaitVBL waits approximately count / 70 seconds using usleep.


11.0.17 πŸ“„ File: i_video.c (lines 527–530)

I_ReadScreen copies the current frame buffer to the given array.


11.0.18 πŸ“„ File: i_system.c (lines 139–146)

I_BeginRead and I_EndRead are stubbed on X11 β€” placeholders for framebuffer locking.


11.0.19 πŸ“„ File: i_video.c (lines 315–323)

I_StartTic processes all pending X events and re-centers mouse if needed.


And that was it.