Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native OSK #5611

Merged
merged 11 commits into from Feb 2, 2019
63 changes: 42 additions & 21 deletions rpcs3/Emu/Cell/Modules/cellOskDialog.cpp
@@ -1,7 +1,8 @@
#include "stdafx.h"
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/RSX/Overlays/overlays.h"
#include "pad_thread.h"

#include "cellSysutil.h"
Expand Down Expand Up @@ -31,6 +32,39 @@ OskDialogBase::~OskDialogBase()
{
}

std::shared_ptr<OskDialogBase> _get_osk_dialog(bool always = false)
{
if (auto manager = fxm::get<rsx::overlays::display_manager>())
{
// NOTE: Osk lifetime is managed by fxm, not display manager
// Visibility is still managed by display manager
auto osk = fxm::get<rsx::overlays::osk_enUS>();
if (always)
{
if (!osk)
{
// Create if does not exist
osk = fxm::make<rsx::overlays::osk_enUS>();
}

// Attach to display manager forcefully
osk = manager->add(osk);
}

return osk;
}
else
{
auto osk = fxm::get<OskDialogBase>();
if (always && !osk)
{
return fxm::import<OskDialogBase>(Emu.GetCallbacks().get_osk_dialog);
}

return osk;
}
}

error_code cellOskDialogLoadAsync(u32 container, vm::ptr<CellOskDialogParam> dialogParam, vm::ptr<CellOskDialogInputFieldInfo> inputFieldInfo)
{
cellOskDialog.warning("cellOskDialogLoadAsync(container=0x%x, dialogParam=*0x%x, inputFieldInfo=*0x%x)", container, dialogParam, inputFieldInfo);
Expand All @@ -40,11 +74,7 @@ error_code cellOskDialogLoadAsync(u32 container, vm::ptr<CellOskDialogParam> dia
return CELL_OSKDIALOG_ERROR_PARAM;
}

auto osk = fxm::get<OskDialogBase>();
if (!osk)
{
osk = fxm::import<OskDialogBase>(Emu.GetCallbacks().get_osk_dialog);
}
auto osk = _get_osk_dialog(true);

// Can't open another dialog if this one is already open.
if (!osk || osk->state.load() == OskDialogState::Open)
Expand Down Expand Up @@ -85,7 +115,7 @@ error_code cellOskDialogLoadAsync(u32 container, vm::ptr<CellOskDialogParam> dia

bool result = false;

osk->on_close = [maxLength, wptr = std::weak_ptr<OskDialogBase>(osk)](s32 status)
osk->on_osk_close = [maxLength, wptr = std::weak_ptr<OskDialogBase>(osk)](s32 status)
kd-11 marked this conversation as resolved.
Show resolved Hide resolved
{
const auto osk = wptr.lock();

Expand Down Expand Up @@ -216,7 +246,7 @@ error_code getText(vm::ptr<CellOskDialogCallbackReturnParam> OutputInfo, bool is
return CELL_OSKDIALOG_ERROR_PARAM;
}

const auto osk = fxm::get<OskDialogBase>();
const auto osk = _get_osk_dialog();

if (!osk)
{
Expand Down Expand Up @@ -306,7 +336,7 @@ error_code cellOskDialogAbort()
{
cellOskDialog.warning("cellOskDialogAbort()");

const auto osk = fxm::get<OskDialogBase>();
const auto osk = _get_osk_dialog();

if (!osk)
{
Expand Down Expand Up @@ -358,12 +388,7 @@ error_code cellOskDialogSetSeparateWindowOption(vm::ptr<CellOskDialogSeparateWin
return CELL_OSKDIALOG_ERROR_PARAM;
}

auto osk = fxm::get<OskDialogBase>();
if (!osk)
{
osk = fxm::import<OskDialogBase>(Emu.GetCallbacks().get_osk_dialog);
}

auto osk = _get_osk_dialog(true);
osk->use_seperate_windows = true;
osk->osk_continuous_mode = (CellOskDialogContinuousMode)(u32)windowOption->continuousMode;

Expand Down Expand Up @@ -446,7 +471,7 @@ error_code cellOskDialogExtSendFinishMessage(u32 /*CellOskDialogFinishReason*/ f
{
cellOskDialog.warning("cellOskDialogExtSendFinishMessage(finishReason=%d)", finishReason);

const auto osk = fxm::get<OskDialogBase>();
const auto osk = _get_osk_dialog();

// Check for open dialog.
if (!osk || osk->state.load() != OskDialogState::Open)
Expand Down Expand Up @@ -492,11 +517,7 @@ error_code cellOskDialogExtRegisterConfirmWordFilterCallback(vm::ptr<cellOskDial
return CELL_OSKDIALOG_ERROR_PARAM;
}

auto osk = fxm::get<OskDialogBase>();
if (!osk)
{
osk = fxm::import<OskDialogBase>(Emu.GetCallbacks().get_osk_dialog);
}
auto osk = _get_osk_dialog(true);
osk->osk_confirm_callback = pCallback;

return CELL_OK;
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/Modules/cellOskDialog.h
@@ -1,4 +1,4 @@
#pragma once
#pragma once



Expand Down Expand Up @@ -247,7 +247,7 @@ class OskDialogBase
virtual void Close(bool accepted) = 0;
virtual ~OskDialogBase();

std::function<void(s32 status)> on_close;
std::function<void(s32 status)> on_osk_close;
std::function<void()> on_osk_input_entered;

atomic_t<OskDialogState> state{ OskDialogState::Close };
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/RSX/GL/GLGSRender.cpp
Expand Up @@ -946,7 +946,7 @@ void GLGSRender::on_init_thread()
struct native_helper : gl::shader_cache::progress_dialog_helper
{
rsx::thread *owner = nullptr;
rsx::overlays::message_dialog *dlg = nullptr;
std::shared_ptr<rsx::overlays::message_dialog> dlg;

native_helper(GLGSRender *ptr) :
owner(ptr) {}
Expand Down
7 changes: 5 additions & 2 deletions rpcs3/Emu/RSX/GL/GLOverlays.h
Expand Up @@ -348,13 +348,15 @@ namespace gl
"layout(location=0) out vec2 tc0;\n"
"layout(location=1) out vec4 clip_rect;\n"
"uniform vec4 ui_scale;\n"
"uniform vec2 viewport;\n"
"uniform vec4 clip_bounds;\n"
"\n"
"void main()\n"
"{\n"
" tc0.xy = in_pos.zw;\n"
" clip_rect = (clip_bounds * ui_scale.zwzw);\n"
" clip_rect.yw = ui_scale.yy - clip_rect.wy; //invert y axis\n"
" clip_rect = clip_bounds;\n"
" clip_rect.yw = ui_scale.yy - clip_rect.wy; // Invert y axis\n"
" clip_rect *= (ui_scale.zwzw * viewport.xyxy) / ui_scale.xyxy; // Normalize and convert to window coords\n"
" vec4 pos = vec4((in_pos.xy * ui_scale.zw) / ui_scale.xy, 0., 1.);\n"
" pos.y = (1. - pos.y); //invert y axis\n"
" gl_Position = (pos + pos) - 1.;\n"
Expand Down Expand Up @@ -581,6 +583,7 @@ namespace gl

void run(u16 w, u16 h, GLuint target, rsx::overlays::overlay& ui)
{
program_handle.uniforms["viewport"] = color2f(f32(w), f32(h));
program_handle.uniforms["ui_scale"] = color4f((f32)ui.virtual_width, (f32)ui.virtual_height, 1.f, 1.f);
program_handle.uniforms["time"] = (f32)(get_system_time() / 1000) * 0.005f;
for (auto &cmd : ui.get_compiled().draw_commands)
Expand Down