diff --git a/native/framebuffers.c b/native/framebuffers.c index cf3d0ba..c8f7f58 100644 --- a/native/framebuffers.c +++ b/native/framebuffers.c @@ -188,6 +188,7 @@ void pyfb_close(uint8_t fbnum) { // Okay, now handle a real close framebuffers[fbnum].users = 0; close(framebuffers[fbnum].fb_fd); + framebuffers[fbnum].fb_fd = -1; // free the offscreen buffers void** buffer; @@ -224,4 +225,31 @@ void pyfb_vinfo(uint8_t fbnum, struct pyfb_videomode_info* info_ptr) { memcpy(info_ptr, &framebuffers[fbnum].fb_info.vinfo, sizeof(struct fb_var_screeninfo)); unlock(framebuffers[fbnum].fb_lock); -} \ No newline at end of file +} + +void pyfb_flushBuffer(uint8_t fbnum) { + // first test if this device number is valid + if(fbnum >= MAX_FRAMEBUFFERS) { + return; + } + + lock(framebuffers[fbnum].fb_lock); + + // next, test if the device is really in use + if(framebuffers[fbnum].fb_fd == -1) { + // this framebuffer is not in use, so ignore + unlock(framebuffers[fbnum].fb_lock); + return; + } + + // if we get here, flush the offscreen buffer to the framebuffer + lseek(framebuffers[fbnum].fb_fd, 0L, SEEK_SET); + if(framebuffers[fbnum].fb_info.vinfo.bits_per_pixel == 32) { + write(framebuffers[fbnum].fb_fd, (void*)framebuffers[fbnum].u32_buffer, (size_t)framebuffers[fbnum].fb_info.fb_size_b); + }else{ + write(framebuffers[fbnum].fb_fd, (void*)framebuffers[fbnum].u16_buffer, (size_t)framebuffers[fbnum].fb_info.fb_size_b); + } + + // okay, ready flushed + unlock(framebuffers[fbnum].fb_lock); +} diff --git a/native/pyframebuffer.h b/native/pyframebuffer.h index b8b8170..151ac10 100644 --- a/native/pyframebuffer.h +++ b/native/pyframebuffer.h @@ -289,9 +289,6 @@ extern void __APISTATUS_internal pyfb_drawHorizontalLine(uint8_t fbnum, unsigned * As this operation must be transfered via DMA, this still can take a while. In the internet, * it says that it can take something between 20 and 100 milliseconds. * - * Additional to this, it swaps the offscreen buffer, so that this function does not block - * other threads rendering. - * * @param fbnum The framebuffer number of which to flush all buffers */ extern void pyfb_flushBuffer(uint8_t fbnum);