Use movable allocation system for terminal tilegrid.

Moving memory is now done by the infrastructure and neither necessary nor correct here anymore.
This commit is contained in:
Christian Walther 2020-10-11 20:39:19 +02:00
parent c7404a3ff8
commit 2ba9805f84
2 changed files with 17 additions and 27 deletions

View File

@ -867,7 +867,6 @@ struct _supervisor_allocation_node;
mp_obj_t rtc_time_source; \
GAMEPAD_ROOT_POINTERS \
mp_obj_t pew_singleton; \
mp_obj_t terminal_tilegrid_tiles; \
BOARD_UART_ROOT_POINTER \
FLASH_ROOT_POINTERS \
MEMORYMONITOR_ROOT_POINTERS \

View File

@ -81,19 +81,21 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) {
uint16_t total_tiles = width_in_tiles * height_in_tiles;
// First try to allocate outside the heap. This will fail when the VM is running.
tilegrid_tiles = allocate_memory(align32_size(total_tiles), false, false);
uint8_t* tiles;
if (tilegrid_tiles == NULL) {
tiles = m_malloc(total_tiles, true);
MP_STATE_VM(terminal_tilegrid_tiles) = tiles;
} else {
tiles = (uint8_t*) tilegrid_tiles->ptr;
// Reuse the previous allocation if possible
if (tilegrid_tiles) {
if (get_allocation_length(tilegrid_tiles) != align32_size(total_tiles)) {
free_memory(tilegrid_tiles);
tilegrid_tiles = NULL;
}
}
if (!tilegrid_tiles) {
tilegrid_tiles = allocate_memory(align32_size(total_tiles), false, true);
if (!tilegrid_tiles) {
return;
}
}
uint8_t* tiles = (uint8_t*) tilegrid_tiles->ptr;
if (tiles == NULL) {
return;
}
grid->y = tall ? blinka_bitmap.height : 0;
grid->x = tall ? 0 : blinka_bitmap.width;
grid->top_left_y = 0;
@ -120,7 +122,6 @@ void supervisor_stop_terminal(void) {
if (tilegrid_tiles != NULL) {
free_memory(tilegrid_tiles);
tilegrid_tiles = NULL;
supervisor_terminal_text_grid.inline_tiles = false;
supervisor_terminal_text_grid.tiles = NULL;
}
#endif
@ -128,20 +129,10 @@ void supervisor_stop_terminal(void) {
void supervisor_display_move_memory(void) {
#if CIRCUITPY_TERMINALIO
displayio_tilegrid_t* grid = &supervisor_terminal_text_grid;
if (MP_STATE_VM(terminal_tilegrid_tiles) != NULL &&
grid->tiles == MP_STATE_VM(terminal_tilegrid_tiles)) {
uint16_t total_tiles = grid->width_in_tiles * grid->height_in_tiles;
tilegrid_tiles = allocate_memory(align32_size(total_tiles), false, false);
if (tilegrid_tiles != NULL) {
memcpy(tilegrid_tiles->ptr, grid->tiles, total_tiles);
grid->tiles = (uint8_t*) tilegrid_tiles->ptr;
} else {
grid->tiles = NULL;
grid->inline_tiles = false;
}
MP_STATE_VM(terminal_tilegrid_tiles) = NULL;
if (tilegrid_tiles != NULL) {
supervisor_terminal_text_grid.tiles = (uint8_t*) tilegrid_tiles->ptr;
} else {
supervisor_terminal_text_grid.tiles = NULL;
}
#endif