Rev 1485 | Rev 1489 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1485 | Rev 1486 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Jakub Vana |
2 | * Copyright (C) 2006 Jakub Vana |
3 | * Copyright (C) 2006 Ondrej Palkovsky |
3 | * Copyright (C) 2006 Ondrej Palkovsky |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
14 | * documentation and/or other materials provided with the distribution. |
15 | * - The name of the author may not be used to endorse or promote products |
15 | * - The name of the author may not be used to endorse or promote products |
16 | * derived from this software without specific prior written permission. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | #include <stdio.h> |
30 | #include <stdio.h> |
31 | #include <stdlib.h> |
31 | #include <stdlib.h> |
32 | #include <unistd.h> |
32 | #include <unistd.h> |
33 | #include <string.h> |
33 | #include <string.h> |
34 | #include <ddi.h> |
34 | #include <ddi.h> |
35 | #include <task.h> |
35 | #include <task.h> |
36 | #include <sysinfo.h> |
36 | #include <sysinfo.h> |
37 | #include <align.h> |
37 | #include <align.h> |
38 | #include <as.h> |
38 | #include <as.h> |
39 | #include <ipc/fb.h> |
39 | #include <ipc/fb.h> |
40 | #include <ipc/ipc.h> |
40 | #include <ipc/ipc.h> |
41 | #include <ipc/ns.h> |
41 | #include <ipc/ns.h> |
42 | #include <ipc/services.h> |
42 | #include <ipc/services.h> |
43 | #include <kernel/errno.h> |
43 | #include <kernel/errno.h> |
44 | #include <async.h> |
44 | #include <async.h> |
45 | #include "font-8x16.h" |
45 | #include "font-8x16.h" |
46 | #include "helenos.xbm" |
46 | #include "helenos.xbm" |
47 | #include "fb.h" |
47 | #include "fb.h" |
48 | 48 | ||
49 | #define DEFAULT_BGCOLOR 0x000080 |
49 | #define DEFAULT_BGCOLOR 0x000080 |
50 | #define DEFAULT_FGCOLOR 0xffff00 |
50 | #define DEFAULT_FGCOLOR 0xffff00 |
51 | 51 | ||
52 | /***************************************************************/ |
52 | /***************************************************************/ |
53 | /* Pixel specific fuctions */ |
53 | /* Pixel specific fuctions */ |
54 | 54 | ||
55 | typedef void (*putpixel_fn_t)(unsigned int x, unsigned int y, int color); |
55 | typedef void (*putpixel_fn_t)(unsigned int x, unsigned int y, int color); |
56 | typedef int (*getpixel_fn_t)(unsigned int x, unsigned int y); |
56 | typedef int (*getpixel_fn_t)(unsigned int x, unsigned int y); |
57 | 57 | ||
58 | struct { |
58 | struct { |
59 | __u8 *fbaddress ; |
59 | __u8 *fbaddress ; |
60 | 60 | ||
61 | unsigned int xres ; |
61 | unsigned int xres ; |
62 | unsigned int yres ; |
62 | unsigned int yres ; |
63 | unsigned int scanline ; |
63 | unsigned int scanline ; |
64 | unsigned int pixelbytes ; |
64 | unsigned int pixelbytes ; |
65 | 65 | ||
66 | putpixel_fn_t putpixel; |
66 | putpixel_fn_t putpixel; |
67 | getpixel_fn_t getpixel; |
67 | getpixel_fn_t getpixel; |
68 | } screen; |
68 | } screen; |
69 | 69 | ||
70 | typedef struct { |
70 | typedef struct { |
71 | int initialized; |
71 | int initialized; |
72 | unsigned int x, y; |
72 | unsigned int x, y; |
73 | unsigned int width, height; |
73 | unsigned int width, height; |
74 | 74 | ||
75 | /* Text support in window */ |
75 | /* Text support in window */ |
76 | unsigned int rows, cols; |
76 | unsigned int rows, cols; |
77 | /* Style for text printing */ |
77 | /* Style for text printing */ |
78 | int bgcolor, fgcolor; |
78 | int bgcolor, fgcolor; |
79 | /* Auto-cursor position */ |
79 | /* Auto-cursor position */ |
80 | int cursor_active, cur_x, cur_y; |
80 | int cursor_active, cur_col, cur_row; |
81 | } viewport_t; |
81 | } viewport_t; |
82 | 82 | ||
83 | #define MAX_VIEWPORTS 128 |
83 | #define MAX_VIEWPORTS 128 |
84 | static viewport_t viewports[128]; |
84 | static viewport_t viewports[128]; |
85 | 85 | ||
86 | /* Allow only 1 connection */ |
86 | /* Allow only 1 connection */ |
87 | static int client_connected = 0; |
87 | static int client_connected = 0; |
88 | 88 | ||
89 | #define RED(x, bits) ((x >> (16 + 8 - bits)) & ((1 << bits) - 1)) |
89 | #define RED(x, bits) ((x >> (16 + 8 - bits)) & ((1 << bits) - 1)) |
90 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
90 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
91 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
91 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
92 | 92 | ||
93 | #define COL_WIDTH 8 |
93 | #define COL_WIDTH 8 |
94 | #define ROW_BYTES (screen.scanline * FONT_SCANLINES) |
94 | #define ROW_BYTES (screen.scanline * FONT_SCANLINES) |
95 | 95 | ||
96 | #define POINTPOS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) |
96 | #define POINTPOS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) |
97 | 97 | ||
98 | /** Put pixel - 24-bit depth, 1 free byte */ |
98 | /** Put pixel - 24-bit depth, 1 free byte */ |
99 | static void putpixel_4byte(unsigned int x, unsigned int y, int color) |
99 | static void putpixel_4byte(unsigned int x, unsigned int y, int color) |
100 | { |
100 | { |
101 | *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) = color; |
101 | *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) = color; |
102 | } |
102 | } |
103 | 103 | ||
104 | /** Return pixel color - 24-bit depth, 1 free byte */ |
104 | /** Return pixel color - 24-bit depth, 1 free byte */ |
105 | static int getpixel_4byte(unsigned int x, unsigned int y) |
105 | static int getpixel_4byte(unsigned int x, unsigned int y) |
106 | { |
106 | { |
107 | return *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) & 0xffffff; |
107 | return *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) & 0xffffff; |
108 | } |
108 | } |
109 | 109 | ||
110 | /** Put pixel - 24-bit depth */ |
110 | /** Put pixel - 24-bit depth */ |
111 | static void putpixel_3byte(unsigned int x, unsigned int y, int color) |
111 | static void putpixel_3byte(unsigned int x, unsigned int y, int color) |
112 | { |
112 | { |
113 | unsigned int startbyte = POINTPOS(x, y); |
113 | unsigned int startbyte = POINTPOS(x, y); |
114 | 114 | ||
115 | #if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN)) |
115 | #if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN)) |
116 | screen.fbaddress[startbyte] = RED(color, 8); |
116 | screen.fbaddress[startbyte] = RED(color, 8); |
117 | screen.fbaddress[startbyte + 1] = GREEN(color, 8); |
117 | screen.fbaddress[startbyte + 1] = GREEN(color, 8); |
118 | screen.fbaddress[startbyte + 2] = BLUE(color, 8); |
118 | screen.fbaddress[startbyte + 2] = BLUE(color, 8); |
119 | #else |
119 | #else |
120 | screen.fbaddress[startbyte + 2] = RED(color, 8); |
120 | screen.fbaddress[startbyte + 2] = RED(color, 8); |
121 | screen.fbaddress[startbyte + 1] = GREEN(color, 8); |
121 | screen.fbaddress[startbyte + 1] = GREEN(color, 8); |
122 | screen.fbaddress[startbyte + 0] = BLUE(color, 8); |
122 | screen.fbaddress[startbyte + 0] = BLUE(color, 8); |
123 | #endif |
123 | #endif |
124 | 124 | ||
125 | } |
125 | } |
126 | 126 | ||
127 | /** Return pixel color - 24-bit depth */ |
127 | /** Return pixel color - 24-bit depth */ |
128 | static int getpixel_3byte(unsigned int x, unsigned int y) |
128 | static int getpixel_3byte(unsigned int x, unsigned int y) |
129 | { |
129 | { |
130 | unsigned int startbyte = POINTPOS(x, y); |
130 | unsigned int startbyte = POINTPOS(x, y); |
131 | 131 | ||
132 | 132 | ||
133 | 133 | ||
134 | #if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN)) |
134 | #if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN)) |
135 | return screen.fbaddress[startbyte] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 2]; |
135 | return screen.fbaddress[startbyte] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 2]; |
136 | #else |
136 | #else |
137 | return screen.fbaddress[startbyte + 2] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 0]; |
137 | return screen.fbaddress[startbyte + 2] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 0]; |
138 | #endif |
138 | #endif |
139 | 139 | ||
140 | 140 | ||
141 | } |
141 | } |
142 | 142 | ||
143 | /** Put pixel - 16-bit depth (5:6:5) */ |
143 | /** Put pixel - 16-bit depth (5:6:5) */ |
144 | static void putpixel_2byte(unsigned int x, unsigned int y, int color) |
144 | static void putpixel_2byte(unsigned int x, unsigned int y, int color) |
145 | { |
145 | { |
146 | /* 5-bit, 6-bits, 5-bits */ |
146 | /* 5-bit, 6-bits, 5-bits */ |
147 | *((__u16 *)(screen.fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5); |
147 | *((__u16 *)(screen.fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5); |
148 | } |
148 | } |
149 | 149 | ||
150 | /** Return pixel color - 16-bit depth (5:6:5) */ |
150 | /** Return pixel color - 16-bit depth (5:6:5) */ |
151 | static int getpixel_2byte(unsigned int x, unsigned int y) |
151 | static int getpixel_2byte(unsigned int x, unsigned int y) |
152 | { |
152 | { |
153 | int color = *((__u16 *)(screen.fbaddress + POINTPOS(x, y))); |
153 | int color = *((__u16 *)(screen.fbaddress + POINTPOS(x, y))); |
154 | return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); |
154 | return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); |
155 | } |
155 | } |
156 | 156 | ||
157 | /** Put pixel - 8-bit depth (3:2:3) */ |
157 | /** Put pixel - 8-bit depth (3:2:3) */ |
158 | static void putpixel_1byte(unsigned int x, unsigned int y, int color) |
158 | static void putpixel_1byte(unsigned int x, unsigned int y, int color) |
159 | { |
159 | { |
160 | screen.fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3); |
160 | screen.fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3); |
161 | } |
161 | } |
162 | 162 | ||
163 | /** Return pixel color - 8-bit depth (3:2:3) */ |
163 | /** Return pixel color - 8-bit depth (3:2:3) */ |
164 | static int getpixel_1byte(unsigned int x, unsigned int y) |
164 | static int getpixel_1byte(unsigned int x, unsigned int y) |
165 | { |
165 | { |
166 | int color = screen.fbaddress[POINTPOS(x, y)]; |
166 | int color = screen.fbaddress[POINTPOS(x, y)]; |
167 | return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
167 | return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
168 | } |
168 | } |
169 | 169 | ||
170 | static void putpixel(int vp, unsigned int x, unsigned int y, int color) |
170 | static void putpixel(int vp, unsigned int x, unsigned int y, int color) |
171 | { |
171 | { |
172 | screen.putpixel(viewports[vp].x + x, viewports[vp].y + y, color); |
172 | screen.putpixel(viewports[vp].x + x, viewports[vp].y + y, color); |
173 | } |
173 | } |
174 | static int getpixel(int vp, unsigned int x, unsigned int y) |
174 | static int getpixel(int vp, unsigned int x, unsigned int y) |
175 | { |
175 | { |
176 | return screen.getpixel(viewports[vp].x + x, viewports[vp].y + y); |
176 | return screen.getpixel(viewports[vp].x + x, viewports[vp].y + y); |
177 | } |
177 | } |
178 | 178 | ||
179 | /** Fill line with color BGCOLOR */ |
179 | /** Fill line with color BGCOLOR */ |
180 | static void clear_line(int vp, unsigned int y) |
180 | static void clear_line(int vp, unsigned int y) |
181 | { |
181 | { |
182 | unsigned int x; |
182 | unsigned int x; |
183 | for (x = 0; x < viewports[vp].width; x++) |
183 | for (x = 0; x < viewports[vp].width; x++) |
184 | putpixel(vp, x, y, viewports[vp].bgcolor); |
184 | putpixel(vp, x, y, viewports[vp].bgcolor); |
185 | } |
185 | } |
186 | 186 | ||
187 | /** Fill viewport with background color */ |
187 | /** Fill viewport with background color */ |
188 | static void clear_port(int vp) |
188 | static void clear_port(int vp) |
189 | { |
189 | { |
190 | unsigned int y; |
190 | unsigned int y; |
191 | 191 | ||
192 | clear_line(vp, 0); |
192 | clear_line(vp, 0); |
193 | for (y = viewports[vp].y+1; y < viewports[vp].y+viewports[vp].height; y++) { |
193 | for (y = viewports[vp].y+1; y < viewports[vp].y+viewports[vp].height; y++) { |
194 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
194 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
195 | &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)], |
195 | &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)], |
196 | screen.pixelbytes * viewports[vp].width); |
196 | screen.pixelbytes * viewports[vp].width); |
197 | } |
197 | } |
198 | } |
198 | } |
199 | 199 | ||
200 | /** Optimized scroll for windows that cover whole lines */ |
- | |
201 | //static void scroll_optim(int vp, int rows) |
- | |
202 | //{ |
- | |
203 | /* TODO */ |
- | |
204 | //} |
- | |
205 | - | ||
206 | /** Scroll port up/down |
200 | /** Scroll port up/down |
207 | * |
201 | * |
208 | * @param vp Viewport to scroll |
202 | * @param vp Viewport to scroll |
209 | * @param rows Positive number - scroll up, negative - scroll down |
203 | * @param rows Positive number - scroll up, negative - scroll down |
210 | */ |
204 | */ |
211 | static void scroll_port(int vp, int rows) |
205 | static void scroll_port(int vp, int rows) |
212 | { |
206 | { |
213 | int y; |
207 | int y; |
214 | int startline; |
208 | int startline; |
215 | int endline; |
209 | int endline; |
216 | 210 | ||
217 | if (rows > 0) { |
211 | if (rows > 0) { |
218 | for (y=viewports[vp].y; y < viewports[vp].y+viewports[vp].height - rows*FONT_SCANLINES; y++) |
212 | for (y=viewports[vp].y; y < viewports[vp].y+viewports[vp].height - rows*FONT_SCANLINES; y++) |
219 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
213 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
220 | &screen.fbaddress[POINTPOS(viewports[vp].x,y + rows*FONT_SCANLINES)], |
214 | &screen.fbaddress[POINTPOS(viewports[vp].x,y + rows*FONT_SCANLINES)], |
221 | screen.pixelbytes * viewports[vp].width); |
215 | screen.pixelbytes * viewports[vp].width); |
222 | /* Clear last row */ |
216 | /* Clear last row */ |
223 | startline = viewports[vp].y+FONT_SCANLINES*(viewports[vp].rows-1); |
217 | startline = viewports[vp].y+FONT_SCANLINES*(viewports[vp].rows-1); |
224 | endline = viewports[vp].y + viewports[vp].height; |
218 | endline = viewports[vp].y + viewports[vp].height; |
225 | clear_line(vp, startline); |
219 | clear_line(vp, startline); |
226 | for (y=startline+1;y < endline; y++) |
220 | for (y=startline+1;y < endline; y++) |
227 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
221 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
228 | &screen.fbaddress[POINTPOS(viewports[vp].x,startline)], |
222 | &screen.fbaddress[POINTPOS(viewports[vp].x,startline)], |
229 | screen.pixelbytes * viewports[vp].width); |
223 | screen.pixelbytes * viewports[vp].width); |
230 | 224 | ||
231 | } else if (rows < 0) { |
225 | } else if (rows < 0) { |
232 | rows = -rows; |
226 | rows = -rows; |
233 | for (y=viewports[vp].y + viewports[vp].height-1; y >= viewports[vp].y + rows*FONT_SCANLINES; y--) |
227 | for (y=viewports[vp].y + viewports[vp].height-1; y >= viewports[vp].y + rows*FONT_SCANLINES; y--) |
234 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
228 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
235 | &screen.fbaddress[POINTPOS(viewports[vp].x,y - rows*FONT_SCANLINES)], |
229 | &screen.fbaddress[POINTPOS(viewports[vp].x,y - rows*FONT_SCANLINES)], |
236 | screen.pixelbytes * viewports[vp].width); |
230 | screen.pixelbytes * viewports[vp].width); |
237 | /* Clear first row */ |
231 | /* Clear first row */ |
238 | clear_line(0, viewports[vp].bgcolor); |
232 | clear_line(0, viewports[vp].bgcolor); |
239 | for (y=1;y < rows*FONT_SCANLINES; y++) |
233 | for (y=1;y < rows*FONT_SCANLINES; y++) |
240 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y+y)], |
234 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y+y)], |
241 | &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)], |
235 | &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)], |
242 | screen.pixelbytes * viewports[vp].width); |
236 | screen.pixelbytes * viewports[vp].width); |
243 | } |
237 | } |
244 | } |
238 | } |
245 | 239 | ||
246 | static void invert_pixel(int vp,unsigned int x, unsigned int y) |
240 | static void invert_pixel(int vp,unsigned int x, unsigned int y) |
247 | { |
241 | { |
248 | putpixel(vp, x, y, ~getpixel(vp, x, y)); |
242 | putpixel(vp, x, y, ~getpixel(vp, x, y)); |
249 | } |
243 | } |
250 | 244 | ||
251 | 245 | ||
252 | /** Draw one line of glyph at a given position */ |
246 | /** Draw one line of glyph at a given position */ |
253 | static void draw_glyph_line(int vp,unsigned int glline, unsigned int x, unsigned int y) |
247 | static void draw_glyph_line(int vp,unsigned int glline, unsigned int x, unsigned int y) |
254 | { |
248 | { |
255 | unsigned int i; |
249 | unsigned int i; |
256 | 250 | ||
257 | for (i = 0; i < 8; i++) |
251 | for (i = 0; i < 8; i++) |
258 | if (glline & (1 << (7 - i))) { |
252 | if (glline & (1 << (7 - i))) { |
259 | putpixel(vp, x + i, y, viewports[vp].fgcolor); |
253 | putpixel(vp, x + i, y, viewports[vp].fgcolor); |
260 | } else |
254 | } else |
261 | putpixel(vp, x + i, y, viewports[vp].bgcolor); |
255 | putpixel(vp, x + i, y, viewports[vp].bgcolor); |
262 | } |
256 | } |
263 | 257 | ||
264 | /***************************************************************/ |
258 | /***************************************************************/ |
265 | /* Character-console functions */ |
259 | /* Character-console functions */ |
266 | 260 | ||
267 | /** Draw character at given position */ |
261 | /** Draw character at given position */ |
268 | static void draw_glyph(int vp,__u8 glyph, unsigned int row, unsigned int col) |
262 | static void draw_glyph(int vp,__u8 glyph, unsigned int row, unsigned int col) |
269 | { |
263 | { |
270 | unsigned int y; |
264 | unsigned int y; |
271 | 265 | ||
272 | for (y = 0; y < FONT_SCANLINES; y++) |
266 | for (y = 0; y < FONT_SCANLINES; y++) |
273 | draw_glyph_line(vp ,fb_font[glyph * FONT_SCANLINES + y], col * COL_WIDTH, row * FONT_SCANLINES + y); |
267 | draw_glyph_line(vp ,fb_font[glyph * FONT_SCANLINES + y], col * COL_WIDTH, row * FONT_SCANLINES + y); |
274 | } |
268 | } |
275 | 269 | ||
276 | /** Invert character at given position */ |
270 | /** Invert character at given position */ |
277 | static void invert_char(int vp,unsigned int col, unsigned int row) |
271 | static void invert_char(int vp,unsigned int col, unsigned int row) |
278 | { |
272 | { |
279 | unsigned int x; |
273 | unsigned int x; |
280 | unsigned int y; |
274 | unsigned int y; |
281 | 275 | ||
282 | for (x = 0; x < COL_WIDTH; x++) |
276 | for (x = 0; x < COL_WIDTH; x++) |
283 | for (y = 0; y < FONT_SCANLINES; y++) |
277 | for (y = 0; y < FONT_SCANLINES; y++) |
284 | invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y); |
278 | invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y); |
285 | } |
279 | } |
286 | 280 | ||
287 | static void draw_logo(int vp,unsigned int startx, unsigned int starty) |
281 | static void draw_logo(int vp,unsigned int startx, unsigned int starty) |
288 | { |
282 | { |
289 | unsigned int x; |
283 | unsigned int x; |
290 | unsigned int y; |
284 | unsigned int y; |
291 | unsigned int byte; |
285 | unsigned int byte; |
292 | unsigned int rowbytes; |
286 | unsigned int rowbytes; |
293 | 287 | ||
294 | rowbytes = (helenos_width - 1) / 8 + 1; |
288 | rowbytes = (helenos_width - 1) / 8 + 1; |
295 | 289 | ||
296 | for (y = 0; y < helenos_height; y++) |
290 | for (y = 0; y < helenos_height; y++) |
297 | for (x = 0; x < helenos_width; x++) { |
291 | for (x = 0; x < helenos_width; x++) { |
298 | byte = helenos_bits[rowbytes * y + x / 8]; |
292 | byte = helenos_bits[rowbytes * y + x / 8]; |
299 | byte >>= x % 8; |
293 | byte >>= x % 8; |
300 | if (byte & 1) |
294 | if (byte & 1) |
301 | putpixel(vp ,startx + x, starty + y, viewports[vp].fgcolor); |
295 | putpixel(vp ,startx + x, starty + y, viewports[vp].fgcolor); |
302 | } |
296 | } |
303 | } |
297 | } |
304 | 298 | ||
305 | /***************************************************************/ |
299 | /***************************************************************/ |
306 | /* Stdout specific functions */ |
300 | /* Stdout specific functions */ |
307 | 301 | ||
308 | 302 | ||
309 | /** Create new viewport |
303 | /** Create new viewport |
310 | * |
304 | * |
311 | * @return New viewport number |
305 | * @return New viewport number |
312 | */ |
306 | */ |
313 | static int viewport_create(unsigned int x, unsigned int y,unsigned int width, |
307 | static int viewport_create(unsigned int x, unsigned int y,unsigned int width, |
314 | unsigned int height) |
308 | unsigned int height) |
315 | { |
309 | { |
316 | int i; |
310 | int i; |
317 | 311 | ||
318 | for (i=0; i < MAX_VIEWPORTS; i++) { |
312 | for (i=0; i < MAX_VIEWPORTS; i++) { |
319 | if (!viewports[i].initialized) |
313 | if (!viewports[i].initialized) |
320 | break; |
314 | break; |
321 | } |
315 | } |
322 | if (i == MAX_VIEWPORTS) |
316 | if (i == MAX_VIEWPORTS) |
323 | return ELIMIT; |
317 | return ELIMIT; |
324 | 318 | ||
325 | viewports[i].initialized = 1; |
319 | if (width ==0 || height == 0 || |
- | 320 | x+width > screen.xres || y+height > screen.yres) |
|
- | 321 | return EINVAL; |
|
- | 322 | if (width < FONT_SCANLINES || height < COL_WIDTH) |
|
- | 323 | return EINVAL; |
|
- | 324 | ||
326 | viewports[i].x = x; |
325 | viewports[i].x = x; |
327 | viewports[i].y = y; |
326 | viewports[i].y = y; |
328 | viewports[i].width = width; |
327 | viewports[i].width = width; |
329 | viewports[i].height = height; |
328 | viewports[i].height = height; |
330 | 329 | ||
331 | viewports[i].rows = height / FONT_SCANLINES; |
330 | viewports[i].rows = height / FONT_SCANLINES; |
332 | viewports[i].cols = width / COL_WIDTH; |
331 | viewports[i].cols = width / COL_WIDTH; |
333 | 332 | ||
334 | viewports[i].bgcolor = DEFAULT_BGCOLOR; |
333 | viewports[i].bgcolor = DEFAULT_BGCOLOR; |
335 | viewports[i].fgcolor = DEFAULT_FGCOLOR; |
334 | viewports[i].fgcolor = DEFAULT_FGCOLOR; |
336 | 335 | ||
- | 336 | viewports[i].initialized = 1; |
|
- | 337 | ||
337 | return i; |
338 | return i; |
338 | } |
339 | } |
339 | 340 | ||
340 | 341 | ||
341 | /** Initialize framebuffer as a chardev output device |
342 | /** Initialize framebuffer as a chardev output device |
342 | * |
343 | * |
343 | * @param addr Address of theframebuffer |
344 | * @param addr Address of theframebuffer |
344 | * @param x Screen width in pixels |
345 | * @param x Screen width in pixels |
345 | * @param y Screen height in pixels |
346 | * @param y Screen height in pixels |
346 | * @param bpp Bits per pixel (8, 16, 24, 32) |
347 | * @param bpp Bits per pixel (8, 16, 24, 32) |
347 | * @param scan Bytes per one scanline |
348 | * @param scan Bytes per one scanline |
348 | * |
349 | * |
349 | */ |
350 | */ |
350 | static void screen_init(__address addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan) |
351 | static void screen_init(__address addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan) |
351 | { |
352 | { |
352 | switch (bpp) { |
353 | switch (bpp) { |
353 | case 8: |
354 | case 8: |
354 | screen.putpixel = putpixel_1byte; |
355 | screen.putpixel = putpixel_1byte; |
355 | screen.getpixel = getpixel_1byte; |
356 | screen.getpixel = getpixel_1byte; |
356 | screen.pixelbytes = 1; |
357 | screen.pixelbytes = 1; |
357 | break; |
358 | break; |
358 | case 16: |
359 | case 16: |
359 | screen.putpixel = putpixel_2byte; |
360 | screen.putpixel = putpixel_2byte; |
360 | screen.getpixel = getpixel_2byte; |
361 | screen.getpixel = getpixel_2byte; |
361 | screen.pixelbytes = 2; |
362 | screen.pixelbytes = 2; |
362 | break; |
363 | break; |
363 | case 24: |
364 | case 24: |
364 | screen.putpixel = putpixel_3byte; |
365 | screen.putpixel = putpixel_3byte; |
365 | screen.getpixel = getpixel_3byte; |
366 | screen.getpixel = getpixel_3byte; |
366 | screen.pixelbytes = 3; |
367 | screen.pixelbytes = 3; |
367 | break; |
368 | break; |
368 | case 32: |
369 | case 32: |
369 | screen.putpixel = putpixel_4byte; |
370 | screen.putpixel = putpixel_4byte; |
370 | screen.getpixel = getpixel_4byte; |
371 | screen.getpixel = getpixel_4byte; |
371 | screen.pixelbytes = 4; |
372 | screen.pixelbytes = 4; |
372 | break; |
373 | break; |
373 | } |
374 | } |
374 | 375 | ||
375 | 376 | ||
376 | screen.fbaddress = (unsigned char *) addr; |
377 | screen.fbaddress = (unsigned char *) addr; |
377 | screen.xres = xres; |
378 | screen.xres = xres; |
378 | screen.yres = yres; |
379 | screen.yres = yres; |
379 | screen.scanline = scan; |
380 | screen.scanline = scan; |
380 | 381 | ||
381 | /* Create first viewport */ |
382 | /* Create first viewport */ |
382 | viewport_create(0,0,xres,yres); |
383 | viewport_create(0,0,xres,yres); |
383 | 384 | ||
384 | clear_port(0); |
385 | clear_port(0); |
385 | } |
386 | } |
386 | 387 | ||
387 | static int init_fb(void) |
388 | static int init_fb(void) |
388 | { |
389 | { |
389 | __address fb_ph_addr; |
390 | __address fb_ph_addr; |
390 | unsigned int fb_width; |
391 | unsigned int fb_width; |
391 | unsigned int fb_height; |
392 | unsigned int fb_height; |
392 | unsigned int fb_bpp; |
393 | unsigned int fb_bpp; |
393 | unsigned int fb_scanline; |
394 | unsigned int fb_scanline; |
394 | __address fb_addr; |
395 | __address fb_addr; |
395 | int a=0; |
396 | int a=0; |
396 | int i,j,k; |
397 | int i,j,k; |
397 | int w; |
398 | int w; |
398 | char text[]="HelenOS Framebuffer driver\non Virtual Framebuffer\nVFB "; |
399 | char text[]="HelenOS Framebuffer driver\non Virtual Framebuffer\nVFB "; |
399 | 400 | ||
400 | fb_ph_addr=sysinfo_value("fb.address.physical"); |
401 | fb_ph_addr=sysinfo_value("fb.address.physical"); |
401 | fb_width=sysinfo_value("fb.width"); |
402 | fb_width=sysinfo_value("fb.width"); |
402 | fb_height=sysinfo_value("fb.height"); |
403 | fb_height=sysinfo_value("fb.height"); |
403 | fb_bpp=sysinfo_value("fb.bpp"); |
404 | fb_bpp=sysinfo_value("fb.bpp"); |
404 | fb_scanline=sysinfo_value("fb.scanline"); |
405 | fb_scanline=sysinfo_value("fb.scanline"); |
405 | 406 | ||
406 | fb_addr=ALIGN_UP(((__address)set_maxheapsize(USER_ADDRESS_SPACE_SIZE_ARCH>>1)),PAGE_SIZE); |
407 | fb_addr=ALIGN_UP(((__address)set_maxheapsize(USER_ADDRESS_SPACE_SIZE_ARCH>>1)),PAGE_SIZE); |
407 | 408 | ||
408 | map_physmem(task_get_id(),(void *)((__address)fb_ph_addr),(void *)fb_addr, |
409 | map_physmem(task_get_id(),(void *)((__address)fb_ph_addr),(void *)fb_addr, |
409 | (fb_scanline*fb_height+PAGE_SIZE-1)>>PAGE_WIDTH, |
410 | (fb_scanline*fb_height+PAGE_SIZE-1)>>PAGE_WIDTH, |
410 | AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE); |
411 | AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE); |
411 | 412 | ||
412 | screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline); |
413 | screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline); |
413 | 414 | ||
414 | return 0; |
415 | return 0; |
415 | } |
416 | } |
416 | 417 | ||
- | 418 | static void draw_char(int vp, char c, unsigned int col, unsigned int row) |
|
- | 419 | { |
|
- | 420 | viewport_t *vport = &viewports[vp]; |
|
- | 421 | ||
- | 422 | if (vport->cursor_active && (vport->cur_col != col || vport->cur_row != row)) |
|
- | 423 | invert_char(vp, vport->cur_col,vport->cur_row); |
|
- | 424 | ||
- | 425 | draw_glyph(vp, c, col, row); |
|
- | 426 | ||
- | 427 | if (vport->cursor_active) { |
|
- | 428 | vport->cur_col++; |
|
- | 429 | if (vport->cur_col>= vport->cols) { |
|
- | 430 | vport->cur_col = 0; |
|
- | 431 | vport->cur_row++; |
|
- | 432 | if (vport->cur_row >= vport->rows) |
|
- | 433 | vport->cur_row--; |
|
- | 434 | } |
|
- | 435 | invert_char(vp, vport->cur_col,vport->cur_row); |
|
- | 436 | } |
|
- | 437 | } |
|
- | 438 | ||
417 | void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
439 | void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
418 | { |
440 | { |
419 | ipc_callid_t callid; |
441 | ipc_callid_t callid; |
420 | ipc_call_t call; |
442 | ipc_call_t call; |
421 | int retval; |
443 | int retval; |
422 | int i; |
444 | int i; |
423 | unsigned int row,col; |
445 | unsigned int row,col; |
424 | char c; |
446 | char c; |
- | 447 | ||
425 | int vp = 0; |
448 | int vp = 0; |
- | 449 | viewport_t *vport = &viewports[0]; |
|
426 | 450 | ||
427 | if (client_connected) { |
451 | if (client_connected) { |
428 | ipc_answer_fast(iid, ELIMIT, 0,0); |
452 | ipc_answer_fast(iid, ELIMIT, 0,0); |
429 | return; |
453 | return; |
430 | } |
454 | } |
- | 455 | client_connected = 1; |
|
431 | ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */ |
456 | ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */ |
432 | 457 | ||
433 | while (1) { |
458 | while (1) { |
434 | callid = async_get_call(&call); |
459 | callid = async_get_call(&call); |
435 | switch (IPC_GET_METHOD(call)) { |
460 | switch (IPC_GET_METHOD(call)) { |
436 | case IPC_M_PHONE_HUNGUP: |
461 | case IPC_M_PHONE_HUNGUP: |
437 | client_connected = 0; |
462 | client_connected = 0; |
438 | /* cleanup other viewports */ |
463 | /* cleanup other viewports */ |
439 | for (i=1; i < MAX_VIEWPORTS; i++) |
464 | for (i=1; i < MAX_VIEWPORTS; i++) |
440 | viewports[i].initialized = 0; |
465 | vport->initialized = 0; |
441 | ipc_answer_fast(callid,0,0,0); |
466 | ipc_answer_fast(callid,0,0,0); |
442 | return; /* Exit thread */ |
467 | return; /* Exit thread */ |
443 | case FB_PUTCHAR: |
468 | case FB_PUTCHAR: |
444 | c = IPC_GET_ARG1(call); |
469 | c = IPC_GET_ARG1(call); |
445 | row = IPC_GET_ARG2(call); |
470 | row = IPC_GET_ARG2(call); |
446 | col = IPC_GET_ARG3(call); |
471 | col = IPC_GET_ARG3(call); |
447 | if (row >= viewports[vp].rows || col >= viewports[vp].cols) { |
472 | if (row >= vport->rows || col >= vport->cols) { |
448 | retval = EINVAL; |
473 | retval = EINVAL; |
449 | break; |
474 | break; |
450 | } |
475 | } |
451 | ipc_answer_fast(callid,0,0,0); |
476 | ipc_answer_fast(callid,0,0,0); |
- | 477 | ||
452 | draw_glyph(vp,c, row, col); |
478 | draw_char(vp, c, row, col); |
453 | continue; /* msg already answered */ |
479 | continue; /* msg already answered */ |
454 | case FB_CLEAR: |
480 | case FB_CLEAR: |
455 | clear_port(vp); |
481 | clear_port(vp); |
- | 482 | if (vport->cursor_active) |
|
- | 483 | invert_char(vp, vport->cur_col,vport->cur_row); |
|
456 | retval = 0; |
484 | retval = 0; |
457 | break; |
485 | break; |
458 | /* case FB_CURSOR_GOTO: */ |
486 | case FB_CURSOR_GOTO: |
- | 487 | row = IPC_GET_ARG1(call); |
|
- | 488 | col = IPC_GET_ARG2(call); |
|
- | 489 | if (row >= vport->rows || col >= vport->cols) { |
|
- | 490 | retval = EINVAL; |
|
- | 491 | break; |
|
- | 492 | } |
|
459 | /* retval = 0; */ |
493 | retval = 0; |
- | 494 | if (viewports[vp].cursor_active) { |
|
- | 495 | invert_char(vp, vport->cur_col,vport->cur_row); |
|
- | 496 | invert_char(vp, col, row); |
|
- | 497 | } |
|
- | 498 | vport->cur_col = col; |
|
- | 499 | vport->cur_row = row; |
|
460 | /* break; */ |
500 | break; |
461 | /* case FB_CURSOR_VISIBILITY: */ |
501 | case FB_CURSOR_VISIBILITY: |
- | 502 | i = IPC_GET_ARG1(call); |
|
462 | /* retval = 0; */ |
503 | retval = 0; |
- | 504 | if ((i && vport->cursor_active) || (!i && !vport->cursor_active)) |
|
463 | /* break; */ |
505 | break; |
- | 506 | ||
- | 507 | vport->cursor_active = i; |
|
- | 508 | invert_char(vp, vport->cur_col,vport->cur_row); |
|
- | 509 | break; |
|
464 | case FB_GET_CSIZE: |
510 | case FB_GET_CSIZE: |
465 | ipc_answer_fast(callid, 0, viewports[vp].rows, viewports[vp].cols); |
511 | ipc_answer_fast(callid, 0, vport->rows, vport->cols); |
- | 512 | continue; |
|
- | 513 | case FB_SCROLL: |
|
- | 514 | i = IPC_GET_ARG1(call); |
|
- | 515 | if (i > vport->rows || i < (- (int)vport->rows)) { |
|
- | 516 | retval = EINVAL; |
|
- | 517 | break; |
|
- | 518 | } |
|
- | 519 | if (vport->cursor_active) |
|
- | 520 | invert_char(vp, vport->cur_col,vport->cur_row); |
|
- | 521 | scroll_port(vp, i); |
|
- | 522 | if (vport->cursor_active) |
|
- | 523 | invert_char(vp, vport->cur_col,vport->cur_row); |
|
- | 524 | retval = 0; |
|
- | 525 | break; |
|
- | 526 | case FB_VIEWPORT_SWITCH: |
|
- | 527 | i = IPC_GET_ARG1(call); |
|
- | 528 | if (i < 0 || i >= MAX_VIEWPORTS) { |
|
- | 529 | retval = EINVAL; |
|
- | 530 | break; |
|
- | 531 | } |
|
- | 532 | if (! viewports[i].initialized ) { |
|
- | 533 | retval = EADDRNOTAVAIL; |
|
- | 534 | break; |
|
- | 535 | } |
|
- | 536 | vp = i; |
|
- | 537 | vport = &viewports[vp]; |
|
- | 538 | retval = 0; |
|
- | 539 | break; |
|
- | 540 | case FB_VIEWPORT_CREATE: |
|
- | 541 | retval = viewport_create(IPC_GET_ARG1(call) >> 16, |
|
- | 542 | IPC_GET_ARG1(call) & 0xffff, |
|
- | 543 | IPC_GET_ARG2(call) >> 16, |
|
- | 544 | IPC_GET_ARG2(call) & 0xffff); |
|
- | 545 | break; |
|
- | 546 | case FB_VIEWPORT_DELETE: |
|
- | 547 | i = IPC_GET_ARG1(call); |
|
- | 548 | if (i < 0 || i >= MAX_VIEWPORTS) { |
|
- | 549 | retval = EINVAL; |
|
- | 550 | break; |
|
- | 551 | } |
|
- | 552 | if (! viewports[i].initialized ) { |
|
- | 553 | retval = EADDRNOTAVAIL; |
|
- | 554 | break; |
|
- | 555 | } |
|
- | 556 | viewports[i].initialized = 0; |
|
- | 557 | retval = 0; |
|
- | 558 | break; |
|
- | 559 | case FB_SET_STYLE: |
|
- | 560 | vport->fgcolor = IPC_GET_ARG1(call); |
|
- | 561 | vport->bgcolor = IPC_GET_ARG2(call); |
|
- | 562 | retval = 0; |
|
- | 563 | break; |
|
- | 564 | case FB_GET_RESOLUTION: |
|
- | 565 | ipc_answer_fast(callid, 0, screen.xres,screen.yres); |
|
466 | continue; |
566 | continue; |
467 | default: |
567 | default: |
468 | retval = ENOENT; |
568 | retval = ENOENT; |
469 | } |
569 | } |
470 | retval = ENOENT; |
- | |
471 | ipc_answer_fast(callid,retval,0,0); |
570 | ipc_answer_fast(callid,retval,0,0); |
472 | } |
571 | } |
473 | } |
572 | } |
474 | 573 | ||
475 | int main(int argc, char *argv[]) |
574 | int main(int argc, char *argv[]) |
476 | { |
575 | { |
477 | char connected = 0; |
576 | char connected = 0; |
478 | int res; |
577 | int res; |
479 | ipcarg_t phonead; |
578 | ipcarg_t phonead; |
480 | 579 | ||
481 | if(!sysinfo_value("fb")) |
580 | if(!sysinfo_value("fb")) |
482 | return -1; |
581 | return -1; |
483 | 582 | ||
484 | if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, &phonead)) != 0) |
583 | if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, &phonead)) != 0) |
485 | return -1; |
584 | return -1; |
486 | 585 | ||
487 | if (init_fb() != 0) |
586 | if (init_fb() != 0) |
488 | return -1; |
587 | return -1; |
489 | 588 | ||
490 | async_manager(); |
589 | async_manager(); |
491 | /* Never reached */ |
590 | /* Never reached */ |
492 | return 0; |
591 | return 0; |
493 | } |
592 | } |
494 | 593 |