From 2db9a5fdb9b928f50d24491c759060dd40c16a15 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Thu, 7 Dec 2017 11:37:40 -0500 Subject: [PATCH] Imported enum for use with bufferProducerQuery(). Changed gfxGetDisplayResolution to static with adjusted name and removed it from the .h. Disabled _gfxGetDisplayResolution. Added disabled get-{resolution/width/height} code. Check fence->is_valid when calling nvgfxEventWait(), with the commented out line. --- nx/include/switch/gfx/buffer_producer.h | 11 +++++++++++ nx/include/switch/gfx/gfx.h | 3 --- nx/source/gfx/gfx.c | 15 ++++++++++++--- nx/source/gfx/nvgfx.c | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/nx/include/switch/gfx/buffer_producer.h b/nx/include/switch/gfx/buffer_producer.h index 0eaaa535..f81b84a8 100644 --- a/nx/include/switch/gfx/buffer_producer.h +++ b/nx/include/switch/gfx/buffer_producer.h @@ -25,6 +25,17 @@ typedef struct { u32 numPendingBuffers; } PACKED bufferProducerQueueBufferOutput; +//From Android window.h. +/* attributes queriable with query() */ +enum { + NATIVE_WINDOW_WIDTH = 0, + NATIVE_WINDOW_HEIGHT = 1, + NATIVE_WINDOW_FORMAT = 2, +//... +// NATIVE_WINDOW_DEFAULT_WIDTH = 6, //These two return invalid data. +// NATIVE_WINDOW_DEFAULT_HEIGHT = 7, +}; + Result bufferProducerInitialize(binderSession *session); void bufferProducerExit(); diff --git a/nx/include/switch/gfx/gfx.h b/nx/include/switch/gfx/gfx.h index c4cdba03..5daaae00 100644 --- a/nx/include/switch/gfx/gfx.h +++ b/nx/include/switch/gfx/gfx.h @@ -10,9 +10,6 @@ u8* gfxGetFramebuffer(u32* width, u32* height); void gfxSetDoubleBuffering(bool doubleBuffering); void gfxFlushBuffers(void); -//Do not use this for getting the framebuffer width/height, use gfxGetFramebuffer for getting that. -Result gfxGetDisplayResolution(u64 *width, u64 *height); - /// Use this to get the pixel-offset in the framebuffer. Returned value is in pixels, not bytes. /// This implements tegra blocklinear, with hard-coded constants etc. static inline u32 gfxGetFramebufferDisplayOffset(u32 x, u32 y) { diff --git a/nx/source/gfx/gfx.c b/nx/source/gfx/gfx.c index 819e1692..8840be2d 100644 --- a/nx/source/gfx/gfx.c +++ b/nx/source/gfx/gfx.c @@ -15,6 +15,8 @@ static bool g_gfx_ProducerConnected = 0; static bool g_gfx_ProducerSlotsRequested[2] = {0, 0}; static u8 *g_gfxFramebuf; static size_t g_gfxFramebufSize; +/*static u64 g_gfx_DisplayResolution_width, g_gfx_DisplayResolution_height; +static s32 g_gfx_Query_width, g_gfx_Query_height;*/ static bufferProducerFence g_gfx_DequeueBuffer_fence; static bufferProducerQueueBufferOutput g_gfx_Connect_QueueBufferOutput; static bufferProducerQueueBufferOutput g_gfx_QueueBuffer_QueueBufferOutput; @@ -26,6 +28,8 @@ extern u32 __nx_applet_type; extern u32 g_nvgfx_totalframebufs; extern size_t g_nvgfx_singleframebuf_size; +//static Result _gfxGetDisplayResolution(u64 *width, u64 *height); + //TODO: Let the user configure some of this? static bufferProducerQueueBufferInput g_gfxQueueBufferData = { .timestamp = 0x0, @@ -72,7 +76,7 @@ static Result _gfxDequeueBuffer(bufferProducerFence *fence) { rc = bufferProducerDequeueBuffer(/*1*/0, 1280, 720, 0, 0x300, &g_gfxCurrentProducerBuffer, fence); - //if (R_SUCCEEDED(rc) && fence) rc = nvgfxEventWait(fence->nv_fences[0].id, fence->nv_fences[0].value); + //if (R_SUCCEEDED(rc) && fence && fence->is_valid) rc = nvgfxEventWait(fence->nv_fences[0].id, fence->nv_fences[0].value); if (R_SUCCEEDED(rc)) g_gfxCurrentBuffer = (g_gfxCurrentBuffer + 1) & (g_nvgfx_totalframebufs-1); @@ -169,6 +173,11 @@ static Result _gfxInit(viServiceType servicetype, const char *DisplayName, u32 L if (R_SUCCEEDED(rc)) rc = _gfxDequeueBuffer(&g_gfx_DequeueBuffer_fence); + /*if (R_SUCCEEDED(rc)) rc = _gfxGetDisplayResolution(&g_gfx_DisplayResolution_width, &g_gfx_DisplayResolution_height); + + if (R_SUCCEEDED(rc)) rc = bufferProducerQuery(NATIVE_WINDOW_WIDTH, &g_gfx_Query_width); + if (R_SUCCEEDED(rc)) rc = bufferProducerQuery(NATIVE_WINDOW_HEIGHT, &g_gfx_Query_height);*/ + /*if (R_SUCCEEDED(rc)) { //Workaround a gfx display issue. for(i=0; i<2; i++)gfxWaitForVsync(); }*/ @@ -317,7 +326,7 @@ void gfxFlushBuffers(void) { armDCacheFlush(&g_gfxFramebuf[g_gfxCurrentBuffer*g_nvgfx_singleframebuf_size], g_nvgfx_singleframebuf_size); } -Result gfxGetDisplayResolution(u64 *width, u64 *height) { +/*static Result _gfxGetDisplayResolution(u64 *width, u64 *height) { return viGetDisplayResolution(&g_gfxDisplay, width, height); -} +}*/ diff --git a/nx/source/gfx/nvgfx.c b/nx/source/gfx/nvgfx.c index e2b12ae9..558d7aff 100644 --- a/nx/source/gfx/nvgfx.c +++ b/nx/source/gfx/nvgfx.c @@ -286,7 +286,7 @@ Result nvgfxInitialize(void) { if (R_FAILED(rc)) break; if(pos==1) { - rc = bufferProducerQuery(2, &tmp);//"NATIVE_WINDOW_FORMAT" + rc = bufferProducerQuery(NATIVE_WINDOW_FORMAT, &tmp); if (R_FAILED(rc)) break; for(i=0; i<2; i++) {