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