common: Refactor framebuffer API to accept a context.

This commit is contained in:
iabdalkader 2025-04-21 18:07:41 +02:00
parent c122c9dfc2
commit d52287e129
2 changed files with 15 additions and 6 deletions

View File

@ -64,15 +64,17 @@ void fb_alloc_init0() {
} }
uint32_t fb_avail() { uint32_t fb_avail() {
uint32_t temp = pointer - framebuffer_get_buffers_end() - sizeof(uint32_t); framebuffer_t *fb = framebuffer_get(0);
uint32_t temp = pointer - framebuffer_get_buffers_end(fb) - sizeof(uint32_t);
return (temp < sizeof(uint32_t)) ? 0 : temp; return (temp < sizeof(uint32_t)) ? 0 : temp;
} }
void fb_alloc_mark() { void fb_alloc_mark() {
framebuffer_t *fb = framebuffer_get(0);
char *new_pointer = pointer - sizeof(uint32_t); char *new_pointer = pointer - sizeof(uint32_t);
// Check if allocation overwrites the framebuffer pixels // Check if allocation overwrites the framebuffer pixels
if (new_pointer < framebuffer_get_buffers_end()) { if (new_pointer < framebuffer_get_buffers_end(fb)) {
nlr_jump(MP_OBJ_TO_PTR(mp_obj_new_exception_msg(&mp_type_MemoryError, nlr_jump(MP_OBJ_TO_PTR(mp_obj_new_exception_msg(&mp_type_MemoryError,
MP_ERROR_TEXT("Out of fast frame buffer stack memory")))); MP_ERROR_TEXT("Out of fast frame buffer stack memory"))));
} }
@ -135,6 +137,8 @@ void fb_alloc_free_till_mark_past_mark_permanent() {
// returns null pointer without error if size==0 // returns null pointer without error if size==0
void *fb_alloc(uint32_t size, int hints) { void *fb_alloc(uint32_t size, int hints) {
framebuffer_t *fb = framebuffer_get(0);
if (!size) { if (!size) {
return NULL; return NULL;
} }
@ -150,7 +154,7 @@ void *fb_alloc(uint32_t size, int hints) {
char *new_pointer = result - sizeof(uint32_t); char *new_pointer = result - sizeof(uint32_t);
// Check if allocation overwrites the framebuffer pixels // Check if allocation overwrites the framebuffer pixels
if (new_pointer < framebuffer_get_buffers_end()) { if (new_pointer < framebuffer_get_buffers_end(fb)) {
fb_alloc_fail(); fb_alloc_fail();
} }
@ -194,7 +198,8 @@ void *fb_alloc0(uint32_t size, int hints) {
} }
void *fb_alloc_all(uint32_t *size, int hints) { void *fb_alloc_all(uint32_t *size, int hints) {
uint32_t temp = pointer - framebuffer_get_buffers_end() - sizeof(uint32_t); framebuffer_t *fb = framebuffer_get(0);
uint32_t temp = pointer - framebuffer_get_buffers_end(fb) - sizeof(uint32_t);
if (temp < sizeof(uint32_t)) { if (temp < sizeof(uint32_t)) {
*size = 0; *size = 0;

View File

@ -319,7 +319,9 @@ void usbdbg_data_out(uint32_t size, usbdbg_read_callback_t read_callback) {
case USBDBG_TEMPLATE_SAVE: { case USBDBG_TEMPLATE_SAVE: {
#if defined(IMLIB_ENABLE_IMAGE_FILE_IO) #if defined(IMLIB_ENABLE_IMAGE_FILE_IO)
image_t image; image_t image;
framebuffer_init_image(&image); framebuffer_t *fb = framebuffer_get(0);
framebuffer_init_image(fb, &image);
size = MIN(128, size); size = MIN(128, size);
char buffer[size]; char buffer[size];
@ -338,7 +340,9 @@ void usbdbg_data_out(uint32_t size, usbdbg_read_callback_t read_callback) {
#if defined(IMLIB_ENABLE_IMAGE_FILE_IO) \ #if defined(IMLIB_ENABLE_IMAGE_FILE_IO) \
&& defined(IMLIB_ENABLE_KEYPOINTS) && defined(IMLIB_ENABLE_KEYPOINTS)
image_t image; image_t image;
framebuffer_init_image(&image); framebuffer_t *fb = framebuffer_get(0);
framebuffer_init_image(fb, &image);
size = MIN(128, size); size = MIN(128, size);
char buffer[size]; char buffer[size];