Skip to content

Commit

Permalink
Implement framebuffer flush function
Browse files Browse the repository at this point in the history
  • Loading branch information
RossAdrian committed Jul 26, 2024
1 parent 483bbbd commit 5244087
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
30 changes: 29 additions & 1 deletion native/framebuffers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

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);
}
3 changes: 0 additions & 3 deletions native/pyframebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5244087

Please sign in to comment.