| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- /* VGA: VESA LFB (from boot). Shadow buffer; the main loop copies pending
- * damage rectangles to VRAM on every iteration (byte budget, no fixed frame
- * rate). */
- #ifndef VGA_H
- #define VGA_H
- /* Boot video info at 0x600 (written by boot.S in safe conventional memory).
- Layout: valid(1) width(2) height(2) pitch(2) bpp(1) lfb_base(4) vram_64k(2) = 14 bytes. */
- struct vga_boot_fb_info {
- unsigned char valid;
- unsigned short width;
- unsigned short height;
- unsigned short pitch;
- unsigned char bpp;
- unsigned int lfb_base;
- unsigned short vram_64k; /* total VRAM in 64KB blocks (from VBE) */
- } __attribute__((packed));
- #define VGA_BOOT_FB ((volatile struct vga_boot_fb_info *)0x600)
- /* Shadow buffer lives at 1MB — safely above kernel, stacks, DMA, and program load area. */
- #define VGA_SHADOW_BASE 0x100000
- /* LFB API. RGB 0..255. All drawing goes into the shadow buffer; the main loop
- * flushes dirty areas to VRAM on every iteration (byte-budgeted). These
- * describe the *screen*, not the current render target (see below). */
- unsigned int vga_fb_width(void);
- unsigned int vga_fb_height(void);
- unsigned int vga_fb_pitch(void);
- unsigned int vga_fb_bpp(void);
- unsigned int vga_fb_vram_kb(void);
- unsigned int vga_fb_pci_id(void);
- void *vga_fb_ptr(void);
- /* Physical address of the linear framebuffer (for off-screen VRAM access). */
- unsigned long vga_fb_lfb_addr(void);
- int vga_has_vesa(void);
- /* A drawing surface: the screen's shadow buffer, a window layer or a canvas.
- * Drawing helpers paint into the *current render target*, which is the screen
- * unless process_set_render_target() pointed this process at a surface. */
- struct surface {
- unsigned char *px;
- unsigned int w, h;
- unsigned int pitch;
- unsigned int bpp; /* 16, 24 or 32 */
- /* Alpha written into the high byte of 32 bpp pixels. The screen uses
- * 255 (the byte is padding there); a window layer sets what its
- * background fill should composite with, while glyph foregrounds are
- * always written opaque. */
- unsigned char alpha;
- };
- /* The screen surface (shadow buffer, or the LFB when there is no shadow). */
- struct surface *vga_screen_surface(void);
- /* Current render target for this process: the screen by default. */
- struct surface *vga_target(void);
- void vga_set_target(struct surface *s);
- int vga_target_is_screen(void);
- /* Mark a rectangle of the screen dirty. A no-op while the target is not the
- * screen: drawing into a layer must not touch the screen's damage list, the
- * compositor marks the rects it copies out. */
- void vga_target_damage(unsigned int x, unsigned int y, unsigned int w,
- unsigned int h);
- /* The software presenter used by the blit backend: copies up to max_bytes of
- * the pending damage rects from the shadow buffer to VRAM. */
- void vga_present_shadow(unsigned int max_bytes);
- /* 1 when VRAM writes go through a write-combining path (the stolen-VRAM
- * alias on ION-class hardware, where the PCIe aperture is UC no matter what
- * the MTRR says). */
- int vga_fb_lfb_wc(void);
- /* Bytes the presenter has copied in total (lets a benchmark measure the real
- * work even when the flush is skipped because another process is in one). */
- extern unsigned int vga_present_copied;
- void vga_put_pixel_rgb(unsigned int x, unsigned int y, unsigned int r, unsigned int g, unsigned int b);
- void vga_fill_rect(unsigned int x, unsigned int y, unsigned int w, unsigned int h,
- unsigned int r, unsigned int g, unsigned int b);
- void vga_clear_rgb(unsigned int r, unsigned int g, unsigned int b);
- /* Tightly packed row-major: each row is w * pixel_bytes contiguous (pixel_bytes from bpp). */
- void vga_fb_read_rect(unsigned int x, unsigned int y, unsigned int w, unsigned int h,
- unsigned char *buf);
- void vga_fb_write_rect(unsigned int x, unsigned int y, unsigned int w, unsigned int h,
- const unsigned char *buf);
- /* Initialize shadow buffer (called once from kernel_main after vga_cache_boot_fb). */
- void vga_shadow_init(void);
- /* Copy shadow buffer to VRAM (everything dirty, no budget). Called after
- * blocking redraws and at boot. */
- void vga_fb_flush(void);
- /* Copy up to max_bytes of the pending damage rects to VRAM (0 = no limit).
- * Called by the main loop every iteration: small updates reach the screen
- * within one loop, large ones are chunked so they cannot stall input. */
- void vga_fb_flush_budget(unsigned int max_bytes);
- /* Low-level row helpers from vga_copy.S (the blit backend uses the fill). */
- void vga_fb_copy_row(void *dst, const void *src, unsigned int dwords);
- void vga_fb_copy_row_nt(void *dst, const void *src, unsigned int dwords);
- void vga_fb_fill_row_sse2(void *dst, unsigned int value, unsigned int dwords);
- void vga_fb_fill_row_nt(void *dst, unsigned int value, unsigned int dwords);
- /* Per-iteration flush budget: large enough that a window-sized repaint
- * (~0.7 MB) is flushed as one frame, small enough that a full-screen repaint
- * is chunked instead of stalling input behind it. */
- #define VGA_FLUSH_BUDGET_BYTES (1024u * 1024u)
- /* Returns 1 if shadow buffer is active, 0 if rendering directly to VRAM. */
- int vga_shadow_is_active(void);
- /* Mark rows dirty for direct buffer manipulators (e.g. fbtext_scroll). */
- void vga_fb_mark_dirty_rect(unsigned int y, unsigned int h);
- /* Mark a rectangle dirty, limited to the horizontal span [x0, x1). */
- void vga_fb_mark_dirty_rect_xy(unsigned int y, unsigned int h,
- unsigned int x0, unsigned int x1);
- /* Drop all pending damage (so only explicitly re-marked areas get flushed). */
- void vga_fb_clear_dirty(void);
- #endif
|