Changeset 0576df9 in mainline
- 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
- Location:
- uspace
- Files:
-
- 6 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/barber/barber.c
r38f5598 r0576df9 34 34 */ 35 35 36 #include <draw/surface.h>37 #include <draw/codec.h>38 36 #include <device/led_dev.h> 39 37 #include <errno.h> 40 38 #include <fibril_synch.h> 39 #include <gfximage/tga_gz.h> 41 40 #include <io/pixel.h> 42 41 #include <loc.h> … … 94 93 static fibril_timer_t *frame_timer = NULL; 95 94 static ui_image_t *frame_img; 96 static surface_t *frames[FRAMES];97 95 static gfx_bitmap_t *frame_bmp[FRAMES]; 98 96 … … 123 121 static bool decode_frames(gfx_context_t *gc) 124 122 { 125 gfx_bitmap_alloc_t alloc; 126 surface_coord_t w, h; 127 gfx_bitmap_params_t params; 123 gfx_rect_t rect; 128 124 errno_t rc; 129 125 130 126 for (unsigned int i = 0; i < FRAMES; i++) { 131 frames[i] = decode_tga_gz(images[i].addr, images[i].size,132 SURFACE_FLAG_SHARED);133 if ( frames[i] == NULL) {127 rc = decode_tga_gz(gc, images[i].addr, images[i].size, 128 &frame_bmp[i], &rect); 129 if (rc != EOK) { 134 130 printf("Unable to decode frame %u.\n", i); 135 131 return false; 136 132 } 137 133 138 surface_get_resolution(frames[i], &w, &h); 139 gfx_bitmap_params_init(¶ms); 140 params.rect.p1.x = w; 141 params.rect.p1.y = h; 142 143 alloc.pitch = sizeof(uint32_t) * w; 144 alloc.off0 = 0; 145 alloc.pixels = surface_direct_access(frames[i]); 146 147 rc = gfx_bitmap_create(gc, ¶ms, &alloc, &frame_bmp[i]); 148 if (rc != EOK) { 149 printf("Error creating bitmap.\n"); 150 return false; 151 } 134 (void) rect; 152 135 } 153 136 … … 162 145 gfx_bitmap_destroy(frame_bmp[i]); 163 146 frame_bmp[i] = NULL; 164 165 surface_destroy(frames[i]);166 frames[i] = NULL;167 147 } 168 148 } -
uspace/app/barber/meson.build
r38f5598 r0576df9 27 27 # 28 28 29 deps = [ 'ui', ' draw', 'compress' ]29 deps = [ 'ui', 'gfximage', 'compress' ] 30 30 31 31 _images = files( -
uspace/app/launcher/launcher.c
r38f5598 r0576df9 36 36 #include <errno.h> 37 37 #include <gfx/coord.h> 38 #include <gfximage/tga.h> 38 39 #include <stdbool.h> 39 40 #include <stdio.h> … … 42 43 #include <str_error.h> 43 44 #include <task.h> 44 45 #include <draw/surface.h>46 #include <draw/source.h>47 #include <draw/drawctx.h>48 #include <draw/codec.h>49 50 45 #include <ui/fixed.h> 51 46 #include <ui/image.h> … … 157 152 gfx_bitmap_params_t logo_params; 158 153 gfx_bitmap_t *logo_bmp; 159 gfx_bitmap_alloc_t alloc;160 154 gfx_context_t *gc; 161 surface_coord_t w, h;162 155 gfx_rect_t logo_rect; 163 156 gfx_rect_t rect; 157 gfx_coord2_t off; 164 158 errno_t rc; 165 159 … … 182 176 } 183 177 184 surface_t *logo = decode_tga((void *) helenos_tga, helenos_tga_size,185 SURFACE_FLAG_SHARED);186 if (!logo) {187 printf("Unable to decode logo.\n");188 return 1;189 }190 191 178 rc = ui_create(display_spec, &ui); 192 179 if (rc != EOK) { … … 217 204 gc = ui_window_get_gc(window); 218 205 219 surface_get_resolution(logo, &w, &h); 206 rc = decode_tga(gc, (void *) helenos_tga, helenos_tga_size, 207 &logo_bmp, &logo_rect); 208 if (rc != EOK) { 209 printf("Unable to decode logo.\n"); 210 return 1; 211 } 212 220 213 gfx_bitmap_params_init(&logo_params); 221 logo_params.rect.p1.x = w; 222 logo_params.rect.p1.y = h; 223 logo_rect = logo_params.rect; 224 225 alloc.pitch = sizeof(uint32_t) * w; 226 alloc.off0 = 0; 227 alloc.pixels = surface_direct_access(logo); 228 229 rc = gfx_bitmap_create(gc, &logo_params, &alloc, &logo_bmp); 230 if (rc != EOK) { 231 printf("Error creating bitmap.\n"); 232 return 1; 233 } 214 logo_params.rect = logo_rect; 234 215 235 216 rc = ui_fixed_create(&launcher.fixed); … … 245 226 } 246 227 247 rect.p0.x = 5; 248 rect.p0.y = 32; 249 rect.p1.x = 5 + w; 250 rect.p1.y = 32 + h; 228 off.x = 5; 229 off.y = 32; 230 gfx_rect_translate(&off, &logo_rect, &rect); 251 231 ui_image_set_rect(launcher.image, &rect); 252 232 -
uspace/app/launcher/meson.build
r38f5598 r0576df9 27 27 # 28 28 29 deps = [ ' draw', 'ui' ]29 deps = [ 'gfximage', 'ui' ] 30 30 31 31 _images = files('gfx/helenos.tga') -
uspace/app/viewer/meson.build
r38f5598 r0576df9 27 27 # 28 28 29 deps = [ 'ui', ' draw', 'compress' ]29 deps = [ 'ui', 'gfximage', 'compress' ] 30 30 src = files('viewer.c') 31 31 -
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; -
uspace/lib/meson.build
r38f5598 r0576df9 83 83 'ext4', 84 84 'gfxfont', 85 'gfximage', 85 86 'hound', 86 87 'ipcgfx', -
uspace/lib/ui/include/ui/window.h
r38f5598 r0576df9 53 53 extern void ui_window_add(ui_window_t *, ui_control_t *); 54 54 extern void ui_window_remove(ui_window_t *, ui_control_t *); 55 extern errno_t ui_window_resize(ui_window_t *, gfx_rect_t *); 55 56 extern ui_resource_t *ui_window_get_res(ui_window_t *); 56 57 extern gfx_context_t *ui_window_get_gc(ui_window_t *); -
uspace/lib/ui/src/window.c
r38f5598 r0576df9 215 215 } 216 216 217 /** Resize/move window. 218 * 219 * Resize window to the dimensions of @a rect. If @a rect.p0 is not 0,0, 220 * the top-left corner of the window will move on the screen accordingly. 221 * 222 * @param window Window 223 * @param rect Rectangle 224 * 225 * @return EOK on success or an error code 226 */ 227 errno_t ui_window_resize(ui_window_t *window, gfx_rect_t *rect) 228 { 229 gfx_coord2_t offs; 230 gfx_rect_t nrect; 231 errno_t rc; 232 233 /* 234 * Move rect so that p0=0,0 - keep window's coordinate system origin 235 * locked to top-left corner of the window. 236 */ 237 offs = rect->p0; 238 gfx_rect_rtranslate(&offs, rect, &nrect); 239 240 /* dwindow can be NULL in case of unit tests */ 241 if (window->dwindow != NULL) { 242 rc = display_window_resize(window->dwindow, &offs, &nrect); 243 if (rc != EOK) 244 return rc; 245 } 246 247 ui_wdecor_set_rect(window->wdecor, &nrect); 248 ui_wdecor_paint(window->wdecor); 249 return EOK; 250 } 251 217 252 /** Set window callbacks. 218 253 * -
uspace/lib/ui/test/window.c
r38f5598 r0576df9 175 175 } 176 176 177 /** ui_window_resize */ 178 PCUT_TEST(resize) 179 { 180 errno_t rc; 181 ui_t *ui = NULL; 182 ui_wnd_params_t params; 183 ui_window_t *window = NULL; 184 gfx_rect_t nrect; 185 186 rc = ui_create_disp(NULL, &ui); 187 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 188 189 ui_wnd_params_init(¶ms); 190 params.caption = "Hello"; 191 params.rect.p0.x = 0; 192 params.rect.p0.y = 0; 193 params.rect.p1.x = 1; 194 params.rect.p1.y = 1; 195 196 rc = ui_window_create(ui, ¶ms, &window); 197 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 198 PCUT_ASSERT_NOT_NULL(window); 199 200 nrect.p0.x = -1; 201 nrect.p0.y = -1; 202 nrect.p1.x = 2; 203 nrect.p1.y = 2; 204 rc = ui_window_resize(window, &nrect); 205 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 206 207 ui_window_destroy(window); 208 ui_destroy(ui); 209 } 210 177 211 /** ui_window_get_res/gc/rect() return valid objects */ 178 212 PCUT_TEST(get_res_gc_rect)
Note:
See TracChangeset
for help on using the changeset viewer.