From 3a2d612b415a39c12f803aa728e7c4366071ab68 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Tue, 15 May 2018 19:19:39 +1000 Subject: [PATCH] [decoders] change the API to allow more flexability in the future --- client/decoders/null.c | 25 ++++++++++++------------- client/lg-decoder.h | 18 +++++++++--------- client/renderers/opengl.c | 9 ++++----- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/client/decoders/null.c b/client/decoders/null.c index 24beaaf3..26da3b5a 100644 --- a/client/decoders/null.c +++ b/client/decoders/null.c @@ -31,15 +31,15 @@ struct Inst const uint8_t * src; }; -static bool lgd_null_create (void ** opaque); -static void lgd_null_destroy (void * opaque); -static bool lgd_null_initialize (void * opaque, const LG_RendererFormat format, SDL_Window * window); -static void lgd_null_deinitialize (void * opaque); -static LG_OutFormat lgd_null_get_out_format (void * opaque); -static unsigned int lgd_null_get_frame_pitch (void * opaque); -static unsigned int lgd_null_get_frame_stride(void * opaque); -static bool lgd_null_decode (void * opaque, const uint8_t * src, size_t srcSize); -static bool lgd_null_get_buffer (void * opaque, uint8_t * dst, size_t dstSize); +static bool lgd_null_create (void ** opaque); +static void lgd_null_destroy (void * opaque); +static bool lgd_null_initialize (void * opaque, const LG_RendererFormat format, SDL_Window * window); +static void lgd_null_deinitialize (void * opaque); +static LG_OutFormat lgd_null_get_out_format (void * opaque); +static unsigned int lgd_null_get_frame_pitch (void * opaque); +static unsigned int lgd_null_get_frame_stride(void * opaque); +static bool lgd_null_decode (void * opaque, const uint8_t * src, size_t srcSize); +static const uint8_t * lgd_null_get_buffer (void * opaque); static bool lgd_null_create(void ** opaque) { @@ -96,14 +96,13 @@ static bool lgd_null_decode(void * opaque, const uint8_t * src, size_t srcSize) return true; } -static bool lgd_null_get_buffer(void * opaque, uint8_t * dst, size_t dstSize) +static const uint8_t * lgd_null_get_buffer(void * opaque) { struct Inst * this = (struct Inst *)opaque; if (!this->src) - return false; + return NULL; - memcpySSE(dst, this->src, dstSize); - return true; + return this->src; } const LG_Decoder LGD_NULL = diff --git a/client/lg-decoder.h b/client/lg-decoder.h index add0f259..0c8bdcbd 100644 --- a/client/lg-decoder.h +++ b/client/lg-decoder.h @@ -34,15 +34,15 @@ typedef enum LG_OutFormat } LG_OutFormat; -typedef bool (* LG_DecoderCreate )(void ** opaque); -typedef void (* LG_DecoderDestroy )(void * opaque); -typedef bool (* LG_DecoderInitialize )(void * opaque, const LG_RendererFormat format, SDL_Window * window); -typedef void (* LG_DecoderDeInitialize )(void * opaque); -typedef LG_OutFormat (* LG_DecoderGetOutFormat )(void * opaque); -typedef unsigned int (* LG_DecoderGetFramePitch )(void * opaque); -typedef unsigned int (* LG_DecoderGetFrameStride)(void * opaque); -typedef bool (* LG_DecoderDecode )(void * opaque, const uint8_t * src, size_t srcSize); -typedef bool (* LG_DecoderGetBuffer )(void * opaque, uint8_t * dst, size_t dstSize); +typedef bool (* LG_DecoderCreate )(void ** opaque); +typedef void (* LG_DecoderDestroy )(void * opaque); +typedef bool (* LG_DecoderInitialize )(void * opaque, const LG_RendererFormat format, SDL_Window * window); +typedef void (* LG_DecoderDeInitialize )(void * opaque); +typedef LG_OutFormat (* LG_DecoderGetOutFormat )(void * opaque); +typedef unsigned int (* LG_DecoderGetFramePitch )(void * opaque); +typedef unsigned int (* LG_DecoderGetFrameStride)(void * opaque); +typedef bool (* LG_DecoderDecode )(void * opaque, const uint8_t * src, size_t srcSize); +typedef const uint8_t * (* LG_DecoderGetBuffer )(void * opaque); typedef bool (* LG_DecoderInitGLTexture )(void * opaque, GLenum target, GLuint texture, void ** ref); typedef void (* LG_DecoderFreeGLTexture )(void * opaque, void * ref); diff --git a/client/renderers/opengl.c b/client/renderers/opengl.c index c2ce8313..323cf44c 100644 --- a/client/renderers/opengl.c +++ b/client/renderers/opengl.c @@ -1070,17 +1070,16 @@ static bool draw_frame(struct Inst * this) this->fences[this->texIndex] = NULL; } - if (!this->decoder->get_buffer( - this->decoderData, - this->texPixels[this->texIndex], - this->texSize - )) + const uint8_t * data = this->decoder->get_buffer(this->decoderData); + if (!data) { LG_UNLOCK(this->formatLock); DEBUG_ERROR("Failed to get the buffer from the decoder"); return false; } + memcpySSE(this->texPixels[this->texIndex], data, this->texSize); + if (this->amdPinnedMemSupport) this->fences[this->texIndex] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);