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