diff --git a/source/frontends/qt/emulator.cpp b/source/frontends/qt/emulator.cpp index 272e9dc4..9afb1442 100644 --- a/source/frontends/qt/emulator.cpp +++ b/source/frontends/qt/emulator.cpp @@ -34,14 +34,9 @@ void Emulator::refreshScreen(const bool force) } } -bool Emulator::saveScreen(const QString & filename) const +void Emulator::loadVideoSettings(QImage * screenBuffer) { - return ui->video->getScreen().save(filename); -} - -void Emulator::loadVideoSettings() -{ - ui->video->loadVideoSettings(); + ui->video->loadVideoSettings(screenBuffer); } void Emulator::unloadVideoSettings() @@ -49,11 +44,6 @@ void Emulator::unloadVideoSettings() ui->video->unloadVideoSettings(); } -void Emulator::displayLogo() -{ - ui->video->displayLogo(); -} - void Emulator::setVideoSize(QMdiSubWindow * window, const QSize & size) { window->showNormal(); diff --git a/source/frontends/qt/emulator.h b/source/frontends/qt/emulator.h index 0ef42919..2211ed81 100644 --- a/source/frontends/qt/emulator.h +++ b/source/frontends/qt/emulator.h @@ -4,6 +4,7 @@ #include class QMdiSubWindow; +class QImage; namespace Ui { class Emulator; @@ -20,10 +21,8 @@ public: void redrawScreen(); // regenerate image and repaint void refreshScreen(const bool force); - bool saveScreen(const QString & filename) const; - void loadVideoSettings(); + void loadVideoSettings(QImage * screenBuffer); void unloadVideoSettings(); - void displayLogo(); void setZoom(QMdiSubWindow * window, const int x); void set43AspectRatio(QMdiSubWindow * window); diff --git a/source/frontends/qt/qapple.cpp b/source/frontends/qt/qapple.cpp index 21047028..6ce32e80 100644 --- a/source/frontends/qt/qapple.cpp +++ b/source/frontends/qt/qapple.cpp @@ -524,7 +524,7 @@ void QApple::on_actionScreenshot_triggered() } else { - const bool ok = myFrame->saveScreen(filename); + const bool ok = myFrame->SaveScreen(filename); if (!ok) { const QString message = QString::fromUtf8("Cannot save screenshot to %1").arg(filename); diff --git a/source/frontends/qt/qtframe.cpp b/source/frontends/qt/qtframe.cpp index ae777419..5fd21838 100644 --- a/source/frontends/qt/qtframe.cpp +++ b/source/frontends/qt/qtframe.cpp @@ -4,12 +4,14 @@ #include "Core.h" #include "Utilities.h" +#include "Interface.h" #include +#include QtFrame::QtFrame(Emulator * emulator, QMdiSubWindow * window) : myEmulator(emulator), myWindow(window), myForceRepaint(false) { - + myLogo = QImage(":/resources/APPLEWINLOGO.BMP").mirrored(false, true); } void QtFrame::SetForceRepaint(const bool force) @@ -17,6 +19,12 @@ void QtFrame::SetForceRepaint(const bool force) myForceRepaint = force; } +void QtFrame::DisplayLogo() +{ + QPainter painter(&myFrameBuffer); + painter.drawImage(mySX, mySY, myLogo); +} + void QtFrame::VideoPresentScreen() { myEmulator->refreshScreen(myForceRepaint); @@ -33,10 +41,25 @@ void QtFrame::FrameRefreshStatus(int drawflags) void QtFrame::Initialize() { - LinuxFrame::Initialize(); + static_assert(sizeof(bgra_t) == 4, "Invalid size of bgra_t"); + Video & video = GetVideo(); + + mySX = video.GetFrameBufferBorderWidth(); + mySY = video.GetFrameBufferBorderHeight(); + mySW = video.GetFrameBufferBorderlessWidth(); + mySH = video.GetFrameBufferBorderlessHeight(); + + const int width = video.GetFrameBufferWidth(); + const int height = video.GetFrameBufferHeight(); + + myFrameBuffer = QImage(width, height, QImage::Format_ARGB32_Premultiplied); + + uchar * bits = myFrameBuffer.bits(); + video.Initialize(bits); + FrameRefreshStatus(DRAW_TITLE); - myEmulator->loadVideoSettings(); - myEmulator->displayLogo(); + myEmulator->loadVideoSettings(&myFrameBuffer); + DisplayLogo(); } void QtFrame::Destroy() @@ -55,7 +78,8 @@ void QtFrame::Set43Ratio() myEmulator->set43AspectRatio(myWindow); } -bool QtFrame::saveScreen(const QString & filename) const +bool QtFrame::SaveScreen(const QString & filename) const { - return myEmulator->saveScreen(filename); + QImage screen = myFrameBuffer.copy(mySX, mySY, mySW, mySH); + return screen.save(filename); } diff --git a/source/frontends/qt/qtframe.h b/source/frontends/qt/qtframe.h index 6607ab21..f1981e51 100644 --- a/source/frontends/qt/qtframe.h +++ b/source/frontends/qt/qtframe.h @@ -2,8 +2,8 @@ #define QTFRAME_H #include "linux/linuxframe.h" -#include #include +#include class Emulator; class QMdiSubWindow; @@ -17,16 +17,25 @@ public: virtual void FrameRefreshStatus(int drawflags); virtual void Initialize(); virtual void Destroy(); + virtual void DisplayLogo(); void SetForceRepaint(const bool force); void SetZoom(const int x); void Set43Ratio(); - bool saveScreen(const QString & filename) const; + + bool SaveScreen(const QString & filename) const; private: Emulator * myEmulator; QMdiSubWindow * myWindow; bool myForceRepaint; + + QImage myLogo; + QImage myFrameBuffer; + int mySX; + int mySY; + int mySW; + int mySH; }; #endif // QTFRAME_H diff --git a/source/frontends/qt/qvideo.cpp b/source/frontends/qt/qvideo.cpp index 76cc7149..6fd73ae6 100644 --- a/source/frontends/qt/qvideo.cpp +++ b/source/frontends/qt/qvideo.cpp @@ -16,22 +16,17 @@ QVideo::QVideo(QWidget *parent) : QVIDEO_BASECLASS(parent) { this->setMouseTracking(true); - - myLogo = QImage(":/resources/APPLEWINLOGO.BMP").mirrored(false, true); } -void QVideo::loadVideoSettings() +void QVideo::loadVideoSettings(QImage * screenBuffer) { + myFrameBuffer = screenBuffer; Video & video = GetVideo(); mySX = video.GetFrameBufferBorderWidth(); mySY = video.GetFrameBufferBorderHeight(); mySW = video.GetFrameBufferBorderlessWidth(); mySH = video.GetFrameBufferBorderlessHeight(); - myWidth = video.GetFrameBufferWidth(); - myHeight = video.GetFrameBufferHeight(); - - myFrameBuffer = video.GetFrameBuffer(); } void QVideo::unloadVideoSettings() @@ -39,45 +34,25 @@ void QVideo::unloadVideoSettings() myFrameBuffer = nullptr; } -QImage QVideo::getScreenImage() const -{ - QImage frameBuffer(myFrameBuffer, myWidth, myHeight, QImage::Format_ARGB32_Premultiplied); - return frameBuffer; -} - -QImage QVideo::getScreen() const -{ - QImage frameBuffer = getScreenImage(); - QImage screen = frameBuffer.copy(mySX, mySY, mySW, mySH); - - return screen; -} - -void QVideo::displayLogo() -{ - QImage frameBuffer = getScreenImage(); - - QPainter painter(&frameBuffer); - painter.drawImage(mySX, mySY, myLogo); -} - void QVideo::paintEvent(QPaintEvent *) { - QImage frameBuffer = getScreenImage(); - - const QSize actual = size(); - const double scaleX = double(actual.width()) / mySW; - const double scaleY = double(actual.height()) / mySH; - - // then paint it on the widget with scale + if (myFrameBuffer) { - QPainter painter(this); + myFrameBuffer->bits(); // triggers a refresh of the QImage - // scale and flip vertically - const QTransform transform(scaleX, 0.0, 0.0, -scaleY, 0.0, actual.height()); - painter.setTransform(transform); + const QSize actual = size(); + const double scaleX = double(actual.width()) / mySW; + const double scaleY = double(actual.height()) / mySH; - painter.drawImage(0, 0, frameBuffer, mySX, mySY, mySW, mySH); + // then paint it on the widget with scale + { + QPainter painter(this); + + // scale and flip vertically + const QTransform transform(scaleX, 0.0, 0.0, -scaleY, 0.0, actual.height()); + painter.setTransform(transform); + painter.drawImage(0, 0, *myFrameBuffer, mySX, mySY, mySW, mySH); + } } } diff --git a/source/frontends/qt/qvideo.h b/source/frontends/qt/qvideo.h index 4aad05e4..bf6d2a5d 100644 --- a/source/frontends/qt/qvideo.h +++ b/source/frontends/qt/qvideo.h @@ -12,10 +12,8 @@ class QVideo : public QVIDEO_BASECLASS public: explicit QVideo(QWidget *parent = nullptr); - QImage getScreen() const; - void loadVideoSettings(); + void loadVideoSettings(QImage * screenBuffer); void unloadVideoSettings(); - void displayLogo(); signals: @@ -32,18 +30,12 @@ protected: virtual void mouseReleaseEvent(QMouseEvent *event); private: - QImage myLogo; + QImage * myFrameBuffer; int mySX; int mySY; int mySW; int mySH; - int myWidth; - int myHeight; - - quint8 * myFrameBuffer; - - QImage getScreenImage() const; }; #endif // QVIDEO_H