| 1 | /* |
| 2 | app.c: start-up and the frame. |
| 3 | */ |
| 4 | #include <stdlib.h> |
| 5 | #include "plat.h" |
| 6 | #include "gfx.h" |
| 7 | #include "font.h" |
| 8 | #include "jobs.h" |
| 9 | #include "ui.h" |
| 10 | #include "version.h" |
| 11 | #include "app.h" |
| 12 |
|
| 13 | static uint32_t *canvas; |
| 14 |
|
| 15 | int app_start(void) |
| 16 | { |
| 17 | plat_log(APP_NAME " " APP_VERSION " starting"); |
| 18 | canvas = plat_canvas_next(); // (none when the GPU draws) |
| 19 | if (!canvas && !gfx_gpu()) { |
| 20 | plat_log("FATAL: no canvas"); |
| 21 | return 0; |
| 22 | } |
| 23 | gfx_init(canvas, SCREEN_W, SCREEN_H); |
| 24 | if (!gfx_gpu()) gfx_clear(0xff05070d); |
| 25 | if (!font_init()) |
| 26 | plat_log("WARNING: fonts missing from %s/fonts", plat_data_dir()); |
| 27 | http_init(); |
| 28 | jobs_init(); |
| 29 | ui_init(); |
| 30 | return 1; |
| 31 | } |
| 32 |
|
| 33 | static uint64_t t_render, t_frames, t_window; |
| 34 |
|
| 35 | uint32_t *app_frame(int *drawn) |
| 36 | { |
| 37 | ui_update(); |
| 38 | *drawn = 0; |
| 39 | if (gfx_wants_redraw()) ui_force_redraw(); // (the GPU's list ran out of room last time) |
| 40 | if (ui_needs_redraw()) { |
| 41 | uint64_t t0 = plat_time_us(); |
| 42 | canvas = plat_canvas_next(); // the one not being shown (NULL when the GPU draws) |
| 43 | gfx_frame_begin(); |
| 44 | gfx_init(canvas, SCREEN_W, SCREEN_H); |
| 45 | ui_render(); |
| 46 | gfx_frame_end(); |
| 47 | t_render += plat_time_us() - t0; |
| 48 | t_frames++; |
| 49 | *drawn = 1; |
| 50 | } |
| 51 | // how long drawing takes, every 10 s (for the log) |
| 52 | uint64_t now = plat_time_us(); |
| 53 | if (!t_window) t_window = now; |
| 54 | if (now - t_window > 10000000) { |
| 55 | if (t_frames) |
| 56 | plat_log("frames: redrawn %llu times in 10 s (only on changes), %.1f ms to draw each", |
| 57 | (unsigned long long)t_frames, t_render / 1000.0 / t_frames); |
| 58 | t_render = t_frames = 0; |
| 59 | t_window = now; |
| 60 | } |
| 61 | return canvas; |
| 62 | } |
| 63 |
|
| 64 | void app_background(void) |
| 65 | { |
| 66 | } |
| 67 |
|
| 68 | void app_redraw(void) |
| 69 | { |
| 70 | ui_force_redraw(); |
| 71 | } |
| 72 |
|
| 73 | void app_shutdown(void) |
| 74 | { |
| 75 | ui_shutdown(); |
| 76 | plat_log("bye"); |
| 77 | } |