Skip to content

Commit

Permalink
High DPI scaling: Fix displaying the ProgramGuide when embedded
Browse files Browse the repository at this point in the history
- previously, when playing video, we disabled framebuffer clearing,
setting of the viewport and any high dpi scaling in the painter.
- when high dpi was being used, this broke rendering of the programme
guide etc
- we now differentiate beween control over the framebuffer and the
viewport, and allow the painter to set the viewport (and scaling) when
embedding - and the guide is rendered correctly
  • Loading branch information
mark-kendall committed Sep 17, 2020
1 parent 9419cf7 commit 88add49
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 21 deletions.
9 changes: 7 additions & 2 deletions mythtv/libs/libmythtv/mythvideooutgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ MythVideoOutputGPU::MythVideoOutputGPU(MythRender* Render, QString& Profile)
{
m_painter = dynamic_cast<MythPainterGPU*>(win->GetCurrentPainter());
if (m_painter)
m_painter->SetMaster(false);
m_painter->SetViewControl(MythPainterGPU::None);
}

if (!(win && m_render && m_painter))
Expand All @@ -49,7 +49,7 @@ MythVideoOutputGPU::~MythVideoOutputGPU()
MythVideoOutputGPU::DestroyBuffers();
delete m_video;
if (m_painter)
m_painter->SetMaster(true);
m_painter->SetViewControl(MythPainterGPU::Viewport | MythPainterGPU::Framebuffer);
if (m_render)
m_render->DecrRef();
}
Expand Down Expand Up @@ -437,12 +437,17 @@ void MythVideoOutputGPU::RenderFrame(VideoFrame *Frame, FrameScanType Scan, OSD
// Main UI when embedded
if (m_painter && IsEmbedding())
{
// If we are using high dpi, the painter needs to set the appropriate
// viewport and enable scaling of its images
m_painter->SetViewControl(MythPainterGPU::Viewport);

MythMainWindow* win = GetMythMainWindow();
if (win && win->GetPaintWindow())
{
win->GetPaintWindow()->clearMask();
win->Draw(m_painter);
}
m_painter->SetViewControl(MythPainterGPU::None);
}

// Video
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythui/mythpaintergpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ MythPainterGPU::~MythPainterGPU()
#endif
}

void MythPainterGPU::SetMaster(bool Master)
void MythPainterGPU::SetViewControl(ViewControls Control)
{
m_master = Master;
m_viewControl = Control;
}

void MythPainterGPU::CurrentDPIChanged(qreal DPI)
Expand Down
26 changes: 18 additions & 8 deletions mythtv/libs/libmythui/mythpaintergpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,31 @@ class MUI_PUBLIC MythPainterGPU : public MythPainter
Q_OBJECT

public:
enum ViewControl
{
None = 0x00,
Viewport = 0x01,
Framebuffer = 0x02
};
Q_DECLARE_FLAGS(ViewControls, ViewControl)

MythPainterGPU(QWidget *Parent);
~MythPainterGPU() override;

void SetMaster(bool Master);
void SetViewControl (ViewControls Control);

public slots:
void CurrentDPIChanged(qreal DPI);
void CurrentDPIChanged (qreal DPI);

protected:
QWidget* m_widget { nullptr };
bool m_master { true };
qreal m_pixelRatio { 1.0 };
MythDisplay* m_display { nullptr };
bool m_usingHighDPI { false };
QSize m_lastSize;
QWidget* m_widget { nullptr };
ViewControls m_viewControl { Viewport | Framebuffer };
qreal m_pixelRatio { 1.0 };
MythDisplay* m_display { nullptr };
bool m_usingHighDPI { false };
QSize m_lastSize;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(MythPainterGPU::ViewControls)

#endif
22 changes: 15 additions & 7 deletions mythtv/libs/libmythui/opengl/mythpainteropengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,21 @@ void MythOpenGLPainter::Begin(QPaintDevice *Parent)
DeleteTextures();
m_render->makeCurrent();

// If master (have complete swap control) then clear and set viewport
if (m_master)
// If master (have complete swap control) then bind default framebuffer and clear
if (m_viewControl.testFlag(Framebuffer))
{
m_render->BindFramebuffer(nullptr);
m_render->SetBackground(0, 0, 0, 255);
m_render->ClearFramebuffer();
}

// If we have viewport control, set as needed.
if (m_viewControl.testFlag(Viewport))
{
// If using high DPI then scale the viewport
if (m_usingHighDPI)
currentsize *= m_pixelRatio;
m_render->BindFramebuffer(nullptr);
m_render->SetViewPort(QRect(0, 0, currentsize.width(), currentsize.height()));
m_render->SetBackground(0, 0, 0, 255);
m_render->ClearFramebuffer();
}
}

Expand All @@ -156,7 +161,8 @@ void MythOpenGLPainter::End(void)

if (VERBOSE_LEVEL_CHECK(VB_GPU, LOG_INFO))
m_render->logDebugMarker("PAINTER_FRAME_END");
if (m_master)

if (m_viewControl.testFlag(Framebuffer))
{
m_render->Flush();
m_render->swapBuffers();
Expand Down Expand Up @@ -241,7 +247,9 @@ void MythOpenGLPainter::DrawImage(const QRect &Dest, MythImage *Image,
{
if (m_render)
{
qreal pixelratio = (m_master && m_usingHighDPI) ? m_pixelRatio : 1.0;
qreal pixelratio = 1.0;
if (m_usingHighDPI && m_viewControl.testFlag(Viewport))
pixelratio = m_pixelRatio;
#ifdef Q_OS_MACOS
QRect dest = QRect(static_cast<int>(Dest.left() * pixelratio),
static_cast<int>(Dest.top() * pixelratio),
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythui/vulkan/mythpaintervulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void MythPainterVulkan::End()
if (m_queuedTextures.empty())
return;

if (m_master)
if (m_viewControl.testFlag(Framebuffer))
{
// Tell the renderer that we are requesting a frame start
m_vulkan->Render()->SetFrameExpected();
Expand Down Expand Up @@ -359,7 +359,7 @@ void MythPainterVulkan::End()

m_queuedTextures.clear();

if (m_master)
if (m_viewControl.testFlag(Framebuffer))
m_vulkan->Render()->EndFrame();
}

Expand Down

0 comments on commit 88add49

Please sign in to comment.