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 uint8_t c;
47 bool fg_default;
48 bool bg_default;
49 /* 1 byte implicit tail-of-first-word padding */
50 uint32_t fg;
51 uint32_t bg;
52};
53
54struct flanterm_fb_queue_item {
55 size_t x, y;
56 struct flanterm_fb_char c;
57};
58
59struct flanterm_fb_context {
60 struct flanterm_context term;
61
62 void (*plot_char)(struct flanterm_context *ctx, struct flanterm_fb_char *c, size_t x, size_t y);
63 void (*flush_callback)(volatile void *address, size_t length);
64
65 size_t font_width;
66 size_t font_height;
67 size_t glyph_width;
68 size_t glyph_height;
69
70 size_t font_scale_x;
71 size_t font_scale_y;
72
73 size_t offset_x, offset_y;
74
75 volatile uint32_t *framebuffer;
76 size_t pitch;
77 size_t width;
78 size_t height;
79 size_t phys_height;
80 size_t bpp;
81
82 uint8_t red_mask_size, red_mask_shift;
83 uint8_t green_mask_size, green_mask_shift;
84 uint8_t blue_mask_size, blue_mask_shift;
85
86 int rotation;
87
88 size_t font_bits_size;
89 uint8_t *font_bits;
90 size_t font_bool_size;
91 bool *font_bool;
92
93 uint32_t ansi_colours[8];
94 uint32_t ansi_bright_colours[8];
95 uint32_t default_fg, default_bg;
96 uint32_t default_fg_bright, default_bg_bright;
97
98 size_t canvas_size;
99 uint32_t *canvas;
100
101 size_t grid_size;
102 size_t queue_size;
103 size_t map_size;
104
105 struct flanterm_fb_char *grid;
106
107 struct flanterm_fb_queue_item *queue;
108 size_t queue_i;
109
110 struct flanterm_fb_queue_item **map;
111
112 uint32_t text_fg;
113 uint32_t text_bg;
114 bool text_fg_default;
115 bool text_bg_default;
116 size_t cursor_x;
117 size_t cursor_y;
118
119 uint32_t saved_state_text_fg;
120 uint32_t saved_state_text_bg;
121 bool saved_state_text_fg_default;
122 bool saved_state_text_bg_default;
123 size_t saved_state_cursor_x;
124 size_t saved_state_cursor_y;
125
126 size_t old_cursor_x;
127 size_t old_cursor_y;
128
129 bool full_refresh_pending;
130};
131
132#ifdef __cplusplus
133}
134#endif
135
136#endif
137