void vc_free_gfx() { if (vc_gfx) { gfx_surface_destroy(vc_gfx); vc_gfx = NULL; } if (vc_tb_gfx) { gfx_surface_destroy(vc_tb_gfx); vc_tb_gfx = NULL; } if (vc_gfx_mem) { zx_vmar_unmap(zx_vmar_root_self(), vc_gfx_mem, vc_gfx_size); vc_gfx_mem = 0; } if (vc_gfx_vmo) { zx_handle_close(vc_gfx_vmo); vc_gfx_vmo = ZX_HANDLE_INVALID; } if (vc_hw_gfx_mem) { zx_vmar_unmap(zx_vmar_root_self(), vc_hw_gfx_mem, vc_gfx_size); vc_hw_gfx_mem = 0; } if (vc_hw_gfx_vmo) { zx_handle_close(vc_hw_gfx_vmo); vc_hw_gfx_vmo = ZX_HANDLE_INVALID; } }
zx_status_t vc_init_gfx(gfx_surface* test) { const gfx_font* font = vc_get_font(); vc_font = font; vc_test_gfx = test; // init the status bar vc_tb_gfx = gfx_create_surface(NULL, test->width, font->height, test->stride, test->format, 0); if (!vc_tb_gfx) { return ZX_ERR_NO_MEMORY; } // init the main surface vc_gfx = gfx_create_surface(NULL, test->width, test->height, test->stride, test->format, 0); if (!vc_gfx) { gfx_surface_destroy(vc_tb_gfx); vc_tb_gfx = NULL; return ZX_ERR_NO_MEMORY; } g_status_width = vc_gfx->width / font->width; return ZX_OK; }
/** * @brief Refresh the display */ void text_update(void) { struct display_info info; display_get_info(&info); /* get the display's surface */ gfx_surface *surface = gfx_create_surface_from_display(&info); struct text_line *line; list_for_every_entry(&text_list, line, struct text_line, node) { const char *c; int x = line->x; for (c = line->str; *c; c++) { font_draw_char(surface, *c, x, line->y, TEXT_COLOR); x += FONT_X; } } gfx_flush(surface); gfx_surface_destroy(surface); }