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:
parent
c7404a3ff8
commit
2ba9805f84
@ -867,7 +867,6 @@ struct _supervisor_allocation_node;
|
|||||||
mp_obj_t rtc_time_source; \
|
mp_obj_t rtc_time_source; \
|
||||||
GAMEPAD_ROOT_POINTERS \
|
GAMEPAD_ROOT_POINTERS \
|
||||||
mp_obj_t pew_singleton; \
|
mp_obj_t pew_singleton; \
|
||||||
mp_obj_t terminal_tilegrid_tiles; \
|
|
||||||
BOARD_UART_ROOT_POINTER \
|
BOARD_UART_ROOT_POINTER \
|
||||||
FLASH_ROOT_POINTERS \
|
FLASH_ROOT_POINTERS \
|
||||||
MEMORYMONITOR_ROOT_POINTERS \
|
MEMORYMONITOR_ROOT_POINTERS \
|
||||||
|
@ -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;
|
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.
|
// Reuse the previous allocation if possible
|
||||||
tilegrid_tiles = allocate_memory(align32_size(total_tiles), false, false);
|
if (tilegrid_tiles) {
|
||||||
uint8_t* tiles;
|
if (get_allocation_length(tilegrid_tiles) != align32_size(total_tiles)) {
|
||||||
if (tilegrid_tiles == NULL) {
|
free_memory(tilegrid_tiles);
|
||||||
tiles = m_malloc(total_tiles, true);
|
tilegrid_tiles = NULL;
|
||||||
MP_STATE_VM(terminal_tilegrid_tiles) = tiles;
|
|
||||||
} else {
|
|
||||||
tiles = (uint8_t*) tilegrid_tiles->ptr;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (tiles == NULL) {
|
if (!tilegrid_tiles) {
|
||||||
|
tilegrid_tiles = allocate_memory(align32_size(total_tiles), false, true);
|
||||||
|
if (!tilegrid_tiles) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
uint8_t* tiles = (uint8_t*) tilegrid_tiles->ptr;
|
||||||
|
|
||||||
grid->y = tall ? blinka_bitmap.height : 0;
|
grid->y = tall ? blinka_bitmap.height : 0;
|
||||||
grid->x = tall ? 0 : blinka_bitmap.width;
|
grid->x = tall ? 0 : blinka_bitmap.width;
|
||||||
grid->top_left_y = 0;
|
grid->top_left_y = 0;
|
||||||
@ -120,7 +122,6 @@ void supervisor_stop_terminal(void) {
|
|||||||
if (tilegrid_tiles != NULL) {
|
if (tilegrid_tiles != NULL) {
|
||||||
free_memory(tilegrid_tiles);
|
free_memory(tilegrid_tiles);
|
||||||
tilegrid_tiles = NULL;
|
tilegrid_tiles = NULL;
|
||||||
supervisor_terminal_text_grid.inline_tiles = false;
|
|
||||||
supervisor_terminal_text_grid.tiles = NULL;
|
supervisor_terminal_text_grid.tiles = NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -128,20 +129,10 @@ void supervisor_stop_terminal(void) {
|
|||||||
|
|
||||||
void supervisor_display_move_memory(void) {
|
void supervisor_display_move_memory(void) {
|
||||||
#if CIRCUITPY_TERMINALIO
|
#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) {
|
if (tilegrid_tiles != NULL) {
|
||||||
memcpy(tilegrid_tiles->ptr, grid->tiles, total_tiles);
|
supervisor_terminal_text_grid.tiles = (uint8_t*) tilegrid_tiles->ptr;
|
||||||
grid->tiles = (uint8_t*) tilegrid_tiles->ptr;
|
|
||||||
} else {
|
} else {
|
||||||
grid->tiles = NULL;
|
supervisor_terminal_text_grid.tiles = NULL;
|
||||||
grid->inline_tiles = false;
|
|
||||||
}
|
|
||||||
MP_STATE_VM(terminal_tilegrid_tiles) = NULL;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user