Skip to content

Commit

Permalink
X11: expose crtc needed by drm video sync
Browse files Browse the repository at this point in the history
  • Loading branch information
FernetMenta committed Oct 31, 2014
1 parent ce924e9 commit cadfd73
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
4 changes: 2 additions & 2 deletions xbmc-xrandr.c
Expand Up @@ -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);
Expand Down
23 changes: 20 additions & 3 deletions xbmc/windowing/X11/WinSystemX11.cpp
Expand Up @@ -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))
{
Expand Down Expand Up @@ -1232,6 +1235,8 @@ bool CWinSystemX11::SetWindow(int width, int height, bool fullscreen, const std:
#endif
}

UpdateCrtc();

return true;
}

Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions xbmc/windowing/X11/WinSystemX11.h
Expand Up @@ -87,6 +87,7 @@ class CWinSystemX11 : public CWinSystemBase, public ISettingCallback
void GetConnectedOutputs(std::vector<CStdString> *outputs);
bool IsCurrentOutput(CStdString output);
void RecreateWindow();
int GetCrtc() { return m_crtc; }

protected:
bool RefreshGlxContext(bool force);
Expand Down Expand Up @@ -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;
};
Expand Down
19 changes: 19 additions & 0 deletions xbmc/windowing/X11/XRandR.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions xbmc/windowing/X11/XRandR.h
Expand Up @@ -84,6 +84,7 @@ class XOutput
int h;
int x;
int y;
int crtc;
int wmm;
int hmm;
std::vector<XMode> modes;
Expand All @@ -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();
Expand Down

0 comments on commit cadfd73

Please sign in to comment.