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:
@@ -1,20 +1,40 @@
|
||||
#include "qt_softwarerenderer.hpp"
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
|
||||
SoftwareRenderer::SoftwareRenderer(QWidget *parent) : QRasterWindow(parent->windowHandle()) { parentWidget = parent; }
|
||||
extern "C" {
|
||||
#include <86box/86box.h>
|
||||
#include <86box/video.h>
|
||||
}
|
||||
|
||||
void SoftwareRenderer::paintEvent(QPaintEvent *event) {
|
||||
(void) event;
|
||||
SoftwareRenderer::SoftwareRenderer(QWidget *parent)
|
||||
: QRasterWindow(parent->windowHandle())
|
||||
{
|
||||
parentWidget = parent;
|
||||
|
||||
images[0] = std::make_unique<QImage>(QSize(2048, 2048), QImage::Format_RGB32);
|
||||
images[1] = std::make_unique<QImage>(QSize(2048, 2048), QImage::Format_RGB32);
|
||||
|
||||
buf_usage = std::vector<std::atomic_flag>(2);
|
||||
buf_usage[0].clear();
|
||||
buf_usage[1].clear();
|
||||
}
|
||||
|
||||
void SoftwareRenderer::paintEvent(QPaintEvent* event) {
|
||||
(void)event;
|
||||
onPaint(this);
|
||||
}
|
||||
|
||||
void SoftwareRenderer::onBlit(const std::unique_ptr<uint8_t>* img, int x, int y, int w, int h, std::atomic_flag* in_use) {
|
||||
void SoftwareRenderer::onBlit(int buf_idx, int x, int y, int w, int h) {
|
||||
/* TODO: should look into deleteLater() */
|
||||
auto tval = this;
|
||||
void* nuldata = 0;
|
||||
if (memcmp(&tval, &nuldata, sizeof(void*)) == 0) return;
|
||||
memcpy(image.bits(), img->get(), 2048 * 2048 * 4);
|
||||
in_use->clear();
|
||||
source.setRect(x, y, w, h);
|
||||
|
||||
cur_image = buf_idx;
|
||||
buf_usage[(buf_idx + 1) % 2].clear();
|
||||
|
||||
source.setRect(x, y, w, h),
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -29,3 +49,24 @@ bool SoftwareRenderer::event(QEvent *event)
|
||||
if (!eventDelegate(event, res)) return QRasterWindow::event(event);
|
||||
return res;
|
||||
}
|
||||
|
||||
void SoftwareRenderer::onPaint(QPaintDevice* device) {
|
||||
if (cur_image == -1)
|
||||
return;
|
||||
|
||||
QPainter painter(device);
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform, video_filter_method > 0 ? true : false);
|
||||
painter.fillRect(0, 0, device->width(), device->height(), QColorConstants::Black);
|
||||
painter.setCompositionMode(QPainter::CompositionMode_Plus);
|
||||
painter.drawImage(destination, *images[cur_image], source);
|
||||
}
|
||||
|
||||
std::vector<std::tuple<uint8_t*, std::atomic_flag*>> SoftwareRenderer::getBuffers()
|
||||
{
|
||||
std::vector<std::tuple<uint8_t*, std::atomic_flag*>> buffers;
|
||||
|
||||
buffers.push_back(std::make_tuple(images[0]->bits(), &buf_usage[0]));
|
||||
buffers.push_back(std::make_tuple(images[1]->bits(), &buf_usage[1]));
|
||||
|
||||
return buffers;
|
||||
}
|
||||
Reference in New Issue
Block a user