ensure texture is not copied in one thread while it's read in another

This seems to cause issues in the rendering pipeline, so this commit never lets
a texture copy and read occur at the same time.
This commit is contained in:
itsmattkc
2020-01-02 06:00:21 +11:00
parent 7eae6a85f8
commit f8839e74de
4 changed files with 25 additions and 0 deletions
@@ -159,6 +159,8 @@ void OpenGLBackend::EmitCachedFrameReady(const QList<rational> &times, const QVa
OpenGLTexturePtr OpenGLBackend::CopyTexture(OpenGLTexturePtr input)
{
input->Lock();
QOpenGLContext* ctx = QOpenGLContext::currentContext();
OpenGLTexturePtr copy = std::make_shared<OpenGLTexture>();
@@ -176,5 +178,7 @@ OpenGLTexturePtr OpenGLBackend::CopyTexture(OpenGLTexturePtr input)
copy_buffer_.Release();
copy_buffer_.Detach();
input->Unlock();
return copy;
}
@@ -156,6 +156,16 @@ void OpenGLTexture::Upload(const void *data)
Release();
}
void OpenGLTexture::Lock()
{
mutex_.lock();
}
void OpenGLTexture::Unlock()
{
mutex_.unlock();
}
void OpenGLTexture::CreateInternal(QOpenGLContext* create_ctx, GLuint* tex, const void *data)
{
QOpenGLFunctions* f = create_ctx->functions();
@@ -22,6 +22,7 @@
#define OPENGLTEXTURE_H
#include <memory>
#include <QMutex>
#include <QOpenGLFunctions>
#include "codec/frame.h"
@@ -59,6 +60,10 @@ public:
void Upload(const void *data);
void Lock();
void Unlock();
public slots:
void Destroy();
@@ -75,6 +80,8 @@ private:
PixelFormat::Format format_;
QMutex mutex_;
};
using OpenGLTexturePtr = std::shared_ptr<OpenGLTexture>;
@@ -355,6 +355,8 @@ void OpenGLWorker::TextureToBuffer(const QVariant &tex_in, QByteArray &buffer)
PixelFormat::Info format_info = PixelService::GetPixelFormatInfo(video_params().format());
texture->texture()->Lock();
QOpenGLFunctions* f = QOpenGLContext::currentContext()->functions();
buffer_.Attach(texture->texture());
buffer_.Bind();
@@ -369,6 +371,8 @@ void OpenGLWorker::TextureToBuffer(const QVariant &tex_in, QByteArray &buffer)
buffer_.Release();
buffer_.Detach();
texture->texture()->Unlock();
}
void OpenGLWorker::FinishInit()