From 4c1c1ee14b7f16dcf07832fa0b71c965e143f58a Mon Sep 17 00:00:00 2001 From: yellows8 Date: Mon, 4 Dec 2017 13:31:29 -0500 Subject: [PATCH] Parse bufferProducerConnect() parcel reply properly. Store the output QueueBufferOutput from bufferProducerConnect/bufferProducerQueueBuffer in gfx.c. --- nx/include/switch/gfx/buffer_producer.h | 2 +- nx/source/gfx/buffer_producer.c | 8 ++++++-- nx/source/gfx/gfx.c | 6 ++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/nx/include/switch/gfx/buffer_producer.h b/nx/include/switch/gfx/buffer_producer.h index 87016b39..0eaaa535 100644 --- a/nx/include/switch/gfx/buffer_producer.h +++ b/nx/include/switch/gfx/buffer_producer.h @@ -33,6 +33,6 @@ Result bufferProducerDequeueBuffer(bool async, u32 width, u32 height, s32 format Result bufferProducerDetachBuffer(s32 slot); Result bufferProducerQueueBuffer(s32 buf, bufferProducerQueueBufferInput *input, bufferProducerQueueBufferOutput *output); Result bufferProducerQuery(s32 what, s32* value); -Result bufferProducerConnect(s32 api, bool producerControlledByApp); +Result bufferProducerConnect(s32 api, bool producerControlledByApp, bufferProducerQueueBufferOutput *output); Result bufferProducerDisconnect(s32 api); Result bufferProducerTegraBufferInit(s32 buf, u8 input[0x178]); diff --git a/nx/source/gfx/buffer_producer.c b/nx/source/gfx/buffer_producer.c index 12d37c34..c45a15f5 100644 --- a/nx/source/gfx/buffer_producer.c +++ b/nx/source/gfx/buffer_producer.c @@ -193,7 +193,7 @@ Result bufferProducerQuery(s32 what, s32* value) return rc; } -Result bufferProducerConnect(s32 api, bool producerControlledByApp) +Result bufferProducerConnect(s32 api, bool producerControlledByApp, bufferProducerQueueBufferOutput *output) { Result rc; Parcel parcel, parcel_reply; @@ -214,7 +214,11 @@ Result bufferProducerConnect(s32 api, bool producerControlledByApp) rc = parcelTransact(g_bufferProducerBinderSession, CONNECT, &parcel, &parcel_reply); if (R_SUCCEEDED(rc)) { - //TODO: parse reply (contains 32bit width and height) + if (parcelReadData(&parcel_reply, output, sizeof(bufferProducerQueueBufferOutput))==NULL) return MAKERESULT(MODULE_LIBNX, LIBNX_BADINPUT); + + int result = parcelReadInt32(&parcel_reply); + if (result != 0) + rc = MAKERESULT(MODULE_LIBNX, LIBNX_BUFFERPRODUCER_ERROR); } return rc; diff --git a/nx/source/gfx/gfx.c b/nx/source/gfx/gfx.c index d3c7bc22..819e1692 100644 --- a/nx/source/gfx/gfx.c +++ b/nx/source/gfx/gfx.c @@ -16,6 +16,8 @@ static bool g_gfx_ProducerSlotsRequested[2] = {0, 0}; static u8 *g_gfxFramebuf; static size_t g_gfxFramebufSize; static bufferProducerFence g_gfx_DequeueBuffer_fence; +static bufferProducerQueueBufferOutput g_gfx_Connect_QueueBufferOutput; +static bufferProducerQueueBufferOutput g_gfx_QueueBuffer_QueueBufferOutput; static bool g_gfxDoubleBuf = 1; @@ -84,7 +86,7 @@ static Result _gfxQueueBuffer(s32 buf) { g_gfxQueueBufferData.timestamp = svcGetSystemTick();//This is probably not the proper value for the timestamp, but shouldn't(?) matter. - rc = bufferProducerQueueBuffer(buf, &g_gfxQueueBufferData, NULL); + rc = bufferProducerQueueBuffer(buf, &g_gfxQueueBufferData, &g_gfx_QueueBuffer_QueueBufferOutput); if (R_FAILED(rc)) return rc; /*if(buf==0) {// @@ -135,7 +137,7 @@ static Result _gfxInit(viServiceType servicetype, const char *DisplayName, u32 L if (R_SUCCEEDED(rc)) rc = bufferProducerInitialize(&g_gfxBinderSession); - if (R_SUCCEEDED(rc)) rc = bufferProducerConnect(2, 0); + if (R_SUCCEEDED(rc)) rc = bufferProducerConnect(2, 0, &g_gfx_Connect_QueueBufferOutput); if (R_SUCCEEDED(rc)) g_gfx_ProducerConnected = 1;