1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/* Copyright (C) 2022-2026 Mintsuki and contributors.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef FLANTERM_FB_PRIVATE_H
29#define FLANTERM_FB_PRIVATE_H 1
30
31#ifndef FLANTERM_IN_FLANTERM
32#error "Do not use fb_private.h. Use interfaces defined in fb.h only."
33#endif
34
35#include <stdint.h>
36#include <stddef.h>
37#include <stdbool.h>
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43#define FLANTERM_FB_FONT_GLYPHS 256
44
45struct flanterm_fb_char {
46 uint32_t c;
47 uint32_t fg;
48 uint32_t bg;
49};
50
51struct flanterm_fb_queue_item {
52 size_t x, y;
53 struct flanterm_fb_char c;
54};
55
56struct flanterm_fb_context {
57 struct flanterm_context term;
58
59 void (*plot_char)(struct flanterm_context *ctx, struct flanterm_fb_char *c, size_t x, size_t y);
60 void (*flush_callback)(volatile void *address, size_t length);
61
62 size_t font_width;
63 size_t font_height;
64 size_t glyph_width;
65 size_t glyph_height;
66
67 size_t font_scale_x;
68 size_t font_scale_y;
69
70 size_t offset_x, offset_y;
71
72 volatile uint32_t *framebuffer;
73 size_t pitch;
74 size_t width;
75 size_t height;
76 size_t phys_height;
77 size_t bpp;
78
79 uint8_t red_mask_size, red_mask_shift;
80 uint8_t green_mask_size, green_mask_shift;
81 uint8_t blue_mask_size, blue_mask_shift;
82
83 int rotation;
84
85 size_t font_bits_size;
86 uint8_t *font_bits;
87 size_t font_bool_size;
88 bool *font_bool;
89
90 uint32_t ansi_colours[8];
91 uint32_t ansi_bright_colours[8];
92 uint32_t default_fg, default_bg;
93 uint32_t default_fg_bright, default_bg_bright;
94
95 size_t canvas_size;
96 uint32_t *canvas;
97
98 size_t grid_size;
99 size_t queue_size;
100 size_t map_size;
101
102 struct flanterm_fb_char *grid;
103
104 struct flanterm_fb_queue_item *queue;
105 size_t queue_i;
106
107 struct flanterm_fb_queue_item **map;
108
109 uint32_t text_fg;
110 uint32_t text_bg;
111 size_t cursor_x;
112 size_t cursor_y;
113
114 uint32_t saved_state_text_fg;
115 uint32_t saved_state_text_bg;
116 size_t saved_state_cursor_x;
117 size_t saved_state_cursor_y;
118
119 size_t old_cursor_x;
120 size_t old_cursor_y;
121};
122
123#ifdef __cplusplus
124}
125#endif
126
127#endif
128