[client] [Patch 2/2] fixes #106

This commit is contained in:
Geoffrey McRae 2019-01-02 10:30:19 +11:00
parent 2a86339b1d
commit 640bc03c6b
7 changed files with 72 additions and 64 deletions

View File

@ -219,7 +219,7 @@ void egl_alert_render(EGL_Alert * alert, const float scaleX, const float scaleY)
EGL_PF_BGRA, EGL_PF_BGRA,
alert->bmp->width , alert->bmp->width ,
alert->bmp->height, alert->bmp->height,
alert->bmp->width * alert->bmp->height * alert->bmp->bpp, alert->bmp->width * alert->bmp->bpp,
false false
); );

View File

@ -34,7 +34,7 @@ struct EGL_Cursor
LG_RendererCursor type; LG_RendererCursor type;
int width; int width;
int height; int height;
int pitch; int stride;
uint8_t * data; uint8_t * data;
size_t dataSize; size_t dataSize;
bool update; bool update;
@ -204,16 +204,16 @@ void egl_cursor_free(EGL_Cursor ** cursor)
*cursor = NULL; *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); LG_LOCK(cursor->lock);
cursor->type = type; cursor->type = type;
cursor->width = width; cursor->width = width;
cursor->height = (type == LG_CURSOR_MONOCHROME ? height / 2 : height); 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 (size > cursor->dataSize)
{ {
if (cursor->data) if (cursor->data)
@ -282,7 +282,7 @@ void egl_cursor_render(EGL_Cursor * cursor)
case LG_CURSOR_COLOR: 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_texture_update(cursor->texture, data);
egl_model_set_texture(cursor->model, cursor->texture); egl_model_set_texture(cursor->model, cursor->texture);
break; break;
@ -296,8 +296,8 @@ void egl_cursor_render(EGL_Cursor * cursor)
for(int y = 0; y < cursor->height; ++y) for(int y = 0; y < cursor->height; ++y)
for(int x = 0; x < cursor->width; ++x) for(int x = 0; x < cursor->width; ++x)
{ {
const uint8_t * srcAnd = data + (cursor->pitch * y) + (x / 8); const uint8_t * srcAnd = data + (cursor->stride * y) + (x / 8);
const uint8_t * srcXor = srcAnd + cursor->pitch * cursor->height; const uint8_t * srcXor = srcAnd + cursor->stride * cursor->height;
const uint8_t mask = 0x80 >> (x % 8); const uint8_t mask = 0x80 >> (x % 8);
const uint32_t andMask = (*srcAnd & mask) ? 0xFFFFFFFF : 0xFF000000; const uint32_t andMask = (*srcAnd & mask) ? 0xFFFFFFFF : 0xFF000000;
const uint32_t xorMask = (*srcXor & mask) ? 0x00FFFFFF : 0x00000000; 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; 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->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 * cursor->height * 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->texture , (uint8_t *)and);
egl_texture_update(cursor->textureMono, (uint8_t *)xor); egl_texture_update(cursor->textureMono, (uint8_t *)xor);
break; break;

View File

@ -27,7 +27,7 @@ typedef struct EGL_Cursor EGL_Cursor;
bool egl_cursor_init(EGL_Cursor ** cursor); bool egl_cursor_init(EGL_Cursor ** cursor);
void egl_cursor_free(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_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_set_state(EGL_Cursor * cursor, const bool visible, const float x, const float y);
void egl_cursor_render (EGL_Cursor * cursor); void egl_cursor_render (EGL_Cursor * cursor);

View File

@ -44,7 +44,7 @@ struct EGL_Desktop
// internals // internals
enum EGL_PixelFormat pixFmt; enum EGL_PixelFormat pixFmt;
unsigned int width, height; unsigned int width, height;
size_t frameSize; unsigned int pitch;
const uint8_t * data; const uint8_t * data;
bool update; bool update;
}; };
@ -195,27 +195,23 @@ bool egl_desktop_prepare_update(EGL_Desktop * desktop, const bool sourceChanged,
switch(format.type) switch(format.type)
{ {
case FRAME_TYPE_BGRA: case FRAME_TYPE_BGRA:
desktop->pixFmt = EGL_PF_BGRA; desktop->pixFmt = EGL_PF_BGRA;
desktop->shader = desktop->shader_generic; desktop->shader = desktop->shader_generic;
desktop->frameSize = format.height * format.pitch;
break; break;
case FRAME_TYPE_RGBA: case FRAME_TYPE_RGBA:
desktop->pixFmt = EGL_PF_RGBA; desktop->pixFmt = EGL_PF_RGBA;
desktop->shader = desktop->shader_generic; desktop->shader = desktop->shader_generic;
desktop->frameSize = format.height * format.pitch;
break; break;
case FRAME_TYPE_RGBA10: case FRAME_TYPE_RGBA10:
desktop->pixFmt = EGL_PF_RGBA10; desktop->pixFmt = EGL_PF_RGBA10;
desktop->shader = desktop->shader_generic; desktop->shader = desktop->shader_generic;
desktop->frameSize = format.height * format.pitch;
break; break;
case FRAME_TYPE_YUV420: case FRAME_TYPE_YUV420:
desktop->pixFmt = EGL_PF_YUV420; desktop->pixFmt = EGL_PF_YUV420;
desktop->shader = desktop->shader_yuv; desktop->shader = desktop->shader_yuv;
desktop->frameSize = format.width * format.height * 3 / 2;
break; break;
default: default:
@ -225,6 +221,7 @@ bool egl_desktop_prepare_update(EGL_Desktop * desktop, const bool sourceChanged,
desktop->width = format.width; desktop->width = format.width;
desktop->height = format.height; desktop->height = format.height;
desktop->pitch = format.pitch;
} }
desktop->data = data; desktop->data = data;
@ -245,7 +242,7 @@ bool egl_desktop_perform_update(EGL_Desktop * desktop, const bool sourceChanged)
desktop->pixFmt, desktop->pixFmt,
desktop->width, desktop->width,
desktop->height, desktop->height,
desktop->frameSize, desktop->pitch,
true // streaming texture true // streaming texture
)) ))
{ {

View File

@ -195,7 +195,7 @@ void egl_fps_update(EGL_FPS * fps, const float avgFPS, const float renderFPS)
EGL_PF_BGRA, EGL_PF_BGRA,
bmp->width , bmp->width ,
bmp->height, bmp->height,
bmp->width * bmp->height * bmp->bpp, bmp->width * bmp->bpp,
false false
); );

View File

@ -36,7 +36,7 @@ struct EGL_Texture
int textureCount; int textureCount;
GLuint textures[3]; GLuint textures[3];
GLuint samplers[3]; GLuint samplers[3];
size_t planes[3][2]; size_t planes[3][3];
GLintptr offsets[3]; GLintptr offsets[3];
GLenum intFormat; GLenum intFormat;
GLenum format; GLenum format;
@ -81,61 +81,70 @@ void egl_texture_free(EGL_Texture ** texture)
*texture = NULL; *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; int textureCount;
texture->pixFmt = pixFmt; texture->pixFmt = pixFmt;
texture->width = width; texture->width = width;
texture->height = height; texture->height = height;
texture->pboBufferSize = bufferSize;
texture->streaming = streaming; texture->streaming = streaming;
switch(pixFmt) switch(pixFmt)
{ {
case EGL_PF_BGRA: case EGL_PF_BGRA:
textureCount = 1; textureCount = 1;
texture->format = GL_BGRA; texture->format = GL_BGRA;
texture->planes[0][0] = width; texture->planes[0][0] = width;
texture->planes[0][1] = height; texture->planes[0][1] = height;
texture->offsets[0] = 0; texture->planes[0][2] = stride / 4;
texture->intFormat = GL_BGRA; texture->offsets[0] = 0;
texture->dataType = GL_UNSIGNED_BYTE; texture->intFormat = GL_BGRA;
texture->dataType = GL_UNSIGNED_BYTE;
texture->pboBufferSize = height * stride;
break; break;
case EGL_PF_RGBA: case EGL_PF_RGBA:
textureCount = 1; textureCount = 1;
texture->format = GL_RGBA; texture->format = GL_RGBA;
texture->planes[0][0] = width; texture->planes[0][0] = width;
texture->planes[0][1] = height; texture->planes[0][1] = height;
texture->offsets[0] = 0; texture->planes[0][2] = stride / 4;
texture->intFormat = GL_BGRA; texture->offsets[0] = 0;
texture->dataType = GL_UNSIGNED_BYTE; texture->intFormat = GL_BGRA;
texture->dataType = GL_UNSIGNED_BYTE;
texture->pboBufferSize = height * stride;
break; break;
case EGL_PF_RGBA10: case EGL_PF_RGBA10:
textureCount = 1; textureCount = 1;
texture->format = GL_RGBA; texture->format = GL_RGBA;
texture->planes[0][0] = width; texture->planes[0][0] = width;
texture->planes[0][1] = height; texture->planes[0][1] = height;
texture->offsets[0] = 0; texture->planes[0][2] = stride / 4;
texture->intFormat = GL_RGB10_A2; texture->offsets[0] = 0;
texture->dataType = GL_UNSIGNED_INT_2_10_10_10_REV; texture->intFormat = GL_RGB10_A2;
texture->dataType = GL_UNSIGNED_INT_2_10_10_10_REV;
texture->pboBufferSize = height * stride;
break; break;
case EGL_PF_YUV420: case EGL_PF_YUV420:
textureCount = 3; textureCount = 3;
texture->format = GL_RED; texture->format = GL_RED;
texture->planes[0][0] = width; texture->planes[0][0] = width;
texture->planes[0][1] = height; texture->planes[0][1] = height;
texture->planes[1][0] = width / 2; texture->planes[0][2] = stride;
texture->planes[1][1] = height / 2; texture->planes[1][0] = width / 2;
texture->planes[2][0] = width / 2; texture->planes[1][1] = height / 2;
texture->planes[2][1] = height / 2; texture->planes[1][2] = stride / 2;
texture->offsets[0] = 0; texture->planes[2][0] = width / 2;
texture->offsets[1] = width * height; texture->planes[2][1] = height / 2;
texture->offsets[2] = texture->offsets[1] + (texture->offsets[1] / 4); texture->planes[2][2] = stride / 2;
texture->dataType = GL_UNSIGNED_BYTE; 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; break;
default: 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]); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->pbo[i]);
glBufferData( glBufferData(
GL_PIXEL_UNPACK_BUFFER, GL_PIXEL_UNPACK_BUFFER,
bufferSize, height * stride,
NULL, NULL,
GL_DYNAMIC_DRAW 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) for(int i = 0; i < texture->textureCount; ++i)
{ {
glBindTexture(GL_TEXTURE_2D, texture->textures[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], glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->planes[i][0], texture->planes[i][1],
texture->format, texture->dataType, buffer + texture->offsets[i]); 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) for(int i = 0; i < texture->textureCount; ++i)
{ {
glBindTexture(GL_TEXTURE_2D, texture->textures[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], glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->planes[i][0], texture->planes[i][1],
texture->format, texture->dataType, (const void *)texture->offsets[i]); texture->format, texture->dataType, (const void *)texture->offsets[i]);
} }

View File

@ -37,7 +37,7 @@ enum EGL_PixelFormat
bool egl_texture_init(EGL_Texture ** tex); bool egl_texture_init(EGL_Texture ** tex);
void egl_texture_free(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); bool egl_texture_update(EGL_Texture * texture, const uint8_t * buffer);
void egl_texture_bind (EGL_Texture * texture); void egl_texture_bind (EGL_Texture * texture);
int egl_texture_count (EGL_Texture * texture); int egl_texture_count (EGL_Texture * texture);