diff --git a/source/frontends/qapple/video.cpp b/source/frontends/qapple/video.cpp index f625786f..090043c7 100644 --- a/source/frontends/qapple/video.cpp +++ b/source/frontends/qapple/video.cpp @@ -4,66 +4,58 @@ #include #include "StdAfx.h" -#include "linux/videobuffer.h" #include "linux/keyboard.h" #include "linux/paddle.h" #include "Common.h" #include "CardManager.h" #include "MouseInterface.h" #include "Core.h" +#include "Frame.h" +#include "Video.h" Video::Video(QWidget *parent) : VIDEO_BASECLASS(parent) { setMouseTracking(true); myLogo = QImage(":/resources/APPLEWINLOGO.BMP").mirrored(false, true); + + mySX = GetFrameBufferBorderWidth(); + mySY = GetFrameBufferBorderHeight(); + mySW = GetFrameBufferBorderlessWidth(); + mySH = GetFrameBufferBorderlessHeight(); + myWidth = GetFrameBufferWidth(); + myHeight = GetFrameBufferHeight(); +} + +QImage Video::getScreenImage() const +{ + QImage frameBuffer(g_pFramebufferbits, myWidth, myHeight, QImage::Format_ARGB32_Premultiplied); + return frameBuffer; } QImage Video::getScreen() const { - uint8_t * data; - int width; - int height; - int sx, sy; - int sw, sh; - - getScreenData(data, width, height, sx, sy, sw, sh); - QImage frameBuffer(data, width, height, QImage::Format_ARGB32_Premultiplied); - - QImage screen = frameBuffer.copy(sx, sy, sw, sh); + QImage frameBuffer = getScreenImage(); + QImage screen = frameBuffer.copy(mySX, mySY, mySW, mySH); return screen; } void Video::displayLogo() { - uint8_t * data; - int width; - int height; - int sx, sy; - int sw, sh; - - getScreenData(data, width, height, sx, sy, sw, sh); - QImage frameBuffer(data, width, height, QImage::Format_ARGB32_Premultiplied); + QImage frameBuffer = getScreenImage(); QPainter painter(&frameBuffer); - painter.drawImage(sx, sy, myLogo); + painter.drawImage(mySX, mySY, myLogo); } void Video::paintEvent(QPaintEvent *) { - uint8_t * data; - int width; - int height; - int sx, sy; - int sw, sh; - - getScreenData(data, width, height, sx, sy, sw, sh); - QImage frameBuffer(data, width, height, QImage::Format_ARGB32_Premultiplied); + QImage frameBuffer = getScreenImage(); const QSize actual = size(); - const double scaleX = double(actual.width()) / sw; - const double scaleY = double(actual.height()) / sh; + const double scaleX = double(actual.width()) / mySW; + const double scaleY = double(actual.height()) / mySH; // then paint it on the widget with scale { @@ -73,7 +65,7 @@ void Video::paintEvent(QPaintEvent *) const QTransform transform(scaleX, 0.0, 0.0, -scaleY, 0.0, actual.height()); painter.setTransform(transform); - painter.drawImage(0, 0, frameBuffer, sx, sy, sw, sh); + painter.drawImage(0, 0, frameBuffer, mySX, mySY, mySW, mySH); } } diff --git a/source/frontends/qapple/video.h b/source/frontends/qapple/video.h index 0bbddbaa..0486781c 100644 --- a/source/frontends/qapple/video.h +++ b/source/frontends/qapple/video.h @@ -31,6 +31,15 @@ protected: private: QImage myLogo; + + int mySX; + int mySY; + int mySW; + int mySH; + int myWidth; + int myHeight; + + QImage getScreenImage() const; }; #endif // VIDEO_H diff --git a/source/frontends/sa2/emulator.cpp b/source/frontends/sa2/emulator.cpp index ecefdf7b..c9025676 100644 --- a/source/frontends/sa2/emulator.cpp +++ b/source/frontends/sa2/emulator.cpp @@ -4,7 +4,6 @@ #include #include "linux/videobuffer.h" -#include "linux/data.h" #include "linux/paddle.h" #include "linux/keyboard.h" @@ -148,6 +147,11 @@ Emulator::Emulator( , myFullscreen(false) , mySpeed(fixedSpeed) { + myRect.x = GetFrameBufferBorderWidth(); + myRect.y = GetFrameBufferBorderHeight(); + myRect.w = GetFrameBufferBorderlessWidth(); + myRect.h = GetFrameBufferBorderlessHeight(); + myPitch = GetFrameBufferWidth() * sizeof(bgra_t); } void Emulator::execute(const size_t next) @@ -165,29 +169,14 @@ void Emulator::execute(const size_t next) SpkrUpdate(executedCycles); } -SDL_Rect Emulator::updateTexture() +void Emulator::updateTexture() { - uint8_t * data; - int width; - int height; - int sx, sy; - int sw, sh; - - getScreenData(data, width, height, sx, sy, sw, sh); - SDL_UpdateTexture(myTexture.get(), nullptr, data, width * 4); - - SDL_Rect srect; - srect.x = sx; - srect.y = sy; - srect.w = sw; - srect.h = sh; - - return srect; + SDL_UpdateTexture(myTexture.get(), nullptr, g_pFramebufferbits, myPitch); } -void Emulator::refreshVideo(const SDL_Rect & rect) +void Emulator::refreshVideo() { - SDL_RenderCopyEx(myRenderer.get(), myTexture.get(), &rect, nullptr, 0.0, nullptr, SDL_FLIP_VERTICAL); + SDL_RenderCopyEx(myRenderer.get(), myTexture.get(), &myRect, nullptr, 0.0, nullptr, SDL_FLIP_VERTICAL); SDL_RenderPresent(myRenderer.get()); } diff --git a/source/frontends/sa2/emulator.h b/source/frontends/sa2/emulator.h index bafddf15..265ee440 100644 --- a/source/frontends/sa2/emulator.h +++ b/source/frontends/sa2/emulator.h @@ -16,9 +16,9 @@ public: ); void execute(const size_t milliseconds); + + void updateTexture(); void refreshVideo(); - SDL_Rect updateTexture(); - void refreshVideo(const SDL_Rect & rect); void processEvents(bool & quit); @@ -35,4 +35,7 @@ private: bool myFullscreen; Speed mySpeed; + + SDL_Rect myRect; + int myPitch; }; diff --git a/source/frontends/sa2/main.cpp b/source/frontends/sa2/main.cpp index 70269308..5f4f2951 100644 --- a/source/frontends/sa2/main.cpp +++ b/source/frontends/sa2/main.cpp @@ -269,13 +269,13 @@ void run_sdl(int argc, const char * argv []) // if this fails, should we throw, print something or just ignore? const auto redraw = [&emulator, res]{ - const auto rect = emulator.updateTexture(); + emulator.updateTexture(); if (res == 0) { - emulator.refreshVideo(rect); + emulator.refreshVideo(); } }; - const auto refresh = [&emulator, redraw]{ + const auto refresh = [redraw]{ NTSC_SetVideoMode( g_uVideoMode ); NTSC_VideoRedrawWholeScreen(); redraw(); @@ -338,7 +338,7 @@ void run_sdl(int argc, const char * argv []) } updateTextureTimer.tic(); - const SDL_Rect rect = emulator.updateTexture(); + emulator.updateTexture(); updateTextureTimer.toc(); if (!options.looseMutex) @@ -351,7 +351,7 @@ void run_sdl(int argc, const char * argv []) if (!options.headless) { refreshScreenTimer.tic(); - emulator.refreshVideo(rect); + emulator.refreshVideo(); refreshScreenTimer.toc(); } @@ -387,13 +387,13 @@ void run_sdl(int argc, const char * argv []) cpuTimer.toc(); updateTextureTimer.tic(); - const SDL_Rect rect = emulator.updateTexture(); + emulator.updateTexture(); updateTextureTimer.toc(); if (!options.headless) { refreshScreenTimer.tic(); - emulator.refreshVideo(rect); + emulator.refreshVideo(); refreshScreenTimer.toc(); } } while (!quit); diff --git a/source/linux/videobuffer.cpp b/source/linux/videobuffer.cpp index de56c7d9..e0d4ccc1 100644 --- a/source/linux/videobuffer.cpp +++ b/source/linux/videobuffer.cpp @@ -7,8 +7,11 @@ void VideoBufferInitialize() { + static_assert(sizeof(bgra_t) == 4, "Invalid size of bgra_t"); VideoResetState(); - g_pFramebufferbits = static_cast(calloc(sizeof(bgra_t), GetFrameBufferWidth() * GetFrameBufferHeight())); + + const int numberOfPixels = GetFrameBufferWidth() * GetFrameBufferHeight(); + g_pFramebufferbits = static_cast(calloc(sizeof(bgra_t), numberOfPixels)); NTSC_VideoInit(g_pFramebufferbits); } @@ -18,14 +21,3 @@ void VideoBufferDestroy() g_pFramebufferbits = nullptr; NTSC_Destroy(); } - -void getScreenData(uint8_t * & data, int & width, int & height, int & sx, int & sy, int & sw, int & sh) -{ - data = g_pFramebufferbits; - width = GetFrameBufferWidth(); - height = GetFrameBufferHeight(); - sx = GetFrameBufferBorderWidth(); - sy = GetFrameBufferBorderHeight(); - sw = GetFrameBufferBorderlessWidth(); - sh = GetFrameBufferBorderlessHeight(); -} diff --git a/source/linux/videobuffer.h b/source/linux/videobuffer.h index 71406245..9f56bb71 100644 --- a/source/linux/videobuffer.h +++ b/source/linux/videobuffer.h @@ -1,11 +1,7 @@ #pragma once -#include - // calls VideoResetState(); // and // initialises g_pFramebufferbits as a simple malloc'ed buffer void VideoBufferInitialize(); void VideoBufferDestroy(); - -void getScreenData(uint8_t * & data, int & width, int & height, int & sx, int & sy, int & sw, int & sh);