00001
00002 #include "DisplayResOSX.h"
00003
00004 #import <Carbon/Carbon.h>
00005 #import <IOKit/graphics/IOGraphicsLib.h>
00006
00007 #include "mythdisplay.h"
00008 #include "util-osx.h"
00009 #include "util-osx-cocoa.h"
00010
00011 DisplayResOSX::DisplayResOSX(void)
00012 {
00013 Initialize();
00014 }
00015
00016 DisplayResOSX::~DisplayResOSX(void)
00017 {
00018 }
00019
00020 bool DisplayResOSX::GetDisplayInfo(int &w_pix, int &h_pix, int &w_mm,
00021 int &h_mm, double &rate, double &par) const
00022 {
00023 DisplayInfo info = MythDisplay::GetDisplayInfo();
00024 w_mm = info.size.width();
00025 h_mm = info.size.height();
00026 w_pix = info.res.width();
00027 h_pix = info.res.height();
00028 rate = 1000000.0f / info.rate;
00029 par = 1.0;
00030 return true;
00031 }
00032
00033 bool DisplayResOSX::SwitchToVideoMode(int width, int height, double refreshrate)
00034 {
00035 CGDirectDisplayID d = GetOSXDisplay(MythDisplay::GetWindowID());
00036 CFDictionaryRef dispMode = NULL;
00037 boolean_t match = 0;
00038
00039
00040
00041 if (refreshrate)
00042 dispMode = CGDisplayBestModeForParametersAndRefreshRate(
00043 d, 32, width, height,
00044 (CGRefreshRate)((short)refreshrate), &match);
00045
00046 if (!match)
00047 dispMode =
00048 CGDisplayBestModeForParameters(d, 32, width, height, &match);
00049
00050 if (!match)
00051 dispMode =
00052 CGDisplayBestModeForParameters(d, 16, width, height, &match);
00053
00054 if (!match)
00055 return false;
00056
00057
00058 CGDisplayCapture(d);
00059
00060 CGDisplayConfigRef cfg;
00061
00062 CGBeginDisplayConfiguration(&cfg);
00063
00064 CGConfigureDisplayFadeEffect(cfg, 0.3f, 0.5f, 0, 0, 0);
00065
00066 CGConfigureDisplayMode(cfg, d, dispMode);
00067
00068 CGError err = CGCompleteDisplayConfiguration(cfg, kCGConfigureForAppOnly);
00069
00070 CGDisplayRelease(d);
00071
00072 return (err == kCGErrorSuccess);
00073 }
00074
00075 const DisplayResVector& DisplayResOSX::GetVideoModes() const
00076 {
00077 if (!m_videoModes.empty())
00078 return m_videoModes;
00079
00080 CGDirectDisplayID d = GetOSXDisplay(MythDisplay::GetWindowID());
00081
00082 CFArrayRef displayModes = CGDisplayAvailableModes(d);
00083
00084 if (NULL == displayModes)
00085 return m_videoModes;
00086
00087 DisplayResMap screen_map;
00088
00089 for (int i = 0; i < CFArrayGetCount(displayModes); ++i)
00090 {
00091 CFDictionaryRef displayMode = (CFDictionaryRef)
00092 CFArrayGetValueAtIndex(displayModes, i);
00093 int width = get_int_CF(displayMode, kCGDisplayWidth);
00094 int height = get_int_CF(displayMode, kCGDisplayHeight);
00095 int refresh = get_int_CF(displayMode, kCGDisplayRefreshRate);
00096
00097 uint64_t key = DisplayResScreen::CalcKey(width, height, 0.0);
00098
00099 if (screen_map.find(key) == screen_map.end())
00100 screen_map[key] = DisplayResScreen(width, height,
00101 0, 0, -1.0, (double) refresh);
00102 else
00103 screen_map[key].AddRefreshRate(refresh);
00104 }
00105
00106
00107
00108 DisplayResMapCIt it = screen_map.begin();
00109
00110 for (; screen_map.end() != it; ++it)
00111 m_videoModes.push_back(it->second);
00112
00113 return m_videoModes;
00114 }