Subversion Repositories HelenOS-historic

Rev

Rev 1547 | Rev 1555 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1547 Rev 1552
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 <stdlib.h>
30
#include <stdlib.h>
31
#include <unistd.h>
31
#include <unistd.h>
32
#include <string.h>
32
#include <string.h>
33
#include <ddi.h>
33
#include <ddi.h>
34
#include <sysinfo.h>
34
#include <sysinfo.h>
35
#include <align.h>
35
#include <align.h>
36
#include <as.h>
36
#include <as.h>
37
#include <ipc/fb.h>
37
#include <ipc/fb.h>
38
#include <ipc/ipc.h>
38
#include <ipc/ipc.h>
39
#include <ipc/ns.h>
39
#include <ipc/ns.h>
40
#include <ipc/services.h>
40
#include <ipc/services.h>
41
#include <kernel/errno.h>
41
#include <kernel/errno.h>
42
#include <async.h>
42
#include <async.h>
43
 
43
 
44
#include "font-8x16.h"
44
#include "font-8x16.h"
45
#include "helenos.xbm"
45
#include "helenos.xbm"
46
#include "fb.h"
46
#include "fb.h"
47
#include "main.h"
47
#include "main.h"
48
#include "../console/screenbuffer.h"
48
#include "../console/screenbuffer.h"
49
#include "ppm.h"
49
#include "ppm.h"
50
 
50
 
51
#define DEFAULT_BGCOLOR                0x000080
51
#define DEFAULT_BGCOLOR                0x000080
52
#define DEFAULT_FGCOLOR                0xffff00
52
#define DEFAULT_FGCOLOR                0xffff00
53
 
53
 
54
/***************************************************************/
54
/***************************************************************/
55
/* Pixel specific fuctions */
55
/* Pixel specific fuctions */
56
 
56
 
57
typedef void (*putpixel_fn_t)(unsigned int x, unsigned int y, int color);
57
typedef void (*putpixel_fn_t)(unsigned int x, unsigned int y, int color);
58
typedef int (*getpixel_fn_t)(unsigned int x, unsigned int y);
58
typedef int (*getpixel_fn_t)(unsigned int x, unsigned int y);
59
 
59
 
60
struct {
60
struct {
61
    __u8 *fbaddress ;
61
    __u8 *fbaddress ;
62
 
62
 
63
    unsigned int xres ;
63
    unsigned int xres ;
64
    unsigned int yres ;
64
    unsigned int yres ;
65
    unsigned int scanline ;
65
    unsigned int scanline ;
66
    unsigned int pixelbytes ;
66
    unsigned int pixelbytes ;
67
 
67
 
68
    putpixel_fn_t putpixel;
68
    putpixel_fn_t putpixel;
69
    getpixel_fn_t getpixel;
69
    getpixel_fn_t getpixel;
70
} screen;
70
} screen;
71
 
71
 
72
typedef struct {
72
typedef struct {
73
    int initialized;
73
    int initialized;
74
    unsigned int x, y;
74
    unsigned int x, y;
75
    unsigned int width, height;
75
    unsigned int width, height;
76
 
76
 
77
    /* Text support in window */
77
    /* Text support in window */
78
    unsigned int rows, cols;
78
    unsigned int rows, cols;
79
    /* Style for text printing */
79
    /* Style for text printing */
80
    style_t style;
80
    style_t style;
81
    /* Auto-cursor position */
81
    /* Auto-cursor position */
82
    int cursor_active, cur_col, cur_row;
82
    int cursor_active, cur_col, cur_row;
83
    int cursor_shown;
83
    int cursor_shown;
84
} viewport_t;
84
} viewport_t;
85
 
85
 
-
 
86
/** Maximum number of saved pixmaps
-
 
87
 * Pixmap is a saved rectangle
-
 
88
 */
-
 
89
#define MAX_PIXMAPS        256
-
 
90
typedef struct {
-
 
91
    unsigned int width;
-
 
92
    unsigned int height;
-
 
93
    void *data;
-
 
94
} pixmap_t;
-
 
95
static pixmap_t pixmaps[MAX_PIXMAPS];
-
 
96
 
-
 
97
/* Viewport is a rectangular area on the screen */
86
#define MAX_VIEWPORTS 128
98
#define MAX_VIEWPORTS 128
87
static viewport_t viewports[128];
99
static viewport_t viewports[128];
88
 
100
 
89
/* Allow only 1 connection */
101
/* Allow only 1 connection */
90
static int client_connected = 0;
102
static int client_connected = 0;
91
 
103
 
92
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
104
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
93
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
105
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
94
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
106
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
95
 
107
 
96
#define COL_WIDTH   8
108
#define COL_WIDTH   8
97
#define ROW_BYTES   (screen.scanline * FONT_SCANLINES)
109
#define ROW_BYTES   (screen.scanline * FONT_SCANLINES)
98
 
110
 
99
#define POINTPOS(x, y)  ((y) * screen.scanline + (x) * screen.pixelbytes)
111
#define POINTPOS(x, y)  ((y) * screen.scanline + (x) * screen.pixelbytes)
100
 
112
 
101
/** Put pixel - 24-bit depth, 1 free byte */
113
/** Put pixel - 24-bit depth, 1 free byte */
102
static void putpixel_4byte(unsigned int x, unsigned int y, int color)
114
static void putpixel_4byte(unsigned int x, unsigned int y, int color)
103
{
115
{
104
    *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) = color;
116
    *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) = color;
105
}
117
}
106
 
118
 
107
/** Return pixel color - 24-bit depth, 1 free byte */
119
/** Return pixel color - 24-bit depth, 1 free byte */
108
static int getpixel_4byte(unsigned int x, unsigned int y)
120
static int getpixel_4byte(unsigned int x, unsigned int y)
109
{
121
{
110
    return *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) & 0xffffff;
122
    return *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) & 0xffffff;
111
}
123
}
112
 
124
 
113
/** Put pixel - 24-bit depth */
125
/** Put pixel - 24-bit depth */
114
static void putpixel_3byte(unsigned int x, unsigned int y, int color)
126
static void putpixel_3byte(unsigned int x, unsigned int y, int color)
115
{
127
{
116
    unsigned int startbyte = POINTPOS(x, y);
128
    unsigned int startbyte = POINTPOS(x, y);
117
 
129
 
118
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
130
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
119
    screen.fbaddress[startbyte] = RED(color, 8);
131
    screen.fbaddress[startbyte] = RED(color, 8);
120
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
132
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
121
    screen.fbaddress[startbyte + 2] = BLUE(color, 8);
133
    screen.fbaddress[startbyte + 2] = BLUE(color, 8);
122
#else
134
#else
123
    screen.fbaddress[startbyte + 2] = RED(color, 8);
135
    screen.fbaddress[startbyte + 2] = RED(color, 8);
124
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
136
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
125
    screen.fbaddress[startbyte + 0] = BLUE(color, 8);
137
    screen.fbaddress[startbyte + 0] = BLUE(color, 8);
126
#endif
138
#endif
127
 
139
 
128
}
140
}
129
 
141
 
130
/** Return pixel color - 24-bit depth */
142
/** Return pixel color - 24-bit depth */
131
static int getpixel_3byte(unsigned int x, unsigned int y)
143
static int getpixel_3byte(unsigned int x, unsigned int y)
132
{
144
{
133
    unsigned int startbyte = POINTPOS(x, y);
145
    unsigned int startbyte = POINTPOS(x, y);
134
 
146
 
135
 
147
 
136
 
148
 
137
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
149
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
138
    return screen.fbaddress[startbyte] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 2];
150
    return screen.fbaddress[startbyte] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 2];
139
#else
151
#else
140
    return screen.fbaddress[startbyte + 2] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 0];
152
    return screen.fbaddress[startbyte + 2] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 0];
141
#endif
153
#endif
142
                               
154
                               
143
 
155
 
144
}
156
}
145
 
157
 
146
/** Put pixel - 16-bit depth (5:6:5) */
158
/** Put pixel - 16-bit depth (5:6:5) */
147
static void putpixel_2byte(unsigned int x, unsigned int y, int color)
159
static void putpixel_2byte(unsigned int x, unsigned int y, int color)
148
{
160
{
149
    /* 5-bit, 6-bits, 5-bits */
161
    /* 5-bit, 6-bits, 5-bits */
150
    *((__u16 *)(screen.fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5);
162
    *((__u16 *)(screen.fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5);
151
}
163
}
152
 
164
 
153
/** Return pixel color - 16-bit depth (5:6:5) */
165
/** Return pixel color - 16-bit depth (5:6:5) */
154
static int getpixel_2byte(unsigned int x, unsigned int y)
166
static int getpixel_2byte(unsigned int x, unsigned int y)
155
{
167
{
156
    int color = *((__u16 *)(screen.fbaddress + POINTPOS(x, y)));
168
    int color = *((__u16 *)(screen.fbaddress + POINTPOS(x, y)));
157
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
169
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
158
}
170
}
159
 
171
 
160
/** Put pixel - 8-bit depth (3:2:3) */
172
/** Put pixel - 8-bit depth (3:2:3) */
161
static void putpixel_1byte(unsigned int x, unsigned int y, int color)
173
static void putpixel_1byte(unsigned int x, unsigned int y, int color)
162
{
174
{
163
    screen.fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3);
175
    screen.fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3);
164
}
176
}
165
 
177
 
166
/** Return pixel color - 8-bit depth (3:2:3) */
178
/** Return pixel color - 8-bit depth (3:2:3) */
167
static int getpixel_1byte(unsigned int x, unsigned int y)
179
static int getpixel_1byte(unsigned int x, unsigned int y)
168
{
180
{
169
    int color = screen.fbaddress[POINTPOS(x, y)];
181
    int color = screen.fbaddress[POINTPOS(x, y)];
170
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
182
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
171
}
183
}
172
 
184
 
173
/** Put pixel into viewport
185
/** Put pixel into viewport
174
 *
186
 *
175
 * @param vp Viewport identification
187
 * @param vp Viewport identification
176
 * @param x X coord relative to viewport
188
 * @param x X coord relative to viewport
177
 * @param y Y coord relative to viewport
189
 * @param y Y coord relative to viewport
178
 * @param color RGB color
190
 * @param color RGB color
179
 */
191
 */
180
static void putpixel(int vp, unsigned int x, unsigned int y, int color)
192
static void putpixel(int vp, unsigned int x, unsigned int y, int color)
181
{
193
{
182
    screen.putpixel(viewports[vp].x + x, viewports[vp].y + y, color);
194
    screen.putpixel(viewports[vp].x + x, viewports[vp].y + y, color);
183
}
195
}
184
/** Get pixel from viewport */
196
/** Get pixel from viewport */
185
static int getpixel(int vp, unsigned int x, unsigned int y)
197
static int getpixel(int vp, unsigned int x, unsigned int y)
186
{
198
{
187
    return screen.getpixel(viewports[vp].x + x, viewports[vp].y + y);
199
    return screen.getpixel(viewports[vp].x + x, viewports[vp].y + y);
188
}
200
}
189
 
201
 
190
/** Fill line with color BGCOLOR */
202
/** Fill line with color BGCOLOR */
191
static void clear_line(int vp, unsigned int y)
203
static void clear_line(int vp, unsigned int y)
192
{
204
{
193
    unsigned int x;
205
    unsigned int x;
194
    for (x = 0; x < viewports[vp].width; x++)
206
    for (x = 0; x < viewports[vp].width; x++)
195
        putpixel(vp, x, y, viewports[vp].style.bg_color);
207
        putpixel(vp, x, y, viewports[vp].style.bg_color);
196
}
208
}
197
 
209
 
198
/** Fill viewport with background color */
210
/** Fill viewport with background color */
199
static void clear_port(int vp)
211
static void clear_port(int vp)
200
{
212
{
201
    unsigned int y;
213
    unsigned int y;
202
 
214
 
203
    clear_line(vp, 0);
215
    clear_line(vp, 0);
204
    for (y = viewports[vp].y+1; y < viewports[vp].y+viewports[vp].height; y++) {
216
    for (y = viewports[vp].y+1; y < viewports[vp].y+viewports[vp].height; y++) {
205
        memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
217
        memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
206
               &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
218
               &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
207
               screen.pixelbytes * viewports[vp].width);
219
               screen.pixelbytes * viewports[vp].width);
208
    }  
220
    }  
209
}
221
}
210
 
222
 
211
/** Scroll port up/down
223
/** Scroll port up/down
212
 *
224
 *
213
 * @param vp Viewport to scroll
225
 * @param vp Viewport to scroll
214
 * @param rows Positive number - scroll up, negative - scroll down
226
 * @param rows Positive number - scroll up, negative - scroll down
215
 */
227
 */
216
static void scroll_port(int vp, int rows)
228
static void scroll_port(int vp, int rows)
217
{
229
{
218
    int y;
230
    int y;
219
    int startline;
231
    int startline;
220
    int endline;
232
    int endline;
221
   
233
   
222
    if (rows > 0) {
234
    if (rows > 0) {
223
        for (y=viewports[vp].y; y < viewports[vp].y+viewports[vp].height - rows*FONT_SCANLINES; y++)
235
        for (y=viewports[vp].y; y < viewports[vp].y+viewports[vp].height - rows*FONT_SCANLINES; y++)
224
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
236
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
225
                   &screen.fbaddress[POINTPOS(viewports[vp].x,y + rows*FONT_SCANLINES)],
237
                   &screen.fbaddress[POINTPOS(viewports[vp].x,y + rows*FONT_SCANLINES)],
226
                   screen.pixelbytes * viewports[vp].width);
238
                   screen.pixelbytes * viewports[vp].width);
227
        /* Clear last row */
239
        /* Clear last row */
228
        startline = viewports[vp].y+FONT_SCANLINES*(viewports[vp].rows-1);
240
        startline = viewports[vp].y+FONT_SCANLINES*(viewports[vp].rows-1);
229
        endline = viewports[vp].y + viewports[vp].height;
241
        endline = viewports[vp].y + viewports[vp].height;
230
        clear_line(vp, startline);
242
        clear_line(vp, startline);
231
        for (y=startline+1;y < endline; y++)
243
        for (y=startline+1;y < endline; y++)
232
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
244
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
233
                   &screen.fbaddress[POINTPOS(viewports[vp].x,startline)],
245
                   &screen.fbaddress[POINTPOS(viewports[vp].x,startline)],
234
                   screen.pixelbytes * viewports[vp].width);
246
                   screen.pixelbytes * viewports[vp].width);
235
                 
247
                 
236
    } else if (rows < 0) {
248
    } else if (rows < 0) {
237
        rows = -rows;
249
        rows = -rows;
238
        for (y=viewports[vp].y + viewports[vp].height-1; y >= viewports[vp].y + rows*FONT_SCANLINES; y--)
250
        for (y=viewports[vp].y + viewports[vp].height-1; y >= viewports[vp].y + rows*FONT_SCANLINES; y--)
239
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
251
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
240
                &screen.fbaddress[POINTPOS(viewports[vp].x,y - rows*FONT_SCANLINES)],
252
                &screen.fbaddress[POINTPOS(viewports[vp].x,y - rows*FONT_SCANLINES)],
241
                screen.pixelbytes * viewports[vp].width);
253
                screen.pixelbytes * viewports[vp].width);
242
        /* Clear first row */
254
        /* Clear first row */
243
        clear_line(0, viewports[vp].style.bg_color);
255
        clear_line(0, viewports[vp].style.bg_color);
244
        for (y=1;y < rows*FONT_SCANLINES; y++)
256
        for (y=1;y < rows*FONT_SCANLINES; y++)
245
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y+y)],
257
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y+y)],
246
                   &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
258
                   &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
247
                   screen.pixelbytes * viewports[vp].width);
259
                   screen.pixelbytes * viewports[vp].width);
248
    }
260
    }
249
}
261
}
250
 
262
 
251
static void invert_pixel(int vp,unsigned int x, unsigned int y)
263
static void invert_pixel(int vp,unsigned int x, unsigned int y)
252
{
264
{
253
    putpixel(vp, x, y, ~getpixel(vp, x, y));
265
    putpixel(vp, x, y, ~getpixel(vp, x, y));
254
}
266
}
255
 
267
 
256
 
268
 
257
/***************************************************************/
269
/***************************************************************/
258
/* Character-console functions */
270
/* Character-console functions */
259
 
271
 
260
/** Draw character at given position */
272
/** Draw character at given position */
261
static void draw_glyph(int vp,__u8 glyph, unsigned int sx, unsigned int sy, style_t style)
273
static void draw_glyph(int vp,__u8 glyph, unsigned int sx, unsigned int sy, style_t style)
262
{
274
{
263
    int i;
275
    int i;
264
    unsigned int y;
276
    unsigned int y;
265
    unsigned int glline;
277
    unsigned int glline;
266
 
278
 
267
    for (y = 0; y < FONT_SCANLINES; y++) {
279
    for (y = 0; y < FONT_SCANLINES; y++) {
268
        glline = fb_font[glyph * FONT_SCANLINES + y];
280
        glline = fb_font[glyph * FONT_SCANLINES + y];
269
        for (i = 0; i < 8; i++) {
281
        for (i = 0; i < 8; i++) {
270
            if (glline & (1 << (7 - i)))
282
            if (glline & (1 << (7 - i)))
271
                putpixel(vp, sx + i, sy + y, style.fg_color);
283
                putpixel(vp, sx + i, sy + y, style.fg_color);
272
            else
284
            else
273
                putpixel(vp, sx + i, sy + y, style.bg_color);
285
                putpixel(vp, sx + i, sy + y, style.bg_color);
274
        }
286
        }
275
    }
287
    }
276
}
288
}
277
 
289
 
278
/** Invert character at given position */
290
/** Invert character at given position */
279
static void invert_char(int vp,unsigned int row, unsigned int col)
291
static void invert_char(int vp,unsigned int row, unsigned int col)
280
{
292
{
281
    unsigned int x;
293
    unsigned int x;
282
    unsigned int y;
294
    unsigned int y;
283
 
295
 
284
    for (x = 0; x < COL_WIDTH; x++)
296
    for (x = 0; x < COL_WIDTH; x++)
285
        for (y = 0; y < FONT_SCANLINES; y++)
297
        for (y = 0; y < FONT_SCANLINES; y++)
286
            invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y);
298
            invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y);
287
}
299
}
288
 
300
 
289
static void draw_logo(int vp,unsigned int startx, unsigned int starty)
-
 
290
{
-
 
291
    unsigned int x;
-
 
292
    unsigned int y;
-
 
293
    unsigned int byte;
-
 
294
    unsigned int rowbytes;
-
 
295
 
-
 
296
    rowbytes = (helenos_width - 1) / 8 + 1;
-
 
297
 
-
 
298
    for (y = 0; y < helenos_height; y++)
-
 
299
        for (x = 0; x < helenos_width; x++) {
-
 
300
            byte = helenos_bits[rowbytes * y + x / 8];
-
 
301
            byte >>= x % 8;
-
 
302
            if (byte & 1)
-
 
303
                putpixel(vp ,startx + x, starty + y, viewports[vp].style.fg_color);
-
 
304
        }
-
 
305
}
-
 
306
 
-
 
307
/***************************************************************/
301
/***************************************************************/
308
/* Stdout specific functions */
302
/* Stdout specific functions */
309
 
303
 
310
 
304
 
311
/** Create new viewport
305
/** Create new viewport
312
 *
306
 *
313
 * @return New viewport number
307
 * @return New viewport number
314
 */
308
 */
315
static int viewport_create(unsigned int x, unsigned int y,unsigned int width,
309
static int viewport_create(unsigned int x, unsigned int y,unsigned int width,
316
               unsigned int height)
310
               unsigned int height)
317
{
311
{
318
    int i;
312
    int i;
319
 
313
 
320
for (i=0; i < MAX_VIEWPORTS; i++) {
314
for (i=0; i < MAX_VIEWPORTS; i++) {
321
        if (!viewports[i].initialized)
315
        if (!viewports[i].initialized)
322
            break;
316
            break;
323
    }
317
    }
324
    if (i == MAX_VIEWPORTS)
318
    if (i == MAX_VIEWPORTS)
325
        return ELIMIT;
319
        return ELIMIT;
326
 
320
 
327
    if (width ==0 || height == 0 ||
321
    if (width ==0 || height == 0 ||
328
        x+width > screen.xres || y+height > screen.yres)
322
        x+width > screen.xres || y+height > screen.yres)
329
        return EINVAL;
323
        return EINVAL;
330
    if (width < FONT_SCANLINES || height < COL_WIDTH)
324
    if (width < FONT_SCANLINES || height < COL_WIDTH)
331
        return EINVAL;
325
        return EINVAL;
332
 
326
 
333
    viewports[i].x = x;
327
    viewports[i].x = x;
334
    viewports[i].y = y;
328
    viewports[i].y = y;
335
    viewports[i].width = width;
329
    viewports[i].width = width;
336
    viewports[i].height = height;
330
    viewports[i].height = height;
337
   
331
   
338
    viewports[i].rows = height / FONT_SCANLINES;
332
    viewports[i].rows = height / FONT_SCANLINES;
339
    viewports[i].cols = width / COL_WIDTH;
333
    viewports[i].cols = width / COL_WIDTH;
340
 
334
 
341
    viewports[i].style.bg_color = DEFAULT_BGCOLOR;
335
    viewports[i].style.bg_color = DEFAULT_BGCOLOR;
342
    viewports[i].style.fg_color = DEFAULT_FGCOLOR;
336
    viewports[i].style.fg_color = DEFAULT_FGCOLOR;
343
   
337
   
344
    viewports[i].cur_col = 0;
338
    viewports[i].cur_col = 0;
345
    viewports[i].cur_row = 0;
339
    viewports[i].cur_row = 0;
346
    viewports[i].cursor_active = 0;
340
    viewports[i].cursor_active = 0;
347
 
341
 
348
    viewports[i].initialized = 1;
342
    viewports[i].initialized = 1;
349
 
343
 
350
    return i;
344
    return i;
351
}
345
}
352
 
346
 
353
 
347
 
354
/** Initialize framebuffer as a chardev output device
348
/** Initialize framebuffer as a chardev output device
355
 *
349
 *
356
 * @param addr Address of theframebuffer
350
 * @param addr Address of theframebuffer
357
 * @param x    Screen width in pixels
351
 * @param x    Screen width in pixels
358
 * @param y    Screen height in pixels
352
 * @param y    Screen height in pixels
359
 * @param bpp  Bits per pixel (8, 16, 24, 32)
353
 * @param bpp  Bits per pixel (8, 16, 24, 32)
360
 * @param scan Bytes per one scanline
354
 * @param scan Bytes per one scanline
361
 *
355
 *
362
 */
356
 */
363
static void screen_init(void *addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan)
357
static void screen_init(void *addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan)
364
{
358
{
365
    switch (bpp) {
359
    switch (bpp) {
366
        case 8:
360
        case 8:
367
            screen.putpixel = putpixel_1byte;
361
            screen.putpixel = putpixel_1byte;
368
            screen.getpixel = getpixel_1byte;
362
            screen.getpixel = getpixel_1byte;
369
            screen.pixelbytes = 1;
363
            screen.pixelbytes = 1;
370
            break;
364
            break;
371
        case 16:
365
        case 16:
372
            screen.putpixel = putpixel_2byte;
366
            screen.putpixel = putpixel_2byte;
373
            screen.getpixel = getpixel_2byte;
367
            screen.getpixel = getpixel_2byte;
374
            screen.pixelbytes = 2;
368
            screen.pixelbytes = 2;
375
            break;
369
            break;
376
        case 24:
370
        case 24:
377
            screen.putpixel = putpixel_3byte;
371
            screen.putpixel = putpixel_3byte;
378
            screen.getpixel = getpixel_3byte;
372
            screen.getpixel = getpixel_3byte;
379
            screen.pixelbytes = 3;
373
            screen.pixelbytes = 3;
380
            break;
374
            break;
381
        case 32:
375
        case 32:
382
            screen.putpixel = putpixel_4byte;
376
            screen.putpixel = putpixel_4byte;
383
            screen.getpixel = getpixel_4byte;
377
            screen.getpixel = getpixel_4byte;
384
            screen.pixelbytes = 4;
378
            screen.pixelbytes = 4;
385
            break;
379
            break;
386
    }
380
    }
387
 
381
 
388
       
382
       
389
    screen.fbaddress = (unsigned char *) addr;
383
    screen.fbaddress = (unsigned char *) addr;
390
    screen.xres = xres;
384
    screen.xres = xres;
391
    screen.yres = yres;
385
    screen.yres = yres;
392
    screen.scanline = scan;
386
    screen.scanline = scan;
393
   
387
   
394
    /* Create first viewport */
388
    /* Create first viewport */
395
    viewport_create(0,0,xres,yres);
389
    viewport_create(0,0,xres,yres);
396
}
390
}
397
 
391
 
-
 
392
/** Hide cursor if it is shown */
398
static void cursor_hide(int vp)
393
static void cursor_hide(int vp)
399
{
394
{
400
    viewport_t *vport = &viewports[vp];
395
    viewport_t *vport = &viewports[vp];
401
 
396
 
402
    if (vport->cursor_active && vport->cursor_shown) {
397
    if (vport->cursor_active && vport->cursor_shown) {
403
        invert_char(vp, vport->cur_row, vport->cur_col);
398
        invert_char(vp, vport->cur_row, vport->cur_col);
404
        vport->cursor_shown = 0;
399
        vport->cursor_shown = 0;
405
    }
400
    }
406
}
401
}
407
 
402
 
-
 
403
/** Show cursor if cursor showing is enabled */
408
static void cursor_print(int vp)
404
static void cursor_print(int vp)
409
{
405
{
410
    viewport_t *vport = &viewports[vp];
406
    viewport_t *vport = &viewports[vp];
411
 
407
 
412
    /* Do not check for cursor_shown */
408
    /* Do not check for cursor_shown */
413
    if (vport->cursor_active) {
409
    if (vport->cursor_active) {
414
        invert_char(vp, vport->cur_row, vport->cur_col);
410
        invert_char(vp, vport->cur_row, vport->cur_col);
415
        vport->cursor_shown = 1;
411
        vport->cursor_shown = 1;
416
    }
412
    }
417
}
413
}
418
 
414
 
-
 
415
/** Invert cursor, if it is enabled */
419
static void cursor_blink(int vp)
416
static void cursor_blink(int vp)
420
{
417
{
421
    viewport_t *vport = &viewports[vp];
418
    viewport_t *vport = &viewports[vp];
422
 
419
 
423
    if (vport->cursor_shown)
420
    if (vport->cursor_shown)
424
        cursor_hide(vp);
421
        cursor_hide(vp);
425
    else
422
    else
426
        cursor_print(vp);
423
        cursor_print(vp);
427
}
424
}
428
 
425
 
429
/** Draw character at given position relative to viewport
426
/** Draw character at given position relative to viewport
430
 *
427
 *
431
 * @param vp Viewport identification
428
 * @param vp Viewport identification
432
 * @param c Character to print
429
 * @param c Character to print
433
 * @param row Screen position relative to viewport
430
 * @param row Screen position relative to viewport
434
 * @param col Screen position relative to viewport
431
 * @param col Screen position relative to viewport
435
 */
432
 */
436
static void draw_char(int vp, char c, unsigned int row, unsigned int col, style_t style)
433
static void draw_char(int vp, char c, unsigned int row, unsigned int col, style_t style)
437
{
434
{
438
    viewport_t *vport = &viewports[vp];
435
    viewport_t *vport = &viewports[vp];
439
 
436
 
440
    /* Optimize - do not hide cursor if we are going to overwrite it */
437
    /* Optimize - do not hide cursor if we are going to overwrite it */
441
    if (vport->cursor_active && vport->cursor_shown &&
438
    if (vport->cursor_active && vport->cursor_shown &&
442
        (vport->cur_col != col || vport->cur_row != row))
439
        (vport->cur_col != col || vport->cur_row != row))
443
        invert_char(vp, vport->cur_row, vport->cur_col);
440
        invert_char(vp, vport->cur_row, vport->cur_col);
444
   
441
   
445
    draw_glyph(vp, c, col * COL_WIDTH, row * FONT_SCANLINES, style);
442
    draw_glyph(vp, c, col * COL_WIDTH, row * FONT_SCANLINES, style);
446
 
443
 
447
    vport->cur_col = col;
444
    vport->cur_col = col;
448
    vport->cur_row = row;
445
    vport->cur_row = row;
449
 
446
 
450
    vport->cur_col++;
447
    vport->cur_col++;
451
    if (vport->cur_col>= vport->cols) {
448
    if (vport->cur_col>= vport->cols) {
452
        vport->cur_col = 0;
449
        vport->cur_col = 0;
453
        vport->cur_row++;
450
        vport->cur_row++;
454
        if (vport->cur_row >= vport->rows)
451
        if (vport->cur_row >= vport->rows)
455
            vport->cur_row--;
452
            vport->cur_row--;
456
    }
453
    }
457
    cursor_print(vp);
454
    cursor_print(vp);
458
}
455
}
459
 
456
 
-
 
457
/** Draw text data to viewport
-
 
458
 *
-
 
459
 * @param vp Viewport id
-
 
460
 * @param data Text data fitting exactly into viewport
-
 
461
 */
460
static void draw_text_data(int vp, keyfield_t *data)
462
static void draw_text_data(int vp, keyfield_t *data)
461
{
463
{
462
    viewport_t *vport = &viewports[vp];
464
    viewport_t *vport = &viewports[vp];
463
    int i;
465
    int i;
464
    char c;
466
    char c;
465
    int col,row;
467
    int col,row;
466
 
468
 
467
    clear_port(vp);
469
    clear_port(vp);
468
    for (i=0; i < vport->cols * vport->rows; i++) {
470
    for (i=0; i < vport->cols * vport->rows; i++) {
469
        if (data[i].character == ' ' && style_same(data[i].style,vport->style))
471
        if (data[i].character == ' ' && style_same(data[i].style,vport->style))
470
            continue;
472
            continue;
471
        col = i % vport->cols;
473
        col = i % vport->cols;
472
        row = i / vport->cols;
474
        row = i / vport->cols;
473
        draw_glyph(vp, data[i].character, col * COL_WIDTH, row * FONT_SCANLINES, data[i].style);
475
        draw_glyph(vp, data[i].character, col * COL_WIDTH, row * FONT_SCANLINES, data[i].style);
474
    }
476
    }
475
    cursor_print(vp);
477
    cursor_print(vp);
476
}
478
}
477
 
479
 
-
 
480
/** Handle shared memory communication calls
-
 
481
 *
-
 
482
 * Protocol for drawing pixmaps:
-
 
483
 * - FB_PREPARE_SHM(client shm identification)
-
 
484
 * - IPC_M_SEND_AS_AREA
-
 
485
 * - FB_DRAW_PPM(startx,starty)
-
 
486
 * - FB_DROP_SHM
-
 
487
 *
-
 
488
 * Protocol for text drawing
-
 
489
 * - IPC_M_SEND_AS_AREA
-
 
490
 * - FB_DRAW_TEXT_DATA
-
 
491
 *
-
 
492
 * @param callid Callid of the current call
-
 
493
 * @param call Current call data
-
 
494
 * @param vp Active viewport
-
 
495
 * @return 0 if the call was not handled byt this function, 1 otherwise
-
 
496
 *
-
 
497
 * note: this function is not threads safe, you would have
-
 
498
 * to redefine static variables with __thread
-
 
499
 */
478
static int shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
500
static int shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
479
{
501
{
480
    static keyfield_t *interbuffer = NULL;
502
    static keyfield_t *interbuffer = NULL;
481
    static size_t intersize = 0;
503
    static size_t intersize = 0;
482
 
504
 
483
    static char *pixmap = NULL;
505
    static char *pixmap = NULL;
484
    static ipcarg_t pixmap_id = 0;
506
    static ipcarg_t pixmap_id = 0;
485
    static size_t pixmap_size;
507
    static size_t pixmap_size;
486
 
508
 
487
    int handled = 1;
509
    int handled = 1;
488
    int retval = 0;
510
    int retval = 0;
489
    viewport_t *vport = &viewports[vp];
511
    viewport_t *vport = &viewports[vp];
490
    unsigned int x,y;
512
    unsigned int x,y;
491
 
513
 
492
    switch (IPC_GET_METHOD(*call)) {
514
    switch (IPC_GET_METHOD(*call)) {
493
    case IPC_M_AS_AREA_SEND:
515
    case IPC_M_AS_AREA_SEND:
494
        /* We accept one area for data interchange */
516
        /* We accept one area for data interchange */
495
        if (IPC_GET_ARG1(*call) == pixmap_id) {
517
        if (IPC_GET_ARG1(*call) == pixmap_id) {
496
            void *dest = as_get_mappable_page(IPC_GET_ARG2(*call));
518
            void *dest = as_get_mappable_page(IPC_GET_ARG2(*call));
497
            pixmap_size = IPC_GET_ARG2(*call);
519
            pixmap_size = IPC_GET_ARG2(*call);
498
            if (!ipc_answer_fast(callid, 0, (sysarg_t)dest, 0))
520
            if (!ipc_answer_fast(callid, 0, (sysarg_t)dest, 0))
499
                pixmap = dest;
521
                pixmap = dest;
500
            else
522
            else
501
                pixmap_id = 0;
523
                pixmap_id = 0;
502
            if (pixmap[0] != 'P')
524
            if (pixmap[0] != 'P')
503
                while (1)
525
                while (1)
504
                    ;
526
                    ;
505
            return 1;
527
            return 1;
506
        } else {
528
        } else {
507
            intersize = IPC_GET_ARG2(*call);
529
            intersize = IPC_GET_ARG2(*call);
508
            receive_comm_area(callid,call,(void **)&interbuffer);
530
            receive_comm_area(callid,call,(void **)&interbuffer);
509
        }
531
        }
510
        return 1;
532
        return 1;
511
    case FB_PREPARE_SHM:
533
    case FB_PREPARE_SHM:
512
        if (pixmap_id)
534
        if (pixmap_id)
513
            retval = EBUSY;
535
            retval = EBUSY;
514
        else
536
        else
515
            pixmap_id = IPC_GET_ARG1(*call);
537
            pixmap_id = IPC_GET_ARG1(*call);
516
        break;
538
        break;
517
       
539
       
518
    case FB_DROP_SHM:
540
    case FB_DROP_SHM:
519
        if (pixmap) {
541
        if (pixmap) {
520
            as_area_destroy(pixmap);
542
            as_area_destroy(pixmap);
521
            pixmap = NULL;
543
            pixmap = NULL;
522
        }
544
        }
523
        pixmap_id = 0;
545
        pixmap_id = 0;
524
        break;
546
        break;
525
       
547
       
526
    case FB_DRAW_PPM:
548
    case FB_DRAW_PPM:
527
        if (!pixmap) {
549
        if (!pixmap) {
528
            retval = EINVAL;
550
            retval = EINVAL;
529
            break;
551
            break;
530
        }
552
        }
531
        x = IPC_GET_ARG1(*call);
553
        x = IPC_GET_ARG1(*call);
532
        y = IPC_GET_ARG2(*call);
554
        y = IPC_GET_ARG2(*call);
533
        if (x > vport->width || y > vport->height) {
555
        if (x > vport->width || y > vport->height) {
534
            retval = EINVAL;
556
            retval = EINVAL;
535
            break;
557
            break;
536
        }
558
        }
537
       
559
       
538
        draw_ppm(pixmap, pixmap_size, IPC_GET_ARG1(*call), IPC_GET_ARG2(*call),
560
        draw_ppm(pixmap, pixmap_size, IPC_GET_ARG1(*call), IPC_GET_ARG2(*call),
539
             vport->width - x, vport->height - y, putpixel, vp);
561
             vport->width - x, vport->height - y, putpixel, vp);
540
        break;
562
        break;
541
    case FB_DRAW_TEXT_DATA:
563
    case FB_DRAW_TEXT_DATA:
542
        if (!interbuffer) {
564
        if (!interbuffer) {
543
            retval = EINVAL;
565
            retval = EINVAL;
544
            break;
566
            break;
545
        }
567
        }
546
        if (intersize < vport->cols*vport->rows*sizeof(*interbuffer)) {
568
        if (intersize < vport->cols*vport->rows*sizeof(*interbuffer)) {
547
            retval = EINVAL;
569
            retval = EINVAL;
548
            break;
570
            break;
549
        }
571
        }
550
        draw_text_data(vp, interbuffer);
572
        draw_text_data(vp, interbuffer);
551
        break;
573
        break;
552
    default:
574
    default:
553
        handled = 0;
575
        handled = 0;
554
    }
576
    }
555
   
577
   
556
    if (handled)
578
    if (handled)
557
        ipc_answer_fast(callid, retval, 0, 0);
579
        ipc_answer_fast(callid, retval, 0, 0);
558
    return handled;
580
    return handled;
559
}
581
}
560
 
582
 
-
 
583
/** Return first free pixmap */
-
 
584
static int find_free_pixmap(void)
-
 
585
{
-
 
586
    int i;
-
 
587
   
-
 
588
    for (i=0;i < MAX_PIXMAPS;i++)
-
 
589
        if (!pixmaps[i].data)
-
 
590
            return i;
-
 
591
    return -1;
-
 
592
}
-
 
593
 
-
 
594
/** Save viewport to pixmap */
-
 
595
static int save_vp_to_pixmap(int vp)
-
 
596
{
-
 
597
    int pm;
-
 
598
    pixmap_t *pmap;
-
 
599
    viewport_t *vport = &viewports[vp];
-
 
600
    int x,y;
-
 
601
    int rowsize;
-
 
602
    int tmp;
-
 
603
 
-
 
604
    pm = find_free_pixmap();
-
 
605
    if (pm == -1)
-
 
606
        return ELIMIT;
-
 
607
   
-
 
608
    pmap = &pixmaps[pm];
-
 
609
    pmap->data = malloc(screen.pixelbytes * vport->width * vport->height);
-
 
610
    if (!pmap->data)
-
 
611
        return ENOMEM;
-
 
612
 
-
 
613
    pmap->width = vport->width;
-
 
614
    pmap->height = vport->height;
-
 
615
   
-
 
616
    rowsize = vport->width * screen.pixelbytes;
-
 
617
    for (y=0;y < vport->height; y++) {
-
 
618
        tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
-
 
619
        memcpy(pmap->data + rowsize*y, screen.fbaddress + tmp, rowsize);
-
 
620
    }
-
 
621
    return pm;
-
 
622
}
-
 
623
 
-
 
624
/** Draw pixmap on screen
-
 
625
 *
-
 
626
 * @param vp Viewport to draw on
-
 
627
 * @param pm Pixmap identifier
-
 
628
 */
-
 
629
static int draw_pixmap(int vp, int pm)
-
 
630
{
-
 
631
    pixmap_t *pmap = &pixmaps[pm];
-
 
632
    viewport_t *vport = &viewports[vp];
-
 
633
    int x,y;
-
 
634
    int tmp, srcrowsize;
-
 
635
    int realwidth, realheight, realrowsize;
-
 
636
 
-
 
637
    if (!pmap->data)
-
 
638
        return EINVAL;
-
 
639
 
-
 
640
    realwidth = pmap->width <= vport->width ? pmap->width : vport->width;
-
 
641
    realheight = pmap->height <= vport->height ? pmap->height : vport->height;
-
 
642
 
-
 
643
    srcrowsize = vport->width * screen.pixelbytes;
-
 
644
    realrowsize = realwidth * screen.pixelbytes;
-
 
645
 
-
 
646
    for (y=0; y < realheight; y++) {
-
 
647
        tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
-
 
648
        memcpy(screen.fbaddress + tmp, pmap->data + y * srcrowsize, realrowsize);
-
 
649
    }
-
 
650
}
-
 
651
 
-
 
652
/** Handler for messages concerning pixmap handling */
-
 
653
static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
-
 
654
{
-
 
655
    int handled = 1;
-
 
656
    int retval = 0;
-
 
657
    int i,nvp;
-
 
658
 
-
 
659
    switch (IPC_GET_METHOD(*call)) {
-
 
660
    case FB_VP_DRAW_PIXMAP:
-
 
661
        nvp = IPC_GET_ARG1(*call);
-
 
662
        if (nvp == -1)
-
 
663
            nvp = vp;
-
 
664
        if (nvp < 0 || nvp >= MAX_VIEWPORTS || !viewports[nvp].initialized) {
-
 
665
            retval = EINVAL;
-
 
666
            break;
-
 
667
        }
-
 
668
        i = IPC_GET_ARG2(*call);
-
 
669
        retval = draw_pixmap(nvp, i);
-
 
670
        break;
-
 
671
    case FB_VP2PIXMAP:
-
 
672
        nvp = IPC_GET_ARG1(*call);
-
 
673
        if (nvp == -1)
-
 
674
            nvp = vp;
-
 
675
        if (nvp < 0 || nvp >= MAX_VIEWPORTS || !viewports[nvp].initialized)
-
 
676
            retval = EINVAL;
-
 
677
        else
-
 
678
            retval = save_vp_to_pixmap(nvp);
-
 
679
        break;
-
 
680
    case FB_DROP_PIXMAP:
-
 
681
        i = IPC_GET_ARG1(*call);
-
 
682
        if (i >= MAX_PIXMAPS) {
-
 
683
            retval = EINVAL;
-
 
684
            break;
-
 
685
        }
-
 
686
        if (pixmaps[i].data) {
-
 
687
            free(pixmaps[i].data);
-
 
688
            pixmaps[i].data = NULL;
-
 
689
        }
-
 
690
        break;
-
 
691
    default:
-
 
692
        handled = 0;
-
 
693
    }
-
 
694
 
-
 
695
    if (handled)
-
 
696
        ipc_answer_fast(callid, retval, 0, 0);
-
 
697
    return handled;
-
 
698
   
-
 
699
}
-
 
700
 
561
/** Function for handling connections to FB
701
/** Function for handling connections to FB
562
 *
702
 *
563
 */
703
 */
564
static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
704
static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
565
{
705
{
566
    ipc_callid_t callid;
706
    ipc_callid_t callid;
567
    ipc_call_t call;
707
    ipc_call_t call;
568
    int retval;
708
    int retval;
569
    int i;
709
    int i;
570
    unsigned int row,col;
710
    unsigned int row,col;
571
    char c;
711
    char c;
572
 
712
 
573
    int vp = 0;
713
    int vp = 0;
574
    viewport_t *vport = &viewports[0];
714
    viewport_t *vport = &viewports[0];
575
 
715
 
576
    if (client_connected) {
716
    if (client_connected) {
577
        ipc_answer_fast(iid, ELIMIT, 0,0);
717
        ipc_answer_fast(iid, ELIMIT, 0,0);
578
        return;
718
        return;
579
    }
719
    }
580
    client_connected = 1;
720
    client_connected = 1;
581
    ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
721
    ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
582
 
722
 
583
    while (1) {
723
    while (1) {
584
        callid = async_get_call_timeout(&call,250000);
724
        callid = async_get_call_timeout(&call,250000);
585
        if (!callid) {
725
        if (!callid) {
586
            cursor_blink(vp);
726
            cursor_blink(vp);
587
            continue;
727
            continue;
588
        }
728
        }
589
        if (shm_handle(callid, &call, vp))
729
        if (shm_handle(callid, &call, vp))
590
            continue;
730
            continue;
-
 
731
        if (pixmap_handle(callid, &call, vp))
-
 
732
            continue;
591
 
733
 
592
        switch (IPC_GET_METHOD(call)) {
734
        switch (IPC_GET_METHOD(call)) {
593
        case IPC_M_PHONE_HUNGUP:
735
        case IPC_M_PHONE_HUNGUP:
594
            client_connected = 0;
736
            client_connected = 0;
595
            /* cleanup other viewports */
737
            /* cleanup other viewports */
596
            for (i=1; i < MAX_VIEWPORTS; i++)
738
            for (i=1; i < MAX_VIEWPORTS; i++)
597
                vport->initialized = 0;
739
                vport->initialized = 0;
598
            ipc_answer_fast(callid,0,0,0);
740
            ipc_answer_fast(callid,0,0,0);
599
            return; /* Exit thread */
741
            return; /* Exit thread */
600
 
742
 
601
        case FB_PUTCHAR:
743
        case FB_PUTCHAR:
602
            c = IPC_GET_ARG1(call);
744
            c = IPC_GET_ARG1(call);
603
            row = IPC_GET_ARG2(call);
745
            row = IPC_GET_ARG2(call);
604
            col = IPC_GET_ARG3(call);
746
            col = IPC_GET_ARG3(call);
605
            if (row >= vport->rows || col >= vport->cols) {
747
            if (row >= vport->rows || col >= vport->cols) {
606
                retval = EINVAL;
748
                retval = EINVAL;
607
                break;
749
                break;
608
            }
750
            }
609
            ipc_answer_fast(callid,0,0,0);
751
            ipc_answer_fast(callid,0,0,0);
610
 
752
 
611
            draw_char(vp, c, row, col, vport->style);
753
            draw_char(vp, c, row, col, vport->style);
612
            continue; /* msg already answered */
754
            continue; /* msg already answered */
613
        case FB_CLEAR:
755
        case FB_CLEAR:
614
            clear_port(vp);
756
            clear_port(vp);
615
            cursor_print(vp);
757
            cursor_print(vp);
616
            retval = 0;
758
            retval = 0;
617
            break;
759
            break;
618
        case FB_CURSOR_GOTO:
760
        case FB_CURSOR_GOTO:
619
            row = IPC_GET_ARG1(call);
761
            row = IPC_GET_ARG1(call);
620
            col = IPC_GET_ARG2(call);
762
            col = IPC_GET_ARG2(call);
621
            if (row >= vport->rows || col >= vport->cols) {
763
            if (row >= vport->rows || col >= vport->cols) {
622
                retval = EINVAL;
764
                retval = EINVAL;
623
                break;
765
                break;
624
            }
766
            }
625
            retval = 0;
767
            retval = 0;
626
            cursor_hide(vp);
768
            cursor_hide(vp);
627
            vport->cur_col = col;
769
            vport->cur_col = col;
628
            vport->cur_row = row;
770
            vport->cur_row = row;
629
            cursor_print(vp);
771
            cursor_print(vp);
630
            break;
772
            break;
631
        case FB_CURSOR_VISIBILITY:
773
        case FB_CURSOR_VISIBILITY:
632
            cursor_hide(vp);
774
            cursor_hide(vp);
633
            vport->cursor_active = IPC_GET_ARG1(call);
775
            vport->cursor_active = IPC_GET_ARG1(call);
634
            cursor_print(vp);
776
            cursor_print(vp);
635
            retval = 0;
777
            retval = 0;
636
            break;
778
            break;
637
        case FB_GET_CSIZE:
779
        case FB_GET_CSIZE:
638
            ipc_answer_fast(callid, 0, vport->rows, vport->cols);
780
            ipc_answer_fast(callid, 0, vport->rows, vport->cols);
639
            continue;
781
            continue;
640
        case FB_SCROLL:
782
        case FB_SCROLL:
641
            i = IPC_GET_ARG1(call);
783
            i = IPC_GET_ARG1(call);
642
            if (i > vport->rows || i < (- (int)vport->rows)) {
784
            if (i > vport->rows || i < (- (int)vport->rows)) {
643
                retval = EINVAL;
785
                retval = EINVAL;
644
                break;
786
                break;
645
            }
787
            }
646
            cursor_hide(vp);
788
            cursor_hide(vp);
647
            scroll_port(vp, i);
789
            scroll_port(vp, i);
648
            cursor_print(vp);
790
            cursor_print(vp);
649
            retval = 0;
791
            retval = 0;
650
            break;
792
            break;
651
        case FB_VIEWPORT_SWITCH:
793
        case FB_VIEWPORT_SWITCH:
652
            i = IPC_GET_ARG1(call);
794
            i = IPC_GET_ARG1(call);
653
            if (i < 0 || i >= MAX_VIEWPORTS) {
795
            if (i < 0 || i >= MAX_VIEWPORTS) {
654
                retval = EINVAL;
796
                retval = EINVAL;
655
                break;
797
                break;
656
            }
798
            }
657
            if (! viewports[i].initialized ) {
799
            if (! viewports[i].initialized ) {
658
                retval = EADDRNOTAVAIL;
800
                retval = EADDRNOTAVAIL;
659
                break;
801
                break;
660
            }
802
            }
661
            cursor_hide(vp);
803
            cursor_hide(vp);
662
            vp = i;
804
            vp = i;
663
            vport = &viewports[vp];
805
            vport = &viewports[vp];
664
            cursor_print(vp);
806
            cursor_print(vp);
665
            retval = 0;
807
            retval = 0;
666
            break;
808
            break;
667
        case FB_VIEWPORT_CREATE:
809
        case FB_VIEWPORT_CREATE:
668
            retval = viewport_create(IPC_GET_ARG1(call) >> 16,
810
            retval = viewport_create(IPC_GET_ARG1(call) >> 16,
669
                         IPC_GET_ARG1(call) & 0xffff,
811
                         IPC_GET_ARG1(call) & 0xffff,
670
                         IPC_GET_ARG2(call) >> 16,
812
                         IPC_GET_ARG2(call) >> 16,
671
                         IPC_GET_ARG2(call) & 0xffff);
813
                         IPC_GET_ARG2(call) & 0xffff);
672
            break;
814
            break;
673
        case FB_VIEWPORT_DELETE:
815
        case FB_VIEWPORT_DELETE:
674
            i = IPC_GET_ARG1(call);
816
            i = IPC_GET_ARG1(call);
675
            if (i < 0 || i >= MAX_VIEWPORTS) {
817
            if (i < 0 || i >= MAX_VIEWPORTS) {
676
                retval = EINVAL;
818
                retval = EINVAL;
677
                break;
819
                break;
678
            }
820
            }
679
            if (! viewports[i].initialized ) {
821
            if (! viewports[i].initialized ) {
680
                retval = EADDRNOTAVAIL;
822
                retval = EADDRNOTAVAIL;
681
                break;
823
                break;
682
            }
824
            }
683
            viewports[i].initialized = 0;
825
            viewports[i].initialized = 0;
684
            retval = 0;
826
            retval = 0;
685
            break;
827
            break;
686
        case FB_SET_STYLE:
828
        case FB_SET_STYLE:
687
            vport->style.fg_color = IPC_GET_ARG1(call);
829
            vport->style.fg_color = IPC_GET_ARG1(call);
688
            vport->style.bg_color = IPC_GET_ARG2(call);
830
            vport->style.bg_color = IPC_GET_ARG2(call);
689
            retval = 0;
831
            retval = 0;
690
            break;
832
            break;
691
        case FB_GET_RESOLUTION:
833
        case FB_GET_RESOLUTION:
692
            ipc_answer_fast(callid, 0, screen.xres,screen.yres);
834
            ipc_answer_fast(callid, 0, screen.xres,screen.yres);
693
            continue;
835
            continue;
694
        default:
836
        default:
695
            retval = ENOENT;
837
            retval = ENOENT;
696
        }
838
        }
697
        ipc_answer_fast(callid,retval,0,0);
839
        ipc_answer_fast(callid,retval,0,0);
698
    }
840
    }
699
}
841
}
700
 
842
 
701
/** Initialization of framebuffer */
843
/** Initialization of framebuffer */
702
int fb_init(void)
844
int fb_init(void)
703
{
845
{
704
    void *fb_ph_addr;
846
    void *fb_ph_addr;
705
    unsigned int fb_width;
847
    unsigned int fb_width;
706
    unsigned int fb_height;
848
    unsigned int fb_height;
707
    unsigned int fb_bpp;
849
    unsigned int fb_bpp;
708
    unsigned int fb_scanline;
850
    unsigned int fb_scanline;
709
    void *fb_addr;
851
    void *fb_addr;
710
    size_t asz;
852
    size_t asz;
711
 
853
 
712
    async_set_client_connection(fb_client_connection);
854
    async_set_client_connection(fb_client_connection);
713
 
855
 
714
    fb_ph_addr=(void *)sysinfo_value("fb.address.physical");
856
    fb_ph_addr=(void *)sysinfo_value("fb.address.physical");
715
    fb_width=sysinfo_value("fb.width");
857
    fb_width=sysinfo_value("fb.width");
716
    fb_height=sysinfo_value("fb.height");
858
    fb_height=sysinfo_value("fb.height");
717
    fb_bpp=sysinfo_value("fb.bpp");
859
    fb_bpp=sysinfo_value("fb.bpp");
718
    fb_scanline=sysinfo_value("fb.scanline");
860
    fb_scanline=sysinfo_value("fb.scanline");
719
 
861
 
720
    asz = fb_scanline*fb_height;
862
    asz = fb_scanline*fb_height;
721
    fb_addr = as_get_mappable_page(asz);
863
    fb_addr = as_get_mappable_page(asz);
722
   
864
   
723
    map_physmem(fb_ph_addr, fb_addr, ALIGN_UP(asz,PAGE_SIZE) >>PAGE_WIDTH,
865
    map_physmem(fb_ph_addr, fb_addr, ALIGN_UP(asz,PAGE_SIZE) >>PAGE_WIDTH,
724
            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
866
            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
725
   
867
   
726
    screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline);
868
    screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline);
727
 
869
 
728
    return 0;
870
    return 0;
729
}
871
}
730
 
872
 
731
 
873