PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
fb.h
Go to the documentation of this file.
1#pragma once
2
3#include <_libstd/MAX_PATH.h>
4#include <kernel/fs/devfs.h>
5#include <kernel/mem/vmm.h>
6
7#include <stdint.h>
8#include <sys/proc.h>
9
10typedef struct fb fb_t;
11
12/**
13 * @brief Framebuffer abstraction.
14 * @defgroup kernel_drivers_abstract_fb Framebuffer Abstraction
15 * @ingroup kernel_drivers_abstract
16 *
17 * Framebuffer devices are exposed as a `/dev/fb/[id]/` directory, containing the below files.
18 *
19 * ## name
20 *
21 * A read-only file that contains the driver defined name of the framebuffer device.
22 *
23 * ## info
24 *
25 * A read-only file that contains information about the framebuffer in the format
26 *
27 * ```
28 * [width] [height] [pitch] [format]
29 * ```
30 *
31 * where `width` and `height` are the integer dimensions of the framebuffer in pixels, `pitch` is the integer number of
32 * bytes per row, and `format` is the pixel format presented as a series of letter number pairs in little-endian order
33 * (starting from the lowest memory address).
34 *
35 * For example, `1920 1080 7680 B8G8R8A8` represents a 1920x1080 framebuffer with a pitch of 7680 bytes in 32-bit ARGB
36 * format.
37 *
38 * ## data
39 *
40 * A readable, writable and mappable file that represents the actual framebuffer memory. Writing to this file updates
41 * the pixels on the screen and reading from it retrieves the current pixel data.
42 *
43 * @{
44 */
45
46/**
47 * @brief Framebuffer information.
48 * @struct fb_info_t
49 */
50typedef struct fb_info
51{
52 size_t width;
53 size_t height;
54 size_t pitch;
56} fb_info_t;
57
58/**
59 * @brief Framebuffer operations.
60 * @struct fb_ops_t
61 */
62typedef struct fb_ops
63{
65 size_t (*read)(fb_t* fb, void* buffer, size_t count, size_t* offset);
66 size_t (*write)(fb_t* fb, const void* buffer, size_t count, size_t* offset);
67 void* (*mmap)(fb_t* fb, void* address, size_t length, size_t* offset, pml_flags_t flags);
68 void (*cleanup)(fb_t* fb);
69} fb_ops_t;
70
71/**
72 * @brief Framebuffer structure.
73 * @struct fb_t
74 */
75typedef struct fb
76{
77 char name[MAX_PATH];
78 const fb_ops_t* ops;
79 void* data;
82} fb_t;
83
84/**
85 * @brief Allocate and initialize a new framebuffer.
86 *
87 * @param name The driver specified name of the framebuffer.
88 * @param ops The operations for the framebuffer.
89 * @param private Private data for the framebuffer.
90 * @return On success, the new framebuffer. On failure, `NULL` and `errno` is set.
91 */
92fb_t* fb_new(const char* name, const fb_ops_t* ops, void* data);
93
94/**
95 * @brief Frees a framebuffer.
96 *
97 * @param fb The framebuffer to free.
98 */
99void fb_free(fb_t* fb);
100
101/** @} */
#define MAX_PATH
Maximum length of filepaths.
Definition MAX_PATH.h:11
EFI_PHYSICAL_ADDRESS buffer
Definition main.c:237
static char format[MAX_NAME]
Definition screen.c:17
static fd_t data
Definition dwm.c:21
fb_t * fb_new(const char *name, const fb_ops_t *ops, void *data)
Allocate and initialize a new framebuffer.
Definition fb.c:134
void fb_free(fb_t *fb)
Frees a framebuffer.
Definition fb.c:214
static fb_ops_t ops
Definition gop.c:80
static fb_t * fb
Definition gop.c:28
static uintptr_t address
Mapped virtual address of the HPET registers.
Definition hpet.c:96
size_t write(fd_t fd, const void *buffer, size_t count)
System call for writing to files.
Definition write.c:8
size_t read(fd_t fd, void *buffer, size_t count)
System call for reading from files.
Definition read.c:8
static uint64_t offset
Definition screen.c:19
static const path_flag_t flags[]
Definition path.c:47
static atomic_long count
Definition main.c:11
__SIZE_TYPE__ size_t
Definition size_t.h:4
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
Directory entry structure.
Definition dentry.h:155
Framebuffer information.
Definition fb.h:51
size_t height
Definition fb.h:53
size_t pitch
Definition fb.h:54
size_t width
Definition fb.h:52
Framebuffer operations.
Definition fb.h:63
uint64_t(* info)(fb_t *fb, fb_info_t *info)
Definition fb.h:64
Framebuffer structure.
Definition fb.h:76
void * data
Definition fb.h:79
dentry_t * dir
Definition fb.h:80
const fb_ops_t * ops
Definition fb.h:78
list_t files
Definition fb.h:81
A doubly linked list.
Definition list.h:46
A entry in a page table without a specified address or callback ID.