Rev 3692 | Rev 3710 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3692 | Rev 3707 | ||
---|---|---|---|
Line 1... | Line 1... | ||
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 |
Line 30... | Line 31... | ||
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> |
Line 60... | Line 61... | ||
60 | #include "ppm.h" |
61 | #include "ppm.h" |
61 | 62 | ||
62 | #include "pointer.xbm" |
63 | #include "pointer.xbm" |
63 | #include "pointer_mask.xbm" |
64 | #include "pointer_mask.xbm" |
64 | 65 | ||
65 | #define DEFAULT_BGCOLOR 0xf0f0f0 |
66 | #define DEFAULT_BGCOLOR 0xf0f0f0 |
66 | #define DEFAULT_FGCOLOR 0x0 |
67 | #define DEFAULT_FGCOLOR 0x000000 |
67 | 68 | ||
- | 69 | #define MAX_ANIM_LEN 8 |
|
- | 70 | #define MAX_ANIMATIONS 4 |
|
68 | /***************************************************************/ |
71 | #define MAX_PIXMAPS 256 /**< Maximum number of saved pixmaps */ |
69 | /* Pixel specific fuctions */ |
72 | #define MAX_VIEWPORTS 128 /**< Viewport is a rectangular area on the screen */ |
70 | 73 | ||
71 | typedef void (*conv2scr_fn_t)(void *, int); |
74 | typedef void (*rgb_conv_t)(void *, uint32_t); |
72 | typedef int (*conv2rgb_fn_t)(void *); |
- | |
73 | 75 | ||
74 | struct { |
76 | struct { |
75 | uint8_t *fbaddress; |
77 | uint8_t *fb_addr; |
76 | 78 | ||
77 | unsigned int xres; |
79 | unsigned int xres; |
78 | unsigned int yres; |
80 | unsigned int yres; |
- | 81 | ||
79 | unsigned int scanline; |
82 | unsigned int scanline; |
- | 83 | unsigned int glyphscanline; |
|
- | 84 | ||
80 | unsigned int pixelbytes; |
85 | unsigned int pixelbytes; |
81 | unsigned int invert_colors; |
86 | unsigned int glyphbytes; |
82 | 87 | ||
83 | conv2scr_fn_t rgb2scr; |
88 | rgb_conv_t rgb_conv; |
84 | conv2rgb_fn_t scr2rgb; |
- | |
85 | } screen; |
89 | } screen; |
86 | 90 | ||
87 | typedef struct { |
91 | typedef struct { |
88 | int initialized; |
92 | bool initialized; |
89 | unsigned int x, y; |
93 | unsigned int x; |
- | 94 | unsigned int y; |
|
- | 95 | unsigned int width; |
|
90 | unsigned int width, height; |
96 | unsigned int height; |
91 | 97 | ||
92 | /* Text support in window */ |
98 | /* Text support in window */ |
- | 99 | unsigned int cols; |
|
93 | unsigned int rows, cols; |
100 | unsigned int rows; |
- | 101 | ||
94 | /* Style for text printing */ |
102 | /* Style and glyphs for text printing */ |
95 | style_t style; |
103 | style_t style; |
- | 104 | uint8_t *glyphs; |
|
- | 105 | uint8_t *bgpixel; |
|
- | 106 | ||
96 | /* Auto-cursor position */ |
107 | /* Auto-cursor position */ |
97 | int cursor_active, cur_col, cur_row; |
108 | bool cursor_active; |
- | 109 | unsigned int cur_col; |
|
- | 110 | unsigned int cur_row; |
|
98 | int cursor_shown; |
111 | bool cursor_shown; |
- | 112 | ||
99 | /* Double buffering */ |
113 | /* Back buffer */ |
100 | uint8_t *dbdata; |
- | |
101 | unsigned int dboffset; |
114 | unsigned int bbsize; |
102 | unsigned int paused; |
115 | uint8_t *backbuf; |
103 | } viewport_t; |
116 | } viewport_t; |
104 | 117 | ||
105 | #define MAX_ANIM_LEN 8 |
- | |
106 | #define MAX_ANIMATIONS 4 |
- | |
107 | typedef struct { |
118 | typedef struct { |
108 | int initialized; |
119 | bool initialized; |
109 | int enabled; |
120 | bool enabled; |
110 | unsigned int vp; |
121 | unsigned int vp; |
111 | 122 | ||
112 | unsigned int pos; |
123 | unsigned int pos; |
113 | unsigned int animlen; |
124 | unsigned int animlen; |
114 | unsigned int pixmaps[MAX_ANIM_LEN]; |
125 | unsigned int pixmaps[MAX_ANIM_LEN]; |
115 | } animation_t; |
126 | } animation_t; |
- | 127 | ||
116 | static animation_t animations[MAX_ANIMATIONS]; |
128 | static animation_t animations[MAX_ANIMATIONS]; |
117 | static int anims_enabled; |
129 | static bool anims_enabled; |
118 | 130 | ||
119 | /** Maximum number of saved pixmaps |
- | |
120 | * Pixmap is a saved rectangle |
- | |
121 | */ |
- | |
122 | #define MAX_PIXMAPS 256 |
- | |
123 | typedef struct { |
131 | typedef struct { |
124 | unsigned int width; |
132 | unsigned int width; |
125 | unsigned int height; |
133 | unsigned int height; |
126 | uint8_t *data; |
134 | uint8_t *data; |
127 | } pixmap_t; |
135 | } pixmap_t; |
128 | static pixmap_t pixmaps[MAX_PIXMAPS]; |
- | |
129 | 136 | ||
130 | /* Viewport is a rectangular area on the screen */ |
137 | static pixmap_t pixmaps[MAX_PIXMAPS]; |
131 | #define MAX_VIEWPORTS 128 |
- | |
132 | static viewport_t viewports[128]; |
138 | static viewport_t viewports[128]; |
133 | 139 | ||
134 | /* Allow only 1 connection */ |
- | |
135 | static int client_connected = 0; |
140 | static bool client_connected = false; /**< Allow only 1 connection */ |
136 | 141 | ||
137 | #define RED(x, bits) ((x >> (16 + 8 - bits)) & ((1 << bits) - 1)) |
142 | #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) |
138 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
143 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
139 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
144 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
140 | 145 | ||
141 | #define COL_WIDTH 8 |
146 | #define COL2X(col) ((col) * FONT_WIDTH) |
142 | #define ROW_BYTES (screen.scanline * FONT_SCANLINES) |
147 | #define ROW2Y(row) ((row) * FONT_SCANLINES) |
143 | 148 | ||
- | 149 | #define X2COL(x) ((x) / FONT_WIDTH) |
|
144 | #define POINTPOS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) |
150 | #define Y2ROW(y) ((y) / FONT_SCANLINES) |
145 | 151 | ||
146 | static inline int COLOR(int color) |
152 | #define FB_POS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) |
147 | { |
- | |
148 | return screen.invert_colors ? ~color : color; |
153 | #define BB_POS(vport, col, row) ((row) * vport->cols + (col)) |
149 | } |
- | |
- | 154 | #define GLYPH_POS(glyph, y, cursor) (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline) |
|
150 | 155 | ||
151 | /* Conversion routines between different color representations */ |
- | |
152 | static void |
- | |
153 | rgb_byte0888(void *dst, int rgb) |
- | |
154 | { |
- | |
155 | *(int *)dst = rgb; |
- | |
156 | } |
- | |
157 | 156 | ||
- | 157 | /** ARGB 8:8:8:8 conversion |
|
- | 158 | * |
|
158 | static int |
159 | */ |
159 | byte0888_rgb(void *src) |
160 | static void rgb_0888(void *dst, uint32_t rgb) |
160 | { |
161 | { |
161 | return (*(int *)src) & 0xffffff; |
162 | *((uint32_t *) dst) = rgb & 0xffffff; |
162 | } |
163 | } |
163 | 164 | ||
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 | 165 | ||
- | 166 | /** ABGR 8:8:8:8 conversion |
|
- | 167 | * |
|
171 | static int |
168 | */ |
172 | byte0888_bgr(void *src) |
169 | static void bgr_0888(void *dst, uint32_t rgb) |
173 | { |
170 | { |
174 | int color = *(uint32_t *)(src); |
171 | *((uint32_t *) dst) |
175 | return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | |
172 | = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8); |
176 | ((color >> 16) & 0xff); |
- | |
177 | } |
173 | } |
178 | 174 | ||
- | 175 | ||
179 | static void |
176 | /** BGR 8:8:8 conversion |
- | 177 | * |
|
- | 178 | */ |
|
180 | rgb_byte888(void *dst, int rgb) |
179 | static void rgb_888(void *dst, uint32_t rgb) |
181 | { |
180 | { |
182 | uint8_t *scr = dst; |
- | |
183 | #if defined(FB_INVERT_ENDIAN) |
181 | #if defined(FB_INVERT_ENDIAN) |
184 | scr[0] = RED(rgb, 8); |
182 | *((uint32_t *) dst) |
185 | scr[1] = GREEN(rgb, 8); |
183 | = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8) |
186 | scr[2] = BLUE(rgb, 8); |
184 | | (*((uint32_t *) dst) & 0xff0000); |
187 | #else |
185 | #else |
188 | scr[2] = RED(rgb, 8); |
186 | *((uint32_t *) dst) |
189 | scr[1] = GREEN(rgb, 8); |
187 | = (rgb & 0xffffff) | (*((uint32_t *) dst) & 0xff0000); |
190 | scr[0] = BLUE(rgb, 8); |
- | |
191 | #endif |
188 | #endif |
192 | } |
189 | } |
193 | 190 | ||
194 | static int |
- | |
195 | byte888_rgb(void *src) |
- | |
196 | { |
- | |
197 | uint8_t *scr = src; |
- | |
198 | #if defined(FB_INVERT_ENDIAN) |
- | |
199 | return scr[0] << 16 | scr[1] << 8 | scr[2]; |
- | |
200 | #else |
- | |
201 | return scr[2] << 16 | scr[1] << 8 | scr[0]; |
- | |
202 | #endif |
- | |
203 | } |
- | |
204 | 191 | ||
205 | /** 16-bit depth (5:5:5) */ |
192 | /** RGB 5:5:5 conversion |
- | 193 | * |
|
206 | static void |
194 | */ |
207 | rgb_byte555(void *dst, int rgb) |
195 | static void rgb_555(void *dst, uint32_t rgb) |
208 | { |
196 | { |
209 | /* 5-bit, 5-bits, 5-bits */ |
197 | *((uint16_t *) dst) |
210 | *((uint16_t *)(dst)) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | |
198 | = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5); |
211 | BLUE(rgb, 5); |
- | |
212 | } |
199 | } |
213 | 200 | ||
214 | /** 16-bit depth (5:5:5) */ |
- | |
215 | static int |
- | |
216 | byte555_rgb(void *src) |
- | |
217 | { |
- | |
218 | int color = *(uint16_t *)(src); |
- | |
219 | return (((color >> 10) & 0x1f) << (16 + 3)) | |
- | |
220 | (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3); |
- | |
221 | } |
- | |
222 | 201 | ||
223 | /** 16-bit depth (5:6:5) */ |
202 | /** RGB 5:6:5 conversion |
- | 203 | * |
|
224 | static void |
204 | */ |
225 | rgb_byte565(void *dst, int rgb) |
205 | static void rgb_565(void *dst, uint32_t rgb) |
226 | { |
206 | { |
227 | /* 5-bit, 6-bits, 5-bits */ |
207 | *((uint16_t *) dst) |
228 | *((uint16_t *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | |
208 | = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5); |
229 | BLUE(rgb, 5); |
- | |
230 | } |
209 | } |
231 | 210 | ||
232 | /** 16-bit depth (5:6:5) */ |
- | |
233 | static int |
- | |
234 | byte565_rgb(void *src) |
- | |
235 | { |
- | |
236 | int color = *(uint16_t *)(src); |
- | |
237 | return (((color >> 11) & 0x1f) << (16 + 3)) | |
- | |
238 | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); |
- | |
239 | } |
- | |
240 | 211 | ||
241 | /** Put pixel - 8-bit depth (3:2:3) */ |
212 | /** RGB 3:2:3 |
- | 213 | * |
|
242 | static void |
214 | */ |
243 | rgb_byte8(void *dst, int rgb) |
215 | static void rgb_323(void *dst, uint32_t rgb) |
244 | { |
216 | { |
- | 217 | *((uint8_t *) dst) |
|
245 | *(uint8_t *)dst = 255 - (RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | |
218 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
246 | BLUE(rgb, 3)); |
- | |
247 | } |
219 | } |
248 | 220 | ||
249 | /** Return pixel color - 8-bit depth (3:2:3) */ |
- | |
250 | static int |
- | |
251 | byte8_rgb(void *src) |
- | |
252 | { |
- | |
253 | int color = 255 - (*(uint8_t *)src); |
- | |
254 | return (((color >> 5) & 0x7) << (16 + 5)) | |
- | |
255 | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
- | |
256 | } |
- | |
257 | 221 | ||
258 | /** Put pixel into viewport |
222 | /** Redraw viewport |
- | 223 | * |
|
- | 224 | * @param vport Viewport to redraw |
|
259 | * |
225 | * |
260 | * @param vport Viewport identification |
- | |
261 | * @param x X coord relative to viewport |
- | |
262 | * @param y Y coord relative to viewport |
- | |
263 | * @param color RGB color |
- | |
264 | */ |
226 | */ |
265 | static void |
- | |
266 | putpixel(viewport_t *vport, unsigned int x, unsigned int y, int color) |
227 | static void vport_redraw(viewport_t *vport) |
267 | { |
228 | { |
268 | int dx = vport->x + x; |
- | |
269 | int dy = vport->y + y; |
229 | unsigned int row; |
270 | 230 | ||
271 | if (! (vport->paused && vport->dbdata)) |
231 | for (row = 0; row < vport->rows; row++) { |
272 | (*screen.rgb2scr)(&screen.fbaddress[POINTPOS(dx,dy)], |
232 | unsigned int y = vport->y + ROW2Y(row); |
273 | COLOR(color)); |
233 | unsigned int yd; |
274 | 234 | ||
- | 235 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
|
275 | if (vport->dbdata) { |
236 | unsigned int x; |
- | 237 | unsigned int col; |
|
- | 238 | ||
276 | int dline = (y + vport->dboffset) % vport->height; |
239 | for (col = 0, x = vport->x; col < vport->cols; col++, x += FONT_WIDTH) |
277 | int doffset = screen.pixelbytes * (dline * vport->width + x); |
240 | memcpy(&screen.fb_addr[FB_POS(x, y + yd)], |
278 | (*screen.rgb2scr)(&vport->dbdata[doffset], COLOR(color)); |
241 | &vport->glyphs[GLYPH_POS(vport->backbuf[BB_POS(vport, col, row)], yd, false)], |
- | 242 | screen.glyphscanline); |
|
- | 243 | } |
|
279 | } |
244 | } |
280 | } |
245 | |
281 | - | ||
282 | /** Get pixel from viewport */ |
246 | if (COL2X(vport->cols) < vport->width) { |
283 | static int |
247 | unsigned int y; |
284 | getpixel(viewport_t *vport, unsigned int x, unsigned int y) |
- | |
285 | { |
248 | |
286 | int dx = vport->x + x; |
- | |
287 | int dy = vport->y + y; |
249 | for (y = 0; y < vport->height; y++) { |
288 | - | ||
289 | return COLOR((*screen.scr2rgb)(&screen.fbaddress[POINTPOS(dx, dy)])); |
- | |
290 | } |
- | |
291 | - | ||
292 | static inline void |
- | |
293 | putpixel_mem(char *mem, unsigned int x, unsigned int y, int color) |
- | |
294 | { |
- | |
295 | (*screen.rgb2scr)(&mem[POINTPOS(x, y)], COLOR(color)); |
- | |
296 | } |
- | |
297 | - | ||
298 | static void |
- | |
299 | draw_rectangle(viewport_t *vport, unsigned int sx, unsigned int sy, |
- | |
300 | unsigned int width, unsigned int height, int color) |
- | |
301 | { |
- | |
302 | unsigned int x, y; |
250 | unsigned int x; |
303 | static void *tmpline; |
- | |
304 | - | ||
305 | if (!tmpline) |
- | |
306 | tmpline = malloc(screen.scanline * screen.pixelbytes); |
- | |
307 | 251 | ||
308 | /* Clear first line */ |
- | |
309 | for (x = 0; x < width; x++) |
252 | for (x = COL2X(vport->cols); x < vport->width; x++) |
310 | putpixel_mem(tmpline, x, 0, color); |
253 | memcpy(&screen.fb_addr[FB_POS(x, y)], vport->bgpixel, screen.pixelbytes); |
311 | 254 | } |
|
312 | if (!vport->paused) { |
- | |
313 | /* Recompute to screen coords */ |
- | |
314 | sx += vport->x; |
- | |
315 | sy += vport->y; |
- | |
316 | /* Copy the rest */ |
- | |
317 | for (y = sy;y < sy+height; y++) |
- | |
318 | memcpy(&screen.fbaddress[POINTPOS(sx,y)], tmpline, |
- | |
319 | screen.pixelbytes * width); |
- | |
320 | } |
255 | } |
- | 256 | ||
321 | if (vport->dbdata) { |
257 | if (ROW2Y(vport->rows) < vport->height) { |
322 | for (y = sy; y < sy + height; y++) { |
258 | unsigned int y; |
- | 259 | ||
323 | int rline = (y + vport->dboffset) % vport->height; |
260 | for (y = ROW2Y(vport->rows); y < vport->height; y++) { |
324 | int rpos = (rline * vport->width + sx) * |
- | |
325 | screen.pixelbytes; |
261 | unsigned int x; |
- | 262 | ||
326 | memcpy(&vport->dbdata[rpos], tmpline, |
263 | for (x = 0; x < vport->width; x++) |
327 | screen.pixelbytes * width); |
264 | memcpy(&screen.fb_addr[FB_POS(x, y)], vport->bgpixel, screen.pixelbytes); |
328 | } |
265 | } |
329 | } |
266 | } |
330 | - | ||
331 | } |
267 | } |
332 | 268 | ||
333 | /** Fill viewport with background color */ |
- | |
334 | static void |
- | |
335 | clear_port(viewport_t *vport) |
- | |
336 | { |
- | |
337 | draw_rectangle(vport, 0, 0, vport->width, vport->height, |
- | |
338 | vport->style.bg_color); |
- | |
339 | } |
- | |
340 | 269 | ||
- | 270 | /** Clear viewport |
|
- | 271 | * |
|
341 | /** Scroll unbuffered viewport up/down |
272 | * @param vport Viewport to clear |
342 | * |
273 | * |
343 | * @param vport Viewport to scroll |
- | |
344 | * @param lines Positive number - scroll up, negative - scroll down |
- | |
345 | */ |
274 | */ |
346 | static void |
- | |
347 | scroll_port_nodb(viewport_t *vport, int lines) |
275 | static void vport_clear(viewport_t *vport) |
348 | { |
276 | { |
349 | int y; |
- | |
350 | - | ||
351 | if (lines > 0) { |
- | |
352 | for (y = vport->y; y < vport->y+vport->height - lines; y++) |
- | |
353 | memcpy(&screen.fbaddress[POINTPOS(vport->x,y)], |
- | |
354 | &screen.fbaddress[POINTPOS(vport->x,y + lines)], |
- | |
355 | screen.pixelbytes * vport->width); |
- | |
356 | draw_rectangle(vport, 0, vport->height - lines, vport->width, |
- | |
357 | lines, vport->style.bg_color); |
- | |
358 | } else if (lines < 0) { |
- | |
359 | lines = -lines; |
- | |
360 | for (y = vport->y + vport->height-1; y >= vport->y + lines; y--) |
- | |
361 | memcpy(&screen.fbaddress[POINTPOS(vport->x,y)], |
- | |
362 | &screen.fbaddress[POINTPOS(vport->x,y - lines)], |
- | |
363 | screen.pixelbytes * vport->width); |
- | |
364 | draw_rectangle(vport, 0, 0, vport->width, lines, |
277 | memset(vport->backbuf, 0, vport->bbsize); |
365 | vport->style.bg_color); |
278 | vport_redraw(vport); |
366 | } |
- | |
367 | } |
279 | } |
368 | 280 | ||
369 | /** Refresh given viewport from double buffer */ |
- | |
370 | static void |
- | |
371 | refresh_viewport_db(viewport_t *vport) |
- | |
372 | { |
- | |
373 | unsigned int y, srcy, srcoff, dsty, dstx; |
- | |
374 | 281 | ||
375 | for (y = 0; y < vport->height; y++) { |
- | |
376 | srcy = (y + vport->dboffset) % vport->height; |
282 | /** Scroll viewport by given number of lines |
377 | srcoff = (vport->width * srcy) * screen.pixelbytes; |
- | |
378 | 283 | * |
|
379 | dstx = vport->x; |
- | |
380 | dsty = vport->y + y; |
284 | * @param vport Viewport to scroll |
381 | - | ||
382 | memcpy(&screen.fbaddress[POINTPOS(dstx,dsty)], |
285 | * @param lines Number of lines to scroll |
383 | &vport->dbdata[srcoff], vport->width * screen.pixelbytes); |
- | |
384 | } |
286 | * |
385 | } |
287 | */ |
386 | - | ||
387 | /** Scroll viewport that has double buffering enabled */ |
- | |
388 | static void |
- | |
389 | scroll_port_db(viewport_t *vport, int lines) |
288 | static void vport_scroll(viewport_t *vport, int lines) |
390 | { |
289 | { |
391 | ++vport->paused; |
- | |
392 | if (lines > 0) { |
- | |
393 | draw_rectangle(vport, 0, 0, vport->width, lines, |
- | |
394 | vport->style.bg_color); |
- | |
395 | vport->dboffset += lines; |
- | |
396 | vport->dboffset %= vport->height; |
- | |
397 | } else if (lines < 0) { |
- | |
398 | lines = -lines; |
290 | unsigned int row; |
399 | draw_rectangle(vport, 0, vport->height-lines, vport->width, |
- | |
400 | lines, vport->style.bg_color); |
- | |
401 | - | ||
402 | if (vport->dboffset < lines) |
- | |
403 | vport->dboffset += vport->height; |
- | |
404 | vport->dboffset -= lines; |
- | |
405 | } |
- | |
406 | - | ||
407 | --vport->paused; |
- | |
408 | 291 | ||
409 | refresh_viewport_db(vport); |
292 | for (row = 0; row < vport->rows; row++) { |
- | 293 | unsigned int y = vport->y + ROW2Y(row); |
|
- | 294 | unsigned int yd; |
|
410 | } |
295 | |
411 | - | ||
412 | /** Scrolls viewport given number of lines */ |
296 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
- | 297 | unsigned int x; |
|
413 | static void |
298 | unsigned int col; |
- | 299 | ||
414 | scroll_port(viewport_t *vport, int lines) |
300 | for (col = 0, x = vport->x; col < vport->cols; col++, x += FONT_WIDTH) { |
- | 301 | uint8_t glyph; |
|
415 | { |
302 | |
- | 303 | if ((row + lines >= 0) && (row + lines < vport->rows)) { |
|
- | 304 | if (vport->backbuf[BB_POS(vport, col, row)] == vport->backbuf[BB_POS(vport, col, row + lines)]) |
|
416 | if (vport->dbdata) |
305 | continue; |
- | 306 | ||
417 | scroll_port_db(vport, lines); |
307 | glyph = vport->backbuf[BB_POS(vport, col, row + lines)]; |
418 | else |
308 | } else |
- | 309 | glyph = 0; |
|
- | 310 | ||
419 | scroll_port_nodb(vport, lines); |
311 | memcpy(&screen.fb_addr[FB_POS(x, y + yd)], |
- | 312 | &vport->glyphs[GLYPH_POS(glyph, yd, false)], screen.glyphscanline); |
|
- | 313 | } |
|
- | 314 | } |
|
- | 315 | } |
|
420 | 316 | ||
421 | } |
- | |
422 | - | ||
423 | static void |
317 | if (lines > 0) { |
- | 318 | memcpy(vport->backbuf, vport->backbuf + vport->cols * lines, vport->cols * (vport->rows - lines)); |
|
424 | invert_pixel(viewport_t *vport, unsigned int x, unsigned int y) |
319 | memset(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)], 0, vport->cols * lines); |
425 | { |
320 | } else { |
- | 321 | memcpy(vport->backbuf - vport->cols * lines, vport->backbuf, vport->cols * (vport->rows + lines)); |
|
426 | putpixel(vport, x, y, ~getpixel(vport, x, y)); |
322 | memset(vport->backbuf, 0, - vport->cols * lines); |
- | 323 | } |
|
427 | } |
324 | } |
428 | 325 | ||
429 | 326 | ||
- | 327 | /** Render glyphs |
|
- | 328 | * |
|
430 | /***************************************************************/ |
329 | * Convert glyphs from device independent font |
431 | /* Character-console functions */ |
330 | * description to current visual representation. |
432 | 331 | * |
|
433 | /** Draw character at given position |
332 | * @param vport Viewport |
434 | * |
333 | * |
435 | * @param vport Viewport where the character is printed |
- | |
436 | * @param sx Coordinates of top-left of the character |
- | |
437 | * @param sy Coordinates of top-left of the character |
- | |
438 | * @param style Color of the character |
- | |
439 | * @param transparent If false, print background color |
- | |
440 | */ |
334 | */ |
441 | static void |
- | |
442 | draw_glyph(viewport_t *vport,uint8_t glyph, unsigned int sx, unsigned int sy, |
- | |
443 | style_t style, int transparent) |
335 | static void render_glyphs(viewport_t* vport) |
444 | { |
336 | { |
445 | int i; |
337 | unsigned int glyph; |
- | 338 | ||
- | 339 | for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { |
|
446 | unsigned int y; |
340 | unsigned int y; |
- | 341 | ||
- | 342 | for (y = 0; y < FONT_SCANLINES; y++) { |
|
447 | unsigned int glline; |
343 | unsigned int x; |
448 | 344 | ||
449 | for (y = 0; y < FONT_SCANLINES; y++) { |
345 | for (x = 0; x < FONT_WIDTH; x++) { |
- | 346 | screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes], |
|
450 | glline = fb_font[glyph * FONT_SCANLINES + y]; |
347 | (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x))) |
- | 348 | ? vport->style.fg_color : vport->style.bg_color); |
|
- | 349 | ||
451 | for (i = 0; i < 8; i++) { |
350 | uint32_t curcolor; |
- | 351 | ||
452 | if (glline & (1 << (7 - i))) |
352 | if (y < FONT_SCANLINES - 2) |
- | 353 | curcolor = |
|
- | 354 | (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x))) |
|
453 | putpixel(vport, sx + i, sy + y, style.fg_color); |
355 | ? vport->style.fg_color : vport->style.bg_color; |
454 | else if (!transparent) |
356 | else |
455 | putpixel(vport, sx + i, sy + y, style.bg_color); |
357 | curcolor = vport->style.fg_color; |
- | 358 | ||
- | 359 | screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes], curcolor); |
|
- | 360 | } |
|
456 | } |
361 | } |
457 | } |
362 | } |
- | 363 | ||
- | 364 | screen.rgb_conv(vport->bgpixel, vport->style.bg_color); |
|
458 | } |
365 | } |
459 | 366 | ||
460 | /** Invert character at given position */ |
- | |
461 | static void |
- | |
462 | invert_char(viewport_t *vport,unsigned int row, unsigned int col) |
- | |
463 | { |
- | |
464 | unsigned int x; |
- | |
465 | unsigned int y; |
- | |
466 | - | ||
467 | for (x = 0; x < COL_WIDTH; x++) |
- | |
468 | for (y = 0; y < FONT_SCANLINES; y++) |
- | |
469 | invert_pixel(vport, col * COL_WIDTH + x, row * |
- | |
470 | FONT_SCANLINES + y); |
- | |
471 | } |
- | |
472 | - | ||
473 | /***************************************************************/ |
- | |
474 | /* Stdout specific functions */ |
- | |
475 | - | ||
476 | 367 | ||
477 | /** Create new viewport |
368 | /** Create new viewport |
478 | * |
369 | * |
- | 370 | * @param x Origin of the viewport (x). |
|
- | 371 | * @param y Origin of the viewport (y). |
|
- | 372 | * @param width Width of the viewport. |
|
- | 373 | * @param height Height of the viewport. |
|
- | 374 | * |
|
479 | * @return New viewport number |
375 | * @return New viewport number. |
- | 376 | * |
|
480 | */ |
377 | */ |
481 | static int |
- | |
482 | viewport_create(unsigned int x, unsigned int y,unsigned int width, |
378 | static int vport_create(unsigned int x, unsigned int y, |
483 | unsigned int height) |
379 | unsigned int width, unsigned int height) |
484 | { |
380 | { |
485 | int i; |
381 | unsigned int i; |
486 | 382 | ||
487 | for (i = 0; i < MAX_VIEWPORTS; i++) { |
383 | for (i = 0; i < MAX_VIEWPORTS; i++) { |
488 | if (!viewports[i].initialized) |
384 | if (!viewports[i].initialized) |
489 | break; |
385 | break; |
490 | } |
386 | } |
491 | if (i == MAX_VIEWPORTS) |
387 | if (i == MAX_VIEWPORTS) |
492 | return ELIMIT; |
388 | return ELIMIT; |
493 | 389 | ||
- | 390 | unsigned int cols = width / FONT_WIDTH; |
|
- | 391 | unsigned int rows = height / FONT_SCANLINES; |
|
- | 392 | unsigned int bbsize = cols * rows; |
|
- | 393 | unsigned int glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes; |
|
- | 394 | ||
- | 395 | uint8_t *backbuf = (uint8_t *) malloc(bbsize); |
|
- | 396 | if (!backbuf) |
|
- | 397 | return ENOMEM; |
|
- | 398 | ||
- | 399 | uint8_t *glyphs = (uint8_t *) malloc(glyphsize); |
|
- | 400 | if (!glyphs) { |
|
- | 401 | free(backbuf); |
|
- | 402 | return ENOMEM; |
|
- | 403 | } |
|
- | 404 | ||
- | 405 | uint8_t *bgpixel = (uint8_t *) malloc(screen.pixelbytes); |
|
- | 406 | if (!bgpixel) { |
|
- | 407 | free(glyphs); |
|
- | 408 | free(backbuf); |
|
- | 409 | return ENOMEM; |
|
- | 410 | } |
|
- | 411 | ||
- | 412 | memset(backbuf, 0, bbsize); |
|
- | 413 | memset(glyphs, 0, glyphsize); |
|
- | 414 | memset(bgpixel, 0, screen.pixelbytes); |
|
- | 415 | ||
494 | viewports[i].x = x; |
416 | viewports[i].x = x; |
495 | viewports[i].y = y; |
417 | viewports[i].y = y; |
496 | viewports[i].width = width; |
418 | viewports[i].width = width; |
497 | viewports[i].height = height; |
419 | viewports[i].height = height; |
498 | 420 | ||
499 | viewports[i].rows = height / FONT_SCANLINES; |
421 | viewports[i].cols = cols; |
500 | viewports[i].cols = width / COL_WIDTH; |
422 | viewports[i].rows = rows; |
501 | 423 | ||
502 | viewports[i].style.bg_color = DEFAULT_BGCOLOR; |
424 | viewports[i].style.bg_color = DEFAULT_BGCOLOR; |
503 | viewports[i].style.fg_color = DEFAULT_FGCOLOR; |
425 | viewports[i].style.fg_color = DEFAULT_FGCOLOR; |
504 | 426 | ||
- | 427 | viewports[i].glyphs = glyphs; |
|
- | 428 | viewports[i].bgpixel = bgpixel; |
|
- | 429 | ||
505 | viewports[i].cur_col = 0; |
430 | viewports[i].cur_col = 0; |
506 | viewports[i].cur_row = 0; |
431 | viewports[i].cur_row = 0; |
507 | viewports[i].cursor_active = 0; |
432 | viewports[i].cursor_active = false; |
- | 433 | viewports[i].cursor_shown = false; |
|
- | 434 | ||
- | 435 | viewports[i].bbsize = bbsize; |
|
- | 436 | viewports[i].backbuf = backbuf; |
|
508 | 437 | ||
509 | viewports[i].initialized = 1; |
438 | viewports[i].initialized = true; |
- | 439 | ||
- | 440 | render_glyphs(&viewports[i]); |
|
510 | 441 | ||
511 | return i; |
442 | return i; |
512 | } |
443 | } |
513 | 444 | ||
- | 445 | ||
514 | /** Initialize framebuffer as a chardev output device |
446 | /** Initialize framebuffer as a chardev output device |
515 | * |
447 | * |
516 | * @param addr Address of theframebuffer |
448 | * @param addr Address of the framebuffer |
517 | * @param xres Screen width in pixels |
449 | * @param xres Screen width in pixels |
518 | * @param yres Screen height in pixels |
450 | * @param yres Screen height in pixels |
519 | * @param visual Bits per pixel (8, 16, 24, 32) |
451 | * @param visual Bits per pixel (8, 16, 24, 32) |
520 | * @param scan Bytes per one scanline |
452 | * @param scan Bytes per one scanline |
521 | * @param invert_colors Inverted colors. |
- | |
522 | * |
453 | * |
523 | */ |
454 | */ |
524 | static bool |
- | |
525 | screen_init(void *addr, unsigned int offset, unsigned int xres, |
455 | static bool screen_init(void *addr, unsigned int xres, unsigned int yres, |
526 | unsigned int yres, unsigned int scan, unsigned int visual, |
456 | unsigned int scan, unsigned int visual) |
527 | bool invert_colors) |
- | |
528 | { |
457 | { |
529 | switch (visual) { |
458 | switch (visual) { |
530 | case VISUAL_INDIRECT_8: |
459 | case VISUAL_INDIRECT_8: |
531 | screen.rgb2scr = rgb_byte8; |
460 | screen.rgb_conv = rgb_323; |
532 | screen.scr2rgb = byte8_rgb; |
- | |
533 | screen.pixelbytes = 1; |
461 | screen.pixelbytes = 1; |
534 | break; |
462 | break; |
535 | case VISUAL_RGB_5_5_5: |
463 | case VISUAL_RGB_5_5_5: |
536 | screen.rgb2scr = rgb_byte555; |
464 | screen.rgb_conv = rgb_555; |
537 | screen.scr2rgb = byte555_rgb; |
- | |
538 | screen.pixelbytes = 2; |
465 | screen.pixelbytes = 2; |
539 | break; |
466 | break; |
540 | case VISUAL_RGB_5_6_5: |
467 | case VISUAL_RGB_5_6_5: |
541 | screen.rgb2scr = rgb_byte565; |
468 | screen.rgb_conv = rgb_565; |
542 | screen.scr2rgb = byte565_rgb; |
- | |
543 | screen.pixelbytes = 2; |
469 | screen.pixelbytes = 2; |
544 | break; |
470 | break; |
545 | case VISUAL_RGB_8_8_8: |
471 | case VISUAL_RGB_8_8_8: |
546 | screen.rgb2scr = rgb_byte888; |
472 | screen.rgb_conv = rgb_888; |
547 | screen.scr2rgb = byte888_rgb; |
- | |
548 | screen.pixelbytes = 3; |
473 | screen.pixelbytes = 3; |
549 | break; |
474 | break; |
550 | case VISUAL_RGB_8_8_8_0: |
475 | case VISUAL_RGB_8_8_8_0: |
551 | screen.rgb2scr = rgb_byte888; |
476 | screen.rgb_conv = rgb_888; |
552 | screen.scr2rgb = byte888_rgb; |
- | |
553 | screen.pixelbytes = 4; |
477 | screen.pixelbytes = 4; |
554 | break; |
478 | break; |
555 | case VISUAL_RGB_0_8_8_8: |
479 | case VISUAL_RGB_0_8_8_8: |
556 | screen.rgb2scr = rgb_byte0888; |
480 | screen.rgb_conv = rgb_0888; |
557 | screen.scr2rgb = byte0888_rgb; |
- | |
558 | screen.pixelbytes = 4; |
481 | screen.pixelbytes = 4; |
559 | break; |
482 | break; |
560 | case VISUAL_BGR_0_8_8_8: |
483 | case VISUAL_BGR_0_8_8_8: |
561 | screen.rgb2scr = bgr_byte0888; |
484 | screen.rgb_conv = bgr_0888; |
562 | screen.scr2rgb = byte0888_bgr; |
- | |
563 | screen.pixelbytes = 4; |
485 | screen.pixelbytes = 4; |
564 | break; |
486 | break; |
565 | default: |
487 | default: |
566 | return false; |
488 | return false; |
567 | } |
489 | } |
568 | 490 | ||
569 | screen.fbaddress = (unsigned char *) (((uintptr_t) addr)); |
491 | screen.fb_addr = (unsigned char *) addr; |
570 | screen.xres = xres; |
492 | screen.xres = xres; |
571 | screen.yres = yres; |
493 | screen.yres = yres; |
572 | screen.scanline = scan; |
494 | screen.scanline = scan; |
- | 495 | ||
573 | screen.invert_colors = invert_colors; |
496 | screen.glyphscanline = FONT_WIDTH * screen.pixelbytes; |
- | 497 | screen.glyphbytes = screen.glyphscanline * FONT_SCANLINES; |
|
574 | 498 | ||
575 | /* Create first viewport */ |
499 | /* Create first viewport */ |
576 | viewport_create(0, 0, xres, yres); |
500 | vport_create(0, 0, xres, yres); |
577 | 501 | ||
578 | return true; |
502 | return true; |
579 | } |
503 | } |
580 | 504 | ||
- | 505 | ||
- | 506 | /** Draw glyph at given position relative to viewport |
|
- | 507 | * |
|
- | 508 | * @param vport Viewport identification |
|
- | 509 | * @param cursor Draw glyph with cursor |
|
- | 510 | * @param col Screen position relative to viewport |
|
- | 511 | * @param row Screen position relative to viewport |
|
- | 512 | * |
|
- | 513 | */ |
|
- | 514 | static void draw_glyph(viewport_t *vport, bool cursor, unsigned int col, unsigned int row) |
|
- | 515 | { |
|
- | 516 | unsigned int x = vport->x + COL2X(col); |
|
- | 517 | unsigned int y = vport->y + ROW2Y(row); |
|
- | 518 | unsigned int yd; |
|
- | 519 | ||
- | 520 | uint8_t glyph = vport->backbuf[BB_POS(vport, col, row)]; |
|
- | 521 | ||
- | 522 | for (yd = 0; yd < FONT_SCANLINES; yd++) |
|
- | 523 | memcpy(&screen.fb_addr[FB_POS(x, y + yd)], |
|
- | 524 | &vport->glyphs[GLYPH_POS(glyph, yd, cursor)], screen.glyphscanline); |
|
- | 525 | } |
|
- | 526 | ||
- | 527 | ||
581 | /** Hide cursor if it is shown */ |
528 | /** Hide cursor if it is shown |
- | 529 | * |
|
582 | static void |
530 | */ |
583 | cursor_hide(viewport_t *vport) |
531 | static void cursor_hide(viewport_t *vport) |
584 | { |
532 | { |
585 | if (vport->cursor_active && vport->cursor_shown) { |
533 | if ((vport->cursor_active) && (vport->cursor_shown)) { |
586 | invert_char(vport, vport->cur_row, vport->cur_col); |
534 | draw_glyph(vport, false, vport->cur_col, vport->cur_row); |
587 | vport->cursor_shown = 0; |
535 | vport->cursor_shown = false; |
588 | } |
536 | } |
589 | } |
537 | } |
590 | 538 | ||
- | 539 | ||
591 | /** Show cursor if cursor showing is enabled */ |
540 | /** Show cursor if cursor showing is enabled |
- | 541 | * |
|
592 | static void |
542 | */ |
593 | cursor_print(viewport_t *vport) |
543 | static void cursor_show(viewport_t *vport) |
594 | { |
544 | { |
595 | /* Do not check for cursor_shown */ |
545 | /* Do not check for cursor_shown */ |
596 | if (vport->cursor_active) { |
546 | if (vport->cursor_active) { |
597 | invert_char(vport, vport->cur_row, vport->cur_col); |
547 | draw_glyph(vport, true, vport->cur_col, vport->cur_row); |
598 | vport->cursor_shown = 1; |
548 | vport->cursor_shown = true; |
599 | } |
549 | } |
600 | } |
550 | } |
601 | 551 | ||
- | 552 | ||
602 | /** Invert cursor, if it is enabled */ |
553 | /** Invert cursor, if it is enabled |
- | 554 | * |
|
603 | static void |
555 | */ |
604 | cursor_blink(viewport_t *vport) |
556 | static void cursor_blink(viewport_t *vport) |
605 | { |
557 | { |
606 | if (vport->cursor_shown) |
558 | if (vport->cursor_shown) |
607 | cursor_hide(vport); |
559 | cursor_hide(vport); |
608 | else |
560 | else |
609 | cursor_print(vport); |
561 | cursor_show(vport); |
610 | } |
562 | } |
611 | 563 | ||
612 | /** Draw character at given position relative to viewport |
- | |
613 | * |
- | |
614 | * @param vport Viewport identification |
- | |
615 | * @param c Character to print |
- | |
616 | * @param row Screen position relative to viewport |
- | |
617 | * @param col Screen position relative to viewport |
- | |
618 | * @param transparent If false, print background color with character |
- | |
619 | */ |
- | |
620 | static void |
- | |
621 | draw_char(viewport_t *vport, char c, unsigned int row, unsigned int col, |
- | |
622 | style_t style, int transparent) |
- | |
623 | { |
- | |
624 | /* Optimize - do not hide cursor if we are going to overwrite it */ |
- | |
625 | if (vport->cursor_active && vport->cursor_shown && |
- | |
626 | (vport->cur_col != col || vport->cur_row != row)) |
- | |
627 | invert_char(vport, vport->cur_row, vport->cur_col); |
- | |
628 | - | ||
629 | draw_glyph(vport, c, col * COL_WIDTH, row * FONT_SCANLINES, style, |
- | |
630 | transparent); |
- | |
631 | 564 | ||
- | 565 | /** Draw character at given position relative to viewport |
|
- | 566 | * |
|
- | 567 | * @param vport Viewport identification |
|
- | 568 | * @param c Character to draw |
|
- | 569 | * @param col Screen position relative to viewport |
|
- | 570 | * @param row Screen position relative to viewport |
|
- | 571 | * |
|
- | 572 | */ |
|
- | 573 | static void draw_char(viewport_t *vport, uint8_t c, unsigned int col, unsigned int row) |
|
- | 574 | { |
|
- | 575 | /* Do not hide cursor if we are going to overwrite it */ |
|
- | 576 | if ((vport->cursor_active) && (vport->cursor_shown) && |
|
- | 577 | ((vport->cur_col != col) || (vport->cur_row != row))) |
|
- | 578 | cursor_hide(vport); |
|
- | 579 | ||
- | 580 | uint8_t glyph = vport->backbuf[BB_POS(vport, col, row)]; |
|
- | 581 | ||
- | 582 | if (glyph != c) { |
|
- | 583 | vport->backbuf[BB_POS(vport, col, row)] = c; |
|
- | 584 | draw_glyph(vport, false, col, row); |
|
- | 585 | } |
|
- | 586 | ||
632 | vport->cur_col = col; |
587 | vport->cur_col = col; |
633 | vport->cur_row = row; |
588 | vport->cur_row = row; |
634 | 589 | ||
635 | vport->cur_col++; |
590 | vport->cur_col++; |
636 | if (vport->cur_col >= vport->cols) { |
591 | if (vport->cur_col >= vport->cols) { |
637 | vport->cur_col = 0; |
592 | vport->cur_col = 0; |
638 | vport->cur_row++; |
593 | vport->cur_row++; |
639 | if (vport->cur_row >= vport->rows) |
594 | if (vport->cur_row >= vport->rows) |
640 | vport->cur_row--; |
595 | vport->cur_row--; |
641 | } |
596 | } |
- | 597 | ||
642 | cursor_print(vport); |
598 | cursor_show(vport); |
643 | } |
599 | } |
644 | 600 | ||
- | 601 | ||
645 | /** Draw text data to viewport |
602 | /** Draw text data to viewport |
646 | * |
603 | * |
647 | * @param vport Viewport id |
604 | * @param vport Viewport id |
648 | * @param data Text data fitting exactly into viewport |
605 | * @param data Text data fitting exactly into viewport |
- | 606 | * |
|
649 | */ |
607 | */ |
650 | static void |
- | |
651 | draw_text_data(viewport_t *vport, keyfield_t *data) |
608 | static void draw_text_data(viewport_t *vport, keyfield_t *data) |
652 | { |
609 | { |
653 | int i; |
610 | unsigned int i; |
654 | int col,row; |
- | |
655 | 611 | ||
656 | clear_port(vport); |
- | |
657 | for (i = 0; i < vport->cols * vport->rows; i++) { |
612 | for (i = 0; i < vport->cols * vport->rows; i++) { |
658 | if (data[i].character == ' ' && style_same(data[i].style, |
613 | unsigned int col = i % vport->cols; |
659 | vport->style)) |
614 | unsigned int row = i / vport->cols; |
660 | continue; |
615 | |
661 | col = i % vport->cols; |
616 | uint8_t glyph = vport->backbuf[BB_POS(vport, col, row)]; |
- | 617 | ||
662 | row = i / vport->cols; |
618 | // TODO: use data[i].style |
- | 619 | ||
663 | draw_glyph(vport, data[i].character, col * COL_WIDTH, row * |
620 | if (glyph != data[i].character) { |
664 | FONT_SCANLINES, data[i].style, style_same(data[i].style, |
621 | vport->backbuf[BB_POS(vport, col, row)] = data[i].character; |
665 | vport->style)); |
622 | draw_glyph(vport, false, col, row); |
- | 623 | } |
|
666 | } |
624 | } |
667 | cursor_print(vport); |
625 | cursor_show(vport); |
668 | } |
626 | } |
669 | 627 | ||
670 | /** Return first free pixmap */ |
- | |
671 | static int |
628 | |
672 | find_free_pixmap(void) |
629 | static void putpixel_pixmap(void *data, unsigned int x, unsigned int y, uint32_t color) |
673 | { |
630 | { |
674 | int i; |
631 | int pm = *((int *) data); |
- | 632 | pixmap_t *pmap = &pixmaps[pm]; |
|
- | 633 | unsigned int pos = (y * pmap->width + x) * screen.pixelbytes; |
|
675 | 634 | ||
676 | for (i = 0;i < MAX_PIXMAPS;i++) |
635 | screen.rgb_conv(&pmap->data[pos], color); |
677 | if (!pixmaps[i].data) |
- | |
678 | return i; |
- | |
679 | return -1; |
- | |
680 | } |
636 | } |
681 | 637 | ||
682 | static void |
638 | |
683 | putpixel_pixmap(int pm, unsigned int x, unsigned int y, int color) |
639 | static void putpixel(void *data, unsigned int x, unsigned int y, uint32_t color) |
684 | { |
640 | { |
- | 641 | viewport_t *vport = (viewport_t *) data; |
|
- | 642 | unsigned int dx = vport->x + x; |
|
685 | pixmap_t *pmap = &pixmaps[pm]; |
643 | unsigned int dy = vport->y + y; |
- | 644 | ||
686 | int pos = (y * pmap->width + x) * screen.pixelbytes; |
645 | screen.rgb_conv(&screen.fb_addr[FB_POS(dx, dy)], color); |
- | 646 | } |
|
- | 647 | ||
687 | 648 | ||
- | 649 | /** Return first free pixmap |
|
- | 650 | * |
|
- | 651 | */ |
|
688 | (*screen.rgb2scr)(&pmap->data[pos],COLOR(color)); |
652 | static int find_free_pixmap(void) |
- | 653 | { |
|
- | 654 | unsigned int i; |
|
- | 655 | ||
- | 656 | for (i = 0; i < MAX_PIXMAPS; i++) |
|
- | 657 | if (!pixmaps[i].data) |
|
- | 658 | return i; |
|
- | 659 | ||
- | 660 | return -1; |
|
689 | } |
661 | } |
690 | 662 | ||
- | 663 | ||
691 | /** Create a new pixmap and return appropriate ID */ |
664 | /** Create a new pixmap and return appropriate ID |
- | 665 | * |
|
692 | static int |
666 | */ |
693 | shm2pixmap(unsigned char *shm, size_t size) |
667 | static int shm2pixmap(unsigned char *shm, size_t size) |
694 | { |
668 | { |
695 | int pm; |
669 | int pm; |
696 | pixmap_t *pmap; |
670 | pixmap_t *pmap; |
697 | 671 | ||
698 | pm = find_free_pixmap(); |
672 | pm = find_free_pixmap(); |
699 | if (pm == -1) |
673 | if (pm == -1) |
700 | return ELIMIT; |
674 | return ELIMIT; |
- | 675 | ||
701 | pmap = &pixmaps[pm]; |
676 | pmap = &pixmaps[pm]; |
702 | 677 | ||
703 | if (ppm_get_data(shm, size, &pmap->width, &pmap->height)) |
678 | if (ppm_get_data(shm, size, &pmap->width, &pmap->height)) |
704 | return EINVAL; |
679 | return EINVAL; |
705 | 680 | ||
706 | pmap->data = malloc(pmap->width * pmap->height * screen.pixelbytes); |
681 | pmap->data = malloc(pmap->width * pmap->height * screen.pixelbytes); |
707 | if (!pmap->data) |
682 | if (!pmap->data) |
708 | return ENOMEM; |
683 | return ENOMEM; |
709 | 684 | ||
710 | ppm_draw(shm, size, 0, 0, pmap->width, pmap->height, |
685 | ppm_draw(shm, size, 0, 0, pmap->width, pmap->height, putpixel_pixmap, (void *) &pm); |
711 | (putpixel_cb_t)putpixel_pixmap, (void *)pm); |
- | |
712 | 686 | ||
713 | return pm; |
687 | return pm; |
714 | } |
688 | } |
715 | 689 | ||
- | 690 | ||
716 | /** Handle shared memory communication calls |
691 | /** Handle shared memory communication calls |
717 | * |
692 | * |
718 | * Protocol for drawing pixmaps: |
693 | * Protocol for drawing pixmaps: |
719 | * - FB_PREPARE_SHM(client shm identification) |
694 | * - FB_PREPARE_SHM(client shm identification) |
720 | * - IPC_M_AS_AREA_SEND |
695 | * - IPC_M_AS_AREA_SEND |
721 | * - FB_DRAW_PPM(startx,starty) |
696 | * - FB_DRAW_PPM(startx, starty) |
722 | * - FB_DROP_SHM |
697 | * - FB_DROP_SHM |
723 | * |
698 | * |
724 | * Protocol for text drawing |
699 | * Protocol for text drawing |
725 | * - IPC_M_AS_AREA_SEND |
700 | * - IPC_M_AS_AREA_SEND |
726 | * - FB_DRAW_TEXT_DATA |
701 | * - FB_DRAW_TEXT_DATA |
727 | * |
702 | * |
728 | * @param callid Callid of the current call |
703 | * @param callid Callid of the current call |
729 | * @param call Current call data |
704 | * @param call Current call data |
730 | * @param vp Active viewport |
705 | * @param vp Active viewport |
731 | * @return 0 if the call was not handled byt this function, 1 otherwise |
- | |
732 | * |
706 | * |
- | 707 | * @return false if the call was not handled byt this function, true otherwise |
|
- | 708 | * |
|
733 | * note: this function is not threads safe, you would have |
709 | * Note: this function is not threads safe, you would have |
734 | * to redefine static variables with __thread |
710 | * to redefine static variables with __thread |
- | 711 | * |
|
735 | */ |
712 | */ |
736 | static int |
- | |
737 | shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
713 | static bool shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
738 | { |
714 | { |
739 | static keyfield_t *interbuffer = NULL; |
715 | static keyfield_t *interbuffer = NULL; |
740 | static size_t intersize = 0; |
716 | static size_t intersize = 0; |
741 | 717 | ||
742 | static unsigned char *shm = NULL; |
718 | static unsigned char *shm = NULL; |
743 | static ipcarg_t shm_id = 0; |
719 | static ipcarg_t shm_id = 0; |
744 | static size_t shm_size; |
720 | static size_t shm_size; |
745 | 721 | ||
746 | int handled = 1; |
722 | bool handled = true; |
747 | int retval = 0; |
723 | int retval = EOK; |
748 | viewport_t *vport = &viewports[vp]; |
724 | viewport_t *vport = &viewports[vp]; |
- | 725 | unsigned int x; |
|
749 | unsigned int x, y; |
726 | unsigned int y; |
750 | 727 | ||
751 | switch (IPC_GET_METHOD(*call)) { |
728 | switch (IPC_GET_METHOD(*call)) { |
752 | case IPC_M_SHARE_OUT: |
729 | case IPC_M_SHARE_OUT: |
753 | /* We accept one area for data interchange */ |
730 | /* We accept one area for data interchange */ |
754 | if (IPC_GET_ARG1(*call) == shm_id) { |
731 | if (IPC_GET_ARG1(*call) == shm_id) { |
755 | void *dest = as_get_mappable_page(IPC_GET_ARG2(*call)); |
732 | void *dest = as_get_mappable_page(IPC_GET_ARG2(*call)); |
756 | shm_size = IPC_GET_ARG2(*call); |
733 | shm_size = IPC_GET_ARG2(*call); |
757 | if (!ipc_answer_1(callid, EOK, (sysarg_t) dest)) |
734 | if (!ipc_answer_1(callid, EOK, (sysarg_t) dest)) |
758 | shm = dest; |
735 | shm = dest; |
759 | else |
736 | else |
760 | shm_id = 0; |
737 | shm_id = 0; |
- | 738 | ||
761 | if (shm[0] != 'P') |
739 | if (shm[0] != 'P') |
762 | while (1) |
740 | return false; |
763 | ; |
741 | |
764 | return 1; |
742 | return true; |
765 | } else { |
743 | } else { |
766 | intersize = IPC_GET_ARG2(*call); |
744 | intersize = IPC_GET_ARG2(*call); |
767 | receive_comm_area(callid, call, (void *) &interbuffer); |
745 | receive_comm_area(callid, call, (void *) &interbuffer); |
768 | } |
746 | } |
769 | return 1; |
747 | return true; |
770 | case FB_PREPARE_SHM: |
748 | case FB_PREPARE_SHM: |
771 | if (shm_id) |
749 | if (shm_id) |
772 | retval = EBUSY; |
750 | retval = EBUSY; |
773 | else |
751 | else |
774 | shm_id = IPC_GET_ARG1(*call); |
752 | shm_id = IPC_GET_ARG1(*call); |
Line 779... | Line 757... | ||
779 | as_area_destroy(shm); |
757 | as_area_destroy(shm); |
780 | shm = NULL; |
758 | shm = NULL; |
781 | } |
759 | } |
782 | shm_id = 0; |
760 | shm_id = 0; |
783 | break; |
761 | break; |
784 | 762 | ||
785 | case FB_SHM2PIXMAP: |
763 | case FB_SHM2PIXMAP: |
786 | if (!shm) { |
764 | if (!shm) { |
787 | retval = EINVAL; |
765 | retval = EINVAL; |
788 | break; |
766 | break; |
789 | } |
767 | } |
Line 794... | Line 772... | ||
794 | retval = EINVAL; |
772 | retval = EINVAL; |
795 | break; |
773 | break; |
796 | } |
774 | } |
797 | x = IPC_GET_ARG1(*call); |
775 | x = IPC_GET_ARG1(*call); |
798 | y = IPC_GET_ARG2(*call); |
776 | y = IPC_GET_ARG2(*call); |
- | 777 | ||
799 | if (x > vport->width || y > vport->height) { |
778 | if ((x > vport->width) || (y > vport->height)) { |
800 | retval = EINVAL; |
779 | retval = EINVAL; |
801 | break; |
780 | break; |
802 | } |
781 | } |
803 | 782 | ||
804 | ppm_draw(shm, shm_size, IPC_GET_ARG1(*call), |
783 | ppm_draw(shm, shm_size, IPC_GET_ARG1(*call), |
805 | IPC_GET_ARG2(*call), vport->width - x, vport->height - y, |
784 | IPC_GET_ARG2(*call), vport->width - x, vport->height - y, putpixel, (void *) vport); |
806 | (putpixel_cb_t)putpixel, vport); |
- | |
807 | break; |
785 | break; |
808 | case FB_DRAW_TEXT_DATA: |
786 | case FB_DRAW_TEXT_DATA: |
809 | if (!interbuffer) { |
787 | if (!interbuffer) { |
810 | retval = EINVAL; |
788 | retval = EINVAL; |
811 | break; |
789 | break; |
812 | } |
790 | } |
813 | if (intersize < vport->cols * vport->rows * |
791 | if (intersize < vport->cols * vport->rows * sizeof(*interbuffer)) { |
814 | sizeof(*interbuffer)) { |
- | |
815 | retval = EINVAL; |
792 | retval = EINVAL; |
816 | break; |
793 | break; |
817 | } |
794 | } |
818 | draw_text_data(vport, interbuffer); |
795 | draw_text_data(vport, interbuffer); |
819 | break; |
796 | break; |
820 | default: |
797 | default: |
821 | handled = 0; |
798 | handled = false; |
822 | } |
799 | } |
823 | 800 | ||
824 | if (handled) |
801 | if (handled) |
825 | ipc_answer_0(callid, retval); |
802 | ipc_answer_0(callid, retval); |
826 | return handled; |
803 | return handled; |
827 | } |
804 | } |
828 | 805 | ||
829 | static void |
- | |
830 | copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap) |
- | |
831 | { |
- | |
832 | int y; |
- | |
833 | int tmp, srcrowsize; |
- | |
834 | int realwidth, realheight, realrowsize; |
- | |
835 | int width = vport->width; |
- | |
836 | int height = vport->height; |
- | |
837 | 806 | ||
- | 807 | static void copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap) |
|
- | 808 | { |
|
- | 809 | unsigned int width = vport->width; |
|
- | 810 | unsigned int height = vport->height; |
|
- | 811 | ||
838 | if (width + vport->x > screen.xres) |
812 | if (width + vport->x > screen.xres) |
839 | width = screen.xres - vport->x; |
813 | width = screen.xres - vport->x; |
840 | if (height + vport->y > screen.yres) |
814 | if (height + vport->y > screen.yres) |
841 | height = screen.yres - vport->y; |
815 | height = screen.yres - vport->y; |
842 | 816 | ||
843 | realwidth = pmap->width <= width ? pmap->width : width; |
817 | unsigned int realwidth = pmap->width <= width ? pmap->width : width; |
844 | realheight = pmap->height <= height ? pmap->height : height; |
818 | unsigned int realheight = pmap->height <= height ? pmap->height : height; |
845 | - | ||
846 | srcrowsize = vport->width * screen.pixelbytes; |
- | |
847 | realrowsize = realwidth * screen.pixelbytes; |
- | |
848 | 819 | ||
- | 820 | unsigned int srcrowsize = vport->width * screen.pixelbytes; |
|
- | 821 | unsigned int realrowsize = realwidth * screen.pixelbytes; |
|
- | 822 | ||
- | 823 | unsigned int y; |
|
849 | for (y = 0; y < realheight; y++) { |
824 | for (y = 0; y < realheight; y++) { |
850 | tmp = (vport->y + y) * screen.scanline + |
825 | unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; |
851 | vport->x * screen.pixelbytes; |
- | |
852 | memcpy(pmap->data + srcrowsize * y, screen.fbaddress + tmp, |
826 | memcpy(pmap->data + srcrowsize * y, screen.fb_addr + tmp, realrowsize); |
853 | realrowsize); |
- | |
854 | } |
827 | } |
855 | } |
828 | } |
856 | 829 | ||
- | 830 | ||
857 | /** Save viewport to pixmap */ |
831 | /** Save viewport to pixmap |
- | 832 | * |
|
858 | static int |
833 | */ |
859 | save_vp_to_pixmap(viewport_t *vport) |
834 | static int save_vp_to_pixmap(viewport_t *vport) |
860 | { |
835 | { |
861 | int pm; |
836 | int pm; |
862 | pixmap_t *pmap; |
837 | pixmap_t *pmap; |
863 | 838 | ||
864 | pm = find_free_pixmap(); |
839 | pm = find_free_pixmap(); |
865 | if (pm == -1) |
840 | if (pm == -1) |
866 | return ELIMIT; |
841 | return ELIMIT; |
867 | 842 | ||
868 | pmap = &pixmaps[pm]; |
843 | pmap = &pixmaps[pm]; |
869 | pmap->data = malloc(screen.pixelbytes * vport->width * vport->height); |
844 | pmap->data = malloc(screen.pixelbytes * vport->width * vport->height); |
870 | if (!pmap->data) |
845 | if (!pmap->data) |
871 | return ENOMEM; |
846 | return ENOMEM; |
872 | 847 | ||
873 | pmap->width = vport->width; |
848 | pmap->width = vport->width; |
874 | pmap->height = vport->height; |
849 | pmap->height = vport->height; |
875 | 850 | ||
876 | copy_vp_to_pixmap(vport, pmap); |
851 | copy_vp_to_pixmap(vport, pmap); |
877 | 852 | ||
878 | return pm; |
853 | return pm; |
879 | } |
854 | } |
880 | 855 | ||
- | 856 | ||
881 | /** Draw pixmap on screen |
857 | /** Draw pixmap on screen |
882 | * |
858 | * |
883 | * @param vp Viewport to draw on |
859 | * @param vp Viewport to draw on |
884 | * @param pm Pixmap identifier |
860 | * @param pm Pixmap identifier |
- | 861 | * |
|
885 | */ |
862 | */ |
886 | static int draw_pixmap(int vp, int pm) |
863 | static int draw_pixmap(int vp, int pm) |
887 | { |
864 | { |
888 | pixmap_t *pmap = &pixmaps[pm]; |
865 | pixmap_t *pmap = &pixmaps[pm]; |
889 | viewport_t *vport = &viewports[vp]; |
866 | viewport_t *vport = &viewports[vp]; |
890 | int y; |
867 | |
891 | int tmp, srcrowsize; |
- | |
892 | int realwidth, realheight, realrowsize; |
- | |
893 | int width = vport->width; |
868 | unsigned int width = vport->width; |
894 | int height = vport->height; |
869 | unsigned int height = vport->height; |
895 | 870 | ||
896 | if (width + vport->x > screen.xres) |
871 | if (width + vport->x > screen.xres) |
897 | width = screen.xres - vport->x; |
872 | width = screen.xres - vport->x; |
898 | if (height + vport->y > screen.yres) |
873 | if (height + vport->y > screen.yres) |
899 | height = screen.yres - vport->y; |
874 | height = screen.yres - vport->y; |
900 | 875 | ||
901 | if (!pmap->data) |
876 | if (!pmap->data) |
902 | return EINVAL; |
877 | return EINVAL; |
903 | 878 | ||
904 | realwidth = pmap->width <= width ? pmap->width : width; |
879 | unsigned int realwidth = pmap->width <= width ? pmap->width : width; |
905 | realheight = pmap->height <= height ? pmap->height : height; |
880 | unsigned int realheight = pmap->height <= height ? pmap->height : height; |
906 | 881 | ||
907 | srcrowsize = vport->width * screen.pixelbytes; |
882 | unsigned int srcrowsize = vport->width * screen.pixelbytes; |
908 | realrowsize = realwidth * screen.pixelbytes; |
883 | unsigned int realrowsize = realwidth * screen.pixelbytes; |
909 | 884 | ||
- | 885 | unsigned int y; |
|
910 | for (y = 0; y < realheight; y++) { |
886 | for (y = 0; y < realheight; y++) { |
911 | tmp = (vport->y + y) * screen.scanline + |
887 | unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes; |
912 | vport->x * screen.pixelbytes; |
- | |
913 | memcpy(screen.fbaddress + tmp, pmap->data + y * srcrowsize, |
888 | memcpy(screen.fb_addr + tmp, pmap->data + y * srcrowsize, realrowsize); |
914 | realrowsize); |
- | |
915 | } |
889 | } |
- | 890 | ||
916 | return 0; |
891 | return EOK; |
917 | } |
892 | } |
918 | 893 | ||
- | 894 | ||
919 | /** Tick animation one step forward */ |
895 | /** Tick animation one step forward |
- | 896 | * |
|
920 | static void |
897 | */ |
921 | anims_tick(void) |
898 | static void anims_tick(void) |
922 | { |
899 | { |
923 | int i; |
900 | unsigned int i; |
924 | static int counts = 0; |
901 | static int counts = 0; |
925 | 902 | ||
926 | /* Limit redrawing */ |
903 | /* Limit redrawing */ |
927 | counts = (counts + 1) % 8; |
904 | counts = (counts + 1) % 8; |
928 | if (counts) |
905 | if (counts) |
929 | return; |
906 | return; |
930 | 907 | ||
931 | for (i = 0; i < MAX_ANIMATIONS; i++) { |
908 | for (i = 0; i < MAX_ANIMATIONS; i++) { |
932 | if (!animations[i].animlen || !animations[i].initialized || |
909 | if ((!animations[i].animlen) || (!animations[i].initialized) || |
933 | !animations[i].enabled) |
910 | (!animations[i].enabled)) |
934 | continue; |
911 | continue; |
935 | draw_pixmap(animations[i].vp, |
912 | |
936 | animations[i].pixmaps[animations[i].pos]); |
913 | draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]); |
937 | animations[i].pos = (animations[i].pos + 1) % |
914 | animations[i].pos = (animations[i].pos + 1) % animations[i].animlen; |
938 | animations[i].animlen; |
- | |
939 | } |
915 | } |
940 | } |
916 | } |
941 | 917 | ||
942 | 918 | ||
- | 919 | static unsigned int pointer_x; |
|
943 | static int pointer_x, pointer_y; |
920 | static unsigned int pointer_y; |
944 | static int pointer_shown, pointer_enabled; |
921 | static bool pointer_shown, pointer_enabled; |
945 | static int pointer_vport = -1; |
922 | static int pointer_vport = -1; |
946 | static int pointer_pixmap = -1; |
923 | static int pointer_pixmap = -1; |
947 | 924 | ||
948 | static void |
925 | |
949 | mouse_show(void) |
926 | static void mouse_show(void) |
950 | { |
927 | { |
951 | int i, j; |
928 | int i, j; |
952 | int visibility; |
929 | int visibility; |
953 | int color; |
930 | int color; |
954 | int bytepos; |
931 | int bytepos; |
955 | 932 | ||
956 | if (pointer_shown || !pointer_enabled) |
933 | if ((pointer_shown) || (!pointer_enabled)) |
957 | return; |
934 | return; |
958 | 935 | ||
959 | /* Save image under the cursor */ |
936 | /* Save image under the cursor */ |
960 | if (pointer_vport == -1) { |
937 | if (pointer_vport == -1) { |
961 | pointer_vport = viewport_create(pointer_x, pointer_y, |
938 | pointer_vport = vport_create(pointer_x, pointer_y, pointer_width, pointer_height); |
962 | pointer_width, pointer_height); |
- | |
963 | if (pointer_vport < 0) |
939 | if (pointer_vport < 0) |
964 | return; |
940 | return; |
965 | } else { |
941 | } else { |
966 | viewports[pointer_vport].x = pointer_x; |
942 | viewports[pointer_vport].x = pointer_x; |
967 | viewports[pointer_vport].y = pointer_y; |
943 | viewports[pointer_vport].y = pointer_y; |
968 | } |
944 | } |
969 | 945 | ||
970 | if (pointer_pixmap == -1) |
946 | if (pointer_pixmap == -1) |
971 | pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]); |
947 | pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]); |
972 | else |
948 | else |
973 | copy_vp_to_pixmap(&viewports[pointer_vport], |
949 | copy_vp_to_pixmap(&viewports[pointer_vport], &pixmaps[pointer_pixmap]); |
974 | &pixmaps[pointer_pixmap]); |
- | |
975 | 950 | ||
976 | /* Draw cursor */ |
951 | /* Draw cursor */ |
977 | for (i = 0; i < pointer_height; i++) |
952 | for (i = 0; i < pointer_height; i++) |
978 | for (j = 0; j < pointer_width; j++) { |
953 | for (j = 0; j < pointer_width; j++) { |
979 | bytepos = i * ((pointer_width - 1) / 8 + 1) + j / 8; |
954 | bytepos = i * ((pointer_width - 1) / 8 + 1) + j / 8; |
980 | visibility = pointer_mask_bits[bytepos] & |
955 | visibility = pointer_mask_bits[bytepos] & |
Line 989... | Line 964... | ||
989 | } |
964 | } |
990 | } |
965 | } |
991 | pointer_shown = 1; |
966 | pointer_shown = 1; |
992 | } |
967 | } |
993 | 968 | ||
994 | static void |
969 | |
995 | mouse_hide(void) |
970 | static void mouse_hide(void) |
996 | { |
971 | { |
997 | /* Restore image under the cursor */ |
972 | /* Restore image under the cursor */ |
998 | if (pointer_shown) { |
973 | if (pointer_shown) { |
999 | draw_pixmap(pointer_vport, pointer_pixmap); |
974 | draw_pixmap(pointer_vport, pointer_pixmap); |
1000 | pointer_shown = 0; |
975 | pointer_shown = 0; |
1001 | } |
976 | } |
1002 | } |
977 | } |
1003 | 978 | ||
1004 | static void |
979 | |
1005 | mouse_move(unsigned int x, unsigned int y) |
980 | static void mouse_move(unsigned int x, unsigned int y) |
1006 | { |
981 | { |
1007 | mouse_hide(); |
982 | mouse_hide(); |
1008 | pointer_x = x; |
983 | pointer_x = x; |
1009 | pointer_y = y; |
984 | pointer_y = y; |
1010 | mouse_show(); |
985 | mouse_show(); |
1011 | } |
986 | } |
1012 | 987 | ||
1013 | static int |
988 | |
1014 | anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
989 | static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
1015 | { |
990 | { |
1016 | int handled = 1; |
991 | bool handled = true; |
1017 | int retval = 0; |
992 | int retval = EOK; |
1018 | int i,nvp; |
993 | int i, nvp; |
1019 | int newval; |
994 | int newval; |
1020 | 995 | ||
1021 | switch (IPC_GET_METHOD(*call)) { |
996 | switch (IPC_GET_METHOD(*call)) { |
1022 | case FB_ANIM_CREATE: |
997 | case FB_ANIM_CREATE: |
1023 | nvp = IPC_GET_ARG1(*call); |
998 | nvp = IPC_GET_ARG1(*call); |
1024 | if (nvp == -1) |
999 | if (nvp == -1) |
1025 | nvp = vp; |
1000 | nvp = vp; |
Line 1105... | Line 1080... | ||
1105 | if (handled) |
1080 | if (handled) |
1106 | ipc_answer_0(callid, retval); |
1081 | ipc_answer_0(callid, retval); |
1107 | return handled; |
1082 | return handled; |
1108 | } |
1083 | } |
1109 | 1084 | ||
1110 | /** Handler for messages concerning pixmap handling */ |
- | |
1111 | static int |
- | |
1112 | pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
- | |
1113 | { |
- | |
1114 | int handled = 1; |
- | |
1115 | int retval = 0; |
- | |
1116 | int i,nvp; |
- | |
1117 | 1085 | ||
- | 1086 | /** Handler for messages concerning pixmap handling |
|
- | 1087 | * |
|
- | 1088 | */ |
|
- | 1089 | static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
|
- | 1090 | { |
|
- | 1091 | bool handled = true; |
|
- | 1092 | int retval = EOK; |
|
- | 1093 | int i, nvp; |
|
- | 1094 | ||
1118 | switch (IPC_GET_METHOD(*call)) { |
1095 | switch (IPC_GET_METHOD(*call)) { |
1119 | case FB_VP_DRAW_PIXMAP: |
1096 | case FB_VP_DRAW_PIXMAP: |
1120 | nvp = IPC_GET_ARG1(*call); |
1097 | nvp = IPC_GET_ARG1(*call); |
1121 | if (nvp == -1) |
1098 | if (nvp == -1) |
1122 | nvp = vp; |
1099 | nvp = vp; |
Line 1150... | Line 1127... | ||
1150 | } |
1127 | } |
1151 | break; |
1128 | break; |
1152 | default: |
1129 | default: |
1153 | handled = 0; |
1130 | handled = 0; |
1154 | } |
1131 | } |
1155 | 1132 | ||
1156 | if (handled) |
1133 | if (handled) |
1157 | ipc_answer_0(callid, retval); |
1134 | ipc_answer_0(callid, retval); |
1158 | return handled; |
1135 | return handled; |
1159 | 1136 | ||
1160 | } |
1137 | } |
1161 | 1138 | ||
1162 | /** Function for handling connections to FB |
1139 | /** Function for handling connections to FB |
1163 | * |
1140 | * |
1164 | */ |
1141 | */ |
1165 | static void |
- | |
1166 | fb_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
1142 | static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
1167 | { |
1143 | { |
1168 | ipc_callid_t callid; |
- | |
1169 | ipc_call_t call; |
- | |
1170 | int retval; |
- | |
1171 | int i; |
- | |
1172 | unsigned int row,col; |
1144 | unsigned int vp = 0; |
1173 | char c; |
- | |
1174 | - | ||
1175 | int vp = 0; |
- | |
1176 | viewport_t *vport = &viewports[0]; |
1145 | viewport_t *vport = &viewports[vp]; |
1177 | 1146 | ||
1178 | if (client_connected) { |
1147 | if (client_connected) { |
1179 | ipc_answer_0(iid, ELIMIT); |
1148 | ipc_answer_0(iid, ELIMIT); |
1180 | return; |
1149 | return; |
1181 | } |
1150 | } |
- | 1151 | ||
- | 1152 | /* Accept connection */ |
|
1182 | client_connected = 1; |
1153 | client_connected = true; |
1183 | ipc_answer_0(iid, EOK); /* Accept connection */ |
1154 | ipc_answer_0(iid, EOK); |
1184 | 1155 | ||
1185 | while (1) { |
1156 | while (true) { |
- | 1157 | ipc_callid_t callid; |
|
- | 1158 | ipc_call_t call; |
|
- | 1159 | int retval; |
|
- | 1160 | unsigned int i; |
|
- | 1161 | int scroll; |
|
- | 1162 | uint8_t glyph; |
|
- | 1163 | unsigned int row, col; |
|
- | 1164 | ||
1186 | if (vport->cursor_active || anims_enabled) |
1165 | if ((vport->cursor_active) || (anims_enabled)) |
1187 | callid = async_get_call_timeout(&call, 250000); |
1166 | callid = async_get_call_timeout(&call, 250000); |
1188 | else |
1167 | else |
1189 | callid = async_get_call(&call); |
1168 | callid = async_get_call(&call); |
1190 | 1169 | ||
1191 | mouse_hide(); |
1170 | mouse_hide(); |
1192 | if (!callid) { |
1171 | if (!callid) { |
1193 | cursor_blink(vport); |
1172 | cursor_blink(vport); |
1194 | anims_tick(); |
1173 | anims_tick(); |
1195 | mouse_show(); |
1174 | mouse_show(); |
1196 | continue; |
1175 | continue; |
1197 | } |
1176 | } |
- | 1177 | ||
1198 | if (shm_handle(callid, &call, vp)) |
1178 | if (shm_handle(callid, &call, vp)) |
1199 | continue; |
1179 | continue; |
- | 1180 | ||
1200 | if (pixmap_handle(callid, &call, vp)) |
1181 | if (pixmap_handle(callid, &call, vp)) |
1201 | continue; |
1182 | continue; |
- | 1183 | ||
1202 | if (anim_handle(callid, &call, vp)) |
1184 | if (anim_handle(callid, &call, vp)) |
1203 | continue; |
1185 | continue; |
1204 | 1186 | ||
1205 | switch (IPC_GET_METHOD(call)) { |
1187 | switch (IPC_GET_METHOD(call)) { |
1206 | case IPC_M_PHONE_HUNGUP: |
1188 | case IPC_M_PHONE_HUNGUP: |
1207 | client_connected = 0; |
1189 | client_connected = false; |
- | 1190 | ||
1208 | /* cleanup other viewports */ |
1191 | /* Cleanup other viewports */ |
1209 | for (i = 1; i < MAX_VIEWPORTS; i++) |
1192 | for (i = 1; i < MAX_VIEWPORTS; i++) |
1210 | vport->initialized = 0; |
1193 | vport->initialized = false; |
- | 1194 | ||
1211 | return; /* Exit thread */ |
1195 | /* Exit thread */ |
- | 1196 | return; |
|
1212 | 1197 | ||
1213 | case FB_PUTCHAR: |
1198 | case FB_PUTCHAR: |
1214 | case FB_TRANS_PUTCHAR: |
- | |
1215 | c = IPC_GET_ARG1(call); |
1199 | glyph = IPC_GET_ARG1(call); |
1216 | row = IPC_GET_ARG2(call); |
1200 | row = IPC_GET_ARG2(call); |
1217 | col = IPC_GET_ARG3(call); |
1201 | col = IPC_GET_ARG3(call); |
- | 1202 | ||
1218 | if (row >= vport->rows || col >= vport->cols) { |
1203 | if ((col >= vport->cols) || (row >= vport->rows)) { |
1219 | retval = EINVAL; |
1204 | retval = EINVAL; |
1220 | break; |
1205 | break; |
1221 | } |
1206 | } |
1222 | ipc_answer_0(callid, EOK); |
1207 | ipc_answer_0(callid, EOK); |
1223 | 1208 | ||
1224 | draw_char(vport, c, row, col, vport->style, |
1209 | draw_char(vport, glyph, col, row); |
- | 1210 | ||
1225 | IPC_GET_METHOD(call) == FB_TRANS_PUTCHAR); |
1211 | /* Message already answered */ |
1226 | continue; /* msg already answered */ |
1212 | continue; |
1227 | case FB_CLEAR: |
1213 | case FB_CLEAR: |
1228 | clear_port(vport); |
1214 | vport_clear(vport); |
1229 | cursor_print(vport); |
1215 | cursor_show(vport); |
1230 | retval = 0; |
1216 | retval = EOK; |
1231 | break; |
1217 | break; |
1232 | case FB_CURSOR_GOTO: |
1218 | case FB_CURSOR_GOTO: |
1233 | row = IPC_GET_ARG1(call); |
1219 | row = IPC_GET_ARG1(call); |
1234 | col = IPC_GET_ARG2(call); |
1220 | col = IPC_GET_ARG2(call); |
- | 1221 | ||
1235 | if (row >= vport->rows || col >= vport->cols) { |
1222 | if ((col >= vport->cols) || (row >= vport->rows)) { |
1236 | retval = EINVAL; |
1223 | retval = EINVAL; |
1237 | break; |
1224 | break; |
1238 | } |
1225 | } |
1239 | retval = 0; |
1226 | retval = EOK; |
- | 1227 | ||
1240 | cursor_hide(vport); |
1228 | cursor_hide(vport); |
1241 | vport->cur_col = col; |
1229 | vport->cur_col = col; |
1242 | vport->cur_row = row; |
1230 | vport->cur_row = row; |
1243 | cursor_print(vport); |
1231 | cursor_show(vport); |
1244 | break; |
1232 | break; |
1245 | case FB_CURSOR_VISIBILITY: |
1233 | case FB_CURSOR_VISIBILITY: |
1246 | cursor_hide(vport); |
1234 | cursor_hide(vport); |
1247 | vport->cursor_active = IPC_GET_ARG1(call); |
1235 | vport->cursor_active = IPC_GET_ARG1(call); |
1248 | cursor_print(vport); |
1236 | cursor_show(vport); |
1249 | retval = 0; |
1237 | retval = EOK; |
1250 | break; |
1238 | break; |
1251 | case FB_GET_CSIZE: |
1239 | case FB_GET_CSIZE: |
1252 | ipc_answer_2(callid, EOK, vport->rows, vport->cols); |
1240 | ipc_answer_2(callid, EOK, vport->rows, vport->cols); |
1253 | continue; |
1241 | continue; |
1254 | case FB_SCROLL: |
1242 | case FB_SCROLL: |
1255 | i = IPC_GET_ARG1(call); |
1243 | scroll = IPC_GET_ARG1(call); |
1256 | if (i > vport->rows || i < (- (int)vport->rows)) { |
1244 | if ((scroll > (int) vport->rows) || (scroll < (-(int) vport->rows))) { |
1257 | retval = EINVAL; |
1245 | retval = EINVAL; |
1258 | break; |
1246 | break; |
1259 | } |
1247 | } |
1260 | cursor_hide(vport); |
1248 | cursor_hide(vport); |
1261 | scroll_port(vport, i*FONT_SCANLINES); |
1249 | vport_scroll(vport, scroll); |
1262 | cursor_print(vport); |
1250 | cursor_show(vport); |
1263 | retval = 0; |
- | |
1264 | break; |
- | |
1265 | case FB_VIEWPORT_DB: |
- | |
1266 | /* Enable double buffering */ |
- | |
1267 | i = IPC_GET_ARG1(call); |
- | |
1268 | if (i == -1) |
- | |
1269 | i = vp; |
- | |
1270 | if (i < 0 || i >= MAX_VIEWPORTS) { |
- | |
1271 | retval = EINVAL; |
- | |
1272 | break; |
- | |
1273 | } |
- | |
1274 | if (!viewports[i].initialized ) { |
- | |
1275 | retval = EADDRNOTAVAIL; |
- | |
1276 | break; |
- | |
1277 | } |
- | |
1278 | viewports[i].dboffset = 0; |
- | |
1279 | if (IPC_GET_ARG2(call) == 1 && !viewports[i].dbdata) |
- | |
1280 | viewports[i].dbdata = |
- | |
1281 | malloc(screen.pixelbytes * |
- | |
1282 | viewports[i].width * viewports[i].height); |
- | |
1283 | else if (IPC_GET_ARG2(call) == 0 && |
- | |
1284 | viewports[i].dbdata) { |
- | |
1285 | free(viewports[i].dbdata); |
- | |
1286 | viewports[i].dbdata = NULL; |
- | |
1287 | } |
- | |
1288 | retval = 0; |
1251 | retval = EOK; |
1289 | break; |
1252 | break; |
1290 | case FB_VIEWPORT_SWITCH: |
1253 | case FB_VIEWPORT_SWITCH: |
1291 | i = IPC_GET_ARG1(call); |
1254 | i = IPC_GET_ARG1(call); |
1292 | if (i < 0 || i >= MAX_VIEWPORTS) { |
1255 | if (i >= MAX_VIEWPORTS) { |
1293 | retval = EINVAL; |
1256 | retval = EINVAL; |
1294 | break; |
1257 | break; |
1295 | } |
1258 | } |
1296 | if (! viewports[i].initialized ) { |
1259 | if (!viewports[i].initialized) { |
1297 | retval = EADDRNOTAVAIL; |
1260 | retval = EADDRNOTAVAIL; |
1298 | break; |
1261 | break; |
1299 | } |
1262 | } |
1300 | cursor_hide(vport); |
1263 | cursor_hide(vport); |
1301 | vp = i; |
1264 | vp = i; |
1302 | vport = &viewports[vp]; |
1265 | vport = &viewports[vp]; |
1303 | cursor_print(vport); |
1266 | cursor_show(vport); |
1304 | retval = 0; |
1267 | retval = EOK; |
1305 | break; |
1268 | break; |
1306 | case FB_VIEWPORT_CREATE: |
1269 | case FB_VIEWPORT_CREATE: |
1307 | retval = viewport_create(IPC_GET_ARG1(call) >> 16, |
1270 | retval = vport_create(IPC_GET_ARG1(call) >> 16, |
1308 | IPC_GET_ARG1(call) & 0xffff, |
1271 | IPC_GET_ARG1(call) & 0xffff, |
1309 | IPC_GET_ARG2(call) >> 16, |
1272 | IPC_GET_ARG2(call) >> 16, |
1310 | IPC_GET_ARG2(call) & 0xffff); |
1273 | IPC_GET_ARG2(call) & 0xffff); |
1311 | break; |
1274 | break; |
1312 | case FB_VIEWPORT_DELETE: |
1275 | case FB_VIEWPORT_DELETE: |
1313 | i = IPC_GET_ARG1(call); |
1276 | i = IPC_GET_ARG1(call); |
1314 | if (i < 0 || i >= MAX_VIEWPORTS) { |
1277 | if (i >= MAX_VIEWPORTS) { |
1315 | retval = EINVAL; |
1278 | retval = EINVAL; |
1316 | break; |
1279 | break; |
1317 | } |
1280 | } |
1318 | if (! viewports[i].initialized ) { |
1281 | if (!viewports[i].initialized) { |
1319 | retval = EADDRNOTAVAIL; |
1282 | retval = EADDRNOTAVAIL; |
1320 | break; |
1283 | break; |
1321 | } |
1284 | } |
1322 | viewports[i].initialized = 0; |
1285 | viewports[i].initialized = false; |
1323 | if (viewports[i].dbdata) { |
1286 | if (viewports[i].glyphs) |
1324 | free(viewports[i].dbdata); |
1287 | free(viewports[i].glyphs); |
- | 1288 | if (viewports[i].bgpixel) |
|
1325 | viewports[i].dbdata = NULL; |
1289 | free(viewports[i].bgpixel); |
1326 | } |
1290 | if (viewports[i].backbuf) |
- | 1291 | free(viewports[i].backbuf); |
|
1327 | retval = 0; |
1292 | retval = EOK; |
1328 | break; |
1293 | break; |
1329 | case FB_SET_STYLE: |
1294 | case FB_SET_STYLE: |
1330 | vport->style.fg_color = IPC_GET_ARG1(call); |
1295 | vport->style.fg_color = IPC_GET_ARG1(call); |
1331 | vport->style.bg_color = IPC_GET_ARG2(call); |
1296 | vport->style.bg_color = IPC_GET_ARG2(call); |
- | 1297 | render_glyphs(vport); |
|
1332 | retval = 0; |
1298 | retval = EOK; |
1333 | break; |
1299 | break; |
1334 | case FB_GET_RESOLUTION: |
1300 | case FB_GET_RESOLUTION: |
1335 | ipc_answer_2(callid, EOK, screen.xres, screen.yres); |
1301 | ipc_answer_2(callid, EOK, screen.xres, screen.yres); |
1336 | continue; |
1302 | continue; |
1337 | case FB_POINTER_MOVE: |
1303 | case FB_POINTER_MOVE: |
1338 | pointer_enabled = 1; |
1304 | pointer_enabled = true; |
1339 | mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); |
1305 | mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); |
1340 | retval = 0; |
1306 | retval = EOK; |
1341 | break; |
1307 | break; |
1342 | default: |
1308 | default: |
1343 | retval = ENOENT; |
1309 | retval = ENOENT; |
1344 | } |
1310 | } |
1345 | ipc_answer_0(callid, retval); |
1311 | ipc_answer_0(callid, retval); |
1346 | } |
1312 | } |
1347 | } |
1313 | } |
1348 | 1314 | ||
1349 | /** Initialization of framebuffer */ |
1315 | /** Initialization of framebuffer |
- | 1316 | * |
|
1350 | int |
1317 | */ |
1351 | fb_init(void) |
1318 | int fb_init(void) |
1352 | { |
1319 | { |
1353 | void *fb_ph_addr; |
- | |
1354 | unsigned int fb_width; |
- | |
1355 | unsigned int fb_height; |
- | |
1356 | unsigned int fb_scanline; |
- | |
1357 | unsigned int fb_visual; |
- | |
1358 | unsigned int fb_offset; |
- | |
1359 | bool fb_invert_colors; |
- | |
1360 | void *fb_addr; |
- | |
1361 | size_t asz; |
- | |
1362 | - | ||
1363 | async_set_client_connection(fb_client_connection); |
1320 | async_set_client_connection(fb_client_connection); |
1364 | - | ||
1365 | fb_ph_addr = (void *) sysinfo_value("fb.address.physical"); |
- | |
1366 | fb_offset = sysinfo_value("fb.offset"); |
- | |
1367 | fb_width = sysinfo_value("fb.width"); |
- | |
1368 | fb_height = sysinfo_value("fb.height"); |
- | |
1369 | fb_scanline = sysinfo_value("fb.scanline"); |
- | |
1370 | fb_visual = sysinfo_value("fb.visual"); |
- | |
1371 | fb_invert_colors = sysinfo_value("fb.invert-colors"); |
- | |
1372 | - | ||
1373 | asz = fb_scanline * fb_height; |
- | |
1374 | fb_addr = as_get_mappable_page(asz); |
- | |
1375 | 1321 | ||
- | 1322 | void *fb_ph_addr = (void *) sysinfo_value("fb.address.physical"); |
|
- | 1323 | unsigned int fb_offset = sysinfo_value("fb.offset"); |
|
- | 1324 | unsigned int fb_width = sysinfo_value("fb.width"); |
|
- | 1325 | unsigned int fb_height = sysinfo_value("fb.height"); |
|
- | 1326 | unsigned int fb_scanline = sysinfo_value("fb.scanline"); |
|
- | 1327 | unsigned int fb_visual = sysinfo_value("fb.visual"); |
|
- | 1328 | ||
- | 1329 | unsigned int fbsize = fb_scanline * fb_height; |
|
- | 1330 | void *fb_addr = as_get_mappable_page(fbsize); |
|
- | 1331 | ||
1376 | physmem_map(fb_ph_addr + fb_offset, fb_addr, ALIGN_UP(asz, PAGE_SIZE) >> |
1332 | physmem_map(fb_ph_addr + fb_offset, fb_addr, |
1377 | PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE); |
1333 | ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE); |
1378 | 1334 | ||
1379 | if (screen_init(fb_addr, fb_offset, fb_width, fb_height, fb_scanline, fb_visual, |
1335 | if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual)) |
1380 | fb_invert_colors)) |
- | |
1381 | return 0; |
1336 | return 0; |
1382 | 1337 | ||
1383 | return -1; |
1338 | return -1; |
1384 | } |
1339 | } |
1385 | 1340 | ||
1386 | /** |
1341 | /** |
1387 | * @} |
1342 | * @} |
1388 | */ |
1343 | */ |