Skip to content
This repository
Browse code

Merge pull request #2041 from popcornmix/display_aspect_ratio

[rbp] Fix non-square pixel display apect ratio and 3D TAB modes correctly
  • Loading branch information...
commit 1f8d72560c2e1fb3705462ba151b83723c170e3d 2 parents f4c4857 + 4193032
davilla authored January 20, 2013
18  xbmc/cores/VideoRenderers/BaseRenderer.cpp
@@ -214,6 +214,16 @@ RESOLUTION CBaseRenderer::FindClosestResolution(float fps, float multiplier, RES
214 214
    *
215 215
    */
216 216
 
  217
+  // work out current non-3D resolution (in case we are currently in 3D mode)
  218
+  if (curr.dwFlags & D3DPRESENTFLAG_MODE3DSBS)
  219
+  {
  220
+    iScreenWidth *= 2;
  221
+  }
  222
+  else if (curr.dwFlags & D3DPRESENTFLAG_MODE3DTB)
  223
+  {
  224
+    iScreenHeight *= 2;
  225
+  }
  226
+  // work out resolution if we switch to 3D mode
217 227
   if(m_iFlags & CONF_FLAGS_FORMAT_SBS)
218 228
   {
219 229
     iScreenWidth /= 2;
@@ -500,11 +510,6 @@ void CBaseRenderer::CalcNormalDisplayRect(float offsetX, float offsetY, float sc
500 510
 //***************************************************************************************
501 511
 void CBaseRenderer::CalculateFrameAspectRatio(unsigned int desired_width, unsigned int desired_height)
502 512
 {
503  
-  if(m_iFlags & CONF_FLAGS_FORMAT_SBS)
504  
-    desired_width /= 2;
505  
-  else if(m_iFlags & CONF_FLAGS_FORMAT_TB)
506  
-    desired_height /= 2;
507  
-
508 513
   m_sourceFrameRatio = (float)desired_width / desired_height;
509 514
 
510 515
   // Check whether mplayer has decided that the size of the video file should be changed
@@ -577,6 +582,9 @@ void CBaseRenderer::SetViewMode(int viewMode)
577 582
   if (viewMode < VIEW_MODE_NORMAL || viewMode > VIEW_MODE_CUSTOM)
578 583
     viewMode = VIEW_MODE_NORMAL;
579 584
 
  585
+  if (m_iFlags & (CONF_FLAGS_FORMAT_SBS | CONF_FLAGS_FORMAT_TB))
  586
+    viewMode = VIEW_MODE_NORMAL;
  587
+
580 588
   g_settings.m_currentVideoSettings.m_ViewMode = viewMode;
581 589
 
582 590
   // get our calibrated full screen resolution
0  xbmc/cores/omxplayer/.goutputstream-ISUQQW
No changes.
4  xbmc/cores/omxplayer/OMXPlayer.cpp
@@ -2958,8 +2958,10 @@ bool COMXPlayer::OpenVideoStream(int iStream, int source, bool reset)
2958 2958
     m_player_video.SendMessage(new CDVDMsg(CDVDMsg::GENERAL_RESET));
2959 2959
 
2960 2960
   unsigned flags = 0;
2961  
-  if(m_filename.find("3DSBS") != string::npos) 
  2961
+  if(m_filename.find("3DSBS") != string::npos || m_filename.find("HSBS") != string::npos)
2962 2962
     flags = CONF_FLAGS_FORMAT_SBS;
  2963
+  else if(m_filename.find("3DTAB") != string::npos || m_filename.find("HTAB") != string::npos)
  2964
+    flags = CONF_FLAGS_FORMAT_TB;
2963 2965
   m_player_video.SetFlags(flags);
2964 2966
 
2965 2967
   /* store information about stream */
28  xbmc/cores/omxplayer/OMXPlayerVideo.cpp
@@ -99,8 +99,8 @@ OMXPlayerVideo::OMXPlayerVideo(OMXClock *av_clock,
99 99
   m_messageQueue.SetMaxTimeSize(8.0);
100 100
 
101 101
   RESOLUTION res  = g_graphicsContext.GetVideoResolution();
102  
-  m_video_width   = g_settings.m_ResInfo[res].iWidth;
103  
-  m_video_height  = g_settings.m_ResInfo[res].iHeight;
  102
+  m_video_width   = g_settings.m_ResInfo[res].iScreenWidth;
  103
+  m_video_height  = g_settings.m_ResInfo[res].iScreenHeight;
104 104
 
105 105
   m_dst_rect.SetRect(0, 0, 0, 0);
106 106
 
@@ -337,16 +337,25 @@ void OMXPlayerVideo::Output(int iGroupId, double pts, bool bDropPacket)
337 337
         flags |= CONF_FLAGS_FORMAT_SBS;
338 338
       }
339 339
     }
340  
-
341  
-    CLog::Log(LOGDEBUG,"%s - change configuration. %dx%d. framerate: %4.2f. format: BYPASS",
342  
-        __FUNCTION__, m_width, m_height, m_fps);
  340
+    else if(m_flags & CONF_FLAGS_FORMAT_TB)
  341
+    {
  342
+      if(g_Windowing.Support3D(m_video_width, m_video_height, D3DPRESENTFLAG_MODE3DTB))
  343
+      {
  344
+        CLog::Log(LOGNOTICE, "3DTB movie found");
  345
+        flags |= CONF_FLAGS_FORMAT_TB;
  346
+      }
  347
+    }
343 348
 
344 349
     unsigned int iDisplayWidth  = m_hints.width;
345 350
     unsigned int iDisplayHeight = m_hints.height;
  351
+
346 352
     /* use forced aspect if any */
347 353
     if( m_fForcedAspectRatio != 0.0f )
348 354
       iDisplayWidth = (int) (iDisplayHeight * m_fForcedAspectRatio);
349 355
 
  356
+    CLog::Log(LOGDEBUG,"%s - change configuration. %dx%d. framerate: %4.2f. %dx%x format: BYPASS",
  357
+        __FUNCTION__, m_width, m_height, m_fps, iDisplayWidth, iDisplayHeight);
  358
+
350 359
     if(!g_renderManager.Configure(m_hints.width, m_hints.height,
351 360
           iDisplayWidth, iDisplayHeight, m_fps, flags, format, 0,
352 361
           m_hints.orientation))
@@ -813,21 +822,22 @@ void OMXPlayerVideo::SetVideoRect(const CRect &SrcRect, const CRect &DestRect)
813 822
   CRect gui, display, dst_rect;
814 823
   RESOLUTION res = g_graphicsContext.GetVideoResolution();
815 824
   gui.SetRect(0, 0, g_settings.m_ResInfo[res].iWidth, g_settings.m_ResInfo[res].iHeight);
816  
-  display.SetRect(0, 0, g_settings.m_ResInfo[res].iWidth, g_settings.m_ResInfo[res].iHeight);
  825
+  display.SetRect(0, 0, g_settings.m_ResInfo[res].iScreenWidth, g_settings.m_ResInfo[res].iScreenHeight);
817 826
   
818 827
   dst_rect = m_dst_rect;
819 828
   if (gui != display)
820 829
   {
821 830
     float xscale = display.Width()  / gui.Width();
822 831
     float yscale = display.Height() / gui.Height();
  832
+    // video is displayed in absolute coordinates (bypassing half width or height GUI mode)
  833
+    if (m_flags & CONF_FLAGS_FORMAT_SBS) xscale *= 2.0f;
  834
+    if (m_flags & CONF_FLAGS_FORMAT_TB)  yscale *= 2.0f;
823 835
     dst_rect.x1 *= xscale;
824 836
     dst_rect.x2 *= xscale;
825 837
     dst_rect.y1 *= yscale;
826 838
     dst_rect.y2 *= yscale;
827 839
   }
828  
-
829  
-  if(!(m_flags & CONF_FLAGS_FORMAT_SBS) && !(m_flags & CONF_FLAGS_FORMAT_TB))
830  
-    m_omxVideo.SetVideoRect(SrcRect, m_dst_rect);
  840
+  m_omxVideo.SetVideoRect(SrcRect, dst_rect);
831 841
 }
832 842
 
833 843
 void OMXPlayerVideo::RenderUpdateCallBack(const void *ctx, const CRect &SrcRect, const CRect &DestRect)
10  xbmc/cores/omxplayer/OMXVideo.cpp
@@ -940,14 +940,8 @@ void COMXVideo::SetVideoRect(const CRect& SrcRect, const CRect& DestRect)
940 940
     return;
941 941
 
942 942
   OMX_CONFIG_DISPLAYREGIONTYPE configDisplay;
943  
-  OMX_INIT_STRUCTURE(configDisplay);
944  
-  configDisplay.nPortIndex = m_omx_render.GetInputPort();
945  
-  RESOLUTION res = g_graphicsContext.GetVideoResolution();
946  
-  // DestRect is in GUI coordinates, rather than display coordinates, so we have to scale
947  
-  float xscale = (float)g_settings.m_ResInfo[res].iScreenWidth  / (float)g_settings.m_ResInfo[res].iWidth;
948  
-  float yscale = (float)g_settings.m_ResInfo[res].iScreenHeight / (float)g_settings.m_ResInfo[res].iHeight;
949 943
   float sx1 = SrcRect.x1, sy1 = SrcRect.y1, sx2 = SrcRect.x2, sy2 = SrcRect.y2;
950  
-  float dx1 = DestRect.x1*xscale, dy1 = DestRect.y1*yscale, dx2 = DestRect.x2*xscale, dy2 = DestRect.y2*yscale;
  944
+  float dx1 = DestRect.x1, dy1 = DestRect.y1, dx2 = DestRect.x2, dy2 = DestRect.y2;
951 945
   float sw = SrcRect.Width() / DestRect.Width();
952 946
   float sh = SrcRect.Height() / DestRect.Height();
953 947
 
@@ -961,6 +955,8 @@ void COMXVideo::SetVideoRect(const CRect& SrcRect, const CRect& DestRect)
961 955
     dy1 -= dy1;
962 956
   }
963 957
 
  958
+  OMX_INIT_STRUCTURE(configDisplay);
  959
+  configDisplay.nPortIndex = m_omx_render.GetInputPort();
964 960
   configDisplay.fullscreen = OMX_FALSE;
965 961
   configDisplay.noaspect   = OMX_TRUE;
966 962
 
35  xbmc/linux/DllBCM.h
@@ -53,11 +53,12 @@ class DllBcmHostInterface
53 53
   virtual int vc_tv_hdmi_power_on_best_3d(uint32_t width, uint32_t height, uint32_t frame_rate,
54 54
                                        HDMI_INTERLACED_T scan_mode, EDID_MODE_MATCH_FLAG_T match_flags) = 0;
55 55
 
56  
-  virtual int vc_tv_hdmi_get_supported_modes(HDMI_RES_GROUP_T group, TV_SUPPORTED_MODE_T *supported_modes,
  56
+  virtual int vc_tv_hdmi_get_supported_modes_new(HDMI_RES_GROUP_T group, TV_SUPPORTED_MODE_NEW_T *supported_modes,
57 57
                                              uint32_t max_supported_modes, HDMI_RES_GROUP_T *preferred_group,
58 58
                                              uint32_t *preferred_mode) = 0;
59  
-  virtual int vc_tv_hdmi_power_on_explicit(HDMI_MODE_T mode, HDMI_RES_GROUP_T group, uint32_t code) = 0;
60  
-  virtual int vc_tv_get_state(TV_GET_STATE_RESP_T *tvstate) = 0;
  59
+  virtual int vc_tv_hdmi_power_on_explicit_new(HDMI_MODE_T mode, HDMI_RES_GROUP_T group, uint32_t code) = 0;
  60
+  virtual int vc_tv_hdmi_set_property(const HDMI_PROPERTY_PARAM_T *property) = 0;
  61
+  virtual int vc_tv_get_display_state(TV_DISPLAY_STATE_T *tvstate) = 0;
61 62
   virtual int vc_tv_show_info(uint32_t show) = 0;
62 63
   virtual int vc_gencmd(char *response, int maxlen, const char *string) = 0;
63 64
   virtual void vc_tv_register_callback(TVSERVICE_CALLBACK_T callback, void *callback_data) = 0;
@@ -97,14 +98,16 @@ class DllBcmHost : public DllDynamic, DllBcmHostInterface
97 98
   virtual int vc_tv_hdmi_power_on_best_3d(uint32_t width, uint32_t height, uint32_t frame_rate,
98 99
                                        HDMI_INTERLACED_T scan_mode, EDID_MODE_MATCH_FLAG_T match_flags)
99 100
     { return ::vc_tv_hdmi_power_on_best_3d(width, height, frame_rate, scan_mode, match_flags); };
100  
-  virtual int vc_tv_hdmi_get_supported_modes(HDMI_RES_GROUP_T group, TV_SUPPORTED_MODE_T *supported_modes,
  101
+  virtual int vc_tv_hdmi_get_supported_modes_new(HDMI_RES_GROUP_T group, TV_SUPPORTED_MODE_NEW_T *supported_modes,
101 102
                                              uint32_t max_supported_modes, HDMI_RES_GROUP_T *preferred_group,
102 103
                                              uint32_t *preferred_mode)
103  
-    { return ::vc_tv_hdmi_get_supported_modes(group, supported_modes, max_supported_modes, preferred_group, preferred_mode); };
104  
-  virtual int vc_tv_hdmi_power_on_explicit(HDMI_MODE_T mode, HDMI_RES_GROUP_T group, uint32_t code)
105  
-    { return ::vc_tv_hdmi_power_on_explicit(mode, group, code); };
106  
-  virtual int vc_tv_get_state(TV_GET_STATE_RESP_T *tvstate)
107  
-    { return ::vc_tv_get_state(tvstate); };
  104
+    { return ::vc_tv_hdmi_get_supported_modes_new(group, supported_modes, max_supported_modes, preferred_group, preferred_mode); };
  105
+  virtual int vc_tv_hdmi_power_on_explicit_new(HDMI_MODE_T mode, HDMI_RES_GROUP_T group, uint32_t code)
  106
+    { return ::vc_tv_hdmi_power_on_explicit_new(mode, group, code); };
  107
+  virtual int vc_tv_hdmi_set_property(const HDMI_PROPERTY_PARAM_T *property)
  108
+    { return ::vc_tv_hdmi_set_property(property); };
  109
+  virtual int vc_tv_get_display_state(TV_DISPLAY_STATE_T *tvstate)
  110
+    { return ::vc_tv_get_display_state(tvstate); };
108 111
   virtual int vc_tv_show_info(uint32_t show)
109 112
     { return ::vc_tv_show_info(show); };
110 113
   virtual int vc_gencmd(char *response, int maxlen, const char *string)
@@ -162,10 +165,11 @@ class DllBcmHost : public DllDynamic, DllBcmHostInterface
162 165
                                                      HDMI_INTERLACED_T p4, EDID_MODE_MATCH_FLAG_T p5))
163 166
   DEFINE_METHOD5(int,     vc_tv_hdmi_power_on_best_3d, (uint32_t p1, uint32_t p2, uint32_t p3,
164 167
                                                      HDMI_INTERLACED_T p4, EDID_MODE_MATCH_FLAG_T p5))
165  
-  DEFINE_METHOD5(int,     vc_tv_hdmi_get_supported_modes, (HDMI_RES_GROUP_T p1, TV_SUPPORTED_MODE_T *p2,
  168
+  DEFINE_METHOD5(int,     vc_tv_hdmi_get_supported_modes_new, (HDMI_RES_GROUP_T p1, TV_SUPPORTED_MODE_NEW_T *p2,
166 169
                                                            uint32_t p3, HDMI_RES_GROUP_T *p4, uint32_t *p5))
167  
-  DEFINE_METHOD3(int,     vc_tv_hdmi_power_on_explicit, (HDMI_MODE_T p1, HDMI_RES_GROUP_T p2, uint32_t p3))
168  
-  DEFINE_METHOD1(int,     vc_tv_get_state, (TV_GET_STATE_RESP_T *p1))
  170
+  DEFINE_METHOD3(int,     vc_tv_hdmi_power_on_explicit_new, (HDMI_MODE_T p1, HDMI_RES_GROUP_T p2, uint32_t p3))
  171
+  DEFINE_METHOD1(int,     vc_tv_hdmi_set_property, (const HDMI_PROPERTY_PARAM_T *property))
  172
+  DEFINE_METHOD1(int,     vc_tv_get_display_state, (TV_DISPLAY_STATE_T *p1))
169 173
   DEFINE_METHOD1(int,    vc_tv_show_info, (uint32_t p1))
170 174
   DEFINE_METHOD3(int,    vc_gencmd, (char *p1, int p2, const char *p3))
171 175
 
@@ -195,9 +199,10 @@ class DllBcmHost : public DllDynamic, DllBcmHostInterface
195 199
     RESOLVE_METHOD(graphics_get_display_size)
196 200
     RESOLVE_METHOD(vc_tv_hdmi_power_on_best)
197 201
     RESOLVE_METHOD(vc_tv_hdmi_power_on_best_3d)
198  
-    RESOLVE_METHOD(vc_tv_hdmi_get_supported_modes)
199  
-    RESOLVE_METHOD(vc_tv_hdmi_power_on_explicit)
200  
-    RESOLVE_METHOD(vc_tv_get_state)
  202
+    RESOLVE_METHOD(vc_tv_hdmi_get_supported_modes_new)
  203
+    RESOLVE_METHOD(vc_tv_hdmi_power_on_explicit_new)
  204
+    RESOLVE_METHOD(vc_tv_hdmi_set_property)
  205
+    RESOLVE_METHOD(vc_tv_get_display_state)
201 206
     RESOLVE_METHOD(vc_tv_show_info)
202 207
     RESOLVE_METHOD(vc_gencmd)
203 208
     RESOLVE_METHOD(vc_tv_register_callback)
332  xbmc/windowing/egl/EGLNativeTypeRaspberryPI.cpp
@@ -37,19 +37,13 @@
37 37
     m == 38 || m == 43 || m == 45 || m == 49 || m == 51 || \
38 38
     m == 53 || m == 55 || m == 57 || m == 59)
39 39
 
40  
-#define MAKEFLAGS(group, mode, interlace, mode3d) \
  40
+#define MAKEFLAGS(group, mode, interlace) \
41 41
   ( ( (mode)<<24 ) | ( (group)<<16 ) | \
42 42
    ( (interlace) != 0 ? D3DPRESENTFLAG_INTERLACED : D3DPRESENTFLAG_PROGRESSIVE) | \
43  
-   ( ((group) == HDMI_RES_GROUP_CEA && IS_WIDESCREEN(mode) ) ? D3DPRESENTFLAG_WIDESCREEN : 0) | \
44  
-   ( (mode3d) != 0 ? D3DPRESENTFLAG_MODE3DSBS : 0 ))
  43
+   ( ((group) == HDMI_RES_GROUP_CEA && IS_WIDESCREEN(mode) ) ? D3DPRESENTFLAG_WIDESCREEN : 0) )
45 44
 
46  
-#define GETFLAGS_INTERLACE(f)   ( ( (f) & D3DPRESENTFLAG_INTERLACED ) != 0)
47  
-#define GETFLAGS_WIDESCREEN(f)  ( ( (f) & D3DPRESENTFLAG_WIDESCREEN ) != 0)
48 45
 #define GETFLAGS_GROUP(f)       ( (HDMI_RES_GROUP_T)( ((f) >> 16) & 0xff ))
49 46
 #define GETFLAGS_MODE(f)        ( ( (f) >>24 ) & 0xff )
50  
-#define GETFLAGS_MODE3D(f)      ( ( (f) & D3DPRESENTFLAG_MODE3DSBS ) !=0 )
51  
-
52  
-#define TV_MAX_SUPPORTED_MODES 60
53 47
 
54 48
 //#ifndef DEBUG_PRINT
55 49
 //#define DEBUG_PRINT 1
@@ -182,62 +176,86 @@ bool CEGLNativeTypeRaspberryPI::GetNativeResolution(RESOLUTION_INFO *res) const
182 176
 #endif
183 177
 }
184 178
 
185  
-bool CEGLNativeTypeRaspberryPI::SetNativeResolution(const RESOLUTION_INFO &res)
  179
+#if defined(TARGET_RASPBERRY_PI)
  180
+int CEGLNativeTypeRaspberryPI::FindMatchingResolution(const RESOLUTION_INFO &res, const std::vector<RESOLUTION_INFO> &resolutions)
186 181
 {
  182
+  for (int i = 0; i < (int)resolutions.size(); i++)
  183
+  {
  184
+    if(resolutions[i].iScreenWidth == res.iScreenWidth && resolutions[i].iScreenHeight == res.iScreenHeight && resolutions[i].fRefreshRate == res.fRefreshRate)
  185
+    {
  186
+       return i;
  187
+    }
  188
+  }
  189
+  return -1;
  190
+}
  191
+#endif
  192
+
187 193
 #if defined(TARGET_RASPBERRY_PI)
188  
-  bool bFound = false;
  194
+int CEGLNativeTypeRaspberryPI::AddUniqueResolution(const RESOLUTION_INFO &res, std::vector<RESOLUTION_INFO> &resolutions)
  195
+{
  196
+  int i = FindMatchingResolution(res, resolutions);
  197
+  if (i>=0)
  198
+  {  // don't replace a progressive resolution with an interlaced one of same resolution
  199
+     if (!(res.dwFlags & D3DPRESENTFLAG_INTERLACED))
  200
+       resolutions[i] = res;
  201
+  }
  202
+  else
  203
+  {
  204
+     resolutions.push_back(res);
  205
+  }
  206
+  return i;
  207
+}
  208
+#endif
189 209
 
  210
+bool CEGLNativeTypeRaspberryPI::SetNativeResolution(const RESOLUTION_INFO &res)
  211
+{
  212
+#if defined(TARGET_RASPBERRY_PI)
190 213
   if(!m_DllBcmHost || !m_nativeWindow)
191 214
     return false;
192 215
 
193 216
   DestroyDispmaxWindow();
194 217
 
195  
-  RESOLUTION_INFO resSearch;
196  
-
197  
-  int best_score = 0;
198  
-
199  
-  for (size_t i = 0; i < m_res.size(); i++)
200  
-  {
201  
-    if(m_res[i].iScreenWidth == res.iScreenWidth && m_res[i].iScreenHeight == res.iScreenHeight && m_res[i].fRefreshRate == res.fRefreshRate)
202  
-    {
203  
-      int score = 0;
204  
-
205  
-      /* prefere progressive over interlaced */
206  
-      if(!GETFLAGS_INTERLACE(m_res[i].dwFlags))
207  
-        score = 1;
208  
-
209  
-      if(score >= best_score)
210  
-      {
211  
-        resSearch = m_res[i];
212  
-        bFound = true;
213  
-      }
214  
-    }
215  
-  }
216  
-
217  
-  if(bFound && !m_fixedMode)
  218
+  if(!m_fixedMode && GETFLAGS_GROUP(res.dwFlags) && GETFLAGS_MODE(res.dwFlags))
218 219
   {
219 220
     sem_init(&m_tv_synced, 0, 0);
220 221
     m_DllBcmHost->vc_tv_register_callback(CallbackTvServiceCallback, this);
221 222
 
222  
-    int success = m_DllBcmHost->vc_tv_hdmi_power_on_explicit(HDMI_MODE_HDMI, GETFLAGS_GROUP(resSearch.dwFlags), GETFLAGS_MODE(resSearch.dwFlags));
  223
+    if (res.dwFlags & (D3DPRESENTFLAG_MODE3DSBS|D3DPRESENTFLAG_MODE3DTB))
  224
+    {
  225
+      /* inform TV of any 3D settings. Note this property just applies to next hdmi mode change, so no need to call for 2D modes */
  226
+      HDMI_PROPERTY_PARAM_T property;
  227
+      property.property = HDMI_PROPERTY_3D_STRUCTURE;
  228
+      if (res.dwFlags & D3DPRESENTFLAG_MODE3DSBS)
  229
+        property.param1 = HDMI_3D_FORMAT_SBS_HALF;
  230
+      else if (res.dwFlags & D3DPRESENTFLAG_MODE3DTB)
  231
+        property.param1 = HDMI_3D_FORMAT_TB_HALF;
  232
+      else
  233
+        property.param1 = HDMI_3D_FORMAT_NONE;
  234
+      property.param2 = 0;
  235
+      vc_tv_hdmi_set_property(&property);
  236
+    }
  237
+    int success = m_DllBcmHost->vc_tv_hdmi_power_on_explicit_new(HDMI_MODE_HDMI, GETFLAGS_GROUP(res.dwFlags), GETFLAGS_MODE(res.dwFlags));
223 238
 
224 239
     if (success == 0)
225 240
     {
226  
-      CLog::Log(LOGDEBUG, "EGL set HDMI mode (%d,%d,%d)=%d\n",
227  
-                          GETFLAGS_MODE3D(resSearch.dwFlags) ? HDMI_MODE_3D:HDMI_MODE_HDMI, GETFLAGS_GROUP(resSearch.dwFlags),
228  
-                          GETFLAGS_MODE(resSearch.dwFlags), success);
  241
+      CLog::Log(LOGDEBUG, "EGL set HDMI mode (%d,%d)=%d%s%s\n",
  242
+                          GETFLAGS_GROUP(res.dwFlags), GETFLAGS_MODE(res.dwFlags), success,
  243
+                          (res.dwFlags & D3DPRESENTFLAG_MODE3DSBS) ? " SBS":"",
  244
+                          (res.dwFlags & D3DPRESENTFLAG_MODE3DTB) ? " TB":"");
  245
+
229 246
       sem_wait(&m_tv_synced);
230 247
     }
231 248
     else
232 249
     {
233  
-      CLog::Log(LOGERROR, "EGL failed to set HDMI mode (%d,%d,%d)=%d\n",
234  
-                          GETFLAGS_MODE3D(resSearch.dwFlags) ? HDMI_MODE_3D:HDMI_MODE_HDMI, GETFLAGS_GROUP(resSearch.dwFlags),
235  
-                          GETFLAGS_MODE(resSearch.dwFlags), success);
  250
+      CLog::Log(LOGERROR, "EGL failed to set HDMI mode (%d,%d)=%d%s%s\n",
  251
+                          GETFLAGS_GROUP(res.dwFlags), GETFLAGS_MODE(res.dwFlags), success,
  252
+                          (res.dwFlags & D3DPRESENTFLAG_MODE3DSBS) ? " SBS":"",
  253
+                          (res.dwFlags & D3DPRESENTFLAG_MODE3DTB) ? " TB":"");
236 254
     }
237 255
     m_DllBcmHost->vc_tv_unregister_callback(CallbackTvServiceCallback);
238 256
     sem_destroy(&m_tv_synced);
239 257
 
240  
-    m_desktopRes = resSearch;
  258
+    m_desktopRes = res;
241 259
   }
242 260
 
243 261
   m_dispman_display = m_DllBcmHost->vc_dispmanx_display_open(0);
@@ -268,16 +286,23 @@ bool CEGLNativeTypeRaspberryPI::SetNativeResolution(const RESOLUTION_INFO &res)
268 286
   DISPMANX_TRANSFORM_T transform = DISPMANX_NO_ROTATE;
269 287
   DISPMANX_UPDATE_HANDLE_T dispman_update = m_DllBcmHost->vc_dispmanx_update_start(0);
270 288
 
271  
-  CLog::Log(LOGDEBUG, "EGL set resolution %dx%d -> %dx%d @ %.2f fps\n",
272  
-      m_width, m_height, dst_rect.width, dst_rect.height, bFound ? resSearch.fRefreshRate : res.fRefreshRate);
  289
+  CLog::Log(LOGDEBUG, "EGL set resolution %dx%d -> %dx%d @ %.2f fps (%d,%d) flags:%x aspect:%.2f\n",
  290
+      m_width, m_height, dst_rect.width, dst_rect.height, res.fRefreshRate, GETFLAGS_GROUP(res.dwFlags), GETFLAGS_MODE(res.dwFlags), (int)res.dwFlags, res.fPixelRatio);
273 291
 
274 292
   // The trick for SBS is that we stick two dispman elements together 
275  
-  // and the PI firmware knows that we are in SBS mode and it renders the gui in SBS
276  
-  if(bFound && (resSearch.dwFlags & D3DPRESENTFLAG_MODE3DSBS))
  293
+  // and the PI firmware knows that we are in SBS/TAB mode and it renders the gui in SBS/TAB
  294
+  if(res.dwFlags & (D3DPRESENTFLAG_MODE3DSBS|D3DPRESENTFLAG_MODE3DTB))
277 295
   {
278  
-    // right side
279  
-    dst_rect.x = res.iScreenWidth;
280  
-    dst_rect.width = res.iScreenWidth;
  296
+    if (res.dwFlags & D3DPRESENTFLAG_MODE3DTB)
  297
+    {
  298
+      // bottom half
  299
+      dst_rect.y = res.iScreenHeight;
  300
+    }
  301
+    else
  302
+    {
  303
+      // right side
  304
+      dst_rect.x = res.iScreenWidth;
  305
+    }
281 306
 
282 307
     m_dispman_element2 = m_DllBcmHost->vc_dispmanx_element_add(dispman_update,
283 308
       m_dispman_display,
@@ -292,9 +317,16 @@ bool CEGLNativeTypeRaspberryPI::SetNativeResolution(const RESOLUTION_INFO &res)
292 317
       assert(m_dispman_element2 != DISPMANX_NO_HANDLE);
293 318
       assert(m_dispman_element2 != (unsigned)DISPMANX_INVALID);
294 319
 
295  
-    // left side - fall through
296  
-    dst_rect.x = 0;
297  
-    dst_rect.width = res.iScreenWidth;
  320
+    if (res.dwFlags & D3DPRESENTFLAG_MODE3DTB)
  321
+    {
  322
+      // top half - fall through
  323
+      dst_rect.y = 0;
  324
+    }
  325
+    else
  326
+    {
  327
+      // left side - fall through
  328
+      dst_rect.x = 0;
  329
+    }
298 330
   }
299 331
 
300 332
   m_dispman_element = m_DllBcmHost->vc_dispmanx_element_add(dispman_update,
@@ -330,11 +362,38 @@ bool CEGLNativeTypeRaspberryPI::SetNativeResolution(const RESOLUTION_INFO &res)
330 362
 #endif
331 363
 }
332 364
 
  365
+static float get_display_aspect_ratio(HDMI_ASPECT_T aspect)
  366
+{
  367
+  float display_aspect;
  368
+  switch (aspect) {
  369
+    case HDMI_ASPECT_4_3:   display_aspect = 4.0/3.0;   break;
  370
+    case HDMI_ASPECT_14_9:  display_aspect = 14.0/9.0;  break;
  371
+    case HDMI_ASPECT_16_9:  display_aspect = 16.0/9.0;  break;
  372
+    case HDMI_ASPECT_5_4:   display_aspect = 5.0/4.0;   break;
  373
+    case HDMI_ASPECT_16_10: display_aspect = 16.0/10.0; break;
  374
+    case HDMI_ASPECT_15_9:  display_aspect = 15.0/9.0;  break;
  375
+    case HDMI_ASPECT_64_27: display_aspect = 64.0/27.0; break;
  376
+    default:                display_aspect = 16.0/9.0;  break;
  377
+  }
  378
+  return display_aspect;
  379
+}
  380
+
  381
+static float get_display_aspect_ratio(SDTV_ASPECT_T aspect)
  382
+{
  383
+  float display_aspect;
  384
+  switch (aspect) {
  385
+    case SDTV_ASPECT_4_3:  display_aspect = 4.0/3.0;  break;
  386
+    case SDTV_ASPECT_14_9: display_aspect = 14.0/9.0; break;
  387
+    case SDTV_ASPECT_16_9: display_aspect = 16.0/9.0; break;
  388
+    default:               display_aspect = 4.0/3.0;  break;
  389
+  }
  390
+  return display_aspect;
  391
+}
  392
+
333 393
 bool CEGLNativeTypeRaspberryPI::ProbeResolutions(std::vector<RESOLUTION_INFO> &resolutions)
334 394
 {
335 395
 #if defined(TARGET_RASPBERRY_PI)
336 396
   resolutions.clear();
337  
-  m_res.clear();
338 397
 
339 398
   if(!m_DllBcmHost)
340 399
     return false;
@@ -349,25 +408,56 @@ bool CEGLNativeTypeRaspberryPI::ProbeResolutions(std::vector<RESOLUTION_INFO> &r
349 408
 
350 409
   if(m_initDesktopRes)
351 410
   {
352  
-    TV_GET_STATE_RESP_T tv_state;
  411
+    TV_DISPLAY_STATE_T tv_state;
353 412
 
354 413
     // get current display settings state
355  
-    memset(&tv_state, 0, sizeof(TV_GET_STATE_RESP_T));
356  
-    m_DllBcmHost->vc_tv_get_state(&tv_state);
357  
-
358  
-    m_desktopRes.iScreen      = 0;
359  
-    m_desktopRes.bFullScreen  = true;
360  
-    m_desktopRes.iWidth       = tv_state.width;
361  
-    m_desktopRes.iHeight      = tv_state.height;
362  
-    m_desktopRes.iScreenWidth = tv_state.width;
363  
-    m_desktopRes.iScreenHeight= tv_state.height;
364  
-    m_desktopRes.dwFlags      = tv_state.scan_mode ? D3DPRESENTFLAG_INTERLACED : D3DPRESENTFLAG_PROGRESSIVE;
365  
-    m_desktopRes.fRefreshRate = (float)tv_state.frame_rate;
366  
-    m_desktopRes.strMode.Format("%dx%d", tv_state.width, tv_state.height);
367  
-    if((float)tv_state.frame_rate > 1)
  414
+    memset(&tv_state, 0, sizeof(TV_DISPLAY_STATE_T));
  415
+    m_DllBcmHost->vc_tv_get_display_state(&tv_state);
  416
+
  417
+    if ((tv_state.state & ( VC_HDMI_HDMI | VC_HDMI_DVI )) != 0) // hdtv
  418
+    {
  419
+      m_desktopRes.iScreen      = 0;
  420
+      m_desktopRes.bFullScreen  = true;
  421
+      m_desktopRes.iWidth       = tv_state.display.hdmi.width;
  422
+      m_desktopRes.iHeight      = tv_state.display.hdmi.height;
  423
+      m_desktopRes.iScreenWidth = tv_state.display.hdmi.width;
  424
+      m_desktopRes.iScreenHeight= tv_state.display.hdmi.height;
  425
+      m_desktopRes.dwFlags      = MAKEFLAGS(tv_state.display.hdmi.group, tv_state.display.hdmi.mode, tv_state.display.hdmi.scan_mode);
  426
+      // Also add 3D flags
  427
+      if (tv_state.display.hdmi.format_3d == HDMI_3D_FORMAT_SBS_HALF)
  428
+      {
  429
+        m_desktopRes.dwFlags |= D3DPRESENTFLAG_MODE3DSBS;
  430
+        m_desktopRes.iWidth       >>= 1;
  431
+        m_desktopRes.iScreenWidth >>= 1;
  432
+      }
  433
+      else if (tv_state.display.hdmi.format_3d == HDMI_3D_FORMAT_TB_HALF)
  434
+      {
  435
+        m_desktopRes.dwFlags |= D3DPRESENTFLAG_MODE3DTB;
  436
+        m_desktopRes.iHeight       >>= 1;
  437
+        m_desktopRes.iScreenHeight >>= 1;
  438
+      }
  439
+      m_desktopRes.fRefreshRate = (float)tv_state.display.hdmi.frame_rate;
  440
+      m_desktopRes.fPixelRatio  = get_display_aspect_ratio((HDMI_ASPECT_T)tv_state.display.hdmi.display_options.aspect) / ((float)m_desktopRes.iScreenWidth / (float)m_desktopRes.iScreenHeight);
  441
+    }
  442
+    else // sdtv
  443
+    {
  444
+      m_desktopRes.iScreen      = 0;
  445
+      m_desktopRes.bFullScreen  = true;
  446
+      m_desktopRes.iWidth       = tv_state.display.sdtv.width;
  447
+      m_desktopRes.iHeight      = tv_state.display.sdtv.height;
  448
+      m_desktopRes.iScreenWidth = tv_state.display.sdtv.width;
  449
+      m_desktopRes.iScreenHeight= tv_state.display.sdtv.height;
  450
+      m_desktopRes.dwFlags      = D3DPRESENTFLAG_INTERLACED;
  451
+      m_desktopRes.fRefreshRate = (float)tv_state.display.sdtv.frame_rate;
  452
+      m_desktopRes.fPixelRatio  = get_display_aspect_ratio((SDTV_ASPECT_T)tv_state.display.sdtv.display_options.aspect) / ((float)m_desktopRes.iScreenWidth / (float)m_desktopRes.iScreenHeight);
  453
+    }
  454
+
  455
+    m_desktopRes.strMode.Format("%dx%d", m_desktopRes.iScreenWidth, m_desktopRes.iScreenHeight);
  456
+
  457
+    if((int)m_desktopRes.fRefreshRate > 1)
368 458
     {
369  
-        m_desktopRes.strMode.Format("%s @ %.2f%s - Full Screen", m_desktopRes.strMode, (float)tv_state.frame_rate,
370  
-            m_desktopRes.dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "");
  459
+      m_desktopRes.strMode.Format("%dx%d @ %.2f%s - Full Screen", m_desktopRes.iScreenWidth, m_desktopRes.iScreenHeight, m_desktopRes.fRefreshRate,
  460
+        m_desktopRes.dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "");
371 461
     }
372 462
     m_initDesktopRes = false;
373 463
 
@@ -381,26 +471,18 @@ bool CEGLNativeTypeRaspberryPI::ProbeResolutions(std::vector<RESOLUTION_INFO> &r
381 471
 
382 472
     m_desktopRes.iSubtitles   = (int)(0.965 * m_desktopRes.iHeight);
383 473
 
384  
-    CLog::Log(LOGDEBUG, "EGL initial desktop resolution %s\n", m_desktopRes.strMode.c_str());
  474
+    CLog::Log(LOGDEBUG, "EGL initial desktop resolution %s (%.2f)\n", m_desktopRes.strMode.c_str(), m_desktopRes.fPixelRatio);
385 475
   }
386 476
 
387  
-
388 477
   GetSupportedModes(HDMI_RES_GROUP_CEA, resolutions);
389 478
   GetSupportedModes(HDMI_RES_GROUP_DMT, resolutions);
390  
-  GetSupportedModes(HDMI_RES_GROUP_CEA_3D, resolutions);
391 479
 
392 480
   if(resolutions.size() == 0)
393 481
   {
394  
-    TV_GET_STATE_RESP_T tv;
395  
-    m_DllBcmHost->vc_tv_get_state(&tv);
396  
-
397 482
     RESOLUTION_INFO res;
398  
-    CLog::Log(LOGDEBUG, "EGL probe resolution %dx%d@%f %s:%x\n",
399  
-        m_desktopRes.iWidth, m_desktopRes.iHeight, m_desktopRes.fRefreshRate,
400  
-        m_desktopRes.dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "p");
  483
+    CLog::Log(LOGDEBUG, "EGL probe resolution %s:%x\n", m_desktopRes.strMode.c_str(), m_desktopRes.dwFlags);
401 484
 
402  
-    m_res.push_back(m_desktopRes);
403  
-    resolutions.push_back(m_desktopRes);
  485
+    AddUniqueResolution(m_desktopRes, resolutions);
404 486
   }
405 487
 
406 488
   if(resolutions.size() < 2)
@@ -458,45 +540,43 @@ void CEGLNativeTypeRaspberryPI::GetSupportedModes(HDMI_RES_GROUP_T group, std::v
458 540
   if(!m_DllBcmHost)
459 541
     return;
460 542
 
461  
-  //Supported HDMI CEA/DMT resolutions, first one will be preferred resolution
462  
-  TV_SUPPORTED_MODE_T supported_modes[TV_MAX_SUPPORTED_MODES];
463  
-  int32_t num_modes;
  543
+  //Supported HDMI CEA/DMT resolutions, preferred resolution will be returned
  544
+  int32_t num_modes = 0;
464 545
   HDMI_RES_GROUP_T prefer_group;
465 546
   uint32_t prefer_mode;
466 547
   int i;
  548
+  TV_SUPPORTED_MODE_NEW_T *supported_modes = NULL;
  549
+  // query the number of modes first
  550
+  int max_supported_modes = m_DllBcmHost->vc_tv_hdmi_get_supported_modes_new(group, NULL, 0, &prefer_group, &prefer_mode);
467 551
 
468  
-  num_modes = m_DllBcmHost->vc_tv_hdmi_get_supported_modes(group,
469  
-      supported_modes, TV_MAX_SUPPORTED_MODES, &prefer_group, &prefer_mode);
  552
+  if (max_supported_modes > 0)
  553
+    supported_modes = new TV_SUPPORTED_MODE_NEW_T[max_supported_modes];
470 554
 
471  
-  CLog::Log(LOGDEBUG, "EGL get supported modes (%d) = %d, prefer_group=%x, prefer_mode=%x\n",
472  
-      group, num_modes, prefer_group, prefer_mode);
  555
+  if (supported_modes)
  556
+  {
  557
+    num_modes = m_DllBcmHost->vc_tv_hdmi_get_supported_modes_new(group,
  558
+        supported_modes, max_supported_modes, &prefer_group, &prefer_mode);
  559
+
  560
+    CLog::Log(LOGDEBUG, "EGL get supported modes (%d) = %d, prefer_group=%x, prefer_mode=%x\n",
  561
+        group, num_modes, prefer_group, prefer_mode);
  562
+  }
473 563
 
474 564
   if (num_modes > 0 && prefer_group != HDMI_RES_GROUP_INVALID)
475 565
   {
476  
-    TV_SUPPORTED_MODE_T *tv = supported_modes;
  566
+    TV_SUPPORTED_MODE_NEW_T *tv = supported_modes;
477 567
     for (i=0; i < num_modes; i++, tv++)
478 568
     {
479  
-      // treat 3D modes as half-width SBS
480  
-      unsigned int width = (group == HDMI_RES_GROUP_CEA_3D) ? tv->width>>1 : tv->width;
481 569
       RESOLUTION_INFO res;
482  
-      CLog::Log(LOGDEBUG, "EGL mode %d: %dx%d@%d %s%s:%x\n", i, width, tv->height, tv->frame_rate,
483  
-          tv->native ? "N" : "", tv->scan_mode ? "I" : "", tv->code);
484 570
 
485 571
       res.iScreen       = 0;
486 572
       res.bFullScreen   = true;
487  
-      res.dwFlags       = MAKEFLAGS(group, tv->code, tv->scan_mode, group==HDMI_RES_GROUP_CEA_3D);
  573
+      res.dwFlags       = MAKEFLAGS(group, tv->code, tv->scan_mode);
488 574
       res.fRefreshRate  = (float)tv->frame_rate;
489  
-      res.fPixelRatio   = 1.0f;
490  
-      res.iWidth        = width;
  575
+      res.iWidth        = tv->width;
491 576
       res.iHeight       = tv->height;
492  
-      res.iScreenWidth  = width;
  577
+      res.iScreenWidth  = tv->width;
493 578
       res.iScreenHeight = tv->height;
494  
-      res.strMode.Format("%dx%d", width, tv->height);
495  
-      if((float)tv->frame_rate > 1)
496  
-      {
497  
-        res.strMode.Format("%dx%d @ %.2f%s - Full Screen", res.iScreenWidth, res.iScreenHeight, res.fRefreshRate,
498  
-          res.dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "");
499  
-      }
  579
+      res.fPixelRatio   = get_display_aspect_ratio((HDMI_ASPECT_T)tv->aspect_ratio) / ((float)res.iScreenWidth / (float)res.iScreenHeight);
500 580
 
501 581
       int gui_width  = res.iWidth;
502 582
       int gui_height = res.iHeight;
@@ -506,23 +586,53 @@ void CEGLNativeTypeRaspberryPI::GetSupportedModes(HDMI_RES_GROUP_T group, std::v
506 586
       res.iWidth = gui_width;
507 587
       res.iHeight = gui_height;
508 588
 
  589
+      res.strMode.Format("%dx%d @ %.2f%s - Full Screen", res.iScreenWidth, res.iScreenHeight, res.fRefreshRate,
  590
+        res.dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "");
  591
+
  592
+      CLog::Log(LOGDEBUG, "EGL mode %d: %s (%.2f) %s%s:%x\n", i, res.strMode.c_str(), res.fPixelRatio,
  593
+          tv->native ? "N" : "", tv->scan_mode ? "I" : "", tv->code);
  594
+
509 595
       res.iSubtitles    = (int)(0.965 * res.iHeight);
510 596
 
511  
-      resolutions.push_back(res);
  597
+      AddUniqueResolution(res, resolutions);
512 598
 
513  
-      /* replace initial desktop resolution with probed hdmi resolution */
514  
-      if(m_desktopRes.iWidth == res.iWidth && m_desktopRes.iHeight == res.iHeight &&
515  
-          m_desktopRes.iScreenWidth == res.iScreenWidth && m_desktopRes.iScreenHeight == res.iScreenHeight &&
516  
-          m_desktopRes.fRefreshRate == res.fRefreshRate)
  599
+      // Also add 3D versions of modes
  600
+      if (tv->struct_3d_mask & HDMI_3D_STRUCT_SIDE_BY_SIDE_HALF_HORIZONTAL)
517 601
       {
518  
-        m_desktopRes = res;
519  
-        CLog::Log(LOGDEBUG, "EGL desktop replacement resolution %dx%d@%d %s%s:%x\n",
520  
-            width, tv->height, tv->frame_rate, tv->native ? "N" : "", tv->scan_mode ? "I" : "", tv->code);
  602
+        RESOLUTION_INFO res2 = res;
  603
+        res2.dwFlags |= D3DPRESENTFLAG_MODE3DSBS;
  604
+        res2.iWidth       >>= 1;
  605
+        res2.iScreenWidth >>= 1;
  606
+        res2.fPixelRatio    = get_display_aspect_ratio((HDMI_ASPECT_T)tv->aspect_ratio) / ((float)res2.iScreenWidth / (float)res2.iScreenHeight);
  607
+        res2.strMode.Format("%dx%d", res2.iScreenWidth, res2.iScreenHeight);
  608
+        res2.strMode.Format("%dx%d @ %.2f%s - Full Screen", res2.iScreenWidth, res2.iScreenHeight, res2.fRefreshRate,
  609
+            res2.dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "");
  610
+        CLog::Log(LOGDEBUG, "EGL mode %d: %s (%.2f) SBS\n", i, res2.strMode.c_str(), res2.fPixelRatio);
  611
+
  612
+        res2.iSubtitles    = (int)(0.965 * res2.iHeight);
  613
+
  614
+        AddUniqueResolution(res2, resolutions);
  615
+      }
  616
+      if (tv->struct_3d_mask & HDMI_3D_STRUCT_TOP_AND_BOTTOM)
  617
+      {
  618
+        RESOLUTION_INFO res2 = res;
  619
+        res2.dwFlags |= D3DPRESENTFLAG_MODE3DTB;
  620
+        res2.iHeight       >>= 1;
  621
+        res2.iScreenHeight >>= 1;
  622
+        res2.fPixelRatio    = get_display_aspect_ratio((HDMI_ASPECT_T)tv->aspect_ratio) / ((float)res2.iScreenWidth / (float)res2.iScreenHeight);
  623
+        res2.strMode.Format("%dx%d", res2.iScreenWidth, res2.iScreenHeight);
  624
+        res2.strMode.Format("%dx%d @ %.2f%s - Full Screen", res2.iScreenWidth, res2.iScreenHeight, res2.fRefreshRate,
  625
+            res2.dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "");
  626
+        CLog::Log(LOGDEBUG, "EGL mode %d: %s (%.2f) TAB\n", i, res2.strMode.c_str(), res2.fPixelRatio);
  627
+
  628
+        res2.iSubtitles    = (int)(0.965 * res2.iHeight);
  629
+
  630
+        AddUniqueResolution(res2, resolutions);
521 631
       }
522  
-
523  
-      m_res.push_back(res);
524 632
     }
525 633
   }
  634
+  if (supported_modes)
  635
+    delete supported_modes;
526 636
 }
527 637
 
528 638
 void CEGLNativeTypeRaspberryPI::TvServiceCallback(uint32_t reason, uint32_t param1, uint32_t param2)
3  xbmc/windowing/egl/EGLNativeTypeRaspberryPI.h
@@ -61,7 +61,6 @@ class CEGLNativeTypeRaspberryPI : public CEGLNativeType
61 61
   TV_GET_STATE_RESP_T           m_tv_state;
62 62
   sem_t                         m_tv_synced;
63 63
   bool                          m_fixedMode;
64  
-  std::vector<RESOLUTION_INFO>  m_res;
65 64
   RESOLUTION_INFO               m_desktopRes;
66 65
   int                           m_width;
67 66
   int                           m_height;
@@ -73,5 +72,7 @@ class CEGLNativeTypeRaspberryPI : public CEGLNativeType
73 72
 
74 73
   void DestroyDispmaxWindow();
75 74
   bool ClampToGUIDisplayLimits(int &width, int &height);
  75
+  int FindMatchingResolution(const RESOLUTION_INFO &res, const std::vector<RESOLUTION_INFO> &resolutions);
  76
+  int AddUniqueResolution(const RESOLUTION_INFO &res, std::vector<RESOLUTION_INFO> &resolutions);
76 77
 #endif
77 78
 };
57  xbmc/windowing/egl/WinSystemEGL.cpp
@@ -24,6 +24,7 @@
24 24
 #include "WinSystemEGL.h"
25 25
 #include "filesystem/SpecialProtocol.h"
26 26
 #include "settings/Settings.h"
  27
+#include "settings/GUISettings.h"
27 28
 #include "utils/log.h"
28 29
 #include "EGLWrapper.h"
29 30
 #include "EGLQuirks.h"
@@ -437,33 +438,51 @@ EGLContext CWinSystemEGL::GetEGLContext()
437 438
   return m_context;
438 439
 }
439 440
 
  441
+// the logic in this function should match whether CBaseRenderer::FindClosestResolution picks a 3D mode
440 442
 bool CWinSystemEGL::Support3D(int width, int height, uint32_t mode) const
441 443
 {
442  
-  bool bFound = false;
443  
-  int searchMode = 0;
444  
-  int searchWidth = width;
445  
-  int searchHeight = height;
  444
+  RESOLUTION_INFO &curr = g_settings.m_ResInfo[g_graphicsContext.GetVideoResolution()];
446 445
 
447  
-  if (mode & D3DPRESENTFLAG_MODE3DSBS)
  446
+  // if we are using automatic hdmi mode switching
  447
+  if (g_guiSettings.GetInt("videoplayer.adjustrefreshrate") != ADJUST_REFRESHRATE_OFF)
448 448
   {
449  
-    searchWidth /= 2;
450  
-    searchMode = D3DPRESENTFLAG_MODE3DSBS;
451  
-  }
452  
-  else if (mode & D3DPRESENTFLAG_MODE3DTB)
453  
-  {
454  
-    searchHeight /= 2;
455  
-    searchMode = D3DPRESENTFLAG_MODE3DTB;
456  
-  }
  449
+    int searchWidth = curr.iScreenWidth;
  450
+    int searchHeight = curr.iScreenHeight;
457 451
 
458  
-  for (unsigned int i = 0; i < g_settings.m_ResInfo.size(); i++)
  452
+    // work out current non-3D resolution (in case we are currently in 3D mode)
  453
+    if (curr.dwFlags & D3DPRESENTFLAG_MODE3DSBS)
  454
+    {
  455
+      searchWidth *= 2;
  456
+    }
  457
+    else if (curr.dwFlags & D3DPRESENTFLAG_MODE3DTB)
  458
+    {
  459
+      searchHeight *= 2;
  460
+    }
  461
+    // work out resolution if we switch to 3D mode
  462
+    if (mode & D3DPRESENTFLAG_MODE3DSBS)
  463
+    {
  464
+      searchWidth /= 2;
  465
+    }
  466
+    else if (mode & D3DPRESENTFLAG_MODE3DTB)
  467
+    {
  468
+      searchHeight /= 2;
  469
+    }
  470
+    // only search the custom resolutions
  471
+    for (unsigned int i = (int)RES_DESKTOP; i < g_settings.m_ResInfo.size(); i++)
  472
+    {
  473
+      RESOLUTION_INFO res = g_settings.m_ResInfo[i];
  474
+      if(res.iScreenWidth == searchWidth && res.iScreenHeight == searchHeight && (res.dwFlags & mode))
  475
+        return true;
  476
+    }
  477
+  }
  478
+  // otherwise just consider current mode
  479
+  else
459 480
   {
460  
-    RESOLUTION_INFO res = g_settings.m_ResInfo[i];
461  
-
462  
-    if(res.iWidth == searchWidth && res.iHeight == searchHeight && (res.dwFlags & searchMode))
463  
-      return true;
  481
+     if (curr.dwFlags & mode)
  482
+       return true;
464 483
   }
465 484
 
466  
-  return bFound;
  485
+  return false;
467 486
 }
468 487
 
469 488
 bool CWinSystemEGL::ClampToGUIDisplayLimits(int &width, int &height)

0 notes on commit 1f8d725

Please sign in to comment.
Something went wrong with that request. Please try again.