The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
Loading...
Searching...
No Matches
fb.h
Go to the documentation of this file.
1
#pragma once
2
3
/**
4
* @file fb.h
5
* @brief linear framebuffer driver.
6
*
7
* a pixel-pushing driver for the VBE linear framebuffer described in
8
* boot_info_t (see the FB0 bootloader work). it is the framebuffer equivalent
9
* of the raw VGA text driver: it knows nothing about fonts, terminals, or ANSI
10
* only pixels and rectangles. higher layers (the font renderer, the tty
11
* backend) build on top of it.
12
*
13
* pixels are composed from the channel masks the boot protocol reported, so
14
* the driver works for whatever RGB packing the mode uses (24- or 32-bpp)
15
* rather than assuming a fixed 0x00RRGGBB layout.
16
*/
17
18
#include "
common/stdint.h
"
19
#include "
kernel/memory/phys.h
"
20
#include "
common/boot/boot_info.h
"
21
22
/**
23
* framebuffer geometry and pixel format, filled by fb_init().
24
*/
25
typedef
struct
26
{
27
uint8_t
*
addr
;
// framebuffer base, mapped with ioremap.
28
phys_addr_t
phys
;
// physical address of the framebuffer.
29
uint32_t
width
;
// width in pixels.
30
uint32_t
height
;
// height in pixels.
31
uint32_t
pitch
;
// bytes per scanline (may exceed width * bytes_per_pixel).
32
uint8_t
bpp
;
// bits per pixel (24 or 32).
33
uint8_t
bytes_pp
;
// bytes per pixel (3 or 4).
34
uint8_t
red_size
,
red_shift
;
// how the red channel sits in a pixel.
35
uint8_t
green_size
,
green_shift
;
// how the green channel sits in a pixel.
36
uint8_t
blue_size
,
blue_shift
;
// how the blue channel sits in a pixel.
37
}
fb_info_t
;
38
39
/**
40
* initialize the framebuffer from the boot info and map it into the address
41
* space. must be called after paging_init(), since the framebuffer lives at a
42
* high physical address outside the identity-mapped RAM range.
43
* @param boot the boot information from the bootloader.
44
* @return true if a usable framebuffer was set up, false if none is present.
45
*/
46
bool
fb_init
(
const
boot_info_t
*boot);
47
48
/**
49
* whether fb_init() found and mapped a framebuffer.
50
*/
51
bool
fb_available
(
void
);
52
53
/**
54
* read-only view of the framebuffer geometry/format. valid after fb_init()
55
* returns true.
56
*/
57
const
fb_info_t
*
fb_get_info
(
void
);
58
59
/**
60
* compose a pixel value from 8-bit r/g/b according to the framebuffer masks.
61
* @return the packed pixel, ready to store at a pixel address.
62
*/
63
uint32_t
fb_pack_rgb
(
uint8_t
r,
uint8_t
g,
uint8_t
b);
64
65
/**
66
* write one pixel. out-of-bounds coordinates are ignored.
67
* @param x column, @param y row, @param pixel packed pixel from fb_pack_rgb().
68
*/
69
void
fb_put_pixel
(
uint32_t
x,
uint32_t
y,
uint32_t
pixel);
70
71
/**
72
* fill a rectangle with a packed pixel value. clipped to the framebuffer.
73
*/
74
void
fb_fill_rect
(
uint32_t
x,
uint32_t
y,
uint32_t
w,
uint32_t
h,
uint32_t
pixel);
75
76
/**
77
* clear the whole framebuffer to a packed pixel value.
78
*/
79
void
fb_clear
(
uint32_t
pixel);
80
81
/**
82
* copy a rectangle from one position to another (used for scrolling).
83
* source and destination may overlap vertically; rows are copied in an order
84
* that is safe for an upward move (dst_y < src_y).
85
*/
86
void
fb_copy_rect
(
uint32_t
dst_x,
uint32_t
dst_y,
uint32_t
src_x,
uint32_t
src_y,
uint32_t
w,
87
uint32_t
h);
88
89
/**
90
* push all pending drawing to the visible framebuffer.
91
*
92
* when a back buffer is in use, drawing ops render into RAM and mark dirty
93
* scanlines; this copies the dirty range out to the (slow, uncached) linear
94
* framebuffer in one pass. cheap to call after every batch of output. a no-op
95
* when running unbuffered.
96
*/
97
void
fb_flush
(
void
);
98
99
/**
100
* give the screen back to the console (FBIO_GRAPHICS): the next fb_flush
101
* draws the whole console again. a kernel panic calls it.
102
*/
103
void
fb_release_graphics
(
void
);
104
105
/**
106
* change the mode with the display driver (32 bits per pixel). the text
107
* grid stays as it is; what does not fit is not drawn.
108
* @return false without a driver, or if the driver cannot set the size.
109
*/
110
bool
fb_set_mode
(
uint32_t
width,
uint32_t
height);
boot_info.h
stdint.h
fb_flush
void fb_flush(void)
push all pending drawing to the visible framebuffer.
Definition
fb.c:675
fb_set_mode
bool fb_set_mode(uint32_t width, uint32_t height)
change the mode with the display driver (32 bits per pixel).
Definition
fb.c:696
fb_release_graphics
void fb_release_graphics(void)
give the screen back to the console (FBIO_GRAPHICS): the next fb_flush draws the whole console again.
Definition
fb.c:664
fb_clear
void fb_clear(uint32_t pixel)
clear the whole framebuffer to a packed pixel value.
Definition
fb.c:603
fb_pack_rgb
uint32_t fb_pack_rgb(uint8_t r, uint8_t g, uint8_t b)
compose a pixel value from 8-bit r/g/b according to the framebuffer masks.
Definition
fb.c:533
fb_available
bool fb_available(void)
whether fb_init() found and mapped a framebuffer.
Definition
fb.c:509
fb_put_pixel
void fb_put_pixel(uint32_t x, uint32_t y, uint32_t pixel)
write one pixel.
Definition
fb.c:558
fb_get_info
const fb_info_t * fb_get_info(void)
read-only view of the framebuffer geometry/format.
Definition
fb.c:514
fb_fill_rect
void fb_fill_rect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t pixel)
fill a rectangle with a packed pixel value.
Definition
fb.c:569
fb_copy_rect
void fb_copy_rect(uint32_t dst_x, uint32_t dst_y, uint32_t src_x, uint32_t src_y, uint32_t w, uint32_t h)
copy a rectangle from one position to another (used for scrolling).
Definition
fb.c:613
fb_init
bool fb_init(const boot_info_t *boot)
initialize the framebuffer from the boot info and map it into the address space.
Definition
fb.c:449
uint32_t
unsigned int uint32_t
Definition
fb.h:17
uint8_t
unsigned char uint8_t
Definition
fb.h:18
phys.h
phys_addr_t
uintptr_t phys_addr_t
physical addresses and the conversion between physical and virtual.
Definition
phys.h:18
boot_info_t
information the bootloader hands to the kernel.
Definition
boot_info.h:21
fb_info_t
framebuffer geometry and pixel format, filled by fbinfo().
Definition
fb.h:26
fb_info_t::bpp
uint32_t bpp
Definition
fb.h:30
fb_info_t::phys
phys_addr_t phys
Definition
fb.h:28
fb_info_t::blue_size
uint8_t blue_size
Definition
fb.h:33
fb_info_t::pitch
uint32_t pitch
Definition
fb.h:29
fb_info_t::width
uint32_t width
Definition
fb.h:27
fb_info_t::height
uint32_t height
Definition
fb.h:28
fb_info_t::addr
uint8_t * addr
Definition
fb.h:27
fb_info_t::blue_shift
uint8_t blue_shift
Definition
fb.h:33
fb_info_t::green_size
uint8_t green_size
Definition
fb.h:32
fb_info_t::red_size
uint8_t red_size
Definition
fb.h:31
fb_info_t::red_shift
uint8_t red_shift
Definition
fb.h:31
fb_info_t::green_shift
uint8_t green_shift
Definition
fb.h:32
fb_info_t::bytes_pp
uint8_t bytes_pp
Definition
fb.h:33
src
drivers
video
fb
fb.h
Generated by
1.18.0