Skip to content

Commit

Permalink
Allow VideoOutputOpenGL to use the main UI renderer and painter objects.
Browse files Browse the repository at this point in the history
Currently disabled, this will allow the video renderer to share the same
hardware context and UI painter as the main UI window.

If anyone wants to test, you will have to uncomment the one obvious line
in VideoOutputOpenGL and remove the 2 uses of 'GetMythMainWindow()-
  • Loading branch information
Mark Kendall committed Jan 11, 2011
1 parent 3128c78 commit 2f93c0d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 35 deletions.
107 changes: 72 additions & 35 deletions mythtv/libs/libmythtv/videoout_opengl.cpp
@@ -1,4 +1,5 @@
#include "mythcontext.h"
#include "mythmainwindow.h"
#include "mythplayer.h"
#include "videooutbase.h"
#include "videoout_opengl.h"
Expand Down Expand Up @@ -40,8 +41,10 @@ void VideoOutputOpenGL::GetRenderOptions(render_opts &opts,
VideoOutputOpenGL::VideoOutputOpenGL()
: VideoOutput(),
gl_context_lock(QMutex::Recursive),
gl_context(NULL), gl_videochain(NULL), gl_pipchain_active(NULL),
gl_parent_win(0), gl_embed_win(0), gl_painter(NULL)
gl_context(NULL), gl_created_context(false),
gl_videochain(NULL), gl_pipchain_active(NULL),
gl_parent_win(0), gl_embed_win(0),
gl_painter(NULL), gl_created_painter(false)
{
memset(&av_pause_frame, 0, sizeof(av_pause_frame));
av_pause_frame.buf = NULL;
Expand All @@ -55,11 +58,9 @@ VideoOutputOpenGL::~VideoOutputOpenGL()
QMutexLocker locker(&gl_context_lock);
TearDown();

if (gl_context)
{
if (gl_created_context)
delete gl_context;
gl_context = NULL;
}
gl_context = NULL;
}

void VideoOutputOpenGL::TearDown(void)
Expand Down Expand Up @@ -90,11 +91,13 @@ void VideoOutputOpenGL::TearDown(void)
gl_videochain = NULL;
}

if (gl_painter)
{
if (gl_created_painter)
delete gl_painter;
gl_painter = NULL;
}
else
gl_painter->SetSwapControl(true);

gl_painter = NULL;
gl_created_painter = false;

while (!gl_pipchains.empty())
{
Expand Down Expand Up @@ -198,33 +201,49 @@ bool VideoOutputOpenGL::SetupContext(void)
{
QMutexLocker locker(&gl_context_lock);

bool success = false;

if (gl_context)
{
VERBOSE(VB_PLAYBACK, LOC + QString("Re-using context"));
success = true;
return true;
}
else

MythMainWindow* win = MythMainWindow::getMainWindow();
if (!win)
{
QGLFormat fmt;
fmt.setDepth(false);
VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to get MythMainWindow");
return false;
}

QGLWidget *device = (QGLWidget*)QWidget::find(gl_parent_win);
if (!device)
{
VERBOSE(VB_IMPORTANT, LOC + QString("Failed to cast parent to QGLWidget."));
return false;
}
gl_context = new MythRenderOpenGL(fmt, device);
if (gl_context && gl_context->create())
{
gl_context->Init();
success = true;
VERBOSE(VB_GENERAL, LOC + QString("Created MythRenderOpenGL device."));
}
gl_created_context = false;
//gl_context = dynamic_cast<MythRenderOpenGL*>(win->GetRenderDevice());
if (gl_context)
{
VERBOSE(VB_PLAYBACK, LOC + "Using main UI render context");
return true;
}
return success;

QGLFormat fmt;
fmt.setDepth(false);

QGLWidget *device = (QGLWidget*)QWidget::find(gl_parent_win);
if (!device)
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to cast parent to QGLWidget");
return false;
}

gl_context = new MythRenderOpenGL(fmt, device);
if (gl_context && gl_context->create())
{
gl_context->Init();
VERBOSE(VB_GENERAL, LOC + QString("Created MythRenderOpenGL device."));
gl_created_context = true;
return true;
}

VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to create MythRenderOpenGL device.");
delete gl_context;
return false;
}

bool VideoOutputOpenGL::SetupOpenGL(void)
Expand Down Expand Up @@ -270,12 +289,30 @@ void VideoOutputOpenGL::InitOSD(void)
{
QMutexLocker locker(&gl_context_lock);

gl_painter = new MythOpenGLPainter(gl_context,
(QGLWidget*)QWidget::find(gl_parent_win));
if (!gl_painter)
VERBOSE(VB_IMPORTANT, LOC + QString("Failed to create OpenGL OSD"));
gl_created_painter = false;
MythMainWindow *win = MythMainWindow::getMainWindow();
if (gl_created_context && gl_context)
{
QGLWidget *device = (QGLWidget*)QWidget::find(gl_parent_win);
gl_painter = new MythOpenGLPainter(gl_context, device);
if (!gl_painter)
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to create painter");
return;
}
gl_created_painter = true;
}
else
gl_painter->SetSwapControl(false);
{
gl_painter = (MythOpenGLPainter*)win->GetCurrentPainter();
if (!gl_painter)
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to get painter");
return;
}
VERBOSE(VB_PLAYBACK, LOC + "Using main UI painter");
}
gl_painter->SetSwapControl(false);
}

bool VideoOutputOpenGL::CreateBuffers(void)
Expand Down
2 changes: 2 additions & 0 deletions mythtv/libs/libmythtv/videoout_opengl.h
Expand Up @@ -61,6 +61,7 @@ class VideoOutputOpenGL : public VideoOutput

QMutex gl_context_lock;
MythRenderOpenGL *gl_context;
bool gl_created_context;
OpenGLVideo *gl_videochain;
QMap<MythPlayer*,OpenGLVideo*> gl_pipchains;
QMap<MythPlayer*,bool> gl_pip_ready;
Expand All @@ -70,6 +71,7 @@ class VideoOutputOpenGL : public VideoOutput
VideoFrame av_pause_frame;

MythOpenGLPainter *gl_painter;
bool gl_created_painter;
};

#endif

0 comments on commit 2f93c0d

Please sign in to comment.