Skip to content

Commit

Permalink
Change structures and documentations for supporting double buffering
Browse files Browse the repository at this point in the history
By designing the internal API, I've got into the challenge, that with a single offscreen buffer, other threads could not render to this buffer until it is fully transfered via DMA. Now as it takes a while, the best solution would be if it is possible to render to another buffer in the time the current one is transfered. Now double buffering is the solution, that allows offscreen rendering while another buffer is still in transferation.
  • Loading branch information
RossAdrian committed Jul 22, 2024
1 parent aea743c commit cea7fd1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions native/pyframebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@ struct pyfb_framebuffer {
* Used if the framebuffer depth (color bits) is 32bit.
*/
uint32_t* u32_buffer;
} buffers[2];

/**
* The current framebuffer index. The enum constant can be used directly
* to get the index of the buffer to use. For example:
*
* \code{.c}
*
* struct pyfb_framebuffer* buffer = XXX();
* uint32_t* offscreen_buffer = buffer->buffers[buffer->used_buffer].u32_buffer;
*
* // render here something with this buffer
*
* \endcode
*/
enum used_buffer {

/**
* Set if the first buffer is in use.
*/
BUFFER_USED_0 = 0,

/**
* Set if the second buffer is in use.
*/
BUFFER_USED_1 = 1
};

/**
Expand Down Expand Up @@ -224,6 +250,9 @@ 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 cea7fd1

Please sign in to comment.