diff --git a/client/renderers/EGL/desktop.c b/client/renderers/EGL/desktop.c index f64523c4..cd179a73 100644 --- a/client/renderers/EGL/desktop.c +++ b/client/renderers/EGL/desktop.c @@ -256,7 +256,8 @@ bool egl_desktop_setup(EGL_Desktop * desktop, const LG_RendererFormat format) return true; } -bool egl_desktop_update(EGL_Desktop * desktop, const FrameBuffer * frame, int dmaFd) +bool egl_desktop_update(EGL_Desktop * desktop, const FrameBuffer * frame, int dmaFd, + const FrameDamageRect * damageRects, int damageRectsCount) { if (dmaFd >= 0) { @@ -265,7 +266,7 @@ bool egl_desktop_update(EGL_Desktop * desktop, const FrameBuffer * frame, int dm } else { - if (!egl_texture_update_from_frame(desktop->texture, frame)) + if (!egl_texture_update_from_frame(desktop->texture, frame, damageRects, damageRectsCount)) return false; } diff --git a/client/renderers/EGL/desktop.h b/client/renderers/EGL/desktop.h index 76bcebdf..a6af953b 100644 --- a/client/renderers/EGL/desktop.h +++ b/client/renderers/EGL/desktop.h @@ -42,7 +42,8 @@ void egl_desktop_free(EGL_Desktop ** desktop); void egl_desktop_config_ui(EGL_Desktop * desktop); bool egl_desktop_setup (EGL_Desktop * desktop, const LG_RendererFormat format); -bool egl_desktop_update(EGL_Desktop * desktop, const FrameBuffer * frame, int dmaFd); +bool egl_desktop_update(EGL_Desktop * desktop, const FrameBuffer * frame, int dmaFd, + const FrameDamageRect * damageRects, int damageRectsCount); bool egl_desktop_render(EGL_Desktop * desktop, const float x, const float y, const float scaleX, const float scaleY, enum EGL_DesktopScaleType scaleType, LG_RendererRotate rotate, const struct DamageRects * rects); diff --git a/client/renderers/EGL/egl.c b/client/renderers/EGL/egl.c index 3487947b..9b2c49d3 100644 --- a/client/renderers/EGL/egl.c +++ b/client/renderers/EGL/egl.c @@ -512,7 +512,7 @@ static bool egl_on_frame(void * opaque, const FrameBuffer * frame, int dmaFd, struct Inst * this = (struct Inst *)opaque; uint64_t start = nanotime(); - if (!egl_desktop_update(this->desktop, frame, dmaFd)) + if (!egl_desktop_update(this->desktop, frame, dmaFd, damageRects, damageRectsCount)) { DEBUG_INFO("Failed to to update the desktop"); return false; diff --git a/client/renderers/EGL/texture.c b/client/renderers/EGL/texture.c index 6bf3717c..9f3e4c46 100644 --- a/client/renderers/EGL/texture.c +++ b/client/renderers/EGL/texture.c @@ -99,12 +99,15 @@ bool egl_texture_update(EGL_Texture * texture, const uint8_t * buffer) } bool egl_texture_update_from_frame(EGL_Texture * texture, - const FrameBuffer * frame) + const FrameBuffer * frame, const FrameDamageRect * damageRects, + int damageRectsCount) { const struct EGL_TexUpdate update = { - .type = EGL_TEXTYPE_FRAMEBUFFER, - .frame = frame + .type = EGL_TEXTYPE_FRAMEBUFFER, + .frame = frame, + .rects = damageRects, + .rectCount = damageRectsCount, }; return texture->ops->update(texture, &update); } diff --git a/client/renderers/EGL/texture.h b/client/renderers/EGL/texture.h index be32e9f3..c1849bb2 100644 --- a/client/renderers/EGL/texture.h +++ b/client/renderers/EGL/texture.h @@ -92,7 +92,12 @@ typedef struct EGL_TexUpdate const uint8_t * buffer; /* EGL_TEXTURE_FRAMEBUFFER */ - const FrameBuffer * frame; + struct + { + const FrameBuffer * frame; + const FrameDamageRect * rects; + int rectCount; + }; /* EGL_TEXTURE_DMABUF */ int dmaFD; @@ -132,7 +137,8 @@ bool egl_texture_setup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt, bool egl_texture_update (EGL_Texture * texture, const uint8_t * buffer); bool egl_texture_update_from_frame(EGL_Texture * texture, - const FrameBuffer * frame); + const FrameBuffer * frame, const FrameDamageRect * damageRects, + int damageRectsCount); bool egl_texture_update_from_dma(EGL_Texture * texture, const FrameBuffer * frame, const int dmaFd); diff --git a/client/renderers/EGL/texture_buffer.h b/client/renderers/EGL/texture_buffer.h index 958d8275..e40eb814 100644 --- a/client/renderers/EGL/texture_buffer.h +++ b/client/renderers/EGL/texture_buffer.h @@ -24,6 +24,8 @@ #include "texture_util.h" #include "common/locking.h" +#define EGL_TEX_BUFFER_MAX 2 + typedef struct TextureBuffer { EGL_Texture base; @@ -31,9 +33,9 @@ typedef struct TextureBuffer EGL_TexFormat format; int texCount; - GLuint tex[2]; + GLuint tex[EGL_TEX_BUFFER_MAX]; GLuint sampler; - EGL_TexBuffer buf[2]; + EGL_TexBuffer buf[EGL_TEX_BUFFER_MAX]; int bufFree; GLsync sync; LG_Lock copyLock; diff --git a/client/renderers/EGL/texture_framebuffer.c b/client/renderers/EGL/texture_framebuffer.c index 1cfa5d2e..dbe132fd 100644 --- a/client/renderers/EGL/texture_framebuffer.c +++ b/client/renderers/EGL/texture_framebuffer.c @@ -24,25 +24,97 @@ #include "texture_buffer.h" #include "common/debug.h" +#include "common/KVMFR.h" +#include "common/rects.h" + +struct TexDamage +{ + int count; + FrameDamageRect rects[KVMFR_MAX_DAMAGE_RECTS]; +}; + +typedef struct TexFB +{ + TextureBuffer base; + struct TexDamage damage[EGL_TEX_BUFFER_MAX]; +} +TexFB; + +static bool eglTexFB_init(EGL_Texture ** texture, EGLDisplay * display) +{ + TexFB * this = calloc(sizeof(*this), 1); + *texture = &this->base.base; + + EGL_Texture * parent = &this->base.base; + if (!eglTexBuffer_init(&parent, display)) + { + free(this); + *texture = NULL; + return false; + } + + for (int i = 0; i < EGL_TEX_BUFFER_MAX; ++i) + this->damage[i].count = -1; + + return true; +} static bool eglTexFB_update(EGL_Texture * texture, const EGL_TexUpdate * update) { TextureBuffer * this = UPCAST(TextureBuffer, texture); + TexFB * fb = UPCAST(TexFB, this); assert(update->type == EGL_TEXTYPE_FRAMEBUFFER); LG_LOCK(this->copyLock); - framebuffer_read( - update->frame, - this->buf[this->bufIndex].map, - this->format.stride, - this->format.height, - this->format.width, - this->format.bpp, - this->format.stride - ); + struct TexDamage * damage = fb->damage + this->bufIndex; + bool damageAll = !update->rects || update->rectCount == 0 || damage->count < 0 || + damage->count + update->rectCount > KVMFR_MAX_DAMAGE_RECTS; + + if (damageAll) + framebuffer_read( + update->frame, + this->buf[this->bufIndex].map, + this->format.stride, + this->format.height, + this->format.width, + this->format.bpp, + this->format.stride + ); + else + { + memcpy(damage->rects + damage->count, update->rects, + update->rectCount * sizeof(FrameDamageRect)); + damage->count += update->rectCount; + rectsFramebufferToBuffer( + damage->rects, + damage->count, + this->buf[this->bufIndex].map, + this->format.stride, + this->format.height, + update->frame, + this->format.stride + ); + } this->buf[this->bufIndex].updated = true; + + for (int i = 0; i < EGL_TEX_BUFFER_MAX; ++i) + { + struct TexDamage * damage = fb->damage + i; + if (i == this->bufIndex) + damage->count = 0; + else if (update->rects && update->rectCount > 0 && damage->count >= 0 && + damage->count + update->rectCount <= KVMFR_MAX_DAMAGE_RECTS) + { + memcpy(damage->rects + damage->count, update->rects, + update->rectCount * sizeof(FrameDamageRect)); + damage->count += update->rectCount; + } + else + damage->count = -1; + } + LG_UNLOCK(this->copyLock); return true; @@ -50,7 +122,7 @@ static bool eglTexFB_update(EGL_Texture * texture, const EGL_TexUpdate * update) EGL_TextureOps EGL_TextureFrameBuffer = { - .init = eglTexBuffer_stream_init, + .init = eglTexFB_init, .free = eglTexBuffer_free, .setup = eglTexBuffer_stream_setup, .update = eglTexFB_update,