Advertisement
Guest User

XBMC Frodo - Save Video Settings Calibration patch

a guest
Jul 3rd, 2012
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.95 KB | None | 0 0
  1. From d9a0ec0de50f6fec005d3562eb08ea561a8bfcbe Mon Sep 17 00:00:00 2001
  2. From: xbmc <fernetmenta@online.de>
  3. Date: Thu, 21 Jun 2012 17:26:51 +0200
  4. Subject: [PATCH 097/100] X11: fix video calibrations
  5.  
  6. ---
  7. .../GUIWindowSettingsScreenCalibration.cpp | 1 +
  8. xbmc/settings/Settings.cpp | 147 +++++++++++++-------
  9. xbmc/settings/Settings.h | 4 +
  10. xbmc/windowing/WinSystem.h | 1 +
  11. xbmc/windowing/X11/WinSystemX11.cpp | 34 +++++
  12. xbmc/windowing/X11/WinSystemX11.h | 1 +
  13. 6 files changed, 138 insertions(+), 50 deletions(-)
  14.  
  15. diff --git a/xbmc/settings/GUIWindowSettingsScreenCalibration.cpp b/xbmc/settings/GUIWindowSettingsScreenCalibration.cpp
  16. index 6aaf61b..e120744 100644
  17. --- a/xbmc/settings/GUIWindowSettingsScreenCalibration.cpp
  18. +++ b/xbmc/settings/GUIWindowSettingsScreenCalibration.cpp
  19. @@ -117,6 +117,7 @@ bool CGUIWindowSettingsScreenCalibration::OnMessage(CGUIMessage& message)
  20. {
  21. case GUI_MSG_WINDOW_DEINIT:
  22. {
  23. + g_settings.UpdateCalibrations();
  24. g_settings.Save();
  25. g_graphicsContext.SetCalibrating(false);
  26. g_windowManager.ShowOverlay(OVERLAY_STATE_SHOWN);
  27. diff --git a/xbmc/settings/Settings.cpp b/xbmc/settings/Settings.cpp
  28. index 8af3d10..1006904 100644
  29. --- a/xbmc/settings/Settings.cpp
  30. +++ b/xbmc/settings/Settings.cpp
  31. @@ -56,6 +56,7 @@
  32. #include "input/MouseStat.h"
  33. #include "filesystem/File.h"
  34. #include "filesystem/DirectoryCache.h"
  35. +#include "windowing/WindowingFactory.h"
  36.  
  37. using namespace std;
  38. using namespace XFILE;
  39. @@ -487,25 +488,62 @@ bool CSettings::LoadCalibration(const TiXmlElement* pRoot, const CStdString& str
  40. const TiXmlElement *pResolution = pElement->FirstChildElement("resolution");
  41. while (pResolution)
  42. {
  43. - // get the data for this resolution
  44. - CStdString mode;
  45. - XMLUtils::GetString(pResolution, "description", mode);
  46. - // find this resolution in our resolution vector
  47. - for (unsigned int res = 0; res < m_ResInfo.size(); res++)
  48. + // get the data for this calibration
  49. + RESOLUTION_INFO cal;
  50. +
  51. + XMLUtils::GetString(pResolution, "description", cal.strMode);
  52. + XMLUtils::GetInt(pResolution, "subtitles", cal.iSubtitles);
  53. + XMLUtils::GetFloat(pResolution, "pixelratio", cal.fPixelRatio);
  54. +#ifdef HAS_XRANDR
  55. + XMLUtils::GetFloat(pResolution, "refreshrate", cal.fRefreshRate);
  56. + XMLUtils::GetString(pResolution, "output", cal.strOutput);
  57. + XMLUtils::GetString(pResolution, "xrandrid", cal.strId);
  58. +#endif
  59. +
  60. + const TiXmlElement *pOverscan = pResolution->FirstChildElement("overscan");
  61. + if (pOverscan)
  62. + {
  63. + XMLUtils::GetInt(pOverscan, "left", cal.Overscan.left);
  64. + XMLUtils::GetInt(pOverscan, "top", cal.Overscan.top);
  65. + XMLUtils::GetInt(pOverscan, "right", cal.Overscan.right);
  66. + XMLUtils::GetInt(pOverscan, "bottom", cal.Overscan.bottom);
  67. + }
  68. +
  69. + // mark calibration as not updated
  70. + // we must not delete those, resolution just might not be available
  71. + cal.iWidth = cal.iHeight = 0;
  72. +
  73. + // stote calibration
  74. + m_Calibrations.push_back(cal);
  75. +
  76. + // iterate around
  77. + pResolution = pResolution->NextSiblingElement("resolution");
  78. + }
  79. + ApplyCalibrations();
  80. + return true;
  81. +}
  82. +
  83. +void CSettings::ApplyCalibrations()
  84. +{
  85. + // apply all calibrations to the resolutions
  86. + for (size_t i = 0; i < m_Calibrations.size(); ++i)
  87. + {
  88. + // find resolutions
  89. + for (size_t res = 0; res < m_ResInfo.size(); ++res)
  90. {
  91. if (res == RES_WINDOW)
  92. continue;
  93. -
  94. - if (m_ResInfo[res].strMode == mode)
  95. - { // found, read in the rest of the information for this item
  96. - const TiXmlElement *pOverscan = pResolution->FirstChildElement("overscan");
  97. - if (pOverscan)
  98. - {
  99. - GetInteger(pOverscan, "left", m_ResInfo[res].Overscan.left, 0, -m_ResInfo[res].iWidth / 4, m_ResInfo[res].iWidth / 4);
  100. - GetInteger(pOverscan, "top", m_ResInfo[res].Overscan.top, 0, -m_ResInfo[res].iHeight / 4, m_ResInfo[res].iHeight / 4);
  101. - GetInteger(pOverscan, "right", m_ResInfo[res].Overscan.right, m_ResInfo[res].iWidth, m_ResInfo[res].iWidth / 2, m_ResInfo[res].iWidth*3 / 2);
  102. - GetInteger(pOverscan, "bottom", m_ResInfo[res].Overscan.bottom, m_ResInfo[res].iHeight, m_ResInfo[res].iHeight / 2, m_ResInfo[res].iHeight*3 / 2);
  103. - }
  104. + if (m_Calibrations[i].strMode.Equals(m_ResInfo[res].strMode))
  105. + {
  106. + // overscan
  107. + if (-m_ResInfo[res].iWidth/4 < m_Calibrations[i].Overscan.left < m_ResInfo[res].iWidth/4)
  108. + m_ResInfo[res].Overscan.left = m_Calibrations[i].Overscan.left;
  109. + if (-m_ResInfo[res].iHeight/4 < m_Calibrations[i].Overscan.top < m_ResInfo[res].iHeight/4)
  110. + m_ResInfo[res].Overscan.top = m_Calibrations[i].Overscan.top;
  111. + if (-m_ResInfo[res].iWidth/2 < m_Calibrations[i].Overscan.right < m_ResInfo[res].iWidth*3/2)
  112. + m_ResInfo[res].Overscan.right = m_Calibrations[i].Overscan.right;
  113. + if (-m_ResInfo[res].iHeight/2 < m_Calibrations[i].Overscan.bottom < m_ResInfo[res].iHeight*3/2)
  114. + m_ResInfo[res].Overscan.bottom = m_Calibrations[i].Overscan.bottom;
  115.  
  116. // get the appropriate "safe graphics area" = 10% for 4x3, 3.5% for 16x9
  117. float fSafe;
  118. @@ -514,33 +552,42 @@ bool CSettings::LoadCalibration(const TiXmlElement* pRoot, const CStdString& str
  119. else
  120. fSafe = 0.035f;
  121.  
  122. - 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);
  123. - GetFloat(pResolution, "pixelratio", m_ResInfo[res].fPixelRatio, 128.0f / 117.0f, 0.5f, 2.0f);
  124. - /* CLog::Log(LOGDEBUG, " calibration for %s %ix%i", m_ResInfo[res].strMode, m_ResInfo[res].iWidth, m_ResInfo[res].iHeight);
  125. - CLog::Log(LOGDEBUG, " subtitle yposition:%i pixelratio:%03.3f offsets:(%i,%i)->(%i,%i)",
  126. - m_ResInfo[res].iSubtitles, m_ResInfo[res].fPixelRatio,
  127. - m_ResInfo[res].Overscan.left, m_ResInfo[res].Overscan.top,
  128. - m_ResInfo[res].Overscan.right, m_ResInfo[res].Overscan.bottom);*/
  129. + if (m_ResInfo[res].iHeight / 2 < m_Calibrations[i].iSubtitles < m_ResInfo[res].iHeight*5 / 4)
  130. + m_ResInfo[res].iSubtitles = m_Calibrations[i].iSubtitles;
  131. + if (0.5f < m_Calibrations[i].fPixelRatio < 2.0f)
  132. + m_ResInfo[res].fPixelRatio = m_Calibrations[i].fPixelRatio;
  133. +
  134. + break;
  135. }
  136. }
  137. - // iterate around
  138. - pResolution = pResolution->NextSiblingElement("resolution");
  139. + }
  140. +}
  141.  
  142. +void CSettings::UpdateCalibrations()
  143. +{
  144. + for (size_t res = RES_DESKTOP; res < m_ResInfo.size(); ++res)
  145. + {
  146. + // only those with changes in calibration, windowing knows as it loads defaults
  147. + if (!g_Windowing.HasCalibration(m_ResInfo[res]))
  148. + continue;
  149.  
  150. -/* Hmm, these stuff shouldn't be releaded, they should be used instead of our internal
  151. - id counter to select what resolution is affected by this settings
  152. -#ifdef HAS_XRANDR
  153. - const CStdString def("");
  154. - CStdString val;
  155. - GetString(pResolution, "xrandrid", val, def);
  156. - strncpy(m_ResInfo[iRes].strId, val.c_str(), sizeof(m_ResInfo[iRes].strId));
  157. - GetString(pResolution, "output", val, def);
  158. - strncpy(m_ResInfo[iRes].strOutput, val.c_str(), sizeof(m_ResInfo[iRes].strOutput));
  159. - GetFloat(pResolution, "refreshrate", m_ResInfo[iRes].fRefreshRate, 0, 0, 200);
  160. -#endif
  161. -*/
  162. + // find calibration
  163. + bool found = false;
  164. + for (std::vector<RESOLUTION_INFO>::iterator it = m_Calibrations.begin(); it != m_Calibrations.end(); ++it)
  165. + {
  166. + if (it->strMode.Equals(m_ResInfo[res].strMode))
  167. + {
  168. + if (g_Windowing.HasCalibration(m_ResInfo[res]))
  169. + (*it) = m_ResInfo[res];
  170. + else
  171. + m_Calibrations.erase(it);
  172. + found = true;
  173. + break;
  174. + }
  175. + }
  176. + if (!found)
  177. + m_Calibrations.push_back(m_ResInfo[res]);
  178. }
  179. - return true;
  180. }
  181.  
  182. bool CSettings::SaveCalibration(TiXmlNode* pRootNode) const
  183. @@ -548,28 +595,28 @@ bool CSettings::SaveCalibration(TiXmlNode* pRootNode) const
  184. TiXmlElement xmlRootElement("resolutions");
  185. TiXmlNode *pRoot = pRootNode->InsertEndChild(xmlRootElement);
  186.  
  187. - // save WINDOW, DESKTOP and CUSTOM resolution
  188. - for (size_t i = RES_WINDOW ; i < m_ResInfo.size() ; i++)
  189. + // save calibrations
  190. + for (size_t i = 0 ; i < m_Calibrations.size() ; i++)
  191. {
  192. // Write the resolution tag
  193. TiXmlElement resElement("resolution");
  194. TiXmlNode *pNode = pRoot->InsertEndChild(resElement);
  195. // Now write each of the pieces of information we need...
  196. - XMLUtils::SetString(pNode, "description", m_ResInfo[i].strMode);
  197. - XMLUtils::SetInt(pNode, "subtitles", m_ResInfo[i].iSubtitles);
  198. - XMLUtils::SetFloat(pNode, "pixelratio", m_ResInfo[i].fPixelRatio);
  199. + XMLUtils::SetString(pNode, "description", m_Calibrations[i].strMode);
  200. + XMLUtils::SetInt(pNode, "subtitles", m_Calibrations[i].iSubtitles);
  201. + XMLUtils::SetFloat(pNode, "pixelratio", m_Calibrations[i].fPixelRatio);
  202. #ifdef HAS_XRANDR
  203. - XMLUtils::SetFloat(pNode, "refreshrate", m_ResInfo[i].fRefreshRate);
  204. - XMLUtils::SetString(pNode, "output", m_ResInfo[i].strOutput);
  205. - XMLUtils::SetString(pNode, "xrandrid", m_ResInfo[i].strId);
  206. + XMLUtils::SetFloat(pNode, "refreshrate", m_Calibrations[i].fRefreshRate);
  207. + XMLUtils::SetString(pNode, "output", m_Calibrations[i].strOutput);
  208. + XMLUtils::SetString(pNode, "xrandrid", m_Calibrations[i].strId);
  209. #endif
  210. // create the overscan child
  211. TiXmlElement overscanElement("overscan");
  212. TiXmlNode *pOverscanNode = pNode->InsertEndChild(overscanElement);
  213. - XMLUtils::SetInt(pOverscanNode, "left", m_ResInfo[i].Overscan.left);
  214. - XMLUtils::SetInt(pOverscanNode, "top", m_ResInfo[i].Overscan.top);
  215. - XMLUtils::SetInt(pOverscanNode, "right", m_ResInfo[i].Overscan.right);
  216. - XMLUtils::SetInt(pOverscanNode, "bottom", m_ResInfo[i].Overscan.bottom);
  217. + XMLUtils::SetInt(pOverscanNode, "left", m_Calibrations[i].Overscan.left);
  218. + XMLUtils::SetInt(pOverscanNode, "top", m_Calibrations[i].Overscan.top);
  219. + XMLUtils::SetInt(pOverscanNode, "right", m_Calibrations[i].Overscan.right);
  220. + XMLUtils::SetInt(pOverscanNode, "bottom", m_Calibrations[i].Overscan.bottom);
  221. }
  222. return true;
  223. }
  224. diff --git a/xbmc/settings/Settings.h b/xbmc/settings/Settings.h
  225. index 46a7b0c..81b47fc 100644
  226. --- a/xbmc/settings/Settings.h
  227. +++ b/xbmc/settings/Settings.h
  228. @@ -335,6 +335,7 @@ public:
  229. int GetCurrentProfileId() const;
  230.  
  231. std::vector<RESOLUTION_INFO> m_ResInfo;
  232. + std::vector<RESOLUTION_INFO> m_Calibrations;
  233.  
  234. // utility functions for user data folders
  235.  
  236. @@ -386,6 +387,9 @@ public:
  237. static bool GetString(const TiXmlElement* pRootElement, const char *strTagName, CStdString& strValue, const CStdString& strDefaultValue);
  238. bool GetString(const TiXmlElement* pRootElement, const char *strTagName, char *szValue, const CStdString& strDefaultValue);
  239. bool GetSource(const CStdString &category, const TiXmlNode *source, CMediaSource &share);
  240. +
  241. + void ApplyCalibrations();
  242. + void UpdateCalibrations();
  243. protected:
  244. void GetSources(const TiXmlElement* pRootElement, const CStdString& strTagName, VECSOURCES& items, CStdString& strDefault);
  245. bool SetSources(TiXmlNode *root, const char *section, const VECSOURCES &shares, const char *defaultPath);
  246. diff --git a/xbmc/windowing/WinSystem.h b/xbmc/windowing/WinSystem.h
  247. index 1af91c6..45d4872 100644
  248. --- a/xbmc/windowing/WinSystem.h
  249. +++ b/xbmc/windowing/WinSystem.h
  250. @@ -99,6 +99,7 @@ public:
  251. std::vector<RESOLUTION_WHR> ScreenResolutions(int screen);
  252. std::vector<REFRESHRATE> RefreshRates(int screen, int width, int height);
  253. REFRESHRATE DefaultRefreshRate(int screen, std::vector<REFRESHRATE> rates);
  254. + virtual bool HasCalibration(const RESOLUTION_INFO &resInfo) { return true; };
  255.  
  256. protected:
  257. void UpdateDesktopResolution(RESOLUTION_INFO& newRes, int screen, int width, int height, float refreshRate, uint32_t dwFlags = 0);
  258. diff --git a/xbmc/windowing/X11/WinSystemX11.cpp b/xbmc/windowing/X11/WinSystemX11.cpp
  259. index 3bb8f66..e94bd38 100644
  260. --- a/xbmc/windowing/X11/WinSystemX11.cpp
  261. +++ b/xbmc/windowing/X11/WinSystemX11.cpp
  262. @@ -421,8 +421,42 @@ void CWinSystemX11::UpdateResolutions()
  263. g_settings.m_ResInfo.push_back(res);
  264. }
  265. }
  266. + g_settings.ApplyCalibrations();
  267. #endif
  268. +}
  269. +
  270. +bool CWinSystemX11::HasCalibration(const RESOLUTION_INFO &resInfo)
  271. +{
  272. + XOutput out = g_xrandr.GetCurrentOutput();
  273. +
  274. + // keep calibrations done on a not connected output
  275. + if (!out.name.Equals(resInfo.strOutput))
  276. + return true;
  277. +
  278. + // keep calibrations not updated with resolution data
  279. + if (resInfo.iWidth == 0)
  280. + return true;
  281. +
  282. + float fPixRatio;
  283. + if (resInfo.iHeight>0 && resInfo.iWidth>0 && out.hmm>0 && out.wmm>0)
  284. + fPixRatio = ((float)out.wmm/(float)resInfo.iWidth) / (((float)out.hmm/(float)resInfo.iHeight));
  285. + else
  286. + fPixRatio = 1.0f;
  287.  
  288. + if (resInfo.Overscan.left != 0)
  289. + return true;
  290. + if (resInfo.Overscan.top != 0)
  291. + return true;
  292. + if (resInfo.Overscan.right != resInfo.iWidth)
  293. + return true;
  294. + if (resInfo.Overscan.bottom != resInfo.iHeight)
  295. + return true;
  296. + if (resInfo.fPixelRatio != fPixRatio)
  297. + return true;
  298. + if (resInfo.iSubtitles != (int)(0.95*resInfo.iHeight))
  299. + return true;
  300. +
  301. + return false;
  302. }
  303.  
  304. void CWinSystemX11::GetConnectedOutputs(std::vector<CStdString> *outputs)
  305. diff --git a/xbmc/windowing/X11/WinSystemX11.h b/xbmc/windowing/X11/WinSystemX11.h
  306. index 022b131..1defe73 100644
  307. --- a/xbmc/windowing/X11/WinSystemX11.h
  308. +++ b/xbmc/windowing/X11/WinSystemX11.h
  309. @@ -61,6 +61,7 @@ public:
  310. virtual bool Show(bool raise = true);
  311. virtual void Register(IDispResource *resource);
  312. virtual void Unregister(IDispResource *resource);
  313. + virtual bool HasCalibration(const RESOLUTION_INFO &resInfo);
  314.  
  315. // Local to WinSystemX11 only
  316. Display* GetDisplay() { return m_dpy; }
  317. --
  318. 1.7.10.2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement