00001 #include "compat.h"
00002 #include "mythdisplay.h"
00003 #include "mythmainwindow.h"
00004
00005 #if defined(Q_WS_MAC)
00006 #import "util-osx.h"
00007 #elif USING_X11
00008 #include "mythxdisplay.h"
00009 #endif
00010
00011 #if !USING_X11
00012 #include <QApplication>
00013 #include <QDesktopWidget>
00014 #endif
00015
00016 #define VALID_RATE(rate) (rate > 20.0 && rate < 200.0)
00017
00018 static float fix_rate(int video_rate)
00019 {
00020 static const float default_rate = 1000000.0 / 60.0;
00021 float fixed = default_rate;
00022 if (video_rate > 0)
00023 {
00024 fixed = video_rate / 2;
00025 if (fixed < default_rate)
00026 fixed = default_rate;
00027 }
00028 return fixed;
00029 }
00030
00031 WId MythDisplay::GetWindowID(void)
00032 {
00033 WId win = 0;
00034 QWidget *main_widget = (QWidget*)MythMainWindow::getMainWindow();
00035 if (main_widget)
00036 win = main_widget->winId();
00037 return win;
00038 }
00039
00040 DisplayInfo MythDisplay::GetDisplayInfo(int video_rate)
00041 {
00042 DisplayInfo ret;
00043
00044 #if defined(Q_WS_MAC)
00045 CGDirectDisplayID disp = GetOSXDisplay(GetWindowID());
00046 if (!disp)
00047 return ret;
00048
00049 CFDictionaryRef ref = CGDisplayCurrentMode(disp);
00050 float rate = 0.0f;
00051 if (ref)
00052 rate = get_float_CF(ref, kCGDisplayRefreshRate);
00053
00054 if (VALID_RATE(rate))
00055 ret.rate = 1000000.0f / rate;
00056 else
00057 ret.rate = fix_rate(video_rate);
00058
00059 CGSize size_in_mm = CGDisplayScreenSize(disp);
00060 ret.size = QSize((uint) size_in_mm.width, (uint) size_in_mm.height);
00061
00062 uint width = (uint)CGDisplayPixelsWide(disp);
00063 uint height = (uint)CGDisplayPixelsHigh(disp);
00064 ret.res = QSize(width, height);
00065
00066 #elif defined(Q_WS_WIN)
00067 HDC hdc = GetDC(GetWindowID());
00068 int rate = 0;
00069 if (hdc)
00070 {
00071 rate = GetDeviceCaps(hdc, VREFRESH);
00072 int width = GetDeviceCaps(hdc, HORZSIZE);
00073 int height = GetDeviceCaps(hdc, VERTSIZE);
00074 ret.size = QSize((uint)width, (uint)height);
00075 width = GetDeviceCaps(hdc, HORZRES);
00076 height = GetDeviceCaps(hdc, VERTRES);
00077 ret.res = QSize((uint)width, (uint)height);
00078 }
00079
00080 if (VALID_RATE(rate))
00081 {
00082
00083 switch (rate)
00084 {
00085 case 23: ret.rate = 41708; break;
00086 case 29: ret.rate = 33367; break;
00087 case 47: ret.rate = 20854; break;
00088 case 59: ret.rate = 16683; break;
00089 case 71: ret.rate = 13903; break;
00090 case 119: ret.rate = 8342; break;
00091 default: ret.rate = 1000000.0f / (float)rate;
00092 }
00093 }
00094 else
00095 ret.rate = fix_rate(video_rate);
00096
00097 #elif USING_X11
00098 MythXDisplay *disp = OpenMythXDisplay();
00099 if (!disp)
00100 return ret;
00101
00102 float rate = disp->GetRefreshRate();
00103 if (VALID_RATE(rate))
00104 ret.rate = 1000000.0f / rate;
00105 else
00106 ret.rate = fix_rate(video_rate);
00107 ret.res = disp->GetDisplaySize();
00108 ret.size = disp->GetDisplayDimensions();
00109 delete disp;
00110 #endif
00111 return ret;
00112 }
00113
00114 int MythDisplay::GetNumberXineramaScreens(void)
00115 {
00116 int nr_xinerama_screens = 0;
00117
00118 #if USING_X11
00119
00120 MythXDisplay *d = OpenMythXDisplay();
00121 if (d)
00122 {
00123 nr_xinerama_screens = d->GetNumberXineramaScreens();
00124 delete d;
00125 }
00126 #else
00127
00128 if (QApplication::desktop())
00129 nr_xinerama_screens = QApplication::desktop()->numScreens();
00130 #endif
00131
00132 return nr_xinerama_screens;
00133 }
00134
00135