mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
[fb] Use double-buffering in fb driver
Allocate and use a back buffer, so that draws to the screen are always a single memcpy()
This commit is contained in:
@@ -60,6 +60,7 @@ main(int argc, const char **argv)
|
||||
screen::pixel_t fg = scr.color(0xb0, 0xb0, 0xb0);
|
||||
screen::pixel_t bg = scr.color(49, 79, 128);
|
||||
scr.fill(bg);
|
||||
scr.update();
|
||||
|
||||
constexpr int margin = 2;
|
||||
const unsigned xstride = (margin + fnt.width());
|
||||
@@ -85,11 +86,13 @@ main(int argc, const char **argv)
|
||||
scroll.add_line(e->message, eom);
|
||||
if (++pending > pending_threshold) {
|
||||
scroll.render(scr, fnt);
|
||||
scr.update();
|
||||
pending = 0;
|
||||
}
|
||||
} else {
|
||||
if (pending) {
|
||||
scroll.render(scr, fnt);
|
||||
scr.update();
|
||||
pending = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "screen.h"
|
||||
|
||||
screen::screen(void *addr, unsigned hres, unsigned vres, pixel_order order) :
|
||||
@@ -6,6 +8,7 @@ screen::screen(void *addr, unsigned hres, unsigned vres, pixel_order order) :
|
||||
m_resx(hres),
|
||||
m_resy(vres)
|
||||
{
|
||||
m_back = reinterpret_cast<pixel_t*>(malloc(hres*vres*sizeof(pixel_t)));
|
||||
}
|
||||
|
||||
screen::pixel_t
|
||||
@@ -31,11 +34,17 @@ screen::fill(pixel_t color)
|
||||
{
|
||||
const size_t len = m_resx * m_resy;
|
||||
for (size_t i = 0; i < len; ++i)
|
||||
m_fb[i] = color;
|
||||
m_back[i] = color;
|
||||
}
|
||||
|
||||
void
|
||||
screen::draw_pixel(unsigned x, unsigned y, pixel_t color)
|
||||
{
|
||||
m_fb[x + y * m_resx] = color;
|
||||
m_back[x + y * m_resx] = color;
|
||||
}
|
||||
|
||||
void
|
||||
screen::update()
|
||||
{
|
||||
memcpy(m_fb, m_back, m_resx*m_resy*sizeof(pixel_t));
|
||||
}
|
||||
|
||||
@@ -19,8 +19,10 @@ public:
|
||||
void fill(pixel_t color);
|
||||
void draw_pixel(unsigned x, unsigned y, pixel_t color);
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
pixel_t *m_fb;
|
||||
pixel_t *m_fb, *m_back;
|
||||
pixel_order m_order;
|
||||
unsigned m_resx, m_resy;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user