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