vga.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* VGA: VESA LFB (from boot). Shadow buffer, damage-driven flush with a
  2. * per-iteration byte budget (no fixed frame rate). */
  3. #ifndef VGA_H
  4. #define VGA_H
  5. /* Boot video info at 0x600 (written by boot.S in safe conventional memory).
  6. Layout: valid(1) width(2) height(2) pitch(2) bpp(1) lfb_base(4) vram_64k(2) = 14 bytes. */
  7. struct vga_boot_fb_info {
  8. unsigned char valid;
  9. unsigned short width;
  10. unsigned short height;
  11. unsigned short pitch;
  12. unsigned char bpp;
  13. unsigned int lfb_base;
  14. unsigned short vram_64k; /* total VRAM in 64KB blocks (from VBE) */
  15. } __attribute__((packed));
  16. #define VGA_BOOT_FB ((volatile struct vga_boot_fb_info *)0x600)
  17. /* Shadow buffer lives at 1MB — safely above kernel, stacks, DMA, and program load area. */
  18. #define VGA_SHADOW_BASE 0x100000
  19. /* LFB API. RGB 0..255. All drawing goes into the shadow buffer; the main loop
  20. * flushes dirty areas to VRAM on every iteration (byte-budgeted). */
  21. unsigned int vga_fb_width(void);
  22. unsigned int vga_fb_height(void);
  23. unsigned int vga_fb_pitch(void);
  24. unsigned int vga_fb_bpp(void);
  25. unsigned int vga_fb_vram_kb(void);
  26. unsigned int vga_fb_pci_id(void);
  27. void *vga_fb_ptr(void);
  28. /* Physical address of the linear framebuffer (for off-screen VRAM access). */
  29. unsigned long vga_fb_lfb_addr(void);
  30. int vga_has_vesa(void);
  31. void vga_put_pixel_rgb(unsigned int x, unsigned int y, unsigned int r, unsigned int g, unsigned int b);
  32. void vga_fill_rect(unsigned int x, unsigned int y, unsigned int w, unsigned int h,
  33. unsigned int r, unsigned int g, unsigned int b);
  34. void vga_clear_rgb(unsigned int r, unsigned int g, unsigned int b);
  35. /* Tightly packed row-major: each row is w * pixel_bytes contiguous (pixel_bytes from bpp). */
  36. void vga_fb_read_rect(unsigned int x, unsigned int y, unsigned int w, unsigned int h,
  37. unsigned char *buf);
  38. void vga_fb_write_rect(unsigned int x, unsigned int y, unsigned int w, unsigned int h,
  39. const unsigned char *buf);
  40. /* Initialize shadow buffer (called once from kernel_main after vga_cache_boot_fb). */
  41. void vga_shadow_init(void);
  42. /* Copy shadow buffer to VRAM (everything dirty, no budget). Called after
  43. * blocking redraws and at boot. */
  44. void vga_fb_flush(void);
  45. /* Copy up to max_bytes of the dirty shadow rows to VRAM (0 = no limit).
  46. * Called by the main loop every iteration: small updates reach the screen
  47. * within one loop, large ones are chunked so they cannot stall input. */
  48. void vga_fb_flush_budget(unsigned int max_bytes);
  49. /* Per-iteration flush budget: large enough that a window-sized repaint
  50. * (~0.7 MB) is flushed as one frame, small enough that a full-screen repaint
  51. * is chunked instead of stalling input behind it. */
  52. #define VGA_FLUSH_BUDGET_BYTES (1024u * 1024u)
  53. /* Returns 1 if shadow buffer is active, 0 if rendering directly to VRAM. */
  54. int vga_shadow_is_active(void);
  55. /* Mark rows dirty for direct buffer manipulators (e.g. fbtext_scroll). */
  56. void vga_fb_mark_dirty_rect(unsigned int y, unsigned int h);
  57. /* Mark rows dirty, limited to the horizontal span [x0, x1). */
  58. void vga_fb_mark_dirty_rect_xy(unsigned int y, unsigned int h,
  59. unsigned int x0, unsigned int x1);
  60. /* Clear the dirty-row bitmap (so only explicitly re-marked rows get flushed). */
  61. void vga_fb_clear_dirty(void);
  62. #endif