| 1 | // Copyright 2021 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #ifdef HAS_LIBMGBA |
| 5 | |
| 6 | #include "DolphinQt/GBAHost.h" |
| 7 | |
| 8 | #include <QApplication> |
| 9 | |
| 10 | #include "Core/HW/GBACore.h" |
| 11 | #include "DolphinQt/GBAWidget.h" |
| 12 | #include "DolphinQt/QtUtils/QueueOnObject.h" |
| 13 | |
| 14 | GBAHost::GBAHost(std::weak_ptr<HW::GBA::Core> core) |
| 15 | { |
| 16 | m_widget_controller = new GBAWidgetController(); |
| 17 | m_widget_controller->moveToThread(qApp->thread()); |
| 18 | m_core = std::move(core); |
| 19 | auto core_ptr = m_core.lock(); |
| 20 | HW::GBA::CoreInfo info = core_ptr->GetCoreInfo(); |
| 21 | QueueOnObject(m_widget_controller, [widget_controller = m_widget_controller, core = m_core, |
| 22 | info] { widget_controller->Create(core, info); }); |
| 23 | } |
| 24 | |
| 25 | GBAHost::~GBAHost() |
| 26 | { |
| 27 | m_widget_controller->deleteLater(); |
| 28 | } |
| 29 | |
| 30 | void GBAHost::GameChanged() |
| 31 | { |
| 32 | auto core_ptr = m_core.lock(); |
| 33 | if (!core_ptr || !core_ptr->IsStarted()) |
| 34 | return; |
| 35 | HW::GBA::CoreInfo info = core_ptr->GetCoreInfo(); |
| 36 | QueueOnObject(m_widget_controller, [widget_controller = m_widget_controller, info] { |
| 37 | widget_controller->GameChanged(info); |
| 38 | }); |
| 39 | } |
| 40 | |
| 41 | void GBAHost::FrameEnded(std::span<const u32> video_buffer) |
| 42 | { |
| 43 | QueueOnObject(m_widget_controller, [widget_controller = m_widget_controller, video_buffer] { |
| 44 | widget_controller->FrameEnded(video_buffer); |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | std::unique_ptr<GBAHostInterface> Host_CreateGBAHost(std::weak_ptr<HW::GBA::Core> core) |
| 49 | { |
| 50 | return std::make_unique<GBAHost>(core); |
| 51 | } |
| 52 | #endif // HAS_LIBMGBA |