2021-06-06 01:26:18 +00:00
|
|
|
/**
|
|
|
|
* Looking Glass
|
2021-08-04 09:48:32 +00:00
|
|
|
* Copyright © 2017-2021 The Looking Glass Authors
|
2021-06-06 01:26:18 +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
|
|
|
|
*/
|
2018-09-23 05:48:44 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2021-08-09 04:08:10 +00:00
|
|
|
#include "egl.h"
|
2018-12-12 05:39:04 +00:00
|
|
|
#include "shader.h"
|
2021-08-09 04:08:10 +00:00
|
|
|
#include "model.h"
|
2019-10-01 13:17:20 +00:00
|
|
|
#include "common/framebuffer.h"
|
2021-08-09 04:08:10 +00:00
|
|
|
#include "common/ringbuffer.h"
|
2018-09-23 05:48:44 +00:00
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
#include "util.h"
|
2021-08-09 04:08:10 +00:00
|
|
|
#include "ll.h"
|
2021-08-02 13:37:33 +00:00
|
|
|
|
2021-02-20 06:45:38 +00:00
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <EGL/eglext.h>
|
2018-09-23 05:48:44 +00:00
|
|
|
|
2021-08-09 04:08:10 +00:00
|
|
|
#include "texture_util.h"
|
|
|
|
|
|
|
|
typedef struct EGL_Model EGL_Model;
|
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
typedef enum EGL_TexType
|
|
|
|
{
|
|
|
|
EGL_TEXTYPE_BUFFER,
|
|
|
|
EGL_TEXTYPE_FRAMEBUFFER,
|
|
|
|
EGL_TEXTYPE_DMABUF
|
|
|
|
}
|
|
|
|
EGL_TexType;
|
|
|
|
|
|
|
|
typedef enum EGL_PixelFormat
|
2018-09-23 10:45:20 +00:00
|
|
|
{
|
|
|
|
EGL_PF_RGBA,
|
|
|
|
EGL_PF_BGRA,
|
2018-12-04 10:23:28 +00:00
|
|
|
EGL_PF_RGBA10,
|
2021-08-02 13:37:33 +00:00
|
|
|
EGL_PF_RGBA16F
|
|
|
|
}
|
|
|
|
EGL_PixelFormat;
|
2018-09-23 10:45:20 +00:00
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
typedef enum EGL_TexStatus
|
2019-06-12 12:36:00 +00:00
|
|
|
{
|
|
|
|
EGL_TEX_STATUS_NOTREADY,
|
|
|
|
EGL_TEX_STATUS_OK,
|
|
|
|
EGL_TEX_STATUS_ERROR
|
2021-08-02 13:37:33 +00:00
|
|
|
}
|
|
|
|
EGL_TexStatus;
|
|
|
|
|
|
|
|
typedef struct EGL_TexSetup
|
|
|
|
{
|
|
|
|
/* the pixel format of the texture */
|
|
|
|
EGL_PixelFormat pixFmt;
|
|
|
|
|
|
|
|
/* the width of the texture in pixels */
|
|
|
|
size_t width;
|
|
|
|
|
|
|
|
/* the height of the texture in pixels */
|
|
|
|
size_t height;
|
|
|
|
|
|
|
|
/* the stide of the texture in bytes */
|
|
|
|
size_t stride;
|
|
|
|
}
|
|
|
|
EGL_TexSetup;
|
|
|
|
|
|
|
|
typedef struct EGL_TexUpdate
|
|
|
|
{
|
|
|
|
/* the type of this update */
|
|
|
|
EGL_TexType type;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
/* EGL_TEXTURE_BUFFER */
|
|
|
|
const uint8_t * buffer;
|
|
|
|
|
|
|
|
/* EGL_TEXTURE_FRAMEBUFFER */
|
2021-08-07 06:10:30 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
const FrameBuffer * frame;
|
|
|
|
const FrameDamageRect * rects;
|
|
|
|
int rectCount;
|
|
|
|
};
|
2019-06-12 12:36:00 +00:00
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
/* EGL_TEXTURE_DMABUF */
|
|
|
|
int dmaFD;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
EGL_TexUpdate;
|
|
|
|
|
2021-08-08 07:31:52 +00:00
|
|
|
typedef struct EGL_Texture EGL_Texture;
|
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
typedef struct EGL_TextureOps
|
|
|
|
{
|
|
|
|
/* allocate & initialize an EGL_Texture */
|
|
|
|
bool (*init)(EGL_Texture ** texture, EGLDisplay * display);
|
|
|
|
|
|
|
|
/* free the EGL_Texture */
|
|
|
|
void (*free)(EGL_Texture * texture);
|
|
|
|
|
|
|
|
/* setup/reconfigure the texture format */
|
|
|
|
bool (*setup)(EGL_Texture * texture, const EGL_TexSetup * setup);
|
|
|
|
|
|
|
|
/* update the texture */
|
|
|
|
bool (*update)(EGL_Texture * texture, const EGL_TexUpdate * update);
|
|
|
|
|
|
|
|
/* called from a background job to prepare the texture for use before bind */
|
|
|
|
enum EGL_TexStatus (*process)(EGL_Texture * texture);
|
|
|
|
|
2021-08-09 04:08:10 +00:00
|
|
|
/* get the texture for use */
|
|
|
|
enum EGL_TexStatus (*get)(EGL_Texture * texture, GLuint * tex);
|
2021-08-02 13:37:33 +00:00
|
|
|
}
|
|
|
|
EGL_TextureOps;
|
|
|
|
|
2021-08-08 07:31:52 +00:00
|
|
|
struct EGL_Texture
|
|
|
|
{
|
|
|
|
struct EGL_TextureOps ops;
|
2021-08-09 04:08:10 +00:00
|
|
|
EGL * egl;
|
|
|
|
GLuint sampler;
|
|
|
|
RingBuffer textures;
|
|
|
|
|
|
|
|
EGL_TexFormat format;
|
|
|
|
bool formatValid;
|
2021-08-08 07:31:52 +00:00
|
|
|
|
|
|
|
// needed for dmabuf
|
|
|
|
size_t size;
|
2021-08-09 04:08:10 +00:00
|
|
|
|
|
|
|
// for applying shaders
|
|
|
|
struct ll * render;
|
|
|
|
_Atomic(bool) updated;
|
|
|
|
bool postProcessed;
|
|
|
|
EGL_Model * model;
|
2021-08-09 08:22:28 +00:00
|
|
|
float scale;
|
2021-08-08 07:31:52 +00:00
|
|
|
};
|
|
|
|
|
2021-08-09 04:08:10 +00:00
|
|
|
bool egl_textureInit(EGL * egl, EGL_Texture ** texture, EGLDisplay * display,
|
2021-08-02 13:37:33 +00:00
|
|
|
EGL_TexType type, bool streaming);
|
2021-08-08 07:52:13 +00:00
|
|
|
void egl_textureFree(EGL_Texture ** tex);
|
2018-09-23 05:48:44 +00:00
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
bool egl_textureSetup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt,
|
2021-08-02 13:37:33 +00:00
|
|
|
size_t width, size_t height, size_t stride);
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
bool egl_textureUpdate(EGL_Texture * texture, const uint8_t * buffer);
|
2021-08-02 13:37:33 +00:00
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
bool egl_textureUpdateFromFrame(EGL_Texture * texture,
|
2021-08-07 06:10:30 +00:00
|
|
|
const FrameBuffer * frame, const FrameDamageRect * damageRects,
|
|
|
|
int damageRectsCount);
|
2021-08-02 13:37:33 +00:00
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
bool egl_textureUpdateFromDMA(EGL_Texture * texture,
|
2021-08-02 13:37:33 +00:00
|
|
|
const FrameBuffer * frame, const int dmaFd);
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
enum EGL_TexStatus egl_textureProcess(EGL_Texture * texture);
|
2021-08-02 13:37:33 +00:00
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
enum EGL_TexStatus egl_textureBind(EGL_Texture * texture);
|
2021-08-09 04:08:10 +00:00
|
|
|
|
2021-08-09 07:48:07 +00:00
|
|
|
enum EGL_TexStatus egl_textureAddShader(EGL_Texture * texture,
|
|
|
|
EGL_Shader * shader, float outputScale);
|
2021-08-09 08:22:28 +00:00
|
|
|
|
|
|
|
float egl_textureGetScale(EGL_Texture * texture);
|