mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-04 02:22:15 +02:00
Simplify nv
This commit is contained in:
parent
fd7db563ee
commit
12e1d92412
@ -47,6 +47,7 @@ struct AppletHookCookie
|
||||
Result appletInitialize(void);
|
||||
void appletExit(void);
|
||||
Result appletGetAppletResourceUserId(u64 *out);
|
||||
AppletType appletGetAppletType(void);
|
||||
|
||||
void appletNotifyRunning(u8 *out);
|
||||
Result appletCreateManagedDisplayLayer(u64 *out);
|
||||
|
@ -7,15 +7,7 @@
|
||||
#pragma once
|
||||
#include "../types.h"
|
||||
|
||||
typedef enum {
|
||||
NVSERVTYPE_Default = -1,
|
||||
NVSERVTYPE_Application = 0,
|
||||
NVSERVTYPE_Applet = 1,
|
||||
NVSERVTYPE_Sysmodule = 2,
|
||||
NVSERVTYPE_T = 3,
|
||||
} nvServiceType;
|
||||
|
||||
Result nvInitialize(nvServiceType servicetype, size_t sharedmem_size);
|
||||
Result nvInitialize(size_t sharedmem_size);
|
||||
void nvExit(void);
|
||||
|
||||
Result nvOpen(u32 *fd, const char *devicepath);
|
||||
|
@ -166,7 +166,7 @@ static Result _gfxQueueBuffer(s32 buf) {
|
||||
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;
|
||||
u32 i=0;
|
||||
|
||||
@ -241,7 +241,7 @@ static Result _gfxInit(ViServiceType servicetype, const char *DisplayName, u32 L
|
||||
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);
|
||||
|
||||
@ -326,25 +326,8 @@ static Result _gfxInit(ViServiceType servicetype, const char *DisplayName, u32 L
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result gfxInitDefault(void)
|
||||
{
|
||||
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);
|
||||
Result gfxInitDefault(void) {
|
||||
return _gfxInit(ViServiceType_Default, "Default", ViLayerFlags_Default, 0, 0x300000);
|
||||
}
|
||||
|
||||
void gfxExit(void)
|
||||
|
@ -273,6 +273,10 @@ void appletExit(void)
|
||||
}
|
||||
}
|
||||
|
||||
AppletType appletGetAppletType(void) {
|
||||
return __nx_applet_type;
|
||||
}
|
||||
|
||||
static void appletCallHook(AppletHookType hookType)
|
||||
{
|
||||
AppletHookCookie* c;
|
||||
|
@ -10,55 +10,52 @@
|
||||
|
||||
static Service g_nvSrv;
|
||||
static size_t g_nvIpcBufferSize = 0;
|
||||
static u32 g_nvServiceType = -1;
|
||||
static TransferMemory g_nvTransfermem;
|
||||
|
||||
static Result _nvInitialize(Handle proc, Handle sharedmem, u32 transfermem_size);
|
||||
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);
|
||||
|
||||
Result rc = 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");
|
||||
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");
|
||||
g_nvServiceType = 1;
|
||||
}
|
||||
|
||||
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;
|
||||
break;
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
g_nvIpcBufferSize = 0;
|
||||
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.
|
||||
|
||||
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)) {
|
||||
@ -70,11 +67,6 @@ Result nvInitialize(nvServiceType servicetype, size_t transfermem_size)
|
||||
|
||||
void nvExit(void)
|
||||
{
|
||||
if (g_nvServiceType == -1)
|
||||
return;
|
||||
|
||||
g_nvServiceType = -1;
|
||||
|
||||
serviceClose(&g_nvSrv);
|
||||
tmemClose(&g_nvTransfermem);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user