From 3c4c35e6e5cf23310212bfd4719139175fb54784 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Thu, 22 Feb 2018 20:31:51 -0500 Subject: [PATCH] Added gfxSetDrawFlip() and gfxConfigureTransform(). --- nx/include/switch/gfx/gfx.h | 9 ++++++++- nx/source/gfx/gfx.c | 14 +++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/nx/include/switch/gfx/gfx.h b/nx/include/switch/gfx/gfx.h index f1c93e64..8a39503c 100644 --- a/nx/include/switch/gfx/gfx.h +++ b/nx/include/switch/gfx/gfx.h @@ -83,6 +83,12 @@ size_t gfxGetFramebufferSize(void); /// Sets the \ref GfxMode. void gfxSetMode(GfxMode mode); +/// Controls whether a vertical-flip is done when determining the pixel-offset within the actual framebuffer. By default this is enabled. +void gfxSetDrawFlip(bool flip); + +/// Configures transform. See the NATIVE_WINDOW_TRANSFORM_* enums in buffer_producer.h. The default is NATIVE_WINDOW_TRANSFORM_FLIP_V. +void gfxConfigureTransform(u32 transform); + /// Flushes the framebuffer in the data cache. When \ref GfxMode is GfxMode_LinearDouble, this also transfers the linear-framebuffer to the actual framebuffer. void gfxFlushBuffers(void); @@ -94,10 +100,11 @@ static inline u32 gfxGetFramebufferDisplayOffset(u32 x, u32 y) { extern size_t g_gfx_framebuf_aligned_width; extern size_t g_gfx_framebuf_display_height; + extern bool g_gfx_drawflip; //if (x >= g_gfx_framebuf_width || y >= g_gfx_framebuf_display_height) return (gfxGetFramebufferSize()-4)/4;//Return the last pixel-offset in the buffer, the data located here is not displayed due to alignment. (Disabled for perf) - y = g_gfx_framebuf_display_height-1-y; + if (g_gfx_drawflip) y = g_gfx_framebuf_display_height-1-y; tmp_pos = ((y & 127) / 16) + (x/16*8) + ((y/16/8)*(g_gfx_framebuf_aligned_width/16*8)); tmp_pos *= 16*16 * 4; diff --git a/nx/source/gfx/gfx.c b/nx/source/gfx/gfx.c index a70ae5fe..8bfa2208 100644 --- a/nx/source/gfx/gfx.c +++ b/nx/source/gfx/gfx.c @@ -40,6 +40,8 @@ size_t g_gfx_framebuf_display_width=0, g_gfx_framebuf_display_height=0; size_t g_gfx_singleframebuf_size=0; size_t g_gfx_singleframebuf_linear_size=0; +bool g_gfx_drawflip = true; + static AppletHookCookie g_gfx_autoresolution_applethookcookie; static bool g_gfx_autoresolution_enabled; @@ -55,7 +57,6 @@ extern nvioctl_fence g_nvgfx_nvhostgpu_gpfifo_fence; //static Result _gfxGetDisplayResolution(u64 *width, u64 *height); -//TODO: Let the user configure some of this? static bufferProducerQueueBufferInput g_gfxQueueBufferData = { .timestamp = 0x0, .isAutoTimestamp = 0x1, @@ -178,6 +179,9 @@ static Result _gfxInit(ViServiceType servicetype, const char *DisplayName, u32 L g_gfxFramebufSize = 0; g_gfxMode = GfxMode_LinearDouble; + g_gfx_drawflip = true; + g_gfxQueueBufferData.transform = NATIVE_WINDOW_TRANSFORM_FLIP_V; + memset(g_gfx_ProducerSlotsRequested, 0, sizeof(g_gfx_ProducerSlotsRequested)); memset(&g_gfx_DequeueBuffer_fence, 0, sizeof(g_gfx_DequeueBuffer_fence)); @@ -539,6 +543,14 @@ void gfxSetMode(GfxMode mode) { g_gfxMode = mode; } +void gfxSetDrawFlip(bool flip) { + g_gfx_drawflip = flip; +} + +void gfxConfigureTransform(u32 transform) { + g_gfxQueueBufferData.transform = transform; +} + void gfxFlushBuffers(void) { u32 *actual_framebuf = (u32*)&g_gfxFramebuf[g_gfxCurrentBuffer*g_gfx_singleframebuf_size];