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