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