qt: Refactor renderers buffer ownership
Invert the way buffers are created; make renderer create buffers for renderer stack. Use QImage bits as the buffer for software renderer.
This commit is contained in:
@@ -27,12 +27,6 @@ RendererStack::RendererStack(QWidget *parent) :
|
||||
ui(new Ui::RendererStack)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
imagebufs[0].reset(new uint8_t[2048 * 2048 * 4]);
|
||||
imagebufs[1].reset(new uint8_t[2048 * 2048 * 4]);
|
||||
|
||||
buffers_in_use = std::vector<std::atomic_flag>(2);
|
||||
buffers_in_use[0].clear();
|
||||
buffers_in_use[1].clear();
|
||||
|
||||
#ifdef WAYLAND
|
||||
if (QApplication::platformName().contains("wayland")) {
|
||||
@@ -182,7 +176,7 @@ void RendererStack::switchRenderer(Renderer renderer) {
|
||||
switch (renderer) {
|
||||
case Renderer::Software:
|
||||
{
|
||||
auto sw = new SoftwareRenderer(this);
|
||||
auto sw = new SoftwareRenderer(this);
|
||||
rendererWindow = sw;
|
||||
connect(this, &RendererStack::blitToRenderer, sw, &SoftwareRenderer::onBlit, Qt::QueuedConnection);
|
||||
current.reset(this->createWindowContainer(sw, this));
|
||||
@@ -216,13 +210,14 @@ void RendererStack::switchRenderer(Renderer renderer) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
imagebufs = std::move(rendererWindow->getBuffers());
|
||||
|
||||
current->setFocusPolicy(Qt::NoFocus);
|
||||
current->setFocusProxy(this);
|
||||
addWidget(current.get());
|
||||
|
||||
this->setStyleSheet("background-color: black");
|
||||
for (auto& in_use : buffers_in_use)
|
||||
in_use.clear();
|
||||
|
||||
endblit();
|
||||
}
|
||||
@@ -230,7 +225,7 @@ void RendererStack::switchRenderer(Renderer renderer) {
|
||||
// called from blitter thread
|
||||
void RendererStack::blit(int x, int y, int w, int h)
|
||||
{
|
||||
if ((w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL) || buffers_in_use[currentBuf].test_and_set())
|
||||
if ((w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL) || std::get<std::atomic_flag*>(imagebufs[currentBuf])->test_and_set())
|
||||
{
|
||||
video_blit_complete();
|
||||
return;
|
||||
@@ -239,7 +234,7 @@ void RendererStack::blit(int x, int y, int w, int h)
|
||||
sy = y;
|
||||
sw = this->w = w;
|
||||
sh = this->h = h;
|
||||
auto imagebits = imagebufs[currentBuf].get();
|
||||
uint8_t* imagebits = std::get<uint8_t*>(imagebufs[currentBuf]);
|
||||
for (int y1 = y; y1 < (y + h - 1); y1++)
|
||||
{
|
||||
auto scanline = imagebits + (y1 * (2048) * 4) + (x * 4);
|
||||
@@ -251,6 +246,6 @@ void RendererStack::blit(int x, int y, int w, int h)
|
||||
video_screenshot((uint32_t *)imagebits, x, y, 2048);
|
||||
}
|
||||
video_blit_complete();
|
||||
blitToRenderer(&imagebufs[currentBuf], sx, sy, sw, sh, &buffers_in_use[currentBuf]);
|
||||
currentBuf = (currentBuf + 1) % 2;
|
||||
emit blitToRenderer(currentBuf, sx, sy, sw, sh);
|
||||
currentBuf = (currentBuf + 1) % imagebufs.size();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user