Changeset d18f3b7 in mainline
- Timestamp:
- 2019-10-21T00:08:24Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1822545
- Parents:
- e0545de
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/gfxdemo/gfxdemo.c
re0545de rd18f3b7 136 136 for (i = 0; i < 5; i++) { 137 137 srect.p0.x = rand() % (w - 40); 138 srect.p0.y = rand() % (h - 40);138 srect.p0.y = rand() % (h - 20); 139 139 srect.p1.x = srect.p0.x + rand() % (w - srect.p0.x); 140 140 srect.p1.y = srect.p0.y + rand() % (h - srect.p0.y); -
uspace/lib/congfx/private/console.h
re0545de rd18f3b7 40 40 #include <gfx/context.h> 41 41 #include <io/console.h> 42 #include <io/pixel.h> 42 43 #include <stdio.h> 43 44 … … 53 54 /** File for printing characters */ 54 55 FILE *fout; 56 /** Current drawing color */ 57 pixel_t clr; 55 58 }; 59 60 /** Bitmap in console GC */ 61 typedef struct { 62 /** Containing console GC */ 63 struct console_gc *cgc; 64 /** Allocation info */ 65 gfx_bitmap_alloc_t alloc; 66 /** @c true if we allocated the bitmap, @c false if allocated by caller */ 67 bool myalloc; 68 /** Rectangle covered by bitmap */ 69 gfx_rect_t rect; 70 } console_gc_bitmap_t; 56 71 57 72 #endif -
uspace/lib/congfx/src/console.c
re0545de rd18f3b7 42 42 #include <gfx/render.h> 43 43 #include <io/pixel.h> 44 #include <io/pixelmap.h> 44 45 #include <stdlib.h> 45 46 #include "../private/console.h" … … 48 49 static errno_t console_gc_set_color(void *, gfx_color_t *); 49 50 static errno_t console_gc_fill_rect(void *, gfx_rect_t *); 51 static errno_t console_gc_bitmap_create(void *, gfx_bitmap_params_t *, 52 gfx_bitmap_alloc_t *, void **); 53 static errno_t console_gc_bitmap_destroy(void *); 54 static errno_t console_gc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *); 55 static errno_t console_gc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *); 50 56 51 57 gfx_context_ops_t console_gc_ops = { 52 58 .set_color = console_gc_set_color, 53 .fill_rect = console_gc_fill_rect 59 .fill_rect = console_gc_fill_rect, 60 .bitmap_create = console_gc_bitmap_create, 61 .bitmap_destroy = console_gc_bitmap_destroy, 62 .bitmap_render = console_gc_bitmap_render, 63 .bitmap_get_alloc = console_gc_bitmap_get_alloc 54 64 }; 55 65 … … 66 76 { 67 77 console_gc_t *cgc = (console_gc_t *) arg; 68 pixel_t clr; 69 70 clr = PIXEL(0, color->r >> 8, color->g >> 8, color->b >> 8); 71 72 console_set_rgb_color(cgc->con, clr, clr); 78 79 cgc->clr = PIXEL(0, color->r >> 8, color->g >> 8, color->b >> 8); 73 80 return EOK; 74 81 } … … 88 95 89 96 // XXX We should handle p0.x > p1.x and p0.y > p1.y 97 98 console_set_rgb_color(cgc->con, cgc->clr, cgc->clr); 90 99 91 100 for (y = rect->p0.y; y < rect->p1.y; y++) { … … 169 178 } 170 179 180 /** Create bitmap in console GC. 181 * 182 * @param arg console GC 183 * @param params Bitmap params 184 * @param alloc Bitmap allocation info or @c NULL 185 * @param rbm Place to store pointer to new bitmap 186 * @return EOK on success or an error code 187 */ 188 errno_t console_gc_bitmap_create(void *arg, gfx_bitmap_params_t *params, 189 gfx_bitmap_alloc_t *alloc, void **rbm) 190 { 191 console_gc_t *cgc = (console_gc_t *) arg; 192 console_gc_bitmap_t *cbm = NULL; 193 int w, h; 194 errno_t rc; 195 196 cbm = calloc(1, sizeof(console_gc_bitmap_t)); 197 if (cbm == NULL) 198 return ENOMEM; 199 200 w = params->rect.p1.x - params->rect.p0.x; 201 h = params->rect.p1.y - params->rect.p0.y; 202 cbm->rect = params->rect; 203 204 if (alloc == NULL) { 205 cbm->alloc.pitch = w * sizeof(uint32_t); 206 cbm->alloc.off0 = 0; 207 cbm->alloc.pixels = calloc(w * h, sizeof(uint32_t)); 208 if (cbm->alloc.pixels == NULL) { 209 rc = ENOMEM; 210 goto error; 211 } 212 213 cbm->myalloc = true; 214 } else { 215 cbm->alloc = *alloc; 216 } 217 218 cbm->cgc = cgc; 219 *rbm = (void *)cbm; 220 return EOK; 221 error: 222 if (cbm != NULL) 223 free(cbm); 224 return rc; 225 } 226 227 /** Destroy bitmap in console GC. 228 * 229 * @param bm Bitmap 230 * @return EOK on success or an error code 231 */ 232 static errno_t console_gc_bitmap_destroy(void *bm) 233 { 234 console_gc_bitmap_t *cbm = (console_gc_bitmap_t *)bm; 235 if (cbm->myalloc) 236 free(cbm->alloc.pixels); 237 free(cbm); 238 return EOK; 239 } 240 241 /** Render bitmap in console GC. 242 * 243 * @param bm Bitmap 244 * @param srect0 Source rectangle or @c NULL 245 * @param offs0 Offset or @c NULL 246 * @return EOK on success or an error code 247 */ 248 static errno_t console_gc_bitmap_render(void *bm, gfx_rect_t *srect0, 249 gfx_coord2_t *offs0) 250 { 251 console_gc_bitmap_t *cbm = (console_gc_bitmap_t *)bm; 252 int x, y; 253 int rv; 254 pixel_t clr; 255 pixelmap_t pixelmap; 256 gfx_rect_t srect; 257 gfx_rect_t drect; 258 gfx_coord2_t offs; 259 260 if (srect0 != NULL) 261 srect = *srect0; 262 else 263 srect = cbm->rect; 264 265 if (offs0 != NULL) { 266 offs = *offs0; 267 } else { 268 offs.x = 0; 269 offs.y = 0; 270 } 271 272 // XXX Add function to translate rectangle 273 drect.p0.x = srect.p0.x + offs.x; 274 drect.p0.y = srect.p0.y + offs.y; 275 drect.p1.x = srect.p1.x + offs.x; 276 drect.p1.y = srect.p1.y + offs.y; 277 278 pixelmap.width = cbm->rect.p1.x - cbm->rect.p0.x; 279 pixelmap.height = cbm->rect.p1.y = cbm->rect.p1.y; 280 pixelmap.data = cbm->alloc.pixels; 281 282 for (y = drect.p0.y; y < drect.p1.y; y++) { 283 console_set_pos(cbm->cgc->con, drect.p0.x, y); 284 285 for (x = drect.p0.x; x < drect.p1.x; x++) { 286 clr = pixelmap_get_pixel(&pixelmap, 287 x - offs.x - cbm->rect.p0.x, 288 y - offs.y - cbm->rect.p0.y); 289 console_set_rgb_color(cbm->cgc->con, clr, clr); 290 291 rv = fputc('X', cbm->cgc->fout); 292 if (rv < 0) 293 return EIO; 294 295 console_flush(cbm->cgc->con); 296 } 297 } 298 299 return EOK; 300 } 301 302 /** Get allocation info for bitmap in console GC. 303 * 304 * @param bm Bitmap 305 * @param alloc Place to store allocation info 306 * @return EOK on success or an error code 307 */ 308 static errno_t console_gc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc) 309 { 310 console_gc_bitmap_t *cbm = (console_gc_bitmap_t *)bm; 311 *alloc = cbm->alloc; 312 return EOK; 313 } 314 315 171 316 /** @} 172 317 */
Note:
See TracChangeset
for help on using the changeset viewer.