From 98800c31c76d0da1f30cd6c8f9cd1b80a8d41191 Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Sat, 5 Mar 2016 11:27:03 -0500 Subject: [PATCH] Add fb_alloc_all. Now you can just grab all the free ram in the frame buffer in one go. This fixes problems figuring out how many lines to alloc. Will update line op code with this new info later. --- src/omv/fb_alloc.c | 31 +++++++++++++++++++++++++++++-- src/omv/fb_alloc.h | 2 ++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/omv/fb_alloc.c b/src/omv/fb_alloc.c index dfab75698..ff657dc5a 100644 --- a/src/omv/fb_alloc.c +++ b/src/omv/fb_alloc.c @@ -29,6 +29,7 @@ void *fb_alloc(uint32_t size) if (!size) { return NULL; } + size=((size+sizeof(uint32_t)-1)/sizeof(uint32_t))*sizeof(uint32_t);// Round Up char *result = pointer - size; char *new_pointer = result - sizeof(uint32_t); @@ -43,11 +44,37 @@ void *fb_alloc(uint32_t size) return result; } -// returns null pointer without error if size==0 +// returns null pointer without error if passed size==0 void *fb_alloc0(uint32_t size) { void *mem = fb_alloc(size); - memset(mem, 0, size); + memset(mem, 0, size); // does nothing if size is zero. + return mem; +} + +void *fb_alloc_all(uint32_t *size) +{ + int temp = pointer - ((char *) FB_PIXELS()) - sizeof(uint32_t); + + if (temp < sizeof(uint32_t)) { + *size = 0; + return NULL; + } + + *size = (temp / sizeof(uint32_t)) * sizeof(uint32_t); // Round Down + char *result = pointer - *size; + char *new_pointer = result - sizeof(uint32_t); + + *((uint32_t *) new_pointer) = *size + sizeof(uint32_t); // Save size. + pointer = new_pointer; + return result; +} + +// returns null pointer without error if returned size==0 +void *fb_alloc0_all(uint32_t *size) +{ + void *mem = fb_alloc_all(size); + memset(mem, 0, *size); // does nothing if size is zero. return mem; } diff --git a/src/omv/fb_alloc.h b/src/omv/fb_alloc.h index 2cca303fd..4fa59682a 100644 --- a/src/omv/fb_alloc.h +++ b/src/omv/fb_alloc.h @@ -12,6 +12,8 @@ void fb_alloc_init0(); void *fb_alloc(uint32_t size); void *fb_alloc0(uint32_t size); +void *fb_alloc_all(uint32_t *size); // returns pointer and sets size +void *fb_alloc0_all(uint32_t *size); // returns pointer and sets size void fb_free(); void fb_free_all(); #endif /* __FF_ALLOC_H__ */