Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From d9a0ec0de50f6fec005d3562eb08ea561a8bfcbe Mon Sep 17 00:00:00 2001
- From: xbmc <fernetmenta@online.de>
- Date: Thu, 21 Jun 2012 17:26:51 +0200
- Subject: [PATCH 097/100] X11: fix video calibrations
- ---
- .../GUIWindowSettingsScreenCalibration.cpp | 1 +
- xbmc/settings/Settings.cpp | 147 +++++++++++++-------
- xbmc/settings/Settings.h | 4 +
- xbmc/windowing/WinSystem.h | 1 +
- xbmc/windowing/X11/WinSystemX11.cpp | 34 +++++
- xbmc/windowing/X11/WinSystemX11.h | 1 +
- 6 files changed, 138 insertions(+), 50 deletions(-)
- diff --git a/xbmc/settings/GUIWindowSettingsScreenCalibration.cpp b/xbmc/settings/GUIWindowSettingsScreenCalibration.cpp
- index 6aaf61b..e120744 100644
- --- a/xbmc/settings/GUIWindowSettingsScreenCalibration.cpp
- +++ b/xbmc/settings/GUIWindowSettingsScreenCalibration.cpp
- @@ -117,6 +117,7 @@ bool CGUIWindowSettingsScreenCalibration::OnMessage(CGUIMessage& message)
- {
- case GUI_MSG_WINDOW_DEINIT:
- {
- + g_settings.UpdateCalibrations();
- g_settings.Save();
- g_graphicsContext.SetCalibrating(false);
- g_windowManager.ShowOverlay(OVERLAY_STATE_SHOWN);
- diff --git a/xbmc/settings/Settings.cpp b/xbmc/settings/Settings.cpp
- index 8af3d10..1006904 100644
- --- a/xbmc/settings/Settings.cpp
- +++ b/xbmc/settings/Settings.cpp
- @@ -56,6 +56,7 @@
- #include "input/MouseStat.h"
- #include "filesystem/File.h"
- #include "filesystem/DirectoryCache.h"
- +#include "windowing/WindowingFactory.h"
- using namespace std;
- using namespace XFILE;
- @@ -487,25 +488,62 @@ bool CSettings::LoadCalibration(const TiXmlElement* pRoot, const CStdString& str
- const TiXmlElement *pResolution = pElement->FirstChildElement("resolution");
- while (pResolution)
- {
- - // get the data for this resolution
- - CStdString mode;
- - XMLUtils::GetString(pResolution, "description", mode);
- - // find this resolution in our resolution vector
- - for (unsigned int res = 0; res < m_ResInfo.size(); res++)
- + // get the data for this calibration
- + RESOLUTION_INFO cal;
- +
- + XMLUtils::GetString(pResolution, "description", cal.strMode);
- + XMLUtils::GetInt(pResolution, "subtitles", cal.iSubtitles);
- + XMLUtils::GetFloat(pResolution, "pixelratio", cal.fPixelRatio);
- +#ifdef HAS_XRANDR
- + XMLUtils::GetFloat(pResolution, "refreshrate", cal.fRefreshRate);
- + XMLUtils::GetString(pResolution, "output", cal.strOutput);
- + XMLUtils::GetString(pResolution, "xrandrid", cal.strId);
- +#endif
- +
- + const TiXmlElement *pOverscan = pResolution->FirstChildElement("overscan");
- + if (pOverscan)
- + {
- + XMLUtils::GetInt(pOverscan, "left", cal.Overscan.left);
- + XMLUtils::GetInt(pOverscan, "top", cal.Overscan.top);
- + XMLUtils::GetInt(pOverscan, "right", cal.Overscan.right);
- + XMLUtils::GetInt(pOverscan, "bottom", cal.Overscan.bottom);
- + }
- +
- + // mark calibration as not updated
- + // we must not delete those, resolution just might not be available
- + cal.iWidth = cal.iHeight = 0;
- +
- + // stote calibration
- + m_Calibrations.push_back(cal);
- +
- + // iterate around
- + pResolution = pResolution->NextSiblingElement("resolution");
- + }
- + ApplyCalibrations();
- + return true;
- +}
- +
- +void CSettings::ApplyCalibrations()
- +{
- + // apply all calibrations to the resolutions
- + for (size_t i = 0; i < m_Calibrations.size(); ++i)
- + {
- + // find resolutions
- + for (size_t res = 0; res < m_ResInfo.size(); ++res)
- {
- if (res == RES_WINDOW)
- continue;
- -
- - if (m_ResInfo[res].strMode == mode)
- - { // found, read in the rest of the information for this item
- - const TiXmlElement *pOverscan = pResolution->FirstChildElement("overscan");
- - if (pOverscan)
- - {
- - GetInteger(pOverscan, "left", m_ResInfo[res].Overscan.left, 0, -m_ResInfo[res].iWidth / 4, m_ResInfo[res].iWidth / 4);
- - GetInteger(pOverscan, "top", m_ResInfo[res].Overscan.top, 0, -m_ResInfo[res].iHeight / 4, m_ResInfo[res].iHeight / 4);
- - GetInteger(pOverscan, "right", m_ResInfo[res].Overscan.right, m_ResInfo[res].iWidth, m_ResInfo[res].iWidth / 2, m_ResInfo[res].iWidth*3 / 2);
- - GetInteger(pOverscan, "bottom", m_ResInfo[res].Overscan.bottom, m_ResInfo[res].iHeight, m_ResInfo[res].iHeight / 2, m_ResInfo[res].iHeight*3 / 2);
- - }
- + if (m_Calibrations[i].strMode.Equals(m_ResInfo[res].strMode))
- + {
- + // overscan
- + if (-m_ResInfo[res].iWidth/4 < m_Calibrations[i].Overscan.left < m_ResInfo[res].iWidth/4)
- + m_ResInfo[res].Overscan.left = m_Calibrations[i].Overscan.left;
- + if (-m_ResInfo[res].iHeight/4 < m_Calibrations[i].Overscan.top < m_ResInfo[res].iHeight/4)
- + m_ResInfo[res].Overscan.top = m_Calibrations[i].Overscan.top;
- + if (-m_ResInfo[res].iWidth/2 < m_Calibrations[i].Overscan.right < m_ResInfo[res].iWidth*3/2)
- + m_ResInfo[res].Overscan.right = m_Calibrations[i].Overscan.right;
- + if (-m_ResInfo[res].iHeight/2 < m_Calibrations[i].Overscan.bottom < m_ResInfo[res].iHeight*3/2)
- + m_ResInfo[res].Overscan.bottom = m_Calibrations[i].Overscan.bottom;
- // get the appropriate "safe graphics area" = 10% for 4x3, 3.5% for 16x9
- float fSafe;
- @@ -514,33 +552,42 @@ bool CSettings::LoadCalibration(const TiXmlElement* pRoot, const CStdString& str
- else
- fSafe = 0.035f;
- - GetInteger(pResolution, "subtitles", m_ResInfo[res].iSubtitles, (int)((1 - fSafe)*m_ResInfo[res].iHeight), m_ResInfo[res].iHeight / 2, m_ResInfo[res].iHeight*5 / 4);
- - GetFloat(pResolution, "pixelratio", m_ResInfo[res].fPixelRatio, 128.0f / 117.0f, 0.5f, 2.0f);
- - /* CLog::Log(LOGDEBUG, " calibration for %s %ix%i", m_ResInfo[res].strMode, m_ResInfo[res].iWidth, m_ResInfo[res].iHeight);
- - CLog::Log(LOGDEBUG, " subtitle yposition:%i pixelratio:%03.3f offsets:(%i,%i)->(%i,%i)",
- - m_ResInfo[res].iSubtitles, m_ResInfo[res].fPixelRatio,
- - m_ResInfo[res].Overscan.left, m_ResInfo[res].Overscan.top,
- - m_ResInfo[res].Overscan.right, m_ResInfo[res].Overscan.bottom);*/
- + if (m_ResInfo[res].iHeight / 2 < m_Calibrations[i].iSubtitles < m_ResInfo[res].iHeight*5 / 4)
- + m_ResInfo[res].iSubtitles = m_Calibrations[i].iSubtitles;
- + if (0.5f < m_Calibrations[i].fPixelRatio < 2.0f)
- + m_ResInfo[res].fPixelRatio = m_Calibrations[i].fPixelRatio;
- +
- + break;
- }
- }
- - // iterate around
- - pResolution = pResolution->NextSiblingElement("resolution");
- + }
- +}
- +void CSettings::UpdateCalibrations()
- +{
- + for (size_t res = RES_DESKTOP; res < m_ResInfo.size(); ++res)
- + {
- + // only those with changes in calibration, windowing knows as it loads defaults
- + if (!g_Windowing.HasCalibration(m_ResInfo[res]))
- + continue;
- -/* Hmm, these stuff shouldn't be releaded, they should be used instead of our internal
- - id counter to select what resolution is affected by this settings
- -#ifdef HAS_XRANDR
- - const CStdString def("");
- - CStdString val;
- - GetString(pResolution, "xrandrid", val, def);
- - strncpy(m_ResInfo[iRes].strId, val.c_str(), sizeof(m_ResInfo[iRes].strId));
- - GetString(pResolution, "output", val, def);
- - strncpy(m_ResInfo[iRes].strOutput, val.c_str(), sizeof(m_ResInfo[iRes].strOutput));
- - GetFloat(pResolution, "refreshrate", m_ResInfo[iRes].fRefreshRate, 0, 0, 200);
- -#endif
- -*/
- + // find calibration
- + bool found = false;
- + for (std::vector<RESOLUTION_INFO>::iterator it = m_Calibrations.begin(); it != m_Calibrations.end(); ++it)
- + {
- + if (it->strMode.Equals(m_ResInfo[res].strMode))
- + {
- + if (g_Windowing.HasCalibration(m_ResInfo[res]))
- + (*it) = m_ResInfo[res];
- + else
- + m_Calibrations.erase(it);
- + found = true;
- + break;
- + }
- + }
- + if (!found)
- + m_Calibrations.push_back(m_ResInfo[res]);
- }
- - return true;
- }
- bool CSettings::SaveCalibration(TiXmlNode* pRootNode) const
- @@ -548,28 +595,28 @@ bool CSettings::SaveCalibration(TiXmlNode* pRootNode) const
- TiXmlElement xmlRootElement("resolutions");
- TiXmlNode *pRoot = pRootNode->InsertEndChild(xmlRootElement);
- - // save WINDOW, DESKTOP and CUSTOM resolution
- - for (size_t i = RES_WINDOW ; i < m_ResInfo.size() ; i++)
- + // save calibrations
- + for (size_t i = 0 ; i < m_Calibrations.size() ; i++)
- {
- // Write the resolution tag
- TiXmlElement resElement("resolution");
- TiXmlNode *pNode = pRoot->InsertEndChild(resElement);
- // Now write each of the pieces of information we need...
- - XMLUtils::SetString(pNode, "description", m_ResInfo[i].strMode);
- - XMLUtils::SetInt(pNode, "subtitles", m_ResInfo[i].iSubtitles);
- - XMLUtils::SetFloat(pNode, "pixelratio", m_ResInfo[i].fPixelRatio);
- + XMLUtils::SetString(pNode, "description", m_Calibrations[i].strMode);
- + XMLUtils::SetInt(pNode, "subtitles", m_Calibrations[i].iSubtitles);
- + XMLUtils::SetFloat(pNode, "pixelratio", m_Calibrations[i].fPixelRatio);
- #ifdef HAS_XRANDR
- - XMLUtils::SetFloat(pNode, "refreshrate", m_ResInfo[i].fRefreshRate);
- - XMLUtils::SetString(pNode, "output", m_ResInfo[i].strOutput);
- - XMLUtils::SetString(pNode, "xrandrid", m_ResInfo[i].strId);
- + XMLUtils::SetFloat(pNode, "refreshrate", m_Calibrations[i].fRefreshRate);
- + XMLUtils::SetString(pNode, "output", m_Calibrations[i].strOutput);
- + XMLUtils::SetString(pNode, "xrandrid", m_Calibrations[i].strId);
- #endif
- // create the overscan child
- TiXmlElement overscanElement("overscan");
- TiXmlNode *pOverscanNode = pNode->InsertEndChild(overscanElement);
- - XMLUtils::SetInt(pOverscanNode, "left", m_ResInfo[i].Overscan.left);
- - XMLUtils::SetInt(pOverscanNode, "top", m_ResInfo[i].Overscan.top);
- - XMLUtils::SetInt(pOverscanNode, "right", m_ResInfo[i].Overscan.right);
- - XMLUtils::SetInt(pOverscanNode, "bottom", m_ResInfo[i].Overscan.bottom);
- + XMLUtils::SetInt(pOverscanNode, "left", m_Calibrations[i].Overscan.left);
- + XMLUtils::SetInt(pOverscanNode, "top", m_Calibrations[i].Overscan.top);
- + XMLUtils::SetInt(pOverscanNode, "right", m_Calibrations[i].Overscan.right);
- + XMLUtils::SetInt(pOverscanNode, "bottom", m_Calibrations[i].Overscan.bottom);
- }
- return true;
- }
- diff --git a/xbmc/settings/Settings.h b/xbmc/settings/Settings.h
- index 46a7b0c..81b47fc 100644
- --- a/xbmc/settings/Settings.h
- +++ b/xbmc/settings/Settings.h
- @@ -335,6 +335,7 @@ public:
- int GetCurrentProfileId() const;
- std::vector<RESOLUTION_INFO> m_ResInfo;
- + std::vector<RESOLUTION_INFO> m_Calibrations;
- // utility functions for user data folders
- @@ -386,6 +387,9 @@ public:
- static bool GetString(const TiXmlElement* pRootElement, const char *strTagName, CStdString& strValue, const CStdString& strDefaultValue);
- bool GetString(const TiXmlElement* pRootElement, const char *strTagName, char *szValue, const CStdString& strDefaultValue);
- bool GetSource(const CStdString &category, const TiXmlNode *source, CMediaSource &share);
- +
- + void ApplyCalibrations();
- + void UpdateCalibrations();
- protected:
- void GetSources(const TiXmlElement* pRootElement, const CStdString& strTagName, VECSOURCES& items, CStdString& strDefault);
- bool SetSources(TiXmlNode *root, const char *section, const VECSOURCES &shares, const char *defaultPath);
- diff --git a/xbmc/windowing/WinSystem.h b/xbmc/windowing/WinSystem.h
- index 1af91c6..45d4872 100644
- --- a/xbmc/windowing/WinSystem.h
- +++ b/xbmc/windowing/WinSystem.h
- @@ -99,6 +99,7 @@ public:
- std::vector<RESOLUTION_WHR> ScreenResolutions(int screen);
- std::vector<REFRESHRATE> RefreshRates(int screen, int width, int height);
- REFRESHRATE DefaultRefreshRate(int screen, std::vector<REFRESHRATE> rates);
- + virtual bool HasCalibration(const RESOLUTION_INFO &resInfo) { return true; };
- protected:
- void UpdateDesktopResolution(RESOLUTION_INFO& newRes, int screen, int width, int height, float refreshRate, uint32_t dwFlags = 0);
- diff --git a/xbmc/windowing/X11/WinSystemX11.cpp b/xbmc/windowing/X11/WinSystemX11.cpp
- index 3bb8f66..e94bd38 100644
- --- a/xbmc/windowing/X11/WinSystemX11.cpp
- +++ b/xbmc/windowing/X11/WinSystemX11.cpp
- @@ -421,8 +421,42 @@ void CWinSystemX11::UpdateResolutions()
- g_settings.m_ResInfo.push_back(res);
- }
- }
- + g_settings.ApplyCalibrations();
- #endif
- +}
- +
- +bool CWinSystemX11::HasCalibration(const RESOLUTION_INFO &resInfo)
- +{
- + XOutput out = g_xrandr.GetCurrentOutput();
- +
- + // keep calibrations done on a not connected output
- + if (!out.name.Equals(resInfo.strOutput))
- + return true;
- +
- + // keep calibrations not updated with resolution data
- + if (resInfo.iWidth == 0)
- + return true;
- +
- + float fPixRatio;
- + if (resInfo.iHeight>0 && resInfo.iWidth>0 && out.hmm>0 && out.wmm>0)
- + fPixRatio = ((float)out.wmm/(float)resInfo.iWidth) / (((float)out.hmm/(float)resInfo.iHeight));
- + else
- + fPixRatio = 1.0f;
- + if (resInfo.Overscan.left != 0)
- + return true;
- + if (resInfo.Overscan.top != 0)
- + return true;
- + if (resInfo.Overscan.right != resInfo.iWidth)
- + return true;
- + if (resInfo.Overscan.bottom != resInfo.iHeight)
- + return true;
- + if (resInfo.fPixelRatio != fPixRatio)
- + return true;
- + if (resInfo.iSubtitles != (int)(0.95*resInfo.iHeight))
- + return true;
- +
- + return false;
- }
- void CWinSystemX11::GetConnectedOutputs(std::vector<CStdString> *outputs)
- diff --git a/xbmc/windowing/X11/WinSystemX11.h b/xbmc/windowing/X11/WinSystemX11.h
- index 022b131..1defe73 100644
- --- a/xbmc/windowing/X11/WinSystemX11.h
- +++ b/xbmc/windowing/X11/WinSystemX11.h
- @@ -61,6 +61,7 @@ public:
- virtual bool Show(bool raise = true);
- virtual void Register(IDispResource *resource);
- virtual void Unregister(IDispResource *resource);
- + virtual bool HasCalibration(const RESOLUTION_INFO &resInfo);
- // Local to WinSystemX11 only
- Display* GetDisplay() { return m_dpy; }
- --
- 1.7.10.2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement