Blender V2.61 - r43446

GHOST_DisplayManagerCarbon.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00040 #include "GHOST_DisplayManagerCarbon.h"
00041 #include "GHOST_Debug.h"
00042 
00043 // We do not support multiple monitors at the moment
00044 
00045 
00046 GHOST_DisplayManagerCarbon::GHOST_DisplayManagerCarbon(void)
00047 {
00048     if (::CGGetActiveDisplayList(0, NULL, &m_numDisplays) != CGDisplayNoErr)
00049     {
00050         m_numDisplays = 0;
00051         m_displayIDs = NULL;
00052     }
00053     if (m_numDisplays > 0)
00054     {
00055         m_displayIDs = new CGDirectDisplayID [m_numDisplays];
00056         GHOST_ASSERT((m_displayIDs!=NULL), "GHOST_DisplayManagerCarbon::GHOST_DisplayManagerCarbon(): memory allocation failed");
00057         ::CGGetActiveDisplayList(m_numDisplays, m_displayIDs, &m_numDisplays);
00058     }
00059 }
00060 
00061 
00062 GHOST_TSuccess GHOST_DisplayManagerCarbon::getNumDisplays(GHOST_TUns8& numDisplays) const
00063 {
00064     numDisplays = (GHOST_TUns8) m_numDisplays;
00065     return GHOST_kSuccess;
00066 }
00067 
00068 
00069 GHOST_TSuccess GHOST_DisplayManagerCarbon::getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const
00070 {
00071     GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCarbon::getNumDisplaySettings(): only main display is supported");
00072     
00073     CFArrayRef displayModes;
00074     displayModes = ::CGDisplayAvailableModes(m_displayIDs[display]);
00075     CFIndex numModes = ::CFArrayGetCount(displayModes);
00076     numSettings = (GHOST_TInt32)numModes;
00077     
00078     return GHOST_kSuccess;
00079 }
00080 
00081 
00082 GHOST_TSuccess GHOST_DisplayManagerCarbon::getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const
00083 {
00084     GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCarbon::getDisplaySetting(): only main display is supported");
00085     
00086     CFArrayRef displayModes;
00087     CGDirectDisplayID d = m_displayIDs[display];
00088     displayModes = ::CGDisplayAvailableModes(d);
00089     //CFIndex numModes = ::CFArrayGetCount(displayModes);/*unused*/
00090     //GHOST_TInt32 numSettings = (GHOST_TInt32)numModes; /*unused*/
00091     CFDictionaryRef displayModeValues = (CFDictionaryRef)::CFArrayGetValueAtIndex(displayModes, index);
00092             
00093     setting.xPixels     = getValue(displayModeValues, kCGDisplayWidth);
00094     setting.yPixels     = getValue(displayModeValues, kCGDisplayHeight);
00095     setting.bpp         = getValue(displayModeValues, kCGDisplayBitsPerPixel);
00096     setting.frequency   = getValue(displayModeValues, kCGDisplayRefreshRate);
00097             
00098 #ifdef GHOST_DEBUG
00099     printf("display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
00100 #endif // GHOST_DEBUG
00101 
00102     return GHOST_kSuccess;
00103 }
00104 
00105 
00106 GHOST_TSuccess GHOST_DisplayManagerCarbon::getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const
00107 {
00108     GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCarbon::getCurrentDisplaySetting(): only main display is supported");
00109         
00110     CFDictionaryRef displayModeValues = ::CGDisplayCurrentMode(m_displayIDs[display]);
00111     
00112     setting.xPixels     = getValue(displayModeValues, kCGDisplayWidth);
00113     setting.yPixels     = getValue(displayModeValues, kCGDisplayHeight);
00114     setting.bpp         = getValue(displayModeValues, kCGDisplayBitsPerPixel);
00115     setting.frequency   = getValue(displayModeValues, kCGDisplayRefreshRate);
00116 
00117 #ifdef GHOST_DEBUG
00118     printf("current display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
00119 #endif // GHOST_DEBUG
00120 
00121     return GHOST_kSuccess;
00122 }
00123 
00124 
00125 GHOST_TSuccess GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting)
00126 {
00127     GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(): only main display is supported");
00128 
00129 #ifdef GHOST_DEBUG
00130     printf("GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(): requested settings:\n");
00131     printf("  setting.xPixels=%d\n", setting.xPixels);
00132     printf("  setting.yPixels=%d\n", setting.yPixels);
00133     printf("  setting.bpp=%d\n", setting.bpp);
00134     printf("  setting.frequency=%d\n", setting.frequency);
00135 #endif // GHOST_DEBUG
00136 
00137     CFDictionaryRef displayModeValues = ::CGDisplayBestModeForParametersAndRefreshRate(
00138         m_displayIDs[display],
00139         (size_t)setting.bpp,
00140         (size_t)setting.xPixels,
00141         (size_t)setting.yPixels,
00142         (CGRefreshRate)setting.frequency,
00143         NULL);
00144 
00145 #ifdef GHOST_DEBUG
00146     printf("GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(): switching to:\n");
00147     printf("  setting.xPixels=%d\n", getValue(displayModeValues, kCGDisplayWidth));
00148     printf("  setting.yPixels=%d\n", getValue(displayModeValues, kCGDisplayHeight));
00149     printf("  setting.bpp=%d\n", getValue(displayModeValues, kCGDisplayBitsPerPixel));
00150     printf("  setting.frequency=%d\n", getValue(displayModeValues, kCGDisplayRefreshRate));
00151 #endif // GHOST_DEBUG
00152 
00153     CGDisplayErr err = ::CGDisplaySwitchToMode(m_displayIDs[display], displayModeValues);
00154         
00155     return err == CGDisplayNoErr ? GHOST_kSuccess : GHOST_kFailure;
00156 }
00157 
00158 
00159 long GHOST_DisplayManagerCarbon::getValue(CFDictionaryRef values, CFStringRef key) const
00160 {
00161     CFNumberRef numberValue = (CFNumberRef) CFDictionaryGetValue(values, key);
00162     
00163     if (!numberValue)
00164     {
00165         return -1;
00166     }
00167     
00168     long intValue;
00169     
00170     if (!CFNumberGetValue(numberValue, kCFNumberLongType, &intValue))
00171     {
00172         return -1;
00173     }
00174     
00175     return intValue;
00176 }
00177