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 "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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <iostream>
|
||||
|
||||
#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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -7,8 +7,11 @@
|
|||
|
||||
void VideoBufferInitialize()
|
||||
{
|
||||
static_assert(sizeof(bgra_t) == 4, "Invalid size of bgra_t");
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// 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);
|
||||
|
|
Loading…
Add table
Reference in a new issue