From 1fcdcc87257e3d87aec535fdc35a6655a35ca279 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 21 May 2022 21:21:16 +1000 Subject: [PATCH] [client] egl: allow for partial texture updates --- client/renderers/EGL/texture.c | 49 +++++++++++++++++++++++++-- client/renderers/EGL/texture.h | 10 ++++++ client/renderers/EGL/texture_buffer.c | 10 +++--- common/include/common/util.h | 4 +++ 4 files changed, 67 insertions(+), 6 deletions(-) diff --git a/client/renderers/EGL/texture.c b/client/renderers/EGL/texture.c index 06af7c06..b5e89e71 100644 --- a/client/renderers/EGL/texture.c +++ b/client/renderers/EGL/texture.c @@ -108,6 +108,39 @@ bool egl_textureUpdate(EGL_Texture * this, const uint8_t * buffer) const struct EGL_TexUpdate update = { .type = EGL_TEXTYPE_BUFFER, + .x = 0, + .y = 0, + .width = this->format.width, + .height = this->format.height, + .pitch = this->format.pitch, + .stride = this->format.stride, + .buffer = buffer + }; + + return this->ops.update(this, &update); +} + +bool egl_textureUpdateRect(EGL_Texture * this, + int x, int y, int width, int height, int stride, + const uint8_t * buffer) +{ + x = clamp(x , 0, this->format.width ); + y = clamp(y , 0, this->format.height ); + width = clamp(width , x, this->format.width - x); + height = clamp(height, y, this->format.height - y); + + if (!width || !height) + return true; + + const struct EGL_TexUpdate update = + { + .type = EGL_TEXTYPE_BUFFER, + .x = x, + .y = y, + .width = width, + .height = height, + .pitch = stride / (stride / width), + .stride = stride, .buffer = buffer }; @@ -121,6 +154,12 @@ bool egl_textureUpdateFromFrame(EGL_Texture * this, const struct EGL_TexUpdate update = { .type = EGL_TEXTYPE_FRAMEBUFFER, + .x = 0, + .y = 0, + .width = this->format.width, + .height = this->format.height, + .pitch = this->format.pitch, + .stride = this->format.stride, .frame = frame, .rects = damageRects, .rectCount = damageRectsCount, @@ -134,8 +173,14 @@ bool egl_textureUpdateFromDMA(EGL_Texture * this, { const struct EGL_TexUpdate update = { - .type = EGL_TEXTYPE_DMABUF, - .dmaFD = dmaFd + .type = EGL_TEXTYPE_DMABUF, + .x = 0, + .y = 0, + .width = this->format.width, + .height = this->format.height, + .pitch = this->format.pitch, + .stride = this->format.stride, + .dmaFD = dmaFd }; /* wait for completion */ diff --git a/client/renderers/EGL/texture.h b/client/renderers/EGL/texture.h index 53d709b4..3f251a84 100644 --- a/client/renderers/EGL/texture.h +++ b/client/renderers/EGL/texture.h @@ -42,6 +42,12 @@ typedef struct EGL_TexUpdate /* the type of this update */ EGL_TexType type; + int x, y, width, height; + + //pitch = row length in pixels + //stride = row length in bytes + int pitch, stride; + union { /* EGL_TEXTURE_BUFFER */ @@ -102,6 +108,10 @@ bool egl_textureSetup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt, bool egl_textureUpdate(EGL_Texture * texture, const uint8_t * buffer); +bool egl_textureUpdateRect(EGL_Texture * texture, + int x, int y, int width, int height, int stride, + const uint8_t * buffer); + bool egl_textureUpdateFromFrame(EGL_Texture * texture, const FrameBuffer * frame, const FrameDamageRect * damageRects, int damageRectsCount); diff --git a/client/renderers/EGL/texture_buffer.c b/client/renderers/EGL/texture_buffer.c index 2ee83223..5f7b497b 100644 --- a/client/renderers/EGL/texture_buffer.c +++ b/client/renderers/EGL/texture_buffer.c @@ -111,11 +111,13 @@ static bool egl_texBufferUpdate(EGL_Texture * texture, const EGL_TexUpdate * upd DEBUG_ASSERT(update->type == EGL_TEXTYPE_BUFFER); glBindTexture(GL_TEXTURE_2D, this->tex[0]); - glPixelStorei(GL_UNPACK_ROW_LENGTH, texture->format.pitch); + glPixelStorei(GL_UNPACK_ROW_LENGTH, update->pitch); glTexSubImage2D(GL_TEXTURE_2D, - 0, 0, 0, - texture->format.width, - texture->format.height, + 0, + update->x, + update->y, + update->width, + update->height, texture->format.format, texture->format.dataType, update->buffer); diff --git a/common/include/common/util.h b/common/include/common/util.h index 0f5a2fe4..bb21fecc 100644 --- a/common/include/common/util.h +++ b/common/include/common/util.h @@ -31,6 +31,10 @@ _a > _b ? _a : _b; }) #endif +#ifndef clamp +#define clamp(v,a,b) min(max(v, a), b) +#endif + #define UPCAST(type, x) \ (type *)((uintptr_t)(x) - offsetof(type, base))