mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-09-02 04:03:56 +00:00
Some checks failed
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Has been cancelled
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Has been cancelled
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Has been cancelled
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Has been cancelled
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Has been cancelled
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Has been cancelled
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Has been cancelled
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Has been cancelled
build / module (push) Has been cancelled
build / host-linux (push) Has been cancelled
build / host-windows-cross (push) Has been cancelled
build / host-windows-native (push) Has been cancelled
build / idd (push) Has been cancelled
build / obs (clang) (push) Has been cancelled
build / obs (gcc) (push) Has been cancelled
build / docs (push) Has been cancelled
Add LGProtocol as a pinned submodule and consume its KVMFR protocol definitions throughout the client, host, IDD, OBS, and profiler. Keep Looking Glass framebuffer helpers local while removing duplicated protocol headers and migrating users to KVMFR-scoped types.
264 lines
6.7 KiB
C
264 lines
6.7 KiB
C
/**
|
|
* Looking Glass
|
|
* Copyright © 2017-2026 The Looking Glass Authors
|
|
* 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 "state.h"
|
|
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
#include "shader.h"
|
|
#include "common/framebuffer.h"
|
|
#include "common/debug.h"
|
|
#include "common/array.h"
|
|
|
|
#include <EGL/egl.h>
|
|
#include <EGL/eglext.h>
|
|
|
|
#include "texture_buffer.h"
|
|
|
|
extern const EGL_TextureOps EGL_TextureBuffer;
|
|
extern const EGL_TextureOps EGL_TextureBufferStream;
|
|
extern const EGL_TextureOps EGL_TextureFrameBuffer;
|
|
extern const EGL_TextureOps EGL_TextureDMABUF;
|
|
|
|
bool egl_textureInit(EGL_Texture ** texture_, EGLDisplay * display,
|
|
EGL_TexType type)
|
|
{
|
|
const EGL_TextureOps * ops;
|
|
|
|
switch(type)
|
|
{
|
|
case EGL_TEXTYPE_BUFFER:
|
|
ops = &EGL_TextureBuffer;
|
|
break;
|
|
|
|
case EGL_TEXTYPE_BUFFER_MAP:
|
|
case EGL_TEXTYPE_BUFFER_STREAM:
|
|
ops = &EGL_TextureBufferStream;
|
|
break;
|
|
|
|
case EGL_TEXTYPE_FRAMEBUFFER:
|
|
ops = &EGL_TextureFrameBuffer;
|
|
break;
|
|
|
|
case EGL_TEXTYPE_DMABUF:
|
|
ops = &EGL_TextureDMABUF;
|
|
break;
|
|
|
|
default:
|
|
return false;
|
|
}
|
|
|
|
*texture_ = NULL;
|
|
if (!ops->init(texture_, type, display))
|
|
return false;
|
|
|
|
EGL_Texture * this = *texture_;
|
|
memcpy(&this->ops, ops, sizeof(*ops));
|
|
|
|
glGenSamplers(1, &this->sampler);
|
|
glSamplerParameteri(this->sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
glSamplerParameteri(this->sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
glSamplerParameteri(this->sampler, GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE);
|
|
glSamplerParameteri(this->sampler, GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE);
|
|
|
|
return true;
|
|
}
|
|
|
|
void egl_textureFree(EGL_Texture ** tex)
|
|
{
|
|
EGL_Texture * this = *tex;
|
|
if (!this)
|
|
return;
|
|
|
|
glDeleteSamplers(1, &this->sampler);
|
|
egl_stateInvalidateShared();
|
|
|
|
this->ops.free(this);
|
|
*tex = NULL;
|
|
}
|
|
|
|
bool egl_textureSetup(EGL_Texture * this, enum EGL_PixelFormat pixFmt,
|
|
size_t width, size_t height, size_t stride, size_t pitch)
|
|
{
|
|
const struct EGL_TexSetup setup =
|
|
{
|
|
.pixFmt = pixFmt,
|
|
.width = width,
|
|
.height = height,
|
|
.stride = stride,
|
|
.pitch = pitch,
|
|
};
|
|
|
|
if (!egl_texUtilGetFormat(&setup, &this->format))
|
|
return false;
|
|
|
|
return this->ops.setup(this, &setup);
|
|
}
|
|
|
|
bool egl_textureUpdate(EGL_Texture * this, const uint8_t * buffer, bool topDown)
|
|
{
|
|
const struct EGL_TexUpdate update =
|
|
{
|
|
.type = EGL_TEXTYPE_BUFFER,
|
|
.x = 0,
|
|
.y = 0,
|
|
.width = this->format.width,
|
|
.height = this->format.height,
|
|
.pitch = this->format.pitch,
|
|
.stride = this->format.stride,
|
|
.topDown = topDown,
|
|
.buffer = buffer
|
|
};
|
|
|
|
return this->ops.update(this, &update);
|
|
}
|
|
|
|
bool egl_textureUpdateRect(EGL_Texture * this,
|
|
int x, int y, int width, int height, int stride, int pitch,
|
|
const uint8_t * buffer, bool topDown)
|
|
{
|
|
x = clamp(x , 0, this->format.width );
|
|
y = clamp(y , 0, this->format.height );
|
|
width = clamp(width , 0, this->format.width - x);
|
|
height = clamp(height, 0, 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,
|
|
.stride = stride,
|
|
.pitch = pitch,
|
|
.topDown = topDown,
|
|
.buffer = buffer
|
|
};
|
|
|
|
return this->ops.update(this, &update);
|
|
}
|
|
|
|
bool egl_textureUpdateFromFrame(EGL_Texture * this,
|
|
const KVMFRFrameBuffer * frame, LG_RendererFrameToken frameToken,
|
|
const KVMFRFrameDamageRect * damageRects, int damageRectsCount,
|
|
uint64_t * waitTimeNs)
|
|
{
|
|
const struct EGL_TexUpdate update =
|
|
{
|
|
.type = EGL_TEXTYPE_FRAMEBUFFER,
|
|
.frameToken = frameToken,
|
|
.x = 0,
|
|
.y = 0,
|
|
.width = this->format.width,
|
|
.height = this->format.height,
|
|
.pitch = this->format.pitch,
|
|
.stride = this->format.stride,
|
|
.frame = frame,
|
|
.rects = damageRects,
|
|
.rectCount = damageRectsCount,
|
|
.waitTimeNs = waitTimeNs,
|
|
};
|
|
|
|
return this->ops.update(this, &update);
|
|
}
|
|
|
|
bool egl_textureUpdateFromDMA(EGL_Texture * this,
|
|
const KVMFRFrameBuffer * frame, LG_RendererFrameToken frameToken,
|
|
const int dmaFd, uint64_t * waitTimeNs, LG_FrameReleaseFn releaseFn,
|
|
void * releaseOpaque, uint64_t releaseHandle)
|
|
{
|
|
const struct EGL_TexUpdate update =
|
|
{
|
|
.type = EGL_TEXTYPE_DMABUF,
|
|
.frameToken = frameToken,
|
|
.x = 0,
|
|
.y = 0,
|
|
.width = this->format.width,
|
|
.height = this->format.height,
|
|
.pitch = this->format.pitch,
|
|
.stride = this->format.stride,
|
|
.dmaFD = dmaFd,
|
|
.releaseFn = releaseFn,
|
|
.releaseOpaque = releaseOpaque,
|
|
.releaseHandle = releaseHandle,
|
|
};
|
|
|
|
/* wait for completion */
|
|
if (unlikely(!framebuffer_wait_timed(
|
|
frame, this->format.dataSize, waitTimeNs)))
|
|
return false;
|
|
|
|
return this->ops.update(this, &update);
|
|
}
|
|
|
|
void egl_textureReset(EGL_Texture * this)
|
|
{
|
|
if (this->ops.reset)
|
|
this->ops.reset(this);
|
|
}
|
|
|
|
void egl_texturePoll(EGL_Texture * this)
|
|
{
|
|
if (this->ops.poll)
|
|
this->ops.poll(this);
|
|
}
|
|
|
|
void egl_textureMarkUsed(EGL_Texture * this)
|
|
{
|
|
if (this->ops.markUsed)
|
|
this->ops.markUsed(this);
|
|
}
|
|
|
|
enum EGL_TexStatus egl_textureProcess(EGL_Texture * this,
|
|
LG_RendererFrameToken frameTokenLimit,
|
|
LG_RendererFrameToken * consumedFrameToken)
|
|
{
|
|
if (consumedFrameToken)
|
|
*consumedFrameToken = LG_RENDERER_FRAME_TOKEN_NONE;
|
|
|
|
const enum EGL_TexStatus status =
|
|
this->ops.process(this, frameTokenLimit);
|
|
if (status == EGL_TEX_STATUS_UPDATED && consumedFrameToken)
|
|
*consumedFrameToken = this->frameToken;
|
|
return status;
|
|
}
|
|
|
|
enum EGL_TexStatus egl_textureBind(EGL_Texture * this)
|
|
{
|
|
return egl_textureBindWithSampler(this, this->sampler);
|
|
}
|
|
|
|
enum EGL_TexStatus egl_textureBindWithSampler(EGL_Texture * this,
|
|
GLuint sampler)
|
|
{
|
|
return egl_textureBindUnitWithSampler(this, 0, sampler);
|
|
}
|
|
|
|
enum EGL_TexStatus egl_textureBindUnitWithSampler(EGL_Texture * this,
|
|
GLuint unit, GLuint sampler)
|
|
{
|
|
egl_stateBindSampler(unit, sampler);
|
|
return this->ops.bind(this, unit);
|
|
}
|