WinVideo: share some generic code (PR #901)

* WinVideo: move some generic functions back to Video.

Introduce a new virtual function (VideoPresentScreen) to draw the video buffer to video memory.

* Move Win32Frame::VideoRedrawScreen() to FrameBase as it is generic.
This commit is contained in:
Andrea 2020-12-29 21:30:17 +00:00 committed by GitHub
parent b226bdfd53
commit d0cd7ca090
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 79 additions and 83 deletions

View File

@ -1,6 +1,7 @@
#include "StdAfx.h"
#include "FrameBase.h"
#include "Interface.h"
FrameBase::FrameBase()
{
@ -15,3 +16,9 @@ FrameBase::~FrameBase()
{
}
void FrameBase::VideoRedrawScreen(void)
{
// NB. Can't rely on g_uVideoMode being non-zero (ie. so it can double up as a flag) since 'GR,PAGE1,non-mixed' mode == 0x00.
GetVideo().VideoRefreshScreen(GetVideo().GetVideoMode(), true);
}

View File

@ -13,13 +13,14 @@ public:
BOOL g_bMultiMon;
bool g_bFreshReset;
void VideoRedrawScreen();
virtual void FrameDrawDiskLEDS(HDC hdc) = 0;
virtual void FrameDrawDiskStatus(HDC hdc) = 0;
virtual void FrameRefreshStatus(int, bool bUpdateDiskStatus = true) = 0;
virtual void FrameUpdateApple2Type() = 0;
virtual void FrameSetCursorPosByMousePos() = 0;
virtual void VideoRedrawScreen() = 0;
virtual void SetFullScreenShowSubunitStatus(bool bShow) = 0;
virtual bool GetBestDisplayResolutionForFullScreen(UINT& bestWidth, UINT& bestHeight, UINT userSpecifiedHeight = 0) = 0;
virtual int SetViewportScale(int nNewScale, bool bForce = false) = 0;

View File

@ -620,7 +620,7 @@ void Video::Video_SaveScreenShot(const VideoScreenShot_e ScreenShotType, const T
//===========================================================================
bool Video::ReadVideoRomFile(const TCHAR* pRomFile)
bool Video::ReadVideoRomFile(const char* pRomFile)
{
g_videoRomSize = 0;
@ -830,3 +830,57 @@ const char* Video::VideoGetAppWindowTitle(void)
else
return apVideoMonitorModeDesc[ GetVideoRefreshRate() == VR_60HZ ? 0 : 1 ]; // NTSC or PAL
}
void Video::VideoRedrawScreenDuringFullSpeed(DWORD dwCyclesThisFrame, bool bInit /*=false*/)
{
if (bInit)
{
// Just entered full-speed mode
dwFullSpeedStartTime = GetTickCount();
return;
}
DWORD dwFullSpeedDuration = GetTickCount() - dwFullSpeedStartTime;
if (dwFullSpeedDuration <= 16) // Only update after every realtime ~17ms of *continuous* full-speed
return;
dwFullSpeedStartTime += dwFullSpeedDuration;
VideoRedrawScreenAfterFullSpeed(dwCyclesThisFrame);
}
void Video::VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame)
{
NTSC_VideoClockResync(dwCyclesThisFrame);
GetFrame().VideoRedrawScreen(); // Better (no flicker) than using: NTSC_VideoReinitialize() or VideoReinitialize()
}
void Video::Video_RedrawAndTakeScreenShot(const char* pScreenshotFilename)
{
_ASSERT(pScreenshotFilename);
if (!pScreenshotFilename)
return;
GetFrame().VideoRedrawScreen();
Video_SaveScreenShot(Video::SCREENSHOT_560x384, pScreenshotFilename);
}
void Video::VideoRefreshScreen(uint32_t uRedrawWholeScreenVideoMode, bool bRedrawWholeScreen)
{
if (bRedrawWholeScreen || g_nAppMode == MODE_PAUSED)
{
// uVideoModeForWholeScreen set if:
// . MODE_DEBUG : always
// . MODE_RUNNING : called from VideoRedrawScreen(), eg. during full-speed
if (bRedrawWholeScreen)
NTSC_SetVideoMode(uRedrawWholeScreenVideoMode);
NTSC_VideoRedrawWholeScreen();
// MODE_DEBUG|PAUSED: Need to refresh a 2nd time if changing video-type, otherwise could have residue from prev image!
// . eg. Amber -> B&W TV
if (g_nAppMode == MODE_DEBUG || g_nAppMode == MODE_PAUSED)
NTSC_VideoRedrawWholeScreen();
}
VideoPresentScreen();
}

View File

@ -210,14 +210,16 @@ public:
{
}
virtual void VideoRedrawScreenDuringFullSpeed(DWORD dwCyclesThisFrame, bool bInit = false) = 0;
virtual void VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame) = 0;
virtual void VideoRefreshScreen(uint32_t uRedrawWholeScreenVideoMode = 0, bool bRedrawWholeScreen = false) = 0;
virtual void Video_RedrawAndTakeScreenShot(const char* pScreenshotFilename) = 0;
virtual void VideoPresentScreen(void) = 0;
virtual void ChooseMonochromeColor(void) = 0;
virtual void Benchmark(void) = 0;
virtual void DisplayLogo(void) = 0;
void VideoRefreshScreen(uint32_t uRedrawWholeScreenVideoMode, bool bRedrawWholeScreen);
void VideoRedrawScreenDuringFullSpeed(DWORD dwCyclesThisFrame, bool bInit = false);
void VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame);
void Video_RedrawAndTakeScreenShot(const char* pScreenshotFilename);
uint8_t* GetFrameBuffer(void) { return g_pFramebufferbits; }
void SetFrameBuffer(uint8_t* frameBuffer) { g_pFramebufferbits = frameBuffer; }
@ -331,6 +333,8 @@ private:
UINT g_videoRomSize;
bool g_videoRomRockerSwitch;
DWORD dwFullSpeedStartTime;
static const char g_aVideoChoices[];
static const char m_szModeDesc0[];

View File

@ -253,7 +253,7 @@ static void ContinueExecution(void)
if (g_bFullSpeed)
GetVideo().VideoRedrawScreenDuringFullSpeed(g_dwCyclesThisFrame);
else
GetVideo().VideoRefreshScreen(); // Just copy the output of our Apple framebuffer to the system Back Buffer
GetVideo().VideoPresentScreen(); // Just copy the output of our Apple framebuffer to the system Back Buffer
}
#ifdef LOG_PERF_TIMINGS

View File

@ -11,7 +11,6 @@ public:
virtual void FrameUpdateApple2Type();
virtual void FrameSetCursorPosByMousePos();
virtual void VideoRedrawScreen();
virtual void SetFullScreenShowSubunitStatus(bool bShow);
virtual bool GetBestDisplayResolutionForFullScreen(UINT& bestWidth, UINT& bestHeight, UINT userSpecifiedHeight = 0);
virtual int SetViewportScale(int nNewScale, bool bForce = false);

View File

@ -1256,11 +1256,11 @@ LRESULT CALLBACK FrameWndProc (
if ( DebugGetVideoMode(&debugVideoMode) )
GetVideo().VideoRefreshScreen(debugVideoMode, true);
else
GetVideo().VideoRefreshScreen();
GetVideo().VideoPresentScreen();
}
else
{
GetVideo().VideoRefreshScreen();
GetVideo().VideoPresentScreen();
}
}

View File

@ -29,7 +29,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "StdAfx.h"
#include "Windows/WinVideo.h"
#include "Windows/Win32Frame.h"
#include "Windows/WinFrame.h"
#include "Windows/AppleWin.h"
#include "Interface.h"
@ -162,7 +161,7 @@ void WinVideo::Benchmark(void)
memset(mem+0x400,0x14,0x400);
else
memcpy(mem+0x400,mem+((cycle & 2) ? 0x4000 : 0x6000),0x400);
VideoRefreshScreen();
VideoPresentScreen();
if (cycle++ >= 3)
cycle = 0;
totaltextfps++;
@ -184,7 +183,7 @@ void WinVideo::Benchmark(void)
memset(mem+0x2000,0x14,0x2000);
else
memcpy(mem+0x2000,mem+((cycle & 2) ? 0x4000 : 0x6000),0x2000);
VideoRefreshScreen();
VideoPresentScreen();
if (cycle++ >= 3)
cycle = 0;
totalhiresfps++;
@ -421,53 +420,8 @@ void WinVideo::DisplayLogo(void)
//===========================================================================
void WinVideo::VideoRedrawScreenDuringFullSpeed(DWORD dwCyclesThisFrame, bool bInit /*=false*/)
void WinVideo::VideoPresentScreen(void)
{
static DWORD dwFullSpeedStartTime = 0;
if (bInit)
{
// Just entered full-speed mode
dwFullSpeedStartTime = GetTickCount();
return;
}
DWORD dwFullSpeedDuration = GetTickCount() - dwFullSpeedStartTime;
if (dwFullSpeedDuration <= 16) // Only update after every realtime ~17ms of *continuous* full-speed
return;
dwFullSpeedStartTime += dwFullSpeedDuration;
VideoRedrawScreenAfterFullSpeed(dwCyclesThisFrame);
}
//===========================================================================
void WinVideo::VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame)
{
NTSC_VideoClockResync(dwCyclesThisFrame);
GetFrame().VideoRedrawScreen(); // Better (no flicker) than using: NTSC_VideoReinitialize() or VideoReinitialize()
}
//===========================================================================
void WinVideo::VideoRefreshScreen(uint32_t uRedrawWholeScreenVideoMode /* =0*/, bool bRedrawWholeScreen /* =false*/)
{
if (bRedrawWholeScreen || g_nAppMode == MODE_PAUSED)
{
// uVideoModeForWholeScreen set if:
// . MODE_DEBUG : always
// . MODE_RUNNING : called from VideoRedrawScreen(), eg. during full-speed
if (bRedrawWholeScreen)
NTSC_SetVideoMode( uRedrawWholeScreenVideoMode );
NTSC_VideoRedrawWholeScreen();
// MODE_DEBUG|PAUSED: Need to refresh a 2nd time if changing video-type, otherwise could have residue from prev image!
// . eg. Amber -> B&W TV
if (g_nAppMode == MODE_DEBUG || g_nAppMode == MODE_PAUSED)
NTSC_VideoRedrawWholeScreen();
}
HDC hFrameDC = FrameGetDC();
if (hFrameDC)
@ -569,23 +523,3 @@ void WinVideo::DDUninit(void)
#undef SAFE_RELEASE
//===========================================================================
void WinVideo::Video_RedrawAndTakeScreenShot(const char* pScreenshotFilename)
{
_ASSERT(pScreenshotFilename);
if (!pScreenshotFilename)
return;
GetFrame().VideoRedrawScreen();
Video_SaveScreenShot(Video::SCREENSHOT_560x384, pScreenshotFilename);
}
//===========================================================================
//===========================================================================
// NB. Win32Frame, not WinVideo
void Win32Frame::VideoRedrawScreen(void)
{
// NB. Can't rely on g_uVideoMode being non-zero (ie. so it can double up as a flag) since 'GR,PAGE1,non-mixed' mode == 0x00.
GetVideo().VideoRefreshScreen( GetVideo().GetVideoMode(), true );
}

View File

@ -19,10 +19,7 @@ public:
virtual void Initialize(void);
virtual void Destroy(void);
virtual void VideoRedrawScreenDuringFullSpeed(DWORD dwCyclesThisFrame, bool bInit = false);
virtual void VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame);
virtual void VideoRefreshScreen(uint32_t uRedrawWholeScreenVideoMode = 0, bool bRedrawWholeScreen = false);
virtual void Video_RedrawAndTakeScreenShot(const char* pScreenshotFilename);
virtual void VideoPresentScreen(void);
virtual void ChooseMonochromeColor(void);
virtual void Benchmark(void);
virtual void DisplayLogo(void);