vga.h 3.2 KB

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