Rev 3792 | Rev 3795 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3792 | Rev 3793 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2008 Martin Decky |
2 | * Copyright (c) 2008 Martin Decky |
3 | * Copyright (c) 2006 Jakub Vana |
3 | * Copyright (c) 2006 Jakub Vana |
4 | * Copyright (c) 2006 Ondrej Palkovsky |
4 | * Copyright (c) 2006 Ondrej Palkovsky |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without |
7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions |
8 | * modification, are permitted provided that the following conditions |
9 | * are met: |
9 | * are met: |
10 | * |
10 | * |
11 | * - Redistributions of source code must retain the above copyright |
11 | * - Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. |
12 | * notice, this list of conditions and the following disclaimer. |
13 | * - Redistributions in binary form must reproduce the above copyright |
13 | * - Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the |
14 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. |
15 | * documentation and/or other materials provided with the distribution. |
16 | * - The name of the author may not be used to endorse or promote products |
16 | * - The name of the author may not be used to endorse or promote products |
17 | * derived from this software without specific prior written permission. |
17 | * derived from this software without specific prior written permission. |
18 | * |
18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | */ |
29 | */ |
30 | 30 | ||
31 | /** |
31 | /** |
32 | * @defgroup fb Graphical framebuffer |
32 | * @defgroup fb Graphical framebuffer |
33 | * @brief HelenOS graphical framebuffer. |
33 | * @brief HelenOS graphical framebuffer. |
34 | * @ingroup fbs |
34 | * @ingroup fbs |
35 | * @{ |
35 | * @{ |
36 | */ |
36 | */ |
37 | 37 | ||
38 | /** @file |
38 | /** @file |
39 | */ |
39 | */ |
40 | 40 | ||
41 | #include <stdlib.h> |
41 | #include <stdlib.h> |
42 | #include <unistd.h> |
42 | #include <unistd.h> |
43 | #include <string.h> |
43 | #include <string.h> |
44 | #include <ddi.h> |
44 | #include <ddi.h> |
45 | #include <sysinfo.h> |
45 | #include <sysinfo.h> |
46 | #include <align.h> |
46 | #include <align.h> |
47 | #include <as.h> |
47 | #include <as.h> |
48 | #include <ipc/fb.h> |
48 | #include <ipc/fb.h> |
49 | #include <ipc/ipc.h> |
49 | #include <ipc/ipc.h> |
50 | #include <ipc/ns.h> |
50 | #include <ipc/ns.h> |
51 | #include <ipc/services.h> |
51 | #include <ipc/services.h> |
52 | #include <kernel/errno.h> |
52 | #include <kernel/errno.h> |
53 | #include <kernel/genarch/fb/visuals.h> |
53 | #include <kernel/genarch/fb/visuals.h> |
54 | #include <console/color.h> |
54 | #include <console/color.h> |
55 | #include <console/style.h> |
55 | #include <console/style.h> |
56 | #include <async.h> |
56 | #include <async.h> |
57 | #include <bool.h> |
57 | #include <bool.h> |
58 | 58 | ||
59 | #include "font-8x16.h" |
59 | #include "font-8x16.h" |
60 | #include "fb.h" |
60 | #include "fb.h" |
61 | #include "main.h" |
61 | #include "main.h" |
62 | #include "../console/screenbuffer.h" |
62 | #include "../console/screenbuffer.h" |
63 | #include "ppm.h" |
63 | #include "ppm.h" |
64 | 64 | ||
65 | #include "pointer.xbm" |
65 | #include "pointer.xbm" |
66 | #include "pointer_mask.xbm" |
66 | #include "pointer_mask.xbm" |
67 | 67 | ||
68 | #define DEFAULT_BGCOLOR 0xf0f0f0 |
68 | #define DEFAULT_BGCOLOR 0xf0f0f0 |
69 | #define DEFAULT_FGCOLOR 0x000000 |
69 | #define DEFAULT_FGCOLOR 0x000000 |
70 | 70 | ||
71 | #define MAX_ANIM_LEN 8 |
71 | #define MAX_ANIM_LEN 8 |
72 | #define MAX_ANIMATIONS 4 |
72 | #define MAX_ANIMATIONS 4 |
73 | #define MAX_PIXMAPS 256 /**< Maximum number of saved pixmaps */ |
73 | #define MAX_PIXMAPS 256 /**< Maximum number of saved pixmaps */ |
74 | #define MAX_VIEWPORTS 128 /**< Viewport is a rectangular area on the screen */ |
74 | #define MAX_VIEWPORTS 128 /**< Viewport is a rectangular area on the screen */ |
75 | 75 | ||
76 | /** Function to render a pixel from a RGB value. */ |
76 | /** Function to render a pixel from a RGB value. */ |
77 | typedef void (*rgb_conv_t)(void *, uint32_t); |
77 | typedef void (*rgb_conv_t)(void *, uint32_t); |
78 | 78 | ||
79 | /** Function to draw a glyph. */ |
79 | /** Function to draw a glyph. */ |
80 | typedef void (*dg_t)(unsigned int x, unsigned int y, bool cursor, |
80 | typedef void (*dg_t)(unsigned int x, unsigned int y, bool cursor, |
81 | uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color); |
81 | uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color); |
82 | 82 | ||
83 | struct { |
83 | struct { |
84 | uint8_t *fb_addr; |
84 | uint8_t *fb_addr; |
85 | 85 | ||
86 | unsigned int xres; |
86 | unsigned int xres; |
87 | unsigned int yres; |
87 | unsigned int yres; |
88 | 88 | ||
89 | unsigned int scanline; |
89 | unsigned int scanline; |
90 | unsigned int glyphscanline; |
90 | unsigned int glyphscanline; |
91 | 91 | ||
92 | unsigned int pixelbytes; |
92 | unsigned int pixelbytes; |
93 | unsigned int glyphbytes; |
93 | unsigned int glyphbytes; |
94 | 94 | ||
95 | rgb_conv_t rgb_conv; |
95 | rgb_conv_t rgb_conv; |
96 | } screen; |
96 | } screen; |
97 | 97 | ||
98 | /** Backbuffer character cell. */ |
98 | /** Backbuffer character cell. */ |
99 | typedef struct { |
99 | typedef struct { |
100 | uint8_t glyph; |
100 | uint8_t glyph; |
101 | uint32_t fg_color; |
101 | uint32_t fg_color; |
102 | uint32_t bg_color; |
102 | uint32_t bg_color; |
103 | } bb_cell_t; |
103 | } bb_cell_t; |
104 | 104 | ||
105 | typedef struct { |
105 | typedef struct { |
106 | bool initialized; |
106 | bool initialized; |
107 | unsigned int x; |
107 | unsigned int x; |
108 | unsigned int y; |
108 | unsigned int y; |
109 | unsigned int width; |
109 | unsigned int width; |
110 | unsigned int height; |
110 | unsigned int height; |
111 | 111 | ||
112 | /* Text support in window */ |
112 | /* Text support in window */ |
113 | unsigned int cols; |
113 | unsigned int cols; |
114 | unsigned int rows; |
114 | unsigned int rows; |
115 | 115 | ||
116 | /* |
116 | /* |
117 | * Style and glyphs for text printing |
117 | * Style and glyphs for text printing |
118 | */ |
118 | */ |
119 | 119 | ||
120 | /** Current attributes. */ |
120 | /** Current attributes. */ |
121 | attr_rgb_t attr; |
121 | attr_rgb_t attr; |
122 | 122 | ||
123 | /** Pre-rendered mask for rendering glyphs. Different viewports |
123 | /** Pre-rendered mask for rendering glyphs. Different viewports |
124 | * might use different drawing functions depending on whether their |
124 | * might use different drawing functions depending on whether their |
125 | * scanlines are aligned on a word boundary.*/ |
125 | * scanlines are aligned on a word boundary.*/ |
126 | uint8_t *glyphs; |
126 | uint8_t *glyphs; |
127 | 127 | ||
128 | uint8_t *bgpixel; |
128 | uint8_t *bgpixel; |
129 | 129 | ||
130 | /** Glyph drawing function for this viewport. */ |
130 | /** Glyph drawing function for this viewport. */ |
131 | dg_t dglyph; |
131 | dg_t dglyph; |
132 | 132 | ||
133 | /* Auto-cursor position */ |
133 | /* Auto-cursor position */ |
134 | bool cursor_active; |
134 | bool cursor_active; |
135 | unsigned int cur_col; |
135 | unsigned int cur_col; |
136 | unsigned int cur_row; |
136 | unsigned int cur_row; |
137 | bool cursor_shown; |
137 | bool cursor_shown; |
138 | 138 | ||
139 | /* Back buffer */ |
139 | /* Back buffer */ |
140 | bb_cell_t *backbuf; |
140 | bb_cell_t *backbuf; |
141 | unsigned int bbsize; |
141 | unsigned int bbsize; |
- | 142 | bool bb_invalid; |
|
142 | } viewport_t; |
143 | } viewport_t; |
143 | 144 | ||
144 | typedef struct { |
145 | typedef struct { |
145 | bool initialized; |
146 | bool initialized; |
146 | bool enabled; |
147 | bool enabled; |
147 | unsigned int vp; |
148 | unsigned int vp; |
148 | 149 | ||
149 | unsigned int pos; |
150 | unsigned int pos; |
150 | unsigned int animlen; |
151 | unsigned int animlen; |
151 | unsigned int pixmaps[MAX_ANIM_LEN]; |
152 | unsigned int pixmaps[MAX_ANIM_LEN]; |
152 | } animation_t; |
153 | } animation_t; |
153 | 154 | ||
154 | static animation_t animations[MAX_ANIMATIONS]; |
155 | static animation_t animations[MAX_ANIMATIONS]; |
155 | static bool anims_enabled; |
156 | static bool anims_enabled; |
156 | 157 | ||
157 | typedef struct { |
158 | typedef struct { |
158 | unsigned int width; |
159 | unsigned int width; |
159 | unsigned int height; |
160 | unsigned int height; |
160 | uint8_t *data; |
161 | uint8_t *data; |
161 | } pixmap_t; |
162 | } pixmap_t; |
162 | 163 | ||
163 | static pixmap_t pixmaps[MAX_PIXMAPS]; |
164 | static pixmap_t pixmaps[MAX_PIXMAPS]; |
164 | static viewport_t viewports[128]; |
165 | static viewport_t viewports[128]; |
165 | 166 | ||
166 | static bool client_connected = false; /**< Allow only 1 connection */ |
167 | static bool client_connected = false; /**< Allow only 1 connection */ |
167 | 168 | ||
168 | static uint32_t color_table[16] = { |
169 | static uint32_t color_table[16] = { |
169 | [COLOR_BLACK] = 0x000000, |
170 | [COLOR_BLACK] = 0x000000, |
170 | [COLOR_BLUE] = 0x0000f0, |
171 | [COLOR_BLUE] = 0x0000f0, |
171 | [COLOR_GREEN] = 0x00f000, |
172 | [COLOR_GREEN] = 0x00f000, |
172 | [COLOR_CYAN] = 0x00f0f0, |
173 | [COLOR_CYAN] = 0x00f0f0, |
173 | [COLOR_RED] = 0xf00000, |
174 | [COLOR_RED] = 0xf00000, |
174 | [COLOR_MAGENTA] = 0xf000f0, |
175 | [COLOR_MAGENTA] = 0xf000f0, |
175 | [COLOR_YELLOW] = 0xf0f000, |
176 | [COLOR_YELLOW] = 0xf0f000, |
176 | [COLOR_WHITE] = 0xf0f0f0, |
177 | [COLOR_WHITE] = 0xf0f0f0, |
177 | 178 | ||
178 | [8 + COLOR_BLACK] = 0x000000, |
179 | [8 + COLOR_BLACK] = 0x000000, |
179 | [8 + COLOR_BLUE] = 0x0000ff, |
180 | [8 + COLOR_BLUE] = 0x0000ff, |
180 | [8 + COLOR_GREEN] = 0x00ff00, |
181 | [8 + COLOR_GREEN] = 0x00ff00, |
181 | [8 + COLOR_CYAN] = 0x00ffff, |
182 | [8 + COLOR_CYAN] = 0x00ffff, |
182 | [8 + COLOR_RED] = 0xff0000, |
183 | [8 + COLOR_RED] = 0xff0000, |
183 | [8 + COLOR_MAGENTA] = 0xff00ff, |
184 | [8 + COLOR_MAGENTA] = 0xff00ff, |
184 | [8 + COLOR_YELLOW] = 0xffff00, |
185 | [8 + COLOR_YELLOW] = 0xffff00, |
185 | [8 + COLOR_WHITE] = 0xffffff, |
186 | [8 + COLOR_WHITE] = 0xffffff, |
186 | }; |
187 | }; |
187 | 188 | ||
188 | static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a); |
189 | static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a); |
189 | static int rgb_from_style(attr_rgb_t *rgb, int style); |
190 | static int rgb_from_style(attr_rgb_t *rgb, int style); |
190 | static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color, |
191 | static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color, |
191 | ipcarg_t bg_color, ipcarg_t flags); |
192 | ipcarg_t bg_color, ipcarg_t flags); |
192 | 193 | ||
193 | static int fb_set_color(viewport_t *vport, ipcarg_t fg_color, |
194 | static int fb_set_color(viewport_t *vport, ipcarg_t fg_color, |
194 | ipcarg_t bg_color, ipcarg_t attr); |
195 | ipcarg_t bg_color, ipcarg_t attr); |
195 | 196 | ||
196 | static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor, |
197 | static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor, |
197 | uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color); |
198 | uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color); |
198 | static void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor, |
199 | static void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor, |
199 | uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color); |
200 | uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color); |
200 | 201 | ||
201 | static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col, |
202 | static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col, |
202 | unsigned int row); |
203 | unsigned int row); |
203 | 204 | ||
204 | 205 | ||
205 | #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) |
206 | #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) |
206 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
207 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
207 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
208 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
208 | 209 | ||
209 | #define COL2X(col) ((col) * FONT_WIDTH) |
210 | #define COL2X(col) ((col) * FONT_WIDTH) |
210 | #define ROW2Y(row) ((row) * FONT_SCANLINES) |
211 | #define ROW2Y(row) ((row) * FONT_SCANLINES) |
211 | 212 | ||
212 | #define X2COL(x) ((x) / FONT_WIDTH) |
213 | #define X2COL(x) ((x) / FONT_WIDTH) |
213 | #define Y2ROW(y) ((y) / FONT_SCANLINES) |
214 | #define Y2ROW(y) ((y) / FONT_SCANLINES) |
214 | 215 | ||
215 | #define FB_POS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) |
216 | #define FB_POS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) |
216 | #define BB_POS(vport, col, row) ((row) * vport->cols + (col)) |
217 | #define BB_POS(vport, col, row) ((row) * vport->cols + (col)) |
217 | #define GLYPH_POS(glyph, y, cursor) (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline) |
218 | #define GLYPH_POS(glyph, y, cursor) (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline) |
218 | 219 | ||
219 | 220 | ||
220 | /** ARGB 8:8:8:8 conversion |
221 | /** ARGB 8:8:8:8 conversion |
221 | * |
222 | * |
222 | */ |
223 | */ |
223 | static void rgb_0888(void *dst, uint32_t rgb) |
224 | static void rgb_0888(void *dst, uint32_t rgb) |
224 | { |
225 | { |
225 | *((uint32_t *) dst) = rgb & 0xffffff; |
226 | *((uint32_t *) dst) = rgb & 0xffffff; |
226 | } |
227 | } |
227 | 228 | ||
228 | 229 | ||
229 | /** ABGR 8:8:8:8 conversion |
230 | /** ABGR 8:8:8:8 conversion |
230 | * |
231 | * |
231 | */ |
232 | */ |
232 | static void bgr_0888(void *dst, uint32_t rgb) |
233 | static void bgr_0888(void *dst, uint32_t rgb) |
233 | { |
234 | { |
234 | *((uint32_t *) dst) |
235 | *((uint32_t *) dst) |
235 | = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8); |
236 | = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8); |
236 | } |
237 | } |
237 | 238 | ||
238 | 239 | ||
239 | /** BGR 8:8:8 conversion |
240 | /** BGR 8:8:8 conversion |
240 | * |
241 | * |
241 | */ |
242 | */ |
242 | static void rgb_888(void *dst, uint32_t rgb) |
243 | static void rgb_888(void *dst, uint32_t rgb) |
243 | { |
244 | { |
244 | #if defined(FB_INVERT_ENDIAN) |
245 | #if defined(FB_INVERT_ENDIAN) |
245 | ((uint8_t *) dst)[0] = RED(rgb, 8); |
246 | ((uint8_t *) dst)[0] = RED(rgb, 8); |
246 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
247 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
247 | ((uint8_t *) dst)[2] = BLUE(rgb, 8); |
248 | ((uint8_t *) dst)[2] = BLUE(rgb, 8); |
248 | #else |
249 | #else |
249 | ((uint8_t *) dst)[0] = BLUE(rgb, 8); |
250 | ((uint8_t *) dst)[0] = BLUE(rgb, 8); |
250 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
251 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
251 | ((uint8_t *) dst)[2] = RED(rgb, 8); |
252 | ((uint8_t *) dst)[2] = RED(rgb, 8); |
252 | #endif |
253 | #endif |
253 | } |
254 | } |
254 | 255 | ||
255 | 256 | ||
256 | /** RGB 5:5:5 conversion |
257 | /** RGB 5:5:5 conversion |
257 | * |
258 | * |
258 | */ |
259 | */ |
259 | static void rgb_555(void *dst, uint32_t rgb) |
260 | static void rgb_555(void *dst, uint32_t rgb) |
260 | { |
261 | { |
261 | *((uint16_t *) dst) |
262 | *((uint16_t *) dst) |
262 | = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5); |
263 | = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5); |
263 | } |
264 | } |
264 | 265 | ||
265 | 266 | ||
266 | /** RGB 5:6:5 conversion |
267 | /** RGB 5:6:5 conversion |
267 | * |
268 | * |
268 | */ |
269 | */ |
269 | static void rgb_565(void *dst, uint32_t rgb) |
270 | static void rgb_565(void *dst, uint32_t rgb) |
270 | { |
271 | { |
271 | *((uint16_t *) dst) |
272 | *((uint16_t *) dst) |
272 | = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5); |
273 | = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5); |
273 | } |
274 | } |
274 | 275 | ||
275 | 276 | ||
276 | /** RGB 3:2:3 |
277 | /** RGB 3:2:3 |
277 | * |
278 | * |
278 | */ |
279 | */ |
279 | static void rgb_323(void *dst, uint32_t rgb) |
280 | static void rgb_323(void *dst, uint32_t rgb) |
280 | { |
281 | { |
281 | *((uint8_t *) dst) |
282 | *((uint8_t *) dst) |
282 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
283 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
283 | } |
284 | } |
284 | 285 | ||
285 | /** Draw a filled rectangle. |
286 | /** Draw a filled rectangle. |
286 | * |
287 | * |
287 | * @note Need real implementation that does not access VRAM twice. |
288 | * @note Need real implementation that does not access VRAM twice. |
288 | */ |
289 | */ |
289 | static void draw_filled_rect(unsigned int x0, unsigned int y0, unsigned int x1, |
290 | static void draw_filled_rect(unsigned int x0, unsigned int y0, unsigned int x1, |
290 | unsigned int y1, uint32_t color) |
291 | unsigned int y1, uint32_t color) |
291 | { |
292 | { |
292 | unsigned int x, y; |
293 | unsigned int x, y; |
293 | unsigned int copy_bytes; |
294 | unsigned int copy_bytes; |
294 | 295 | ||
295 | uint8_t *sp, *dp; |
296 | uint8_t *sp, *dp; |
296 | uint8_t cbuf[4]; |
297 | uint8_t cbuf[4]; |
297 | 298 | ||
298 | if (y0 >= y1 || x0 >= x1) return; |
299 | if (y0 >= y1 || x0 >= x1) return; |
299 | screen.rgb_conv(cbuf, color); |
300 | screen.rgb_conv(cbuf, color); |
300 | 301 | ||
301 | sp = &screen.fb_addr[FB_POS(x0, y0)]; |
302 | sp = &screen.fb_addr[FB_POS(x0, y0)]; |
302 | dp = sp; |
303 | dp = sp; |
303 | 304 | ||
304 | /* Draw the first line. */ |
305 | /* Draw the first line. */ |
305 | for (x = x0; x < x1; x++) { |
306 | for (x = x0; x < x1; x++) { |
306 | memcpy(dp, cbuf, screen.pixelbytes); |
307 | memcpy(dp, cbuf, screen.pixelbytes); |
307 | dp += screen.pixelbytes; |
308 | dp += screen.pixelbytes; |
308 | } |
309 | } |
309 | 310 | ||
310 | dp = sp + screen.scanline; |
311 | dp = sp + screen.scanline; |
311 | copy_bytes = (x1 - x0) * screen.pixelbytes; |
312 | copy_bytes = (x1 - x0) * screen.pixelbytes; |
312 | 313 | ||
313 | /* Draw the remaining lines by copying. */ |
314 | /* Draw the remaining lines by copying. */ |
314 | for (y = y0 + 1; y < y1; y++) { |
315 | for (y = y0 + 1; y < y1; y++) { |
315 | memcpy(dp, sp, copy_bytes); |
316 | memcpy(dp, sp, copy_bytes); |
316 | dp += screen.scanline; |
317 | dp += screen.scanline; |
317 | } |
318 | } |
318 | } |
319 | } |
319 | 320 | ||
320 | /** Redraw viewport. |
321 | /** Redraw viewport. |
321 | * |
322 | * |
322 | * @param vport Viewport to redraw |
323 | * @param vport Viewport to redraw |
323 | * |
324 | * |
324 | */ |
325 | */ |
325 | static void vport_redraw(viewport_t *vport) |
326 | static void vport_redraw(viewport_t *vport) |
326 | { |
327 | { |
327 | unsigned int row, col; |
328 | unsigned int row, col; |
328 | 329 | ||
329 | for (row = 0; row < vport->rows; row++) { |
330 | for (row = 0; row < vport->rows; row++) { |
330 | for (col = 0; col < vport->cols; col++) { |
331 | for (col = 0; col < vport->cols; col++) { |
331 | draw_vp_glyph(vport, false, col, row); |
332 | draw_vp_glyph(vport, false, col, row); |
332 | } |
333 | } |
333 | } |
334 | } |
334 | 335 | ||
335 | if (COL2X(vport->cols) < vport->width) { |
336 | if (COL2X(vport->cols) < vport->width) { |
336 | draw_filled_rect( |
337 | draw_filled_rect( |
337 | vport->x + COL2X(vport->cols), vport->y, |
338 | vport->x + COL2X(vport->cols), vport->y, |
338 | vport->x + vport->width, vport->y + vport->height, |
339 | vport->x + vport->width, vport->y + vport->height, |
339 | vport->attr.bg_color); |
340 | vport->attr.bg_color); |
340 | } |
341 | } |
341 | 342 | ||
342 | if (ROW2Y(vport->rows) < vport->height) { |
343 | if (ROW2Y(vport->rows) < vport->height) { |
343 | draw_filled_rect( |
344 | draw_filled_rect( |
344 | vport->x, vport->y + ROW2Y(vport->rows), |
345 | vport->x, vport->y + ROW2Y(vport->rows), |
345 | vport->x + vport->width, vport->y + vport->height, |
346 | vport->x + vport->width, vport->y + vport->height, |
346 | vport->attr.bg_color); |
347 | vport->attr.bg_color); |
347 | } |
348 | } |
348 | } |
349 | } |
349 | 350 | ||
350 | static void backbuf_clear(bb_cell_t *backbuf, size_t len, uint32_t fg_color, |
351 | static void backbuf_clear(bb_cell_t *backbuf, size_t len, uint32_t fg_color, |
351 | uint32_t bg_color) |
352 | uint32_t bg_color) |
352 | { |
353 | { |
353 | unsigned i; |
354 | unsigned i; |
354 | 355 | ||
355 | for (i = 0; i < len; i++) { |
356 | for (i = 0; i < len; i++) { |
356 | backbuf[i].glyph = 0; |
357 | backbuf[i].glyph = 0; |
357 | backbuf[i].fg_color = fg_color; |
358 | backbuf[i].fg_color = fg_color; |
358 | backbuf[i].bg_color = bg_color; |
359 | backbuf[i].bg_color = bg_color; |
359 | } |
360 | } |
360 | } |
361 | } |
361 | 362 | ||
362 | /** Clear viewport. |
363 | /** Clear viewport. |
363 | * |
364 | * |
364 | * @param vport Viewport to clear |
365 | * @param vport Viewport to clear |
365 | * |
366 | * |
366 | */ |
367 | */ |
367 | static void vport_clear(viewport_t *vport) |
368 | static void vport_clear(viewport_t *vport) |
368 | { |
369 | { |
369 | backbuf_clear(vport->backbuf, vport->cols * vport->rows, |
370 | backbuf_clear(vport->backbuf, vport->cols * vport->rows, |
370 | vport->attr.fg_color, vport->attr.bg_color); |
371 | vport->attr.fg_color, vport->attr.bg_color); |
371 | vport_redraw(vport); |
372 | vport_redraw(vport); |
372 | } |
373 | } |
373 | 374 | ||
374 | /** Scroll viewport by the specified number of lines. |
375 | /** Scroll viewport by the specified number of lines. |
375 | * |
376 | * |
376 | * @param vport Viewport to scroll |
377 | * @param vport Viewport to scroll |
377 | * @param lines Number of lines to scroll |
378 | * @param lines Number of lines to scroll |
378 | * |
379 | * |
379 | */ |
380 | */ |
380 | static void vport_scroll(viewport_t *vport, int lines) |
381 | static void vport_scroll(viewport_t *vport, int lines) |
381 | { |
382 | { |
382 | unsigned int row, col; |
383 | unsigned int row, col; |
383 | unsigned int x, y; |
384 | unsigned int x, y; |
384 | uint8_t glyph; |
385 | uint8_t glyph; |
385 | uint32_t fg_color; |
386 | uint32_t fg_color; |
386 | uint32_t bg_color; |
387 | uint32_t bg_color; |
387 | bb_cell_t *bbp, *xbp; |
388 | bb_cell_t *bbp, *xbp; |
388 | 389 | ||
389 | /* |
390 | /* |
390 | * Redraw. |
391 | * Redraw. |
391 | */ |
392 | */ |
392 | 393 | ||
393 | y = vport->y; |
394 | y = vport->y; |
394 | for (row = 0; row < vport->rows; row++) { |
395 | for (row = 0; row < vport->rows; row++) { |
395 | x = vport->x; |
396 | x = vport->x; |
396 | for (col = 0; col < vport->cols; col++) { |
397 | for (col = 0; col < vport->cols; col++) { |
397 | if ((row + lines >= 0) && (row + lines < vport->rows)) { |
398 | if ((row + lines >= 0) && (row + lines < vport->rows)) { |
398 | xbp = &vport->backbuf[BB_POS(vport, col, row + lines)]; |
399 | xbp = &vport->backbuf[BB_POS(vport, col, row + lines)]; |
399 | bbp = &vport->backbuf[BB_POS(vport, col, row)]; |
400 | bbp = &vport->backbuf[BB_POS(vport, col, row)]; |
400 | 401 | ||
401 | glyph = xbp->glyph; |
402 | glyph = xbp->glyph; |
402 | fg_color = xbp->fg_color; |
403 | fg_color = xbp->fg_color; |
403 | bg_color = xbp->bg_color; |
404 | bg_color = xbp->bg_color; |
404 | 405 | ||
405 | if (bbp->glyph == glyph && |
406 | if (bbp->glyph == glyph && |
406 | bbp->fg_color == xbp->fg_color && |
407 | bbp->fg_color == xbp->fg_color && |
407 | bbp->bg_color == xbp->bg_color) { |
408 | bbp->bg_color == xbp->bg_color) { |
408 | x += FONT_WIDTH; |
409 | x += FONT_WIDTH; |
409 | continue; |
410 | continue; |
410 | } |
411 | } |
411 | } else { |
412 | } else { |
412 | glyph = 0; |
413 | glyph = 0; |
413 | fg_color = vport->attr.fg_color; |
414 | fg_color = vport->attr.fg_color; |
414 | bg_color = vport->attr.bg_color; |
415 | bg_color = vport->attr.bg_color; |
415 | } |
416 | } |
416 | 417 | ||
417 | (*vport->dglyph)(x, y, false, vport->glyphs, glyph, |
418 | (*vport->dglyph)(x, y, false, vport->glyphs, glyph, |
418 | fg_color, bg_color); |
419 | fg_color, bg_color); |
419 | x += FONT_WIDTH; |
420 | x += FONT_WIDTH; |
420 | } |
421 | } |
421 | y += FONT_SCANLINES; |
422 | y += FONT_SCANLINES; |
422 | } |
423 | } |
423 | 424 | ||
424 | /* |
425 | /* |
425 | * Scroll backbuffer. |
426 | * Scroll backbuffer. |
426 | */ |
427 | */ |
427 | 428 | ||
428 | if (lines > 0) { |
429 | if (lines > 0) { |
429 | memmove(vport->backbuf, vport->backbuf + vport->cols * lines, |
430 | memmove(vport->backbuf, vport->backbuf + vport->cols * lines, |
430 | vport->cols * (vport->rows - lines) * sizeof(bb_cell_t)); |
431 | vport->cols * (vport->rows - lines) * sizeof(bb_cell_t)); |
431 | backbuf_clear(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)], |
432 | backbuf_clear(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)], |
432 | vport->cols * lines, vport->attr.fg_color, vport->attr.bg_color); |
433 | vport->cols * lines, vport->attr.fg_color, vport->attr.bg_color); |
433 | } else { |
434 | } else { |
434 | memmove(vport->backbuf - vport->cols * lines, vport->backbuf, |
435 | memmove(vport->backbuf - vport->cols * lines, vport->backbuf, |
435 | vport->cols * (vport->rows + lines) * sizeof(bb_cell_t)); |
436 | vport->cols * (vport->rows + lines) * sizeof(bb_cell_t)); |
436 | backbuf_clear(vport->backbuf, - vport->cols * lines, |
437 | backbuf_clear(vport->backbuf, - vport->cols * lines, |
437 | vport->attr.fg_color, vport->attr.bg_color); |
438 | vport->attr.fg_color, vport->attr.bg_color); |
438 | } |
439 | } |
439 | } |
440 | } |
440 | 441 | ||
441 | /** Render glyphs |
442 | /** Render glyphs |
442 | * |
443 | * |
443 | * Convert glyphs from device independent font |
444 | * Convert glyphs from device independent font |
444 | * description to current visual representation. |
445 | * description to current visual representation. |
445 | * |
446 | * |
446 | * @param vport Viewport |
447 | * @param vport Viewport |
447 | * |
448 | * |
448 | */ |
449 | */ |
449 | static void render_glyphs(viewport_t* vport) |
450 | static void render_glyphs(viewport_t* vport) |
450 | { |
451 | { |
451 | unsigned int glyph; |
452 | unsigned int glyph; |
452 | 453 | ||
453 | for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { |
454 | for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { |
454 | unsigned int y; |
455 | unsigned int y; |
455 | 456 | ||
456 | for (y = 0; y < FONT_SCANLINES; y++) { |
457 | for (y = 0; y < FONT_SCANLINES; y++) { |
457 | unsigned int x; |
458 | unsigned int x; |
458 | 459 | ||
459 | for (x = 0; x < FONT_WIDTH; x++) { |
460 | for (x = 0; x < FONT_WIDTH; x++) { |
460 | screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes], |
461 | screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes], |
461 | (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x))) |
462 | (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x))) |
462 | ? 0xffffff : 0x000000); |
463 | ? 0xffffff : 0x000000); |
463 | 464 | ||
464 | screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes], |
465 | screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes], |
465 | (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x))) |
466 | (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x))) |
466 | ? 0x000000 : 0xffffff); |
467 | ? 0x000000 : 0xffffff); |
467 | } |
468 | } |
468 | } |
469 | } |
469 | } |
470 | } |
470 | 471 | ||
471 | screen.rgb_conv(vport->bgpixel, vport->attr.bg_color); |
472 | screen.rgb_conv(vport->bgpixel, vport->attr.bg_color); |
472 | } |
473 | } |
473 | 474 | ||
474 | 475 | ||
475 | /** Create new viewport |
476 | /** Create new viewport |
476 | * |
477 | * |
477 | * @param x Origin of the viewport (x). |
478 | * @param x Origin of the viewport (x). |
478 | * @param y Origin of the viewport (y). |
479 | * @param y Origin of the viewport (y). |
479 | * @param width Width of the viewport. |
480 | * @param width Width of the viewport. |
480 | * @param height Height of the viewport. |
481 | * @param height Height of the viewport. |
481 | * |
482 | * |
482 | * @return New viewport number. |
483 | * @return New viewport number. |
483 | * |
484 | * |
484 | */ |
485 | */ |
485 | static int vport_create(unsigned int x, unsigned int y, |
486 | static int vport_create(unsigned int x, unsigned int y, |
486 | unsigned int width, unsigned int height) |
487 | unsigned int width, unsigned int height) |
487 | { |
488 | { |
488 | unsigned int i; |
489 | unsigned int i; |
489 | 490 | ||
490 | for (i = 0; i < MAX_VIEWPORTS; i++) { |
491 | for (i = 0; i < MAX_VIEWPORTS; i++) { |
491 | if (!viewports[i].initialized) |
492 | if (!viewports[i].initialized) |
492 | break; |
493 | break; |
493 | } |
494 | } |
494 | if (i == MAX_VIEWPORTS) |
495 | if (i == MAX_VIEWPORTS) |
495 | return ELIMIT; |
496 | return ELIMIT; |
496 | 497 | ||
497 | unsigned int cols = width / FONT_WIDTH; |
498 | unsigned int cols = width / FONT_WIDTH; |
498 | unsigned int rows = height / FONT_SCANLINES; |
499 | unsigned int rows = height / FONT_SCANLINES; |
499 | unsigned int bbsize = cols * rows * sizeof(bb_cell_t); |
500 | unsigned int bbsize = cols * rows * sizeof(bb_cell_t); |
500 | unsigned int glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes; |
501 | unsigned int glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes; |
501 | unsigned int word_size = sizeof(unsigned long); |
502 | unsigned int word_size = sizeof(unsigned long); |
502 | 503 | ||
503 | bb_cell_t *backbuf = (bb_cell_t *) malloc(bbsize); |
504 | bb_cell_t *backbuf = (bb_cell_t *) malloc(bbsize); |
504 | if (!backbuf) |
505 | if (!backbuf) |
505 | return ENOMEM; |
506 | return ENOMEM; |
506 | 507 | ||
507 | uint8_t *glyphs = (uint8_t *) malloc(glyphsize); |
508 | uint8_t *glyphs = (uint8_t *) malloc(glyphsize); |
508 | if (!glyphs) { |
509 | if (!glyphs) { |
509 | free(backbuf); |
510 | free(backbuf); |
510 | return ENOMEM; |
511 | return ENOMEM; |
511 | } |
512 | } |
512 | 513 | ||
513 | uint8_t *bgpixel = (uint8_t *) malloc(screen.pixelbytes); |
514 | uint8_t *bgpixel = (uint8_t *) malloc(screen.pixelbytes); |
514 | if (!bgpixel) { |
515 | if (!bgpixel) { |
515 | free(glyphs); |
516 | free(glyphs); |
516 | free(backbuf); |
517 | free(backbuf); |
517 | return ENOMEM; |
518 | return ENOMEM; |
518 | } |
519 | } |
519 | 520 | ||
520 | backbuf_clear(backbuf, cols * rows, DEFAULT_FGCOLOR, DEFAULT_BGCOLOR); |
521 | backbuf_clear(backbuf, cols * rows, DEFAULT_FGCOLOR, DEFAULT_BGCOLOR); |
521 | memset(glyphs, 0, glyphsize); |
522 | memset(glyphs, 0, glyphsize); |
522 | memset(bgpixel, 0, screen.pixelbytes); |
523 | memset(bgpixel, 0, screen.pixelbytes); |
523 | 524 | ||
524 | viewports[i].x = x; |
525 | viewports[i].x = x; |
525 | viewports[i].y = y; |
526 | viewports[i].y = y; |
526 | viewports[i].width = width; |
527 | viewports[i].width = width; |
527 | viewports[i].height = height; |
528 | viewports[i].height = height; |
528 | 529 | ||
529 | viewports[i].cols = cols; |
530 | viewports[i].cols = cols; |
530 | viewports[i].rows = rows; |
531 | viewports[i].rows = rows; |
531 | 532 | ||
532 | viewports[i].attr.bg_color = DEFAULT_BGCOLOR; |
533 | viewports[i].attr.bg_color = DEFAULT_BGCOLOR; |
533 | viewports[i].attr.fg_color = DEFAULT_FGCOLOR; |
534 | viewports[i].attr.fg_color = DEFAULT_FGCOLOR; |
534 | 535 | ||
535 | viewports[i].glyphs = glyphs; |
536 | viewports[i].glyphs = glyphs; |
536 | viewports[i].bgpixel = bgpixel; |
537 | viewports[i].bgpixel = bgpixel; |
537 | 538 | ||
538 | /* |
539 | /* |
539 | * Conditions necessary to select aligned version: |
540 | * Conditions necessary to select aligned version: |
540 | * |
541 | * |
541 | * - word size is divisible by pixelbytes |
542 | * - word size is divisible by pixelbytes |
542 | * - cell scanline size is divisible by word size |
543 | * - cell scanline size is divisible by word size |
543 | * - cell scanlines are word-aligned |
544 | * - cell scanlines are word-aligned |
544 | */ |
545 | */ |
545 | if ((word_size % screen.pixelbytes) == 0 && |
546 | if ((word_size % screen.pixelbytes) == 0 && |
546 | (FONT_WIDTH * screen.pixelbytes) % word_size == 0 && |
547 | (FONT_WIDTH * screen.pixelbytes) % word_size == 0 && |
547 | (x * screen.pixelbytes) % word_size == 0 && |
548 | (x * screen.pixelbytes) % word_size == 0 && |
548 | screen.scanline % word_size == 0) { |
549 | screen.scanline % word_size == 0) { |
549 | 550 | ||
550 | viewports[i].dglyph = draw_glyph_aligned; |
551 | viewports[i].dglyph = draw_glyph_aligned; |
551 | } else { |
552 | } else { |
552 | viewports[i].dglyph = draw_glyph_fallback; |
553 | viewports[i].dglyph = draw_glyph_fallback; |
553 | } |
554 | } |
554 | 555 | ||
555 | viewports[i].cur_col = 0; |
556 | viewports[i].cur_col = 0; |
556 | viewports[i].cur_row = 0; |
557 | viewports[i].cur_row = 0; |
557 | viewports[i].cursor_active = false; |
558 | viewports[i].cursor_active = false; |
558 | viewports[i].cursor_shown = false; |
559 | viewports[i].cursor_shown = false; |
559 | 560 | ||
560 | viewports[i].bbsize = bbsize; |
561 | viewports[i].bbsize = bbsize; |
561 | viewports[i].backbuf = backbuf; |
562 | viewports[i].backbuf = backbuf; |
- | 563 | viewports[i].bb_invalid = false; |
|
562 | 564 | ||
563 | viewports[i].initialized = true; |
565 | viewports[i].initialized = true; |
564 | 566 | ||
565 | render_glyphs(&viewports[i]); |
567 | render_glyphs(&viewports[i]); |
566 | 568 | ||
567 | return i; |
569 | return i; |
568 | } |
570 | } |
569 | 571 | ||
570 | 572 | ||
571 | /** Initialize framebuffer as a chardev output device |
573 | /** Initialize framebuffer as a chardev output device |
572 | * |
574 | * |
573 | * @param addr Address of the framebuffer |
575 | * @param addr Address of the framebuffer |
574 | * @param xres Screen width in pixels |
576 | * @param xres Screen width in pixels |
575 | * @param yres Screen height in pixels |
577 | * @param yres Screen height in pixels |
576 | * @param visual Bits per pixel (8, 16, 24, 32) |
578 | * @param visual Bits per pixel (8, 16, 24, 32) |
577 | * @param scan Bytes per one scanline |
579 | * @param scan Bytes per one scanline |
578 | * |
580 | * |
579 | */ |
581 | */ |
580 | static bool screen_init(void *addr, unsigned int xres, unsigned int yres, |
582 | static bool screen_init(void *addr, unsigned int xres, unsigned int yres, |
581 | unsigned int scan, unsigned int visual) |
583 | unsigned int scan, unsigned int visual) |
582 | { |
584 | { |
583 | switch (visual) { |
585 | switch (visual) { |
584 | case VISUAL_INDIRECT_8: |
586 | case VISUAL_INDIRECT_8: |
585 | screen.rgb_conv = rgb_323; |
587 | screen.rgb_conv = rgb_323; |
586 | screen.pixelbytes = 1; |
588 | screen.pixelbytes = 1; |
587 | break; |
589 | break; |
588 | case VISUAL_RGB_5_5_5: |
590 | case VISUAL_RGB_5_5_5: |
589 | screen.rgb_conv = rgb_555; |
591 | screen.rgb_conv = rgb_555; |
590 | screen.pixelbytes = 2; |
592 | screen.pixelbytes = 2; |
591 | break; |
593 | break; |
592 | case VISUAL_RGB_5_6_5: |
594 | case VISUAL_RGB_5_6_5: |
593 | screen.rgb_conv = rgb_565; |
595 | screen.rgb_conv = rgb_565; |
594 | screen.pixelbytes = 2; |
596 | screen.pixelbytes = 2; |
595 | break; |
597 | break; |
596 | case VISUAL_RGB_8_8_8: |
598 | case VISUAL_RGB_8_8_8: |
597 | screen.rgb_conv = rgb_888; |
599 | screen.rgb_conv = rgb_888; |
598 | screen.pixelbytes = 3; |
600 | screen.pixelbytes = 3; |
599 | break; |
601 | break; |
600 | case VISUAL_RGB_8_8_8_0: |
602 | case VISUAL_RGB_8_8_8_0: |
601 | screen.rgb_conv = rgb_888; |
603 | screen.rgb_conv = rgb_888; |
602 | screen.pixelbytes = 4; |
604 | screen.pixelbytes = 4; |
603 | break; |
605 | break; |
604 | case VISUAL_RGB_0_8_8_8: |
606 | case VISUAL_RGB_0_8_8_8: |
605 | screen.rgb_conv = rgb_0888; |
607 | screen.rgb_conv = rgb_0888; |
606 | screen.pixelbytes = 4; |
608 | screen.pixelbytes = 4; |
607 | break; |
609 | break; |
608 | case VISUAL_BGR_0_8_8_8: |
610 | case VISUAL_BGR_0_8_8_8: |
609 | screen.rgb_conv = bgr_0888; |
611 | screen.rgb_conv = bgr_0888; |
610 | screen.pixelbytes = 4; |
612 | screen.pixelbytes = 4; |
611 | break; |
613 | break; |
612 | default: |
614 | default: |
613 | return false; |
615 | return false; |
614 | } |
616 | } |
615 | 617 | ||
616 | screen.fb_addr = (unsigned char *) addr; |
618 | screen.fb_addr = (unsigned char *) addr; |
617 | screen.xres = xres; |
619 | screen.xres = xres; |
618 | screen.yres = yres; |
620 | screen.yres = yres; |
619 | screen.scanline = scan; |
621 | screen.scanline = scan; |
620 | 622 | ||
621 | screen.glyphscanline = FONT_WIDTH * screen.pixelbytes; |
623 | screen.glyphscanline = FONT_WIDTH * screen.pixelbytes; |
622 | screen.glyphbytes = screen.glyphscanline * FONT_SCANLINES; |
624 | screen.glyphbytes = screen.glyphscanline * FONT_SCANLINES; |
623 | 625 | ||
624 | /* Create first viewport */ |
626 | /* Create first viewport */ |
625 | vport_create(0, 0, xres, yres); |
627 | vport_create(0, 0, xres, yres); |
626 | 628 | ||
627 | return true; |
629 | return true; |
628 | } |
630 | } |
629 | 631 | ||
630 | 632 | ||
631 | /** Draw a glyph, takes advantage of alignment. |
633 | /** Draw a glyph, takes advantage of alignment. |
632 | * |
634 | * |
633 | * This version can only be used if the following conditions are met: |
635 | * This version can only be used if the following conditions are met: |
634 | * |
636 | * |
635 | * - word size is divisible by pixelbytes |
637 | * - word size is divisible by pixelbytes |
636 | * - cell scanline size is divisible by word size |
638 | * - cell scanline size is divisible by word size |
637 | * - cell scanlines are word-aligned |
639 | * - cell scanlines are word-aligned |
638 | * |
640 | * |
639 | * It makes use of the pre-rendered mask to process (possibly) several |
641 | * It makes use of the pre-rendered mask to process (possibly) several |
640 | * pixels at once (word size / pixelbytes pixels at a time are processed) |
642 | * pixels at once (word size / pixelbytes pixels at a time are processed) |
641 | * making it very fast. Most notably this version is not applicable at 24 bits |
643 | * making it very fast. Most notably this version is not applicable at 24 bits |
642 | * per pixel. |
644 | * per pixel. |
643 | * |
645 | * |
644 | * @param x x coordinate of top-left corner on screen. |
646 | * @param x x coordinate of top-left corner on screen. |
645 | * @param y y coordinate of top-left corner on screen. |
647 | * @param y y coordinate of top-left corner on screen. |
646 | * @param cursor Draw glyph with cursor |
648 | * @param cursor Draw glyph with cursor |
647 | * @param glyphs Pointer to font bitmap. |
649 | * @param glyphs Pointer to font bitmap. |
648 | * @param glyph Code of the glyph to draw. |
650 | * @param glyph Code of the glyph to draw. |
649 | * @param fg_color Foreground color. |
651 | * @param fg_color Foreground color. |
650 | * @param bg_color Backgroudn color. |
652 | * @param bg_color Backgroudn color. |
651 | */ |
653 | */ |
652 | static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor, |
654 | static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor, |
653 | uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color) |
655 | uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color) |
654 | { |
656 | { |
655 | unsigned int i, yd; |
657 | unsigned int i, yd; |
656 | unsigned long fg_buf, bg_buf; |
658 | unsigned long fg_buf, bg_buf; |
657 | unsigned long *maskp, *dp; |
659 | unsigned long *maskp, *dp; |
658 | unsigned long mask; |
660 | unsigned long mask; |
659 | unsigned int ww, d_add; |
661 | unsigned int ww, d_add; |
660 | 662 | ||
661 | /* |
663 | /* |
662 | * Prepare a pair of words, one filled with foreground-color |
664 | * Prepare a pair of words, one filled with foreground-color |
663 | * pattern and the other filled with background-color pattern. |
665 | * pattern and the other filled with background-color pattern. |
664 | */ |
666 | */ |
665 | for (i = 0; i < sizeof(unsigned long) / screen.pixelbytes; i++) { |
667 | for (i = 0; i < sizeof(unsigned long) / screen.pixelbytes; i++) { |
666 | screen.rgb_conv(&((uint8_t *)&fg_buf)[i * screen.pixelbytes], |
668 | screen.rgb_conv(&((uint8_t *)&fg_buf)[i * screen.pixelbytes], |
667 | fg_color); |
669 | fg_color); |
668 | screen.rgb_conv(&((uint8_t *)&bg_buf)[i * screen.pixelbytes], |
670 | screen.rgb_conv(&((uint8_t *)&bg_buf)[i * screen.pixelbytes], |
669 | bg_color); |
671 | bg_color); |
670 | } |
672 | } |
671 | 673 | ||
672 | 674 | ||
673 | /* Pointer to the current position in the mask. */ |
675 | /* Pointer to the current position in the mask. */ |
674 | maskp = (unsigned long *) &glyphs[GLYPH_POS(glyph, 0, cursor)]; |
676 | maskp = (unsigned long *) &glyphs[GLYPH_POS(glyph, 0, cursor)]; |
675 | 677 | ||
676 | /* Pointer to the current position on the screen. */ |
678 | /* Pointer to the current position on the screen. */ |
677 | dp = (unsigned long *) &screen.fb_addr[FB_POS(x, y)]; |
679 | dp = (unsigned long *) &screen.fb_addr[FB_POS(x, y)]; |
678 | 680 | ||
679 | /* Width of the character cell in words. */ |
681 | /* Width of the character cell in words. */ |
680 | ww = FONT_WIDTH * screen.pixelbytes / sizeof(unsigned long); |
682 | ww = FONT_WIDTH * screen.pixelbytes / sizeof(unsigned long); |
681 | 683 | ||
682 | /* Offset to add when moving to another screen scanline. */ |
684 | /* Offset to add when moving to another screen scanline. */ |
683 | d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes; |
685 | d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes; |
684 | 686 | ||
685 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
687 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
686 | /* |
688 | /* |
687 | * Now process the cell scanline, combining foreground |
689 | * Now process the cell scanline, combining foreground |
688 | * and background color patters using the pre-rendered mask. |
690 | * and background color patters using the pre-rendered mask. |
689 | */ |
691 | */ |
690 | for (i = 0; i < ww; i++) { |
692 | for (i = 0; i < ww; i++) { |
691 | mask = *maskp++; |
693 | mask = *maskp++; |
692 | *dp++ = (fg_buf & mask) | (bg_buf & ~mask); |
694 | *dp++ = (fg_buf & mask) | (bg_buf & ~mask); |
693 | } |
695 | } |
694 | 696 | ||
695 | /* Move to the beginning of the next scanline of the cell. */ |
697 | /* Move to the beginning of the next scanline of the cell. */ |
696 | dp = (unsigned long *) ((uint8_t *) dp + d_add); |
698 | dp = (unsigned long *) ((uint8_t *) dp + d_add); |
697 | } |
699 | } |
698 | } |
700 | } |
699 | 701 | ||
700 | /** Draw a glyph, fallback version. |
702 | /** Draw a glyph, fallback version. |
701 | * |
703 | * |
702 | * This version does not make use of the pre-rendered mask, it uses |
704 | * This version does not make use of the pre-rendered mask, it uses |
703 | * the font bitmap directly. It works always, but it is slower. |
705 | * the font bitmap directly. It works always, but it is slower. |
704 | * |
706 | * |
705 | * @param x x coordinate of top-left corner on screen. |
707 | * @param x x coordinate of top-left corner on screen. |
706 | * @param y y coordinate of top-left corner on screen. |
708 | * @param y y coordinate of top-left corner on screen. |
707 | * @param cursor Draw glyph with cursor |
709 | * @param cursor Draw glyph with cursor |
708 | * @param glyphs Pointer to font bitmap. |
710 | * @param glyphs Pointer to font bitmap. |
709 | * @param glyph Code of the glyph to draw. |
711 | * @param glyph Code of the glyph to draw. |
710 | * @param fg_color Foreground color. |
712 | * @param fg_color Foreground color. |
711 | * @param bg_color Backgroudn color. |
713 | * @param bg_color Backgroudn color. |
712 | */ |
714 | */ |
713 | void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor, |
715 | void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor, |
714 | uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color) |
716 | uint8_t *glyphs, uint8_t glyph, uint32_t fg_color, uint32_t bg_color) |
715 | { |
717 | { |
716 | unsigned int i, j, yd; |
718 | unsigned int i, j, yd; |
717 | uint8_t fg_buf[4], bg_buf[4]; |
719 | uint8_t fg_buf[4], bg_buf[4]; |
718 | uint8_t *dp, *sp; |
720 | uint8_t *dp, *sp; |
719 | unsigned int d_add; |
721 | unsigned int d_add; |
720 | uint8_t b; |
722 | uint8_t b; |
721 | 723 | ||
722 | /* Pre-render 1x the foreground and background color pixels. */ |
724 | /* Pre-render 1x the foreground and background color pixels. */ |
723 | if (cursor) { |
725 | if (cursor) { |
724 | screen.rgb_conv(fg_buf, bg_color); |
726 | screen.rgb_conv(fg_buf, bg_color); |
725 | screen.rgb_conv(bg_buf, fg_color); |
727 | screen.rgb_conv(bg_buf, fg_color); |
726 | } else { |
728 | } else { |
727 | screen.rgb_conv(fg_buf, fg_color); |
729 | screen.rgb_conv(fg_buf, fg_color); |
728 | screen.rgb_conv(bg_buf, bg_color); |
730 | screen.rgb_conv(bg_buf, bg_color); |
729 | } |
731 | } |
730 | 732 | ||
731 | /* Pointer to the current position on the screen. */ |
733 | /* Pointer to the current position on the screen. */ |
732 | dp = (uint8_t *) &screen.fb_addr[FB_POS(x, y)]; |
734 | dp = (uint8_t *) &screen.fb_addr[FB_POS(x, y)]; |
733 | 735 | ||
734 | /* Offset to add when moving to another screen scanline. */ |
736 | /* Offset to add when moving to another screen scanline. */ |
735 | d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes; |
737 | d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes; |
736 | 738 | ||
737 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
739 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
738 | /* Byte containing bits of the glyph scanline. */ |
740 | /* Byte containing bits of the glyph scanline. */ |
739 | b = fb_font[glyph * FONT_SCANLINES + yd]; |
741 | b = fb_font[glyph * FONT_SCANLINES + yd]; |
740 | 742 | ||
741 | for (i = 0; i < FONT_WIDTH; i++) { |
743 | for (i = 0; i < FONT_WIDTH; i++) { |
742 | /* Choose color based on the current bit. */ |
744 | /* Choose color based on the current bit. */ |
743 | sp = (b & 0x80) ? fg_buf : bg_buf; |
745 | sp = (b & 0x80) ? fg_buf : bg_buf; |
744 | 746 | ||
745 | /* Copy the pixel. */ |
747 | /* Copy the pixel. */ |
746 | for (j = 0; j < screen.pixelbytes; j++) { |
748 | for (j = 0; j < screen.pixelbytes; j++) { |
747 | *dp++ = *sp++; |
749 | *dp++ = *sp++; |
748 | } |
750 | } |
749 | 751 | ||
750 | /* Move to the next bit. */ |
752 | /* Move to the next bit. */ |
751 | b = b << 1; |
753 | b = b << 1; |
752 | } |
754 | } |
753 | 755 | ||
754 | /* Move to the beginning of the next scanline of the cell. */ |
756 | /* Move to the beginning of the next scanline of the cell. */ |
755 | dp += d_add; |
757 | dp += d_add; |
756 | } |
758 | } |
757 | } |
759 | } |
758 | 760 | ||
759 | /** Draw glyph at specified position in viewport. |
761 | /** Draw glyph at specified position in viewport. |
760 | * |
762 | * |
761 | * @param vport Viewport identification |
763 | * @param vport Viewport identification |
762 | * @param cursor Draw glyph with cursor |
764 | * @param cursor Draw glyph with cursor |
763 | * @param col Screen position relative to viewport |
765 | * @param col Screen position relative to viewport |
764 | * @param row Screen position relative to viewport |
766 | * @param row Screen position relative to viewport |
765 | * |
767 | * |
766 | */ |
768 | */ |
767 | static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col, |
769 | static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col, |
768 | unsigned int row) |
770 | unsigned int row) |
769 | { |
771 | { |
770 | unsigned int x = vport->x + COL2X(col); |
772 | unsigned int x = vport->x + COL2X(col); |
771 | unsigned int y = vport->y + ROW2Y(row); |
773 | unsigned int y = vport->y + ROW2Y(row); |
772 | 774 | ||
773 | uint8_t glyph; |
775 | uint8_t glyph; |
774 | uint32_t fg_color; |
776 | uint32_t fg_color; |
775 | uint32_t bg_color; |
777 | uint32_t bg_color; |
776 | 778 | ||
777 | glyph = vport->backbuf[BB_POS(vport, col, row)].glyph; |
779 | glyph = vport->backbuf[BB_POS(vport, col, row)].glyph; |
778 | fg_color = vport->backbuf[BB_POS(vport, col, row)].fg_color; |
780 | fg_color = vport->backbuf[BB_POS(vport, col, row)].fg_color; |
779 | bg_color = vport->backbuf[BB_POS(vport, col, row)].bg_color; |
781 | bg_color = vport->backbuf[BB_POS(vport, col, row)].bg_color; |
780 | 782 | ||
781 | (*vport->dglyph)(x, y, cursor, vport->glyphs, glyph, |
783 | (*vport->dglyph)(x, y, cursor, vport->glyphs, glyph, |
782 | fg_color, bg_color); |
784 | fg_color, bg_color); |
783 | } |
785 | } |
784 | 786 | ||
785 | /** Hide cursor if it is shown |
787 | /** Hide cursor if it is shown |
786 | * |
788 | * |
787 | */ |
789 | */ |
788 | static void cursor_hide(viewport_t *vport) |
790 | static void cursor_hide(viewport_t *vport) |
789 | { |
791 | { |
790 | if ((vport->cursor_active) && (vport->cursor_shown)) { |
792 | if ((vport->cursor_active) && (vport->cursor_shown)) { |
791 | draw_vp_glyph(vport, false, vport->cur_col, vport->cur_row); |
793 | draw_vp_glyph(vport, false, vport->cur_col, vport->cur_row); |
792 | vport->cursor_shown = false; |
794 | vport->cursor_shown = false; |
793 | } |
795 | } |
794 | } |
796 | } |
795 | 797 | ||
796 | 798 | ||
797 | /** Show cursor if cursor showing is enabled |
799 | /** Show cursor if cursor showing is enabled |
798 | * |
800 | * |
799 | */ |
801 | */ |
800 | static void cursor_show(viewport_t *vport) |
802 | static void cursor_show(viewport_t *vport) |
801 | { |
803 | { |
802 | /* Do not check for cursor_shown */ |
804 | /* Do not check for cursor_shown */ |
803 | if (vport->cursor_active) { |
805 | if (vport->cursor_active) { |
804 | draw_vp_glyph(vport, true, vport->cur_col, vport->cur_row); |
806 | draw_vp_glyph(vport, true, vport->cur_col, vport->cur_row); |
805 | vport->cursor_shown = true; |
807 | vport->cursor_shown = true; |
806 | } |
808 | } |
807 | } |
809 | } |
808 | 810 | ||
809 | 811 | ||
810 | /** Invert cursor, if it is enabled |
812 | /** Invert cursor, if it is enabled |
811 | * |
813 | * |
812 | */ |
814 | */ |
813 | static void cursor_blink(viewport_t *vport) |
815 | static void cursor_blink(viewport_t *vport) |
814 | { |
816 | { |
815 | if (vport->cursor_shown) |
817 | if (vport->cursor_shown) |
816 | cursor_hide(vport); |
818 | cursor_hide(vport); |
817 | else |
819 | else |
818 | cursor_show(vport); |
820 | cursor_show(vport); |
819 | } |
821 | } |
820 | 822 | ||
821 | 823 | ||
822 | /** Draw character at given position relative to viewport |
824 | /** Draw character at given position relative to viewport |
823 | * |
825 | * |
824 | * @param vport Viewport identification |
826 | * @param vport Viewport identification |
825 | * @param c Character to draw |
827 | * @param c Character to draw |
826 | * @param col Screen position relative to viewport |
828 | * @param col Screen position relative to viewport |
827 | * @param row Screen position relative to viewport |
829 | * @param row Screen position relative to viewport |
828 | * |
830 | * |
829 | */ |
831 | */ |
830 | static void draw_char(viewport_t *vport, uint8_t c, unsigned int col, unsigned int row) |
832 | static void draw_char(viewport_t *vport, uint8_t c, unsigned int col, unsigned int row) |
831 | { |
833 | { |
832 | bb_cell_t *bbp; |
834 | bb_cell_t *bbp; |
833 | 835 | ||
834 | /* Do not hide cursor if we are going to overwrite it */ |
836 | /* Do not hide cursor if we are going to overwrite it */ |
835 | if ((vport->cursor_active) && (vport->cursor_shown) && |
837 | if ((vport->cursor_active) && (vport->cursor_shown) && |
836 | ((vport->cur_col != col) || (vport->cur_row != row))) |
838 | ((vport->cur_col != col) || (vport->cur_row != row))) |
837 | cursor_hide(vport); |
839 | cursor_hide(vport); |
838 | 840 | ||
839 | bbp = &vport->backbuf[BB_POS(vport, col, row)]; |
841 | bbp = &vport->backbuf[BB_POS(vport, col, row)]; |
840 | bbp->glyph = c; |
842 | bbp->glyph = c; |
841 | bbp->fg_color = vport->attr.fg_color; |
843 | bbp->fg_color = vport->attr.fg_color; |
842 | bbp->bg_color = vport->attr.bg_color; |
844 | bbp->bg_color = vport->attr.bg_color; |
843 | 845 | ||
844 | draw_vp_glyph(vport, false, col, row); |
846 | draw_vp_glyph(vport, false, col, row); |
845 | 847 | ||
846 | vport->cur_col = col; |
848 | vport->cur_col = col; |
847 | vport->cur_row = row; |
849 | vport->cur_row = row; |
848 | 850 | ||
849 | vport->cur_col++; |
851 | vport->cur_col++; |
850 | if (vport->cur_col >= vport->cols) { |
852 | if (vport->cur_col >= vport->cols) { |
851 | vport->cur_col = 0; |
853 | vport->cur_col = 0; |
852 | vport->cur_row++; |
854 | vport->cur_row++; |
853 | if (vport->cur_row >= vport->rows) |
855 | if (vport->cur_row >= vport->rows) |
854 | vport->cur_row--; |
856 | vport->cur_row--; |
855 | } |
857 | } |
856 | 858 | ||
857 | cursor_show(vport); |
859 | cursor_show(vport); |
858 | } |
860 | } |
859 | 861 | ||
860 | 862 | ||
861 | /** Draw text data to viewport |
863 | /** Draw text data to viewport |
862 | * |
864 | * |
863 | * @param vport Viewport id |
865 | * @param vport Viewport id |
864 | * @param data Text data fitting exactly into viewport |
866 | * @param data Text data fitting exactly into viewport |
865 | * |
867 | * |
866 | */ |
868 | */ |
867 | static void draw_text_data(viewport_t *vport, keyfield_t *data) |
869 | static void draw_text_data(viewport_t *vport, keyfield_t *data) |
868 | { |
870 | { |
869 | unsigned int i; |
871 | unsigned int i; |
870 | bb_cell_t *bbp; |
872 | bb_cell_t *bbp; |
871 | attrs_t *a; |
873 | attrs_t *a; |
872 | attr_rgb_t rgb; |
874 | attr_rgb_t rgb; |
873 | 875 | ||
874 | for (i = 0; i < vport->cols * vport->rows; i++) { |
876 | for (i = 0; i < vport->cols * vport->rows; i++) { |
875 | unsigned int col = i % vport->cols; |
877 | unsigned int col = i % vport->cols; |
876 | unsigned int row = i / vport->cols; |
878 | unsigned int row = i / vport->cols; |
877 | 879 | ||
878 | bbp = &vport->backbuf[BB_POS(vport, col, row)]; |
880 | bbp = &vport->backbuf[BB_POS(vport, col, row)]; |
879 | uint8_t glyph = bbp->glyph; |
881 | uint8_t glyph = bbp->glyph; |
880 | 882 | ||
881 | a = &data[i].attrs; |
883 | a = &data[i].attrs; |
882 | rgb_from_attr(&rgb, a); |
884 | rgb_from_attr(&rgb, a); |
883 | 885 | ||
884 | if (glyph != data[i].character || |
886 | if (glyph != data[i].character || |
885 | rgb.fg_color != bbp->fg_color || |
887 | rgb.fg_color != bbp->fg_color || |
886 | rgb.bg_color != bbp->bg_color) { |
888 | rgb.bg_color != bbp->bg_color || |
- | 889 | vport->bb_invalid) { |
|
887 | bbp->glyph = data[i].character; |
890 | bbp->glyph = data[i].character; |
888 | 891 | ||
889 | bbp->fg_color = rgb.fg_color; |
892 | bbp->fg_color = rgb.fg_color; |
890 | bbp->bg_color = rgb.bg_color; |
893 | bbp->bg_color = rgb.bg_color; |
891 | 894 | ||
892 | draw_vp_glyph(vport, false, col, row); |
895 | draw_vp_glyph(vport, false, col, row); |
893 | } |
896 | } |
894 | } |
897 | } |
895 | cursor_show(vport); |
898 | cursor_show(vport); |
896 | } |
899 | } |
897 | 900 | ||
898 | 901 | ||
899 | static void putpixel_pixmap(void *data, unsigned int x, unsigned int y, uint32_t color) |
902 | static void putpixel_pixmap(void *data, unsigned int x, unsigned int y, uint32_t color) |
900 | { |
903 | { |
901 | int pm = *((int *) data); |
904 | int pm = *((int *) data); |
902 | pixmap_t *pmap = &pixmaps[pm]; |
905 | pixmap_t *pmap = &pixmaps[pm]; |
903 | unsigned int pos = (y * pmap->width + x) * screen.pixelbytes; |
906 | unsigned int pos = (y * pmap->width + x) * screen.pixelbytes; |
904 | 907 | ||
905 | screen.rgb_conv(&pmap->data[pos], color); |
908 | screen.rgb_conv(&pmap->data[pos], color); |
906 | } |
909 | } |
907 | 910 | ||
908 | 911 | ||
909 | static void putpixel(void *data, unsigned int x, unsigned int y, uint32_t color) |
912 | static void putpixel(void *data, unsigned int x, unsigned int y, uint32_t color) |
910 | { |
913 | { |
911 | viewport_t *vport = (viewport_t *) data; |
914 | viewport_t *vport = (viewport_t *) data; |
912 | unsigned int dx = vport->x + x; |
915 | unsigned int dx = vport->x + x; |
913 | unsigned int dy = vport->y + y; |
916 | unsigned int dy = vport->y + y; |
914 | 917 | ||
915 | screen.rgb_conv(&screen.fb_addr[FB_POS(dx, dy)], color); |
918 | screen.rgb_conv(&screen.fb_addr[FB_POS(dx, dy)], color); |
916 | } |
919 | } |
917 | 920 | ||
918 | 921 | ||
919 | /** Return first free pixmap |
922 | /** Return first free pixmap |
920 | * |
923 | * |
921 | */ |
924 | */ |
922 | static int find_free_pixmap(void) |
925 | static int find_free_pixmap(void) |
923 | { |
926 | { |
924 | unsigned int i; |
927 | unsigned int i; |
925 | 928 | ||
926 | for (i = 0; i < MAX_PIXMAPS; i++) |
929 | for (i = 0; i < MAX_PIXMAPS; i++) |
927 | if (!pixmaps[i].data) |
930 | if (!pixmaps[i].data) |
928 | return i; |
931 | return i; |
929 | 932 | ||
930 | return -1; |
933 | return -1; |
931 | } |
934 | } |
932 | 935 | ||
933 | 936 | ||
934 | /** Create a new pixmap and return appropriate ID |
937 | /** Create a new pixmap and return appropriate ID |
935 | * |
938 | * |
936 | */ |
939 | */ |
937 | static int shm2pixmap(unsigned char *shm, size_t size) |
940 | static int shm2pixmap(unsigned char *shm, size_t size) |
938 | { |
941 | { |
939 | int pm; |
942 | int pm; |
940 | pixmap_t *pmap; |
943 | pixmap_t *pmap; |
941 | 944 | ||
942 | pm = find_free_pixmap(); |
945 | pm = find_free_pixmap(); |
943 | if (pm == -1) |
946 | if (pm == -1) |
944 | return ELIMIT; |
947 | return ELIMIT; |
945 | 948 | ||
946 | pmap = &pixmaps[pm]; |
949 | pmap = &pixmaps[pm]; |
947 | 950 | ||
948 | if (ppm_get_data(shm, size, &pmap->width, &pmap->height)) |
951 | if (ppm_get_data(shm, size, &pmap->width, &pmap->height)) |
949 | return EINVAL; |
952 | return EINVAL; |
950 | 953 | ||
951 | pmap->data = malloc(pmap->width * pmap->height * screen.pixelbytes); |
954 | pmap->data = malloc(pmap->width * pmap->height * screen.pixelbytes); |
952 | if (!pmap->data) |
955 | if (!pmap->data) |
953 | return ENOMEM; |
956 | return ENOMEM; |
954 | 957 | ||
955 | ppm_draw(shm, size, 0, 0, pmap->width, pmap->height, putpixel_pixmap, (void *) &pm); |
958 | ppm_draw(shm, size, 0, 0, pmap->width, pmap->height, putpixel_pixmap, (void *) &pm); |
956 | 959 | ||
957 | return pm; |
960 | return pm; |
958 | } |
961 | } |
959 | 962 | ||
960 | 963 | ||
961 | /** Handle shared memory communication calls |
964 | /** Handle shared memory communication calls |
962 | * |
965 | * |
963 | * Protocol for drawing pixmaps: |
966 | * Protocol for drawing pixmaps: |
964 | * - FB_PREPARE_SHM(client shm identification) |
967 | * - FB_PREPARE_SHM(client shm identification) |
965 | * - IPC_M_AS_AREA_SEND |
968 | * - IPC_M_AS_AREA_SEND |
966 | * - FB_DRAW_PPM(startx, starty) |
969 | * - FB_DRAW_PPM(startx, starty) |
967 | * - FB_DROP_SHM |
970 | * - FB_DROP_SHM |
968 | * |
971 | * |
969 | * Protocol for text drawing |
972 | * Protocol for text drawing |
970 | * - IPC_M_AS_AREA_SEND |
973 | * - IPC_M_AS_AREA_SEND |
971 | * - FB_DRAW_TEXT_DATA |
974 | * - FB_DRAW_TEXT_DATA |
972 | * |
975 | * |
973 | * @param callid Callid of the current call |
976 | * @param callid Callid of the current call |
974 | * @param call Current call data |
977 | * @param call Current call data |
975 | * @param vp Active viewport |
978 | * @param vp Active viewport |
976 | * |
979 | * |
977 | * @return false if the call was not handled byt this function, true otherwise |
980 | * @return false if the call was not handled byt this function, true otherwise |
978 | * |
981 | * |
979 | * Note: this function is not threads safe, you would have |
982 | * Note: this function is not threads safe, you would have |
980 | * to redefine static variables with __thread |
983 | * to redefine static variables with __thread |
981 | * |
984 | * |
982 | */ |
985 | */ |
983 | static bool shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
986 | static bool shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
984 | { |
987 | { |
985 | static keyfield_t *interbuffer = NULL; |
988 | static keyfield_t *interbuffer = NULL; |
986 | static size_t intersize = 0; |
989 | static size_t intersize = 0; |
987 | 990 | ||
988 | static unsigned char *shm = NULL; |
991 | static unsigned char *shm = NULL; |
989 | static ipcarg_t shm_id = 0; |
992 | static ipcarg_t shm_id = 0; |
990 | static size_t shm_size; |
993 | static size_t shm_size; |
991 | 994 | ||
992 | bool handled = true; |
995 | bool handled = true; |
993 | int retval = EOK; |
996 | int retval = EOK; |
994 | viewport_t *vport = &viewports[vp]; |
997 | viewport_t *vport = &viewports[vp]; |
995 | unsigned int x; |
998 | unsigned int x; |
996 | unsigned int y; |
999 | unsigned int y; |
997 | 1000 | ||
998 | switch (IPC_GET_METHOD(*call)) { |
1001 | switch (IPC_GET_METHOD(*call)) { |
999 | case IPC_M_SHARE_OUT: |
1002 | case IPC_M_SHARE_OUT: |
1000 | /* We accept one area for data interchange */ |
1003 | /* We accept one area for data interchange */ |
1001 | if (IPC_GET_ARG1(*call) == shm_id) { |
1004 | if (IPC_GET_ARG1(*call) == shm_id) { |
1002 | void *dest = as_get_mappable_page(IPC_GET_ARG2(*call)); |
1005 | void *dest = as_get_mappable_page(IPC_GET_ARG2(*call)); |
1003 | shm_size = IPC_GET_ARG2(*call); |
1006 | shm_size = IPC_GET_ARG2(*call); |
1004 | if (!ipc_answer_1(callid, EOK, (sysarg_t) dest)) |
1007 | if (!ipc_answer_1(callid, EOK, (sysarg_t) dest)) |
1005 | shm = dest; |
1008 | shm = dest; |
1006 | else |
1009 | else |
1007 | shm_id = 0; |
1010 | shm_id = 0; |
1008 | 1011 | ||
1009 | if (shm[0] != 'P') |
1012 | if (shm[0] != 'P') |
1010 | return false; |
1013 | return false; |
1011 | 1014 | ||
1012 | return true; |
1015 | return true; |
1013 | } else { |
1016 | } else { |
1014 | intersize = IPC_GET_ARG2(*call); |
1017 | intersize = IPC_GET_ARG2(*call); |
1015 | receive_comm_area(callid, call, (void *) &interbuffer); |
1018 | receive_comm_area(callid, call, (void *) &interbuffer); |
1016 | } |
1019 | } |
1017 | return true; |
1020 | return true; |
1018 | case FB_PREPARE_SHM: |
1021 | case FB_PREPARE_SHM: |
1019 | if (shm_id) |
1022 | if (shm_id) |
1020 | retval = EBUSY; |
1023 | retval = EBUSY; |
1021 | else |
1024 | else |
1022 | shm_id = IPC_GET_ARG1(*call); |
1025 | shm_id = IPC_GET_ARG1(*call); |
1023 | break; |
1026 | break; |
1024 | 1027 | ||
1025 | case FB_DROP_SHM: |
1028 | case FB_DROP_SHM: |
1026 | if (shm) { |
1029 | if (shm) { |
1027 | as_area_destroy(shm); |
1030 | as_area_destroy(shm); |
1028 | shm = NULL; |
1031 | shm = NULL; |
1029 | } |
1032 | } |
1030 | shm_id = 0; |
1033 | shm_id = 0; |
1031 | break; |
1034 | break; |
1032 | 1035 | ||
1033 | case FB_SHM2PIXMAP: |
1036 | case FB_SHM2PIXMAP: |
1034 | if (!shm) { |
1037 | if (!shm) { |
1035 | retval = EINVAL; |
1038 | retval = EINVAL; |
1036 | break; |
1039 | break; |
1037 | } |
1040 | } |
1038 | retval = shm2pixmap(shm, shm_size); |
1041 | retval = shm2pixmap(shm, shm_size); |
1039 | break; |
1042 | break; |
1040 | case FB_DRAW_PPM: |
1043 | case FB_DRAW_PPM: |
1041 | if (!shm) { |
1044 | if (!shm) { |
1042 | retval = EINVAL; |
1045 | retval = EINVAL; |
1043 | break; |
1046 | break; |
1044 | } |
1047 | } |
1045 | x = IPC_GET_ARG1(*call); |
1048 | x = IPC_GET_ARG1(*call); |
1046 | y = IPC_GET_ARG2(*call); |
1049 | y = IPC_GET_ARG2(*call); |
1047 | 1050 | ||
1048 | if ((x > vport->width) || (y > vport->height)) { |
1051 | if ((x > vport->width) || (y > vport->height)) { |
1049 | retval = EINVAL; |
1052 | retval = EINVAL; |
1050 | break; |
1053 | break; |
1051 | } |
1054 | } |
1052 | 1055 | ||
1053 | ppm_draw(shm, shm_size, IPC_GET_ARG1(*call), |
1056 | ppm_draw(shm, shm_size, IPC_GET_ARG1(*call), |
1054 | IPC_GET_ARG2(*call), vport->width - x, vport->height - y, putpixel, (void *) vport); |
1057 | IPC_GET_ARG2(*call), vport->width - x, vport->height - y, putpixel, (void *) vport); |
1055 | break; |
1058 | break; |
1056 | case FB_DRAW_TEXT_DATA: |
1059 | case FB_DRAW_TEXT_DATA: |
1057 | if (!interbuffer) { |
1060 | if (!interbuffer) { |
1058 | retval = EINVAL; |
1061 | retval = EINVAL; |
1059 | break; |
1062 | break; |
1060 | } |
1063 | } |
1061 | if (intersize < vport->cols * vport->rows * sizeof(*interbuffer)) { |
1064 | if (intersize < vport->cols * vport->rows * sizeof(*interbuffer)) { |
1062 | retval = EINVAL; |
1065 | retval = EINVAL; |
1063 | break; |
1066 | break; |
1064 | } |
1067 | } |
1065 | draw_text_data(vport, interbuffer); |
1068 | draw_text_data(vport, interbuffer); |
1066 | break; |
1069 | break; |
1067 | default: |
1070 | default: |
1068 | handled = false; |
1071 | handled = false; |
1069 | } |
1072 | } |
1070 | 1073 | ||
1071 | if (handled) |
1074 | if (handled) |
1072 | ipc_answer_0(callid, retval); |
1075 | ipc_answer_0(callid, retval); |
1073 | return handled; |
1076 | return handled; |
1074 | } |
1077 | } |
1075 | 1078 | ||
1076 | 1079 | ||
1077 | static void copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap) |
1080 | static void copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap) |
1078 | { |
1081 | { |
1079 | unsigned int width = vport->width; |
1082 | unsigned int width = vport->width; |
1080 | unsigned int height = vport->height; |
1083 | unsigned int height = vport->height; |
1081 | 1084 | ||
1082 | if (width + vport->x > screen.xres) |
1085 | if (width + vport->x > screen.xres) |
1083 | width = screen.xres - vport->x; |
1086 | width = screen.xres - vport->x; |
1084 | if (height + vport->y > screen.yres) |
1087 | if (height + vport->y > screen.yres) |
1085 | height = screen.yres - vport->y; |
1088 | height = screen.yres - vport->y; |
1086 | 1089 | ||
1087 | unsigned int realwidth = pmap->width <= width ? pmap->width : width; |
1090 | unsigned int realwidth = pmap->width <= width ? pmap->width : width; |
1088 | unsigned int realheight = pmap->height <= height ? pmap->height : height; |
1091 | unsigned int realheight = pmap->height <= height ? pmap->height : height; |
1089 | 1092 | ||
1090 | unsigned int srcrowsize = vport->width * screen.pixelbytes; |
1093 | unsigned int srcrowsize = vport->width * screen.pixelbytes; |
1091 | unsigned int realrowsize = realwidth * screen.pixelbytes; |
1094 | unsigned int realrowsize = realwidth * screen.pixelbytes; |
1092 | 1095 | ||
1093 | unsigned int y; |
1096 | unsigned int y; |
1094 | for (y = 0; y < realheight; y++) { |
1097 | for (y = 0; y < realheight; y++) { |
1095 | unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; |
1098 | unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; |
1096 | memcpy(pmap->data + srcrowsize * y, screen.fb_addr + tmp, realrowsize); |
1099 | memcpy(pmap->data + srcrowsize * y, screen.fb_addr + tmp, realrowsize); |
1097 | } |
1100 | } |
1098 | } |
1101 | } |
1099 | 1102 | ||
1100 | 1103 | ||
1101 | /** Save viewport to pixmap |
1104 | /** Save viewport to pixmap |
1102 | * |
1105 | * |
1103 | */ |
1106 | */ |
1104 | static int save_vp_to_pixmap(viewport_t *vport) |
1107 | static int save_vp_to_pixmap(viewport_t *vport) |
1105 | { |
1108 | { |
1106 | int pm; |
1109 | int pm; |
1107 | pixmap_t *pmap; |
1110 | pixmap_t *pmap; |
1108 | 1111 | ||
1109 | pm = find_free_pixmap(); |
1112 | pm = find_free_pixmap(); |
1110 | if (pm == -1) |
1113 | if (pm == -1) |
1111 | return ELIMIT; |
1114 | return ELIMIT; |
1112 | 1115 | ||
1113 | pmap = &pixmaps[pm]; |
1116 | pmap = &pixmaps[pm]; |
1114 | pmap->data = malloc(screen.pixelbytes * vport->width * vport->height); |
1117 | pmap->data = malloc(screen.pixelbytes * vport->width * vport->height); |
1115 | if (!pmap->data) |
1118 | if (!pmap->data) |
1116 | return ENOMEM; |
1119 | return ENOMEM; |
1117 | 1120 | ||
1118 | pmap->width = vport->width; |
1121 | pmap->width = vport->width; |
1119 | pmap->height = vport->height; |
1122 | pmap->height = vport->height; |
1120 | 1123 | ||
1121 | copy_vp_to_pixmap(vport, pmap); |
1124 | copy_vp_to_pixmap(vport, pmap); |
1122 | 1125 | ||
1123 | return pm; |
1126 | return pm; |
1124 | } |
1127 | } |
1125 | 1128 | ||
1126 | 1129 | ||
1127 | /** Draw pixmap on screen |
1130 | /** Draw pixmap on screen |
1128 | * |
1131 | * |
1129 | * @param vp Viewport to draw on |
1132 | * @param vp Viewport to draw on |
1130 | * @param pm Pixmap identifier |
1133 | * @param pm Pixmap identifier |
1131 | * |
1134 | * |
1132 | */ |
1135 | */ |
1133 | static int draw_pixmap(int vp, int pm) |
1136 | static int draw_pixmap(int vp, int pm) |
1134 | { |
1137 | { |
1135 | pixmap_t *pmap = &pixmaps[pm]; |
1138 | pixmap_t *pmap = &pixmaps[pm]; |
1136 | viewport_t *vport = &viewports[vp]; |
1139 | viewport_t *vport = &viewports[vp]; |
1137 | 1140 | ||
1138 | unsigned int width = vport->width; |
1141 | unsigned int width = vport->width; |
1139 | unsigned int height = vport->height; |
1142 | unsigned int height = vport->height; |
1140 | 1143 | ||
1141 | if (width + vport->x > screen.xres) |
1144 | if (width + vport->x > screen.xres) |
1142 | width = screen.xres - vport->x; |
1145 | width = screen.xres - vport->x; |
1143 | if (height + vport->y > screen.yres) |
1146 | if (height + vport->y > screen.yres) |
1144 | height = screen.yres - vport->y; |
1147 | height = screen.yres - vport->y; |
1145 | 1148 | ||
1146 | if (!pmap->data) |
1149 | if (!pmap->data) |
1147 | return EINVAL; |
1150 | return EINVAL; |
1148 | 1151 | ||
1149 | unsigned int realwidth = pmap->width <= width ? pmap->width : width; |
1152 | unsigned int realwidth = pmap->width <= width ? pmap->width : width; |
1150 | unsigned int realheight = pmap->height <= height ? pmap->height : height; |
1153 | unsigned int realheight = pmap->height <= height ? pmap->height : height; |
1151 | 1154 | ||
1152 | unsigned int srcrowsize = vport->width * screen.pixelbytes; |
1155 | unsigned int srcrowsize = vport->width * screen.pixelbytes; |
1153 | unsigned int realrowsize = realwidth * screen.pixelbytes; |
1156 | unsigned int realrowsize = realwidth * screen.pixelbytes; |
1154 | 1157 | ||
1155 | unsigned int y; |
1158 | unsigned int y; |
1156 | for (y = 0; y < realheight; y++) { |
1159 | for (y = 0; y < realheight; y++) { |
1157 | unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; |
1160 | unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; |
1158 | memcpy(screen.fb_addr + tmp, pmap->data + y * srcrowsize, realrowsize); |
1161 | memcpy(screen.fb_addr + tmp, pmap->data + y * srcrowsize, realrowsize); |
1159 | } |
1162 | } |
1160 | 1163 | ||
1161 | return EOK; |
1164 | return EOK; |
1162 | } |
1165 | } |
1163 | 1166 | ||
1164 | 1167 | ||
1165 | /** Tick animation one step forward |
1168 | /** Tick animation one step forward |
1166 | * |
1169 | * |
1167 | */ |
1170 | */ |
1168 | static void anims_tick(void) |
1171 | static void anims_tick(void) |
1169 | { |
1172 | { |
1170 | unsigned int i; |
1173 | unsigned int i; |
1171 | static int counts = 0; |
1174 | static int counts = 0; |
1172 | 1175 | ||
1173 | /* Limit redrawing */ |
1176 | /* Limit redrawing */ |
1174 | counts = (counts + 1) % 8; |
1177 | counts = (counts + 1) % 8; |
1175 | if (counts) |
1178 | if (counts) |
1176 | return; |
1179 | return; |
1177 | 1180 | ||
1178 | for (i = 0; i < MAX_ANIMATIONS; i++) { |
1181 | for (i = 0; i < MAX_ANIMATIONS; i++) { |
1179 | if ((!animations[i].animlen) || (!animations[i].initialized) || |
1182 | if ((!animations[i].animlen) || (!animations[i].initialized) || |
1180 | (!animations[i].enabled)) |
1183 | (!animations[i].enabled)) |
1181 | continue; |
1184 | continue; |
1182 | 1185 | ||
1183 | draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]); |
1186 | draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]); |
1184 | animations[i].pos = (animations[i].pos + 1) % animations[i].animlen; |
1187 | animations[i].pos = (animations[i].pos + 1) % animations[i].animlen; |
1185 | } |
1188 | } |
1186 | } |
1189 | } |
1187 | 1190 | ||
1188 | 1191 | ||
1189 | static unsigned int pointer_x; |
1192 | static unsigned int pointer_x; |
1190 | static unsigned int pointer_y; |
1193 | static unsigned int pointer_y; |
1191 | static bool pointer_shown, pointer_enabled; |
1194 | static bool pointer_shown, pointer_enabled; |
1192 | static int pointer_vport = -1; |
1195 | static int pointer_vport = -1; |
1193 | static int pointer_pixmap = -1; |
1196 | static int pointer_pixmap = -1; |
1194 | 1197 | ||
1195 | 1198 | ||
1196 | static void mouse_show(void) |
1199 | static void mouse_show(void) |
1197 | { |
1200 | { |
1198 | int i, j; |
1201 | int i, j; |
1199 | int visibility; |
1202 | int visibility; |
1200 | int color; |
1203 | int color; |
1201 | int bytepos; |
1204 | int bytepos; |
1202 | 1205 | ||
1203 | if ((pointer_shown) || (!pointer_enabled)) |
1206 | if ((pointer_shown) || (!pointer_enabled)) |
1204 | return; |
1207 | return; |
1205 | 1208 | ||
1206 | /* Save image under the pointer. */ |
1209 | /* Save image under the pointer. */ |
1207 | if (pointer_vport == -1) { |
1210 | if (pointer_vport == -1) { |
1208 | pointer_vport = vport_create(pointer_x, pointer_y, pointer_width, pointer_height); |
1211 | pointer_vport = vport_create(pointer_x, pointer_y, pointer_width, pointer_height); |
1209 | if (pointer_vport < 0) |
1212 | if (pointer_vport < 0) |
1210 | return; |
1213 | return; |
1211 | } else { |
1214 | } else { |
1212 | viewports[pointer_vport].x = pointer_x; |
1215 | viewports[pointer_vport].x = pointer_x; |
1213 | viewports[pointer_vport].y = pointer_y; |
1216 | viewports[pointer_vport].y = pointer_y; |
1214 | } |
1217 | } |
1215 | 1218 | ||
1216 | if (pointer_pixmap == -1) |
1219 | if (pointer_pixmap == -1) |
1217 | pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]); |
1220 | pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]); |
1218 | else |
1221 | else |
1219 | copy_vp_to_pixmap(&viewports[pointer_vport], &pixmaps[pointer_pixmap]); |
1222 | copy_vp_to_pixmap(&viewports[pointer_vport], &pixmaps[pointer_pixmap]); |
1220 | 1223 | ||
1221 | /* Draw mouse pointer. */ |
1224 | /* Draw mouse pointer. */ |
1222 | for (i = 0; i < pointer_height; i++) |
1225 | for (i = 0; i < pointer_height; i++) |
1223 | for (j = 0; j < pointer_width; j++) { |
1226 | for (j = 0; j < pointer_width; j++) { |
1224 | bytepos = i * ((pointer_width - 1) / 8 + 1) + j / 8; |
1227 | bytepos = i * ((pointer_width - 1) / 8 + 1) + j / 8; |
1225 | visibility = pointer_mask_bits[bytepos] & |
1228 | visibility = pointer_mask_bits[bytepos] & |
1226 | (1 << (j % 8)); |
1229 | (1 << (j % 8)); |
1227 | if (visibility) { |
1230 | if (visibility) { |
1228 | color = pointer_bits[bytepos] & |
1231 | color = pointer_bits[bytepos] & |
1229 | (1 << (j % 8)) ? 0 : 0xffffff; |
1232 | (1 << (j % 8)) ? 0 : 0xffffff; |
1230 | if (pointer_x + j < screen.xres && pointer_y + |
1233 | if (pointer_x + j < screen.xres && pointer_y + |
1231 | i < screen.yres) |
1234 | i < screen.yres) |
1232 | putpixel(&viewports[0], pointer_x + j, |
1235 | putpixel(&viewports[0], pointer_x + j, |
1233 | pointer_y + i, color); |
1236 | pointer_y + i, color); |
1234 | } |
1237 | } |
1235 | } |
1238 | } |
1236 | pointer_shown = 1; |
1239 | pointer_shown = 1; |
1237 | } |
1240 | } |
1238 | 1241 | ||
1239 | 1242 | ||
1240 | static void mouse_hide(void) |
1243 | static void mouse_hide(void) |
1241 | { |
1244 | { |
1242 | /* Restore image under the pointer. */ |
1245 | /* Restore image under the pointer. */ |
1243 | if (pointer_shown) { |
1246 | if (pointer_shown) { |
1244 | draw_pixmap(pointer_vport, pointer_pixmap); |
1247 | draw_pixmap(pointer_vport, pointer_pixmap); |
1245 | pointer_shown = 0; |
1248 | pointer_shown = 0; |
1246 | } |
1249 | } |
1247 | } |
1250 | } |
1248 | 1251 | ||
1249 | 1252 | ||
1250 | static void mouse_move(unsigned int x, unsigned int y) |
1253 | static void mouse_move(unsigned int x, unsigned int y) |
1251 | { |
1254 | { |
1252 | mouse_hide(); |
1255 | mouse_hide(); |
1253 | pointer_x = x; |
1256 | pointer_x = x; |
1254 | pointer_y = y; |
1257 | pointer_y = y; |
1255 | mouse_show(); |
1258 | mouse_show(); |
1256 | } |
1259 | } |
1257 | 1260 | ||
1258 | 1261 | ||
1259 | static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
1262 | static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
1260 | { |
1263 | { |
1261 | bool handled = true; |
1264 | bool handled = true; |
1262 | int retval = EOK; |
1265 | int retval = EOK; |
1263 | int i, nvp; |
1266 | int i, nvp; |
1264 | int newval; |
1267 | int newval; |
1265 | 1268 | ||
1266 | switch (IPC_GET_METHOD(*call)) { |
1269 | switch (IPC_GET_METHOD(*call)) { |
1267 | case FB_ANIM_CREATE: |
1270 | case FB_ANIM_CREATE: |
1268 | nvp = IPC_GET_ARG1(*call); |
1271 | nvp = IPC_GET_ARG1(*call); |
1269 | if (nvp == -1) |
1272 | if (nvp == -1) |
1270 | nvp = vp; |
1273 | nvp = vp; |
1271 | if (nvp >= MAX_VIEWPORTS || nvp < 0 || |
1274 | if (nvp >= MAX_VIEWPORTS || nvp < 0 || |
1272 | !viewports[nvp].initialized) { |
1275 | !viewports[nvp].initialized) { |
1273 | retval = EINVAL; |
1276 | retval = EINVAL; |
1274 | break; |
1277 | break; |
1275 | } |
1278 | } |
1276 | for (i = 0; i < MAX_ANIMATIONS; i++) { |
1279 | for (i = 0; i < MAX_ANIMATIONS; i++) { |
1277 | if (!animations[i].initialized) |
1280 | if (!animations[i].initialized) |
1278 | break; |
1281 | break; |
1279 | } |
1282 | } |
1280 | if (i == MAX_ANIMATIONS) { |
1283 | if (i == MAX_ANIMATIONS) { |
1281 | retval = ELIMIT; |
1284 | retval = ELIMIT; |
1282 | break; |
1285 | break; |
1283 | } |
1286 | } |
1284 | animations[i].initialized = 1; |
1287 | animations[i].initialized = 1; |
1285 | animations[i].animlen = 0; |
1288 | animations[i].animlen = 0; |
1286 | animations[i].pos = 0; |
1289 | animations[i].pos = 0; |
1287 | animations[i].enabled = 0; |
1290 | animations[i].enabled = 0; |
1288 | animations[i].vp = nvp; |
1291 | animations[i].vp = nvp; |
1289 | retval = i; |
1292 | retval = i; |
1290 | break; |
1293 | break; |
1291 | case FB_ANIM_DROP: |
1294 | case FB_ANIM_DROP: |
1292 | i = IPC_GET_ARG1(*call); |
1295 | i = IPC_GET_ARG1(*call); |
1293 | if (i >= MAX_ANIMATIONS || i < 0) { |
1296 | if (i >= MAX_ANIMATIONS || i < 0) { |
1294 | retval = EINVAL; |
1297 | retval = EINVAL; |
1295 | break; |
1298 | break; |
1296 | } |
1299 | } |
1297 | animations[i].initialized = 0; |
1300 | animations[i].initialized = 0; |
1298 | break; |
1301 | break; |
1299 | case FB_ANIM_ADDPIXMAP: |
1302 | case FB_ANIM_ADDPIXMAP: |
1300 | i = IPC_GET_ARG1(*call); |
1303 | i = IPC_GET_ARG1(*call); |
1301 | if (i >= MAX_ANIMATIONS || i < 0 || |
1304 | if (i >= MAX_ANIMATIONS || i < 0 || |
1302 | !animations[i].initialized) { |
1305 | !animations[i].initialized) { |
1303 | retval = EINVAL; |
1306 | retval = EINVAL; |
1304 | break; |
1307 | break; |
1305 | } |
1308 | } |
1306 | if (animations[i].animlen == MAX_ANIM_LEN) { |
1309 | if (animations[i].animlen == MAX_ANIM_LEN) { |
1307 | retval = ELIMIT; |
1310 | retval = ELIMIT; |
1308 | break; |
1311 | break; |
1309 | } |
1312 | } |
1310 | newval = IPC_GET_ARG2(*call); |
1313 | newval = IPC_GET_ARG2(*call); |
1311 | if (newval < 0 || newval > MAX_PIXMAPS || |
1314 | if (newval < 0 || newval > MAX_PIXMAPS || |
1312 | !pixmaps[newval].data) { |
1315 | !pixmaps[newval].data) { |
1313 | retval = EINVAL; |
1316 | retval = EINVAL; |
1314 | break; |
1317 | break; |
1315 | } |
1318 | } |
1316 | animations[i].pixmaps[animations[i].animlen++] = newval; |
1319 | animations[i].pixmaps[animations[i].animlen++] = newval; |
1317 | break; |
1320 | break; |
1318 | case FB_ANIM_CHGVP: |
1321 | case FB_ANIM_CHGVP: |
1319 | i = IPC_GET_ARG1(*call); |
1322 | i = IPC_GET_ARG1(*call); |
1320 | if (i >= MAX_ANIMATIONS || i < 0) { |
1323 | if (i >= MAX_ANIMATIONS || i < 0) { |
1321 | retval = EINVAL; |
1324 | retval = EINVAL; |
1322 | break; |
1325 | break; |
1323 | } |
1326 | } |
1324 | nvp = IPC_GET_ARG2(*call); |
1327 | nvp = IPC_GET_ARG2(*call); |
1325 | if (nvp == -1) |
1328 | if (nvp == -1) |
1326 | nvp = vp; |
1329 | nvp = vp; |
1327 | if (nvp >= MAX_VIEWPORTS || nvp < 0 || |
1330 | if (nvp >= MAX_VIEWPORTS || nvp < 0 || |
1328 | !viewports[nvp].initialized) { |
1331 | !viewports[nvp].initialized) { |
1329 | retval = EINVAL; |
1332 | retval = EINVAL; |
1330 | break; |
1333 | break; |
1331 | } |
1334 | } |
1332 | animations[i].vp = nvp; |
1335 | animations[i].vp = nvp; |
1333 | break; |
1336 | break; |
1334 | case FB_ANIM_START: |
1337 | case FB_ANIM_START: |
1335 | case FB_ANIM_STOP: |
1338 | case FB_ANIM_STOP: |
1336 | i = IPC_GET_ARG1(*call); |
1339 | i = IPC_GET_ARG1(*call); |
1337 | if (i >= MAX_ANIMATIONS || i < 0) { |
1340 | if (i >= MAX_ANIMATIONS || i < 0) { |
1338 | retval = EINVAL; |
1341 | retval = EINVAL; |
1339 | break; |
1342 | break; |
1340 | } |
1343 | } |
1341 | newval = (IPC_GET_METHOD(*call) == FB_ANIM_START); |
1344 | newval = (IPC_GET_METHOD(*call) == FB_ANIM_START); |
1342 | if (newval ^ animations[i].enabled) { |
1345 | if (newval ^ animations[i].enabled) { |
1343 | animations[i].enabled = newval; |
1346 | animations[i].enabled = newval; |
1344 | anims_enabled += newval ? 1 : -1; |
1347 | anims_enabled += newval ? 1 : -1; |
1345 | } |
1348 | } |
1346 | break; |
1349 | break; |
1347 | default: |
1350 | default: |
1348 | handled = 0; |
1351 | handled = 0; |
1349 | } |
1352 | } |
1350 | if (handled) |
1353 | if (handled) |
1351 | ipc_answer_0(callid, retval); |
1354 | ipc_answer_0(callid, retval); |
1352 | return handled; |
1355 | return handled; |
1353 | } |
1356 | } |
1354 | 1357 | ||
1355 | 1358 | ||
1356 | /** Handler for messages concerning pixmap handling |
1359 | /** Handler for messages concerning pixmap handling |
1357 | * |
1360 | * |
1358 | */ |
1361 | */ |
1359 | static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
1362 | static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
1360 | { |
1363 | { |
1361 | bool handled = true; |
1364 | bool handled = true; |
1362 | int retval = EOK; |
1365 | int retval = EOK; |
1363 | int i, nvp; |
1366 | int i, nvp; |
1364 | 1367 | ||
1365 | switch (IPC_GET_METHOD(*call)) { |
1368 | switch (IPC_GET_METHOD(*call)) { |
1366 | case FB_VP_DRAW_PIXMAP: |
1369 | case FB_VP_DRAW_PIXMAP: |
1367 | nvp = IPC_GET_ARG1(*call); |
1370 | nvp = IPC_GET_ARG1(*call); |
1368 | if (nvp == -1) |
1371 | if (nvp == -1) |
1369 | nvp = vp; |
1372 | nvp = vp; |
1370 | if (nvp < 0 || nvp >= MAX_VIEWPORTS || |
1373 | if (nvp < 0 || nvp >= MAX_VIEWPORTS || |
1371 | !viewports[nvp].initialized) { |
1374 | !viewports[nvp].initialized) { |
1372 | retval = EINVAL; |
1375 | retval = EINVAL; |
1373 | break; |
1376 | break; |
1374 | } |
1377 | } |
1375 | i = IPC_GET_ARG2(*call); |
1378 | i = IPC_GET_ARG2(*call); |
1376 | retval = draw_pixmap(nvp, i); |
1379 | retval = draw_pixmap(nvp, i); |
1377 | break; |
1380 | break; |
1378 | case FB_VP2PIXMAP: |
1381 | case FB_VP2PIXMAP: |
1379 | nvp = IPC_GET_ARG1(*call); |
1382 | nvp = IPC_GET_ARG1(*call); |
1380 | if (nvp == -1) |
1383 | if (nvp == -1) |
1381 | nvp = vp; |
1384 | nvp = vp; |
1382 | if (nvp < 0 || nvp >= MAX_VIEWPORTS || |
1385 | if (nvp < 0 || nvp >= MAX_VIEWPORTS || |
1383 | !viewports[nvp].initialized) |
1386 | !viewports[nvp].initialized) |
1384 | retval = EINVAL; |
1387 | retval = EINVAL; |
1385 | else |
1388 | else |
1386 | retval = save_vp_to_pixmap(&viewports[nvp]); |
1389 | retval = save_vp_to_pixmap(&viewports[nvp]); |
1387 | break; |
1390 | break; |
1388 | case FB_DROP_PIXMAP: |
1391 | case FB_DROP_PIXMAP: |
1389 | i = IPC_GET_ARG1(*call); |
1392 | i = IPC_GET_ARG1(*call); |
1390 | if (i >= MAX_PIXMAPS) { |
1393 | if (i >= MAX_PIXMAPS) { |
1391 | retval = EINVAL; |
1394 | retval = EINVAL; |
1392 | break; |
1395 | break; |
1393 | } |
1396 | } |
1394 | if (pixmaps[i].data) { |
1397 | if (pixmaps[i].data) { |
1395 | free(pixmaps[i].data); |
1398 | free(pixmaps[i].data); |
1396 | pixmaps[i].data = NULL; |
1399 | pixmaps[i].data = NULL; |
1397 | } |
1400 | } |
1398 | break; |
1401 | break; |
1399 | default: |
1402 | default: |
1400 | handled = 0; |
1403 | handled = 0; |
1401 | } |
1404 | } |
1402 | 1405 | ||
1403 | if (handled) |
1406 | if (handled) |
1404 | ipc_answer_0(callid, retval); |
1407 | ipc_answer_0(callid, retval); |
1405 | return handled; |
1408 | return handled; |
1406 | 1409 | ||
1407 | } |
1410 | } |
1408 | 1411 | ||
1409 | static int rgb_from_style(attr_rgb_t *rgb, int style) |
1412 | static int rgb_from_style(attr_rgb_t *rgb, int style) |
1410 | { |
1413 | { |
1411 | switch (style) { |
1414 | switch (style) { |
1412 | case STYLE_NORMAL: |
1415 | case STYLE_NORMAL: |
1413 | rgb->fg_color = color_table[COLOR_BLACK]; |
1416 | rgb->fg_color = color_table[COLOR_BLACK]; |
1414 | rgb->bg_color = color_table[COLOR_WHITE]; |
1417 | rgb->bg_color = color_table[COLOR_WHITE]; |
1415 | break; |
1418 | break; |
1416 | case STYLE_EMPHASIS: |
1419 | case STYLE_EMPHASIS: |
1417 | rgb->fg_color = color_table[COLOR_RED]; |
1420 | rgb->fg_color = color_table[COLOR_RED]; |
1418 | rgb->bg_color = color_table[COLOR_WHITE]; |
1421 | rgb->bg_color = color_table[COLOR_WHITE]; |
1419 | break; |
1422 | break; |
1420 | default: |
1423 | default: |
1421 | return EINVAL; |
1424 | return EINVAL; |
1422 | } |
1425 | } |
1423 | 1426 | ||
1424 | return EOK; |
1427 | return EOK; |
1425 | } |
1428 | } |
1426 | 1429 | ||
1427 | static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color, |
1430 | static int rgb_from_idx(attr_rgb_t *rgb, ipcarg_t fg_color, |
1428 | ipcarg_t bg_color, ipcarg_t flags) |
1431 | ipcarg_t bg_color, ipcarg_t flags) |
1429 | { |
1432 | { |
1430 | fg_color = (fg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0); |
1433 | fg_color = (fg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0); |
1431 | bg_color = (bg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0); |
1434 | bg_color = (bg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0); |
1432 | 1435 | ||
1433 | rgb->fg_color = color_table[fg_color]; |
1436 | rgb->fg_color = color_table[fg_color]; |
1434 | rgb->bg_color = color_table[bg_color]; |
1437 | rgb->bg_color = color_table[bg_color]; |
1435 | 1438 | ||
1436 | return EOK; |
1439 | return EOK; |
1437 | } |
1440 | } |
1438 | 1441 | ||
1439 | static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a) |
1442 | static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a) |
1440 | { |
1443 | { |
1441 | int rc; |
1444 | int rc; |
1442 | 1445 | ||
1443 | switch (a->t) { |
1446 | switch (a->t) { |
1444 | case at_style: |
1447 | case at_style: |
1445 | rc = rgb_from_style(rgb, a->a.s.style); |
1448 | rc = rgb_from_style(rgb, a->a.s.style); |
1446 | break; |
1449 | break; |
1447 | case at_idx: |
1450 | case at_idx: |
1448 | rc = rgb_from_idx(rgb, a->a.i.fg_color, |
1451 | rc = rgb_from_idx(rgb, a->a.i.fg_color, |
1449 | a->a.i.bg_color, a->a.i.flags); |
1452 | a->a.i.bg_color, a->a.i.flags); |
1450 | break; |
1453 | break; |
1451 | case at_rgb: |
1454 | case at_rgb: |
1452 | *rgb = a->a.r; |
1455 | *rgb = a->a.r; |
1453 | rc = EOK; |
1456 | rc = EOK; |
1454 | break; |
1457 | break; |
1455 | } |
1458 | } |
1456 | 1459 | ||
1457 | return rc; |
1460 | return rc; |
1458 | } |
1461 | } |
1459 | 1462 | ||
1460 | static int fb_set_style(viewport_t *vport, ipcarg_t style) |
1463 | static int fb_set_style(viewport_t *vport, ipcarg_t style) |
1461 | { |
1464 | { |
1462 | return rgb_from_style(&vport->attr, (int) style); |
1465 | return rgb_from_style(&vport->attr, (int) style); |
1463 | } |
1466 | } |
1464 | 1467 | ||
1465 | static int fb_set_color(viewport_t *vport, ipcarg_t fg_color, |
1468 | static int fb_set_color(viewport_t *vport, ipcarg_t fg_color, |
1466 | ipcarg_t bg_color, ipcarg_t flags) |
1469 | ipcarg_t bg_color, ipcarg_t flags) |
1467 | { |
1470 | { |
1468 | return rgb_from_idx(&vport->attr, fg_color, bg_color, flags); |
1471 | return rgb_from_idx(&vport->attr, fg_color, bg_color, flags); |
1469 | } |
1472 | } |
1470 | 1473 | ||
1471 | /** Function for handling connections to FB |
1474 | /** Function for handling connections to FB |
1472 | * |
1475 | * |
1473 | */ |
1476 | */ |
1474 | static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
1477 | static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
1475 | { |
1478 | { |
1476 | unsigned int vp = 0; |
1479 | unsigned int vp = 0; |
1477 | viewport_t *vport = &viewports[vp]; |
1480 | viewport_t *vport = &viewports[vp]; |
1478 | 1481 | ||
1479 | if (client_connected) { |
1482 | if (client_connected) { |
1480 | ipc_answer_0(iid, ELIMIT); |
1483 | ipc_answer_0(iid, ELIMIT); |
1481 | return; |
1484 | return; |
1482 | } |
1485 | } |
1483 | 1486 | ||
1484 | /* Accept connection */ |
1487 | /* Accept connection */ |
1485 | client_connected = true; |
1488 | client_connected = true; |
1486 | ipc_answer_0(iid, EOK); |
1489 | ipc_answer_0(iid, EOK); |
1487 | 1490 | ||
1488 | while (true) { |
1491 | while (true) { |
1489 | ipc_callid_t callid; |
1492 | ipc_callid_t callid; |
1490 | ipc_call_t call; |
1493 | ipc_call_t call; |
1491 | int retval; |
1494 | int retval; |
1492 | unsigned int i; |
1495 | unsigned int i; |
1493 | int scroll; |
1496 | int scroll; |
1494 | uint8_t glyph; |
1497 | uint8_t glyph; |
1495 | unsigned int row, col; |
1498 | unsigned int row, col; |
1496 | 1499 | ||
1497 | if ((vport->cursor_active) || (anims_enabled)) |
1500 | if ((vport->cursor_active) || (anims_enabled)) |
1498 | callid = async_get_call_timeout(&call, 250000); |
1501 | callid = async_get_call_timeout(&call, 250000); |
1499 | else |
1502 | else |
1500 | callid = async_get_call(&call); |
1503 | callid = async_get_call(&call); |
1501 | 1504 | ||
1502 | mouse_hide(); |
1505 | mouse_hide(); |
1503 | if (!callid) { |
1506 | if (!callid) { |
1504 | cursor_blink(vport); |
1507 | cursor_blink(vport); |
1505 | anims_tick(); |
1508 | anims_tick(); |
1506 | mouse_show(); |
1509 | mouse_show(); |
1507 | continue; |
1510 | continue; |
1508 | } |
1511 | } |
1509 | 1512 | ||
1510 | if (shm_handle(callid, &call, vp)) |
1513 | if (shm_handle(callid, &call, vp)) |
1511 | continue; |
1514 | continue; |
1512 | 1515 | ||
1513 | if (pixmap_handle(callid, &call, vp)) |
1516 | if (pixmap_handle(callid, &call, vp)) |
1514 | continue; |
1517 | continue; |
1515 | 1518 | ||
1516 | if (anim_handle(callid, &call, vp)) |
1519 | if (anim_handle(callid, &call, vp)) |
1517 | continue; |
1520 | continue; |
1518 | 1521 | ||
1519 | switch (IPC_GET_METHOD(call)) { |
1522 | switch (IPC_GET_METHOD(call)) { |
1520 | case IPC_M_PHONE_HUNGUP: |
1523 | case IPC_M_PHONE_HUNGUP: |
1521 | client_connected = false; |
1524 | client_connected = false; |
1522 | 1525 | ||
1523 | /* Cleanup other viewports */ |
1526 | /* Cleanup other viewports */ |
1524 | for (i = 1; i < MAX_VIEWPORTS; i++) |
1527 | for (i = 1; i < MAX_VIEWPORTS; i++) |
1525 | vport->initialized = false; |
1528 | vport->initialized = false; |
1526 | 1529 | ||
1527 | /* Exit thread */ |
1530 | /* Exit thread */ |
1528 | return; |
1531 | return; |
1529 | 1532 | ||
1530 | case FB_PUTCHAR: |
1533 | case FB_PUTCHAR: |
1531 | glyph = IPC_GET_ARG1(call); |
1534 | glyph = IPC_GET_ARG1(call); |
1532 | row = IPC_GET_ARG2(call); |
1535 | row = IPC_GET_ARG2(call); |
1533 | col = IPC_GET_ARG3(call); |
1536 | col = IPC_GET_ARG3(call); |
1534 | 1537 | ||
1535 | if ((col >= vport->cols) || (row >= vport->rows)) { |
1538 | if ((col >= vport->cols) || (row >= vport->rows)) { |
1536 | retval = EINVAL; |
1539 | retval = EINVAL; |
1537 | break; |
1540 | break; |
1538 | } |
1541 | } |
1539 | ipc_answer_0(callid, EOK); |
1542 | ipc_answer_0(callid, EOK); |
1540 | 1543 | ||
1541 | draw_char(vport, glyph, col, row); |
1544 | draw_char(vport, glyph, col, row); |
1542 | 1545 | ||
1543 | /* Message already answered */ |
1546 | /* Message already answered */ |
1544 | continue; |
1547 | continue; |
1545 | case FB_CLEAR: |
1548 | case FB_CLEAR: |
1546 | vport_clear(vport); |
1549 | vport_clear(vport); |
1547 | cursor_show(vport); |
1550 | cursor_show(vport); |
1548 | retval = EOK; |
1551 | retval = EOK; |
1549 | break; |
1552 | break; |
1550 | case FB_CURSOR_GOTO: |
1553 | case FB_CURSOR_GOTO: |
1551 | row = IPC_GET_ARG1(call); |
1554 | row = IPC_GET_ARG1(call); |
1552 | col = IPC_GET_ARG2(call); |
1555 | col = IPC_GET_ARG2(call); |
1553 | 1556 | ||
1554 | if ((col >= vport->cols) || (row >= vport->rows)) { |
1557 | if ((col >= vport->cols) || (row >= vport->rows)) { |
1555 | retval = EINVAL; |
1558 | retval = EINVAL; |
1556 | break; |
1559 | break; |
1557 | } |
1560 | } |
1558 | retval = EOK; |
1561 | retval = EOK; |
1559 | 1562 | ||
1560 | cursor_hide(vport); |
1563 | cursor_hide(vport); |
1561 | vport->cur_col = col; |
1564 | vport->cur_col = col; |
1562 | vport->cur_row = row; |
1565 | vport->cur_row = row; |
1563 | cursor_show(vport); |
1566 | cursor_show(vport); |
1564 | break; |
1567 | break; |
1565 | case FB_CURSOR_VISIBILITY: |
1568 | case FB_CURSOR_VISIBILITY: |
1566 | cursor_hide(vport); |
1569 | cursor_hide(vport); |
1567 | vport->cursor_active = IPC_GET_ARG1(call); |
1570 | vport->cursor_active = IPC_GET_ARG1(call); |
1568 | cursor_show(vport); |
1571 | cursor_show(vport); |
1569 | retval = EOK; |
1572 | retval = EOK; |
1570 | break; |
1573 | break; |
1571 | case FB_GET_CSIZE: |
1574 | case FB_GET_CSIZE: |
1572 | ipc_answer_2(callid, EOK, vport->rows, vport->cols); |
1575 | ipc_answer_2(callid, EOK, vport->rows, vport->cols); |
1573 | continue; |
1576 | continue; |
1574 | case FB_SCROLL: |
1577 | case FB_SCROLL: |
1575 | scroll = IPC_GET_ARG1(call); |
1578 | scroll = IPC_GET_ARG1(call); |
1576 | if ((scroll > (int) vport->rows) || (scroll < (-(int) vport->rows))) { |
1579 | if ((scroll > (int) vport->rows) || (scroll < (-(int) vport->rows))) { |
1577 | retval = EINVAL; |
1580 | retval = EINVAL; |
1578 | break; |
1581 | break; |
1579 | } |
1582 | } |
1580 | cursor_hide(vport); |
1583 | cursor_hide(vport); |
1581 | vport_scroll(vport, scroll); |
1584 | vport_scroll(vport, scroll); |
1582 | cursor_show(vport); |
1585 | cursor_show(vport); |
1583 | retval = EOK; |
1586 | retval = EOK; |
1584 | break; |
1587 | break; |
1585 | case FB_VIEWPORT_SWITCH: |
1588 | case FB_VIEWPORT_SWITCH: |
1586 | i = IPC_GET_ARG1(call); |
1589 | i = IPC_GET_ARG1(call); |
1587 | if (i >= MAX_VIEWPORTS) { |
1590 | if (i >= MAX_VIEWPORTS) { |
1588 | retval = EINVAL; |
1591 | retval = EINVAL; |
1589 | break; |
1592 | break; |
1590 | } |
1593 | } |
1591 | if (!viewports[i].initialized) { |
1594 | if (!viewports[i].initialized) { |
1592 | retval = EADDRNOTAVAIL; |
1595 | retval = EADDRNOTAVAIL; |
1593 | break; |
1596 | break; |
1594 | } |
1597 | } |
1595 | cursor_hide(vport); |
1598 | cursor_hide(vport); |
1596 | vp = i; |
1599 | vp = i; |
1597 | vport = &viewports[vp]; |
1600 | vport = &viewports[vp]; |
1598 | cursor_show(vport); |
1601 | cursor_show(vport); |
1599 | retval = EOK; |
1602 | retval = EOK; |
1600 | break; |
1603 | break; |
1601 | case FB_VIEWPORT_CREATE: |
1604 | case FB_VIEWPORT_CREATE: |
1602 | retval = vport_create(IPC_GET_ARG1(call) >> 16, |
1605 | retval = vport_create(IPC_GET_ARG1(call) >> 16, |
1603 | IPC_GET_ARG1(call) & 0xffff, |
1606 | IPC_GET_ARG1(call) & 0xffff, |
1604 | IPC_GET_ARG2(call) >> 16, |
1607 | IPC_GET_ARG2(call) >> 16, |
1605 | IPC_GET_ARG2(call) & 0xffff); |
1608 | IPC_GET_ARG2(call) & 0xffff); |
1606 | break; |
1609 | break; |
1607 | case FB_VIEWPORT_DELETE: |
1610 | case FB_VIEWPORT_DELETE: |
1608 | i = IPC_GET_ARG1(call); |
1611 | i = IPC_GET_ARG1(call); |
1609 | if (i >= MAX_VIEWPORTS) { |
1612 | if (i >= MAX_VIEWPORTS) { |
1610 | retval = EINVAL; |
1613 | retval = EINVAL; |
1611 | break; |
1614 | break; |
1612 | } |
1615 | } |
1613 | if (!viewports[i].initialized) { |
1616 | if (!viewports[i].initialized) { |
1614 | retval = EADDRNOTAVAIL; |
1617 | retval = EADDRNOTAVAIL; |
1615 | break; |
1618 | break; |
1616 | } |
1619 | } |
1617 | viewports[i].initialized = false; |
1620 | viewports[i].initialized = false; |
1618 | if (viewports[i].glyphs) |
1621 | if (viewports[i].glyphs) |
1619 | free(viewports[i].glyphs); |
1622 | free(viewports[i].glyphs); |
1620 | if (viewports[i].bgpixel) |
1623 | if (viewports[i].bgpixel) |
1621 | free(viewports[i].bgpixel); |
1624 | free(viewports[i].bgpixel); |
1622 | if (viewports[i].backbuf) |
1625 | if (viewports[i].backbuf) |
1623 | free(viewports[i].backbuf); |
1626 | free(viewports[i].backbuf); |
1624 | retval = EOK; |
1627 | retval = EOK; |
1625 | break; |
1628 | break; |
- | 1629 | case FB_VIEWPORT_INVALIDATE: |
|
- | 1630 | i = IPC_GET_ARG1(call); |
|
- | 1631 | if (i >= MAX_VIEWPORTS) { |
|
- | 1632 | retval = EINVAL; |
|
- | 1633 | break; |
|
- | 1634 | } |
|
- | 1635 | viewports[i].bb_invalid = true; |
|
- | 1636 | retval = EOK; |
|
- | 1637 | break; |
|
- | 1638 | ||
1626 | case FB_SET_STYLE: |
1639 | case FB_SET_STYLE: |
1627 | retval = fb_set_style(vport, IPC_GET_ARG1(call)); |
1640 | retval = fb_set_style(vport, IPC_GET_ARG1(call)); |
1628 | break; |
1641 | break; |
1629 | case FB_SET_COLOR: |
1642 | case FB_SET_COLOR: |
1630 | retval = fb_set_color(vport, IPC_GET_ARG1(call), |
1643 | retval = fb_set_color(vport, IPC_GET_ARG1(call), |
1631 | IPC_GET_ARG2(call), IPC_GET_ARG3(call)); |
1644 | IPC_GET_ARG2(call), IPC_GET_ARG3(call)); |
1632 | break; |
1645 | break; |
1633 | case FB_SET_RGB_COLOR: |
1646 | case FB_SET_RGB_COLOR: |
1634 | vport->attr.fg_color = IPC_GET_ARG1(call); |
1647 | vport->attr.fg_color = IPC_GET_ARG1(call); |
1635 | vport->attr.bg_color = IPC_GET_ARG2(call); |
1648 | vport->attr.bg_color = IPC_GET_ARG2(call); |
1636 | retval = EOK; |
1649 | retval = EOK; |
1637 | break; |
1650 | break; |
1638 | case FB_GET_RESOLUTION: |
1651 | case FB_GET_RESOLUTION: |
1639 | ipc_answer_2(callid, EOK, screen.xres, screen.yres); |
1652 | ipc_answer_2(callid, EOK, screen.xres, screen.yres); |
1640 | continue; |
1653 | continue; |
1641 | case FB_POINTER_MOVE: |
1654 | case FB_POINTER_MOVE: |
1642 | pointer_enabled = true; |
1655 | pointer_enabled = true; |
1643 | mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); |
1656 | mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); |
1644 | retval = EOK; |
1657 | retval = EOK; |
1645 | break; |
1658 | break; |
1646 | default: |
1659 | default: |
1647 | retval = ENOENT; |
1660 | retval = ENOENT; |
1648 | } |
1661 | } |
1649 | ipc_answer_0(callid, retval); |
1662 | ipc_answer_0(callid, retval); |
1650 | } |
1663 | } |
1651 | } |
1664 | } |
1652 | 1665 | ||
1653 | /** Initialization of framebuffer |
1666 | /** Initialization of framebuffer |
1654 | * |
1667 | * |
1655 | */ |
1668 | */ |
1656 | int fb_init(void) |
1669 | int fb_init(void) |
1657 | { |
1670 | { |
1658 | async_set_client_connection(fb_client_connection); |
1671 | async_set_client_connection(fb_client_connection); |
1659 | 1672 | ||
1660 | void *fb_ph_addr = (void *) sysinfo_value("fb.address.physical"); |
1673 | void *fb_ph_addr = (void *) sysinfo_value("fb.address.physical"); |
1661 | unsigned int fb_offset = sysinfo_value("fb.offset"); |
1674 | unsigned int fb_offset = sysinfo_value("fb.offset"); |
1662 | unsigned int fb_width = sysinfo_value("fb.width"); |
1675 | unsigned int fb_width = sysinfo_value("fb.width"); |
1663 | unsigned int fb_height = sysinfo_value("fb.height"); |
1676 | unsigned int fb_height = sysinfo_value("fb.height"); |
1664 | unsigned int fb_scanline = sysinfo_value("fb.scanline"); |
1677 | unsigned int fb_scanline = sysinfo_value("fb.scanline"); |
1665 | unsigned int fb_visual = sysinfo_value("fb.visual"); |
1678 | unsigned int fb_visual = sysinfo_value("fb.visual"); |
1666 | 1679 | ||
1667 | unsigned int fbsize = fb_scanline * fb_height; |
1680 | unsigned int fbsize = fb_scanline * fb_height; |
1668 | void *fb_addr = as_get_mappable_page(fbsize); |
1681 | void *fb_addr = as_get_mappable_page(fbsize); |
1669 | 1682 | ||
1670 | physmem_map(fb_ph_addr + fb_offset, fb_addr, |
1683 | physmem_map(fb_ph_addr + fb_offset, fb_addr, |
1671 | ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE); |
1684 | ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE); |
1672 | 1685 | ||
1673 | if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual)) |
1686 | if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual)) |
1674 | return 0; |
1687 | return 0; |
1675 | 1688 | ||
1676 | return -1; |
1689 | return -1; |
1677 | } |
1690 | } |
1678 | 1691 | ||
1679 | /** |
1692 | /** |
1680 | * @} |
1693 | * @} |
1681 | */ |
1694 | */ |
1682 | 1695 |