From cadfd73ad6f7c288283ec0170740f28b138e703f Mon Sep 17 00:00:00 2001 From: Rainer Hochecker Date: Wed, 15 Oct 2014 13:21:07 +0200 Subject: [PATCH] X11: expose crtc needed by drm video sync --- xbmc-xrandr.c | 4 ++-- xbmc/windowing/X11/WinSystemX11.cpp | 23 ++++++++++++++++++++--- xbmc/windowing/X11/WinSystemX11.h | 3 +++ xbmc/windowing/X11/XRandR.cpp | 19 +++++++++++++++++++ xbmc/windowing/X11/XRandR.h | 2 ++ 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/xbmc-xrandr.c b/xbmc-xrandr.c index 3c686e20593ba..7d164d0a31648 100644 --- a/xbmc-xrandr.c +++ b/xbmc-xrandr.c @@ -3005,9 +3005,9 @@ main (int argc, char **argv) if (mode) { if (crtc_info) { - printf (" w=\"%d\" h=\"%d\" x=\"%d\" y=\"%d\"", + printf (" w=\"%d\" h=\"%d\" x=\"%d\" y=\"%d\" crtc=\"%d\"", crtc_info->width, crtc_info->height, - crtc_info->x, crtc_info->y); + crtc_info->x, crtc_info->y, crtc->crtc.index); } else { printf (" w=\"%d\" h=\"%d\" x=\"%d\" y=\"%d\"", mode->width, mode->height, output->x, output->y); diff --git a/xbmc/windowing/X11/WinSystemX11.cpp b/xbmc/windowing/X11/WinSystemX11.cpp index e5fa05aef80f2..83ad7df0983d2 100644 --- a/xbmc/windowing/X11/WinSystemX11.cpp +++ b/xbmc/windowing/X11/WinSystemX11.cpp @@ -217,10 +217,13 @@ bool CWinSystemX11::ResizeWindow(int newWidth, int newHeight, int newLeft, int n } } - if(m_nWidth == newWidth - && m_nHeight == newHeight - && m_userOutput.compare(m_currentOutput) == 0) + if(m_nWidth == newWidth && + m_nHeight == newHeight && + m_userOutput.compare(m_currentOutput) == 0) + { + UpdateCrtc(); return true; + } if (!SetWindow(newWidth, newHeight, false, m_userOutput)) { @@ -1232,6 +1235,8 @@ bool CWinSystemX11::SetWindow(int width, int height, bool fullscreen, const std: #endif } + UpdateCrtc(); + return true; } @@ -1423,4 +1428,16 @@ bool CWinSystemX11::HasWindowManager() return true; } +void CWinSystemX11::UpdateCrtc() +{ + XWindowAttributes winattr; + int posx, posy; + Window child; + XGetWindowAttributes(m_dpy, m_mainWindow, &winattr); + XTranslateCoordinates(m_dpy, m_mainWindow, RootWindow(m_dpy, m_nScreen), winattr.x, winattr.y, + &posx, &posy, &child); + + m_crtc = g_xrandr.GetCrtc(posx+winattr.width/2, posy+winattr.height/2); +} + #endif diff --git a/xbmc/windowing/X11/WinSystemX11.h b/xbmc/windowing/X11/WinSystemX11.h index 35ae99fbef5bc..d15655482d08a 100644 --- a/xbmc/windowing/X11/WinSystemX11.h +++ b/xbmc/windowing/X11/WinSystemX11.h @@ -87,6 +87,7 @@ class CWinSystemX11 : public CWinSystemBase, public ISettingCallback void GetConnectedOutputs(std::vector *outputs); bool IsCurrentOutput(CStdString output); void RecreateWindow(); + int GetCrtc() { return m_crtc; } protected: bool RefreshGlxContext(bool force); @@ -118,12 +119,14 @@ class CWinSystemX11 : public CWinSystemBase, public ISettingCallback bool m_bIsInternalXrr; bool m_newGlContext; int m_MouseX, m_MouseY; + int m_crtc; private: bool IsSuitableVisual(XVisualInfo *vInfo); static int XErrorHandler(Display* dpy, XErrorEvent* error); bool CreateIconPixmap(); bool HasWindowManager(); + void UpdateCrtc(); CStopWatch m_screensaverReset; }; diff --git a/xbmc/windowing/X11/XRandR.cpp b/xbmc/windowing/X11/XRandR.cpp index 3102f3d5ac53d..d9d7a8fb1c1fb 100644 --- a/xbmc/windowing/X11/XRandR.cpp +++ b/xbmc/windowing/X11/XRandR.cpp @@ -117,6 +117,7 @@ bool CXRandR::Query(bool force, int screennum, bool ignoreoff) xoutput.h = (output->Attribute("h") != NULL ? atoi(output->Attribute("h")) : 0); xoutput.x = (output->Attribute("x") != NULL ? atoi(output->Attribute("x")) : 0); xoutput.y = (output->Attribute("y") != NULL ? atoi(output->Attribute("y")) : 0); + xoutput.crtc = (output->Attribute("crtc") != NULL ? atoi(output->Attribute("crtc")) : 0); xoutput.wmm = (output->Attribute("wmm") != NULL ? atoi(output->Attribute("wmm")) : 0); xoutput.hmm = (output->Attribute("hmm") != NULL ? atoi(output->Attribute("hmm")) : 0); if (output->Attribute("rotation") != NULL @@ -477,6 +478,24 @@ XOutput* CXRandR::GetOutput(CStdString outputName) return result; } +int CXRandR::GetCrtc(int x, int y) +{ + int crtc = 0; + for (unsigned int i = 0; i < m_outputs.size(); ++i) + { + if (!m_outputs[i].isConnected) + continue; + + if ((m_outputs[i].x <= x && (m_outputs[i].x+m_outputs[i].w) > x) && + (m_outputs[i].y <= y && (m_outputs[i].y+m_outputs[i].h) > y)) + { + crtc = m_outputs[i].crtc; + break; + } + } + return crtc; +} + CXRandR g_xrandr; #endif // HAS_XRANDR diff --git a/xbmc/windowing/X11/XRandR.h b/xbmc/windowing/X11/XRandR.h index ab7cc63ea6332..4538bad7a94c4 100644 --- a/xbmc/windowing/X11/XRandR.h +++ b/xbmc/windowing/X11/XRandR.h @@ -84,6 +84,7 @@ class XOutput int h; int x; int y; + int crtc; int wmm; int hmm; std::vector modes; @@ -107,6 +108,7 @@ class CXRandR bool IsOutputConnected(CStdString name); bool TurnOffOutput(CStdString name); bool TurnOnOutput(CStdString name); + int GetCrtc(int x, int y); //bool Has1080i(); //bool Has1080p(); //bool Has720p();