Skip to content

Commit

Permalink
Display: Move listeners to separate HW file.
Browse files Browse the repository at this point in the history
Mixing this in with the HLE management funcs was messy.
  • Loading branch information
unknownbrackets committed Jan 30, 2022
1 parent 9f9f86d commit ad2e380
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 62 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -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" />
Expand Down
6 changes: 6 additions & 0 deletions Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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" />
Expand Down
1 change: 1 addition & 0 deletions Core/Debugger/WebSocket/GPUStatsSubscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions Core/HLE/sceCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 3 additions & 48 deletions Core/HLE/sceDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -198,6 +193,7 @@ static void ScheduleLagSync(int over = 0) {
}

void __DisplayInit() {
DisplayHWInit();
hasSetMode = false;
mode = 0;
resumeMode = 0;
Expand Down Expand Up @@ -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;

Expand Down
7 changes: 0 additions & 7 deletions Core/HLE/sceDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/sceIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
76 changes: 76 additions & 0 deletions Core/HW/Display.cpp
Original file line number Diff line number Diff line change
@@ -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 changes: 31 additions & 0 deletions Core/HW/Display.h
Original file line number Diff line number Diff line change
@@ -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();
1 change: 1 addition & 0 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions UWP/CoreUWP/CoreUWP.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -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" />
Expand Down
6 changes: 6 additions & 0 deletions UWP/CoreUWP/CoreUWP.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions android/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions libretro/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit ad2e380

Please sign in to comment.