Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GHOST_DisplayManagerCarbon.cpp « intern « ghost « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3220fa1a3306985444f7a1c2bad3ee666d0515a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
 * $Id$
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version. The Blender
 * Foundation also sells licenses for use in proprietary software under
 * the Blender License.  See http://www.blender.org/BL/ for information
 * about this.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 * All rights reserved.
 *
 * The Original Code is: all of this file.
 *
 * Contributor(s): none yet.
 *
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
 */

/**

 * $Id$
 * Copyright (C) 2001 NaN Technologies B.V.
 * @author	Maarten Gribnau
 * @date	September 21, 2001
 */

#include "GHOST_DisplayManagerCarbon.h"

#include "GHOST_Debug.h"

// We do not support multiple monitors at the moment


GHOST_DisplayManagerCarbon::GHOST_DisplayManagerCarbon(void)
{
	if (::CGGetActiveDisplayList(0, NULL, &m_numDisplays) != CGDisplayNoErr)
	{
		m_numDisplays = 0;
		m_displayIDs = NULL;
	}
	if (m_numDisplays > 0)
	{
		m_displayIDs = new CGDirectDisplayID [m_numDisplays];
		GHOST_ASSERT((m_displayIDs!=NULL), "GHOST_DisplayManagerCarbon::GHOST_DisplayManagerCarbon(): memory allocation failed");
		::CGGetActiveDisplayList(m_numDisplays, m_displayIDs, &m_numDisplays);
	}
}


GHOST_TSuccess GHOST_DisplayManagerCarbon::getNumDisplays(GHOST_TUns8& numDisplays) const
{
	numDisplays = (GHOST_TUns8) m_numDisplays;
	return GHOST_kSuccess;
}


GHOST_TSuccess GHOST_DisplayManagerCarbon::getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32& numSettings) const
{
	GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCarbon::getNumDisplaySettings(): only main display is supported");
	
	CFArrayRef displayModes;
	displayModes = ::CGDisplayAvailableModes(m_displayIDs[display]);
	CFIndex numModes = ::CFArrayGetCount(displayModes);
	numSettings = (GHOST_TInt32)numModes;
	
	return GHOST_kSuccess;
}


GHOST_TSuccess GHOST_DisplayManagerCarbon::getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting) const
{
	GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCarbon::getDisplaySetting(): only main display is supported");
	
	CFArrayRef displayModes;
	CGDirectDisplayID d = m_displayIDs[display];
	displayModes = ::CGDisplayAvailableModes(d);
	CFIndex numModes = ::CFArrayGetCount(displayModes);
	GHOST_TInt32 numSettings = (GHOST_TInt32)numModes;
	 CFDictionaryRef displayModeValues = (CFDictionaryRef)::CFArrayGetValueAtIndex(displayModes, index);
			
	setting.xPixels		= getValue(displayModeValues, kCGDisplayWidth);
	setting.yPixels		= getValue(displayModeValues, kCGDisplayHeight);
	setting.bpp			= getValue(displayModeValues, kCGDisplayBitsPerPixel);
	setting.frequency	= getValue(displayModeValues, kCGDisplayRefreshRate);
			
#ifdef GHOST_DEBUG
	printf("display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
#endif // GHOST_DEBUG

	return GHOST_kSuccess;
}


GHOST_TSuccess GHOST_DisplayManagerCarbon::getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting& setting) const
{
	GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCarbon::getCurrentDisplaySetting(): only main display is supported");
        
	CFDictionaryRef displayModeValues = ::CGDisplayCurrentMode(m_displayIDs[display]);
	
	setting.xPixels		= getValue(displayModeValues, kCGDisplayWidth);
	setting.yPixels		= getValue(displayModeValues, kCGDisplayHeight);
	setting.bpp			= getValue(displayModeValues, kCGDisplayBitsPerPixel);
	setting.frequency	= getValue(displayModeValues, kCGDisplayRefreshRate);

#ifdef GHOST_DEBUG
	printf("current display mode: width=%d, height=%d, bpp=%d, frequency=%d\n", setting.xPixels, setting.yPixels, setting.bpp, setting.frequency);
#endif // GHOST_DEBUG

	return GHOST_kSuccess;
}


GHOST_TSuccess GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting& setting)
{
	GHOST_ASSERT((display==kMainDisplay), "GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(): only main display is supported");

#ifdef GHOST_DEBUG
	printf("GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(): requested settings:\n");
	printf("  setting.xPixels=%d\n", setting.xPixels);
	printf("  setting.yPixels=%d\n", setting.yPixels);
	printf("  setting.bpp=%d\n", setting.bpp);
	printf("  setting.frequency=%d\n", setting.frequency);
#endif // GHOST_DEBUG

	CFDictionaryRef displayModeValues = ::CGDisplayBestModeForParametersAndRefreshRate(
		m_displayIDs[display],
		(size_t)setting.bpp,
		(size_t)setting.xPixels,
		(size_t)setting.yPixels,
		(CGRefreshRate)setting.frequency,
		NULL);

#ifdef GHOST_DEBUG
	printf("GHOST_DisplayManagerCarbon::setCurrentDisplaySetting(): switching to:\n");
	printf("  setting.xPixels=%d\n", getValue(displayModeValues, kCGDisplayWidth));
	printf("  setting.yPixels=%d\n", getValue(displayModeValues, kCGDisplayHeight));
	printf("  setting.bpp=%d\n", getValue(displayModeValues, kCGDisplayBitsPerPixel));
	printf("  setting.frequency=%d\n", getValue(displayModeValues, kCGDisplayRefreshRate));
#endif // GHOST_DEBUG

	CGDisplayErr err = ::CGDisplaySwitchToMode(m_displayIDs[display], displayModeValues);
        
	return err == CGDisplayNoErr ? GHOST_kSuccess : GHOST_kFailure;
}


long GHOST_DisplayManagerCarbon::getValue(CFDictionaryRef values, CFStringRef key) const
{
    CFNumberRef numberValue = (CFNumberRef) CFDictionaryGetValue(values, key);
    
    if (!numberValue)
    {
        return -1;
    }
    
    long intValue;
    
    if (!CFNumberGetValue(numberValue, kCFNumberLongType, &intValue))
    {
        return -1;
    }
    
    return intValue;
}