Changeset 0576df9 in mainline for uspace/app/viewer/viewer.c
- Timestamp:
- 2020-11-14T21:28:35Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 63b35c7
- Parents:
- 38f5598
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/viewer/viewer.c
r38f5598 r0576df9 34 34 */ 35 35 36 #include <draw/surface.h>37 #include <draw/codec.h>38 36 #include <errno.h> 37 #include <gfximage/tga.h> 39 38 #include <stdbool.h> 40 39 #include <stdio.h> … … 58 57 59 58 static ui_window_t *window; 60 static surface_t *surface= NULL;59 static gfx_bitmap_t *bitmap = NULL; 61 60 static ui_image_t *image = NULL; 62 61 static gfx_context_t *window_gc; 63 62 64 static surface_coord_t img_width;65 static surface_coord_t img_height; 66 67 static bool img_load(const char *, surface_t **);68 static bool img_setup(gfx_context_t *, surface_t *);63 static gfx_rect_t img_rect; 64 65 static bool img_load(gfx_context_t *gc, const char *, gfx_bitmap_t **, 66 gfx_rect_t *); 67 static bool img_setup(gfx_context_t *, gfx_bitmap_t *, gfx_rect_t *); 69 68 70 69 static void wnd_close(ui_window_t *, void *); … … 115 114 116 115 if (update) { 117 surface_t *lsface; 118 119 if (!img_load(imgs[imgs_current], &lsface)) { 116 gfx_bitmap_t *lbitmap; 117 gfx_rect_t lrect; 118 119 if (!img_load(window_gc, imgs[imgs_current], &lbitmap, &lrect)) { 120 120 printf("Cannot load image \"%s\".\n", imgs[imgs_current]); 121 121 exit(4); 122 122 } 123 if (!img_setup(window_gc, l sface)) {123 if (!img_setup(window_gc, lbitmap, &lrect)) { 124 124 printf("Cannot setup image \"%s\".\n", imgs[imgs_current]); 125 125 exit(6); … … 128 128 } 129 129 130 static bool img_load(const char *fname, surface_t **p_local_surface) 130 static bool img_load(gfx_context_t *gc, const char *fname, 131 gfx_bitmap_t **rbitmap, gfx_rect_t *rect) 131 132 { 132 133 int fd; … … 158 159 vfs_put(fd); 159 160 160 *p_local_surface = decode_tga(tga, stat.size, SURFACE_FLAG_SHARED);161 if ( *p_local_surface == NULL) {161 rc = decode_tga(gc, tga, stat.size, rbitmap, rect); 162 if (rc != EOK) { 162 163 free(tga); 163 164 return false; … … 166 167 free(tga); 167 168 168 surface_get_resolution(*p_local_surface, &img_width, &img_height); 169 169 img_rect = *rect; 170 170 return true; 171 171 } 172 172 173 static bool img_setup(gfx_context_t *gc, surface_t *local_surface) 174 { 175 surface_coord_t w, h; 176 gfx_bitmap_params_t params; 177 gfx_bitmap_alloc_t alloc; 178 gfx_bitmap_t *bmp; 173 static bool img_setup(gfx_context_t *gc, gfx_bitmap_t *bmp, gfx_rect_t *rect) 174 { 179 175 gfx_rect_t arect; 180 176 gfx_rect_t irect; … … 184 180 ui_res = ui_window_get_res(window); 185 181 186 surface_get_resolution(local_surface, &w, &h);187 gfx_bitmap_params_init(¶ms);188 params.rect.p1.x = w;189 params.rect.p1.y = h;190 191 182 ui_window_get_app_rect(window, &arect); 192 gfx_rect_translate(&arect.p0, ¶ms.rect, &irect); 193 194 alloc.pitch = sizeof(uint32_t) * w; 195 alloc.off0 = 0; 196 alloc.pixels = surface_direct_access(local_surface); 197 198 rc = gfx_bitmap_create(gc, ¶ms, &alloc, &bmp); 199 if (rc != EOK) { 200 surface_destroy(local_surface); 201 return false; 202 } 183 gfx_rect_translate(&arect.p0, rect, &irect); 203 184 204 185 if (image != NULL) { 205 ui_image_set_bmp(image, bmp, ¶ms.rect);186 ui_image_set_bmp(image, bmp, rect); 206 187 (void) ui_image_paint(image); 207 188 ui_image_set_rect(image, &irect); 208 189 } else { 209 rc = ui_image_create(ui_res, bmp, ¶ms.rect, &image);190 rc = ui_image_create(ui_res, bmp, rect, &image); 210 191 if (rc != EOK) { 211 192 gfx_bitmap_destroy(bmp); 212 surface_destroy(local_surface);213 193 return false; 214 194 } … … 218 198 } 219 199 220 if ( surface!= NULL)221 surface_destroy(surface);222 223 surface = local_surface;200 if (bitmap != NULL) 201 gfx_bitmap_destroy(bitmap); 202 203 bitmap = bmp; 224 204 return true; 225 205 } … … 235 215 { 236 216 const char *display_spec = DISPLAY_DEFAULT; 237 surface_t *lsface; 217 gfx_bitmap_t *lbitmap; 218 gfx_rect_t lrect; 238 219 bool fullscreen = false; 239 220 gfx_rect_t rect; … … 287 268 } 288 269 289 if (!img_load(imgs[imgs_current], &lsface)) {290 printf("Cannot load image \"%s\".\n", imgs[imgs_current]);291 return 1;292 }293 294 270 // TODO Fullscreen mode 295 271 if (fullscreen) { … … 306 282 viewer.ui = ui; 307 283 308 rect.p0.x = 0; 309 rect.p0.y = 0; 310 rect.p1.x = img_width; 311 rect.p1.y = img_height; 312 284 /* 285 * We don't know the image size yet, so create tiny window and resize 286 * later. 287 */ 313 288 ui_wnd_params_init(¶ms); 314 289 params.caption = "Viewer"; 290 params.rect.p0.x = 0; 291 params.rect.p0.y = 0; 292 params.rect.p1.x = 1; 293 params.rect.p1.y = 1; 294 295 rc = ui_window_create(ui, ¶ms, &window); 296 if (rc != EOK) { 297 printf("Error creating window.\n"); 298 return 1; 299 } 300 301 window_gc = ui_window_get_gc(window); 302 303 ui_window_set_cb(window, &window_cb, (void *) &viewer); 304 305 if (!img_load(window_gc, imgs[imgs_current], &lbitmap, &lrect)) { 306 printf("Cannot load image \"%s\".\n", imgs[imgs_current]); 307 return 1; 308 } 309 315 310 /* 316 311 * Compute window rectangle such that application area corresponds 317 312 * to rect 318 313 */ 319 ui_wdecor_rect_from_app(& rect, &wrect);314 ui_wdecor_rect_from_app(&lrect, &wrect); 320 315 off = wrect.p0; 321 gfx_rect_rtranslate(&off, &wrect, ¶ms.rect); 322 323 rc = ui_window_create(ui, ¶ms, &window); 324 if (rc != EOK) { 325 printf("Error creating window.\n"); 326 return 1; 327 } 328 329 window_gc = ui_window_get_gc(window); 330 331 ui_window_set_cb(window, &window_cb, (void *) &viewer); 332 333 if (!img_setup(window_gc, lsface)) { 316 gfx_rect_rtranslate(&off, &wrect, &rect); 317 rc = ui_window_resize(window, &rect); 318 if (rc != EOK) { 319 printf("Error resizing window.\n"); 320 return 1; 321 } 322 323 if (!img_setup(window_gc, lbitmap, &lrect)) { 334 324 printf("Cannot setup image \"%s\".\n", imgs[imgs_current]); 335 325 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.