summaryrefslogtreecommitdiff
path: root/src/core/hle/applets
diff options
context:
space:
mode:
authorGravatar Subv2015-05-26 11:00:26 -0500
committerGravatar Subv2015-07-11 21:47:23 -0500
commit621ee10eae0546d4ec3f9e911e113aa9ee609c22 (patch)
treeadfdc1cf9ae7e9ac9a5cf9950a91bbcfeb6cd552 /src/core/hle/applets
parentHLE/APT: Initial HLE support for applets. (diff)
downloadyuzu-621ee10eae0546d4ec3f9e911e113aa9ee609c22.tar.gz
yuzu-621ee10eae0546d4ec3f9e911e113aa9ee609c22.tar.xz
yuzu-621ee10eae0546d4ec3f9e911e113aa9ee609c22.zip
Applets: Add infrastructure to allow custom drawing and input handling in Applets.
Diffstat (limited to 'src/core/hle/applets')
-rw-r--r--src/core/hle/applets/applet.cpp38
-rw-r--r--src/core/hle/applets/applet.h43
-rw-r--r--src/core/hle/applets/swkbd.cpp45
-rw-r--r--src/core/hle/applets/swkbd.h16
4 files changed, 123 insertions, 19 deletions
diff --git a/src/core/hle/applets/applet.cpp b/src/core/hle/applets/applet.cpp
index 1f447e5fc..689f5adc8 100644
--- a/src/core/hle/applets/applet.cpp
+++ b/src/core/hle/applets/applet.cpp
@@ -5,15 +5,35 @@
5#include "common/assert.h" 5#include "common/assert.h"
6#include "common/logging/log.h" 6#include "common/logging/log.h"
7 7
8#include "core/core_timing.h"
8#include "core/hle/applets/applet.h" 9#include "core/hle/applets/applet.h"
9#include "core/hle/applets/swkbd.h" 10#include "core/hle/applets/swkbd.h"
10 11
11//////////////////////////////////////////////////////////////////////////////////////////////////// 12////////////////////////////////////////////////////////////////////////////////////////////////////
12 13
14// Specializes std::hash for AppletId, so that we can use it in std::unordered_map.
15// Workaround for libstdc++ bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60970
16namespace std {
17 template <>
18 struct hash<Service::APT::AppletId> {
19 typedef Service::APT::AppletId argument_type;
20 typedef std::size_t result_type;
21
22 result_type operator()(const argument_type& id_code) const {
23 typedef std::underlying_type<argument_type>::type Type;
24 return std::hash<Type>()(static_cast<Type>(id_code));
25 }
26 };
27}
28
13namespace HLE { 29namespace HLE {
14namespace Applets { 30namespace Applets {
15 31
16static std::unordered_map<Service::APT::AppletId, std::shared_ptr<Applet>> applets; 32static std::unordered_map<Service::APT::AppletId, std::shared_ptr<Applet>> applets;
33static u32 applet_update_event = -1; ///< The CoreTiming event identifier for the Applet update callback.
34/// The interval at which the Applet update callback will be called.
35static const u64 applet_update_interval_microseconds = 16666;
36std::shared_ptr<Applet> g_current_applet = nullptr; ///< The applet that is currently executing
17 37
18ResultCode Applet::Create(Service::APT::AppletId id) { 38ResultCode Applet::Create(Service::APT::AppletId id) {
19 switch (id) { 39 switch (id) {
@@ -36,5 +56,23 @@ std::shared_ptr<Applet> Applet::Get(Service::APT::AppletId id) {
36 return nullptr; 56 return nullptr;
37} 57}
38 58
59/// Handles updating the current Applet every time it's called.
60static void AppletUpdateEvent(u64, int cycles_late) {
61 if (g_current_applet && g_current_applet->IsRunning())
62 g_current_applet->Update();
63
64 CoreTiming::ScheduleEvent(usToCycles(applet_update_interval) - cycles_late,
65 applet_update_event);
66}
67
68void Init() {
69 applet_update_event = CoreTiming::RegisterEvent("HLE Applet Update Event", AppletUpdateEvent);
70 CoreTiming::ScheduleEvent(usToCycles(applet_update_interval), applet_update_event);
71}
72
73void Shutdown() {
74 CoreTiming::UnscheduleEvent(applet_update_event, 0);
75}
76
39} 77}
40} // namespace 78} // namespace
diff --git a/src/core/hle/applets/applet.h b/src/core/hle/applets/applet.h
index 221348d9c..f50f7d604 100644
--- a/src/core/hle/applets/applet.h
+++ b/src/core/hle/applets/applet.h
@@ -12,42 +12,59 @@
12namespace HLE { 12namespace HLE {
13namespace Applets { 13namespace Applets {
14 14
15class Applet { 15class Applet : public std::enable_shared_from_this<Applet> {
16public: 16public:
17 virtual ~Applet() {}; 17 virtual ~Applet() {};
18 Applet(Service::APT::AppletId id) : id(id) {}; 18 Applet(Service::APT::AppletId id) : id(id) {};
19 19
20 /** 20 /**
21 * Creates an instance of the Applet subclass identified by the parameter 21 * Creates an instance of the Applet subclass identified by the parameter.
22 * and stores it in a global map. 22 * and stores it in a global map.
23 * @param id Id of the applet to create 23 * @param id Id of the applet to create.
24 * @returns ResultCode Whether the operation was successful or not 24 * @returns ResultCode Whether the operation was successful or not.
25 */ 25 */
26 static ResultCode Create(Service::APT::AppletId id); 26 static ResultCode Create(Service::APT::AppletId id);
27 27
28 /** 28 /**
29 * Retrieves the Applet instance identified by the specified id 29 * Retrieves the Applet instance identified by the specified id.
30 * @param id Id of the Applet to retrieve 30 * @param id Id of the Applet to retrieve.
31 * @returns Requested Applet or nullptr if not found 31 * @returns Requested Applet or nullptr if not found.
32 */ 32 */
33 static std::shared_ptr<Applet> Get(Service::APT::AppletId id); 33 static std::shared_ptr<Applet> Get(Service::APT::AppletId id);
34 34
35 /** 35 /**
36 * Handles a parameter from the application 36 * Handles a parameter from the application.
37 * @param parameter Parameter data to handle 37 * @param parameter Parameter data to handle.
38 * @returns ResultCode Whether the operation was successful or not 38 * @returns ResultCode Whether the operation was successful or not.
39 */ 39 */
40 virtual ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) = 0; 40 virtual ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) = 0;
41 41
42 /** 42 /**
43 * Handles the Applet start event, triggered from the application 43 * Handles the Applet start event, triggered from the application.
44 * @param parameter Parameter data to handle 44 * @param parameter Parameter data to handle.
45 * @returns ResultCode Whether the operation was successful or not 45 * @returns ResultCode Whether the operation was successful or not.
46 */ 46 */
47 virtual ResultCode Start(Service::APT::AppletStartupParameter const& parameter) = 0; 47 virtual ResultCode Start(Service::APT::AppletStartupParameter const& parameter) = 0;
48 48
49 /**
50 * Whether the applet is currently executing instead of the host application or not.
51 */
52 virtual bool IsRunning() = 0;
53
54 /**
55 * Handles an update tick for the Applet, lets it update the screen, send commands, etc.
56 */
57 virtual void Update() = 0;
58
49 Service::APT::AppletId id; ///< Id of this Applet 59 Service::APT::AppletId id; ///< Id of this Applet
50}; 60};
51 61
62/// Initializes the HLE applets
63void Init();
64
65/// Shuts down the HLE applets
66void Shutdown();
67
68extern std::shared_ptr<Applet> g_current_applet; ///< Applet that is currently executing
52} 69}
53} // namespace 70} // namespace
diff --git a/src/core/hle/applets/swkbd.cpp b/src/core/hle/applets/swkbd.cpp
index 224aeb096..b800e0eb4 100644
--- a/src/core/hle/applets/swkbd.cpp
+++ b/src/core/hle/applets/swkbd.cpp
@@ -6,13 +6,16 @@
6#include "common/logging/log.h" 6#include "common/logging/log.h"
7 7
8#include "core/hle/applets/swkbd.h" 8#include "core/hle/applets/swkbd.h"
9#include "core/hle/service/hid/hid.h"
10#include "core/hle/service/gsp_gpu.h"
11#include "video_core/video_core.h"
9 12
10//////////////////////////////////////////////////////////////////////////////////////////////////// 13////////////////////////////////////////////////////////////////////////////////////////////////////
11 14
12namespace HLE { 15namespace HLE {
13namespace Applets { 16namespace Applets {
14 17
15SoftwareKeyboard::SoftwareKeyboard(Service::APT::AppletId id) : Applet(id) { 18SoftwareKeyboard::SoftwareKeyboard(Service::APT::AppletId id) : Applet(id), started(false) {
16 // Create the SharedMemory that will hold the framebuffer data 19 // Create the SharedMemory that will hold the framebuffer data
17 // TODO(Subv): What size should we use here? 20 // TODO(Subv): What size should we use here?
18 using Kernel::MemoryPermission; 21 using Kernel::MemoryPermission;
@@ -47,17 +50,45 @@ ResultCode SoftwareKeyboard::Start(Service::APT::AppletStartupParameter const& p
47 // TODO(Subv): Verify if this is the correct behavior 50 // TODO(Subv): Verify if this is the correct behavior
48 memset(text_memory->GetPointer(), 0, text_memory->size); 51 memset(text_memory->GetPointer(), 0, text_memory->size);
49 52
53 DrawScreenKeyboard();
54
55 // Update the current applet so we can get update events
56 started = true;
57 g_current_applet = shared_from_this();
58 return RESULT_SUCCESS;
59}
60
61void SoftwareKeyboard::Update() {
62 // TODO(Subv): Handle input using the touch events from the HID module
63
50 // TODO(Subv): Remove this hardcoded text 64 // TODO(Subv): Remove this hardcoded text
51 const wchar_t str[] = L"Subv"; 65 std::u16string text = Common::UTF8ToUTF16("Citra");
52 memcpy(text_memory->GetPointer(), str, 4 * sizeof(wchar_t)); 66 memcpy(text_memory->GetPointer(), text.c_str(), text.length() * sizeof(char16_t));
53 67
54 // TODO(Subv): Ask for input and write it to the shared memory 68 // TODO(Subv): Ask for input and write it to the shared memory
55 // TODO(Subv): Find out what are the possible values for the return code, 69 // TODO(Subv): Find out what are the possible values for the return code,
56 // some games seem to check for a hardcoded 2 70 // some games seem to check for a hardcoded 2
57 config.return_code = 2; 71 config.return_code = 2;
58 config.text_length = 5; 72 config.text_length = 6;
59 config.text_offset = 0; 73 config.text_offset = 0;
60 74
75 // TODO(Subv): We're finalizing the applet immediately after it's started,
76 // but we should defer this call until after all the input has been collected.
77 Finalize();
78}
79
80void SoftwareKeyboard::DrawScreenKeyboard() {
81 auto bottom_screen = GSP_GPU::GetFrameBufferInfo(0, 1);
82 auto info = bottom_screen->framebuffer_info[bottom_screen->index];
83
84 // TODO(Subv): Draw the HLE keyboard, for now just zero-fill the framebuffer
85 memset(Memory::GetPointer(info.address_left), 0, info.stride * 320);
86
87 GSP_GPU::SetBufferSwap(1, info);
88}
89
90void SoftwareKeyboard::Finalize() {
91 // Let the application know that we're closing
61 Service::APT::MessageParameter message; 92 Service::APT::MessageParameter message;
62 message.buffer_size = sizeof(SoftwareKeyboardConfig); 93 message.buffer_size = sizeof(SoftwareKeyboardConfig);
63 message.data = reinterpret_cast<u8*>(&config); 94 message.data = reinterpret_cast<u8*>(&config);
@@ -66,7 +97,9 @@ ResultCode SoftwareKeyboard::Start(Service::APT::AppletStartupParameter const& p
66 message.sender_id = static_cast<u32>(id); 97 message.sender_id = static_cast<u32>(id);
67 Service::APT::SendParameter(message); 98 Service::APT::SendParameter(message);
68 99
69 return RESULT_SUCCESS; 100 started = false;
101 // Unset the current applet, we are not running anymore
102 g_current_applet = nullptr;
70} 103}
71 104
72} 105}
diff --git a/src/core/hle/applets/swkbd.h b/src/core/hle/applets/swkbd.h
index d7199690c..5970390c6 100644
--- a/src/core/hle/applets/swkbd.h
+++ b/src/core/hle/applets/swkbd.h
@@ -51,6 +51,19 @@ public:
51 51
52 ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) override; 52 ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) override;
53 ResultCode Start(Service::APT::AppletStartupParameter const& parameter) override; 53 ResultCode Start(Service::APT::AppletStartupParameter const& parameter) override;
54 void Update() override;
55 bool IsRunning() override { return started; }
56
57 /**
58 * Draws a keyboard to the current bottom screen framebuffer.
59 */
60 void DrawScreenKeyboard();
61
62 /**
63 * Sends the LibAppletClosing signal to the application,
64 * along with the relevant data buffers.
65 */
66 void Finalize();
54 67
55 /// TODO(Subv): Find out what this is actually used for. 68 /// TODO(Subv): Find out what this is actually used for.
56 // It is believed that the application stores the current screen image here. 69 // It is believed that the application stores the current screen image here.
@@ -61,6 +74,9 @@ public:
61 74
62 /// Configuration of this instance of the SoftwareKeyboard, as received from the application 75 /// Configuration of this instance of the SoftwareKeyboard, as received from the application
63 SoftwareKeyboardConfig config; 76 SoftwareKeyboardConfig config;
77
78 /// Whether this applet is currently running instead of the host application or not.
79 bool started;
64}; 80};
65 81
66} 82}