Applets: Add infrastructure to allow custom drawing and input handling in Applets.
This commit is contained in:
parent
2a6ebadf66
commit
621ee10eae
7 changed files with 162 additions and 39 deletions
|
@ -5,15 +5,35 @@
|
|||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hle/applets/applet.h"
|
||||
#include "core/hle/applets/swkbd.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Specializes std::hash for AppletId, so that we can use it in std::unordered_map.
|
||||
// Workaround for libstdc++ bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60970
|
||||
namespace std {
|
||||
template <>
|
||||
struct hash<Service::APT::AppletId> {
|
||||
typedef Service::APT::AppletId argument_type;
|
||||
typedef std::size_t result_type;
|
||||
|
||||
result_type operator()(const argument_type& id_code) const {
|
||||
typedef std::underlying_type<argument_type>::type Type;
|
||||
return std::hash<Type>()(static_cast<Type>(id_code));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace HLE {
|
||||
namespace Applets {
|
||||
|
||||
static std::unordered_map<Service::APT::AppletId, std::shared_ptr<Applet>> applets;
|
||||
static u32 applet_update_event = -1; ///< The CoreTiming event identifier for the Applet update callback.
|
||||
/// The interval at which the Applet update callback will be called.
|
||||
static const u64 applet_update_interval_microseconds = 16666;
|
||||
std::shared_ptr<Applet> g_current_applet = nullptr; ///< The applet that is currently executing
|
||||
|
||||
ResultCode Applet::Create(Service::APT::AppletId id) {
|
||||
switch (id) {
|
||||
|
@ -36,5 +56,23 @@ std::shared_ptr<Applet> Applet::Get(Service::APT::AppletId id) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
/// Handles updating the current Applet every time it's called.
|
||||
static void AppletUpdateEvent(u64, int cycles_late) {
|
||||
if (g_current_applet && g_current_applet->IsRunning())
|
||||
g_current_applet->Update();
|
||||
|
||||
CoreTiming::ScheduleEvent(usToCycles(applet_update_interval) - cycles_late,
|
||||
applet_update_event);
|
||||
}
|
||||
|
||||
void Init() {
|
||||
applet_update_event = CoreTiming::RegisterEvent("HLE Applet Update Event", AppletUpdateEvent);
|
||||
CoreTiming::ScheduleEvent(usToCycles(applet_update_interval), applet_update_event);
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
CoreTiming::UnscheduleEvent(applet_update_event, 0);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
@ -12,42 +12,59 @@
|
|||
namespace HLE {
|
||||
namespace Applets {
|
||||
|
||||
class Applet {
|
||||
class Applet : public std::enable_shared_from_this<Applet> {
|
||||
public:
|
||||
virtual ~Applet() {};
|
||||
Applet(Service::APT::AppletId id) : id(id) {};
|
||||
|
||||
/**
|
||||
* Creates an instance of the Applet subclass identified by the parameter
|
||||
* Creates an instance of the Applet subclass identified by the parameter.
|
||||
* and stores it in a global map.
|
||||
* @param id Id of the applet to create
|
||||
* @returns ResultCode Whether the operation was successful or not
|
||||
* @param id Id of the applet to create.
|
||||
* @returns ResultCode Whether the operation was successful or not.
|
||||
*/
|
||||
static ResultCode Create(Service::APT::AppletId id);
|
||||
|
||||
/**
|
||||
* Retrieves the Applet instance identified by the specified id
|
||||
* @param id Id of the Applet to retrieve
|
||||
* @returns Requested Applet or nullptr if not found
|
||||
* Retrieves the Applet instance identified by the specified id.
|
||||
* @param id Id of the Applet to retrieve.
|
||||
* @returns Requested Applet or nullptr if not found.
|
||||
*/
|
||||
static std::shared_ptr<Applet> Get(Service::APT::AppletId id);
|
||||
|
||||
/**
|
||||
* Handles a parameter from the application
|
||||
* @param parameter Parameter data to handle
|
||||
* @returns ResultCode Whether the operation was successful or not
|
||||
* Handles a parameter from the application.
|
||||
* @param parameter Parameter data to handle.
|
||||
* @returns ResultCode Whether the operation was successful or not.
|
||||
*/
|
||||
virtual ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) = 0;
|
||||
|
||||
/**
|
||||
* Handles the Applet start event, triggered from the application
|
||||
* @param parameter Parameter data to handle
|
||||
* @returns ResultCode Whether the operation was successful or not
|
||||
* Handles the Applet start event, triggered from the application.
|
||||
* @param parameter Parameter data to handle.
|
||||
* @returns ResultCode Whether the operation was successful or not.
|
||||
*/
|
||||
virtual ResultCode Start(Service::APT::AppletStartupParameter const& parameter) = 0;
|
||||
|
||||
/**
|
||||
* Whether the applet is currently executing instead of the host application or not.
|
||||
*/
|
||||
virtual bool IsRunning() = 0;
|
||||
|
||||
/**
|
||||
* Handles an update tick for the Applet, lets it update the screen, send commands, etc.
|
||||
*/
|
||||
virtual void Update() = 0;
|
||||
|
||||
Service::APT::AppletId id; ///< Id of this Applet
|
||||
};
|
||||
|
||||
/// Initializes the HLE applets
|
||||
void Init();
|
||||
|
||||
/// Shuts down the HLE applets
|
||||
void Shutdown();
|
||||
|
||||
extern std::shared_ptr<Applet> g_current_applet; ///< Applet that is currently executing
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
@ -6,13 +6,16 @@
|
|||
#include "common/logging/log.h"
|
||||
|
||||
#include "core/hle/applets/swkbd.h"
|
||||
#include "core/hle/service/hid/hid.h"
|
||||
#include "core/hle/service/gsp_gpu.h"
|
||||
#include "video_core/video_core.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace HLE {
|
||||
namespace Applets {
|
||||
|
||||
SoftwareKeyboard::SoftwareKeyboard(Service::APT::AppletId id) : Applet(id) {
|
||||
SoftwareKeyboard::SoftwareKeyboard(Service::APT::AppletId id) : Applet(id), started(false) {
|
||||
// Create the SharedMemory that will hold the framebuffer data
|
||||
// TODO(Subv): What size should we use here?
|
||||
using Kernel::MemoryPermission;
|
||||
|
@ -47,17 +50,45 @@ ResultCode SoftwareKeyboard::Start(Service::APT::AppletStartupParameter const& p
|
|||
// TODO(Subv): Verify if this is the correct behavior
|
||||
memset(text_memory->GetPointer(), 0, text_memory->size);
|
||||
|
||||
DrawScreenKeyboard();
|
||||
|
||||
// Update the current applet so we can get update events
|
||||
started = true;
|
||||
g_current_applet = shared_from_this();
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void SoftwareKeyboard::Update() {
|
||||
// TODO(Subv): Handle input using the touch events from the HID module
|
||||
|
||||
// TODO(Subv): Remove this hardcoded text
|
||||
const wchar_t str[] = L"Subv";
|
||||
memcpy(text_memory->GetPointer(), str, 4 * sizeof(wchar_t));
|
||||
|
||||
std::u16string text = Common::UTF8ToUTF16("Citra");
|
||||
memcpy(text_memory->GetPointer(), text.c_str(), text.length() * sizeof(char16_t));
|
||||
|
||||
// TODO(Subv): Ask for input and write it to the shared memory
|
||||
// TODO(Subv): Find out what are the possible values for the return code,
|
||||
// some games seem to check for a hardcoded 2
|
||||
config.return_code = 2;
|
||||
config.text_length = 5;
|
||||
config.text_length = 6;
|
||||
config.text_offset = 0;
|
||||
|
||||
// TODO(Subv): We're finalizing the applet immediately after it's started,
|
||||
// but we should defer this call until after all the input has been collected.
|
||||
Finalize();
|
||||
}
|
||||
|
||||
void SoftwareKeyboard::DrawScreenKeyboard() {
|
||||
auto bottom_screen = GSP_GPU::GetFrameBufferInfo(0, 1);
|
||||
auto info = bottom_screen->framebuffer_info[bottom_screen->index];
|
||||
|
||||
// TODO(Subv): Draw the HLE keyboard, for now just zero-fill the framebuffer
|
||||
memset(Memory::GetPointer(info.address_left), 0, info.stride * 320);
|
||||
|
||||
GSP_GPU::SetBufferSwap(1, info);
|
||||
}
|
||||
|
||||
void SoftwareKeyboard::Finalize() {
|
||||
// Let the application know that we're closing
|
||||
Service::APT::MessageParameter message;
|
||||
message.buffer_size = sizeof(SoftwareKeyboardConfig);
|
||||
message.data = reinterpret_cast<u8*>(&config);
|
||||
|
@ -66,7 +97,9 @@ ResultCode SoftwareKeyboard::Start(Service::APT::AppletStartupParameter const& p
|
|||
message.sender_id = static_cast<u32>(id);
|
||||
Service::APT::SendParameter(message);
|
||||
|
||||
return RESULT_SUCCESS;
|
||||
started = false;
|
||||
// Unset the current applet, we are not running anymore
|
||||
g_current_applet = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,6 +51,19 @@ public:
|
|||
|
||||
ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) override;
|
||||
ResultCode Start(Service::APT::AppletStartupParameter const& parameter) override;
|
||||
void Update() override;
|
||||
bool IsRunning() override { return started; }
|
||||
|
||||
/**
|
||||
* Draws a keyboard to the current bottom screen framebuffer.
|
||||
*/
|
||||
void DrawScreenKeyboard();
|
||||
|
||||
/**
|
||||
* Sends the LibAppletClosing signal to the application,
|
||||
* along with the relevant data buffers.
|
||||
*/
|
||||
void Finalize();
|
||||
|
||||
/// TODO(Subv): Find out what this is actually used for.
|
||||
// It is believed that the application stores the current screen image here.
|
||||
|
@ -61,6 +74,9 @@ public:
|
|||
|
||||
/// Configuration of this instance of the SoftwareKeyboard, as received from the application
|
||||
SoftwareKeyboardConfig config;
|
||||
|
||||
/// Whether this applet is currently running instead of the host application or not.
|
||||
bool started;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue