Display: Move listeners to separate HW file.

Mixing this in with the HLE management funcs was messy.
This commit is contained in:
Unknown W. Brackets 2022-01-30 09:41:08 -08:00
parent 9f9f86d468
commit ad2e380987
15 changed files with 139 additions and 62 deletions

View File

@ -1885,6 +1885,8 @@ add_library(${CoreLibName} ${CoreLinkType}
Core/HW/BufferQueue.h
Core/HW/Camera.cpp
Core/HW/Camera.h
Core/HW/Display.cpp
Core/HW/Display.h
Core/HW/MediaEngine.cpp
Core/HW/MediaEngine.h
Core/HW/MpegDemux.cpp

View File

@ -540,6 +540,7 @@
<ClCompile Include="HLE\sceUsbMic.cpp" />
<ClCompile Include="HW\BufferQueue.cpp" />
<ClCompile Include="HW\Camera.cpp" />
<ClCompile Include="HW\Display.cpp" />
<ClCompile Include="Instance.cpp" />
<ClCompile Include="KeyMap.cpp" />
<ClCompile Include="KeyMapDefaults.cpp" />
@ -1099,6 +1100,7 @@
<ClInclude Include="HLE\sceUsbCam.h" />
<ClInclude Include="HLE\sceUsbMic.h" />
<ClInclude Include="HW\Camera.h" />
<ClInclude Include="HW\Display.h" />
<ClInclude Include="Instance.h" />
<ClInclude Include="KeyMap.h" />
<ClInclude Include="KeyMapDefaults.h" />

View File

@ -1184,6 +1184,9 @@
<ClCompile Include="Debugger\WebSocket\GPUStatsSubscriber.cpp">
<Filter>Debugger\WebSocket</Filter>
</ClCompile>
<ClCompile Include="HW\Display.cpp">
<Filter>HW</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ELF\ElfReader.h">
@ -1910,6 +1913,9 @@
<ClInclude Include="Debugger\WebSocket\GPUStatsSubscriber.h">
<Filter>Debugger\WebSocket</Filter>
</ClInclude>
<ClInclude Include="HW\Display.h">
<Filter>HW</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="CMakeLists.txt" />

View File

@ -19,6 +19,7 @@
#include <vector>
#include "Core/Debugger/WebSocket/GPUStatsSubscriber.h"
#include "Core/HLE/sceDisplay.h"
#include "Core/HW/Display.h"
#include "Core/System.h"
struct CollectedStats {

View File

@ -20,18 +20,18 @@
#include "Common/Serialize/Serializer.h"
#include "Common/Serialize/SerializeFuncs.h"
#include "Core/CoreTiming.h"
#include "Core/HLE/HLE.h"
#include "Core/HLE/FunctionWrappers.h"
#include "Core/MIPS/MIPS.h"
#include "Core/CoreTiming.h"
#include "Core/MemMapHelpers.h"
#include "Core/Replay.h"
#include "Core/Util/AudioFormat.h" // for clamp_u8
#include "Core/HLE/sceCtrl.h"
#include "Core/HLE/sceDisplay.h"
#include "Core/HLE/sceKernel.h"
#include "Core/HLE/sceKernelThread.h"
#include "Core/HLE/sceKernelInterrupt.h"
#include "Core/HW/Display.h"
#include "Core/MemMapHelpers.h"
#include "Core/MIPS/MIPS.h"
#include "Core/Replay.h"
#include "Core/Util/AudioFormat.h" // for clamp_u8
/* Index for the two analog directions */
#define CTRL_ANALOG_X 0

View File

@ -47,6 +47,7 @@
#include "Core/HLE/sceKernel.h"
#include "Core/HLE/sceKernelThread.h"
#include "Core/HLE/sceKernelInterrupt.h"
#include "Core/HW/Display.h"
#include "Core/Util/PPGeDraw.h"
#include "GPU/GPU.h"
@ -130,12 +131,6 @@ std::map<SceUID, int> vblankPausedWaits;
// STATE END
// Called when vblank happens (like an internal interrupt.) Not part of state, should be static.
static std::mutex listenersLock;
static std::vector<VblankCallback> vblankListeners;
typedef std::pair<FlipCallback, void *> FlipListener;
static std::vector<FlipListener> flipListeners;
// The vblank period is 731.5 us (0.7315 ms)
const double vblankMs = 0.7315;
// These are guesses based on tests.
@ -198,6 +193,7 @@ static void ScheduleLagSync(int over = 0) {
}
void __DisplayInit() {
DisplayHWInit();
hasSetMode = false;
mode = 0;
resumeMode = 0;
@ -347,51 +343,10 @@ void __DisplayDoState(PointerWrap &p) {
}
void __DisplayShutdown() {
std::lock_guard<std::mutex> guard(listenersLock);
vblankListeners.clear();
flipListeners.clear();
DisplayHWShutdown();
vblankWaitingThreads.clear();
}
void __DisplayListenVblank(VblankCallback callback) {
std::lock_guard<std::mutex> guard(listenersLock);
vblankListeners.push_back(callback);
}
void __DisplayListenFlip(FlipCallback callback, void *userdata) {
std::lock_guard<std::mutex> guard(listenersLock);
flipListeners.push_back(std::make_pair(callback, userdata));
}
void __DisplayForgetFlip(FlipCallback callback, void *userdata) {
std::lock_guard<std::mutex> guard(listenersLock);
flipListeners.erase(std::remove_if(flipListeners.begin(), flipListeners.end(), [&](FlipListener item) {
return item.first == callback && item.second == userdata;
}), flipListeners.end());
}
static void DisplayFireVblank() {
std::vector<VblankCallback> toCall = []{
std::lock_guard<std::mutex> guard(listenersLock);
return vblankListeners;
}();
for (VblankCallback cb : toCall) {
cb();
}
}
static void DisplayFireFlip() {
std::vector<FlipListener> toCall = [] {
std::lock_guard<std::mutex> guard(listenersLock);
return flipListeners;
}();
for (FlipListener cb : toCall) {
cb.first(cb.second);
}
}
void __DisplayVblankBeginCallback(SceUID threadID, SceUID prevCallbackId) {
SceUID pauseKey = prevCallbackId == 0 ? threadID : prevCallbackId;

View File

@ -29,13 +29,6 @@ void Register_sceDisplay();
bool __DisplayGetFramebuf(PSPPointer<u8> *topaddr, u32 *linesize, u32 *pixelFormat, int mode);
void __DisplaySetFramebuf(u32 topaddr, int linesize, int pixelformat, int sync);
typedef void (*VblankCallback)();
// Listen for vblank events.
void __DisplayListenVblank(VblankCallback callback);
typedef void (*FlipCallback)(void *userdata);
void __DisplayListenFlip(FlipCallback callback, void *userdata);
void __DisplayForgetFlip(FlipCallback callback, void *userdata);
void __DisplayGetDebugStats(char stats[], size_t bufsize);
void __DisplayGetFPS(float *out_vps, float *out_fps, float *out_actual_fps);
void __DisplayGetVPS(float *out_vps);

View File

@ -42,9 +42,9 @@
#include "Core/HLE/HLE.h"
#include "Core/HLE/HLEHelperThread.h"
#include "Core/HLE/FunctionWrappers.h"
#include "Core/HLE/sceDisplay.h"
#include "Core/HLE/sceKernel.h"
#include "Core/HLE/sceUmd.h"
#include "Core/HW/Display.h"
#include "Core/MIPS/MIPS.h"
#include "Core/HW/MemoryStick.h"
#include "Core/HW/AsyncIOManager.h"

76
Core/HW/Display.cpp Normal file
View File

@ -0,0 +1,76 @@
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <algorithm>
#include <mutex>
#include <vector>
#include "Core/HW/Display.h"
// Called when vblank happens (like an internal interrupt.) Not part of state, should be static.
static std::mutex listenersLock;
static std::vector<VblankCallback> vblankListeners;
typedef std::pair<FlipCallback, void *> FlipListener;
static std::vector<FlipListener> flipListeners;
void DisplayFireVblank() {
std::vector<VblankCallback> toCall = [] {
std::lock_guard<std::mutex> guard(listenersLock);
return vblankListeners;
}();
for (VblankCallback cb : toCall) {
cb();
}
}
void DisplayFireFlip() {
std::vector<FlipListener> toCall = [] {
std::lock_guard<std::mutex> guard(listenersLock);
return flipListeners;
}();
for (FlipListener cb : toCall) {
cb.first(cb.second);
}
}
void __DisplayListenVblank(VblankCallback callback) {
std::lock_guard<std::mutex> guard(listenersLock);
vblankListeners.push_back(callback);
}
void __DisplayListenFlip(FlipCallback callback, void *userdata) {
std::lock_guard<std::mutex> guard(listenersLock);
flipListeners.push_back(std::make_pair(callback, userdata));
}
void __DisplayForgetFlip(FlipCallback callback, void *userdata) {
std::lock_guard<std::mutex> guard(listenersLock);
flipListeners.erase(std::remove_if(flipListeners.begin(), flipListeners.end(), [&](FlipListener item) {
return item.first == callback && item.second == userdata;
}), flipListeners.end());
}
void DisplayHWInit() {
}
void DisplayHWShutdown() {
std::lock_guard<std::mutex> guard(listenersLock);
vblankListeners.clear();
flipListeners.clear();
}

31
Core/HW/Display.h Normal file
View File

@ -0,0 +1,31 @@
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
typedef void (*VblankCallback)();
// Listen for vblank events.
void __DisplayListenVblank(VblankCallback callback);
typedef void (*FlipCallback)(void *userdata);
void __DisplayListenFlip(FlipCallback callback, void *userdata);
void __DisplayForgetFlip(FlipCallback callback, void *userdata);
void DisplayFireVblank();
void DisplayFireFlip();
void DisplayHWInit();
void DisplayHWShutdown();

View File

@ -71,6 +71,7 @@ using namespace std::placeholders;
#include "Core/HLE/__sceAudio.h"
#include "Core/HLE/proAdhoc.h"
#include "Core/HLE/Plugins.h"
#include "Core/HW/Display.h"
#include "UI/BackgroundAudio.h"
#include "UI/OnScreenDisplay.h"

View File

@ -520,6 +520,7 @@
<ClInclude Include="..\..\Core\HW\AsyncIOManager.h" />
<ClInclude Include="..\..\Core\HW\BufferQueue.h" />
<ClInclude Include="..\..\Core\HW\Camera.h" />
<ClInclude Include="..\..\Core\HW\Display.h" />
<ClInclude Include="..\..\Core\HW\MediaEngine.h" />
<ClInclude Include="..\..\Core\HW\MemoryStick.h" />
<ClInclude Include="..\..\Core\HW\MpegDemux.h" />
@ -752,6 +753,7 @@
<ClCompile Include="..\..\Core\HW\AsyncIOManager.cpp" />
<ClCompile Include="..\..\Core\HW\BufferQueue.cpp" />
<ClCompile Include="..\..\Core\HW\Camera.cpp" />
<ClCompile Include="..\..\Core\HW\Display.cpp" />
<ClCompile Include="..\..\Core\HW\MediaEngine.cpp" />
<ClCompile Include="..\..\Core\HW\MemoryStick.cpp" />
<ClCompile Include="..\..\Core\HW\MpegDemux.cpp" />

View File

@ -751,6 +751,9 @@
<ClCompile Include="..\..\Core\HW\Camera.cpp">
<Filter>HW</Filter>
</ClCompile>
<ClCompile Include="..\..\Core\HW\Display.cpp">
<Filter>HW</Filter>
</ClCompile>
<ClCompile Include="..\..\Core\Util\PortManager.cpp">
<Filter>Util</Filter>
</ClCompile>
@ -1733,6 +1736,9 @@
<ClInclude Include="..\..\Core\HW\Camera.h">
<Filter>HW</Filter>
</ClInclude>
<ClInclude Include="..\..\Core\HW\Display.h">
<Filter>HW</Filter>
</ClInclude>
<ClInclude Include="..\..\Core\Util\PortManager.h">
<Filter>Util</Filter>
</ClInclude>

View File

@ -383,6 +383,7 @@ EXEC_AND_LIB_FILES := \
$(SRC)/Core/HW/AsyncIOManager.cpp \
$(SRC)/Core/HW/BufferQueue.cpp \
$(SRC)/Core/HW/Camera.cpp \
$(SRC)/Core/HW/Display.cpp \
$(SRC)/Core/HW/MemoryStick.cpp \
$(SRC)/Core/HW/MpegDemux.cpp.arm \
$(SRC)/Core/HW/MediaEngine.cpp.arm \

View File

@ -550,6 +550,7 @@ SOURCES_CXX += \
$(COREDIR)/HLE/sceUsbGps.cpp \
$(COREDIR)/HW/BufferQueue.cpp \
$(COREDIR)/HW/Camera.cpp \
$(COREDIR)/HW/Display.cpp \
$(COREDIR)/HW/SimpleAudioDec.cpp \
$(COREDIR)/HW/AsyncIOManager.cpp \
$(COREDIR)/HW/MediaEngine.cpp \