2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19
* All rights reserved.
21
* The Original Code is: all of this file.
23
* Contributor(s): none yet.
25
* ***** END GPL LICENSE BLOCK *****
28
/** \file ghost/intern/GHOST_DisplayManagerCarbon.cpp
34
* Copyright (C) 2001 NaN Technologies B.V.
35
* \author Maarten Gribnau
36
* \date September 21, 2001
39
#include "GHOST_DisplayManagerCarbon.h"
40
#include "GHOST_Debug.h"
42
// We do not support multiple monitors at the moment
45
GHOST_DisplayManagerCarbon::GHOST_DisplayManagerCarbon(void)
47
if (::CGGetActiveDisplayList(0, NULL, &m_numDisplays) != CGDisplayNoErr)
52
if (m_numDisplays > 0)
54
m_displayIDs = new CGDirectDisplayID[m_numDisplays];
55
GHOST_ASSERT((m_displayIDs != NULL), "GHOST_DisplayManagerCarbon::GHOST_DisplayManagerCarbon(): memory allocation failed");
56
::CGGetActiveDisplayList(m_numDisplays, m_displayIDs, &m_numDisplays);
61
GHOST_TSuccess GHOST_DisplayManagerCarbon::getNumDisplays(GHOST_TUns8& numDisplays) const
63
numDisplays = (GHOST_TUns8) m_numDisplays;
64
return GHOST_kSuccess;
68
GHOST_TSuccess GHOST_DisplayManagerCarbon::getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const
70
GHOST_ASSERT((display == kMainDisplay), "GHOST_DisplayManagerCarbon::getNumDisplaySettings(): only main display is supported");
72
CFArrayRef displayModes;
73
displayModes = ::CGDisplayAvailableModes(m_displayIDs[display]);
74
CFIndex numModes = ::CFArrayGetCount(displayModes);
75
numSettings = (GHOST_TInt32)numModes;
77
return GHOST_kSuccess;
81
GHOST_TSuccess GHOST_DisplayManagerCarbon::getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const
83
GHOST_ASSERT((display == kMainDisplay), "GHOST_DisplayManagerCarbon::getDisplaySetting(): only main display is supported");
85
CFArrayRef displayModes;
86
CGDirectDisplayID d = m_displayIDs[display];
87
displayModes = ::CGDisplayAvailableModes(d);
88
//CFIndex numModes = ::CFArrayGetCount(displayModes);/*unused*/
89
//GHOST_TInt32 numSettings = (GHOST_TInt32)numModes; /*unused*/
90
CFDictionaryRef displayModeValues = (CFDictionaryRef) ::CFArrayGetValueAtIndex(displayModes, index);
92
setting.xPixels = getValue(displayModeValues, kCGDisplayWidth);
93
setting.yPixels = getValue(displayModeValues, kCGDisplayHeight);
94
setting.bpp = getValue(displayModeValues, kCGDisplayBitsPerPixel);
95
setting.frequency = getValue(displayModeValues, kCGDisplayRefreshRate);
98
printf("display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
101
return GHOST_kSuccess;
105
GHOST_TSuccess GHOST_DisplayManagerCarbon::getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const
107
GHOST_ASSERT((display == kMainDisplay), "GHOST_DisplayManagerCarbon::getCurrentDisplaySetting(): only main display is supported");
109
CFDictionaryRef displayModeValues = ::CGDisplayCurrentMode(m_displayIDs[display]);
111
setting.xPixels = getValue(displayModeValues, kCGDisplayWidth);
112
setting.yPixels = getValue(displayModeValues, kCGDisplayHeight);
113
setting.bpp = getValue(displayModeValues, kCGDisplayBitsPerPixel);
114
setting.frequency = getValue(displayModeValues, kCGDisplayRefreshRate);
117
printf("current display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
118
#endif // GHOST_DEBUG
120
return GHOST_kSuccess;
124
GHOST_TSuccess GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting)
126
GHOST_ASSERT((display == kMainDisplay), "GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(): only main display is supported");
129
printf("GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(): requested settings:\n");
130
printf(" setting.xPixels=%d\n", setting.xPixels);
131
printf(" setting.yPixels=%d\n", setting.yPixels);
132
printf(" setting.bpp=%d\n", setting.bpp);
133
printf(" setting.frequency=%d\n", setting.frequency);
134
#endif // GHOST_DEBUG
136
CFDictionaryRef displayModeValues = ::CGDisplayBestModeForParametersAndRefreshRate(
137
m_displayIDs[display],
139
(size_t)setting.xPixels,
140
(size_t)setting.yPixels,
141
(CGRefreshRate)setting.frequency,
145
printf("GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(): switching to:\n");
146
printf(" setting.xPixels=%d\n", getValue(displayModeValues, kCGDisplayWidth));
147
printf(" setting.yPixels=%d\n", getValue(displayModeValues, kCGDisplayHeight));
148
printf(" setting.bpp=%d\n", getValue(displayModeValues, kCGDisplayBitsPerPixel));
149
printf(" setting.frequency=%d\n", getValue(displayModeValues, kCGDisplayRefreshRate));
150
#endif // GHOST_DEBUG
152
CGDisplayErr err = ::CGDisplaySwitchToMode(m_displayIDs[display], displayModeValues);
154
return err == CGDisplayNoErr ? GHOST_kSuccess : GHOST_kFailure;
158
long GHOST_DisplayManagerCarbon::getValue(CFDictionaryRef values, CFStringRef key) const
160
CFNumberRef numberValue = (CFNumberRef) CFDictionaryGetValue(values, key);
169
if (!CFNumberGetValue(numberValue, kCFNumberLongType, &intValue))