Ticket #13618: dpi2.diff

File dpi2.diff, 14.3 KB (added by Mark Kendall, 4 years ago)

Test patch - try and scale UI and video

  • mythtv/libs/libmythtv/mythvideoout.cpp

    diff --git a/mythtv/libs/libmythtv/mythvideoout.cpp b/mythtv/libs/libmythtv/mythvideoout.cpp
    index ee4b759d81..f4e4d73c7e 100644
    a b void MythVideoOutput::InitDisplayMeasurements(void) 
    10201020        .arg(displayaspect).arg(source));
    10211021
    10221022    // Get the window and screen resolutions
    1023     QSize window = m_window.GetWindowRect().size();
     1023    QSize window = m_window.GetWindowRect().size() / m_window.GetDevicePixelRatio();
    10241024    QSize screen = m_display->GetResolution();
    10251025
    10261026    // If not running fullscreen, adjust for window size and ignore any video
  • mythtv/libs/libmythtv/videooutwindow.cpp

    diff --git a/mythtv/libs/libmythtv/videooutwindow.cpp b/mythtv/libs/libmythtv/videooutwindow.cpp
    index af8af15c31..3bbd4246f3 100644
    a b  
    3838
    3939#define LOC QString("VideoWin: ")
    4040
     41
     42#define SCALED_RECT(SRC, SCALE) (QRect(static_cast<int>(SRC.left()   * SCALE), \
     43                                       static_cast<int>(SRC.top()    * SCALE), \
     44                                       static_cast<int>(SRC.width()  * SCALE), \
     45                                       static_cast<int>(SRC.height() * SCALE)))
    4146static float fix_aspect(float raw);
    4247static float snap(float value, float snapto, float diff);
    4348
    void VideoOutWindow::ScreenChanged(QScreen */*screen*/) 
    6368    MoveResize();
    6469}
    6570
     71void VideoOutWindow::PhysicalDPIChanged(qreal /*DPI*/)
     72{
     73    // FIXME - just feels wrong:)
     74
     75    // revert old device pixel ratio (noop for pixel ratio = 1.0)
     76    m_windowRect = m_displayVisibleRect = SCALED_RECT(m_windowRect, 1.0 / m_devicePixelRatio);
     77    PopulateGeometry();
     78    // and apply new
     79    m_windowRect = m_displayVisibleRect = SCALED_RECT(m_windowRect, m_devicePixelRatio);
     80    MoveResize();
     81}
     82
    6683void VideoOutWindow::PopulateGeometry(void)
    6784{
    6885    if (!m_display)
    void VideoOutWindow::PopulateGeometry(void) 
    7289    if (!screen)
    7390        return;
    7491
     92    m_devicePixelRatio = screen->devicePixelRatio();
     93
    7594    if (MythDisplay::SpanAllScreens() && MythDisplay::GetScreenCount() > 1)
    7695    {
    7796        m_screenGeometry = screen->virtualGeometry();
    bool VideoOutWindow::Init(const QSize &VideoDim, const QSize &VideoDispDim, 
    416435    {
    417436        m_display = Display;
    418437        connect(m_display, &MythDisplay::CurrentScreenChanged, this, &VideoOutWindow::ScreenChanged);
     438        connect(m_display, &MythDisplay::PhysicalDPIChanged,   this, &VideoOutWindow::PhysicalDPIChanged);
    419439    }
    420440
    421441    if (m_display)
    bool VideoOutWindow::Init(const QSize &VideoDim, const QSize &VideoDispDim, 
    429449
    430450    // N.B. we are always confined to the window size so use that for the initial
    431451    // displayVisibleRect
    432     m_windowRect = m_displayVisibleRect = WindowRect;
     452    m_windowRect = m_displayVisibleRect = SCALED_RECT(WindowRect, m_devicePixelRatio);
    433453
    434454    int pbp_width = m_displayVisibleRect.width() / 2;
    435455    if (m_pipState == kPBPLeft || m_pipState == kPBPRight)
    QRegion VideoOutWindow::GetBoundingRegion(void) const 
    824844}
    825845#endif
    826846
     847qreal VideoOutWindow::GetDevicePixelRatio(void) const
     848{
     849    return m_devicePixelRatio;
     850}
     851
    827852/*
    828853 * \brief Determines PIP Window size and Position.
    829854 */
  • mythtv/libs/libmythtv/videooutwindow.h

    diff --git a/mythtv/libs/libmythtv/videooutwindow.h b/mythtv/libs/libmythtv/videooutwindow.h
    index 9480045c92..45192f93a1 100644
    a b class VideoOutWindow : public QObject 
    4545
    4646  public slots:
    4747    void ScreenChanged          (QScreen *screen);
     48    void PhysicalDPIChanged     (qreal  /*DPI*/);
    4849
    4950    // Sets
    5051    void InputChanged           (const QSize &VideoDim, const QSize &VideoDispDim, float Aspect);
    class VideoOutWindow : public QObject 
    9596#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
    9697    QRegion  GetBoundingRegion(void) const;
    9798#endif
     99    qreal    GetDevicePixelRatio(void) const;
    98100
    99101  private:
    100102    void PopulateGeometry        (void);
    class VideoOutWindow : public QObject 
    115117    bool    m_dbScalingAllowed {true};  ///< disable this to prevent overscan/underscan
    116118    bool    m_dbUseGUISize     {false}; ///< Use the gui size for video window
    117119    QRect   m_screenGeometry   {0,0,1024,768}; ///< Full screen geometry
     120    qreal   m_devicePixelRatio {1.0};
    118121
    119122    // Manual Zoom
    120123    float   m_manualVertScale  {1.0F}; ///< Manually applied vertical scaling.
  • mythtv/libs/libmythui/opengl/mythpainteropengl.cpp

    diff --git a/mythtv/libs/libmythui/opengl/mythpainteropengl.cpp b/mythtv/libs/libmythui/opengl/mythpainteropengl.cpp
    index 8fec14d3c2..e36f597f18 100644
    a b void MythOpenGLPainter::Begin(QPaintDevice *Parent) 
    109109            buf = m_render->CreateVBO(static_cast<int>(MythRenderOpenGL::kVertexSize));
    110110    }
    111111
     112    // check for high dpi
     113    m_pixelRatio = m_parent->devicePixelRatioF();
     114    QSize currentsize = m_parent->size() * m_pixelRatio;
     115
    112116    // check if we need to adjust cache sizes
    113     if (m_lastSize != m_parent->size())
     117    if (m_lastSize != currentsize)
    114118    {
    115119        // This will scale the cache depending on the resolution in use
    116120        static const int s_onehd = 1920 * 1080;
    117121        static const int s_basesize = 64;
    118         m_lastSize = m_parent->size();
     122        m_lastSize = currentsize;
    119123        float hdscreens = (static_cast<float>(m_lastSize.width() + 1) * m_lastSize.height()) / s_onehd;
    120124        int cpu = qMax(static_cast<int>(hdscreens * s_basesize), s_basesize);
    121125        int gpu = cpu * 3 / 2;
    void MythOpenGLPainter::Begin(QPaintDevice *Parent) 
    131135    if (m_target || m_swapControl)
    132136    {
    133137        m_render->BindFramebuffer(m_target);
    134         m_render->SetViewPort(QRect(0, 0, m_parent->width(), m_parent->height()));
     138        m_render->SetViewPort(QRect(0, 0, m_lastSize.width(), m_lastSize.height()));
    135139        m_render->SetBackground(0, 0, 0, 0);
    136140        m_render->ClearFramebuffer();
    137141    }
    MythGLTexture* MythOpenGLPainter::GetTextureFromCache(MythImage *Image) 
    221225    return texture;
    222226}
    223227
     228#define SCALED_RECT(DEST, SCALE) QRect dest = QRect(static_cast<int>(DEST.left()   * SCALE), \
     229                                                    static_cast<int>(DEST.top()    * SCALE), \
     230                                                    static_cast<int>(DEST.width()  * SCALE), \
     231                                                    static_cast<int>(DEST.height() * SCALE));
     232
    224233void MythOpenGLPainter::DrawImage(const QRect &Dest, MythImage *Image,
    225234                                  const QRect &Source, int Alpha)
    226235{
    227236    if (m_render)
    228237    {
    229         // Drawing an image  multiple times with the same VBO will stall most GPUs as
     238        SCALED_RECT(Dest, m_pixelRatio)
     239
     240        // Drawing an image multiple times with the same VBO will stall most GPUs as
    230241        // the VBO is re-mapped whilst still in use. Use a pooled VBO instead.
    231242        MythGLTexture *texture = GetTextureFromCache(Image);
    232243        if (texture && m_mappedTextures.contains(texture))
    void MythOpenGLPainter::DrawImage(const QRect &Dest, MythImage *Image, 
    234245            QOpenGLBuffer *vbo = texture->m_vbo;
    235246            texture->m_vbo = m_mappedBufferPool[m_mappedBufferPoolIdx];
    236247            texture->m_destination = QRect();
    237             m_render->DrawBitmap(texture, m_target, Source, Dest, nullptr, Alpha);
     248            m_render->DrawBitmap(texture, m_target, Source, dest, nullptr, Alpha);
    238249            texture->m_destination = QRect();
    239250            texture->m_vbo = vbo;
    240251            if (++m_mappedBufferPoolIdx >= MAX_BUFFER_POOL)
    void MythOpenGLPainter::DrawImage(const QRect &Dest, MythImage *Image, 
    242253        }
    243254        else
    244255        {
    245             m_render->DrawBitmap(texture, m_target, Source, Dest, nullptr, Alpha);
     256            m_render->DrawBitmap(texture, m_target, Source, dest, nullptr, Alpha);
    246257            m_mappedTextures.append(texture);
    247258        }
    248259    }
    void MythOpenGLPainter::DrawImage(const QRect &Dest, MythImage *Image, 
    251262void MythOpenGLPainter::DrawRect(const QRect &Area, const QBrush &FillBrush,
    252263                                 const QPen &LinePen, int Alpha)
    253264{
     265    /*
    254266    if ((FillBrush.style() == Qt::SolidPattern ||
    255267         FillBrush.style() == Qt::NoBrush) && m_render)
    256268    {
    257269        m_render->DrawRect(m_target, Area, FillBrush, LinePen, Alpha);
    258270        return;
    259271    }
     272    */
    260273    MythPainter::DrawRect(Area, FillBrush, LinePen, Alpha);
    261274}
    262275
    void MythOpenGLPainter::DrawRoundRect(const QRect &Area, int CornerRadius, 
    264277                                      const QBrush &FillBrush,
    265278                                      const QPen &LinePen, int Alpha)
    266279{
     280    /*
    267281    if ((FillBrush.style() == Qt::SolidPattern ||
    268282         FillBrush.style() == Qt::NoBrush) && m_render)
    269283    {
    270         m_render->DrawRoundRect(m_target, Area, CornerRadius, FillBrush,
    271                                   LinePen, Alpha);
     284        m_render->DrawRoundRect(m_target, Area, CornerRadius, FillBrush, LinePen, Alpha);
    272285        return;
    273286    }
     287    */
    274288    MythPainter::DrawRoundRect(Area, CornerRadius, FillBrush, LinePen, Alpha);
    275289}
    276290
  • mythtv/libs/libmythui/opengl/mythpainteropengl.h

    diff --git a/mythtv/libs/libmythui/opengl/mythpainteropengl.h b/mythtv/libs/libmythui/opengl/mythpainteropengl.h
    index 097577231f..b4a72bd586 100644
    a b class MUI_PUBLIC MythOpenGLPainter : public MythPainter 
    6060    QOpenGLFramebufferObject* m_target { nullptr };
    6161    bool              m_swapControl { true };
    6262    QSize             m_lastSize { };
     63    qreal             m_pixelRatio { 1.0 };
    6364
    6465    QMap<MythImage *, MythGLTexture*> m_imageToTextureMap;
    6566    std::list<MythImage *>     m_ImageExpireList;
  • mythtv/libs/libmythui/opengl/mythrenderopengl.cpp

    diff --git a/mythtv/libs/libmythui/opengl/mythrenderopengl.cpp b/mythtv/libs/libmythui/opengl/mythrenderopengl.cpp
    index e34320f3dc..26d4414b09 100644
    a b void MythRenderOpenGL::SetViewPort(const QRect &Rect, bool ViewportOnly) 
    579579{
    580580    if (Rect == m_viewport)
    581581        return;
     582    LOG(VB_GENERAL, LOG_INFO, LOC + QString("New viewport: %1x%2+%3+%4")
     583        .arg(Rect.width()).arg(Rect.height()).arg(Rect.left()).arg(Rect.top()));
    582584    makeCurrent();
    583585    m_viewport = Rect;
    584586    glViewport(m_viewport.left(), m_viewport.top(),
  • mythtv/libs/libmythui/platforms/mythdisplayosx.cpp

    diff --git a/mythtv/libs/libmythui/platforms/mythdisplayosx.cpp b/mythtv/libs/libmythui/platforms/mythdisplayosx.cpp
    index fa2de7c4cf..68e342a2a1 100644
    a b void MythDisplayOSX::UpdateCurrentMode(void) 
    2727    {
    2828        if (!HasMythMainWindow())
    2929        {
     30            LOG(VB_GENERAL, LOG_WARNING, LOC + "Cannot update current mode");
    3031            MythDisplay::UpdateCurrentMode();
    3132            return;
    3233        }
    void MythDisplayOSX::UpdateCurrentMode(void) 
    3637    CGDirectDisplayID disp = GetOSXDisplay(widget->winId());
    3738    if (!disp)
    3839    {
     40        LOG(VB_GENERAL, LOG_WARNING, LOC + "No display");
    3941        MythDisplay::UpdateCurrentMode();
    4042        return;
    4143    }
    4244    CGDisplayModeRef mode = CGDisplayCopyDisplayMode(disp);
    4345    if (!mode)
    4446    {
     47        LOG(VB_GENERAL, LOG_WARNING, LOC + "Could not copy mode");
    4548        MythDisplay::UpdateCurrentMode();
    4649        return;
    4750    }
    bool MythDisplayOSX::UsingVideoModes(void) 
    6770
    6871const std::vector<MythDisplayMode>& MythDisplayOSX::GetVideoModes(void)
    6972{
    70     if (!m_videoModes.empty() || !HasMythMainWindow())
     73    if (!m_videoModes.empty())
    7174        return m_videoModes;
    7275
     76    if (!HasMythMainWindow())
     77    {
     78        LOG(VB_GENERAL, LOG_WARNING, LOC + "Cannot retrieve modes");
     79        return m_videoModes;
     80    }
     81
    7382    ClearModes();
    7483
    7584    WId win = (qobject_cast<QWidget*>(MythMainWindow::getMainWindow()))->winId();
    const std::vector<MythDisplayMode>& MythDisplayOSX::GetVideoModes(void) 
    8392    DisplayModeMap screen_map;
    8493    CGSize sizemm = CGDisplayScreenSize(disp);
    8594
     95    LOG(VB_GENERAL, LOG_INFO, LOC + "Raw video mode sizes:");
    8696    for (int i = 0; i < CFArrayGetCount(modes); ++i)
    8797    {
    8898        CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(modes, i);
    const std::vector<MythDisplayMode>& MythDisplayOSX::GetVideoModes(void) 
    90100        bool interlaced = CGDisplayModeGetIOFlags(mode) & kDisplayModeInterlacedFlag;
    91101        int width       = static_cast<int>(CGDisplayModeGetWidth(mode));
    92102        int height      = static_cast<int>(CGDisplayModeGetHeight(mode));
     103        int widthp      = static_cast<int>(CGDisplayModeGetPixelWidth(mode));
     104        int heightp     = static_cast<int>(CGDisplayModeGetPixelHeight(mode));
     105
     106        LOG(VB_GENERAL, LOG_INFO, LOC + QString("Resolution: %1x%2 PixelSize: %3x%4")
     107            .arg(width).arg(height).arg(widthp).arg(heightp));
    93108
    94109        // See note in MythDisplayX11
    95110        if (interlaced)
    const std::vector<MythDisplayMode>& MythDisplayOSX::GetVideoModes(void) 
    120135bool MythDisplayOSX::SwitchToVideoMode(QSize Size, double DesiredRate)
    121136{
    122137    if (!HasMythMainWindow())
     138    {
     139        LOG(VB_GENERAL, LOG_WARNING, LOC + "Cannot switch mode");
    123140        return false;
     141    }
     142
    124143    WId win = (qobject_cast<QWidget*>(MythMainWindow::getMainWindow()))->winId();
    125144    CGDirectDisplayID disp = GetOSXDisplay(win);
    126145    if (!disp)
     146    {
     147        LOG(VB_GENERAL, LOG_WARNING, LOC + "No display");
    127148        return false;
     149    }
    128150
    129151    auto rate = static_cast<double>(NAN);
    130152    MythDisplayMode desired(Size, QSize(0, 0), -1.0, DesiredRate);
    bool MythDisplayOSX::SwitchToVideoMode(QSize Size, double DesiredRate) 
    147169    CGDisplayConfigRef cfg;
    148170    CGBeginDisplayConfiguration(&cfg);
    149171    CGConfigureDisplayFadeEffect(cfg, 0.3f, 0.5f, 0, 0, 0);
    150     CGDisplaySetDisplayMode(disp, m_modeMap.value(mode), nullptr);
    151     CGError err = CGCompleteDisplayConfiguration(cfg, kCGConfigureForAppOnly);
     172    CGError err = CGDisplaySetDisplayMode(disp, m_modeMap.value(mode), nullptr);
     173    if (err != kCGErrorSuccess)
     174        LOG(VB_GENERAL, LOG_ERR, LOC + QString("Failed to set display mode (%1)").arg(err));
     175    err = CGCompleteDisplayConfiguration(cfg, kCGConfigureForAppOnly);
    152176    CGDisplayRelease(disp);
    153177    return err == kCGErrorSuccess;
    154178}