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
|
|
|
|
2018-12-12 05:39:04 +00:00
|
|
|
#include "texture.h"
|
2018-09-23 05:48:44 +00:00
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include "shader.h"
|
|
|
|
#include "common/framebuffer.h"
|
2021-05-02 14:48:36 +00:00
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <EGL/eglext.h>
|
2020-05-29 05:48:59 +00:00
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
#include "texture_buffer.h"
|
2020-05-22 07:47:19 +00:00
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
extern const EGL_TextureOps EGL_TextureBuffer;
|
|
|
|
extern const EGL_TextureOps EGL_TextureBufferStream;
|
|
|
|
extern const EGL_TextureOps EGL_TextureFrameBuffer;
|
|
|
|
extern const EGL_TextureOps EGL_TextureDMABUF;
|
2020-05-29 05:48:59 +00:00
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
bool egl_texture_init(EGL_Texture ** texture, EGLDisplay * display,
|
|
|
|
EGL_TexType type, bool streaming)
|
2018-09-23 05:48:44 +00:00
|
|
|
{
|
2021-08-02 13:37:33 +00:00
|
|
|
const EGL_TextureOps * ops;
|
2020-05-29 06:54:25 +00:00
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
switch(type)
|
2018-09-23 10:45:20 +00:00
|
|
|
{
|
2021-08-02 13:37:33 +00:00
|
|
|
case EGL_TEXTYPE_BUFFER:
|
|
|
|
ops = streaming ? &EGL_TextureBufferStream : &EGL_TextureBuffer;
|
2018-12-04 10:23:28 +00:00
|
|
|
break;
|
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
case EGL_TEXTYPE_FRAMEBUFFER:
|
|
|
|
assert(streaming);
|
|
|
|
ops = &EGL_TextureFrameBuffer;
|
2018-12-04 10:23:28 +00:00
|
|
|
break;
|
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
case EGL_TEXTYPE_DMABUF:
|
|
|
|
assert(streaming);
|
|
|
|
ops = &EGL_TextureDMABUF;
|
2020-10-11 08:22:31 +00:00
|
|
|
break;
|
|
|
|
|
2018-09-23 10:45:20 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-02 17:58:30 +00:00
|
|
|
*texture = NULL;
|
2021-08-02 13:37:33 +00:00
|
|
|
if (!ops->init(texture, display))
|
|
|
|
return false;
|
2020-05-21 01:44:56 +00:00
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
(*texture)->ops = ops;
|
2018-09-23 05:48:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
void egl_texture_free(EGL_Texture ** tex)
|
2020-05-19 12:42:55 +00:00
|
|
|
{
|
2021-08-02 13:37:33 +00:00
|
|
|
(*tex)->ops->free(*tex);
|
|
|
|
*tex = NULL;
|
2020-05-19 12:42:55 +00:00
|
|
|
}
|
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
bool egl_texture_setup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt,
|
|
|
|
size_t width, size_t height, size_t stride)
|
2018-09-23 05:48:44 +00:00
|
|
|
{
|
2021-08-02 13:37:33 +00:00
|
|
|
const struct EGL_TexSetup setup =
|
|
|
|
{
|
|
|
|
.pixFmt = pixFmt,
|
|
|
|
.width = width,
|
|
|
|
.height = height,
|
|
|
|
.stride = stride
|
|
|
|
};
|
|
|
|
texture->size = height * stride;
|
|
|
|
return texture->ops->setup(texture, &setup);
|
2018-09-23 05:48:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
bool egl_texture_update(EGL_Texture * texture, const uint8_t * buffer)
|
2019-10-01 13:17:20 +00:00
|
|
|
{
|
2021-08-02 13:37:33 +00:00
|
|
|
const struct EGL_TexUpdate update =
|
2020-05-19 12:42:55 +00:00
|
|
|
{
|
2021-08-02 13:37:33 +00:00
|
|
|
.type = EGL_TEXTYPE_BUFFER,
|
|
|
|
.buffer = buffer
|
|
|
|
};
|
|
|
|
return texture->ops->update(texture, &update);
|
2019-10-01 13:17:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
bool egl_texture_update_from_frame(EGL_Texture * texture,
|
2021-08-07 06:10:30 +00:00
|
|
|
const FrameBuffer * frame, const FrameDamageRect * damageRects,
|
|
|
|
int damageRectsCount)
|
2020-10-29 15:32:25 +00:00
|
|
|
{
|
2021-08-02 13:37:33 +00:00
|
|
|
const struct EGL_TexUpdate update =
|
2020-10-29 15:32:25 +00:00
|
|
|
{
|
2021-08-07 06:10:30 +00:00
|
|
|
.type = EGL_TEXTYPE_FRAMEBUFFER,
|
|
|
|
.frame = frame,
|
|
|
|
.rects = damageRects,
|
|
|
|
.rectCount = damageRectsCount,
|
2021-08-02 13:37:33 +00:00
|
|
|
};
|
|
|
|
return texture->ops->update(texture, &update);
|
|
|
|
}
|
2020-10-29 15:32:25 +00:00
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
bool egl_texture_update_from_dma(EGL_Texture * texture,
|
|
|
|
const FrameBuffer * frame, const int dmaFd)
|
|
|
|
{
|
|
|
|
const struct EGL_TexUpdate update =
|
2020-12-31 01:58:40 +00:00
|
|
|
{
|
2021-08-02 13:37:33 +00:00
|
|
|
.type = EGL_TEXTYPE_DMABUF,
|
|
|
|
.dmaFD = dmaFd
|
|
|
|
};
|
2020-10-29 15:32:25 +00:00
|
|
|
|
|
|
|
/* wait for completion */
|
2021-08-02 13:37:33 +00:00
|
|
|
framebuffer_wait(frame, texture->size);
|
2020-10-29 15:32:25 +00:00
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
return texture->ops->update(texture, &update);
|
2020-10-29 15:32:25 +00:00
|
|
|
}
|
|
|
|
|
2019-06-12 12:36:00 +00:00
|
|
|
enum EGL_TexStatus egl_texture_process(EGL_Texture * texture)
|
2018-09-23 05:48:44 +00:00
|
|
|
{
|
2021-08-02 13:37:33 +00:00
|
|
|
return texture->ops->process(texture);
|
2019-06-12 12:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum EGL_TexStatus egl_texture_bind(EGL_Texture * texture)
|
|
|
|
{
|
2021-08-02 13:37:33 +00:00
|
|
|
return texture->ops->bind(texture);
|
2020-04-14 03:27:07 +00:00
|
|
|
}
|