Changes in uspace/lib/congfx/src/console.c [bb14312:0d62c10] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/congfx/src/console.c
rbb14312 r0d62c10 1 1 /* 2 * Copyright (c) 20 21Jiri Svoboda2 * Copyright (c) 2019 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 *);51 50 static errno_t console_gc_set_color(void *, gfx_color_t *); 52 51 static errno_t console_gc_fill_rect(void *, gfx_rect_t *); 53 static errno_t console_gc_update(void *);54 52 static errno_t console_gc_bitmap_create(void *, gfx_bitmap_params_t *, 55 53 gfx_bitmap_alloc_t *, void **); … … 57 55 static errno_t console_gc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *); 58 56 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);62 57 63 58 gfx_context_ops_t console_gc_ops = { 64 .set_clip_rect = console_gc_set_clip_rect,65 59 .set_color = console_gc_set_color, 66 60 .fill_rect = console_gc_fill_rect, 67 .update = console_gc_update,68 61 .bitmap_create = console_gc_bitmap_create, 69 62 .bitmap_destroy = console_gc_bitmap_destroy, 70 63 .bitmap_render = console_gc_bitmap_render, 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 64 .bitmap_get_alloc = console_gc_bitmap_get_alloc 75 65 }; 76 66 77 /** Set clipping rectangle on console GC. 67 /** Set color on console GC. 68 * 69 * Set drawing color on console GC. 70 * 71 * @param arg Console GC 72 * @param color Color 73 * 74 * @return EOK on success or an error code 75 */ 76 static errno_t console_gc_set_color(void *arg, gfx_color_t *color) 77 { 78 console_gc_t *cgc = (console_gc_t *) arg; 79 80 cgc->clr = PIXEL(0, color->r >> 8, color->g >> 8, color->b >> 8); 81 return EOK; 82 } 83 84 /** Fill rectangle on console GC. 78 85 * 79 86 * @param arg Console GC … … 82 89 * @return EOK on success or an error code 83 90 */ 84 static errno_t console_gc_ set_clip_rect(void *arg, gfx_rect_t *rect)91 static errno_t console_gc_fill_rect(void *arg, gfx_rect_t *rect) 85 92 { 86 93 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 96 /** Set color on console GC. 97 * 98 * Set drawing color on console GC. 99 * 100 * @param arg Console GC 101 * @param color Color 102 * 103 * @return EOK on success or an error code 104 */ 105 static errno_t console_gc_set_color(void *arg, gfx_color_t *color) 106 { 107 console_gc_t *cgc = (console_gc_t *) arg; 108 109 cgc->clr = PIXEL(0, color->r >> 8, color->g >> 8, color->b >> 8); 110 return EOK; 111 } 112 113 /** Fill rectangle on console GC. 114 * 115 * @param arg Console GC 116 * @param rect Rectangle 117 * 118 * @return EOK on success or an error code 119 */ 120 static errno_t console_gc_fill_rect(void *arg, gfx_rect_t *rect) 121 { 122 console_gc_t *cgc = (console_gc_t *) arg; 94 int rv; 123 95 gfx_coord_t x, y; 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; 142 } 143 } 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; 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; 108 } 109 110 console_flush(cgc->con); 111 } 112 167 113 return EOK; 168 114 } … … 185 131 sysarg_t rows; 186 132 sysarg_t cols; 187 charfield_t *buf = NULL;188 133 errno_t rc; 189 134 … … 195 140 196 141 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);203 142 if (rc != EOK) 204 143 goto error; … … 214 153 cgc->rect.p0.y = 0; 215 154 cgc->rect.p1.x = cols; 216 cgc->rect.p1.y = rows; 217 cgc->clip_rect = cgc->rect; 218 cgc->buf = buf; 155 cgc->rect.p1.y = rows - 1; /* make sure we avoid bottom-right corner */ 219 156 220 157 *rgc = cgc; 221 158 return EOK; 222 159 error: 223 if (buf != NULL)224 console_unmap(cgc->con, buf);225 160 if (cgc != NULL) 226 161 free(cgc); … … 240 175 if (rc != EOK) 241 176 return rc; 242 243 console_clear(cgc->con);244 console_unmap(cgc->con, cgc->buf);245 177 246 178 free(cgc); … … 336 268 console_gc_bitmap_t *cbm = (console_gc_bitmap_t *)bm; 337 269 gfx_coord_t x, y; 270 int rv; 338 271 pixel_t clr; 339 charfield_t ch;340 272 pixelmap_t pixelmap; 341 273 gfx_rect_t srect; … … 343 275 gfx_rect_t crect; 344 276 gfx_coord2_t offs; 345 gfx_coord_t cols;346 277 347 278 if (srect0 != NULL) … … 358 289 359 290 gfx_rect_translate(&offs, &srect, &drect); 360 gfx_rect_clip(&drect, &cbm->cgc-> clip_rect, &crect);291 gfx_rect_clip(&drect, &cbm->cgc->rect, &crect); 361 292 362 293 pixelmap.width = cbm->rect.p1.x - cbm->rect.p0.x; … … 364 295 pixelmap.data = cbm->alloc.pixels; 365 296 366 cols = cbm->cgc->rect.p1.x - cbm->cgc->rect.p0.x;367 368 297 if ((cbm->flags & bmpf_color_key) == 0) { 369 298 /* Simple copy */ 370 299 for (y = crect.p0.y; y < crect.p1.y; y++) { 300 console_set_pos(cbm->cgc->con, crect.p0.x, y); 301 371 302 for (x = crect.p0.x; x < crect.p1.x; x++) { 372 303 clr = pixelmap_get_pixel(&pixelmap, 373 304 x - offs.x - cbm->rect.p0.x, 374 305 y - offs.y - cbm->rect.p0.y); 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; 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); 383 313 } 384 314 } … … 391 321 x - offs.x - cbm->rect.p0.x, 392 322 y - offs.y - cbm->rect.p0.y); 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; 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 402 334 } 403 335 } 404 336 } else { 405 337 /* Color key & colorize */ 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; 338 console_set_rgb_color(cbm->cgc->con, cbm->cgc->clr, 339 cbm->cgc->clr); 411 340 412 341 for (y = crect.p0.y; y < crect.p1.y; y++) { 413 342 for (x = crect.p0.x; x < crect.p1.x; x++) { 343 414 344 clr = pixelmap_get_pixel(&pixelmap, 415 345 x - offs.x - cbm->rect.p0.x, 416 346 y - offs.y - cbm->rect.p0.y); 417 347 418 if (clr != cbm->key_color) 419 cbm->cgc->buf[y * cols + x] = ch; 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 420 357 } 421 358 } 422 359 } 423 424 console_update(cbm->cgc->con, crect.p0.x, crect.p0.y, crect.p1.x,425 crect.p1.y);426 360 427 361 return EOK; … … 441 375 } 442 376 443 /** Get cursor position on console GC.444 *445 * @param arg Console GC446 * @param pos Place to store position447 *448 * @return EOK on success or an error code449 */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 GC469 * @param pos New cursor position470 *471 * @return EOK on success or an error code472 */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 GC484 * @param visible @c true iff cursor should be made visible485 *486 * @return EOK on success or an error code487 */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 496 377 /** @} 497 378 */
Note:
See TracChangeset
for help on using the changeset viewer.