Skip to content

Commit a4b84cf

Browse files
committed
Use movable allocation system for RGBMatrix allocations.
Hybrid allocation is now part of the infrastructure. Moving memory contents would not be necessary because displayio can recreate them, but does not hurt.
1 parent ac91220 commit a4b84cf

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

shared-module/rgbmatrix/RGBMatrix.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
7878
// verify that the matrix is big enough
7979
mp_get_index(mp_obj_get_type(self->framebuffer), self->bufinfo.len, MP_OBJ_NEW_SMALL_INT(self->bufsize-1), false);
8080
} else {
81-
_PM_free(self->bufinfo.buf);
82-
_PM_free(self->protomatter.rgbPins);
83-
_PM_free(self->protomatter.addr);
84-
_PM_free(self->protomatter.screenData);
81+
common_hal_rgbmatrix_free_impl(self->bufinfo.buf);
82+
common_hal_rgbmatrix_free_impl(self->protomatter.rgbPins);
83+
common_hal_rgbmatrix_free_impl(self->protomatter.addr);
84+
common_hal_rgbmatrix_free_impl(self->protomatter.screenData);
8585

8686
self->framebuffer = NULL;
8787
self->bufinfo.buf = common_hal_rgbmatrix_allocator_impl(self->bufsize);
@@ -180,9 +180,6 @@ void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t* self) {
180180

181181
void rgbmatrix_rgbmatrix_collect_ptrs(rgbmatrix_rgbmatrix_obj_t* self) {
182182
gc_collect_ptr(self->framebuffer);
183-
gc_collect_ptr(self->protomatter.rgbPins);
184-
gc_collect_ptr(self->protomatter.addr);
185-
gc_collect_ptr(self->protomatter.screenData);
186183
}
187184

188185
void common_hal_rgbmatrix_rgbmatrix_set_paused(rgbmatrix_rgbmatrix_obj_t* self, bool paused) {
@@ -217,18 +214,10 @@ int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t* self) {
217214
}
218215

219216
void *common_hal_rgbmatrix_allocator_impl(size_t sz) {
220-
if (gc_alloc_possible()) {
221-
return m_malloc_maybe(sz + sizeof(void*), true);
222-
} else {
223-
supervisor_allocation *allocation = allocate_memory(align32_size(sz), false, false);
224-
return allocation ? allocation->ptr : NULL;
225-
}
217+
supervisor_allocation *allocation = allocate_memory(align32_size(sz), false, true);
218+
return allocation ? allocation->ptr : NULL;
226219
}
227220

228221
void common_hal_rgbmatrix_free_impl(void *ptr_in) {
229-
supervisor_allocation *allocation = allocation_from_ptr(ptr_in);
230-
231-
if (allocation) {
232-
free_memory(allocation);
233-
}
222+
free_memory(allocation_from_ptr(ptr_in));
234223
}

0 commit comments

Comments
 (0)