mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-04 10:32:15 +02:00
Simplify nv
This commit is contained in:
parent
fd7db563ee
commit
12e1d92412
@ -47,6 +47,7 @@ struct AppletHookCookie
|
|||||||
Result appletInitialize(void);
|
Result appletInitialize(void);
|
||||||
void appletExit(void);
|
void appletExit(void);
|
||||||
Result appletGetAppletResourceUserId(u64 *out);
|
Result appletGetAppletResourceUserId(u64 *out);
|
||||||
|
AppletType appletGetAppletType(void);
|
||||||
|
|
||||||
void appletNotifyRunning(u8 *out);
|
void appletNotifyRunning(u8 *out);
|
||||||
Result appletCreateManagedDisplayLayer(u64 *out);
|
Result appletCreateManagedDisplayLayer(u64 *out);
|
||||||
|
@ -7,15 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../types.h"
|
#include "../types.h"
|
||||||
|
|
||||||
typedef enum {
|
Result nvInitialize(size_t sharedmem_size);
|
||||||
NVSERVTYPE_Default = -1,
|
|
||||||
NVSERVTYPE_Application = 0,
|
|
||||||
NVSERVTYPE_Applet = 1,
|
|
||||||
NVSERVTYPE_Sysmodule = 2,
|
|
||||||
NVSERVTYPE_T = 3,
|
|
||||||
} nvServiceType;
|
|
||||||
|
|
||||||
Result nvInitialize(nvServiceType servicetype, size_t sharedmem_size);
|
|
||||||
void nvExit(void);
|
void nvExit(void);
|
||||||
|
|
||||||
Result nvOpen(u32 *fd, const char *devicepath);
|
Result nvOpen(u32 *fd, const char *devicepath);
|
||||||
|
@ -166,7 +166,7 @@ static Result _gfxQueueBuffer(s32 buf) {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result _gfxInit(ViServiceType servicetype, const char *DisplayName, u32 LayerFlags, u64 LayerId, nvServiceType nv_servicetype, size_t nv_transfermem_size) {
|
static Result _gfxInit(ViServiceType servicetype, const char *DisplayName, u32 LayerFlags, u64 LayerId, size_t nv_transfermem_size) {
|
||||||
Result rc=0;
|
Result rc=0;
|
||||||
u32 i=0;
|
u32 i=0;
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ static Result _gfxInit(ViServiceType servicetype, const char *DisplayName, u32 L
|
|||||||
rc = binderInitSession(&g_gfxBinderSession, 0x0f);
|
rc = binderInitSession(&g_gfxBinderSession, 0x0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) rc = nvInitialize(nv_servicetype, nv_transfermem_size);
|
if (R_SUCCEEDED(rc)) rc = nvInitialize(nv_transfermem_size);
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) rc = bqInitialize(&g_gfxBinderSession);
|
if (R_SUCCEEDED(rc)) rc = bqInitialize(&g_gfxBinderSession);
|
||||||
|
|
||||||
@ -326,25 +326,8 @@ static Result _gfxInit(ViServiceType servicetype, const char *DisplayName, u32 L
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result gfxInitDefault(void)
|
Result gfxInitDefault(void) {
|
||||||
{
|
return _gfxInit(ViServiceType_Default, "Default", ViLayerFlags_Default, 0, 0x300000);
|
||||||
nvServiceType nv_servicetype;
|
|
||||||
|
|
||||||
switch(__nx_applet_type) {
|
|
||||||
case AppletType_Application:
|
|
||||||
case AppletType_SystemApplication:
|
|
||||||
nv_servicetype = NVSERVTYPE_Application;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AppletType_SystemApplet:
|
|
||||||
case AppletType_LibraryApplet:
|
|
||||||
case AppletType_OverlayApplet:
|
|
||||||
default:
|
|
||||||
nv_servicetype = NVSERVTYPE_Applet;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _gfxInit(ViServiceType_Default, "Default", ViLayerFlags_Default, 0, nv_servicetype, 0x300000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void gfxExit(void)
|
void gfxExit(void)
|
||||||
|
@ -273,6 +273,10 @@ void appletExit(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AppletType appletGetAppletType(void) {
|
||||||
|
return __nx_applet_type;
|
||||||
|
}
|
||||||
|
|
||||||
static void appletCallHook(AppletHookType hookType)
|
static void appletCallHook(AppletHookType hookType)
|
||||||
{
|
{
|
||||||
AppletHookCookie* c;
|
AppletHookCookie* c;
|
||||||
@ -514,7 +518,7 @@ Result appletGetDesiredLanguage(u64 *LanguageCode) {
|
|||||||
IpcCommand c;
|
IpcCommand c;
|
||||||
ipcInitialize(&c);
|
ipcInitialize(&c);
|
||||||
|
|
||||||
if (!serviceIsActive(&g_appletSrv) || __nx_applet_type!=AppletType_Application)
|
if (!serviceIsActive(&g_appletSrv) || __nx_applet_type != AppletType_Application)
|
||||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
@ -10,55 +10,52 @@
|
|||||||
|
|
||||||
static Service g_nvSrv;
|
static Service g_nvSrv;
|
||||||
static size_t g_nvIpcBufferSize = 0;
|
static size_t g_nvIpcBufferSize = 0;
|
||||||
static u32 g_nvServiceType = -1;
|
|
||||||
static TransferMemory g_nvTransfermem;
|
static TransferMemory g_nvTransfermem;
|
||||||
|
|
||||||
static Result _nvInitialize(Handle proc, Handle sharedmem, u32 transfermem_size);
|
static Result _nvInitialize(Handle proc, Handle sharedmem, u32 transfermem_size);
|
||||||
static Result _nvSetClientPID(u64 AppletResourceUserId);
|
static Result _nvSetClientPID(u64 AppletResourceUserId);
|
||||||
|
|
||||||
Result nvInitialize(nvServiceType servicetype, size_t transfermem_size)
|
Result nvInitialize(size_t transfermem_size)
|
||||||
{
|
{
|
||||||
if (g_nvServiceType != -1)
|
if (serviceIsActive(&g_nvSrv))
|
||||||
return MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized);
|
return MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized);
|
||||||
|
|
||||||
Result rc = 0;
|
Result rc = 0;
|
||||||
u64 AppletResourceUserId = 0;
|
u64 AppletResourceUserId = 0;
|
||||||
|
|
||||||
if (servicetype==NVSERVTYPE_Default || servicetype==NVSERVTYPE_Application) {
|
switch (appletGetAppletType()) {
|
||||||
|
case AppletType_Default:
|
||||||
|
case AppletType_Application:
|
||||||
|
case AppletType_SystemApplication:
|
||||||
|
default:
|
||||||
rc = smGetService(&g_nvSrv, "nvdrv");
|
rc = smGetService(&g_nvSrv, "nvdrv");
|
||||||
g_nvServiceType = 0;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if ((servicetype==NVSERVTYPE_Default && R_FAILED(rc)) || servicetype==NVSERVTYPE_Applet) {
|
case AppletType_SystemApplet:
|
||||||
|
case AppletType_LibraryApplet:
|
||||||
|
case AppletType_OverlayApplet:
|
||||||
rc = smGetService(&g_nvSrv, "nvdrv:a");
|
rc = smGetService(&g_nvSrv, "nvdrv:a");
|
||||||
g_nvServiceType = 1;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if ((servicetype==NVSERVTYPE_Default && R_FAILED(rc)) || servicetype==NVSERVTYPE_Sysmodule)
|
|
||||||
{
|
|
||||||
rc = smGetService(&g_nvSrv, "nvdrv:s");
|
|
||||||
g_nvServiceType = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((servicetype==NVSERVTYPE_Default && R_FAILED(rc)) || servicetype==NVSERVTYPE_T)
|
|
||||||
{
|
|
||||||
rc = smGetService(&g_nvSrv, "nvdrv:t");
|
|
||||||
g_nvServiceType = 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
g_nvIpcBufferSize = 0;
|
g_nvIpcBufferSize = 0;
|
||||||
rc = ipcQueryPointerBufferSize(g_nvSrv.handle, &g_nvIpcBufferSize);
|
rc = ipcQueryPointerBufferSize(g_nvSrv.handle, &g_nvIpcBufferSize);
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) rc = tmemCreate(&g_nvTransfermem, transfermem_size, Perm_None);
|
if (R_SUCCEEDED(rc))
|
||||||
|
rc = tmemCreate(&g_nvTransfermem, transfermem_size, Perm_None);
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) rc = _nvInitialize(CUR_PROCESS_HANDLE, g_nvTransfermem.handle, transfermem_size);
|
if (R_SUCCEEDED(rc))
|
||||||
|
rc = _nvInitialize(CUR_PROCESS_HANDLE, g_nvTransfermem.handle, transfermem_size);
|
||||||
|
|
||||||
//Officially ipc control DuplicateSessionEx would be used here.
|
// Officially ipc control DuplicateSessionEx would be used here.
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) rc = appletGetAppletResourceUserId(&AppletResourceUserId);//TODO: How do sysmodules handle this?
|
// TODO: How do sysmodules handle this?
|
||||||
|
if (R_SUCCEEDED(rc))
|
||||||
|
rc = appletGetAppletResourceUserId(&AppletResourceUserId);
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) rc = _nvSetClientPID(AppletResourceUserId);
|
if (R_SUCCEEDED(rc))
|
||||||
|
rc = _nvSetClientPID(AppletResourceUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (R_FAILED(rc)) {
|
if (R_FAILED(rc)) {
|
||||||
@ -70,11 +67,6 @@ Result nvInitialize(nvServiceType servicetype, size_t transfermem_size)
|
|||||||
|
|
||||||
void nvExit(void)
|
void nvExit(void)
|
||||||
{
|
{
|
||||||
if (g_nvServiceType == -1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
g_nvServiceType = -1;
|
|
||||||
|
|
||||||
serviceClose(&g_nvSrv);
|
serviceClose(&g_nvSrv);
|
||||||
tmemClose(&g_nvTransfermem);
|
tmemClose(&g_nvTransfermem);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user