From a8b020b1531c4baa8485ac6b6df3d704bf6ede34 Mon Sep 17 00:00:00 2001
From: georgemoralis <giorgosmrls@gmail.com>
Date: Tue, 22 Aug 2023 00:54:44 +0300
Subject: [PATCH] initial video out context object

---
 CMakeLists.txt                                |  2 +-
 .../HLE/Graphics/Objects/video_out_ctx.cpp    | 14 ++++++++++
 .../PS4/HLE/Graphics/Objects/video_out_ctx.h  | 27 +++++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp
 create mode 100644 src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 68236dd7..bd04dbdb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -52,7 +52,7 @@ add_executable(shadps4
     src/Core/PS4/HLE/Kernel/event_queues.h
     src/Core/PS4/HLE/Kernel/cpu_management.cpp
     src/Core/PS4/HLE/Kernel/cpu_management.h
-     "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/Core/PS4/HLE/Kernel/memory_management.cpp" "src/Core/PS4/HLE/Kernel/memory_management.h" "src/Core/PS4/GPU/gpu_memory.cpp" "src/Core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h"  "src/Core/PS4/HLE/Kernel/Objects/event_queue.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.cpp")
+     "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/Core/PS4/HLE/Kernel/memory_management.cpp" "src/Core/PS4/HLE/Kernel/memory_management.h" "src/Core/PS4/GPU/gpu_memory.cpp" "src/Core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h"  "src/Core/PS4/HLE/Kernel/Objects/event_queue.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h")
 
 find_package(OpenGL REQUIRED)
 target_link_libraries(shadps4 PUBLIC fmt mincore spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY})
diff --git a/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp b/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp
new file mode 100644
index 00000000..de9e81de
--- /dev/null
+++ b/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp
@@ -0,0 +1,14 @@
+#include "video_out_ctx.h"
+
+namespace HLE::Graphics::Objects {
+
+void VideoOutCtx::Init(u32 width, u32 height) {
+    for (auto& video_ctx : m_video_out_ctx) {
+        video_ctx.m_resolution.fullWidth = width;
+        video_ctx.m_resolution.fullHeight = height;
+        video_ctx.m_resolution.paneWidth = width;
+        video_ctx.m_resolution.paneHeight = height;
+    }
+}
+void VideoOutCtx::Open() {}
+};  // namespace HLE::Graphics::Objects
\ No newline at end of file
diff --git a/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h b/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h
new file mode 100644
index 00000000..9c5fd9db
--- /dev/null
+++ b/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h
@@ -0,0 +1,27 @@
+#pragma once
+#include <Core/PS4/HLE/Graphics/video_out.h>
+#include <Lib/Threads.h>
+
+using namespace HLE::Libs::Graphics::VideoOut;
+
+namespace HLE::Graphics::Objects {
+
+struct VideoConfigInternal {
+    Lib::Mutex m_mutex;
+    SceVideoOutResolutionStatus m_resolution;
+    bool isOpened = false;
+};
+
+class VideoOutCtx {
+    static constexpr int MAX_VIDEO_OUT = 2;
+
+  public:
+    VideoOutCtx() {}
+    virtual ~VideoOutCtx() {}
+    void Init(u32 width, u32 height);
+    void Open();
+  private:
+    Lib::Mutex m_mutex;
+    VideoConfigInternal m_video_out_ctx[MAX_VIDEO_OUT];
+};
+};  // namespace HLE::Graphics::Objects
\ No newline at end of file