code wiki / _hdl_build / nx_browser_render_pe.nx
nx_browser_render_pe.nx source
↩ module page · 37 lines · 1641 B
1// nx_browser_render_pe.nx -- R2/R3 proof: run the EXTRACTED CSS render organ (br_layout cascade+box-layout,
2// br_draw_fb framebuffer paint) as a NATIVE WINDOWS PE. Reads _offc/nxhtml.html, lays it out, paints into an
3// RGBA framebuffer, swaps to BGRA (Windows DIB order), and dumps the raw pixels to stdout (SW*SH*4 bytes) so
4// a Windows-side blit can PNG it. Built through the fetch keystone (file-read + write + mmap thunks already
5// present). Proves the layout+paint compiles + runs off-X11 on metal, the foundation for the GUI integration.
6import "nx_browser_render.nx"
7
8func main() -> i64 {
9 let lp: *i64 = sys_mmap(16) as *i64
10 let html: *u8 = sys_read_file("_offc/nxhtml.html\x00" as *u8, lp)
11 let hlen: i64 = lp[0]
12 if hlen <= 0 { sys_write(2, "render_pe: no _offc/nxhtml.html\n\x00" as *u8, 31); return 1 }
13
14 let page: *Page = sys_mmap(NX_PAGE_BYTES) as *Page
15 page.raw = html
16 page.raw_len = hlen
17 br_layout(page, 1000)
18 if page.ok != 1 { sys_write(2, "render_pe: layout failed\n\x00" as *u8, 25); return 2 }
19
20 let SW: i64 = 1000
21 let SH: i64 = 1000
22 let fb: *Framebuffer = sys_mmap(NX_FRAMEBUFFER_BYTES) as *Framebuffer
23 let px: *u8 = sys_mmap(SW * SH * 4 + 64)
24 nx_framebuffer_init(fb, px, SW, SH)
25 br_draw_fb(fb, page, SW, "native PE\x00" as *u8, 9, 1)
26
27 // RGBA -> BGRA in place (Windows 32bpp DIB byte order) so the host can Marshal.Copy straight into a bitmap
28 var p: i64 = 0
29 while p < SW * SH {
30 let t: i64 = px[p*4+0] & 0xff
31 px[p*4+0] = px[p*4+2]
32 px[p*4+2] = t as u8
33 p = p + 1
34 }
35 sys_write(1, px, SW * SH * 4)
36 return 0
37}