[client] egl: make texture_dmabuf.c use vector

This replaces the custom memory management code.
This commit is contained in:
Quantum 2021-08-22 07:47:56 -04:00 committed by Geoffrey McRae
parent 377757e743
commit 7c7eff8dba

View File

@ -21,23 +21,22 @@
#include "texture.h" #include "texture.h"
#include "texture_buffer.h" #include "texture_buffer.h"
#include "common/vector.h"
#include "egl_dynprocs.h" #include "egl_dynprocs.h"
#include "egldebug.h" #include "egldebug.h"
struct FdImage
{
int fd;
EGLImage image;
};
typedef struct TexDMABUF typedef struct TexDMABUF
{ {
TextureBuffer base; TextureBuffer base;
EGLDisplay display; EGLDisplay display;
Vector * images;
size_t imageCount;
size_t imageUsed;
struct
{
int fd;
EGLImage image;
}
* images;
} }
TexDMABUF; TexDMABUF;
@ -47,10 +46,10 @@ EGL_TextureOps EGL_TextureDMABUF;
static void egl_texDMABUFCleanup(TexDMABUF * this) static void egl_texDMABUFCleanup(TexDMABUF * this)
{ {
for (size_t i = 0; i < this->imageUsed; ++i) struct FdImage * image;
eglDestroyImage(this->display, this->images[i].image); vector_forEachRef(image, this->images)
eglDestroyImage(this->display, image->image);
this->imageUsed = 0; vector_clear(this->images);
} }
// dmabuf functions // dmabuf functions
@ -60,9 +59,18 @@ static bool egl_texDMABUFInit(EGL_Texture ** texture, EGLDisplay * display)
TexDMABUF * this = calloc(1, sizeof(*this)); TexDMABUF * this = calloc(1, sizeof(*this));
*texture = &this->base.base; *texture = &this->base.base;
this->images = vector_create(sizeof(struct FdImage), 2);
if (!this->images)
{
free(this);
*texture = NULL;
return false;
}
EGL_Texture * parent = &this->base.base; EGL_Texture * parent = &this->base.base;
if (!egl_texBufferStreamInit(&parent, display)) if (!egl_texBufferStreamInit(&parent, display))
{ {
vector_free(this->images);
free(this); free(this);
*texture = NULL; *texture = NULL;
return false; return false;
@ -104,10 +112,11 @@ static bool egl_texDMABUFUpdate(EGL_Texture * texture,
EGLImage image = EGL_NO_IMAGE; EGLImage image = EGL_NO_IMAGE;
for(int i = 0; i < this->imageUsed; ++i) struct FdImage * fdImage;
if (this->images[i].fd == update->dmaFD) vector_forEachRef(fdImage, this->images)
if (fdImage->fd == update->dmaFD)
{ {
image = this->images[i].image; image = fdImage->image;
break; break;
} }
@ -137,24 +146,15 @@ static bool egl_texDMABUFUpdate(EGL_Texture * texture,
return false; return false;
} }
if (this->imageUsed == this->imageCount) if (!vector_push(this->images, &(struct FdImage) {
.fd = update->dmaFD,
.image = image,
}))
{ {
size_t newCount = this->imageCount * 2 + 2; DEBUG_ERROR("Failed to store EGLImage");
void * new = realloc(this->images, newCount * sizeof(*this->images));
if (!new)
{
DEBUG_ERROR("Failed to allocate memory");
eglDestroyImage(this->display, image); eglDestroyImage(this->display, image);
return false; return false;
} }
this->imageCount = newCount;
this->images = new;
}
const size_t index = this->imageUsed++;
this->images[index].fd = update->dmaFD;
this->images[index].image = image;
} }
INTERLOCKED_SECTION(parent->copyLock, INTERLOCKED_SECTION(parent->copyLock,