[client] egl: allow for partial texture updates

This commit is contained in:
Geoffrey McRae 2022-05-21 21:21:16 +10:00
parent 7ad3610276
commit 1fcdcc8725
4 changed files with 67 additions and 6 deletions

View File

@ -108,6 +108,39 @@ bool egl_textureUpdate(EGL_Texture * this, const uint8_t * buffer)
const struct EGL_TexUpdate update = const struct EGL_TexUpdate update =
{ {
.type = EGL_TEXTYPE_BUFFER, .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 .buffer = buffer
}; };
@ -121,6 +154,12 @@ bool egl_textureUpdateFromFrame(EGL_Texture * this,
const struct EGL_TexUpdate update = const struct EGL_TexUpdate update =
{ {
.type = EGL_TEXTYPE_FRAMEBUFFER, .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, .frame = frame,
.rects = damageRects, .rects = damageRects,
.rectCount = damageRectsCount, .rectCount = damageRectsCount,
@ -134,8 +173,14 @@ bool egl_textureUpdateFromDMA(EGL_Texture * this,
{ {
const struct EGL_TexUpdate update = const struct EGL_TexUpdate update =
{ {
.type = EGL_TEXTYPE_DMABUF, .type = EGL_TEXTYPE_DMABUF,
.dmaFD = dmaFd .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 */ /* wait for completion */

View File

@ -42,6 +42,12 @@ typedef struct EGL_TexUpdate
/* the type of this update */ /* the type of this update */
EGL_TexType type; EGL_TexType type;
int x, y, width, height;
//pitch = row length in pixels
//stride = row length in bytes
int pitch, stride;
union union
{ {
/* EGL_TEXTURE_BUFFER */ /* 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_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, bool egl_textureUpdateFromFrame(EGL_Texture * texture,
const FrameBuffer * frame, const FrameDamageRect * damageRects, const FrameBuffer * frame, const FrameDamageRect * damageRects,
int damageRectsCount); int damageRectsCount);

View File

@ -111,11 +111,13 @@ static bool egl_texBufferUpdate(EGL_Texture * texture, const EGL_TexUpdate * upd
DEBUG_ASSERT(update->type == EGL_TEXTYPE_BUFFER); DEBUG_ASSERT(update->type == EGL_TEXTYPE_BUFFER);
glBindTexture(GL_TEXTURE_2D, this->tex[0]); 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, glTexSubImage2D(GL_TEXTURE_2D,
0, 0, 0, 0,
texture->format.width, update->x,
texture->format.height, update->y,
update->width,
update->height,
texture->format.format, texture->format.format,
texture->format.dataType, texture->format.dataType,
update->buffer); update->buffer);

View File

@ -31,6 +31,10 @@
_a > _b ? _a : _b; }) _a > _b ? _a : _b; })
#endif #endif
#ifndef clamp
#define clamp(v,a,b) min(max(v, a), b)
#endif
#define UPCAST(type, x) \ #define UPCAST(type, x) \
(type *)((uintptr_t)(x) - offsetof(type, base)) (type *)((uintptr_t)(x) - offsetof(type, base))