Merge pull request #13 from adafruit/doublebuffering-fix

Fix double buffering & add double buffering to text
This commit is contained in:
Limor "Ladyada" Fried 2025-03-23 15:17:05 -04:00 committed by GitHub
commit 731f56d6d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 6 deletions

View file

@ -74,6 +74,7 @@ void DVHSTX16::swap(bool copy_framebuffer) {
memcpy(hstx.get_front_buffer<uint8_t>(), hstx.get_back_buffer<uint8_t>(), memcpy(hstx.get_front_buffer<uint8_t>(), hstx.get_back_buffer<uint8_t>(),
sizeof(uint16_t) * _width * _height); sizeof(uint16_t) * _width * _height);
} }
buffer = hstx.get_back_buffer<uint16_t>();
} }
void DVHSTX8::swap(bool copy_framebuffer) { void DVHSTX8::swap(bool copy_framebuffer) {
if (!double_buffered) { if (!double_buffered) {
@ -84,6 +85,18 @@ void DVHSTX8::swap(bool copy_framebuffer) {
memcpy(hstx.get_front_buffer<uint8_t>(), hstx.get_back_buffer<uint8_t>(), memcpy(hstx.get_front_buffer<uint8_t>(), hstx.get_back_buffer<uint8_t>(),
sizeof(uint8_t) * _width * _height); sizeof(uint8_t) * _width * _height);
} }
buffer = hstx.get_back_buffer<uint8_t>();
}
void DVHSTXText::swap(bool copy_framebuffer) {
if (!double_buffered) {
return;
}
hstx.flip_blocking();
if (copy_framebuffer) {
memcpy(hstx.get_front_buffer<uint8_t>(), hstx.get_back_buffer<uint8_t>(),
sizeof(uint16_t) * _width * _height);
}
buffer = hstx.get_back_buffer<uint16_t>();
} }
void DVHSTXText::clear() { void DVHSTXText::clear() {

View file

@ -283,11 +283,12 @@ public:
/*! /*!
@brief Instatiate a DVHSTX 8-bit canvas context for graphics @brief Instatiate a DVHSTX 8-bit canvas context for graphics
@param pinout Details of the HSTX pinout @param pinout Details of the HSTX pinout
@param double_buffered Whether to allocate two buffers
*/ */
/**************************************************************************/ /**************************************************************************/
DVHSTXText(DVHSTXPinout pinout) DVHSTXText(DVHSTXPinout pinout, bool double_buffered = false)
: GFXcanvas16(91, 30, false), pinout(pinout), res{}, : GFXcanvas16(91, 30, false), double_buffered{double_buffered},
attr{TextColor::TEXT_WHITE} {} pinout(pinout), res{}, attr{TextColor::TEXT_WHITE} {}
~DVHSTXText() { end(); } ~DVHSTXText() { end(); }
/**************************************************************************/ /**************************************************************************/
@ -305,8 +306,8 @@ public:
*/ */
/**************************************************************************/ /**************************************************************************/
bool begin() { bool begin() {
bool result = bool result = hstx.init(91, 30, pimoroni::DVHSTX::MODE_TEXT_RGB111,
hstx.init(91, 30, pimoroni::DVHSTX::MODE_TEXT_RGB111, false, pinout); double_buffered, pinout);
if (!result) if (!result)
return false; return false;
buffer = hstx.get_back_buffer<uint16_t>(); buffer = hstx.get_back_buffer<uint16_t>();
@ -428,6 +429,16 @@ public:
/**************************************************************************/ /**************************************************************************/
int getCursorY() const { return cursor_y; } int getCursorY() const { return cursor_y; }
/**********************************************************************/
/*!
@brief If double-buffered, wait for retrace and swap buffers. Otherwise,
do nothing (returns immediately)
@param copy_framebuffer if true, copy the new screen to the new back buffer.
Otherwise, the content is undefined.
*/
/**********************************************************************/
void swap(bool copy_framebuffer = false);
private: private:
DVHSTXPinout pinout; DVHSTXPinout pinout;
DVHSTXResolution res; DVHSTXResolution res;

View file

@ -126,7 +126,6 @@ namespace pimoroni {
private: private:
RGB888 palette[PALETTE_SIZE]; RGB888 palette[PALETTE_SIZE];
bool double_buffered;
uint8_t* frame_buffer_display; uint8_t* frame_buffer_display;
uint8_t* frame_buffer_back; uint8_t* frame_buffer_back;
uint32_t* font_cache = nullptr; uint32_t* font_cache = nullptr;