[afa6e74] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Jakub Vana
|
---|
| 3 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
[afa6e74] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 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
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 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
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 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
|
---|
| 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
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[231a60a] | 30 | /**
|
---|
| 31 | * @defgroup fb Graphical framebuffer
|
---|
| 32 | * @brief HelenOS graphical framebuffer.
|
---|
[ce5bcb4] | 33 | * @ingroup fbs
|
---|
| 34 | * @{
|
---|
| 35 | */
|
---|
[06e1e95] | 36 |
|
---|
[ce5bcb4] | 37 | /** @file
|
---|
| 38 | */
|
---|
| 39 |
|
---|
[afa6e74] | 40 | #include <stdlib.h>
|
---|
[7f5b37a] | 41 | #include <unistd.h>
|
---|
| 42 | #include <string.h>
|
---|
[afa6e74] | 43 | #include <ddi.h>
|
---|
| 44 | #include <sysinfo.h>
|
---|
| 45 | #include <align.h>
|
---|
| 46 | #include <as.h>
|
---|
| 47 | #include <ipc/fb.h>
|
---|
| 48 | #include <ipc/ipc.h>
|
---|
| 49 | #include <ipc/ns.h>
|
---|
[7f5b37a] | 50 | #include <ipc/services.h>
|
---|
[afa6e74] | 51 | #include <kernel/errno.h>
|
---|
[2bc137c2] | 52 | #include <kernel/genarch/fb/visuals.h>
|
---|
[80649a91] | 53 | #include <async.h>
|
---|
[2bc137c2] | 54 | #include <bool.h>
|
---|
[83b1d61] | 55 |
|
---|
[a2cd194] | 56 | #include "font-8x16.h"
|
---|
[afa6e74] | 57 | #include "fb.h"
|
---|
[83b1d61] | 58 | #include "main.h"
|
---|
| 59 | #include "../console/screenbuffer.h"
|
---|
[90f5d64] | 60 | #include "ppm.h"
|
---|
[afa6e74] | 61 |
|
---|
[2ce520c] | 62 | #include "pointer.xbm"
|
---|
| 63 | #include "pointer_mask.xbm"
|
---|
| 64 |
|
---|
[7284260] | 65 | #define DEFAULT_BGCOLOR 0xf0f0f0
|
---|
| 66 | #define DEFAULT_FGCOLOR 0x0
|
---|
[afa6e74] | 67 |
|
---|
| 68 | /***************************************************************/
|
---|
| 69 | /* Pixel specific fuctions */
|
---|
| 70 |
|
---|
[a7d2d78] | 71 | typedef void (*conv2scr_fn_t)(void *, int);
|
---|
| 72 | typedef int (*conv2rgb_fn_t)(void *);
|
---|
[afa6e74] | 73 |
|
---|
[a2ae4f4] | 74 | struct {
|
---|
[253f35a1] | 75 | uint8_t *fbaddress;
|
---|
[afa6e74] | 76 |
|
---|
[253f35a1] | 77 | unsigned int xres;
|
---|
| 78 | unsigned int yres;
|
---|
| 79 | unsigned int scanline;
|
---|
| 80 | unsigned int pixelbytes;
|
---|
| 81 | unsigned int invert_colors;
|
---|
[afa6e74] | 82 |
|
---|
[a7d2d78] | 83 | conv2scr_fn_t rgb2scr;
|
---|
| 84 | conv2rgb_fn_t scr2rgb;
|
---|
[a2ae4f4] | 85 | } screen;
|
---|
[afa6e74] | 86 |
|
---|
[a2ae4f4] | 87 | typedef struct {
|
---|
| 88 | int initialized;
|
---|
| 89 | unsigned int x, y;
|
---|
| 90 | unsigned int width, height;
|
---|
[afa6e74] | 91 |
|
---|
[a2ae4f4] | 92 | /* Text support in window */
|
---|
| 93 | unsigned int rows, cols;
|
---|
| 94 | /* Style for text printing */
|
---|
[6b5111a] | 95 | style_t style;
|
---|
[a2ae4f4] | 96 | /* Auto-cursor position */
|
---|
[88c3151] | 97 | int cursor_active, cur_col, cur_row;
|
---|
[49d072e] | 98 | int cursor_shown;
|
---|
[e92aabf] | 99 | /* Double buffering */
|
---|
[afbe96a] | 100 | uint8_t *dbdata;
|
---|
[e92aabf] | 101 | unsigned int dboffset;
|
---|
| 102 | unsigned int paused;
|
---|
[a2ae4f4] | 103 | } viewport_t;
|
---|
| 104 |
|
---|
[1fd7700] | 105 | #define MAX_ANIM_LEN 8
|
---|
| 106 | #define MAX_ANIMATIONS 4
|
---|
| 107 | typedef struct {
|
---|
| 108 | int initialized;
|
---|
| 109 | int enabled;
|
---|
| 110 | unsigned int vp;
|
---|
| 111 |
|
---|
| 112 | unsigned int pos;
|
---|
| 113 | unsigned int animlen;
|
---|
| 114 | unsigned int pixmaps[MAX_ANIM_LEN];
|
---|
| 115 | } animation_t;
|
---|
| 116 | static animation_t animations[MAX_ANIMATIONS];
|
---|
| 117 | static int anims_enabled;
|
---|
| 118 |
|
---|
[429acb9] | 119 | /** Maximum number of saved pixmaps
|
---|
| 120 | * Pixmap is a saved rectangle
|
---|
| 121 | */
|
---|
| 122 | #define MAX_PIXMAPS 256
|
---|
| 123 | typedef struct {
|
---|
| 124 | unsigned int width;
|
---|
| 125 | unsigned int height;
|
---|
[afbe96a] | 126 | uint8_t *data;
|
---|
[429acb9] | 127 | } pixmap_t;
|
---|
| 128 | static pixmap_t pixmaps[MAX_PIXMAPS];
|
---|
| 129 |
|
---|
| 130 | /* Viewport is a rectangular area on the screen */
|
---|
[a2ae4f4] | 131 | #define MAX_VIEWPORTS 128
|
---|
| 132 | static viewport_t viewports[128];
|
---|
| 133 |
|
---|
| 134 | /* Allow only 1 connection */
|
---|
| 135 | static int client_connected = 0;
|
---|
[afa6e74] | 136 |
|
---|
| 137 | #define RED(x, bits) ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
|
---|
| 138 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
|
---|
| 139 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1))
|
---|
| 140 |
|
---|
[a2ae4f4] | 141 | #define COL_WIDTH 8
|
---|
| 142 | #define ROW_BYTES (screen.scanline * FONT_SCANLINES)
|
---|
[afa6e74] | 143 |
|
---|
[a2ae4f4] | 144 | #define POINTPOS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes)
|
---|
[afa6e74] | 145 |
|
---|
[253f35a1] | 146 | static inline int COLOR(int color)
|
---|
| 147 | {
|
---|
| 148 | return screen.invert_colors ? ~color : color;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[a7d2d78] | 151 | /* Conversion routines between different color representations */
|
---|
[d7baee6] | 152 | static void
|
---|
| 153 | rgb_byte0888(void *dst, int rgb)
|
---|
[afa6e74] | 154 | {
|
---|
[a7d2d78] | 155 | *(int *)dst = rgb;
|
---|
[afa6e74] | 156 | }
|
---|
| 157 |
|
---|
[d7baee6] | 158 | static int
|
---|
| 159 | byte0888_rgb(void *src)
|
---|
[afa6e74] | 160 | {
|
---|
[a7d2d78] | 161 | return (*(int *)src) & 0xffffff;
|
---|
[afa6e74] | 162 | }
|
---|
| 163 |
|
---|
[d7baee6] | 164 | static void
|
---|
| 165 | bgr_byte0888(void *dst, int rgb)
|
---|
[ccb0cbc] | 166 | {
|
---|
[00bb6965] | 167 | *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 |
|
---|
| 168 | RED(rgb, 8);
|
---|
[ccb0cbc] | 169 | }
|
---|
| 170 |
|
---|
[d7baee6] | 171 | static int
|
---|
| 172 | byte0888_bgr(void *src)
|
---|
[ccb0cbc] | 173 | {
|
---|
| 174 | int color = *(uint32_t *)(src);
|
---|
[d7baee6] | 175 | return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) |
|
---|
| 176 | ((color >> 16) & 0xff);
|
---|
[ccb0cbc] | 177 | }
|
---|
| 178 |
|
---|
[d7baee6] | 179 | static void
|
---|
| 180 | rgb_byte888(void *dst, int rgb)
|
---|
[afa6e74] | 181 | {
|
---|
[afbe96a] | 182 | uint8_t *scr = dst;
|
---|
[d7e3f1ad] | 183 | #if defined(FB_INVERT_ENDIAN)
|
---|
[a7d2d78] | 184 | scr[0] = RED(rgb, 8);
|
---|
| 185 | scr[1] = GREEN(rgb, 8);
|
---|
| 186 | scr[2] = BLUE(rgb, 8);
|
---|
[afa6e74] | 187 | #else
|
---|
[a7d2d78] | 188 | scr[2] = RED(rgb, 8);
|
---|
| 189 | scr[1] = GREEN(rgb, 8);
|
---|
| 190 | scr[0] = BLUE(rgb, 8);
|
---|
[afa6e74] | 191 | #endif
|
---|
| 192 | }
|
---|
| 193 |
|
---|
[d7baee6] | 194 | static int
|
---|
| 195 | byte888_rgb(void *src)
|
---|
[afa6e74] | 196 | {
|
---|
[afbe96a] | 197 | uint8_t *scr = src;
|
---|
[d7e3f1ad] | 198 | #if defined(FB_INVERT_ENDIAN)
|
---|
[a7d2d78] | 199 | return scr[0] << 16 | scr[1] << 8 | scr[2];
|
---|
[afa6e74] | 200 | #else
|
---|
[a7d2d78] | 201 | return scr[2] << 16 | scr[1] << 8 | scr[0];
|
---|
| 202 | #endif
|
---|
[afa6e74] | 203 | }
|
---|
| 204 |
|
---|
[2bc137c2] | 205 | /** 16-bit depth (5:5:5) */
|
---|
[d7baee6] | 206 | static void
|
---|
| 207 | rgb_byte555(void *dst, int rgb)
|
---|
[2bc137c2] | 208 | {
|
---|
| 209 | /* 5-bit, 5-bits, 5-bits */
|
---|
[00bb6965] | 210 | *((uint16_t *)(dst)) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 |
|
---|
| 211 | BLUE(rgb, 5);
|
---|
[2bc137c2] | 212 | }
|
---|
| 213 |
|
---|
| 214 | /** 16-bit depth (5:5:5) */
|
---|
[d7baee6] | 215 | static int
|
---|
| 216 | byte555_rgb(void *src)
|
---|
[2bc137c2] | 217 | {
|
---|
| 218 | int color = *(uint16_t *)(src);
|
---|
[d7baee6] | 219 | return (((color >> 10) & 0x1f) << (16 + 3)) |
|
---|
| 220 | (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3);
|
---|
[2bc137c2] | 221 | }
|
---|
| 222 |
|
---|
[a7d2d78] | 223 | /** 16-bit depth (5:6:5) */
|
---|
[d7baee6] | 224 | static void
|
---|
| 225 | rgb_byte565(void *dst, int rgb)
|
---|
[afa6e74] | 226 | {
|
---|
| 227 | /* 5-bit, 6-bits, 5-bits */
|
---|
[00bb6965] | 228 | *((uint16_t *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 |
|
---|
| 229 | BLUE(rgb, 5);
|
---|
[afa6e74] | 230 | }
|
---|
| 231 |
|
---|
[a7d2d78] | 232 | /** 16-bit depth (5:6:5) */
|
---|
[d7baee6] | 233 | static int
|
---|
| 234 | byte565_rgb(void *src)
|
---|
[afa6e74] | 235 | {
|
---|
[afbe96a] | 236 | int color = *(uint16_t *)(src);
|
---|
[d7baee6] | 237 | return (((color >> 11) & 0x1f) << (16 + 3)) |
|
---|
| 238 | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
|
---|
[afa6e74] | 239 | }
|
---|
| 240 |
|
---|
| 241 | /** Put pixel - 8-bit depth (3:2:3) */
|
---|
[d7baee6] | 242 | static void
|
---|
| 243 | rgb_byte8(void *dst, int rgb)
|
---|
[afa6e74] | 244 | {
|
---|
[afbe96a] | 245 | *(uint8_t *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
|
---|
[afa6e74] | 246 | }
|
---|
| 247 |
|
---|
| 248 | /** Return pixel color - 8-bit depth (3:2:3) */
|
---|
[d7baee6] | 249 | static int
|
---|
| 250 | byte8_rgb(void *src)
|
---|
[afa6e74] | 251 | {
|
---|
[afbe96a] | 252 | int color = *(uint8_t *)src;
|
---|
[d7baee6] | 253 | return (((color >> 5) & 0x7) << (16 + 5)) |
|
---|
| 254 | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
|
---|
[afa6e74] | 255 | }
|
---|
| 256 |
|
---|
[1180a88e] | 257 | /** Put pixel into viewport
|
---|
| 258 | *
|
---|
[096ba7a] | 259 | * @param vport Viewport identification
|
---|
[1180a88e] | 260 | * @param x X coord relative to viewport
|
---|
| 261 | * @param y Y coord relative to viewport
|
---|
| 262 | * @param color RGB color
|
---|
| 263 | */
|
---|
[d7baee6] | 264 | static void
|
---|
| 265 | putpixel(viewport_t *vport, unsigned int x, unsigned int y, int color)
|
---|
[a2ae4f4] | 266 | {
|
---|
[bd02038] | 267 | int dx = vport->x + x;
|
---|
| 268 | int dy = vport->y + y;
|
---|
[e92aabf] | 269 |
|
---|
[bd02038] | 270 | if (! (vport->paused && vport->dbdata))
|
---|
[d7baee6] | 271 | (*screen.rgb2scr)(&screen.fbaddress[POINTPOS(dx,dy)],
|
---|
| 272 | COLOR(color));
|
---|
[e92aabf] | 273 |
|
---|
[bd02038] | 274 | if (vport->dbdata) {
|
---|
| 275 | int dline = (y + vport->dboffset) % vport->height;
|
---|
| 276 | int doffset = screen.pixelbytes * (dline * vport->width + x);
|
---|
[253f35a1] | 277 | (*screen.rgb2scr)(&vport->dbdata[doffset], COLOR(color));
|
---|
[e92aabf] | 278 | }
|
---|
[a2ae4f4] | 279 | }
|
---|
[e92aabf] | 280 |
|
---|
[1180a88e] | 281 | /** Get pixel from viewport */
|
---|
[d7baee6] | 282 | static int
|
---|
| 283 | getpixel(viewport_t *vport, unsigned int x, unsigned int y)
|
---|
[a2ae4f4] | 284 | {
|
---|
[bd02038] | 285 | int dx = vport->x + x;
|
---|
| 286 | int dy = vport->y + y;
|
---|
[a7d2d78] | 287 |
|
---|
[d7baee6] | 288 | return COLOR((*screen.scr2rgb)(&screen.fbaddress[POINTPOS(dx, dy)]));
|
---|
[a2ae4f4] | 289 | }
|
---|
| 290 |
|
---|
[d7baee6] | 291 | static inline void
|
---|
| 292 | putpixel_mem(char *mem, unsigned int x, unsigned int y, int color)
|
---|
[afa6e74] | 293 | {
|
---|
[253f35a1] | 294 | (*screen.rgb2scr)(&mem[POINTPOS(x,y)], COLOR(color));
|
---|
[afa6e74] | 295 | }
|
---|
| 296 |
|
---|
[d7baee6] | 297 | static void
|
---|
| 298 | draw_rectangle(viewport_t *vport, unsigned int sx, unsigned int sy,
|
---|
[00bb6965] | 299 | unsigned int width, unsigned int height, int color)
|
---|
[67ec84b] | 300 | {
|
---|
| 301 | unsigned int x, y;
|
---|
[0a9a324] | 302 | static void *tmpline;
|
---|
| 303 |
|
---|
| 304 | if (!tmpline)
|
---|
| 305 | tmpline = malloc(screen.scanline*screen.pixelbytes);
|
---|
[67ec84b] | 306 |
|
---|
| 307 | /* Clear first line */
|
---|
| 308 | for (x = 0; x < width; x++)
|
---|
[0a9a324] | 309 | putpixel_mem(tmpline, x, 0, color);
|
---|
[67ec84b] | 310 |
|
---|
[bd02038] | 311 | if (!vport->paused) {
|
---|
[e92aabf] | 312 | /* Recompute to screen coords */
|
---|
[bd02038] | 313 | sx += vport->x;
|
---|
| 314 | sy += vport->y;
|
---|
[e92aabf] | 315 | /* Copy the rest */
|
---|
| 316 | for (y = sy;y < sy+height; y++)
|
---|
| 317 | memcpy(&screen.fbaddress[POINTPOS(sx,y)], tmpline,
|
---|
| 318 | screen.pixelbytes * width);
|
---|
| 319 | }
|
---|
[bd02038] | 320 | if (vport->dbdata) {
|
---|
[00bb6965] | 321 | for (y = sy; y < sy + height; y++) {
|
---|
[bd02038] | 322 | int rline = (y + vport->dboffset) % vport->height;
|
---|
[00bb6965] | 323 | int rpos = (rline * vport->width + sx) *
|
---|
| 324 | screen.pixelbytes;
|
---|
| 325 | memcpy(&vport->dbdata[rpos], tmpline,
|
---|
| 326 | screen.pixelbytes * width);
|
---|
[e92aabf] | 327 | }
|
---|
| 328 | }
|
---|
[67ec84b] | 329 |
|
---|
| 330 | }
|
---|
| 331 |
|
---|
[a2ae4f4] | 332 | /** Fill viewport with background color */
|
---|
[d7baee6] | 333 | static void
|
---|
| 334 | clear_port(viewport_t *vport)
|
---|
[afa6e74] | 335 | {
|
---|
[00bb6965] | 336 | draw_rectangle(vport, 0, 0, vport->width, vport->height,
|
---|
| 337 | vport->style.bg_color);
|
---|
[afa6e74] | 338 | }
|
---|
| 339 |
|
---|
[e92aabf] | 340 | /** Scroll unbuffered viewport up/down
|
---|
[a2ae4f4] | 341 | *
|
---|
[096ba7a] | 342 | * @param vport Viewport to scroll
|
---|
| 343 | * @param lines Positive number - scroll up, negative - scroll down
|
---|
[a2ae4f4] | 344 | */
|
---|
[d7baee6] | 345 | static void
|
---|
| 346 | scroll_port_nodb(viewport_t *vport, int lines)
|
---|
[afa6e74] | 347 | {
|
---|
[a2ae4f4] | 348 | int y;
|
---|
[e92aabf] | 349 |
|
---|
| 350 | if (lines > 0) {
|
---|
[00bb6965] | 351 | for (y = vport->y; y < vport->y+vport->height - lines; y++)
|
---|
[67ec84b] | 352 | memcpy(&screen.fbaddress[POINTPOS(vport->x,y)],
|
---|
[e92aabf] | 353 | &screen.fbaddress[POINTPOS(vport->x,y + lines)],
|
---|
[67ec84b] | 354 | screen.pixelbytes * vport->width);
|
---|
[00bb6965] | 355 | draw_rectangle(vport, 0, vport->height - lines, vport->width,
|
---|
| 356 | lines, vport->style.bg_color);
|
---|
[e92aabf] | 357 | } else if (lines < 0) {
|
---|
| 358 | lines = -lines;
|
---|
[00bb6965] | 359 | for (y = vport->y + vport->height-1; y >= vport->y + lines;
|
---|
| 360 | y--)
|
---|
[67ec84b] | 361 | memcpy(&screen.fbaddress[POINTPOS(vport->x,y)],
|
---|
[e92aabf] | 362 | &screen.fbaddress[POINTPOS(vport->x,y - lines)],
|
---|
| 363 | screen.pixelbytes * vport->width);
|
---|
[00bb6965] | 364 | draw_rectangle(vport, 0, 0, vport->width, lines,
|
---|
| 365 | vport->style.bg_color);
|
---|
[e92aabf] | 366 | }
|
---|
| 367 | }
|
---|
| 368 |
|
---|
| 369 | /** Refresh given viewport from double buffer */
|
---|
[d7baee6] | 370 | static void
|
---|
| 371 | refresh_viewport_db(viewport_t *vport)
|
---|
[e92aabf] | 372 | {
|
---|
| 373 | unsigned int y, srcy, srcoff, dsty, dstx;
|
---|
| 374 |
|
---|
[bd02038] | 375 | for (y = 0; y < vport->height; y++) {
|
---|
| 376 | srcy = (y + vport->dboffset) % vport->height;
|
---|
| 377 | srcoff = (vport->width * srcy) * screen.pixelbytes;
|
---|
[e92aabf] | 378 |
|
---|
[bd02038] | 379 | dstx = vport->x;
|
---|
| 380 | dsty = vport->y + y;
|
---|
[e92aabf] | 381 |
|
---|
| 382 | memcpy(&screen.fbaddress[POINTPOS(dstx,dsty)],
|
---|
[bd02038] | 383 | &vport->dbdata[srcoff],
|
---|
| 384 | vport->width*screen.pixelbytes);
|
---|
[a2ae4f4] | 385 | }
|
---|
[afa6e74] | 386 | }
|
---|
| 387 |
|
---|
[e92aabf] | 388 | /** Scroll viewport that has double buffering enabled */
|
---|
[d7baee6] | 389 | static void
|
---|
| 390 | scroll_port_db(viewport_t *vport, int lines)
|
---|
[e92aabf] | 391 | {
|
---|
[bd02038] | 392 | ++vport->paused;
|
---|
[e92aabf] | 393 | if (lines > 0) {
|
---|
[bd02038] | 394 | draw_rectangle(vport, 0, 0, vport->width, lines,
|
---|
| 395 | vport->style.bg_color);
|
---|
| 396 | vport->dboffset += lines;
|
---|
| 397 | vport->dboffset %= vport->height;
|
---|
[e92aabf] | 398 | } else if (lines < 0) {
|
---|
| 399 | lines = -lines;
|
---|
[bd02038] | 400 | draw_rectangle(vport, 0, vport->height-lines,
|
---|
| 401 | vport->width, lines,
|
---|
| 402 | vport->style.bg_color);
|
---|
[e92aabf] | 403 |
|
---|
[bd02038] | 404 | if (vport->dboffset < lines)
|
---|
| 405 | vport->dboffset += vport->height;
|
---|
| 406 | vport->dboffset -= lines;
|
---|
[e92aabf] | 407 | }
|
---|
| 408 |
|
---|
[bd02038] | 409 | --vport->paused;
|
---|
[e92aabf] | 410 |
|
---|
[bd02038] | 411 | refresh_viewport_db(vport);
|
---|
[e92aabf] | 412 | }
|
---|
| 413 |
|
---|
| 414 | /** Scrolls viewport given number of lines */
|
---|
[d7baee6] | 415 | static void
|
---|
| 416 | scroll_port(viewport_t *vport, int lines)
|
---|
[e92aabf] | 417 | {
|
---|
[bd02038] | 418 | if (vport->dbdata)
|
---|
| 419 | scroll_port_db(vport, lines);
|
---|
[e92aabf] | 420 | else
|
---|
[bd02038] | 421 | scroll_port_nodb(vport, lines);
|
---|
[e92aabf] | 422 |
|
---|
| 423 | }
|
---|
| 424 |
|
---|
[d7baee6] | 425 | static void
|
---|
| 426 | invert_pixel(viewport_t *vport, unsigned int x, unsigned int y)
|
---|
[afa6e74] | 427 | {
|
---|
[bd02038] | 428 | putpixel(vport, x, y, ~getpixel(vport, x, y));
|
---|
[afa6e74] | 429 | }
|
---|
| 430 |
|
---|
| 431 |
|
---|
| 432 | /***************************************************************/
|
---|
| 433 | /* Character-console functions */
|
---|
| 434 |
|
---|
[d530237a] | 435 | /** Draw character at given position
|
---|
| 436 | *
|
---|
[096ba7a] | 437 | * @param vport Viewport where the character is printed
|
---|
[d530237a] | 438 | * @param sx Coordinates of top-left of the character
|
---|
| 439 | * @param sy Coordinates of top-left of the character
|
---|
| 440 | * @param style Color of the character
|
---|
| 441 | * @param transparent If false, print background color
|
---|
| 442 | */
|
---|
[d7baee6] | 443 | static void
|
---|
| 444 | draw_glyph(viewport_t *vport,uint8_t glyph, unsigned int sx,
|
---|
[00bb6965] | 445 | unsigned int sy, style_t style, int transparent)
|
---|
[afa6e74] | 446 | {
|
---|
[6b5111a] | 447 | int i;
|
---|
[afa6e74] | 448 | unsigned int y;
|
---|
[6b5111a] | 449 | unsigned int glline;
|
---|
| 450 |
|
---|
| 451 | for (y = 0; y < FONT_SCANLINES; y++) {
|
---|
| 452 | glline = fb_font[glyph * FONT_SCANLINES + y];
|
---|
| 453 | for (i = 0; i < 8; i++) {
|
---|
| 454 | if (glline & (1 << (7 - i)))
|
---|
[00bb6965] | 455 | putpixel(vport, sx + i, sy + y,
|
---|
| 456 | style.fg_color);
|
---|
[d530237a] | 457 | else if (!transparent)
|
---|
[00bb6965] | 458 | putpixel(vport, sx + i, sy + y,
|
---|
| 459 | style.bg_color);
|
---|
[6b5111a] | 460 | }
|
---|
| 461 | }
|
---|
[afa6e74] | 462 | }
|
---|
| 463 |
|
---|
| 464 | /** Invert character at given position */
|
---|
[d7baee6] | 465 | static void
|
---|
| 466 | invert_char(viewport_t *vport,unsigned int row, unsigned int col)
|
---|
[afa6e74] | 467 | {
|
---|
| 468 | unsigned int x;
|
---|
| 469 | unsigned int y;
|
---|
| 470 |
|
---|
| 471 | for (x = 0; x < COL_WIDTH; x++)
|
---|
| 472 | for (y = 0; y < FONT_SCANLINES; y++)
|
---|
[00bb6965] | 473 | invert_pixel(vport, col * COL_WIDTH + x, row *
|
---|
| 474 | FONT_SCANLINES + y);
|
---|
[afa6e74] | 475 | }
|
---|
| 476 |
|
---|
| 477 | /***************************************************************/
|
---|
| 478 | /* Stdout specific functions */
|
---|
| 479 |
|
---|
| 480 |
|
---|
[a2ae4f4] | 481 | /** Create new viewport
|
---|
[afa6e74] | 482 | *
|
---|
[a2ae4f4] | 483 | * @return New viewport number
|
---|
[afa6e74] | 484 | */
|
---|
[d7baee6] | 485 | static int
|
---|
| 486 | viewport_create(unsigned int x, unsigned int y,unsigned int width,
|
---|
[00bb6965] | 487 | unsigned int height)
|
---|
[afa6e74] | 488 | {
|
---|
[a2ae4f4] | 489 | int i;
|
---|
| 490 |
|
---|
[d7baee6] | 491 | for (i = 0; i < MAX_VIEWPORTS; i++) {
|
---|
[a2ae4f4] | 492 | if (!viewports[i].initialized)
|
---|
[afa6e74] | 493 | break;
|
---|
| 494 | }
|
---|
[a2ae4f4] | 495 | if (i == MAX_VIEWPORTS)
|
---|
| 496 | return ELIMIT;
|
---|
| 497 |
|
---|
| 498 | viewports[i].x = x;
|
---|
| 499 | viewports[i].y = y;
|
---|
| 500 | viewports[i].width = width;
|
---|
| 501 | viewports[i].height = height;
|
---|
[afa6e74] | 502 |
|
---|
[a2ae4f4] | 503 | viewports[i].rows = height / FONT_SCANLINES;
|
---|
| 504 | viewports[i].cols = width / COL_WIDTH;
|
---|
| 505 |
|
---|
[6b5111a] | 506 | viewports[i].style.bg_color = DEFAULT_BGCOLOR;
|
---|
| 507 | viewports[i].style.fg_color = DEFAULT_FGCOLOR;
|
---|
[afa6e74] | 508 |
|
---|
[c1d2c9d] | 509 | viewports[i].cur_col = 0;
|
---|
| 510 | viewports[i].cur_row = 0;
|
---|
| 511 | viewports[i].cursor_active = 0;
|
---|
| 512 |
|
---|
[88c3151] | 513 | viewports[i].initialized = 1;
|
---|
| 514 |
|
---|
[a2ae4f4] | 515 | return i;
|
---|
[afa6e74] | 516 | }
|
---|
| 517 |
|
---|
| 518 | /** Initialize framebuffer as a chardev output device
|
---|
| 519 | *
|
---|
[2bc137c2] | 520 | * @param addr Address of theframebuffer
|
---|
| 521 | * @param xres Screen width in pixels
|
---|
| 522 | * @param yres Screen height in pixels
|
---|
| 523 | * @param visual Bits per pixel (8, 16, 24, 32)
|
---|
| 524 | * @param scan Bytes per one scanline
|
---|
[253f35a1] | 525 | * @param invert_colors Inverted colors.
|
---|
[afa6e74] | 526 | *
|
---|
| 527 | */
|
---|
[d7baee6] | 528 | static bool
|
---|
| 529 | screen_init(void *addr, unsigned int xres, unsigned int yres,
|
---|
[00bb6965] | 530 | unsigned int scan, unsigned int visual, bool invert_colors)
|
---|
[afa6e74] | 531 | {
|
---|
[2bc137c2] | 532 | switch (visual) {
|
---|
| 533 | case VISUAL_INDIRECT_8:
|
---|
| 534 | screen.rgb2scr = rgb_byte8;
|
---|
| 535 | screen.scr2rgb = byte8_rgb;
|
---|
[775df25] | 536 | screen.pixelbytes = 1;
|
---|
| 537 | break;
|
---|
[2bc137c2] | 538 | case VISUAL_RGB_5_5_5:
|
---|
| 539 | screen.rgb2scr = rgb_byte555;
|
---|
| 540 | screen.scr2rgb = byte555_rgb;
|
---|
[775df25] | 541 | screen.pixelbytes = 2;
|
---|
| 542 | break;
|
---|
[2bc137c2] | 543 | case VISUAL_RGB_5_6_5:
|
---|
| 544 | screen.rgb2scr = rgb_byte565;
|
---|
| 545 | screen.scr2rgb = byte565_rgb;
|
---|
| 546 | screen.pixelbytes = 2;
|
---|
[775df25] | 547 | break;
|
---|
[2bc137c2] | 548 | case VISUAL_RGB_8_8_8:
|
---|
| 549 | screen.rgb2scr = rgb_byte888;
|
---|
| 550 | screen.scr2rgb = byte888_rgb;
|
---|
| 551 | screen.pixelbytes = 3;
|
---|
| 552 | break;
|
---|
| 553 | case VISUAL_RGB_8_8_8_0:
|
---|
| 554 | screen.rgb2scr = rgb_byte888;
|
---|
| 555 | screen.scr2rgb = byte888_rgb;
|
---|
| 556 | screen.pixelbytes = 4;
|
---|
| 557 | break;
|
---|
| 558 | case VISUAL_RGB_0_8_8_8:
|
---|
| 559 | screen.rgb2scr = rgb_byte0888;
|
---|
| 560 | screen.scr2rgb = byte0888_rgb;
|
---|
[775df25] | 561 | screen.pixelbytes = 4;
|
---|
| 562 | break;
|
---|
[ccb0cbc] | 563 | case VISUAL_BGR_0_8_8_8:
|
---|
| 564 | screen.rgb2scr = bgr_byte0888;
|
---|
| 565 | screen.scr2rgb = byte0888_bgr;
|
---|
| 566 | screen.pixelbytes = 4;
|
---|
| 567 | break;
|
---|
[2bc137c2] | 568 | default:
|
---|
| 569 | return false;
|
---|
[afa6e74] | 570 | }
|
---|
| 571 |
|
---|
[a2ae4f4] | 572 | screen.fbaddress = (unsigned char *) addr;
|
---|
| 573 | screen.xres = xres;
|
---|
| 574 | screen.yres = yres;
|
---|
| 575 | screen.scanline = scan;
|
---|
[253f35a1] | 576 | screen.invert_colors = invert_colors;
|
---|
[afa6e74] | 577 |
|
---|
[a2ae4f4] | 578 | /* Create first viewport */
|
---|
[2bc137c2] | 579 | viewport_create(0, 0, xres, yres);
|
---|
| 580 |
|
---|
| 581 | return true;
|
---|
[afa6e74] | 582 | }
|
---|
| 583 |
|
---|
[429acb9] | 584 | /** Hide cursor if it is shown */
|
---|
[d7baee6] | 585 | static void
|
---|
| 586 | cursor_hide(viewport_t *vport)
|
---|
[49d072e] | 587 | {
|
---|
| 588 | if (vport->cursor_active && vport->cursor_shown) {
|
---|
[bd02038] | 589 | invert_char(vport, vport->cur_row, vport->cur_col);
|
---|
[49d072e] | 590 | vport->cursor_shown = 0;
|
---|
| 591 | }
|
---|
| 592 | }
|
---|
| 593 |
|
---|
[429acb9] | 594 | /** Show cursor if cursor showing is enabled */
|
---|
[d7baee6] | 595 | static void
|
---|
| 596 | cursor_print(viewport_t *vport)
|
---|
[49d072e] | 597 | {
|
---|
| 598 | /* Do not check for cursor_shown */
|
---|
| 599 | if (vport->cursor_active) {
|
---|
[bd02038] | 600 | invert_char(vport, vport->cur_row, vport->cur_col);
|
---|
[49d072e] | 601 | vport->cursor_shown = 1;
|
---|
| 602 | }
|
---|
| 603 | }
|
---|
| 604 |
|
---|
[429acb9] | 605 | /** Invert cursor, if it is enabled */
|
---|
[d7baee6] | 606 | static void
|
---|
| 607 | cursor_blink(viewport_t *vport)
|
---|
[49d072e] | 608 | {
|
---|
| 609 | if (vport->cursor_shown)
|
---|
[bd02038] | 610 | cursor_hide(vport);
|
---|
[49d072e] | 611 | else
|
---|
[bd02038] | 612 | cursor_print(vport);
|
---|
[49d072e] | 613 | }
|
---|
| 614 |
|
---|
[1180a88e] | 615 | /** Draw character at given position relative to viewport
|
---|
| 616 | *
|
---|
[096ba7a] | 617 | * @param vport Viewport identification
|
---|
[1180a88e] | 618 | * @param c Character to print
|
---|
| 619 | * @param row Screen position relative to viewport
|
---|
| 620 | * @param col Screen position relative to viewport
|
---|
[d530237a] | 621 | * @param transparent If false, print background color with character
|
---|
[1180a88e] | 622 | */
|
---|
[d7baee6] | 623 | static void
|
---|
| 624 | draw_char(viewport_t *vport, char c, unsigned int row, unsigned int col,
|
---|
| 625 | style_t style, int transparent)
|
---|
[88c3151] | 626 | {
|
---|
[49d072e] | 627 | /* Optimize - do not hide cursor if we are going to overwrite it */
|
---|
| 628 | if (vport->cursor_active && vport->cursor_shown &&
|
---|
| 629 | (vport->cur_col != col || vport->cur_row != row))
|
---|
[bd02038] | 630 | invert_char(vport, vport->cur_row, vport->cur_col);
|
---|
[88c3151] | 631 |
|
---|
[00bb6965] | 632 | draw_glyph(vport, c, col * COL_WIDTH, row * FONT_SCANLINES, style,
|
---|
| 633 | transparent);
|
---|
[c1d2c9d] | 634 |
|
---|
| 635 | vport->cur_col = col;
|
---|
| 636 | vport->cur_row = row;
|
---|
| 637 |
|
---|
| 638 | vport->cur_col++;
|
---|
[00bb6965] | 639 | if (vport->cur_col >= vport->cols) {
|
---|
[c1d2c9d] | 640 | vport->cur_col = 0;
|
---|
| 641 | vport->cur_row++;
|
---|
| 642 | if (vport->cur_row >= vport->rows)
|
---|
| 643 | vport->cur_row--;
|
---|
[88c3151] | 644 | }
|
---|
[bd02038] | 645 | cursor_print(vport);
|
---|
[88c3151] | 646 | }
|
---|
| 647 |
|
---|
[429acb9] | 648 | /** Draw text data to viewport
|
---|
| 649 | *
|
---|
[096ba7a] | 650 | * @param vport Viewport id
|
---|
[429acb9] | 651 | * @param data Text data fitting exactly into viewport
|
---|
| 652 | */
|
---|
[d7baee6] | 653 | static void
|
---|
| 654 | draw_text_data(viewport_t *vport, keyfield_t *data)
|
---|
[83b1d61] | 655 | {
|
---|
| 656 | int i;
|
---|
[58fce89] | 657 | int col,row;
|
---|
[83b1d61] | 658 |
|
---|
[bd02038] | 659 | clear_port(vport);
|
---|
[00bb6965] | 660 | for (i = 0; i < vport->cols * vport->rows; i++) {
|
---|
| 661 | if (data[i].character == ' ' && style_same(data[i].style,
|
---|
| 662 | vport->style))
|
---|
[83b1d61] | 663 | continue;
|
---|
[58fce89] | 664 | col = i % vport->cols;
|
---|
| 665 | row = i / vport->cols;
|
---|
[00bb6965] | 666 | draw_glyph(vport, data[i].character, col * COL_WIDTH, row *
|
---|
| 667 | FONT_SCANLINES, data[i].style,
|
---|
| 668 | style_same(data[i].style,vport->style));
|
---|
[83b1d61] | 669 | }
|
---|
[bd02038] | 670 | cursor_print(vport);
|
---|
[83b1d61] | 671 | }
|
---|
| 672 |
|
---|
[a7d2d78] | 673 | /** Return first free pixmap */
|
---|
[d7baee6] | 674 | static int
|
---|
| 675 | find_free_pixmap(void)
|
---|
[a7d2d78] | 676 | {
|
---|
| 677 | int i;
|
---|
| 678 |
|
---|
[d7baee6] | 679 | for (i = 0;i < MAX_PIXMAPS;i++)
|
---|
[a7d2d78] | 680 | if (!pixmaps[i].data)
|
---|
| 681 | return i;
|
---|
| 682 | return -1;
|
---|
| 683 | }
|
---|
| 684 |
|
---|
[d7baee6] | 685 | static void
|
---|
| 686 | putpixel_pixmap(int pm, unsigned int x, unsigned int y, int color)
|
---|
[a7d2d78] | 687 | {
|
---|
| 688 | pixmap_t *pmap = &pixmaps[pm];
|
---|
| 689 | int pos = (y * pmap->width + x) * screen.pixelbytes;
|
---|
| 690 |
|
---|
[253f35a1] | 691 | (*screen.rgb2scr)(&pmap->data[pos],COLOR(color));
|
---|
[a7d2d78] | 692 | }
|
---|
| 693 |
|
---|
| 694 | /** Create a new pixmap and return appropriate ID */
|
---|
[d7baee6] | 695 | static int
|
---|
| 696 | shm2pixmap(unsigned char *shm, size_t size)
|
---|
[a7d2d78] | 697 | {
|
---|
| 698 | int pm;
|
---|
| 699 | pixmap_t *pmap;
|
---|
| 700 |
|
---|
| 701 | pm = find_free_pixmap();
|
---|
| 702 | if (pm == -1)
|
---|
| 703 | return ELIMIT;
|
---|
| 704 | pmap = &pixmaps[pm];
|
---|
| 705 |
|
---|
| 706 | if (ppm_get_data(shm, size, &pmap->width, &pmap->height))
|
---|
| 707 | return EINVAL;
|
---|
| 708 |
|
---|
| 709 | pmap->data = malloc(pmap->width * pmap->height * screen.pixelbytes);
|
---|
| 710 | if (!pmap->data)
|
---|
| 711 | return ENOMEM;
|
---|
| 712 |
|
---|
| 713 | ppm_draw(shm, size, 0, 0, pmap->width, pmap->height,
|
---|
[bd02038] | 714 | (putpixel_cb_t)putpixel_pixmap, (void *)pm);
|
---|
[a7d2d78] | 715 |
|
---|
| 716 | return pm;
|
---|
| 717 | }
|
---|
| 718 |
|
---|
[429acb9] | 719 | /** Handle shared memory communication calls
|
---|
| 720 | *
|
---|
| 721 | * Protocol for drawing pixmaps:
|
---|
| 722 | * - FB_PREPARE_SHM(client shm identification)
|
---|
[00bb6965] | 723 | * - IPC_M_AS_AREA_SEND
|
---|
[429acb9] | 724 | * - FB_DRAW_PPM(startx,starty)
|
---|
| 725 | * - FB_DROP_SHM
|
---|
| 726 | *
|
---|
| 727 | * Protocol for text drawing
|
---|
[00bb6965] | 728 | * - IPC_M_AS_AREA_SEND
|
---|
[429acb9] | 729 | * - FB_DRAW_TEXT_DATA
|
---|
| 730 | *
|
---|
| 731 | * @param callid Callid of the current call
|
---|
| 732 | * @param call Current call data
|
---|
| 733 | * @param vp Active viewport
|
---|
| 734 | * @return 0 if the call was not handled byt this function, 1 otherwise
|
---|
| 735 | *
|
---|
| 736 | * note: this function is not threads safe, you would have
|
---|
| 737 | * to redefine static variables with __thread
|
---|
| 738 | */
|
---|
[d7baee6] | 739 | static int
|
---|
| 740 | shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
|
---|
[90f5d64] | 741 | {
|
---|
| 742 | static keyfield_t *interbuffer = NULL;
|
---|
| 743 | static size_t intersize = 0;
|
---|
| 744 |
|
---|
[153a209] | 745 | static unsigned char *shm = NULL;
|
---|
[a7d2d78] | 746 | static ipcarg_t shm_id = 0;
|
---|
| 747 | static size_t shm_size;
|
---|
[90f5d64] | 748 |
|
---|
| 749 | int handled = 1;
|
---|
| 750 | int retval = 0;
|
---|
| 751 | viewport_t *vport = &viewports[vp];
|
---|
[d7baee6] | 752 | unsigned int x, y;
|
---|
[90f5d64] | 753 |
|
---|
| 754 | switch (IPC_GET_METHOD(*call)) {
|
---|
| 755 | case IPC_M_AS_AREA_SEND:
|
---|
| 756 | /* We accept one area for data interchange */
|
---|
[a7d2d78] | 757 | if (IPC_GET_ARG1(*call) == shm_id) {
|
---|
[2057572] | 758 | void *dest = as_get_mappable_page(IPC_GET_ARG2(*call));
|
---|
[a7d2d78] | 759 | shm_size = IPC_GET_ARG2(*call);
|
---|
[f8ddd17] | 760 | if (!ipc_answer_fast(callid, 0, (sysarg_t) dest, 0))
|
---|
[a7d2d78] | 761 | shm = dest;
|
---|
[90f5d64] | 762 | else
|
---|
[a7d2d78] | 763 | shm_id = 0;
|
---|
| 764 | if (shm[0] != 'P')
|
---|
[90f5d64] | 765 | while (1)
|
---|
| 766 | ;
|
---|
| 767 | return 1;
|
---|
| 768 | } else {
|
---|
| 769 | intersize = IPC_GET_ARG2(*call);
|
---|
[f8ddd17] | 770 | receive_comm_area(callid, call, (void *) &interbuffer);
|
---|
[90f5d64] | 771 | }
|
---|
| 772 | return 1;
|
---|
| 773 | case FB_PREPARE_SHM:
|
---|
[a7d2d78] | 774 | if (shm_id)
|
---|
[90f5d64] | 775 | retval = EBUSY;
|
---|
| 776 | else
|
---|
[a7d2d78] | 777 | shm_id = IPC_GET_ARG1(*call);
|
---|
[90f5d64] | 778 | break;
|
---|
| 779 |
|
---|
| 780 | case FB_DROP_SHM:
|
---|
[a7d2d78] | 781 | if (shm) {
|
---|
| 782 | as_area_destroy(shm);
|
---|
| 783 | shm = NULL;
|
---|
[90f5d64] | 784 | }
|
---|
[a7d2d78] | 785 | shm_id = 0;
|
---|
| 786 | break;
|
---|
| 787 |
|
---|
| 788 | case FB_SHM2PIXMAP:
|
---|
| 789 | if (!shm) {
|
---|
| 790 | retval = EINVAL;
|
---|
| 791 | break;
|
---|
| 792 | }
|
---|
| 793 | retval = shm2pixmap(shm, shm_size);
|
---|
[90f5d64] | 794 | break;
|
---|
| 795 | case FB_DRAW_PPM:
|
---|
[a7d2d78] | 796 | if (!shm) {
|
---|
[90f5d64] | 797 | retval = EINVAL;
|
---|
| 798 | break;
|
---|
| 799 | }
|
---|
| 800 | x = IPC_GET_ARG1(*call);
|
---|
| 801 | y = IPC_GET_ARG2(*call);
|
---|
| 802 | if (x > vport->width || y > vport->height) {
|
---|
| 803 | retval = EINVAL;
|
---|
| 804 | break;
|
---|
| 805 | }
|
---|
| 806 |
|
---|
[00bb6965] | 807 | ppm_draw(shm, shm_size, IPC_GET_ARG1(*call),
|
---|
[d7baee6] | 808 | IPC_GET_ARG2(*call), vport->width - x,
|
---|
| 809 | vport->height - y, (putpixel_cb_t)putpixel, vport);
|
---|
[90f5d64] | 810 | break;
|
---|
| 811 | case FB_DRAW_TEXT_DATA:
|
---|
| 812 | if (!interbuffer) {
|
---|
| 813 | retval = EINVAL;
|
---|
| 814 | break;
|
---|
| 815 | }
|
---|
[00bb6965] | 816 | if (intersize < vport->cols * vport->rows *
|
---|
| 817 | sizeof(*interbuffer)) {
|
---|
[90f5d64] | 818 | retval = EINVAL;
|
---|
| 819 | break;
|
---|
| 820 | }
|
---|
[bd02038] | 821 | draw_text_data(vport, interbuffer);
|
---|
[90f5d64] | 822 | break;
|
---|
| 823 | default:
|
---|
| 824 | handled = 0;
|
---|
| 825 | }
|
---|
| 826 |
|
---|
| 827 | if (handled)
|
---|
| 828 | ipc_answer_fast(callid, retval, 0, 0);
|
---|
| 829 | return handled;
|
---|
| 830 | }
|
---|
[83b1d61] | 831 |
|
---|
[d7baee6] | 832 | static void
|
---|
| 833 | copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap)
|
---|
[429acb9] | 834 | {
|
---|
[153a209] | 835 | int y;
|
---|
[429acb9] | 836 | int rowsize;
|
---|
| 837 | int tmp;
|
---|
[2ce520c] | 838 | int width = vport->width;
|
---|
| 839 | int height = vport->height;
|
---|
| 840 |
|
---|
| 841 | if (width + vport->x > screen.xres)
|
---|
| 842 | width = screen.xres - vport->x;
|
---|
| 843 | if (height + vport->y > screen.yres)
|
---|
| 844 | height = screen.yres - vport->y;
|
---|
| 845 |
|
---|
| 846 | rowsize = width * screen.pixelbytes;
|
---|
| 847 |
|
---|
[00bb6965] | 848 | for (y = 0; y < height; y++) {
|
---|
[d7baee6] | 849 | tmp = (vport->y + y) * screen.scanline +
|
---|
| 850 | vport->x * screen.pixelbytes;
|
---|
[00bb6965] | 851 | memcpy(pmap->data + rowsize * y, screen.fbaddress + tmp,
|
---|
| 852 | rowsize);
|
---|
[2ce520c] | 853 | }
|
---|
| 854 | }
|
---|
| 855 |
|
---|
| 856 | /** Save viewport to pixmap */
|
---|
[d7baee6] | 857 | static int
|
---|
| 858 | save_vp_to_pixmap(viewport_t *vport)
|
---|
[2ce520c] | 859 | {
|
---|
| 860 | int pm;
|
---|
| 861 | pixmap_t *pmap;
|
---|
[429acb9] | 862 |
|
---|
| 863 | pm = find_free_pixmap();
|
---|
| 864 | if (pm == -1)
|
---|
| 865 | return ELIMIT;
|
---|
| 866 |
|
---|
| 867 | pmap = &pixmaps[pm];
|
---|
| 868 | pmap->data = malloc(screen.pixelbytes * vport->width * vport->height);
|
---|
| 869 | if (!pmap->data)
|
---|
| 870 | return ENOMEM;
|
---|
| 871 |
|
---|
| 872 | pmap->width = vport->width;
|
---|
| 873 | pmap->height = vport->height;
|
---|
[2ce520c] | 874 |
|
---|
| 875 | copy_vp_to_pixmap(vport, pmap);
|
---|
[429acb9] | 876 |
|
---|
| 877 | return pm;
|
---|
| 878 | }
|
---|
| 879 |
|
---|
| 880 | /** Draw pixmap on screen
|
---|
| 881 | *
|
---|
| 882 | * @param vp Viewport to draw on
|
---|
| 883 | * @param pm Pixmap identifier
|
---|
| 884 | */
|
---|
| 885 | static int draw_pixmap(int vp, int pm)
|
---|
| 886 | {
|
---|
| 887 | pixmap_t *pmap = &pixmaps[pm];
|
---|
| 888 | viewport_t *vport = &viewports[vp];
|
---|
[153a209] | 889 | int y;
|
---|
[429acb9] | 890 | int tmp, srcrowsize;
|
---|
| 891 | int realwidth, realheight, realrowsize;
|
---|
[2ce520c] | 892 | int width = vport->width;
|
---|
| 893 | int height = vport->height;
|
---|
| 894 |
|
---|
| 895 | if (width + vport->x > screen.xres)
|
---|
| 896 | width = screen.xres - vport->x;
|
---|
| 897 | if (height + vport->y > screen.yres)
|
---|
| 898 | height = screen.yres - vport->y;
|
---|
[429acb9] | 899 |
|
---|
| 900 | if (!pmap->data)
|
---|
| 901 | return EINVAL;
|
---|
| 902 |
|
---|
[2ce520c] | 903 | realwidth = pmap->width <= width ? pmap->width : width;
|
---|
| 904 | realheight = pmap->height <= height ? pmap->height : height;
|
---|
[429acb9] | 905 |
|
---|
| 906 | srcrowsize = vport->width * screen.pixelbytes;
|
---|
| 907 | realrowsize = realwidth * screen.pixelbytes;
|
---|
| 908 |
|
---|
[d7baee6] | 909 | for (y = 0; y < realheight; y++) {
|
---|
| 910 | tmp = (vport->y + y) * screen.scanline +
|
---|
| 911 | vport->x * screen.pixelbytes;
|
---|
[00bb6965] | 912 | memcpy(screen.fbaddress + tmp, pmap->data + y * srcrowsize,
|
---|
| 913 | realrowsize);
|
---|
[429acb9] | 914 | }
|
---|
[6118e5f6] | 915 | return 0;
|
---|
[429acb9] | 916 | }
|
---|
| 917 |
|
---|
[1fd7700] | 918 | /** Tick animation one step forward */
|
---|
[d7baee6] | 919 | static void
|
---|
| 920 | anims_tick(void)
|
---|
[1fd7700] | 921 | {
|
---|
| 922 | int i;
|
---|
| 923 | static int counts = 0;
|
---|
| 924 |
|
---|
| 925 | /* Limit redrawing */
|
---|
[00bb6965] | 926 | counts = (counts + 1) % 8;
|
---|
[1fd7700] | 927 | if (counts)
|
---|
| 928 | return;
|
---|
| 929 |
|
---|
[d7baee6] | 930 | for (i = 0; i < MAX_ANIMATIONS; i++) {
|
---|
[00bb6965] | 931 | if (!animations[i].animlen || !animations[i].initialized ||
|
---|
| 932 | !animations[i].enabled)
|
---|
[1fd7700] | 933 | continue;
|
---|
[00bb6965] | 934 | draw_pixmap(animations[i].vp,
|
---|
| 935 | animations[i].pixmaps[animations[i].pos]);
|
---|
| 936 | animations[i].pos = (animations[i].pos + 1) %
|
---|
| 937 | animations[i].animlen;
|
---|
[1fd7700] | 938 | }
|
---|
| 939 | }
|
---|
| 940 |
|
---|
[2ce520c] | 941 |
|
---|
| 942 | static int pointer_x, pointer_y;
|
---|
[a3d2939] | 943 | static int pointer_shown, pointer_enabled;
|
---|
[2ce520c] | 944 | static int pointer_vport = -1;
|
---|
| 945 | static int pointer_pixmap = -1;
|
---|
| 946 |
|
---|
[d7baee6] | 947 | static void
|
---|
| 948 | mouse_show(void)
|
---|
[2ce520c] | 949 | {
|
---|
[d7baee6] | 950 | int i, j;
|
---|
[2ce520c] | 951 | int visibility;
|
---|
| 952 | int color;
|
---|
| 953 | int bytepos;
|
---|
| 954 |
|
---|
[a3d2939] | 955 | if (pointer_shown || !pointer_enabled)
|
---|
| 956 | return;
|
---|
| 957 |
|
---|
[2ce520c] | 958 | /* Save image under the cursor */
|
---|
| 959 | if (pointer_vport == -1) {
|
---|
[00bb6965] | 960 | pointer_vport = viewport_create(pointer_x, pointer_y,
|
---|
| 961 | pointer_width, pointer_height);
|
---|
[2ce520c] | 962 | if (pointer_vport < 0)
|
---|
| 963 | return;
|
---|
| 964 | } else {
|
---|
| 965 | viewports[pointer_vport].x = pointer_x;
|
---|
| 966 | viewports[pointer_vport].y = pointer_y;
|
---|
| 967 | }
|
---|
| 968 |
|
---|
| 969 | if (pointer_pixmap == -1)
|
---|
| 970 | pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]);
|
---|
| 971 | else
|
---|
[00bb6965] | 972 | copy_vp_to_pixmap(&viewports[pointer_vport],
|
---|
| 973 | &pixmaps[pointer_pixmap]);
|
---|
[2ce520c] | 974 |
|
---|
| 975 | /* Draw cursor */
|
---|
[00bb6965] | 976 | for (i = 0; i < pointer_height; i++)
|
---|
| 977 | for (j = 0; j < pointer_width; j++) {
|
---|
| 978 | bytepos = i * ((pointer_width - 1) / 8 + 1) + j / 8;
|
---|
[d7baee6] | 979 | visibility = pointer_mask_bits[bytepos] &
|
---|
| 980 | (1 << (j % 8));
|
---|
[2ce520c] | 981 | if (visibility) {
|
---|
[00bb6965] | 982 | color = pointer_bits[bytepos] & (1 << (j % 8))
|
---|
| 983 | ? 0 : 0xffffff;
|
---|
| 984 | if (pointer_x + j < screen.xres && pointer_y +
|
---|
| 985 | i < screen.yres)
|
---|
| 986 | putpixel(&viewports[0], pointer_x + j,
|
---|
[d7baee6] | 987 | pointer_y + i, color);
|
---|
[2ce520c] | 988 | }
|
---|
| 989 | }
|
---|
| 990 | pointer_shown = 1;
|
---|
| 991 | }
|
---|
| 992 |
|
---|
[d7baee6] | 993 | static void
|
---|
| 994 | mouse_hide(void)
|
---|
[2ce520c] | 995 | {
|
---|
| 996 | /* Restore image under the cursor */
|
---|
| 997 | if (pointer_shown) {
|
---|
| 998 | draw_pixmap(pointer_vport, pointer_pixmap);
|
---|
| 999 | pointer_shown = 0;
|
---|
| 1000 | }
|
---|
| 1001 | }
|
---|
| 1002 |
|
---|
[d7baee6] | 1003 | static void
|
---|
| 1004 | mouse_move(unsigned int x, unsigned int y)
|
---|
[2ce520c] | 1005 | {
|
---|
| 1006 | mouse_hide();
|
---|
| 1007 | pointer_x = x;
|
---|
| 1008 | pointer_y = y;
|
---|
| 1009 | mouse_show();
|
---|
| 1010 | }
|
---|
| 1011 |
|
---|
[d7baee6] | 1012 | static int
|
---|
| 1013 | anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
|
---|
[1fd7700] | 1014 | {
|
---|
| 1015 | int handled = 1;
|
---|
| 1016 | int retval = 0;
|
---|
| 1017 | int i,nvp;
|
---|
| 1018 | int newval;
|
---|
| 1019 |
|
---|
| 1020 | switch (IPC_GET_METHOD(*call)) {
|
---|
| 1021 | case FB_ANIM_CREATE:
|
---|
| 1022 | nvp = IPC_GET_ARG1(*call);
|
---|
| 1023 | if (nvp == -1)
|
---|
| 1024 | nvp = vp;
|
---|
[00bb6965] | 1025 | if (nvp >= MAX_VIEWPORTS || nvp < 0 ||
|
---|
| 1026 | !viewports[nvp].initialized) {
|
---|
[1fd7700] | 1027 | retval = EINVAL;
|
---|
| 1028 | break;
|
---|
| 1029 | }
|
---|
[00bb6965] | 1030 | for (i = 0; i < MAX_ANIMATIONS; i++) {
|
---|
| 1031 | if (!animations[i].initialized)
|
---|
[1fd7700] | 1032 | break;
|
---|
| 1033 | }
|
---|
| 1034 | if (i == MAX_ANIMATIONS) {
|
---|
| 1035 | retval = ELIMIT;
|
---|
| 1036 | break;
|
---|
| 1037 | }
|
---|
| 1038 | animations[i].initialized = 1;
|
---|
| 1039 | animations[i].animlen = 0;
|
---|
| 1040 | animations[i].pos = 0;
|
---|
| 1041 | animations[i].enabled = 0;
|
---|
| 1042 | animations[i].vp = nvp;
|
---|
| 1043 | retval = i;
|
---|
| 1044 | break;
|
---|
| 1045 | case FB_ANIM_DROP:
|
---|
| 1046 | i = IPC_GET_ARG1(*call);
|
---|
[153a209] | 1047 | if (i >= MAX_ANIMATIONS || i < 0) {
|
---|
[1fd7700] | 1048 | retval = EINVAL;
|
---|
| 1049 | break;
|
---|
| 1050 | }
|
---|
| 1051 | animations[i].initialized = 0;
|
---|
| 1052 | break;
|
---|
| 1053 | case FB_ANIM_ADDPIXMAP:
|
---|
| 1054 | i = IPC_GET_ARG1(*call);
|
---|
[00bb6965] | 1055 | if (i >= MAX_ANIMATIONS || i < 0 ||
|
---|
| 1056 | !animations[i].initialized) {
|
---|
[1fd7700] | 1057 | retval = EINVAL;
|
---|
| 1058 | break;
|
---|
| 1059 | }
|
---|
| 1060 | if (animations[i].animlen == MAX_ANIM_LEN) {
|
---|
| 1061 | retval = ELIMIT;
|
---|
| 1062 | break;
|
---|
| 1063 | }
|
---|
| 1064 | newval = IPC_GET_ARG2(*call);
|
---|
[00bb6965] | 1065 | if (newval < 0 || newval > MAX_PIXMAPS ||
|
---|
| 1066 | !pixmaps[newval].data) {
|
---|
[1fd7700] | 1067 | retval = EINVAL;
|
---|
| 1068 | break;
|
---|
| 1069 | }
|
---|
| 1070 | animations[i].pixmaps[animations[i].animlen++] = newval;
|
---|
| 1071 | break;
|
---|
| 1072 | case FB_ANIM_CHGVP:
|
---|
| 1073 | i = IPC_GET_ARG1(*call);
|
---|
| 1074 | if (i >= MAX_ANIMATIONS || i < 0) {
|
---|
| 1075 | retval = EINVAL;
|
---|
| 1076 | break;
|
---|
| 1077 | }
|
---|
| 1078 | nvp = IPC_GET_ARG2(*call);
|
---|
| 1079 | if (nvp == -1)
|
---|
| 1080 | nvp = vp;
|
---|
[00bb6965] | 1081 | if (nvp >= MAX_VIEWPORTS || nvp < 0 ||
|
---|
| 1082 | !viewports[nvp].initialized) {
|
---|
[1fd7700] | 1083 | retval = EINVAL;
|
---|
| 1084 | break;
|
---|
| 1085 | }
|
---|
| 1086 | animations[i].vp = nvp;
|
---|
| 1087 | break;
|
---|
| 1088 | case FB_ANIM_START:
|
---|
| 1089 | case FB_ANIM_STOP:
|
---|
| 1090 | i = IPC_GET_ARG1(*call);
|
---|
| 1091 | if (i >= MAX_ANIMATIONS || i < 0) {
|
---|
| 1092 | retval = EINVAL;
|
---|
| 1093 | break;
|
---|
| 1094 | }
|
---|
| 1095 | newval = (IPC_GET_METHOD(*call) == FB_ANIM_START);
|
---|
| 1096 | if (newval ^ animations[i].enabled) {
|
---|
| 1097 | animations[i].enabled = newval;
|
---|
| 1098 | anims_enabled += newval ? 1 : -1;
|
---|
| 1099 | }
|
---|
| 1100 | break;
|
---|
| 1101 | default:
|
---|
| 1102 | handled = 0;
|
---|
| 1103 | }
|
---|
| 1104 | if (handled)
|
---|
| 1105 | ipc_answer_fast(callid, retval, 0, 0);
|
---|
| 1106 | return handled;
|
---|
| 1107 | }
|
---|
| 1108 |
|
---|
[429acb9] | 1109 | /** Handler for messages concerning pixmap handling */
|
---|
[d7baee6] | 1110 | static int
|
---|
| 1111 | pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
|
---|
[429acb9] | 1112 | {
|
---|
| 1113 | int handled = 1;
|
---|
| 1114 | int retval = 0;
|
---|
| 1115 | int i,nvp;
|
---|
| 1116 |
|
---|
| 1117 | switch (IPC_GET_METHOD(*call)) {
|
---|
| 1118 | case FB_VP_DRAW_PIXMAP:
|
---|
| 1119 | nvp = IPC_GET_ARG1(*call);
|
---|
| 1120 | if (nvp == -1)
|
---|
| 1121 | nvp = vp;
|
---|
[00bb6965] | 1122 | if (nvp < 0 || nvp >= MAX_VIEWPORTS ||
|
---|
| 1123 | !viewports[nvp].initialized) {
|
---|
[429acb9] | 1124 | retval = EINVAL;
|
---|
| 1125 | break;
|
---|
| 1126 | }
|
---|
| 1127 | i = IPC_GET_ARG2(*call);
|
---|
| 1128 | retval = draw_pixmap(nvp, i);
|
---|
| 1129 | break;
|
---|
| 1130 | case FB_VP2PIXMAP:
|
---|
| 1131 | nvp = IPC_GET_ARG1(*call);
|
---|
| 1132 | if (nvp == -1)
|
---|
| 1133 | nvp = vp;
|
---|
[00bb6965] | 1134 | if (nvp < 0 || nvp >= MAX_VIEWPORTS ||
|
---|
| 1135 | !viewports[nvp].initialized)
|
---|
[429acb9] | 1136 | retval = EINVAL;
|
---|
| 1137 | else
|
---|
[2ce520c] | 1138 | retval = save_vp_to_pixmap(&viewports[nvp]);
|
---|
[429acb9] | 1139 | break;
|
---|
| 1140 | case FB_DROP_PIXMAP:
|
---|
| 1141 | i = IPC_GET_ARG1(*call);
|
---|
| 1142 | if (i >= MAX_PIXMAPS) {
|
---|
| 1143 | retval = EINVAL;
|
---|
| 1144 | break;
|
---|
| 1145 | }
|
---|
| 1146 | if (pixmaps[i].data) {
|
---|
| 1147 | free(pixmaps[i].data);
|
---|
| 1148 | pixmaps[i].data = NULL;
|
---|
| 1149 | }
|
---|
| 1150 | break;
|
---|
| 1151 | default:
|
---|
| 1152 | handled = 0;
|
---|
| 1153 | }
|
---|
| 1154 |
|
---|
| 1155 | if (handled)
|
---|
| 1156 | ipc_answer_fast(callid, retval, 0, 0);
|
---|
| 1157 | return handled;
|
---|
| 1158 |
|
---|
| 1159 | }
|
---|
| 1160 |
|
---|
[1180a88e] | 1161 | /** Function for handling connections to FB
|
---|
| 1162 | *
|
---|
| 1163 | */
|
---|
[d7baee6] | 1164 | static void
|
---|
| 1165 | fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
|
---|
[a2ae4f4] | 1166 | {
|
---|
| 1167 | ipc_callid_t callid;
|
---|
| 1168 | ipc_call_t call;
|
---|
| 1169 | int retval;
|
---|
| 1170 | int i;
|
---|
| 1171 | unsigned int row,col;
|
---|
| 1172 | char c;
|
---|
[88c3151] | 1173 |
|
---|
[a2ae4f4] | 1174 | int vp = 0;
|
---|
[88c3151] | 1175 | viewport_t *vport = &viewports[0];
|
---|
[afa6e74] | 1176 |
|
---|
[a2ae4f4] | 1177 | if (client_connected) {
|
---|
| 1178 | ipc_answer_fast(iid, ELIMIT, 0,0);
|
---|
| 1179 | return;
|
---|
| 1180 | }
|
---|
[88c3151] | 1181 | client_connected = 1;
|
---|
[a2ae4f4] | 1182 | ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
|
---|
[afa6e74] | 1183 |
|
---|
[a2ae4f4] | 1184 | while (1) {
|
---|
[1fd7700] | 1185 | if (vport->cursor_active || anims_enabled)
|
---|
[d7baee6] | 1186 | callid = async_get_call_timeout(&call, 250000);
|
---|
[d3f2cad] | 1187 | else
|
---|
| 1188 | callid = async_get_call(&call);
|
---|
| 1189 |
|
---|
[d552ab9] | 1190 | mouse_hide();
|
---|
[49d072e] | 1191 | if (!callid) {
|
---|
[bd02038] | 1192 | cursor_blink(vport);
|
---|
[1fd7700] | 1193 | anims_tick();
|
---|
[a3d2939] | 1194 | mouse_show();
|
---|
[49d072e] | 1195 | continue;
|
---|
| 1196 | }
|
---|
[90f5d64] | 1197 | if (shm_handle(callid, &call, vp))
|
---|
| 1198 | continue;
|
---|
[429acb9] | 1199 | if (pixmap_handle(callid, &call, vp))
|
---|
| 1200 | continue;
|
---|
[1fd7700] | 1201 | if (anim_handle(callid, &call, vp))
|
---|
| 1202 | continue;
|
---|
[90f5d64] | 1203 |
|
---|
[a2ae4f4] | 1204 | switch (IPC_GET_METHOD(call)) {
|
---|
| 1205 | case IPC_M_PHONE_HUNGUP:
|
---|
| 1206 | client_connected = 0;
|
---|
| 1207 | /* cleanup other viewports */
|
---|
[00bb6965] | 1208 | for (i = 1; i < MAX_VIEWPORTS; i++)
|
---|
[88c3151] | 1209 | vport->initialized = 0;
|
---|
[a2ae4f4] | 1210 | return; /* Exit thread */
|
---|
[83b1d61] | 1211 |
|
---|
[a2ae4f4] | 1212 | case FB_PUTCHAR:
|
---|
[d530237a] | 1213 | case FB_TRANS_PUTCHAR:
|
---|
[a2ae4f4] | 1214 | c = IPC_GET_ARG1(call);
|
---|
| 1215 | row = IPC_GET_ARG2(call);
|
---|
| 1216 | col = IPC_GET_ARG3(call);
|
---|
[88c3151] | 1217 | if (row >= vport->rows || col >= vport->cols) {
|
---|
[a2ae4f4] | 1218 | retval = EINVAL;
|
---|
| 1219 | break;
|
---|
| 1220 | }
|
---|
[d7baee6] | 1221 | ipc_answer_fast(callid, 0, 0, 0);
|
---|
[88c3151] | 1222 |
|
---|
[00bb6965] | 1223 | draw_char(vport, c, row, col, vport->style,
|
---|
| 1224 | IPC_GET_METHOD(call) == FB_TRANS_PUTCHAR);
|
---|
[a2ae4f4] | 1225 | continue; /* msg already answered */
|
---|
| 1226 | case FB_CLEAR:
|
---|
[bd02038] | 1227 | clear_port(vport);
|
---|
| 1228 | cursor_print(vport);
|
---|
[a2ae4f4] | 1229 | retval = 0;
|
---|
| 1230 | break;
|
---|
[88c3151] | 1231 | case FB_CURSOR_GOTO:
|
---|
| 1232 | row = IPC_GET_ARG1(call);
|
---|
| 1233 | col = IPC_GET_ARG2(call);
|
---|
| 1234 | if (row >= vport->rows || col >= vport->cols) {
|
---|
| 1235 | retval = EINVAL;
|
---|
| 1236 | break;
|
---|
| 1237 | }
|
---|
| 1238 | retval = 0;
|
---|
[bd02038] | 1239 | cursor_hide(vport);
|
---|
[88c3151] | 1240 | vport->cur_col = col;
|
---|
| 1241 | vport->cur_row = row;
|
---|
[bd02038] | 1242 | cursor_print(vport);
|
---|
[88c3151] | 1243 | break;
|
---|
| 1244 | case FB_CURSOR_VISIBILITY:
|
---|
[bd02038] | 1245 | cursor_hide(vport);
|
---|
[49d072e] | 1246 | vport->cursor_active = IPC_GET_ARG1(call);
|
---|
[bd02038] | 1247 | cursor_print(vport);
|
---|
[88c3151] | 1248 | retval = 0;
|
---|
| 1249 | break;
|
---|
[a2ae4f4] | 1250 | case FB_GET_CSIZE:
|
---|
[88c3151] | 1251 | ipc_answer_fast(callid, 0, vport->rows, vport->cols);
|
---|
| 1252 | continue;
|
---|
| 1253 | case FB_SCROLL:
|
---|
| 1254 | i = IPC_GET_ARG1(call);
|
---|
| 1255 | if (i > vport->rows || i < (- (int)vport->rows)) {
|
---|
| 1256 | retval = EINVAL;
|
---|
| 1257 | break;
|
---|
| 1258 | }
|
---|
[bd02038] | 1259 | cursor_hide(vport);
|
---|
| 1260 | scroll_port(vport, i*FONT_SCANLINES);
|
---|
| 1261 | cursor_print(vport);
|
---|
[88c3151] | 1262 | retval = 0;
|
---|
| 1263 | break;
|
---|
[e92aabf] | 1264 | case FB_VIEWPORT_DB:
|
---|
| 1265 | /* Enable double buffering */
|
---|
| 1266 | i = IPC_GET_ARG1(call);
|
---|
| 1267 | if (i == -1)
|
---|
| 1268 | i = vp;
|
---|
| 1269 | if (i < 0 || i >= MAX_VIEWPORTS) {
|
---|
| 1270 | retval = EINVAL;
|
---|
| 1271 | break;
|
---|
| 1272 | }
|
---|
| 1273 | if (! viewports[i].initialized ) {
|
---|
| 1274 | retval = EADDRNOTAVAIL;
|
---|
| 1275 | break;
|
---|
| 1276 | }
|
---|
| 1277 | viewports[i].dboffset = 0;
|
---|
| 1278 | if (IPC_GET_ARG2(call) == 1 && !viewports[i].dbdata)
|
---|
[00bb6965] | 1279 | viewports[i].dbdata = malloc(screen.pixelbytes
|
---|
| 1280 | * viewports[i].width *
|
---|
| 1281 | viewports[i].height);
|
---|
| 1282 | else if (IPC_GET_ARG2(call) == 0 &&
|
---|
| 1283 | viewports[i].dbdata) {
|
---|
[e92aabf] | 1284 | free(viewports[i].dbdata);
|
---|
| 1285 | viewports[i].dbdata = NULL;
|
---|
| 1286 | }
|
---|
| 1287 | retval = 0;
|
---|
| 1288 | break;
|
---|
[88c3151] | 1289 | case FB_VIEWPORT_SWITCH:
|
---|
| 1290 | i = IPC_GET_ARG1(call);
|
---|
| 1291 | if (i < 0 || i >= MAX_VIEWPORTS) {
|
---|
| 1292 | retval = EINVAL;
|
---|
| 1293 | break;
|
---|
| 1294 | }
|
---|
| 1295 | if (! viewports[i].initialized ) {
|
---|
| 1296 | retval = EADDRNOTAVAIL;
|
---|
| 1297 | break;
|
---|
| 1298 | }
|
---|
[bd02038] | 1299 | cursor_hide(vport);
|
---|
[88c3151] | 1300 | vp = i;
|
---|
| 1301 | vport = &viewports[vp];
|
---|
[bd02038] | 1302 | cursor_print(vport);
|
---|
[88c3151] | 1303 | retval = 0;
|
---|
| 1304 | break;
|
---|
| 1305 | case FB_VIEWPORT_CREATE:
|
---|
| 1306 | retval = viewport_create(IPC_GET_ARG1(call) >> 16,
|
---|
[d7baee6] | 1307 | IPC_GET_ARG1(call) & 0xffff,
|
---|
| 1308 | IPC_GET_ARG2(call) >> 16,
|
---|
| 1309 | IPC_GET_ARG2(call) & 0xffff);
|
---|
[88c3151] | 1310 | break;
|
---|
| 1311 | case FB_VIEWPORT_DELETE:
|
---|
| 1312 | i = IPC_GET_ARG1(call);
|
---|
| 1313 | if (i < 0 || i >= MAX_VIEWPORTS) {
|
---|
| 1314 | retval = EINVAL;
|
---|
| 1315 | break;
|
---|
| 1316 | }
|
---|
| 1317 | if (! viewports[i].initialized ) {
|
---|
| 1318 | retval = EADDRNOTAVAIL;
|
---|
| 1319 | break;
|
---|
| 1320 | }
|
---|
| 1321 | viewports[i].initialized = 0;
|
---|
[e92aabf] | 1322 | if (viewports[i].dbdata) {
|
---|
| 1323 | free(viewports[i].dbdata);
|
---|
| 1324 | viewports[i].dbdata = NULL;
|
---|
| 1325 | }
|
---|
[88c3151] | 1326 | retval = 0;
|
---|
| 1327 | break;
|
---|
| 1328 | case FB_SET_STYLE:
|
---|
[6b5111a] | 1329 | vport->style.fg_color = IPC_GET_ARG1(call);
|
---|
| 1330 | vport->style.bg_color = IPC_GET_ARG2(call);
|
---|
[88c3151] | 1331 | retval = 0;
|
---|
| 1332 | break;
|
---|
| 1333 | case FB_GET_RESOLUTION:
|
---|
| 1334 | ipc_answer_fast(callid, 0, screen.xres,screen.yres);
|
---|
[a2ae4f4] | 1335 | continue;
|
---|
[830ac99] | 1336 | case FB_POINTER_MOVE:
|
---|
[a3d2939] | 1337 | pointer_enabled = 1;
|
---|
[2ce520c] | 1338 | mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
|
---|
[153a209] | 1339 | retval = 0;
|
---|
[830ac99] | 1340 | break;
|
---|
[a2ae4f4] | 1341 | default:
|
---|
| 1342 | retval = ENOENT;
|
---|
| 1343 | }
|
---|
[d7baee6] | 1344 | ipc_answer_fast(callid,retval, 0, 0);
|
---|
[a2ae4f4] | 1345 | }
|
---|
[afa6e74] | 1346 | }
|
---|
| 1347 |
|
---|
[1180a88e] | 1348 | /** Initialization of framebuffer */
|
---|
[d7baee6] | 1349 | int
|
---|
| 1350 | fb_init(void)
|
---|
[a2ae4f4] | 1351 | {
|
---|
[bf9afa07] | 1352 | void *fb_ph_addr;
|
---|
[da0c91e7] | 1353 | unsigned int fb_width;
|
---|
| 1354 | unsigned int fb_height;
|
---|
| 1355 | unsigned int fb_scanline;
|
---|
[2bc137c2] | 1356 | unsigned int fb_visual;
|
---|
| 1357 | bool fb_invert_colors;
|
---|
[bf9afa07] | 1358 | void *fb_addr;
|
---|
| 1359 | size_t asz;
|
---|
[afa6e74] | 1360 |
|
---|
[da0c91e7] | 1361 | async_set_client_connection(fb_client_connection);
|
---|
| 1362 |
|
---|
[775df25] | 1363 | fb_ph_addr = (void *) sysinfo_value("fb.address.physical");
|
---|
| 1364 | fb_width = sysinfo_value("fb.width");
|
---|
| 1365 | fb_height = sysinfo_value("fb.height");
|
---|
| 1366 | fb_scanline = sysinfo_value("fb.scanline");
|
---|
[2bc137c2] | 1367 | fb_visual = sysinfo_value("fb.visual");
|
---|
[775df25] | 1368 | fb_invert_colors = sysinfo_value("fb.invert-colors");
|
---|
[a2ae4f4] | 1369 |
|
---|
[2bc137c2] | 1370 | asz = fb_scanline * fb_height;
|
---|
[2057572] | 1371 | fb_addr = as_get_mappable_page(asz);
|
---|
[a2ae4f4] | 1372 |
|
---|
[00bb6965] | 1373 | physmem_map(fb_ph_addr, fb_addr, ALIGN_UP(asz, PAGE_SIZE) >>
|
---|
| 1374 | PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE);
|
---|
[afa6e74] | 1375 |
|
---|
[f8ddd17] | 1376 | if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual,
|
---|
| 1377 | fb_invert_colors))
|
---|
[2bc137c2] | 1378 | return 0;
|
---|
| 1379 |
|
---|
| 1380 | return -1;
|
---|
[a2ae4f4] | 1381 | }
|
---|
[da0c91e7] | 1382 |
|
---|
[ce5bcb4] | 1383 | /**
|
---|
| 1384 | * @}
|
---|
| 1385 | */
|
---|