mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-01-10 14:57:04 +00:00
[client] egl: implement partial copies for framebuffer textures
This uses the same line sweep algorithm originally created to copy DXGI textures to IVSHMEM to implement the copy from IVSHMEM to memory-mapped pixel buffer objects.
This commit is contained in:
parent
0462cee9db
commit
ac3677d9ae
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
.frame = frame,
|
||||
.rects = damageRects,
|
||||
.rectCount = damageRectsCount,
|
||||
};
|
||||
return texture->ops->update(texture, &update);
|
||||
}
|
||||
|
@ -92,7 +92,12 @@ typedef struct EGL_TexUpdate
|
||||
const uint8_t * buffer;
|
||||
|
||||
/* EGL_TEXTURE_FRAMEBUFFER */
|
||||
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);
|
||||
|
@ -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;
|
||||
|
@ -24,14 +24,54 @@
|
||||
|
||||
#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);
|
||||
|
||||
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,
|
||||
@ -41,8 +81,40 @@ static bool eglTexFB_update(EGL_Texture * texture, const EGL_TexUpdate * update)
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user