Merge pull request #13 from adafruit/doublebuffering-fix
Fix double buffering & add double buffering to text
This commit is contained in:
commit
731f56d6d9
3 changed files with 29 additions and 6 deletions
|
|
@ -74,6 +74,7 @@ void DVHSTX16::swap(bool 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 DVHSTX8::swap(bool copy_framebuffer) {
|
||||
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>(),
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -283,11 +283,12 @@ public:
|
|||
/*!
|
||||
@brief Instatiate a DVHSTX 8-bit canvas context for graphics
|
||||
@param pinout Details of the HSTX pinout
|
||||
@param double_buffered Whether to allocate two buffers
|
||||
*/
|
||||
/**************************************************************************/
|
||||
DVHSTXText(DVHSTXPinout pinout)
|
||||
: GFXcanvas16(91, 30, false), pinout(pinout), res{},
|
||||
attr{TextColor::TEXT_WHITE} {}
|
||||
DVHSTXText(DVHSTXPinout pinout, bool double_buffered = false)
|
||||
: GFXcanvas16(91, 30, false), double_buffered{double_buffered},
|
||||
pinout(pinout), res{}, attr{TextColor::TEXT_WHITE} {}
|
||||
~DVHSTXText() { end(); }
|
||||
|
||||
/**************************************************************************/
|
||||
|
|
@ -305,8 +306,8 @@ public:
|
|||
*/
|
||||
/**************************************************************************/
|
||||
bool begin() {
|
||||
bool result =
|
||||
hstx.init(91, 30, pimoroni::DVHSTX::MODE_TEXT_RGB111, false, pinout);
|
||||
bool result = hstx.init(91, 30, pimoroni::DVHSTX::MODE_TEXT_RGB111,
|
||||
double_buffered, pinout);
|
||||
if (!result)
|
||||
return false;
|
||||
buffer = hstx.get_back_buffer<uint16_t>();
|
||||
|
|
@ -428,6 +429,16 @@ public:
|
|||
/**************************************************************************/
|
||||
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:
|
||||
DVHSTXPinout pinout;
|
||||
DVHSTXResolution res;
|
||||
|
|
|
|||
|
|
@ -126,7 +126,6 @@ namespace pimoroni {
|
|||
|
||||
private:
|
||||
RGB888 palette[PALETTE_SIZE];
|
||||
bool double_buffered;
|
||||
uint8_t* frame_buffer_display;
|
||||
uint8_t* frame_buffer_back;
|
||||
uint32_t* font_cache = nullptr;
|
||||
|
|
|
|||
Loading…
Reference in a new issue