Changeset cea9f0c in mainline for uspace/lib/guigfx/src/canvas.c
- Timestamp:
- 2020-05-29T19:04:46Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f8375f7
- Parents:
- d8e2485
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/guigfx/src/canvas.c
rd8e2485 rcea9f0c 78 78 { 79 79 canvas_gc_t *cgc = (canvas_gc_t *) arg; 80 uint16_t r, g, b; 81 82 gfx_color_get_rgb_i16(color, &r, &g, &b); 83 cgc->color = PIXEL(0, r >> 8, g >> 8, b >> 8); 84 return EOK; 80 81 return gfx_set_color(cgc->mbgc, color); 85 82 } 86 83 … … 95 92 { 96 93 canvas_gc_t *cgc = (canvas_gc_t *) arg; 97 gfx_coord_t x, y; 98 99 // XXX We should handle p0.x > p1.x and p0.y > p1.y 100 101 for (y = rect->p0.y; y < rect->p1.y; y++) { 102 for (x = rect->p0.x; x < rect->p1.x; x++) { 103 surface_put_pixel(cgc->surface, x, y, cgc->color); 104 } 105 } 106 107 update_canvas(cgc->canvas, cgc->surface); 108 109 return EOK; 94 errno_t rc; 95 96 rc = gfx_fill_rect(cgc->mbgc, rect); 97 if (rc == EOK) 98 update_canvas(cgc->canvas, cgc->surface); 99 100 return rc; 110 101 } 111 102 … … 125 116 canvas_gc_t *cgc = NULL; 126 117 gfx_context_t *gc = NULL; 127 errno_t rc; 118 surface_coord_t w, h; 119 gfx_rect_t rect; 120 gfx_bitmap_alloc_t alloc; 121 errno_t rc; 122 123 surface_get_resolution(surface, &w, &h); 128 124 129 125 cgc = calloc(1, sizeof(canvas_gc_t)); … … 136 132 if (rc != EOK) 137 133 goto error; 134 135 rect.p0.x = 0; 136 rect.p0.y = 0; 137 rect.p1.x = w; 138 rect.p1.y = h; 139 140 alloc.pitch = w * sizeof(uint32_t); 141 alloc.off0 = 0; 142 alloc.pixels = surface_direct_access(surface); 143 144 rc = mem_gc_create(&rect, &alloc, &cgc->mgc); 145 if (rc != EOK) 146 goto error; 147 148 cgc->mbgc = mem_gc_get_ctx(cgc->mgc); 138 149 139 150 cgc->gc = gc; … … 143 154 return EOK; 144 155 error: 156 if (gc != NULL) 157 gfx_context_delete(gc); 145 158 if (cgc != NULL) 146 159 free(cgc); 147 gfx_context_delete(gc);148 160 return rc; 149 161 } … … 156 168 { 157 169 errno_t rc; 170 171 mem_gc_delete(cgc->mgc); 158 172 159 173 rc = gfx_context_delete(cgc->gc); … … 188 202 canvas_gc_t *cgc = (canvas_gc_t *) arg; 189 203 canvas_gc_bitmap_t *cbm = NULL; 190 gfx_coord2_t dim;191 204 errno_t rc; 192 205 … … 195 208 return ENOMEM; 196 209 197 gfx_coord2_subtract(¶ms->rect.p1, ¶ms->rect.p0, &dim); 198 cbm->rect = params->rect; 199 cbm->flags = params->flags; 200 cbm->key_color = params->key_color; 201 202 if (alloc == NULL) { 203 cbm->surface = surface_create(dim.x, dim.y, NULL, 0); 204 if (cbm->surface == NULL) { 205 rc = ENOMEM; 206 goto error; 207 } 208 209 cbm->alloc.pitch = dim.x * sizeof(uint32_t); 210 cbm->alloc.off0 = 0; 211 cbm->alloc.pixels = surface_direct_access(cbm->surface); 212 cbm->myalloc = true; 213 } else { 214 cbm->surface = surface_create(dim.x, dim.y, alloc->pixels, 0); 215 if (cbm->surface == NULL) { 216 rc = ENOMEM; 217 goto error; 218 } 219 220 cbm->alloc = *alloc; 221 } 210 rc = gfx_bitmap_create(cgc->mbgc, params, alloc, &cbm->mbitmap); 211 if (rc != EOK) 212 goto error; 222 213 223 214 cbm->cgc = cgc; … … 238 229 { 239 230 canvas_gc_bitmap_t *cbm = (canvas_gc_bitmap_t *)bm; 240 if (cbm->myalloc) 241 surface_destroy(cbm->surface); 242 // XXX if !cbm->myalloc, surface is leaked - no way to destroy it 243 // without destroying the pixel buffer 231 errno_t rc; 232 233 rc = gfx_bitmap_destroy(cbm->mbitmap); 234 if (rc != EOK) 235 return rc; 236 244 237 free(cbm); 245 238 return EOK; … … 257 250 { 258 251 canvas_gc_bitmap_t *cbm = (canvas_gc_bitmap_t *)bm; 259 gfx_rect_t srect; 260 gfx_rect_t drect; 261 gfx_coord2_t offs; 262 gfx_coord2_t dim; 263 gfx_coord_t x, y; 264 pixel_t pixel; 265 266 if (srect0 != NULL) 267 srect = *srect0; 268 else 269 srect = cbm->rect; 270 271 if (offs0 != NULL) { 272 offs = *offs0; 273 } else { 274 offs.x = 0; 275 offs.y = 0; 276 } 277 278 /* Destination rectangle */ 279 gfx_rect_translate(&offs, &srect, &drect); 280 281 gfx_coord2_subtract(&drect.p1, &drect.p0, &dim); 282 283 transform_t transform; 284 transform_identity(&transform); 285 transform_translate(&transform, offs.x - cbm->rect.p0.x, 286 offs.y - cbm->rect.p0.y); 287 288 source_t source; 289 source_init(&source); 290 source_set_transform(&source, transform); 291 source_set_texture(&source, cbm->surface, 292 PIXELMAP_EXTEND_TRANSPARENT_BLACK); 293 294 if ((cbm->flags & bmpf_color_key) == 0) { 295 drawctx_t drawctx; 296 drawctx_init(&drawctx, cbm->cgc->surface); 297 298 drawctx_set_source(&drawctx, &source); 299 drawctx_transfer(&drawctx, drect.p0.x, drect.p0.y, dim.x, dim.y); 300 } else { 301 for (y = drect.p0.y; y < drect.p1.y; y++) { 302 for (x = drect.p0.x; x < drect.p1.x; x++) { 303 pixel = source_determine_pixel(&source, x, y); 304 if (pixel != cbm->key_color) { 305 surface_put_pixel(cbm->cgc->surface, 306 x, y, pixel); 307 } 308 } 309 } 310 } 311 312 update_canvas(cbm->cgc->canvas, cbm->cgc->surface); 313 return EOK; 252 errno_t rc; 253 254 rc = gfx_bitmap_render(cbm->mbitmap, srect0, offs0); 255 if (rc == EOK) 256 update_canvas(cbm->cgc->canvas, cbm->cgc->surface); 257 258 return rc; 314 259 } 315 260 … … 323 268 { 324 269 canvas_gc_bitmap_t *cbm = (canvas_gc_bitmap_t *)bm; 325 *alloc = cbm->alloc; 326 return EOK;270 271 return gfx_bitmap_get_alloc(cbm->mbitmap, alloc); 327 272 } 328 273
Note:
See TracChangeset
for help on using the changeset viewer.