Remove pointless getScreenData() and shed some nanoseconds from screen repaint.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
299c907be6
commit
861c87efd4
7 changed files with 57 additions and 76 deletions
|
@ -4,66 +4,58 @@
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
|
||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
#include "linux/videobuffer.h"
|
|
||||||
#include "linux/keyboard.h"
|
#include "linux/keyboard.h"
|
||||||
#include "linux/paddle.h"
|
#include "linux/paddle.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "CardManager.h"
|
#include "CardManager.h"
|
||||||
#include "MouseInterface.h"
|
#include "MouseInterface.h"
|
||||||
#include "Core.h"
|
#include "Core.h"
|
||||||
|
#include "Frame.h"
|
||||||
|
#include "Video.h"
|
||||||
|
|
||||||
Video::Video(QWidget *parent) : VIDEO_BASECLASS(parent)
|
Video::Video(QWidget *parent) : VIDEO_BASECLASS(parent)
|
||||||
{
|
{
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
|
|
||||||
myLogo = QImage(":/resources/APPLEWINLOGO.BMP").mirrored(false, 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
|
QImage Video::getScreen() const
|
||||||
{
|
{
|
||||||
uint8_t * data;
|
QImage frameBuffer = getScreenImage();
|
||||||
int width;
|
QImage screen = frameBuffer.copy(mySX, mySY, mySW, mySH);
|
||||||
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);
|
|
||||||
|
|
||||||
return screen;
|
return screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Video::displayLogo()
|
void Video::displayLogo()
|
||||||
{
|
{
|
||||||
uint8_t * data;
|
QImage frameBuffer = getScreenImage();
|
||||||
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);
|
|
||||||
|
|
||||||
QPainter painter(&frameBuffer);
|
QPainter painter(&frameBuffer);
|
||||||
painter.drawImage(sx, sy, myLogo);
|
painter.drawImage(mySX, mySY, myLogo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Video::paintEvent(QPaintEvent *)
|
void Video::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
uint8_t * data;
|
QImage frameBuffer = getScreenImage();
|
||||||
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);
|
|
||||||
|
|
||||||
const QSize actual = size();
|
const QSize actual = size();
|
||||||
const double scaleX = double(actual.width()) / sw;
|
const double scaleX = double(actual.width()) / mySW;
|
||||||
const double scaleY = double(actual.height()) / sh;
|
const double scaleY = double(actual.height()) / mySH;
|
||||||
|
|
||||||
// then paint it on the widget with scale
|
// 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());
|
const QTransform transform(scaleX, 0.0, 0.0, -scaleY, 0.0, actual.height());
|
||||||
painter.setTransform(transform);
|
painter.setTransform(transform);
|
||||||
|
|
||||||
painter.drawImage(0, 0, frameBuffer, sx, sy, sw, sh);
|
painter.drawImage(0, 0, frameBuffer, mySX, mySY, mySW, mySH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,15 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QImage myLogo;
|
QImage myLogo;
|
||||||
|
|
||||||
|
int mySX;
|
||||||
|
int mySY;
|
||||||
|
int mySW;
|
||||||
|
int mySH;
|
||||||
|
int myWidth;
|
||||||
|
int myHeight;
|
||||||
|
|
||||||
|
QImage getScreenImage() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VIDEO_H
|
#endif // VIDEO_H
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "linux/videobuffer.h"
|
#include "linux/videobuffer.h"
|
||||||
#include "linux/data.h"
|
|
||||||
#include "linux/paddle.h"
|
#include "linux/paddle.h"
|
||||||
#include "linux/keyboard.h"
|
#include "linux/keyboard.h"
|
||||||
|
|
||||||
|
@ -148,6 +147,11 @@ Emulator::Emulator(
|
||||||
, myFullscreen(false)
|
, myFullscreen(false)
|
||||||
, mySpeed(fixedSpeed)
|
, 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)
|
void Emulator::execute(const size_t next)
|
||||||
|
@ -165,29 +169,14 @@ void Emulator::execute(const size_t next)
|
||||||
SpkrUpdate(executedCycles);
|
SpkrUpdate(executedCycles);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Rect Emulator::updateTexture()
|
void Emulator::updateTexture()
|
||||||
{
|
{
|
||||||
uint8_t * data;
|
SDL_UpdateTexture(myTexture.get(), nullptr, g_pFramebufferbits, myPitch);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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());
|
SDL_RenderPresent(myRenderer.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,9 @@ public:
|
||||||
);
|
);
|
||||||
|
|
||||||
void execute(const size_t milliseconds);
|
void execute(const size_t milliseconds);
|
||||||
|
|
||||||
|
void updateTexture();
|
||||||
void refreshVideo();
|
void refreshVideo();
|
||||||
SDL_Rect updateTexture();
|
|
||||||
void refreshVideo(const SDL_Rect & rect);
|
|
||||||
|
|
||||||
void processEvents(bool & quit);
|
void processEvents(bool & quit);
|
||||||
|
|
||||||
|
@ -35,4 +35,7 @@ private:
|
||||||
bool myFullscreen;
|
bool myFullscreen;
|
||||||
|
|
||||||
Speed mySpeed;
|
Speed mySpeed;
|
||||||
|
|
||||||
|
SDL_Rect myRect;
|
||||||
|
int myPitch;
|
||||||
};
|
};
|
||||||
|
|
|
@ -269,13 +269,13 @@ void run_sdl(int argc, const char * argv [])
|
||||||
// if this fails, should we throw, print something or just ignore?
|
// if this fails, should we throw, print something or just ignore?
|
||||||
|
|
||||||
const auto redraw = [&emulator, res]{
|
const auto redraw = [&emulator, res]{
|
||||||
const auto rect = emulator.updateTexture();
|
emulator.updateTexture();
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
emulator.refreshVideo(rect);
|
emulator.refreshVideo();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto refresh = [&emulator, redraw]{
|
const auto refresh = [redraw]{
|
||||||
NTSC_SetVideoMode( g_uVideoMode );
|
NTSC_SetVideoMode( g_uVideoMode );
|
||||||
NTSC_VideoRedrawWholeScreen();
|
NTSC_VideoRedrawWholeScreen();
|
||||||
redraw();
|
redraw();
|
||||||
|
@ -338,7 +338,7 @@ void run_sdl(int argc, const char * argv [])
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTextureTimer.tic();
|
updateTextureTimer.tic();
|
||||||
const SDL_Rect rect = emulator.updateTexture();
|
emulator.updateTexture();
|
||||||
updateTextureTimer.toc();
|
updateTextureTimer.toc();
|
||||||
|
|
||||||
if (!options.looseMutex)
|
if (!options.looseMutex)
|
||||||
|
@ -351,7 +351,7 @@ void run_sdl(int argc, const char * argv [])
|
||||||
if (!options.headless)
|
if (!options.headless)
|
||||||
{
|
{
|
||||||
refreshScreenTimer.tic();
|
refreshScreenTimer.tic();
|
||||||
emulator.refreshVideo(rect);
|
emulator.refreshVideo();
|
||||||
refreshScreenTimer.toc();
|
refreshScreenTimer.toc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,13 +387,13 @@ void run_sdl(int argc, const char * argv [])
|
||||||
cpuTimer.toc();
|
cpuTimer.toc();
|
||||||
|
|
||||||
updateTextureTimer.tic();
|
updateTextureTimer.tic();
|
||||||
const SDL_Rect rect = emulator.updateTexture();
|
emulator.updateTexture();
|
||||||
updateTextureTimer.toc();
|
updateTextureTimer.toc();
|
||||||
|
|
||||||
if (!options.headless)
|
if (!options.headless)
|
||||||
{
|
{
|
||||||
refreshScreenTimer.tic();
|
refreshScreenTimer.tic();
|
||||||
emulator.refreshVideo(rect);
|
emulator.refreshVideo();
|
||||||
refreshScreenTimer.toc();
|
refreshScreenTimer.toc();
|
||||||
}
|
}
|
||||||
} while (!quit);
|
} while (!quit);
|
||||||
|
|
|
@ -7,8 +7,11 @@
|
||||||
|
|
||||||
void VideoBufferInitialize()
|
void VideoBufferInitialize()
|
||||||
{
|
{
|
||||||
|
static_assert(sizeof(bgra_t) == 4, "Invalid size of bgra_t");
|
||||||
VideoResetState();
|
VideoResetState();
|
||||||
g_pFramebufferbits = static_cast<uint8_t *>(calloc(sizeof(bgra_t), GetFrameBufferWidth() * GetFrameBufferHeight()));
|
|
||||||
|
const int numberOfPixels = GetFrameBufferWidth() * GetFrameBufferHeight();
|
||||||
|
g_pFramebufferbits = static_cast<uint8_t *>(calloc(sizeof(bgra_t), numberOfPixels));
|
||||||
NTSC_VideoInit(g_pFramebufferbits);
|
NTSC_VideoInit(g_pFramebufferbits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,14 +21,3 @@ void VideoBufferDestroy()
|
||||||
g_pFramebufferbits = nullptr;
|
g_pFramebufferbits = nullptr;
|
||||||
NTSC_Destroy();
|
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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
// calls VideoResetState();
|
// calls VideoResetState();
|
||||||
// and
|
// and
|
||||||
// initialises g_pFramebufferbits as a simple malloc'ed buffer
|
// initialises g_pFramebufferbits as a simple malloc'ed buffer
|
||||||
void VideoBufferInitialize();
|
void VideoBufferInitialize();
|
||||||
void VideoBufferDestroy();
|
void VideoBufferDestroy();
|
||||||
|
|
||||||
void getScreenData(uint8_t * & data, int & width, int & height, int & sx, int & sy, int & sw, int & sh);
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue