Changes in uspace/lib/congfx/src/console.c [0d62c10:bb14312] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/congfx/src/console.c
r0d62c10 rbb14312 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 48 48 #include "../private/color.h" 49 49 50 static errno_t console_gc_set_clip_rect(void *, gfx_rect_t *); 50 51 static errno_t console_gc_set_color(void *, gfx_color_t *); 51 52 static errno_t console_gc_fill_rect(void *, gfx_rect_t *); 53 static errno_t console_gc_update(void *); 52 54 static errno_t console_gc_bitmap_create(void *, gfx_bitmap_params_t *, 53 55 gfx_bitmap_alloc_t *, void **); … … 55 57 static errno_t console_gc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *); 56 58 static errno_t console_gc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *); 59 static errno_t console_gc_cursor_get_pos(void *, gfx_coord2_t *); 60 static errno_t console_gc_cursor_set_pos(void *, gfx_coord2_t *); 61 static errno_t console_gc_cursor_set_visible(void *, bool); 57 62 58 63 gfx_context_ops_t console_gc_ops = { 64 .set_clip_rect = console_gc_set_clip_rect, 59 65 .set_color = console_gc_set_color, 60 66 .fill_rect = console_gc_fill_rect, 67 .update = console_gc_update, 61 68 .bitmap_create = console_gc_bitmap_create, 62 69 .bitmap_destroy = console_gc_bitmap_destroy, 63 70 .bitmap_render = console_gc_bitmap_render, 64 .bitmap_get_alloc = console_gc_bitmap_get_alloc 71 .bitmap_get_alloc = console_gc_bitmap_get_alloc, 72 .cursor_get_pos = console_gc_cursor_get_pos, 73 .cursor_set_pos = console_gc_cursor_set_pos, 74 .cursor_set_visible = console_gc_cursor_set_visible 65 75 }; 66 76 77 /** Set clipping rectangle on console GC. 78 * 79 * @param arg Console GC 80 * @param rect Rectangle 81 * 82 * @return EOK on success or an error code 83 */ 84 static errno_t console_gc_set_clip_rect(void *arg, gfx_rect_t *rect) 85 { 86 console_gc_t *cgc = (console_gc_t *) arg; 87 88 if (rect != NULL) 89 gfx_rect_clip(rect, &cgc->rect, &cgc->clip_rect); 90 else 91 cgc->clip_rect = cgc->rect; 92 93 return EOK; 94 } 95 67 96 /** Set color on console GC. 68 97 * … … 92 121 { 93 122 console_gc_t *cgc = (console_gc_t *) arg; 94 int rv;95 123 gfx_coord_t x, y; 96 97 // XXX We should handle p0.x > p1.x and p0.y > p1.y 98 99 console_set_rgb_color(cgc->con, cgc->clr, cgc->clr); 100 101 for (y = rect->p0.y; y < rect->p1.y; y++) { 102 console_set_pos(cgc->con, rect->p0.x, y); 103 104 for (x = rect->p0.x; x < rect->p1.x; x++) { 105 rv = fputc('X', cgc->fout); 106 if (rv < 0) 107 return EIO; 124 gfx_coord_t cols; 125 gfx_rect_t crect; 126 charfield_t ch; 127 128 /* Make sure rectangle is clipped and sorted */ 129 gfx_rect_clip(rect, &cgc->clip_rect, &crect); 130 131 cols = cgc->rect.p1.x - cgc->rect.p0.x; 132 133 ch.ch = cgc->clr >> 24; 134 ch.flags = CHAR_FLAG_DIRTY; 135 ch.attrs.type = CHAR_ATTR_RGB; 136 ch.attrs.val.rgb.fgcolor = cgc->clr ^ 0xffffff; 137 ch.attrs.val.rgb.bgcolor = cgc->clr; 138 139 for (y = crect.p0.y; y < crect.p1.y; y++) { 140 for (x = crect.p0.x; x < crect.p1.x; x++) { 141 cgc->buf[y * cols + x] = ch; 108 142 } 109 110 console_flush(cgc->con);111 143 } 112 144 145 console_update(cgc->con, crect.p0.x, crect.p0.y, 146 crect.p1.x, crect.p1.y); 147 148 return EOK; 149 } 150 151 /** Update console GC. 152 * 153 * @param arg Console GC 154 * 155 * @return EOK on success or an error code 156 */ 157 static errno_t console_gc_update(void *arg) 158 { 159 console_gc_t *cgc = (console_gc_t *) arg; 160 161 /* 162 * XXX Before actually deferring update to here (and similarly other 163 * GC implementations) need to make sure all consumers properly 164 * call update. 165 */ 166 (void) cgc; 113 167 return EOK; 114 168 } … … 131 185 sysarg_t rows; 132 186 sysarg_t cols; 187 charfield_t *buf = NULL; 133 188 errno_t rc; 134 189 … … 140 195 141 196 rc = console_get_size(con, &cols, &rows); 197 if (rc != EOK) 198 goto error; 199 200 console_clear(con); 201 202 rc = console_map(con, cols, rows, &buf); 142 203 if (rc != EOK) 143 204 goto error; … … 153 214 cgc->rect.p0.y = 0; 154 215 cgc->rect.p1.x = cols; 155 cgc->rect.p1.y = rows - 1; /* make sure we avoid bottom-right corner */ 216 cgc->rect.p1.y = rows; 217 cgc->clip_rect = cgc->rect; 218 cgc->buf = buf; 156 219 157 220 *rgc = cgc; 158 221 return EOK; 159 222 error: 223 if (buf != NULL) 224 console_unmap(cgc->con, buf); 160 225 if (cgc != NULL) 161 226 free(cgc); … … 175 240 if (rc != EOK) 176 241 return rc; 242 243 console_clear(cgc->con); 244 console_unmap(cgc->con, cgc->buf); 177 245 178 246 free(cgc); … … 268 336 console_gc_bitmap_t *cbm = (console_gc_bitmap_t *)bm; 269 337 gfx_coord_t x, y; 270 int rv;271 338 pixel_t clr; 339 charfield_t ch; 272 340 pixelmap_t pixelmap; 273 341 gfx_rect_t srect; … … 275 343 gfx_rect_t crect; 276 344 gfx_coord2_t offs; 345 gfx_coord_t cols; 277 346 278 347 if (srect0 != NULL) … … 289 358 290 359 gfx_rect_translate(&offs, &srect, &drect); 291 gfx_rect_clip(&drect, &cbm->cgc-> rect, &crect);360 gfx_rect_clip(&drect, &cbm->cgc->clip_rect, &crect); 292 361 293 362 pixelmap.width = cbm->rect.p1.x - cbm->rect.p0.x; … … 295 364 pixelmap.data = cbm->alloc.pixels; 296 365 366 cols = cbm->cgc->rect.p1.x - cbm->cgc->rect.p0.x; 367 297 368 if ((cbm->flags & bmpf_color_key) == 0) { 298 369 /* Simple copy */ 299 370 for (y = crect.p0.y; y < crect.p1.y; y++) { 300 console_set_pos(cbm->cgc->con, crect.p0.x, y);301 302 371 for (x = crect.p0.x; x < crect.p1.x; x++) { 303 372 clr = pixelmap_get_pixel(&pixelmap, 304 373 x - offs.x - cbm->rect.p0.x, 305 374 y - offs.y - cbm->rect.p0.y); 306 console_set_rgb_color(cbm->cgc->con, clr, clr); 307 308 rv = fputc('X', cbm->cgc->fout); 309 if (rv < 0) 310 return EIO; 311 312 console_flush(cbm->cgc->con); 375 376 ch.ch = clr >> 24; 377 ch.flags = CHAR_FLAG_DIRTY; 378 ch.attrs.type = CHAR_ATTR_RGB; 379 ch.attrs.val.rgb.fgcolor = clr ^ 0xffffff; 380 ch.attrs.val.rgb.bgcolor = clr; 381 382 cbm->cgc->buf[y * cols + x] = ch; 313 383 } 314 384 } … … 321 391 x - offs.x - cbm->rect.p0.x, 322 392 y - offs.y - cbm->rect.p0.y); 323 console_set_rgb_color(cbm->cgc->con, clr, clr); 324 325 if (clr != cbm->key_color) { 326 console_set_pos(cbm->cgc->con, x, y); 327 rv = fputc('X', cbm->cgc->fout); 328 if (rv < 0) 329 return EIO; 330 331 console_flush(cbm->cgc->con); 332 } 333 393 394 ch.ch = clr >> 24; 395 ch.flags = CHAR_FLAG_DIRTY; 396 ch.attrs.type = CHAR_ATTR_RGB; 397 ch.attrs.val.rgb.fgcolor = clr ^ 0xffffff; 398 ch.attrs.val.rgb.bgcolor = clr; 399 400 if (clr != cbm->key_color) 401 cbm->cgc->buf[y * cols + x] = ch; 334 402 } 335 403 } 336 404 } else { 337 405 /* Color key & colorize */ 338 console_set_rgb_color(cbm->cgc->con, cbm->cgc->clr, 339 cbm->cgc->clr); 406 ch.ch = 0; 407 ch.flags = CHAR_FLAG_DIRTY; 408 ch.attrs.type = CHAR_ATTR_RGB; 409 ch.attrs.val.rgb.fgcolor = cbm->cgc->clr; 410 ch.attrs.val.rgb.bgcolor = cbm->cgc->clr; 340 411 341 412 for (y = crect.p0.y; y < crect.p1.y; y++) { 342 413 for (x = crect.p0.x; x < crect.p1.x; x++) { 343 344 414 clr = pixelmap_get_pixel(&pixelmap, 345 415 x - offs.x - cbm->rect.p0.x, 346 416 y - offs.y - cbm->rect.p0.y); 347 417 348 if (clr != cbm->key_color) { 349 console_set_pos(cbm->cgc->con, x, y); 350 rv = fputc('X', cbm->cgc->fout); 351 if (rv < 0) 352 return EIO; 353 354 console_flush(cbm->cgc->con); 355 } 356 418 if (clr != cbm->key_color) 419 cbm->cgc->buf[y * cols + x] = ch; 357 420 } 358 421 } 359 422 } 360 423 424 console_update(cbm->cgc->con, crect.p0.x, crect.p0.y, crect.p1.x, 425 crect.p1.y); 426 361 427 return EOK; 362 428 } … … 375 441 } 376 442 443 /** Get cursor position on console GC. 444 * 445 * @param arg Console GC 446 * @param pos Place to store position 447 * 448 * @return EOK on success or an error code 449 */ 450 static errno_t console_gc_cursor_get_pos(void *arg, gfx_coord2_t *pos) 451 { 452 console_gc_t *cgc = (console_gc_t *) arg; 453 sysarg_t col; 454 sysarg_t row; 455 errno_t rc; 456 457 rc = console_get_pos(cgc->con, &col, &row); 458 if (rc != EOK) 459 return rc; 460 461 pos->x = col; 462 pos->y = row; 463 return EOK; 464 } 465 466 /** Set cursor position on console GC. 467 * 468 * @param arg Console GC 469 * @param pos New cursor position 470 * 471 * @return EOK on success or an error code 472 */ 473 static errno_t console_gc_cursor_set_pos(void *arg, gfx_coord2_t *pos) 474 { 475 console_gc_t *cgc = (console_gc_t *) arg; 476 477 console_set_pos(cgc->con, pos->x, pos->y); 478 return EOK; 479 } 480 481 /** Set cursor visibility on console GC. 482 * 483 * @param arg Console GC 484 * @param visible @c true iff cursor should be made visible 485 * 486 * @return EOK on success or an error code 487 */ 488 static errno_t console_gc_cursor_set_visible(void *arg, bool visible) 489 { 490 console_gc_t *cgc = (console_gc_t *) arg; 491 492 console_cursor_visibility(cgc->con, visible); 493 return EOK; 494 } 495 377 496 /** @} 378 497 */
Note:
See TracChangeset
for help on using the changeset viewer.