graphics.html 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>Graphics &amp; UI | NebOS Architecture</title>
  7. <meta name="description" content="NebOS graphics architecture: VBE framebuffer, shadow buffer, damage rectangles, blit vtable, window manager, canvas ABI, ngui toolkit and image library.">
  8. <link rel="icon" href="favicon.svg" type="image/svg+xml">
  9. <link rel="stylesheet" href="style.css">
  10. </head>
  11. <body>
  12. <a class="skip" href="#main">Skip to content</a>
  13. <header class="site-header">
  14. <a class="brand" href="index.html">
  15. <span class="brand-mark" aria-hidden="true"></span>
  16. <span>NebOS <span class="brand-sub">Architecture</span></span>
  17. </a>
  18. <nav class="site-nav" aria-label="Architecture sections">
  19. <a href="index.html">Overview</a>
  20. <a href="boot.html">Boot</a>
  21. <a href="memory.html">Memory</a>
  22. <a href="cpu.html">CPU</a>
  23. <a href="drivers.html">Drivers</a>
  24. <a href="filesystems.html">Filesystems</a>
  25. <a href="graphics.html" aria-current="page">Graphics</a>
  26. <a href="network.html">Network</a>
  27. <a href="userland.html">Userland</a>
  28. <a href="development.html">Development</a>
  29. </nav>
  30. </header>
  31. <main id="main" class="page">
  32. <div class="page-head">
  33. <p class="kicker">Graphics &amp; UI</p>
  34. <h1>Draw into a shadow, publish by damage.</h1>
  35. <p class="lede">
  36. The display path is intentionally simple: drawing lands in a RAM
  37. shadow buffer, damage rectangles describe what changed, and a
  38. budgeted flush copies those rectangles to VRAM. Windows add a
  39. compositor and a mapped-canvas ABI on top; a small immediate-mode
  40. toolkit supplies the widgets.
  41. </p>
  42. <div class="meta">
  43. <span class="pill">VBE LFB</span>
  44. <span class="pill">1 MiB flush budget</span>
  45. <span class="pill">8 windows</span>
  46. <span class="pill">RGB565 canvases</span>
  47. </div>
  48. </div>
  49. <nav class="toc" aria-label="On this page">
  50. <h2>On this page</h2>
  51. <ul>
  52. <li><a href="#framebuffer">Framebuffer</a></li>
  53. <li><a href="#shadow">Shadow &amp; damage</a></li>
  54. <li><a href="#blit">Blit backends</a></li>
  55. <li><a href="#wm">Window manager</a></li>
  56. <li><a href="#canvas">Canvas ABI</a></li>
  57. <li><a href="#ngui">ngui toolkit</a></li>
  58. <li><a href="#apps">Applications</a></li>
  59. <li><a href="#images">Image library</a></li>
  60. <li><a href="#gpu">GPU quirks</a></li>
  61. <li><a href="#backlight">Panel backlight</a></li>
  62. <li><a href="#sources">Source map</a></li>
  63. </ul>
  64. </nav>
  65. <section id="framebuffer">
  66. <h2>Framebuffer</h2>
  67. <p>
  68. The boot path writes a <code>struct vga_boot_fb_info</code> to
  69. <code>0x600</code>: LFB base, pitch, width, height, bits per pixel
  70. and an RGBX flag for GOP's byte order. The legacy VESA stage chooses
  71. a mode with at least 16 bpp, a linear framebuffer, it must fit the
  72. card's VRAM, and width at most 1280 pixels. The UEFI loader imposes
  73. its own GOP constraints.
  74. </p>
  75. <p>
  76. <span class="file">vga.c</span> owns the visible surface. On a
  77. normal boot the render target is a RAM shadow buffer at
  78. <code>0x100000</code>, not the LFB; the 8 MB reserve leaves room for
  79. future modes. A surface carries width, height, pitch, format and a
  80. pixel-pointer, so the same drawing code can target a window layer or
  81. a canvas.
  82. </p>
  83. </section>
  84. <section id="shadow">
  85. <h2>Shadow buffer &amp; damage</h2>
  86. <p>
  87. Drawing never writes VRAM directly. Each operation records a damage
  88. rectangle; overlapping or touching rectangles merge, so a keystroke's
  89. cells collapse into one small rect while unrelated damage stays
  90. apart. The main loop calls <code>vga_present_shadow()</code> on every
  91. iteration with a byte budget of <code>VGA_FLUSH_BUDGET_BYTES</code>
  92. (1 MiB by default).
  93. </p>
  94. <ul>
  95. <li><strong>Small rects copy whole.</strong> A window repaint within the budget never tears.</li>
  96. <li><strong>Large rects are chunked.</strong> A full-screen redraw continues across loop iterations; newer damage is queued behind it.</li>
  97. <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>
  98. <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>
  99. <li><strong>Window drags flush immediately.</strong> <code>wm_drag_shadow</code> copies each drag step as one consistent frame.</li>
  100. </ul>
  101. <p>
  102. When the target is not the screen — a window layer or an app canvas —
  103. <code>vga_target_damage()</code> is a no-op. The render target
  104. override is stored in the PCB, so a preempted draw cannot leak into
  105. another process's window.
  106. </p>
  107. </section>
  108. <section id="blit">
  109. <h2>Blit backends</h2>
  110. <p>
  111. <span class="file">blit.c</span> is the pixel-operation vtable:
  112. fill, copy, blend, canvas, present and flip. Software is the only
  113. backend today, but the WM calls the vtable rather than a fixed
  114. function, so an accelerator can replace individual operations
  115. without touching window logic.
  116. </p>
  117. <p>
  118. The software fill uses an SSE2 row store when the CPU supports it.
  119. Rows that do not fit the cache use streaming stores
  120. (<code>movntdq</code>, one <code>sfence</code> per fill), which
  121. avoids read-for-ownership traffic that makes large fills DRAM-bound
  122. on the Atom. SSE/SSE2 are never assumed: the kernel is built with
  123. <code>-mno-sse</code>, and <code>cpu_has_sse2()</code> probes CPUID,
  124. sets <code>CR4.OSFXSR/OSXMMEXCPT</code> and is re-run on every AP.
  125. </p>
  126. <p>
  127. <code>gfxbench</code> times fill, copy, cell, canvas and flush paths
  128. and reports the bytes actually copied by the presenter.
  129. </p>
  130. </section>
  131. <section id="wm">
  132. <h2>Window manager</h2>
  133. <p>
  134. The WM is a process that owns the desktop and a fixed array of eight
  135. windows. It draws a system bar with the banner, launcher buttons,
  136. clock, the temperature, and, on ThinkPads and Chromebooks, an
  137. AC/battery status icon at the far right (a plug on AC, a
  138. level-filled battery on battery, with a percentage tooltip below
  139. the bar on hover, painted above the windows), plus draggable
  140. terminal and canvas windows with a title bar and close button.
  141. Click-to-focus, drag-by-title-bar and close are routed through the
  142. same pointer path. To the left of the rightmost AC/battery status
  143. icon, a network status icon shows a
  144. cable for wired Ethernet, signal bars for a connected WiFi link, a
  145. USB mark for RNDIS tethering, or a red X when no link is up.
  146. The whole right status area — temperature, date/time, network
  147. and AC/battery items plus the gaps between them — is one button:
  148. it opens the anchored <code>bin/netmenu</code> control panel (a
  149. second click closes it).
  150. It opens collapsed: the battery/clock summary and Quick settings
  151. pills are visible, while the network, power-mode and date/time
  152. settings stay hidden until their pill is clicked. Present NICs
  153. can then be selected (DHCP runs), and scanned WiFi networks can be
  154. joined, asking for the WPA2 passphrase first when the AP requires
  155. one.
  156. </p>
  157. <p>
  158. A popover is a chromeless canvas window created with
  159. <code>u_win_create_popover()</code> (<code>WIN_F_POPOVER</code>).
  160. The WM anchors it flush under the top bar at the right screen
  161. edge, treats it as always topmost in painting and hit-testing,
  162. and draws no chrome at all:
  163. the canvas fills the whole window rectangle, with no title bar,
  164. shadow, rim or rounded outer corners, so it reads as a flat menu
  165. panel. The kernel uses the window origin for content-relative
  166. pointer and scroll coordinates. An outside press dismisses the
  167. popover and the click then continues normally; a second click on
  168. any status target toggles it. The panel itself is drawn with the
  169. ngui components: a battery/AC and clock summary, a brightness
  170. slider when the panel PWM is present, and Quick settings tiles for
  171. Network, the CPU power mode (<code>SYS_CPUFREQ</code>) and Date
  172. &amp; Time. Clicking a tile expands that section in place — the
  173. network devices/Wi-Fi/connection lists, the three power modes, or
  174. an inline date/time editor with Set, Now and Sync NTP (no separate
  175. window). <code>SYS_WIN_RESIZE_SELF</code> grows or shrinks the
  176. popover to the section, clamped to <code>SYS_SCREEN_INFO</code>'s
  177. framebuffer; the section scrolls when it is taller than the screen.
  178. </p>
  179. <p>
  180. The WM is the ring-3 process loaded from
  181. <code>/ramfs/bin/wm</code>; there is no kernel WM fallback. The
  182. kernel window server in <span class="file">wm.c</span> owns the
  183. shadow mapping, the per-window canvases, input routing, the cursor,
  184. kexec detection and the boot-console handoff. It starts the first
  185. terminal after the storage mount
  186. (<code>wm_server_boot_ready</code>) and leaves the boot console
  187. visible until the WM attaches.
  188. </p>
  189. <figure class="figure">
  190. <svg viewBox="0 0 920 260" role="img" aria-labelledby="wm-title wm-desc">
  191. <title id="wm-title">Window anatomy</title>
  192. <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>
  193. <rect class="svg-box" x="70" y="22" width="780" height="200" rx="10"/>
  194. <rect class="svg-box accent" x="70" y="22" width="780" height="34" rx="10"/>
  195. <text class="svg-text" x="88" y="45">Terminal · /ramfs/bin/ls</text>
  196. <text class="svg-text" x="800" y="45">×</text>
  197. <rect class="svg-box green" x="86" y="72" width="748" height="132" rx="6"/>
  198. <text class="svg-text" x="104" y="98">content canvas · RGB565 · mapped at 0x50000000</text>
  199. <text class="svg-sub" x="104" y="120">text cells, images, widgets, or arbitrary drawing</text>
  200. </svg>
  201. <figcaption>
  202. <strong>One window, one canvas.</strong> The title bar belongs to
  203. the WM; the content is whatever the owning process draws into its
  204. mapped back buffer. The WM never reads the process's memory — it
  205. composites the front canvas on <code>PRESENT</code>.
  206. </figcaption>
  207. </figure>
  208. <ul>
  209. <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>
  210. <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>
  211. <li><strong>Focus and z-order</strong> are explicit; closing a window kills its session and frees its canvas.</li>
  212. </ul>
  213. <h3>Compositing cost</h3>
  214. <p>
  215. The WM keeps a front-to-back order: the focused window first, then
  216. the remaining windows in descending slot order. For each damage
  217. rectangle it fills the desktop once and walks that order, subtracting
  218. every window in front from the region still uncovered. A window is
  219. drawn only in its exposed pieces, so a fully occluded window costs
  220. nothing and the stack is never repainted back-to-front. The kernel
  221. pointer hit-test uses the same order. A focused-window drag copies
  222. its shadow block to the new position and repaints only the old
  223. strips the new rectangle does not cover, instead of compositing the
  224. window at both positions. If either rectangle is partly off-screen
  225. the shadow has no valid pixels for the hidden part, so that step
  226. repaints the window rect instead of copying desktop background into
  227. it.
  228. </p>
  229. <p>
  230. <code>SYS_WIN_PRESENT</code> carries a content-relative damage
  231. rectangle. The terminal tracks its dirty rows, so a keystroke copies
  232. and composites one 8×16 row block instead of the whole 512×512
  233. canvas. The kernel unions the rectangles between WM polls and
  234. <code>SYS_WM_INFO</code> returns that union; a present with
  235. <code>w == 0</code> or <code>h == 0</code> still means the whole
  236. canvas. The WM overwrites <code>/share/wmstats</code> every two
  237. seconds with the interval's frame count, compositing time, worst
  238. frame and pixels drawn (<code>usurf_pixels</code>), which is the
  239. on-target compositor measurement.
  240. </p>
  241. </section>
  242. <section id="canvas">
  243. <h2>Canvas ABI</h2>
  244. <p>
  245. <code>SYS_WIN_CREATE</code> maps the calling command's window canvas
  246. read/write at <code>0x50000000</code>. The process draws RGB565
  247. pixels and publishes a finished frame with
  248. <code>SYS_WIN_PRESENT</code>, optionally passing a content-relative
  249. rectangle (<code>struct wm_win_present</code>) for the changed
  250. region. Present copies that region from the back buffer into the
  251. composited front canvas with interrupts off, so a half-drawn frame
  252. can never reach the screen. Frames carry monotonic sequence
  253. counters, so the WM cannot lose one. <code>content_gen</code> comes
  254. from a global counter and is unique per window creation, so a new
  255. window that reuses a just-closed slot forces the WM to remap its
  256. front canvas instead of reusing a stale mapping.
  257. </p>
  258. <p>
  259. <code>SYS_WIN_CREATE</code> creates a generic canvas window.
  260. <code>struct win_create.flags</code> can request
  261. <code>WIN_F_POPOVER</code>, a chromeless overlay: the canvas fills
  262. the window and the WM supplies only the topmost placement.
  263. <code>SYS_WIN_RESIZE_SELF</code> (115) resizes the caller's canvas
  264. and <code>SYS_SCREEN_INFO</code> (116) reports the framebuffer
  265. size, so a popover can collapse or grow. Input is exposed through
  266. <code>SYS_WIN_POINTER</code>
  267. (content-relative position, button mask, focus),
  268. <code>SYS_WIN_EVENT</code>, which
  269. queues press/release edges and a capture window, and
  270. <code>SYS_WIN_SCROLL</code>, which returns wheel/touchpad scroll
  271. accumulated for the window under the pointer in pixels
  272. (<code>+dy</code> is later content). A click that starts
  273. in a window still receives its release after the pointer leaves.
  274. The ngui helper <code>ngui_scroll_wheel()</code> applies the delta
  275. to a pane when the pointer is over it.
  276. The WM process itself is special: it maps the screen shadow at
  277. <code>0x58000000</code> and each front canvas at
  278. <code>0x59000000 + index × 4 MB</code>, which is how it composites
  279. without reading another process's memory. The 4 MB slot covers a
  280. full-screen 1280×1024 canvas minus the chrome; the old 2 MB slot
  281. capped a full-height window at roughly 1050 px wide.
  282. <code>SYS_WM_RESIZE</code> (WM side) and
  283. <code>SYS_WIN_ACK_RESIZE</code> (client side) swap in a resized
  284. canvas; the content size is bounded by the framebuffer, so a
  285. window can grow to the edge of the screen.
  286. </p>
  287. <p>
  288. Double-clicking a title bar maximizes the window to the work area
  289. below the system bar (<code>0, WM_BAR_H, fbw, fbh - WM_BAR_H</code>);
  290. the next double-click restores the saved geometry. Dropping a
  291. title-bar drag with the pointer on the left or right screen edge
  292. (<code>WM_SNAP_EDGE</code>, 2 px) snaps the window to that half of
  293. the work area at full height, and the top edge maximizes it. The
  294. restore geometry is saved only when a window leaves the normal state,
  295. so snapping and then maximizing still restores the original size.
  296. Dragging a maximized or snapped window restores it first, with the
  297. grab point kept at the same fraction of the title bar, and a manual
  298. resize clears the state. While a window is dragged, the screen edges
  299. and the facing edges of other windows resist it: the window stays
  300. flush until the pointer overshoots by <code>WM_RESIST</code> (24 px),
  301. which makes side-by-side placement exact. Windows can be dragged past the left, right and
  302. bottom edges; <code>WM_DRAG_VISIBLE</code> (48 px) of the title bar
  303. always stays on-screen for recovery, and the top bar is never
  304. overlapped. The resize grip is clamped to the full work area and
  305. snaps to it when dragged into the screen corner.
  306. </p>
  307. <div class="note">
  308. <p><strong>Buttons fire on the release edge.</strong> The toolkit keeps
  309. a button <code>active</code> until <code>ui-&gt;released</code>;
  310. inferring release from the sampled button mask races the WM event
  311. queue and drops clicks.</p>
  312. </div>
  313. <p>
  314. When a process exits or crashes, the reaper releases its window
  315. mappings and the window server frees the canvas. Closing a window
  316. kills its owner. Keys go through the window key queue
  317. (<code>SYS_WIN_KEY_WAIT</code>) or the generic
  318. <code>SYS_KEY_POLL</code>; Ctrl+C still reaches the terminal.
  319. </p>
  320. </section>
  321. <section id="ngui">
  322. <h2>ngui toolkit</h2>
  323. <p>
  324. <span class="file">ngui.c</span>/<span class="file">ngui.h</span> is an
  325. immediate-mode GUI toolkit shared by the ring-3 apps. It provides
  326. clipped RGB565 primitives, buttons, menu items, text fields, nine
  327. procedural icons, a theme palette, layout cut helpers and scrolling
  328. panes. It is linked into <code>files</code>, <code>mines</code>,
  329. <code>solitaire</code>, <code>chat</code>, the control panel and
  330. the real <code>gallery.elf</code>.
  331. </p>
  332. <ul>
  333. <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>
  334. <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>
  335. <li><strong>Clip stack</strong> keeps nested panes and popups inside their parents.</li>
  336. <li><strong>Layout cuts</strong> split a rectangle into rows, columns and fixed margins without a constraint solver.</li>
  337. <li><strong>No retained widget tree.</strong> Apps redraw from state every frame, which keeps the toolkit small and predictable.</li>
  338. </ul>
  339. <p>
  340. Proportional text comes from <span class="file">ufont.c</span>: a
  341. fixed-point, integer-only TrueType parser and antialiased rasterizer.
  342. The pack carries Latin-1 Arimo regular/bold/italic/bold-italic,
  343. Liberation Mono and a curated monochrome Noto Emoji subset under
  344. <code>/ramfs/fonts</code>. The browser, ngui apps and the WM chrome
  345. use real pixel sizes from 8 to 48 px; the browser maps CSS
  346. <code>font-size</code>, <code>font-weight</code>,
  347. <code>font-style</code> and <code>font-family: monospace</code> to
  348. the faces. Missing fonts fall back to the 8×16 bitmap. The browser
  349. detaches the font arena before <code>heap_reset()</code> and
  350. reattaches after <code>heap_start()</code>; terminal content and
  351. the editor keep the bitmap cells.
  352. </p>
  353. <p>
  354. UTF-8 text is available through <code>ngui_text_utf8*</code> and
  355. <code>ngui_menu_item_utf8()</code>. Per codepoint, the selected
  356. primary face is tried first, then the lazily loaded emoji face;
  357. cmap format 12 covers codepoints above the BMP. The emoji set is
  358. deliberately limited to common single-codepoint glyphs that fit the
  359. rasterizer's 256-point/16-contour limits. ZWJ sequences, flags,
  360. skin tones and color glyphs fall back to a tofu or
  361. <code>?</code>; the browser keeps its Latin-1 byte path.
  362. </p>
  363. </section>
  364. <section id="apps">
  365. <h2>Applications</h2>
  366. <div class="grid">
  367. <div class="card">
  368. <h3>files</h3>
  369. <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>
  370. </div>
  371. <div class="card">
  372. <h3>gallery</h3>
  373. <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>
  374. </div>
  375. <div class="card">
  376. <h3>chat</h3>
  377. <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. The top-bar <em>Chat</em> button launches it.</p>
  378. </div>
  379. <div class="card">
  380. <h3>solitaire</h3>
  381. <p>Klondike with drag-and-drop, draw-one/three, scoring, animation and pixel-art cards on the canvas service.</p>
  382. </div>
  383. <div class="card">
  384. <h3>view</h3>
  385. <p>Image viewer with fit, 1:1, zoom, pan, EXIF orientation and animated GIF playback.</p>
  386. </div>
  387. <div class="card">
  388. <h3>clock / colors / settime</h3>
  389. <p>Small canvas demos: an analog clock, a colour test window, and the standalone Date &amp; Time editor (<code>settime</code>). The control panel's Date &amp; Time tile reveals its own inline editor, which reads and writes the CMOS RTC and can fetch UTC from an SNTP server.</p>
  390. </div>
  391. <div class="card">
  392. <h3>browser</h3>
  393. <p>HTML/CSS renderer with flex rows, auto-fit card grids, inline-block runs, basic tables and inline SVG diagrams. It decodes inline images and fetches through a headless helper; 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>
  394. </div>
  395. </div>
  396. </section>
  397. <section id="images">
  398. <h2>Image library</h2>
  399. <p>
  400. The codecs are independent of the OS and the toolkit: each takes an
  401. input buffer plus a caller-provided <code>struct img_mem</code> arena
  402. and returns an RGB565 image with an optional 8-bit alpha plane. The
  403. browser and the chat client link the same objects and decode HTTP
  404. bodies in memory.
  405. </p>
  406. <ul>
  407. <li><strong>Formats.</strong> PNG, baseline and progressive JPEG, animated GIF, BMP, TGA, PNM, ICO/CUR and PAM.</li>
  408. <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.</li>
  409. <li><strong>Orientation.</strong> EXIF orientation is applied; arithmetic JPEG and CMYK are rejected.</li>
  410. <li><strong>Cost.</strong> Downscaling runs on the CPU. The viewer caches one image; the browser keeps a display bitmap but still rescales on repaint; the chat client caches up to 480x320 message images and 32x32 circular avatars.</li>
  411. </ul>
  412. </section>
  413. <section id="gpu">
  414. <h2>GPU quirks</h2>
  415. <ul>
  416. <li><strong>ATI Mach64.</strong> A CRTC fixup is applied after mode set. The legacy CRTC is skipped under UEFI.</li>
  417. <li><strong>NVIDIA.</strong> VBE-only. The legacy VGA CRTC is never touched. 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.</li>
  418. <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>
  419. <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>
  420. </ul>
  421. </section>
  422. <section id="backlight">
  423. <h2>Panel backlight</h2>
  424. <p>
  425. The HP Chromebook 11 G5 (<code>google/setzer</code>, Braswell)
  426. drives its internal panel PWM from the display engine, not from
  427. the Chrome EC. The board VBT (<code>data.vbt</code>, block 43)
  428. declares PWM controller 0 at 200 Hz, active high. Linux uses the
  429. same Valleyview/Cherryview registers through
  430. <code>intel_backlight</code>.
  431. </p>
  432. <ul>
  433. <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>
  434. <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>
  435. <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>
  436. <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>
  437. <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>
  438. </ul>
  439. </section>
  440. <section id="sources">
  441. <h2>Source map</h2>
  442. <ul class="filelist">
  443. <li><code>vga.c</code>, <code>vga.h</code> — framebuffer and damage</li>
  444. <li><code>vga_copy.S</code> — copy primitives</li>
  445. <li><code>blit.c</code>, <code>blit.h</code> — pixel vtable</li>
  446. <li><code>cpu.c</code> — SSE2 probing</li>
  447. <li><code>wm.c</code>, <code>wm.h</code>, <code>wm_abi.h</code> — kernel window server and shared ABI</li>
  448. <li><code>ucmd_wm.c</code>, <code>uwm_lib.c</code> — ring-3 WM</li>
  449. <li><code>ucmd_netmenu.c</code> — top-bar control panel (network/WiFi, brightness, power mode, Date &amp; Time)</li>
  450. <li><code>ucmd_settime.c</code>, <code>rtc.c</code>, <code>ntp.c</code> — Date &amp; Time editor, RTC access and SNTP sync</li>
  451. <li><code>gfx.c</code>, <code>gfx.h</code> — RGB565 window canvases</li>
  452. <li><code>sys_wm.c</code>, <code>sys_wm.h</code> — WM/window ABI</li>
  453. <li><code>browser.c</code>, <code>browser_html.c</code> — HTML/CSS renderer and inline SVG</li>
  454. <li><code>ngui.c</code>, <code>ngui.h</code> — toolkit</li>
  455. <li><code>ufont.c</code>, <code>ufont_ttf.c</code>, <code>ufont_draw.c</code> — fixed-point TrueType text</li>
  456. <li><code>fonts/*.ttf</code> — Arimo / Liberation Mono / Noto Emoji subsets in the pack</li>
  457. <li><code>ucmd_files.c</code>, <code>gallery.c</code>, <code>ucmd_solitaire.c</code>, <code>ucmd_chat.c</code></li>
  458. <li><code>img*.c</code> — image codecs</li>
  459. <li><code>ati.c</code>, <code>nvidia.c</code>, <code>intel.c</code>, <code>nv50.c</code></li>
  460. <li><code>backlight.c</code>, <code>backlight.h</code> — Cherryview/VLV panel PWM</li>
  461. </ul>
  462. </section>
  463. </main>
  464. <footer class="site-footer">
  465. <div class="inner">
  466. <p><strong>NebOS 0.2.0</strong> · Architecture documentation · <a href="index.html">overview</a></p>
  467. <p>Maintain alongside <code>AGENTS.md</code> and the source files listed on each page.</p>
  468. </div>
  469. </footer>
  470. </body>
  471. </html>