Enable the EGLRenderer to use the render thread

This commit is contained in:
Cameron Gutman 2020-05-13 19:09:20 -07:00
parent ddfbd70b55
commit eb9e1f81d4
2 changed files with 10 additions and 8 deletions

View File

@ -64,6 +64,8 @@ EGLRenderer::EGLRenderer(IFFmpegRenderer *backendRenderer)
EGLRenderer::~EGLRenderer()
{
if (m_Context) {
// Reattach the GL context to the main thread for destruction
SDL_GL_MakeCurrent(m_Window, m_Context);
if (m_ShaderProgram)
glDeleteProgram(m_ShaderProgram);
if (m_VAO)
@ -88,12 +90,6 @@ void EGLRenderer::notifyOverlayUpdated(Overlay::OverlayType)
// TODO: FIXME
}
bool EGLRenderer::isRenderThreadSupported()
{
// TODO: can we use DMA-BUF in multithreaded context ?
return false;
}
bool EGLRenderer::isPixelFormatSupported(int, AVPixelFormat pixelFormat)
{
// Remember to keep this in sync with EGLRenderer::renderFrame()!
@ -307,6 +303,9 @@ bool EGLRenderer::initialize(PDECODER_PARAMETERS params)
if (err != GL_NO_ERROR)
EGL_LOG(Error, "OpenGL error: %d", err);
// Detach the context from this thread, so the render thread can attach it
SDL_GL_MakeCurrent(m_Window, nullptr);
return err == GL_NO_ERROR;
}
@ -366,6 +365,9 @@ const float *EGLRenderer::getColorMatrix() {
bool EGLRenderer::specialize() {
SDL_assert(!m_VAO);
// Attach our GL context to the render thread
SDL_GL_MakeCurrent(m_Window, m_Context);
if (!compileShader())
return false;
@ -436,7 +438,8 @@ void EGLRenderer::renderFrame(AVFrame* frame)
EGLImage imgs[EGL_MAX_PLANES];
if (frame == nullptr) {
// End of stream - nothing to do for us
// End of stream - unbind the GL context
SDL_GL_MakeCurrent(m_Window, nullptr);
return;
}

View File

@ -10,7 +10,6 @@ public:
virtual bool prepareDecoderContext(AVCodecContext* context, AVDictionary** options) override;
virtual void renderFrame(AVFrame* frame) override;
virtual void notifyOverlayUpdated(Overlay::OverlayType) override;
virtual bool isRenderThreadSupported() override;
virtual bool isPixelFormatSupported(int videoFormat, enum AVPixelFormat pixelFormat) override;
private: