The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
display.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file display.h
5 * @brief display drivers: the layer between the fbdev (/dev/fb0) and a
6 * card that can change its mode.
7 *
8 * without a driver, the screen is the framebuffer the bootloader set up,
9 * in one mode. a driver (the Bochs/QEMU VGA, virtio-gpu) can set other
10 * sizes at run time, and can know the size the screen wants (the QEMU
11 * window). /dev/display tells programs when the mode or that size
12 * changes.
13 */
14
15#include "common/stdint.h"
16#include "kernel/memory/phys.h"
17
18/**
19 * a framebuffer in a mode: 32 bits per pixel, x8r8g8b8.
20 */
21typedef struct
22{
23 phys_addr_t phys; // where it is (contiguous)
24 uint8_t *addr; // the kernel's pointer to it
27 uint32_t pitch; // bytes per row
29
30typedef struct
31{
32 const char *name;
33 uint32_t max_width; // the largest mode it can set
35
36 /**
37 * set a mode.
38 * @param out receives the framebuffer of the new mode.
39 * @return false if the size is not possible (the old mode stays).
40 */
42
43 /**
44 * the size the screen wants (optional).
45 * @return false if it does not know.
46 */
47 bool (*preferred)(uint32_t *width, uint32_t *height);
48
49 /**
50 * copy a rect of the framebuffer to the screen (optional: NULL when
51 * the screen shows the memory by itself).
52 */
53 void (*flush)(uint32_t x, uint32_t y, uint32_t width, uint32_t height);
54
55 /**
56 * show a pointer over the framebuffer, drawn by the card (optional).
57 * @param pixels FB_CURSOR_SIZE x FB_CURSOR_SIZE a8r8g8b8, or NULL to
58 * hide the pointer.
59 * @param x where its top left corner goes.
60 * @return false if the card refused.
61 */
62 bool (*cursor_set)(const uint32_t *pixels, uint32_t x, uint32_t y);
63
64 /**
65 * move the pointer's top left corner to x, y (with cursor_set).
66 */
69
70/**
71 * register /dev/display. call once, before the drivers.
72 */
73void display_init(void);
74
75/**
76 * the driver in use, or NULL (the bootloader's framebuffer only).
77 */
79
80/**
81 * use a driver from now on, and set the size the screen wants if it knows
82 * one. call after fb_init.
83 */
84void display_attach(const display_driver_t *driver);
85
86/**
87 * a mode by index for FBIOGET_MODE: the preferred size first, then common
88 * sizes the driver can set.
89 * @return false past the last one.
90 */
91bool display_mode_at(uint32_t index, uint32_t *width, uint32_t *height, bool *preferred);
92
93/**
94 * tell the readers of /dev/display about a change.
95 * @param type FB_EVENT_MODE or FB_EVENT_PREFERRED.
96 */
97void display_event(uint32_t type, uint32_t width, uint32_t height);
98
99/**
100 * the size the screen wants may have changed (a driver's interrupt calls
101 * it). the driver is asked again in process context, when /dev/display is
102 * read or polled.
103 */
const display_driver_t * display_driver(void)
the driver in use, or NULL (the bootloader's framebuffer only).
Definition display.c:119
void display_preferred_changed(void)
the size the screen wants may have changed (a driver's interrupt calls it).
Definition display.c:112
void display_init(void)
register /dev/display.
Definition display.c:296
void display_event(uint32_t type, uint32_t width, uint32_t height)
tell the readers of /dev/display about a change.
Definition display.c:71
void display_attach(const display_driver_t *d)
use a driver from now on, and set the size the screen wants if it knows one.
Definition display.c:124
bool display_mode_at(uint32_t index, uint32_t *width, uint32_t *height, bool *preferred)
a mode by index for FBIOGET_MODE: the preferred size first, then common sizes the driver can set.
Definition display.c:136
unsigned int uint32_t
Definition fb.h:17
unsigned char uint8_t
Definition fb.h:18
uintptr_t phys_addr_t
physical addresses and the conversion between physical and virtual.
Definition phys.h:18
#define bool
Definition stdbool.h:8
Definition display.h:31
uint32_t max_height
Definition display.h:34
void(*) cursor_move(uint32_t x, uint32_t y)
move the pointer's top left corner to x, y (with cursor_set).
Definition display.h:67
uint32_t max_width
Definition display.h:33
const char * name
Definition display.h:32
bool(*) cursor_set(const uint32_t *pixels, uint32_t x, uint32_t y)
show a pointer over the framebuffer, drawn by the card (optional).
Definition display.h:62
bool(*) preferred(uint32_t *width, uint32_t *height)
the size the screen wants (optional).
Definition display.h:47
bool(*) set_mode(uint32_t width, uint32_t height, display_surface_t *out)
set a mode.
Definition display.h:41
void(*) flush(uint32_t x, uint32_t y, uint32_t width, uint32_t height)
copy a rect of the framebuffer to the screen (optional: NULL when the screen shows the memory by itse...
Definition display.h:53
a framebuffer in a mode: 32 bits per pixel, x8r8g8b8.
Definition display.h:22
uint32_t width
Definition display.h:25
uint32_t height
Definition display.h:26
uint8_t * addr
Definition display.h:24
uint32_t pitch
Definition display.h:27
phys_addr_t phys
Definition display.h:23