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