| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575 |
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Graphics & UI | NebOS Architecture</title>
- <meta name="description" content="NebOS graphics architecture: VBE framebuffer, shadow buffer, damage rectangles, blit vtable, window manager, canvas ABI, ngui toolkit and image library.">
- <link rel="icon" href="favicon.svg" type="image/svg+xml">
- <link rel="stylesheet" href="style.css">
- </head>
- <body>
- <a class="skip" href="#main">Skip to content</a>
- <header class="site-header">
- <a class="brand" href="index.html">
- <span class="brand-mark" aria-hidden="true"></span>
- <span>NebOS <span class="brand-sub">Architecture</span></span>
- </a>
- <nav class="site-nav" aria-label="Architecture sections">
- <a href="index.html">Overview</a>
- <a href="boot.html">Boot</a>
- <a href="memory.html">Memory</a>
- <a href="cpu.html">CPU</a>
- <a href="drivers.html">Drivers</a>
- <a href="filesystems.html">Filesystems</a>
- <a href="graphics.html" aria-current="page">Graphics</a>
- <a href="network.html">Network</a>
- <a href="userland.html">Userland</a>
- <a href="development.html">Development</a>
- </nav>
- </header>
- <main id="main" class="page">
- <div class="page-head">
- <p class="kicker">Graphics & UI</p>
- <h1>Draw into a shadow, publish by damage.</h1>
- <p class="lede">
- The display path is intentionally simple: drawing lands in a RAM
- shadow buffer, damage rectangles describe what changed, and a
- budgeted flush copies those rectangles to VRAM. Windows add a
- compositor and a mapped-canvas ABI on top; a small immediate-mode
- toolkit supplies the widgets.
- </p>
- <div class="meta">
- <span class="pill">VBE LFB</span>
- <span class="pill">1 MiB flush budget</span>
- <span class="pill">8 windows</span>
- <span class="pill">RGB565 canvases</span>
- </div>
- </div>
- <nav class="toc" aria-label="On this page">
- <h2>On this page</h2>
- <ul>
- <li><a href="#framebuffer">Framebuffer</a></li>
- <li><a href="#shadow">Shadow & damage</a></li>
- <li><a href="#blit">Blit backends</a></li>
- <li><a href="#wm">Window manager</a></li>
- <li><a href="#canvas">Canvas ABI</a></li>
- <li><a href="#ngui">ngui toolkit</a></li>
- <li><a href="#apps">Applications</a></li>
- <li><a href="#images">Image library</a></li>
- <li><a href="#icons">UI icons</a></li>
- <li><a href="#cursors">Mouse cursors</a></li>
- <li><a href="#gpu">GPU quirks</a></li>
- <li><a href="#backlight">Panel backlight</a></li>
- <li><a href="#sources">Source map</a></li>
- </ul>
- </nav>
- <section id="framebuffer">
- <h2>Framebuffer</h2>
- <p>
- The boot path writes a <code>struct vga_boot_fb_info</code> to
- <code>0x600</code>: LFB base, pitch, width, height, bits per pixel
- and an RGBX flag for GOP's byte order. The legacy VESA stage chooses
- a mode with at least 16 bpp, a linear framebuffer, it must fit the
- card's VRAM, at most 1920 pixels wide, and its shadow (pitch ×
- height) must fit the 8 MB reserve. 1920×1080 is the practical
- maximum: its 8.29 MB shadow fits, and its 4.15 MB RGB565 canvas
- fits the 4 MB window slot; 1920×1200 is rejected because its
- canvas would need 4.6 MB. The UEFI loader applies the same GOP
- limits.
- </p>
- <p>
- <span class="file">vga.c</span> owns the visible surface. On a
- normal boot the render target is a RAM shadow buffer at
- <code>0x100000</code>, not the LFB; the 8 MB reserve holds a
- 1920×1080×32 frame (8.29 MB) with about 94 KB to spare. A surface
- carries width, height, pitch, format and a
- pixel-pointer, so the same drawing code can target a window layer or
- a canvas.
- </p>
- </section>
- <section id="shadow">
- <h2>Shadow buffer & damage</h2>
- <p>
- Drawing never writes VRAM directly. Each operation records a damage
- rectangle; overlapping or touching rectangles merge, so a keystroke's
- cells collapse into one small rect while unrelated damage stays
- apart. The main loop calls <code>vga_present_shadow()</code> on every
- iteration with a byte budget of <code>VGA_FLUSH_BUDGET_BYTES</code>
- (1 MiB by default).
- </p>
- <ul>
- <li><strong>Small rects copy whole.</strong> A window repaint within the budget never tears.</li>
- <li><strong>Large rects are chunked.</strong> A full-screen redraw continues across loop iterations; newer damage is queued behind it.</li>
- <li><strong>No fixed frame rate.</strong> The loop flushes whenever there is pending damage, so a cursor move reaches the screen within one loop.</li>
- <li><strong>Re-entry guard.</strong> <code>vga_present_shadow()</code> refuses to run while another process is mid-flush; a full-screen copy is long enough to be preempted.</li>
- <li><strong>Window drags flush immediately.</strong> <code>wm_drag_shadow</code> copies each drag step as one consistent frame.</li>
- </ul>
- <p>
- When the target is not the screen — a window layer or an app canvas —
- <code>vga_target_damage()</code> is a no-op. The render target
- override is stored in the PCB, so a preempted draw cannot leak into
- another process's window.
- </p>
- </section>
- <section id="blit">
- <h2>Blit backends</h2>
- <p>
- <span class="file">blit.c</span> is the pixel-operation vtable:
- fill, copy, blend, canvas, present and flip. Software is the only
- backend today, but the WM calls the vtable rather than a fixed
- function, so an accelerator can replace individual operations
- without touching window logic.
- </p>
- <p>
- The software fill uses an SSE2 row store when the CPU supports it.
- Rows that do not fit the cache use streaming stores
- (<code>movntdq</code>, one <code>sfence</code> per fill), which
- avoids read-for-ownership traffic that makes large fills DRAM-bound
- on the Atom. SSE/SSE2 are never assumed: the kernel is built with
- <code>-mno-sse</code>, and <code>cpu_has_sse2()</code> probes CPUID,
- sets <code>CR4.OSFXSR/OSXMMEXCPT</code> and is re-run on every AP.
- </p>
- <p>
- <code>gfxbench</code> times fill, copy, cell, canvas and flush paths
- and reports the bytes actually copied by the presenter.
- </p>
- </section>
- <section id="wm">
- <h2>Window manager</h2>
- <p>
- The WM is a process that owns the desktop and a fixed array of eight
- windows. It draws a system bar with the banner, launcher buttons,
- clock, the temperature, and, on ThinkPads and Chromebooks, an
- AC/battery status icon at the far right (a plug on AC, a
- level-filled battery on battery, with a percentage tooltip below
- the bar on hover, painted above the windows), plus draggable
- terminal and canvas windows with a title bar and close button.
- A normal window has no visible frame; an invisible resize band
- (1 px inside, 3 px outside its outer edge) is the resize grab
- area, and the active title bar uses the toolkit's highlight
- colour.
- Click-to-focus, drag-by-title-bar and close are routed through the
- same pointer path. To the left of the rightmost AC/battery status
- icon, a network status icon shows a
- cable for wired Ethernet, signal bars for a connected WiFi link, a
- USB mark for RNDIS tethering, or a red X when no link is up.
- The whole right status area — temperature, date/time, network
- and AC/battery items plus the gaps between them — is one button:
- it opens the anchored <code>bin/netmenu</code> control panel (a
- second click closes it).
- It opens collapsed: the battery/clock summary and Quick settings
- pills are visible, while the network, power-mode and date/time
- settings stay hidden until their pill is clicked. Present NICs
- can then be selected (DHCP runs), and scanned WiFi networks can be
- joined, asking for the WPA2 passphrase first when the AP requires
- one.
- </p>
- <p>
- A popover is a chromeless canvas window created with
- <code>u_win_create_popover()</code> (<code>WIN_F_POPOVER</code>).
- The WM anchors it flush under the top bar at the right screen
- edge, treats it as always topmost in painting and hit-testing,
- and draws no chrome at all:
- the canvas fills the whole window rectangle, with no title bar,
- shadow, rim or rounded outer corners, so it reads as a flat menu
- panel. The kernel uses the window origin for content-relative
- pointer and scroll coordinates. An outside press dismisses the
- popover and the click then continues normally; a second click on
- any status target toggles it. The panel itself is drawn with the
- ngui components: a battery/AC and clock summary, a brightness
- slider when the panel PWM is present, and Quick settings tiles for
- Network, the CPU power mode (<code>SYS_CPUFREQ</code>) and Date
- & Time. Clicking a tile expands that section in place — the
- network devices/Wi-Fi/connection lists, the three power modes, or
- an inline date/time editor with Set, Now and Sync NTP (no separate
- window). <code>SYS_WIN_RESIZE_SELF</code> grows or shrinks the
- popover to the section, clamped to <code>SYS_SCREEN_INFO</code>'s
- framebuffer; the section scrolls with the wheel, touchpad or page
- keys when it is taller than the screen, and its overlay scrollbar
- slides in while the pointer is over the panel.
- </p>
- <p>
- The WM is the ring-3 process loaded from
- <code>/ramfs/bin/wm</code>; there is no kernel WM fallback. The
- kernel window server in <span class="file">wm.c</span> owns the
- shadow mapping, the per-window canvases, input routing, the cursor,
- kexec detection and the boot-console handoff. It starts the first
- terminal after the storage mount
- (<code>wm_server_boot_ready</code>) and leaves the boot console
- visible until the WM attaches. The console uses the same 8×16 face
- and top-left origin as the terminal, so the first frame replaces it
- without a size or position jump.
- </p>
- <figure class="figure">
- <svg viewBox="0 0 920 260" role="img" aria-labelledby="wm-title wm-desc">
- <title id="wm-title">Window anatomy</title>
- <desc id="wm-desc">A window consists of a title bar, a content area backed by an RGB565 canvas, and a close control. The WM composites the canvas into the screen shadow buffer.</desc>
- <rect class="svg-box" x="70" y="22" width="780" height="200" rx="10"/>
- <rect class="svg-box accent" x="70" y="22" width="780" height="34" rx="10"/>
- <text class="svg-text" x="88" y="45">Terminal · /ramfs/bin/ls</text>
- <text class="svg-text" x="800" y="45">×</text>
- <rect class="svg-box green" x="86" y="72" width="748" height="132" rx="6"/>
- <text class="svg-text" x="104" y="98">content canvas · RGB565 · mapped at 0x50000000</text>
- <text class="svg-sub" x="104" y="120">text cells, images, widgets, or arbitrary drawing</text>
- </svg>
- <figcaption>
- <strong>One window, one canvas.</strong> The title bar belongs to
- the WM; the content is whatever the owning process draws into its
- mapped back buffer. The WM never reads the process's memory — it
- composites the front canvas on <code>PRESENT</code>.
- </figcaption>
- </figure>
- <ul>
- <li><strong>Terminal windows</strong> are canvas clients: <span class="file">ucmd_term.c</span> renders its rows into the RGB565 window canvas; keys arrive through the generic <code>SYS_KEY_POLL</code> or <code>SYS_WIN_KEY_WAIT</code>. The WM no longer has a text-cell path.</li>
- <li><strong>Canvas windows</strong> are generic: the app gets a back buffer, pointer position/buttons/focus and queued press/release edges with capture.</li>
- <li><strong>Focus and z-order</strong> are explicit; closing a window kills its session and frees its canvas.</li>
- </ul>
- <h3>Compositing cost</h3>
- <p>
- The WM keeps a front-to-back order: the focused window first, then
- the remaining windows in descending slot order. For each damage
- rectangle it fills the desktop once and walks that order, subtracting
- every window in front from the region still uncovered. A window is
- drawn only in its exposed pieces, so a fully occluded window costs
- nothing and the stack is never repainted back-to-front. The kernel
- pointer hit-test uses the same order. A focused-window drag copies
- its shadow block to the new position and repaints only the old
- strips the new rectangle does not cover, instead of compositing the
- window at both positions. If either rectangle is partly off-screen
- the shadow has no valid pixels for the hidden part, so that step
- repaints the window rect instead of copying desktop background into
- it.
- </p>
- <p>
- <code>SYS_WIN_PRESENT</code> carries a content-relative damage
- rectangle. The terminal tracks its dirty rows, so a keystroke copies
- and composites one 8×16 row block instead of the whole 512×512
- canvas. The kernel unions the rectangles between WM polls and
- <code>SYS_WM_INFO</code> returns that union; a present with
- <code>w == 0</code> or <code>h == 0</code> still means the whole
- canvas. The WM overwrites <code>/share/wmstats</code> every two
- seconds with the interval's frame count, compositing time, worst
- frame and pixels drawn (<code>usurf_pixels</code>), which is the
- on-target compositor measurement.
- </p>
- </section>
- <section id="canvas">
- <h2>Canvas ABI</h2>
- <p>
- <code>SYS_WIN_CREATE</code> maps the calling command's window canvas
- read/write at <code>0x50000000</code>. The process draws RGB565
- pixels and publishes a finished frame with
- <code>SYS_WIN_PRESENT</code>, optionally passing a content-relative
- rectangle (<code>struct wm_win_present</code>) for the changed
- region. Present copies that region from the back buffer into the
- composited front canvas with interrupts off, so a half-drawn frame
- can never reach the screen. Frames carry monotonic sequence
- counters, so the WM cannot lose one. <code>content_gen</code> comes
- from a global counter and is unique per window creation, so a new
- window that reuses a just-closed slot forces the WM to remap its
- front canvas instead of reusing a stale mapping.
- </p>
- <p>
- <code>SYS_WIN_CREATE</code> creates a generic canvas window.
- <code>struct win_create.flags</code> can request
- <code>WIN_F_POPOVER</code>, a chromeless overlay: the canvas fills
- the window and the WM supplies only the topmost placement.
- <code>SYS_WIN_RESIZE_SELF</code> (115) resizes the caller's canvas
- and <code>SYS_SCREEN_INFO</code> (116) reports the framebuffer
- size, so a popover can collapse or grow. Input is exposed through
- <code>SYS_WIN_POINTER</code>
- (content-relative position, button mask, focus),
- <code>SYS_WIN_EVENT</code>, which
- queues press/release edges and a capture window, and
- <code>SYS_WIN_SCROLL</code>, which returns wheel/touchpad scroll
- accumulated for the window under the pointer in pixels
- (<code>+dy</code> is later content). A click that starts
- in a window still receives its release after the pointer leaves.
- The ngui helper <code>ngui_scroll_wheel()</code> applies the delta
- to a pane when the pointer is over it. A pane's scrollbar is an
- overlay: an 8 px rounded pill at its right edge that stays hidden
- while the pointer is outside, slides in over about 100 ms on
- hover, and never reduces the content rectangle or reflows a row.
- <code>hide_bar</code> suppresses it entirely.
- The WM process itself is special: it maps the screen shadow at
- <code>0x58000000</code> and each front canvas at
- <code>0x59000000 + index × 4 MB</code>, which is how it composites
- without reading another process's memory. The 4 MB slot covers a
- full-screen 1920×1080 RGB565 canvas (4.15 MB) minus the chrome;
- the old 2 MB slot capped a full-height window at roughly 1050 px
- wide.
- <code>SYS_WM_RESIZE</code> (WM side) and
- <code>SYS_WIN_ACK_RESIZE</code> (client side) swap in a resized
- canvas; the content size is bounded by the framebuffer, so a
- window can grow to the edge of the screen.
- </p>
- <p>
- Double-clicking a title bar maximizes the window to the work area
- below the system bar (<code>0, WM_BAR_H, fbw, fbh - WM_BAR_H</code>);
- the next double-click restores the saved geometry. Dropping a
- title-bar drag with the pointer on the left or right screen edge
- (<code>WM_SNAP_EDGE</code>, 2 px) snaps the window to that half of
- the work area at full height, and the top edge maximizes it. The
- restore geometry is saved only when a window leaves the normal state,
- so snapping and then maximizing still restores the original size.
- Dragging a maximized or snapped window restores it first, with the
- grab point kept at the same fraction of the title bar, and a manual
- resize clears the state. While a window is dragged, the screen edges
- and the facing edges of other windows resist it: the window stays
- flush until the pointer overshoots by <code>WM_RESIST</code> (24 px),
- which makes side-by-side placement exact. Windows can be dragged past the left, right and
- bottom edges; <code>WM_DRAG_VISIBLE</code> (48 px) of the title bar
- always stays on-screen for recovery, and the top bar is never
- overlapped. An invisible resize band (1 px inside, 3 px outside)
- runs along every edge and corner: the grabbed edges follow the
- pointer while the opposite edges stay put, clamped to the work
- area. While a drag or resize is active the WM owns the pointer,
- so the window content does not see the held button.
- </p>
- <div class="note">
- <p><strong>Buttons fire on the release edge.</strong> The toolkit keeps
- a button <code>active</code> until <code>ui->released</code>;
- inferring release from the sampled button mask races the WM event
- queue and drops clicks.</p>
- </div>
- <p>
- When a process exits or crashes, the reaper releases its window
- mappings and the window server frees the canvas. Closing a window
- kills its owner. Keys go through the window key queue
- (<code>SYS_WIN_KEY_WAIT</code>) or the generic
- <code>SYS_KEY_POLL</code>; Ctrl+C still reaches the terminal.
- </p>
- </section>
- <section id="ngui">
- <h2>ngui toolkit</h2>
- <p>
- <span class="file">ngui.c</span>/<span class="file">ngui.h</span> is an
- immediate-mode GUI toolkit shared by the ring-3 apps. It provides
- clipped RGB565 primitives, buttons, menu items, text fields, the
- Adwaita symbolic icons (see <a href="#icons">UI icons</a>), a theme palette, layout cut helpers and scrolling
- panes. It is linked into <code>files</code>, <code>mines</code>,
- <code>solitaire</code>, <code>chat</code>, the control panel and
- the real <code>gallery.elf</code>.
- </p>
- <ul>
- <li><strong>Text fields</strong> support drag-selection, double-click select-all, Ctrl+Left/Right word jumps, Ctrl+Delete/Backspace word deletion and Ctrl+A. They use the proportional face with measured caret, selection and horizontal scrolling; a field marked <code>disabled</code> ignores pointer and keyboard input, drops the focus and paints its value dimmed in the same proportional face. A field marked <code>secret</code> is measured and painted from a <code>*</code> mask (caret, selection and click positions follow the mask, Ctrl+Left/Right jump to the ends), and Tab returns <code>NGUI_INPUT_NEXT</code> together with <code>NGUI_INPUT_CANCEL</code> so forms can move the focus. Fields hold up to 511 characters (<code>NGUI_INPUT_MAX</code> 512). The terminal and editor keep the 8×16 cell grid.</li>
- <li><strong>Popover components</strong> give a menu panel its surface: <code>ngui_popover_begin()</code> fills the canvas and returns the body and footer rectangles (no title bar or close button); <code>ngui_section()</code> draws a captioned section header with an optional right-aligned action button; <code>ngui_list_row()</code> is a two-line hover/selected row with optional signal bars and trailing text; <code>ngui_tile()</code> is a rounded quick-settings tile and <code>ngui_slider()</code> a draggable horizontal slider. The WM draws no outer chrome, so the app paints the whole window.</li>
- <li><strong>Scroll panes</strong> keep the wheel and page keys, and draw a Firefox-style overlay pill instead of a permanent track. It is hidden by default, animates in from the pane's right edge while the pointer is over the pane, brightens over the hit strip and turns accent-coloured while dragged. Presses in the strip start a drag (or jump the thumb) and do not reach the rows or buttons beneath it; content uses the full pane width in every app.</li>
- <li><strong>Clip stack</strong> keeps nested panes and popups inside their parents.</li>
- <li><strong>Layout cuts</strong> split a rectangle into rows, columns and fixed margins without a constraint solver.</li>
- <li><strong>No retained widget tree.</strong> Apps redraw from state every frame, which keeps the toolkit small and predictable.</li>
- </ul>
- <p>
- Proportional text comes from <span class="file">ufont.c</span>: a
- fixed-point, integer-only TrueType parser and antialiased rasterizer.
- The pack carries Latin-1 Arimo regular/bold/italic/bold-italic,
- Liberation Mono and a curated monochrome Noto Emoji subset under
- <code>/ramfs/fonts</code>. The browser, ngui apps and the WM chrome
- use real pixel sizes from 8 to 48 px; the browser maps CSS
- <code>font-size</code>, <code>font-weight</code>,
- <code>font-style</code> and <code>font-family: monospace</code> to
- the faces. Missing fonts fall back to the 8×16 bitmap. The browser
- detaches the font arena before <code>heap_reset()</code> and
- reattaches after <code>heap_start()</code>; terminal content and
- the editor keep the bitmap cells.
- </p>
- <p>
- UTF-8 text is available through <code>ngui_text_utf8*</code> and
- <code>ngui_menu_item_utf8()</code>. Per codepoint, the selected
- primary face is tried first, then the lazily loaded emoji face;
- cmap format 12 covers codepoints above the BMP. The emoji set is
- deliberately limited to common single-codepoint glyphs that fit the
- rasterizer's 256-point/16-contour limits. ZWJ sequences, flags,
- skin tones and color glyphs fall back to a tofu or
- <code>?</code>; the browser keeps its Latin-1 byte path.
- </p>
- </section>
- <section id="apps">
- <h2>Applications</h2>
- <div class="grid">
- <div class="card">
- <h3>files</h3>
- <p>File browser on the VFS: opens text in <code>edit</code>, images in <code>view</code> and HTML in <code>browser</code>. The first ngui user.</p>
- </div>
- <div class="card">
- <h3>gallery</h3>
- <p>Live showcase of every ngui control and primitive. Ships in the pack as <code>bin/gallery.app</code>; a launcher prefers <code>/share/GALLERY</code> for development.</p>
- </div>
- <div class="card">
- <h3>chat</h3>
- <p>Cloudron Chat client: native OIDC login, channel/DM sidebar with unread badges and presence dots, a wrapped timeline with avatars, day headers and reply snippets, a composer and browse/new-DM pickers. Media downloads use a warm <code>curl __serve</code> helper; message images are also decoded there (480×320 bounds), while avatars decode at 32×32 on the chat thread, so the window keeps drawing. Saved sessions resume from <code>/data</code>. The top-bar <em>Chat</em> button launches it.</p>
- </div>
- <div class="card">
- <h3>disks</h3>
- <p>Storage manager: devices, MBR partitions and mounts, per-volume mount name, read-only and automount, and Format / Install NebOS dialogs that show the kernel command's output. The top-bar <em>Disks</em> button and the <em>Disks</em> button in <code>files</code> launch it.</p>
- </div>
- <div class="card">
- <h3>solitaire</h3>
- <p>Klondike with drag-and-drop, draw-one/three, scoring, animation and pixel-art cards on the canvas service.</p>
- </div>
- <div class="card">
- <h3>view</h3>
- <p>Image viewer with fit, 1:1, zoom, pan, EXIF orientation and animated GIF playback.</p>
- </div>
- <div class="card">
- <h3>clock / colors / settime</h3>
- <p>Small canvas demos: an analog clock, a colour test window, and the standalone Date & Time editor (<code>settime</code>). The control panel's Date & Time tile reveals its own inline editor, which reads and writes the CMOS RTC and can fetch UTC from an SNTP server.</p>
- </div>
- <div class="card">
- <h3>browser</h3>
- <p>HTML/CSS renderer with flex rows, auto-fit and <code>repeat(N, 1fr)</code> card grids, <code>aspect-ratio</code> frames, inline-block runs, inline SVG icons, basic tables and inline SVG diagrams. It decodes inline images at their laid-out bounds (a JPEG gets a reduced IDCT) in the fetch helper, caches a display-size bitmap per image so repaints are 1:1, and fetches through the same helper; image repaints are coalesced and <code>/share/IMGSTAT</code> reports where a load spent its time. Inline and external scripts run on the vendored QuickJS engine (ES2025), and forms render and submit natively. The largest ring-3 application in the tree.</p>
- </div>
- </div>
- </section>
- <section id="images">
- <h2>Image library</h2>
- <p>
- The codecs are independent of the OS and the toolkit: each takes an
- input buffer plus a caller-provided <code>struct img_mem</code> arena
- and returns an RGB565 image with an optional 8-bit alpha plane. The
- browser and the chat client link the same objects and decode HTTP
- bodies in memory.
- </p>
- <ul>
- <li><strong>Formats.</strong> PNG, baseline and progressive JPEG, animated GIF, BMP, TGA, PNM, ICO/CUR and PAM. The browser also takes SVG files (<code><img src="logo.svg"></code>, CSS backgrounds): the markup is parsed into a detached subtree and drawn by its inline-SVG renderer into an RGB565 + alpha bitmap.</li>
- <li><strong>Drawing.</strong> <code>img_draw()</code> is a clipped, scaled RGB565 blit: box-filter downscale, bilinear upscale, alpha over a checkerboard or over the destination. A 1:1 opaque source takes a row copy, and a 1:1 alpha source blends in RGB565 without the 8-bit round trip.</li>
- <li><strong>Display-size decode.</strong> <code>struct img_options</code> carries optional <code>max_w</code>/<code>max_h</code> bounds. JPEG honours them with a scaled IDCT (1/2 4x4, 1/4 2x2, 1/8 1x1, Loeffler/IGJ), so a 1200x800 photo painted at 400×267 is decoded at roughly 600×400 instead of full size and then box-filtered. PNG/GIF/other codecs ignore the bounds and the caller scales them with <code>img_draw()</code>. The browser's <code>curl __serve</code> helper runs this decode for remote <code><img></code> and publishes the finished RGB565+alpha bitmap, so the UI thread only copies it.</li>
- <li><strong>Orientation.</strong> EXIF orientation is applied; arithmetic JPEG and CMYK are rejected.</li>
- <li><strong>Cost.</strong> Downscaling runs on the CPU. The browser decodes at the CSS/attribute box and caches one display-size bitmap per image, so a repaint is a 1:1 blit; the viewer caches one image; the chat client caches 480×320 message images and 32×32 circular avatars. <code>/share/IMGSTAT</code> records the browser's net, io, decode, scale, paint and reflow times.</li>
- </ul>
- </section>
- <section id="icons">
- <h2>UI icons</h2>
- <p>
- ngui's icons (<code>ngui_icon()</code>, <code>ngui_icon_button()</code>:
- back/forward, reload and home in the browser toolbar, folder/file/drive
- in <code>files</code>) are GNOME Adwaita symbolic icons
- (adwaita-icon-theme 51, LGPL-3 or CC-BY-SA-3.0). The unchanged
- <code>*-symbolic.svg</code> files live in
- <span class="file">assets/icons/adwaita/</span>; the host tool
- <span class="file">tools/mkicons.c</span> rasterizes each one with the
- browser's <span class="file">svg_raster.c</span> into a 16×16
- 8-bit coverage mask and writes one <code>NBICO1</code> bundle,
- <code>/ramfs/icons/adwaita16.icn</code> (layout in
- <span class="file">include/icon_abi.h</span>): a 16-byte header and
- 13 masks, ~3.3 KB raw and ~0.8 KB gzip, so both the USB
- and the floppy pack carry it.
- </p>
- <ul>
- <li><strong>Icon list.</strong> <code>ICON_LIST</code> is an X-macro of enum suffix, short name and theme file. Its order is the icon id and the bundle order (append only); it generates <code>enum ngui_icon</code> and <code>ngui_icon_name()</code>, and the gallery shows every entry.</li>
- <li><strong>Tinting.</strong> Symbolic icons are one colour, so only coverage is stored. <code>ngui_icon()</code> blends the mask in the caller's colour (the theme text colour on buttons, <code>icon_folder</code>/<code>icon_disk</code>/<code>icon_file</code> in <code>files</code>), centred and clipped.</li>
- <li><strong>Loading.</strong> Each process reads the bundle once into a BSS buffer, so the browser's <code>heap_reset()</code> cannot free it. The read is capped at the ids the app was built with, so an older app still works with a newer bundle. Without the bundle the icon is left blank; there is no line-drawn fallback, because it cost ~2 KB of code in each app.</li>
- <li><strong>Strict converter.</strong> mkicons reads only what symbolic icons use (<code><svg viewBox></code>, <code><g></code>, <code><path></code>, <code><rect></code>, <code><circle></code>, <code><ellipse></code>, fill, fill-rule, opacity) and fails the build on transforms, strokes, <code>style</code> or unknown elements instead of drawing a wrong icon. <code>./mkicons assets/icons/adwaita 16 out.icn -v</code> prints an ASCII preview of every mask.</li>
- </ul>
- </section>
- <section id="cursors">
- <h2>Mouse cursors</h2>
- <p>
- The cursor set is the GNOME Adwaita theme (adwaita-cursors 51,
- LGPL-3 or CC-BY-SA-3.0). Its 24 px Xcursor images are copied
- into <span class="file">assets/cursors/adwaita/</span> (trimmed by
- <span class="file">tools/xcursor_trim.py</span>), and the host tool
- <span class="file">tools/mkcursors.c</span> turns them into one
- <code>NBCUR1</code> bundle, <code>/ramfs/cursors/adwaita24.cur</code>
- (layout in <span class="file">include/cursor_abi.h</span>):
- 35 shapes named after the CSS <code>cursor</code> keywords, each
- with its size, hotspot, frame count and premultiplied ARGB8888
- frames. The animated <code>wait</code>/<code>progress</code>
- spinners keep every fourth of Adwaita's 60 frames (15 frames at
- 64 ms, the same speed). The bundle is ~146 KB raw,
- ~18 KB gzip, and only in the full pack: the floppy lite pack
- has no room, so a floppy boot keeps the built-in 16×16 arrow.
- </p>
- <ul>
- <li><strong>Loading.</strong> <span class="file">cursor.c</span> copies the bundle out of the ramfs into its own pages after <code>ramfs_init()</code> and after every <code>ramfs_replace()</code> (the old pack is freed), then tells <span class="file">mouse.c</span> to re-fetch its image.</li>
- <li><strong>Selection.</strong> On every <code>SYS_WM_POLL</code> the window server resolves the shape: the WM's override (<code>SYS_WM_SET_CURSOR</code>: resize arrows on the resize band and while resizing, the move cross during a title-bar drag, a hand over launchers and the status area), else the cursor of the window holding the pointer capture, else the content cursor (<code>SYS_WIN_SET_CURSOR</code>) of the window under the pointer, else the arrow.</li>
- <li><strong>Clients.</strong> ngui resets the cursor to the arrow for each redrawn frame, a hovered text field asks for the I-beam, <code>ngui_cursor_rect()</code>/<code>ngui_set_cursor()</code> serve apps, and <code>ngui_end_ex()</code> sends it when it changed. The terminal uses the I-beam; the browser maps the inherited CSS <code>cursor</code> property and, for <code>auto</code>, a hand over links, an I-beam over text fields and the progress arrow while a page loads. The gallery's Cursors section shows every shape.</li>
- <li><strong>Drawing.</strong> <code>cur_x</code>/<code>cur_y</code> stay the hotspot; the image's top-left is the hotspot minus the image's hotspot and may be off-screen. The software cursor saves up to 32×32 pixels under it and blends the premultiplied pixels over them. Intel Ironlake and Radeon copy the ARGB image into their 64×64 planes (Intel uses CURPOS sign bits for negative positions and follows the matching primary plane's gamma enable, because the display palette is after the plane blender and a cursor-only gamma pass brightens its antialiased edges on a VBE mode whose primary bypasses the palette; Radeon uses <code>HORZ_VERT_OFF</code> plus a shifted <code>CUR_OFFSET</code>); Cirrus reduces it to its two colours and clamps the position at 0. Animated frames advance from <code>mouse_poll_update()</code>.</li>
- </ul>
- </section>
- <section id="gpu">
- <h2>GPU quirks</h2>
- <ul>
- <li><strong>ATI Mach64.</strong> A CRTC fixup is applied after mode set. The legacy CRTC is skipped under UEFI.</li>
- <li><strong>NVIDIA.</strong> VBE/GOP only; the kernel never touches the legacy VGA CRTC. On the ION, the framebuffer is stolen DRAM behind a BAR3 aperture; <span class="file">nvidia.c</span> finds the stolen range and writes through a cached alias once a WC MTRR covers it. The nv50 display-engine probe is gated to the ION/nv50 chipsets so Maxwell parts (the GM206 GTX 960) are not poked through nv50 registers. On AMD family 15h the WC MTRR path uses only a free variable entry, leaves <code>MTRRdefType</code> untouched and writes a zero high mask (the LFB is below 4 GB); this is validated on the 970A-DS3P.</li>
- <li><strong>Intel.</strong> The Ironlake-era path supports a hardware cursor where available; the software cursor is the common fallback. Cherryview/Braswell also exposes the panel backlight (below).</li>
- <li><strong>UEFI.</strong> <code>vga.c</code> honours the RGBX flag and skips the VBE-only ATI CRTC reset and NVIDIA stolen-VRAM alias. <span class="file">mouse.c</span> forces the software cursor.</li>
- </ul>
- </section>
- <section id="backlight">
- <h2>Panel backlight</h2>
- <p>
- The HP Chromebook 11 G5 (<code>google/setzer</code>, Braswell)
- drives its internal panel PWM from the display engine, not from
- the Chrome EC. The board VBT (<code>data.vbt</code>, block 43)
- declares PWM controller 0 at 200 Hz, active high. Linux uses the
- same Valleyview/Cherryview registers through
- <code>intel_backlight</code>.
- </p>
- <ul>
- <li><strong>Registers.</strong> <code>BLC_PWM_CTL2</code> at GPU BAR0 + <code>0x1E1250</code> (pipe A; pipe B is <code>+0x100</code>): bit 31 enables, bit 28 is polarity. <code>BLC_PWM_CTL</code> at <code>0x1E1254</code>: period in bits 31:16, duty in bits 15:0. The Cherryview PWM clock is 19.2 MHz with a fixed /16 increment, so 200 Hz is a period of 6000.</li>
- <li><strong>Probe.</strong> <span class="file">backlight.c</span> matches Intel <code>8086:22b0</code>/<code>22b1</code>, maps the graphics MMIO BAR, reads both pipes, follows the one the firmware enabled and falls back to controller 0. It logs the chosen pipe, period, duty and raw registers to COM1.</li>
- <li><strong>Use.</strong> The <code>backlight</code> command prints the percentage and PWM state; <code>backlight up|down</code> steps by 10%, <code>backlight 0-100</code> sets a level (clamped to 5..100), and <code>backlight probe</code> dumps both pipes' registers. <code>SYS_BACKLIGHT</code> gives ring 3 the same get/set/step, which drives the control panel's brightness slider. F6/F7 (the ChromeOS EC action-row brightness keys) and the standard <code>E0 14</code>/<code>E0 15</code> brightness scancodes adjust it; the keys are consumed in <span class="file">io.c</span> and never reach a window.</li>
- <li><strong>Overlay.</strong> <code>SYS_WM_POLL</code> also reports the backlight percentage and a change counter. After each change the ring-3 WM (<span class="file">ucmd_wm.c</span>) draws a centered <em>Brightness</em> bubble with a sun icon, the percentage and a level bar, keeps it up for 3 s, and composits it above the windows on every pass while it is visible.</li>
- <li><strong>Limits.</strong> Only the Cherryview/Braswell native PWM (<code>8086:22b0</code>/<code>22b1</code>) is driven. The level is not persisted; a cold boot returns to the firmware's duty.</li>
- </ul>
- </section>
- <section id="sources">
- <h2>Source map</h2>
- <ul class="filelist">
- <li><code>kernel/vga.c</code>, <code>kernel/vga.h</code> — framebuffer and damage</li>
- <li><code>kernel/bootcon.c</code> — direct-to-LFB boot console</li>
- <li><code>kernel/vga_copy.S</code> — copy primitives</li>
- <li><code>kernel/blit.c</code>, <code>kernel/blit.h</code> — pixel vtable</li>
- <li><code>kernel/cpu.c</code> — SSE2 probing</li>
- <li><code>kernel/wm.c</code>, <code>kernel/wm.h</code>, <code>include/wm_abi.h</code> — kernel window server and shared ABI</li>
- <li><code>user/apps/wm/ucmd_wm.c</code>, <code>user/lib/uwm/uwm_lib.c</code> — ring-3 WM</li>
- <li><code>user/apps/netmenu/ucmd_netmenu.c</code> — top-bar control panel (network/WiFi, brightness, power mode, Date & Time)</li>
- <li><code>user/apps/settime/ucmd_settime.c</code>, <code>kernel/rtc.c</code>, <code>kernel/ntp.c</code> — Date & Time editor, RTC access and SNTP sync</li>
- <li><code>kernel/gfx.c</code>, <code>kernel/gfx.h</code> — RGB565 window canvases</li>
- <li><code>kernel/sys_wm.c</code>, <code>kernel/sys_wm.h</code> — WM/window ABI</li>
- <li><code>user/apps/browser/browser.c</code>, <code>user/apps/browser/browser_html.c</code> — HTML/CSS renderer and inline SVG</li>
- <li><code>user/lib/ngui/ngui.c</code>, <code>user/lib/ngui/ngui.h</code> — toolkit</li>
- <li><code>user/lib/ufont/ufont.c</code>, <code>user/lib/ufont/ufont_ttf.c</code>, <code>user/lib/ufont/ufont_draw.c</code> — fixed-point TrueType text</li>
- <li><code>fonts/*.ttf</code> — Arimo / Liberation Mono / Noto Emoji subsets in the pack</li>
- <li><code>user/apps/files/ucmd_files.c</code>, <code>user/apps/gallery/gallery.c</code>, <code>user/apps/solitaire/ucmd_solitaire.c</code>, <code>user/apps/chat/ucmd_chat.c</code></li>
- <li><code>user/lib/img/img*.c</code> — image codecs</li>
- <li><code>kernel/ati.c</code>, <code>kernel/nvidia.c</code>, <code>kernel/intel.c</code>, <code>kernel/nv50.c</code></li>
- <li><code>kernel/backlight.c</code>, <code>kernel/backlight.h</code> — Cherryview/VLV panel PWM</li>
- <li><code>kernel/cursor.c</code>, <code>kernel/cursor.h</code>, <code>kernel/mouse.c</code>, <code>kernel/cursor_shape.h</code> — cursor bundle loader, drawing and the built-in fallback arrow; <code>kernel/cirrus.c</code>, <code>kernel/radeon.c</code> — hardware cursors</li>
- <li><code>include/icon_abi.h</code>, <code>tools/mkicons.c</code>, <code>assets/icons/adwaita/</code> — UI icon list, the NBICO1 bundle and the Adwaita symbolic SVGs</li>
- <li><code>include/cursor_abi.h</code>, <code>tools/mkcursors.c</code>, <code>tools/xcursor_trim.py</code>, <code>tools/cursor_test.c</code>, <code>assets/cursors/adwaita/</code> — cursor shapes, the NBCUR1 bundle and the Adwaita source images</li>
- </ul>
- </section>
- </main>
- <footer class="site-footer">
- <div class="inner">
- <p><strong>NebOS 0.2.0</strong> · Architecture documentation · <a href="index.html">overview</a></p>
- <p>Maintain alongside <code>AGENTS.md</code> and the source files listed on each page.</p>
- </div>
- </footer>
- </body>
- </html>
|