mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-01-10 23:07: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;
|
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)
|
if (dmaFd >= 0)
|
||||||
{
|
{
|
||||||
@ -265,7 +266,7 @@ bool egl_desktop_update(EGL_Desktop * desktop, const FrameBuffer * frame, int dm
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!egl_texture_update_from_frame(desktop->texture, frame))
|
if (!egl_texture_update_from_frame(desktop->texture, frame, damageRects, damageRectsCount))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,8 @@ void egl_desktop_free(EGL_Desktop ** desktop);
|
|||||||
|
|
||||||
void egl_desktop_config_ui(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_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,
|
bool egl_desktop_render(EGL_Desktop * desktop, const float x, const float y,
|
||||||
const float scaleX, const float scaleY, enum EGL_DesktopScaleType scaleType,
|
const float scaleX, const float scaleY, enum EGL_DesktopScaleType scaleType,
|
||||||
LG_RendererRotate rotate, const struct DamageRects * rects);
|
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;
|
struct Inst * this = (struct Inst *)opaque;
|
||||||
|
|
||||||
uint64_t start = nanotime();
|
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");
|
DEBUG_INFO("Failed to to update the desktop");
|
||||||
return false;
|
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,
|
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 =
|
const struct EGL_TexUpdate update =
|
||||||
{
|
{
|
||||||
.type = EGL_TEXTYPE_FRAMEBUFFER,
|
.type = EGL_TEXTYPE_FRAMEBUFFER,
|
||||||
.frame = frame
|
.frame = frame,
|
||||||
|
.rects = damageRects,
|
||||||
|
.rectCount = damageRectsCount,
|
||||||
};
|
};
|
||||||
return texture->ops->update(texture, &update);
|
return texture->ops->update(texture, &update);
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,12 @@ typedef struct EGL_TexUpdate
|
|||||||
const uint8_t * buffer;
|
const uint8_t * buffer;
|
||||||
|
|
||||||
/* EGL_TEXTURE_FRAMEBUFFER */
|
/* EGL_TEXTURE_FRAMEBUFFER */
|
||||||
const FrameBuffer * frame;
|
struct
|
||||||
|
{
|
||||||
|
const FrameBuffer * frame;
|
||||||
|
const FrameDamageRect * rects;
|
||||||
|
int rectCount;
|
||||||
|
};
|
||||||
|
|
||||||
/* EGL_TEXTURE_DMABUF */
|
/* EGL_TEXTURE_DMABUF */
|
||||||
int dmaFD;
|
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 (EGL_Texture * texture, const uint8_t * buffer);
|
||||||
|
|
||||||
bool egl_texture_update_from_frame(EGL_Texture * texture,
|
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,
|
bool egl_texture_update_from_dma(EGL_Texture * texture,
|
||||||
const FrameBuffer * frame, const int dmaFd);
|
const FrameBuffer * frame, const int dmaFd);
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#include "texture_util.h"
|
#include "texture_util.h"
|
||||||
#include "common/locking.h"
|
#include "common/locking.h"
|
||||||
|
|
||||||
|
#define EGL_TEX_BUFFER_MAX 2
|
||||||
|
|
||||||
typedef struct TextureBuffer
|
typedef struct TextureBuffer
|
||||||
{
|
{
|
||||||
EGL_Texture base;
|
EGL_Texture base;
|
||||||
@ -31,9 +33,9 @@ typedef struct TextureBuffer
|
|||||||
|
|
||||||
EGL_TexFormat format;
|
EGL_TexFormat format;
|
||||||
int texCount;
|
int texCount;
|
||||||
GLuint tex[2];
|
GLuint tex[EGL_TEX_BUFFER_MAX];
|
||||||
GLuint sampler;
|
GLuint sampler;
|
||||||
EGL_TexBuffer buf[2];
|
EGL_TexBuffer buf[EGL_TEX_BUFFER_MAX];
|
||||||
int bufFree;
|
int bufFree;
|
||||||
GLsync sync;
|
GLsync sync;
|
||||||
LG_Lock copyLock;
|
LG_Lock copyLock;
|
||||||
|
@ -24,25 +24,97 @@
|
|||||||
|
|
||||||
#include "texture_buffer.h"
|
#include "texture_buffer.h"
|
||||||
#include "common/debug.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)
|
static bool eglTexFB_update(EGL_Texture * texture, const EGL_TexUpdate * update)
|
||||||
{
|
{
|
||||||
TextureBuffer * this = UPCAST(TextureBuffer, texture);
|
TextureBuffer * this = UPCAST(TextureBuffer, texture);
|
||||||
|
TexFB * fb = UPCAST(TexFB, this);
|
||||||
assert(update->type == EGL_TEXTYPE_FRAMEBUFFER);
|
assert(update->type == EGL_TEXTYPE_FRAMEBUFFER);
|
||||||
|
|
||||||
LG_LOCK(this->copyLock);
|
LG_LOCK(this->copyLock);
|
||||||
|
|
||||||
framebuffer_read(
|
struct TexDamage * damage = fb->damage + this->bufIndex;
|
||||||
update->frame,
|
bool damageAll = !update->rects || update->rectCount == 0 || damage->count < 0 ||
|
||||||
this->buf[this->bufIndex].map,
|
damage->count + update->rectCount > KVMFR_MAX_DAMAGE_RECTS;
|
||||||
this->format.stride,
|
|
||||||
this->format.height,
|
if (damageAll)
|
||||||
this->format.width,
|
framebuffer_read(
|
||||||
this->format.bpp,
|
update->frame,
|
||||||
this->format.stride
|
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;
|
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);
|
LG_UNLOCK(this->copyLock);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -50,7 +122,7 @@ static bool eglTexFB_update(EGL_Texture * texture, const EGL_TexUpdate * update)
|
|||||||
|
|
||||||
EGL_TextureOps EGL_TextureFrameBuffer =
|
EGL_TextureOps EGL_TextureFrameBuffer =
|
||||||
{
|
{
|
||||||
.init = eglTexBuffer_stream_init,
|
.init = eglTexFB_init,
|
||||||
.free = eglTexBuffer_free,
|
.free = eglTexBuffer_free,
|
||||||
.setup = eglTexBuffer_stream_setup,
|
.setup = eglTexBuffer_stream_setup,
|
||||||
.update = eglTexFB_update,
|
.update = eglTexFB_update,
|
||||||
|
Loading…
Reference in New Issue
Block a user