2021-08-02 13:37:33 +00:00
|
|
|
/**
|
|
|
|
* Looking Glass
|
2021-08-04 09:48:32 +00:00
|
|
|
* Copyright © 2017-2021 The Looking Glass Authors
|
2021-08-02 13:37:33 +00:00
|
|
|
* https://looking-glass.io
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
|
|
|
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "texture.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "texture_buffer.h"
|
|
|
|
#include "common/debug.h"
|
2021-08-07 06:10:30 +00:00
|
|
|
#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;
|
2021-08-07 23:43:28 +00:00
|
|
|
if (!eglTexBuffer_stream_init(&parent, display))
|
2021-08-07 06:10:30 +00:00
|
|
|
{
|
|
|
|
free(this);
|
|
|
|
*texture = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < EGL_TEX_BUFFER_MAX; ++i)
|
|
|
|
this->damage[i].count = -1;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-08-02 13:37:33 +00:00
|
|
|
|
2021-08-02 17:58:30 +00:00
|
|
|
static bool eglTexFB_update(EGL_Texture * texture, const EGL_TexUpdate * update)
|
2021-08-02 13:37:33 +00:00
|
|
|
{
|
2021-08-07 23:35:56 +00:00
|
|
|
TextureBuffer * parent = UPCAST(TextureBuffer, texture);
|
|
|
|
TexFB * this = UPCAST(TexFB , parent );
|
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
assert(update->type == EGL_TEXTYPE_FRAMEBUFFER);
|
|
|
|
|
2021-08-07 23:35:56 +00:00
|
|
|
LG_LOCK(parent->copyLock);
|
2021-08-02 13:37:33 +00:00
|
|
|
|
2021-08-07 23:35:56 +00:00
|
|
|
struct TexDamage * damage = this->damage + parent->bufIndex;
|
2021-08-07 06:10:30 +00:00
|
|
|
bool damageAll = !update->rects || update->rectCount == 0 || damage->count < 0 ||
|
|
|
|
damage->count + update->rectCount > KVMFR_MAX_DAMAGE_RECTS;
|
|
|
|
|
|
|
|
if (damageAll)
|
|
|
|
framebuffer_read(
|
|
|
|
update->frame,
|
2021-08-07 23:35:56 +00:00
|
|
|
parent->buf[parent->bufIndex].map,
|
|
|
|
parent->format.stride,
|
|
|
|
parent->format.height,
|
|
|
|
parent->format.width,
|
|
|
|
parent->format.bpp,
|
|
|
|
parent->format.stride
|
2021-08-07 06:10:30 +00:00
|
|
|
);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(damage->rects + damage->count, update->rects,
|
|
|
|
update->rectCount * sizeof(FrameDamageRect));
|
|
|
|
damage->count += update->rectCount;
|
|
|
|
rectsFramebufferToBuffer(
|
|
|
|
damage->rects,
|
|
|
|
damage->count,
|
2021-08-07 23:35:56 +00:00
|
|
|
parent->buf[parent->bufIndex].map,
|
|
|
|
parent->format.stride,
|
|
|
|
parent->format.height,
|
2021-08-07 06:10:30 +00:00
|
|
|
update->frame,
|
2021-08-07 23:35:56 +00:00
|
|
|
parent->format.stride
|
2021-08-07 06:10:30 +00:00
|
|
|
);
|
|
|
|
}
|
2021-08-02 13:37:33 +00:00
|
|
|
|
2021-08-07 23:35:56 +00:00
|
|
|
parent->buf[parent->bufIndex].updated = true;
|
2021-08-07 06:10:30 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < EGL_TEX_BUFFER_MAX; ++i)
|
|
|
|
{
|
2021-08-07 23:35:56 +00:00
|
|
|
struct TexDamage * damage = this->damage + i;
|
|
|
|
if (i == parent->bufIndex)
|
2021-08-07 06:10:30 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-08-07 23:35:56 +00:00
|
|
|
LG_UNLOCK(parent->copyLock);
|
2021-08-02 13:37:33 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGL_TextureOps EGL_TextureFrameBuffer =
|
|
|
|
{
|
2021-08-07 06:10:30 +00:00
|
|
|
.init = eglTexFB_init,
|
2021-08-02 13:37:33 +00:00
|
|
|
.free = eglTexBuffer_free,
|
|
|
|
.setup = eglTexBuffer_stream_setup,
|
|
|
|
.update = eglTexFB_update,
|
|
|
|
.process = eglTexBuffer_stream_process,
|
|
|
|
.bind = eglTexBuffer_stream_bind
|
|
|
|
};
|