2026-03-04 22:51:35 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
2023-10-24 17:00:15 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
|
|
#include <android/native_window_jni.h>
|
2024-02-05 06:07:29 -05:00
|
|
|
#include "common/android/applets/software_keyboard.h"
|
2023-10-24 17:00:15 -04:00
|
|
|
#include "core/core.h"
|
2023-10-24 22:51:09 -04:00
|
|
|
#include "core/file_sys/registered_cache.h"
|
|
|
|
|
#include "core/hle/service/acc/profile_manager.h"
|
2023-10-24 17:00:15 -04:00
|
|
|
#include "core/perf_stats.h"
|
2024-01-19 00:56:43 -05:00
|
|
|
#include "frontend_common/content_manager.h"
|
2023-10-24 22:51:09 -04:00
|
|
|
#include "jni/emu_window/emu_window.h"
|
2023-10-24 17:00:15 -04:00
|
|
|
#include "video_core/rasterizer_interface.h"
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
class EmulationSession final {
|
|
|
|
|
public:
|
|
|
|
|
explicit EmulationSession();
|
|
|
|
|
~EmulationSession() = default;
|
|
|
|
|
|
|
|
|
|
static EmulationSession& GetInstance();
|
|
|
|
|
const Core::System& System() const;
|
|
|
|
|
Core::System& System();
|
2023-12-10 20:57:51 -05:00
|
|
|
FileSys::ManualContentProvider* GetContentProvider();
|
2024-02-16 21:19:17 -05:00
|
|
|
InputCommon::InputSubsystem& GetInputSubsystem();
|
2023-10-24 17:00:15 -04:00
|
|
|
|
|
|
|
|
const EmuWindow_Android& Window() const;
|
|
|
|
|
EmuWindow_Android& Window();
|
|
|
|
|
ANativeWindow* NativeWindow() const;
|
|
|
|
|
void SetNativeWindow(ANativeWindow* native_window);
|
|
|
|
|
void SurfaceChanged();
|
|
|
|
|
|
|
|
|
|
void InitializeGpuDriver(const std::string& hook_lib_dir, const std::string& custom_driver_dir,
|
|
|
|
|
const std::string& custom_driver_name,
|
|
|
|
|
const std::string& file_redirect_dir);
|
|
|
|
|
|
|
|
|
|
bool IsRunning() const;
|
|
|
|
|
bool IsPaused() const;
|
|
|
|
|
void PauseEmulation();
|
|
|
|
|
void UnPauseEmulation();
|
|
|
|
|
void HaltEmulation();
|
|
|
|
|
void RunEmulation();
|
|
|
|
|
void ShutdownEmulation();
|
|
|
|
|
|
2023-11-03 23:57:57 -04:00
|
|
|
const Core::PerfStatsResults& PerfStats();
|
2025-05-21 18:02:34 -04:00
|
|
|
int ShadersBuilding();
|
2023-10-24 17:00:15 -04:00
|
|
|
void ConfigureFilesystemProvider(const std::string& filepath);
|
2026-03-04 22:51:35 +01:00
|
|
|
void ConfigureFilesystemProviderFromGameFolder(const std::string& filepath);
|
2023-11-03 22:49:31 -04:00
|
|
|
void InitializeSystem(bool reload);
|
2024-01-02 18:26:53 -05:00
|
|
|
void SetAppletId(int applet_id);
|
2024-01-26 09:06:24 -05:00
|
|
|
Core::SystemResultStatus InitializeEmulation(const std::string& filepath,
|
2024-01-02 18:26:53 -05:00
|
|
|
const std::size_t program_index,
|
|
|
|
|
const bool frontend_initiated);
|
2023-10-24 17:00:15 -04:00
|
|
|
|
2024-02-05 06:07:29 -05:00
|
|
|
Common::Android::SoftwareKeyboard::AndroidKeyboard* SoftwareKeyboard();
|
2023-10-24 17:00:15 -04:00
|
|
|
|
2023-11-09 22:27:40 -05:00
|
|
|
static void OnEmulationStarted();
|
|
|
|
|
|
2023-12-10 20:27:50 -05:00
|
|
|
static u64 GetProgramId(JNIEnv* env, jstring jprogramId);
|
|
|
|
|
|
2023-10-24 17:00:15 -04:00
|
|
|
private:
|
|
|
|
|
static void LoadDiskCacheProgress(VideoCore::LoadCallbackStage stage, int progress, int max);
|
|
|
|
|
static void OnEmulationStopped(Core::SystemResultStatus result);
|
2024-01-26 09:06:24 -05:00
|
|
|
static void ChangeProgram(std::size_t program_index);
|
2023-10-24 17:00:15 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Window management
|
|
|
|
|
std::unique_ptr<EmuWindow_Android> m_window;
|
|
|
|
|
ANativeWindow* m_native_window{};
|
|
|
|
|
|
|
|
|
|
// Core emulation
|
|
|
|
|
Core::System m_system;
|
|
|
|
|
InputCommon::InputSubsystem m_input_subsystem;
|
|
|
|
|
Core::PerfStatsResults m_perf_stats{};
|
2025-05-21 18:02:34 -04:00
|
|
|
int m_shaders_building{0};
|
2023-10-24 17:00:15 -04:00
|
|
|
std::shared_ptr<FileSys::VfsFilesystem> m_vfs;
|
|
|
|
|
Core::SystemResultStatus m_load_result{Core::SystemResultStatus::ErrorNotInitialized};
|
|
|
|
|
std::atomic<bool> m_is_running = false;
|
|
|
|
|
std::atomic<bool> m_is_paused = false;
|
2024-02-05 06:07:29 -05:00
|
|
|
Common::Android::SoftwareKeyboard::AndroidKeyboard* m_software_keyboard{};
|
2023-10-24 17:00:15 -04:00
|
|
|
std::unique_ptr<FileSys::ManualContentProvider> m_manual_provider;
|
2024-01-02 18:26:53 -05:00
|
|
|
int m_applet_id{1};
|
2023-10-24 17:00:15 -04:00
|
|
|
|
|
|
|
|
// GPU driver parameters
|
|
|
|
|
std::shared_ptr<Common::DynamicLibrary> m_vulkan_library;
|
|
|
|
|
|
|
|
|
|
// Synchronization
|
|
|
|
|
std::condition_variable_any m_cv;
|
|
|
|
|
mutable std::mutex m_mutex;
|
2024-01-26 09:06:24 -05:00
|
|
|
|
|
|
|
|
// Program index for next boot
|
|
|
|
|
std::atomic<s32> m_next_program_index = -1;
|
2025-05-19 21:28:16 +00:00
|
|
|
};
|