Skip to content

Commit

Permalink
Extend opengl lock to cover images as well as textures.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdude42 committed Sep 11, 2021
1 parent 2205521 commit 0ba4120
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 8 additions & 3 deletions mythtv/libs/libmythui/opengl/mythpainteropengl.cpp
Expand Up @@ -58,7 +58,7 @@ void MythOpenGLPainter::DeleteTextures(void)
if (!m_render || m_textureDeleteList.empty())
return;

QMutexLocker gllocker(&m_textureDeleteLock);
QMutexLocker gllocker(&m_imageAndTextureLock);
OpenGLLocker locker(m_render);
while (!m_textureDeleteList.empty())
{
Expand All @@ -73,7 +73,7 @@ void MythOpenGLPainter::ClearCache(void)
{
LOG(VB_GENERAL, LOG_INFO, "Clearing OpenGL painter cache.");

QMutexLocker locker(&m_textureDeleteLock);
QMutexLocker locker(&m_imageAndTextureLock);
QMapIterator<MythImage *, MythGLTexture*> it(m_imageToTextureMap);
while (it.hasNext())
{
Expand Down Expand Up @@ -170,6 +170,7 @@ MythGLTexture* MythOpenGLPainter::GetTextureFromCache(MythImage *Image)
if (!m_render)
return nullptr;

QMutexLocker locker(&m_imageAndTextureLock);
if (m_imageToTextureMap.contains(Image))
{
if (!Image->IsChanged())
Expand All @@ -180,6 +181,7 @@ MythGLTexture* MythOpenGLPainter::GetTextureFromCache(MythImage *Image)
}
DeleteFormatImagePriv(Image);
}
locker.unlock();

Image->SetChanged(false);

Expand All @@ -203,17 +205,20 @@ MythGLTexture* MythOpenGLPainter::GetTextureFromCache(MythImage *Image)
LOG(VB_GENERAL, LOG_NOTICE, QString("Shrinking UIPainterMaxCacheHW to %1KB")
.arg(m_maxHardwareCacheSize / 1024));

locker.relock();
while (m_hardwareCacheSize > m_maxHardwareCacheSize)
{
MythImage *expiredIm = m_imageExpireList.front();
m_imageExpireList.pop_front();
DeleteFormatImagePriv(expiredIm);
DeleteTextures();
}
locker.unlock();
}

CheckFormatImage(Image);
m_hardwareCacheSize += MythRenderOpenGL::GetTextureDataSize(texture);
locker.relock();
m_imageToTextureMap[Image] = texture;
m_imageExpireList.push_back(Image);

Expand Down Expand Up @@ -308,9 +313,9 @@ void MythOpenGLPainter::DrawRoundRect(const QRect Area, int CornerRadius,

void MythOpenGLPainter::DeleteFormatImagePriv(MythImage *Image)
{
QMutexLocker locker(&m_imageAndTextureLock);
if (m_imageToTextureMap.contains(Image))
{
QMutexLocker locker(&m_textureDeleteLock);
m_textureDeleteList.push_back(m_imageToTextureMap[Image]);
m_imageToTextureMap.remove(Image);
m_imageExpireList.remove(Image);
Expand Down
9 changes: 8 additions & 1 deletion mythtv/libs/libmythui/opengl/mythpainteropengl.h
Expand Up @@ -3,6 +3,9 @@

// Qt
#include <QMutex>
#if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
#include <QRecursiveMutex>
#endif
#include <QQueue>

// MythTV
Expand Down Expand Up @@ -55,10 +58,14 @@ class MUI_PUBLIC MythOpenGLPainter : public MythPainterGPU
protected:
MythRenderOpenGL *m_render { nullptr };

#if QT_VERSION < QT_VERSION_CHECK(5,14,0)
QMutex m_imageAndTextureLock { QMutex::Recursive };
#else
QRecursiveMutex m_imageAndTextureLock;
#endif
QMap<MythImage *, MythGLTexture*> m_imageToTextureMap;
std::list<MythImage *> m_imageExpireList;
std::list<MythGLTexture*> m_textureDeleteList;
QMutex m_textureDeleteLock;

QVector<MythGLTexture*> m_mappedTextures;
std::array<QOpenGLBuffer*,MAX_BUFFER_POOL> m_mappedBufferPool { nullptr };
Expand Down

0 comments on commit 0ba4120

Please sign in to comment.