From 18a0d45afedb65dee6163b12d338388c5cb315ce Mon Sep 17 00:00:00 2001 From: yellows8 Date: Fri, 22 Dec 2017 02:40:33 -0500 Subject: [PATCH] Added gfxInitResolutionDefault(). Added gfxConfigureAutoResolution() and gfxConfigureAutoResolutionDefault(). --- nx/include/switch/gfx/gfx.h | 9 +++++++ nx/source/gfx/gfx.c | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/nx/include/switch/gfx/gfx.h b/nx/include/switch/gfx/gfx.h index a49a9ab1..5925eb54 100644 --- a/nx/include/switch/gfx/gfx.h +++ b/nx/include/switch/gfx/gfx.h @@ -16,6 +16,9 @@ void gfxExit(void); /// Normally you should only use this when you need a maximum resolution larger than the default, see above. void gfxInitResolution(u32 width, u32 height); +/// Wrapper for gfxInitResolution() with resolution=1080p. Use this if you want to support 1080p or >720p in docked-mode. +void gfxInitResolutionDefault(void); + /// Configure framebuffer crop, by default crop is all-zero. Use all-zero input to reset to default. gfxExit() resets this to the default. /// When the input is invalid this returns without changing the crop data, this includes the input values being larger than the framebuf width/height. /// This will update the display width/height returned by gfxGetFramebuffer(), with that width/height being reset to the default when required. @@ -26,6 +29,12 @@ void gfxConfigureCrop(s32 left, s32 top, s32 right, s32 bottom); /// Wrapper for gfxConfigureCrop(). Use this to set the resolution, within the bounds of the maximum resolution. Use all-zero input to reset to default. void gfxConfigureResolution(s32 width, s32 height); +/// If enabled, gfxConfigureResolution() will be used with the input resolution for the current OperationMode. Then gfxConfigureResolution() will automatically be used with the specified resolution each time OperationMode changes. +void gfxConfigureAutoResolution(bool enable, s32 handheld_width, s32 handheld_height, s32 docked_width, s32 docked_height); + +/// Wrapper for gfxConfigureAutoResolution(). handheld_resolution=720p, docked_resolution={all-zero for using current maximum resolution}. +void gfxConfigureAutoResolutionDefault(bool enable); + void gfxWaitForVsync(); void gfxSwapBuffers(); diff --git a/nx/source/gfx/gfx.c b/nx/source/gfx/gfx.c index 172bb10c..bc648429 100644 --- a/nx/source/gfx/gfx.c +++ b/nx/source/gfx/gfx.c @@ -28,6 +28,14 @@ static size_t g_gfx_framebuf_height=0, g_gfx_framebuf_aligned_height=0; static size_t g_gfx_framebuf_display_width=0, g_gfx_framebuf_display_height=0; size_t g_gfx_singleframebuf_size=0; +static appletHookCookie g_gfx_autoresolution_applethookcookie; +static bool g_gfx_autoresolution_enabled; + +static s32 g_gfx_autoresolution_handheld_width; +static s32 g_gfx_autoresolution_handheld_height; +static s32 g_gfx_autoresolution_docked_width; +static s32 g_gfx_autoresolution_docked_height; + extern u32 __nx_applet_type; extern u32 g_nvgfx_totalframebufs; @@ -353,6 +361,8 @@ void gfxExit(void) { g_gfx_framebuf_width = 0; g_gfx_framebuf_height = 0; + gfxConfigureAutoResolution(0, 0, 0, 0, 0); + memset(g_gfx_ProducerSlotsRequested, 0, sizeof(g_gfx_ProducerSlotsRequested)); memset(&g_gfxQueueBufferData.crop, 0, sizeof(g_gfxQueueBufferData.crop)); @@ -365,6 +375,10 @@ void gfxInitResolution(u32 width, u32 height) { g_gfx_framebuf_height = height; } +void gfxInitResolutionDefault(void) { + gfxInitResolution(1920, 1080); +} + void gfxConfigureCrop(s32 left, s32 top, s32 right, s32 bottom) { if (right==0 || bottom==0) { g_gfx_framebuf_display_width = g_gfx_framebuf_width; @@ -391,6 +405,42 @@ void gfxConfigureResolution(s32 width, s32 height) { gfxConfigureCrop(0, 0, width, height); } +static void _gfxAutoResolutionAppletHook(applet_HookType hook, void* param) { + u8 mode=0; + + if (hook != APPLETHOOK_ONOPERATIONMODE) return; + + mode = appletGetOperationMode(); + + if (mode == APPLET_OperationMode_Handheld) { + gfxConfigureResolution(g_gfx_autoresolution_handheld_width, g_gfx_autoresolution_handheld_height); + } + else if(mode == APPLET_OperationMode_Docked) { + gfxConfigureResolution(g_gfx_autoresolution_docked_width, g_gfx_autoresolution_docked_height); + } +} + +void gfxConfigureAutoResolution(bool enable, s32 handheld_width, s32 handheld_height, s32 docked_width, s32 docked_height) { + if (g_gfx_autoresolution_enabled != enable) { + if(enable) appletHook(&g_gfx_autoresolution_applethookcookie, _gfxAutoResolutionAppletHook, 0); + if (!enable) appletUnhook(&g_gfx_autoresolution_applethookcookie); + } + + g_gfx_autoresolution_enabled = enable; + + g_gfx_autoresolution_handheld_width = handheld_width; + g_gfx_autoresolution_handheld_height = handheld_height; + g_gfx_autoresolution_docked_width = docked_width; + g_gfx_autoresolution_docked_height = docked_height; + + if (enable) _gfxAutoResolutionAppletHook(APPLETHOOK_ONOPERATIONMODE, 0); + if (!enable) gfxConfigureResolution(0, 0); +} + +void gfxConfigureAutoResolutionDefault(bool enable) { + gfxConfigureAutoResolution(enable, 1280, 720, 0, 0); +} + Result _gfxGraphicBufferInit(s32 buf, u32 nvmap_handle) { g_gfx_BufferInitData.refcount = buf; g_gfx_BufferInitData.data.nvmap_handle0 = nvmap_handle;