From 640bc03c6b24d7ad8731881061cb50b248e7d925 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 2 Jan 2019 10:30:19 +1100 Subject: [PATCH] [client] [Patch 2/2] fixes #106 --- client/renderers/egl/alert.c | 2 +- client/renderers/egl/cursor.c | 18 +++---- client/renderers/egl/cursor.h | 2 +- client/renderers/egl/desktop.c | 25 +++++----- client/renderers/egl/fps.c | 2 +- client/renderers/egl/texture.c | 85 +++++++++++++++++++--------------- client/renderers/egl/texture.h | 2 +- 7 files changed, 72 insertions(+), 64 deletions(-) diff --git a/client/renderers/egl/alert.c b/client/renderers/egl/alert.c index 539204f5..ce9a032f 100644 --- a/client/renderers/egl/alert.c +++ b/client/renderers/egl/alert.c @@ -219,7 +219,7 @@ void egl_alert_render(EGL_Alert * alert, const float scaleX, const float scaleY) EGL_PF_BGRA, alert->bmp->width , alert->bmp->height, - alert->bmp->width * alert->bmp->height * alert->bmp->bpp, + alert->bmp->width * alert->bmp->bpp, false ); diff --git a/client/renderers/egl/cursor.c b/client/renderers/egl/cursor.c index 9f1e1840..7a3aa87b 100644 --- a/client/renderers/egl/cursor.c +++ b/client/renderers/egl/cursor.c @@ -34,7 +34,7 @@ struct EGL_Cursor LG_RendererCursor type; int width; int height; - int pitch; + int stride; uint8_t * data; size_t dataSize; bool update; @@ -204,16 +204,16 @@ void egl_cursor_free(EGL_Cursor ** cursor) *cursor = NULL; } -bool egl_cursor_set_shape(EGL_Cursor * cursor, const LG_RendererCursor type, const int width, const int height, const int pitch, const uint8_t * data) +bool egl_cursor_set_shape(EGL_Cursor * cursor, const LG_RendererCursor type, const int width, const int height, const int stride, const uint8_t * data) { LG_LOCK(cursor->lock); cursor->type = type; cursor->width = width; cursor->height = (type == LG_CURSOR_MONOCHROME ? height / 2 : height); - cursor->pitch = pitch; + cursor->stride = stride; - const size_t size = height * pitch; + const size_t size = height * stride; if (size > cursor->dataSize) { if (cursor->data) @@ -282,7 +282,7 @@ void egl_cursor_render(EGL_Cursor * cursor) case LG_CURSOR_COLOR: { - egl_texture_setup(cursor->texture, EGL_PF_BGRA, cursor->width, cursor->height, cursor->width * cursor->height * 4, false); + egl_texture_setup(cursor->texture, EGL_PF_BGRA, cursor->width, cursor->height, cursor->stride, false); egl_texture_update(cursor->texture, data); egl_model_set_texture(cursor->model, cursor->texture); break; @@ -296,8 +296,8 @@ void egl_cursor_render(EGL_Cursor * cursor) for(int y = 0; y < cursor->height; ++y) for(int x = 0; x < cursor->width; ++x) { - const uint8_t * srcAnd = data + (cursor->pitch * y) + (x / 8); - const uint8_t * srcXor = srcAnd + cursor->pitch * cursor->height; + const uint8_t * srcAnd = data + (cursor->stride * y) + (x / 8); + const uint8_t * srcXor = srcAnd + cursor->stride * cursor->height; const uint8_t mask = 0x80 >> (x % 8); const uint32_t andMask = (*srcAnd & mask) ? 0xFFFFFFFF : 0xFF000000; const uint32_t xorMask = (*srcXor & mask) ? 0x00FFFFFF : 0x00000000; @@ -306,8 +306,8 @@ void egl_cursor_render(EGL_Cursor * cursor) xor[y * cursor->width + x] = xorMask; } - egl_texture_setup (cursor->texture , EGL_PF_BGRA, cursor->width, cursor->height, cursor->width * cursor->height * 4, false); - egl_texture_setup (cursor->textureMono, EGL_PF_BGRA, cursor->width, cursor->height, cursor->width * cursor->height * 4, false); + egl_texture_setup (cursor->texture , EGL_PF_BGRA, cursor->width, cursor->height, cursor->width * 4, false); + egl_texture_setup (cursor->textureMono, EGL_PF_BGRA, cursor->width, cursor->height, cursor->width * 4, false); egl_texture_update(cursor->texture , (uint8_t *)and); egl_texture_update(cursor->textureMono, (uint8_t *)xor); break; diff --git a/client/renderers/egl/cursor.h b/client/renderers/egl/cursor.h index af8b1b60..ccf95099 100644 --- a/client/renderers/egl/cursor.h +++ b/client/renderers/egl/cursor.h @@ -27,7 +27,7 @@ typedef struct EGL_Cursor EGL_Cursor; bool egl_cursor_init(EGL_Cursor ** cursor); void egl_cursor_free(EGL_Cursor ** cursor); -bool egl_cursor_set_shape(EGL_Cursor * cursor, const LG_RendererCursor type, const int width, const int height, const int pitch, const uint8_t * data); +bool egl_cursor_set_shape(EGL_Cursor * cursor, const LG_RendererCursor type, const int width, const int height, const int stride, const uint8_t * data); void egl_cursor_set_size (EGL_Cursor * cursor, const float x, const float y); void egl_cursor_set_state(EGL_Cursor * cursor, const bool visible, const float x, const float y); void egl_cursor_render (EGL_Cursor * cursor); \ No newline at end of file diff --git a/client/renderers/egl/desktop.c b/client/renderers/egl/desktop.c index 5556315c..07c92ffd 100644 --- a/client/renderers/egl/desktop.c +++ b/client/renderers/egl/desktop.c @@ -44,7 +44,7 @@ struct EGL_Desktop // internals enum EGL_PixelFormat pixFmt; unsigned int width, height; - size_t frameSize; + unsigned int pitch; const uint8_t * data; bool update; }; @@ -195,27 +195,23 @@ bool egl_desktop_prepare_update(EGL_Desktop * desktop, const bool sourceChanged, switch(format.type) { case FRAME_TYPE_BGRA: - desktop->pixFmt = EGL_PF_BGRA; - desktop->shader = desktop->shader_generic; - desktop->frameSize = format.height * format.pitch; + desktop->pixFmt = EGL_PF_BGRA; + desktop->shader = desktop->shader_generic; break; case FRAME_TYPE_RGBA: - desktop->pixFmt = EGL_PF_RGBA; - desktop->shader = desktop->shader_generic; - desktop->frameSize = format.height * format.pitch; + desktop->pixFmt = EGL_PF_RGBA; + desktop->shader = desktop->shader_generic; break; case FRAME_TYPE_RGBA10: - desktop->pixFmt = EGL_PF_RGBA10; - desktop->shader = desktop->shader_generic; - desktop->frameSize = format.height * format.pitch; + desktop->pixFmt = EGL_PF_RGBA10; + desktop->shader = desktop->shader_generic; break; case FRAME_TYPE_YUV420: - desktop->pixFmt = EGL_PF_YUV420; - desktop->shader = desktop->shader_yuv; - desktop->frameSize = format.width * format.height * 3 / 2; + desktop->pixFmt = EGL_PF_YUV420; + desktop->shader = desktop->shader_yuv; break; default: @@ -225,6 +221,7 @@ bool egl_desktop_prepare_update(EGL_Desktop * desktop, const bool sourceChanged, desktop->width = format.width; desktop->height = format.height; + desktop->pitch = format.pitch; } desktop->data = data; @@ -245,7 +242,7 @@ bool egl_desktop_perform_update(EGL_Desktop * desktop, const bool sourceChanged) desktop->pixFmt, desktop->width, desktop->height, - desktop->frameSize, + desktop->pitch, true // streaming texture )) { diff --git a/client/renderers/egl/fps.c b/client/renderers/egl/fps.c index 909d2595..8f509514 100644 --- a/client/renderers/egl/fps.c +++ b/client/renderers/egl/fps.c @@ -195,7 +195,7 @@ void egl_fps_update(EGL_FPS * fps, const float avgFPS, const float renderFPS) EGL_PF_BGRA, bmp->width , bmp->height, - bmp->width * bmp->height * bmp->bpp, + bmp->width * bmp->bpp, false ); diff --git a/client/renderers/egl/texture.c b/client/renderers/egl/texture.c index a51f34a6..470a909e 100644 --- a/client/renderers/egl/texture.c +++ b/client/renderers/egl/texture.c @@ -36,7 +36,7 @@ struct EGL_Texture int textureCount; GLuint textures[3]; GLuint samplers[3]; - size_t planes[3][2]; + size_t planes[3][3]; GLintptr offsets[3]; GLenum intFormat; GLenum format; @@ -81,61 +81,70 @@ void egl_texture_free(EGL_Texture ** texture) *texture = NULL; } -bool egl_texture_setup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt, size_t width, size_t height, size_t bufferSize, bool streaming) +bool egl_texture_setup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt, size_t width, size_t height, size_t stride, bool streaming) { int textureCount; texture->pixFmt = pixFmt; texture->width = width; texture->height = height; - texture->pboBufferSize = bufferSize; texture->streaming = streaming; switch(pixFmt) { case EGL_PF_BGRA: - textureCount = 1; - texture->format = GL_BGRA; - texture->planes[0][0] = width; - texture->planes[0][1] = height; - texture->offsets[0] = 0; - texture->intFormat = GL_BGRA; - texture->dataType = GL_UNSIGNED_BYTE; + textureCount = 1; + texture->format = GL_BGRA; + texture->planes[0][0] = width; + texture->planes[0][1] = height; + texture->planes[0][2] = stride / 4; + texture->offsets[0] = 0; + texture->intFormat = GL_BGRA; + texture->dataType = GL_UNSIGNED_BYTE; + texture->pboBufferSize = height * stride; break; case EGL_PF_RGBA: - textureCount = 1; - texture->format = GL_RGBA; - texture->planes[0][0] = width; - texture->planes[0][1] = height; - texture->offsets[0] = 0; - texture->intFormat = GL_BGRA; - texture->dataType = GL_UNSIGNED_BYTE; + textureCount = 1; + texture->format = GL_RGBA; + texture->planes[0][0] = width; + texture->planes[0][1] = height; + texture->planes[0][2] = stride / 4; + texture->offsets[0] = 0; + texture->intFormat = GL_BGRA; + texture->dataType = GL_UNSIGNED_BYTE; + texture->pboBufferSize = height * stride; break; case EGL_PF_RGBA10: - textureCount = 1; - texture->format = GL_RGBA; - texture->planes[0][0] = width; - texture->planes[0][1] = height; - texture->offsets[0] = 0; - texture->intFormat = GL_RGB10_A2; - texture->dataType = GL_UNSIGNED_INT_2_10_10_10_REV; + textureCount = 1; + texture->format = GL_RGBA; + texture->planes[0][0] = width; + texture->planes[0][1] = height; + texture->planes[0][2] = stride / 4; + texture->offsets[0] = 0; + texture->intFormat = GL_RGB10_A2; + texture->dataType = GL_UNSIGNED_INT_2_10_10_10_REV; + texture->pboBufferSize = height * stride; break; case EGL_PF_YUV420: - textureCount = 3; - texture->format = GL_RED; - texture->planes[0][0] = width; - texture->planes[0][1] = height; - texture->planes[1][0] = width / 2; - texture->planes[1][1] = height / 2; - texture->planes[2][0] = width / 2; - texture->planes[2][1] = height / 2; - texture->offsets[0] = 0; - texture->offsets[1] = width * height; - texture->offsets[2] = texture->offsets[1] + (texture->offsets[1] / 4); - texture->dataType = GL_UNSIGNED_BYTE; + textureCount = 3; + texture->format = GL_RED; + texture->planes[0][0] = width; + texture->planes[0][1] = height; + texture->planes[0][2] = stride; + texture->planes[1][0] = width / 2; + texture->planes[1][1] = height / 2; + texture->planes[1][2] = stride / 2; + texture->planes[2][0] = width / 2; + texture->planes[2][1] = height / 2; + texture->planes[2][2] = stride / 2; + texture->offsets[0] = 0; + texture->offsets[1] = stride * height; + texture->offsets[2] = texture->offsets[1] + (texture->offsets[1] / 4); + texture->dataType = GL_UNSIGNED_BYTE; + texture->pboBufferSize = texture->offsets[2] + (texture->offsets[1] / 4); break; default: @@ -182,7 +191,7 @@ bool egl_texture_setup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt, size_ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->pbo[i]); glBufferData( GL_PIXEL_UNPACK_BUFFER, - bufferSize, + height * stride, NULL, GL_DYNAMIC_DRAW ); @@ -217,6 +226,7 @@ bool egl_texture_update(EGL_Texture * texture, const uint8_t * buffer) for(int i = 0; i < texture->textureCount; ++i) { glBindTexture(GL_TEXTURE_2D, texture->textures[i]); + glPixelStorei(GL_UNPACK_ROW_LENGTH, texture->planes[i][0]); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->planes[i][0], texture->planes[i][1], texture->format, texture->dataType, buffer + texture->offsets[i]); } @@ -233,6 +243,7 @@ void egl_texture_bind(EGL_Texture * texture) for(int i = 0; i < texture->textureCount; ++i) { glBindTexture(GL_TEXTURE_2D, texture->textures[i]); + glPixelStorei(GL_UNPACK_ROW_LENGTH, texture->planes[i][2]); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->planes[i][0], texture->planes[i][1], texture->format, texture->dataType, (const void *)texture->offsets[i]); } diff --git a/client/renderers/egl/texture.h b/client/renderers/egl/texture.h index 759c8996..d11c1e0a 100644 --- a/client/renderers/egl/texture.h +++ b/client/renderers/egl/texture.h @@ -37,7 +37,7 @@ enum EGL_PixelFormat bool egl_texture_init(EGL_Texture ** tex); void egl_texture_free(EGL_Texture ** tex); -bool egl_texture_setup (EGL_Texture * texture, enum EGL_PixelFormat pixfmt, size_t width, size_t height, size_t bufferSize, bool streaming); +bool egl_texture_setup (EGL_Texture * texture, enum EGL_PixelFormat pixfmt, size_t width, size_t height, size_t stride, bool streaming); bool egl_texture_update(EGL_Texture * texture, const uint8_t * buffer); void egl_texture_bind (EGL_Texture * texture); int egl_texture_count (EGL_Texture * texture); \ No newline at end of file