Blender V2.61 - r43446

GHOST_DisplayManagerCocoa.mm

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):  Maarten Gribnau 09/2001
00024                     Damien Plisson  10/2009
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00029 #include <Cocoa/Cocoa.h>
00030 
00031 #include "GHOST_DisplayManagerCocoa.h"
00032 #include "GHOST_Debug.h"
00033 
00034 // We do not support multiple monitors at the moment
00035 
00036 
00037 GHOST_DisplayManagerCocoa::GHOST_DisplayManagerCocoa(void)
00038 {
00039 }
00040 
00041 
00042 GHOST_TSuccess GHOST_DisplayManagerCocoa::getNumDisplays(GHOST_TUns8& numDisplays) const
00043 {
00044     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
00045     
00046     numDisplays = (GHOST_TUns8) [[NSScreen screens] count];
00047     
00048     [pool drain];
00049     return GHOST_kSuccess;
00050 }
00051 
00052 
00053 GHOST_TSuccess GHOST_DisplayManagerCocoa::getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const
00054 {
00055     GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getNumDisplaySettings(): only main display is supported");
00056     
00057     numSettings = (GHOST_TInt32)3; //Width, Height, BitsPerPixel
00058     
00059     return GHOST_kSuccess;
00060 }
00061 
00062 
00063 GHOST_TSuccess GHOST_DisplayManagerCocoa::getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const
00064 {
00065     //Note that only current display setting is available
00066     NSScreen *askedDisplay;
00067     
00068     GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getDisplaySetting(): only main display is supported");
00069     
00070     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
00071     
00072     if (display == kMainDisplay) //Screen #0 may not be the main one
00073         askedDisplay = [NSScreen mainScreen];
00074     else
00075         askedDisplay = [[NSScreen screens] objectAtIndex:display];
00076     
00077     if(askedDisplay == nil) {
00078         [pool drain];
00079         return GHOST_kFailure;
00080     }
00081     
00082     NSRect frame = [askedDisplay visibleFrame];
00083     setting.xPixels = frame.size.width;
00084     setting.yPixels = frame.size.height;
00085     
00086     setting.bpp = NSBitsPerPixelFromDepth([askedDisplay depth]);
00087     
00088     setting.frequency = 0; //No more CRT display...
00089                 
00090 #ifdef GHOST_DEBUG
00091     printf("display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
00092 #endif // GHOST_DEBUG
00093 
00094     [pool drain];
00095     return GHOST_kSuccess;
00096 }
00097 
00098 
00099 GHOST_TSuccess GHOST_DisplayManagerCocoa::getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const
00100 {
00101     NSScreen *askedDisplay;
00102     
00103     GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::getCurrentDisplaySetting(): only main display is supported");
00104     
00105     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
00106 
00107     if (display == kMainDisplay) //Screen #0 may not be the main one
00108         askedDisplay = [NSScreen mainScreen];
00109     else
00110         askedDisplay = [[NSScreen screens] objectAtIndex:display];
00111     
00112     if(askedDisplay == nil) {
00113         [pool drain];
00114         return GHOST_kFailure;
00115     }
00116     
00117     NSRect frame = [askedDisplay visibleFrame];
00118     setting.xPixels = frame.size.width;
00119     setting.yPixels = frame.size.height;
00120     
00121     setting.bpp = NSBitsPerPixelFromDepth([askedDisplay depth]);
00122     
00123     setting.frequency = 0; //No more CRT display...
00124 
00125 #ifdef GHOST_DEBUG
00126     printf("current display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
00127 #endif // GHOST_DEBUG
00128 
00129     [pool drain];
00130     return GHOST_kSuccess;
00131 }
00132 
00133 
00134 GHOST_TSuccess GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting)
00135 {
00136     GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): only main display is supported");
00137 
00138 #ifdef GHOST_DEBUG
00139     printf("GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): requested settings:\n");
00140     printf("  setting.xPixels=%d\n", setting.xPixels);
00141     printf("  setting.yPixels=%d\n", setting.yPixels);
00142     printf("  setting.bpp=%d\n", setting.bpp);
00143     printf("  setting.frequency=%d\n", setting.frequency);
00144 #endif // GHOST_DEBUG
00145 
00146     //Display configuration is no more available in 10.6
00147     
00148 /*  CFDictionaryRef displayModeValues = ::CGDisplayBestModeForParametersAndRefreshRate(
00149         m_displayIDs[display],
00150         (size_t)setting.bpp,
00151         (size_t)setting.xPixels,
00152         (size_t)setting.yPixels,
00153         (CGRefreshRate)setting.frequency,
00154         NULL);*/
00155 
00156 #ifdef GHOST_DEBUG
00157 /*  printf("GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): switching to:\n");
00158     printf("  setting.xPixels=%d\n", getValue(displayModeValues, kCGDisplayWidth));
00159     printf("  setting.yPixels=%d\n", getValue(displayModeValues, kCGDisplayHeight));
00160     printf("  setting.bpp=%d\n", getValue(displayModeValues, kCGDisplayBitsPerPixel));
00161     printf("  setting.frequency=%d\n", getValue(displayModeValues, kCGDisplayRefreshRate)); */
00162 #endif // GHOST_DEBUG
00163 
00164     //CGDisplayErr err = ::CGDisplaySwitchToMode(m_displayIDs[display], displayModeValues);
00165         
00166     return /*err == CGDisplayNoErr ?*/ GHOST_kSuccess /*: GHOST_kFailure*/;
00167 }