mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-06 11:22:15 +02:00
Introduce nwindowGetDefault
This commit is contained in:
parent
7807fa7078
commit
5e8a88ce85
@ -43,6 +43,17 @@ typedef struct NWindow {
|
||||
/// Checks whether a pointer refers to a valid \ref NWindow object.
|
||||
bool nwindowIsValid(NWindow* nw);
|
||||
|
||||
/**
|
||||
* @brief Retrieves the default \ref NWindow object.
|
||||
* @return Pointer to the default \ref NWindow object.
|
||||
* @note When this function is used/referenced, libnx will initialize VI services
|
||||
* and create a \ref NWindow object from a \ref ViLayer created on the default \ref ViDisplay;
|
||||
* all of this happening automatically during application startup (i.e. before main is called).
|
||||
* If creating the default \ref NWindow fails, libnx will throw a LibnxError_BadGfxInit fatal error.
|
||||
* Likewise, after main returns (or exit is called) libnx will clean up all resources used by it.
|
||||
*/
|
||||
NWindow* nwindowGetDefault(void);
|
||||
|
||||
/**
|
||||
* @brief Creates a \ref NWindow.
|
||||
* @param[out] nw Output \ref NWindow structure.
|
||||
|
51
nx/source/display/default_window.c
Normal file
51
nx/source/display/default_window.c
Normal file
@ -0,0 +1,51 @@
|
||||
#include <string.h>
|
||||
#include "types.h"
|
||||
#include "result.h"
|
||||
#include "services/vi.h"
|
||||
#include "services/fatal.h"
|
||||
#include "display/binder.h"
|
||||
#include "display/buffer_producer.h"
|
||||
#include "display/native_window.h"
|
||||
#include "nvidia/graphic_buffer.h"
|
||||
|
||||
static ViDisplay g_viDisplay;
|
||||
static ViLayer g_viLayer;
|
||||
static NWindow g_defaultWin;
|
||||
|
||||
NWindow* nwindowGetDefault(void)
|
||||
{
|
||||
return &g_defaultWin;
|
||||
}
|
||||
|
||||
void __nx_win_init(void)
|
||||
{
|
||||
Result rc;
|
||||
rc = viInitialize(ViServiceType_Default);
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
rc = viOpenDefaultDisplay(&g_viDisplay);
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
rc = viCreateLayer(&g_viDisplay, &g_viLayer);
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
rc = viSetLayerScalingMode(&g_viLayer, ViScalingMode_FitToLayer);
|
||||
if (R_SUCCEEDED(rc))
|
||||
rc = nwindowCreateFromLayer(&g_defaultWin, &g_viLayer);
|
||||
if (R_FAILED(rc))
|
||||
viCloseLayer(&g_viLayer);
|
||||
}
|
||||
if (R_FAILED(rc))
|
||||
viCloseDisplay(&g_viDisplay);
|
||||
}
|
||||
if (R_FAILED(rc))
|
||||
viExit();
|
||||
}
|
||||
if (R_FAILED(rc))
|
||||
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGfxInit));
|
||||
}
|
||||
|
||||
void __nx_win_exit(void)
|
||||
{
|
||||
nwindowClose(&g_defaultWin);
|
||||
viCloseLayer(&g_viLayer);
|
||||
viCloseDisplay(&g_viDisplay);
|
||||
viExit();
|
||||
}
|
@ -95,6 +95,7 @@ void __attribute__((weak)) __libnx_initheap(void)
|
||||
fake_heap_end = (char*)addr + size;
|
||||
}
|
||||
|
||||
void __attribute__((weak)) __nx_win_init(void);
|
||||
void __attribute__((weak)) userAppInit(void);
|
||||
|
||||
void __attribute__((weak)) __appInit(void)
|
||||
@ -128,14 +129,18 @@ void __attribute__((weak)) __appInit(void)
|
||||
|
||||
fsdevMountSdmc();
|
||||
|
||||
if (&__nx_win_init) __nx_win_init();
|
||||
if (&userAppInit) userAppInit();
|
||||
}
|
||||
|
||||
void __attribute__((weak)) userAppExit(void);
|
||||
void __attribute__((weak)) __nx_win_exit(void);
|
||||
|
||||
void __attribute__((weak)) __appExit(void)
|
||||
{
|
||||
if (&userAppExit) userAppExit();
|
||||
if (&__nx_win_exit) __nx_win_exit();
|
||||
|
||||
// Cleanup default services.
|
||||
fsdevUnmountAll();
|
||||
fsExit();
|
||||
|
Loading…
Reference in New Issue
Block a user