Blender  V2.93
GHOST_DisplayManagerCocoa.mm
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  Damien Plisson 10/2009
19  */
20 
21 #include <Cocoa/Cocoa.h>
22 
23 #include "GHOST_Debug.h"
25 
26 // We do not support multiple monitors at the moment
27 
29 {
30 }
31 
33 {
34  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
35 
36  numDisplays = (GHOST_TUns8)[[NSScreen screens] count];
37 
38  [pool drain];
39  return GHOST_kSuccess;
40 }
41 
43  GHOST_TInt32 &numSettings) const
44 {
45  numSettings = (GHOST_TInt32)3; // Width, Height, BitsPerPixel
46 
47  return GHOST_kSuccess;
48 }
49 
51  GHOST_TInt32 index,
52  GHOST_DisplaySetting &setting) const
53 {
54  NSScreen *askedDisplay;
55 
56  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
57 
58  if (display == kMainDisplay) // Screen #0 may not be the main one
59  askedDisplay = [NSScreen mainScreen];
60  else
61  askedDisplay = [[NSScreen screens] objectAtIndex:display];
62 
63  if (askedDisplay == nil) {
64  [pool drain];
65  return GHOST_kFailure;
66  }
67 
68  NSRect frame = [askedDisplay visibleFrame];
69  setting.xPixels = frame.size.width;
70  setting.yPixels = frame.size.height;
71 
72  setting.bpp = NSBitsPerPixelFromDepth([askedDisplay depth]);
73 
74  setting.frequency = 0; // No more CRT display...
75 
76 #ifdef GHOST_DEBUG
77  printf("display mode: width=%d, height=%d, bpp=%d, frequency=%d\n",
78  setting.xPixels,
79  setting.yPixels,
80  setting.bpp,
81  setting.frequency);
82 #endif // GHOST_DEBUG
83 
84  [pool drain];
85  return GHOST_kSuccess;
86 }
87 
89  GHOST_TUns8 display, GHOST_DisplaySetting &setting) const
90 {
91  NSScreen *askedDisplay;
92 
94  (display == kMainDisplay),
95  "GHOST_DisplayManagerCocoa::getCurrentDisplaySetting(): only main display is supported");
96 
97  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
98 
99  if (display == kMainDisplay) // Screen #0 may not be the main one
100  askedDisplay = [NSScreen mainScreen];
101  else
102  askedDisplay = [[NSScreen screens] objectAtIndex:display];
103 
104  if (askedDisplay == nil) {
105  [pool drain];
106  return GHOST_kFailure;
107  }
108 
109  NSRect frame = [askedDisplay visibleFrame];
110  setting.xPixels = frame.size.width;
111  setting.yPixels = frame.size.height;
112 
113  setting.bpp = NSBitsPerPixelFromDepth([askedDisplay depth]);
114 
115  setting.frequency = 0; // No more CRT display...
116 
117 #ifdef GHOST_DEBUG
118  printf("current display mode: width=%d, height=%d, bpp=%d, frequency=%d\n",
119  setting.xPixels,
120  setting.yPixels,
121  setting.bpp,
122  setting.frequency);
123 #endif // GHOST_DEBUG
124 
125  [pool drain];
126  return GHOST_kSuccess;
127 }
128 
130  GHOST_TUns8 display, const GHOST_DisplaySetting &setting)
131 {
132  GHOST_ASSERT(
133  (display == kMainDisplay),
134  "GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): only main display is supported");
135 
136 #ifdef GHOST_DEBUG
137  printf("GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): requested settings:\n");
138  printf(" setting.xPixels=%d\n", setting.xPixels);
139  printf(" setting.yPixels=%d\n", setting.yPixels);
140  printf(" setting.bpp=%d\n", setting.bpp);
141  printf(" setting.frequency=%d\n", setting.frequency);
142 #endif // GHOST_DEBUG
143 
144  // Display configuration is no more available in 10.6
145 
146  /* CFDictionaryRef displayModeValues = ::CGDisplayBestModeForParametersAndRefreshRate(
147  m_displayIDs[display],
148  (size_t)setting.bpp,
149  (size_t)setting.xPixels,
150  (size_t)setting.yPixels,
151  (CGRefreshRate)setting.frequency,
152  NULL);*/
153 
154 #ifdef GHOST_DEBUG
155 /* printf("GHOST_DisplayManagerCocoa::setCurrentDisplaySetting(): switching to:\n");
156  printf(" setting.xPixels=%d\n", getValue(displayModeValues, kCGDisplayWidth));
157  printf(" setting.yPixels=%d\n", getValue(displayModeValues, kCGDisplayHeight));
158  printf(" setting.bpp=%d\n", getValue(displayModeValues, kCGDisplayBitsPerPixel));
159  printf(" setting.frequency=%d\n", getValue(displayModeValues, kCGDisplayRefreshRate)); */
160 #endif // GHOST_DEBUG
161 
162  // CGDisplayErr err = ::CGDisplaySwitchToMode(m_displayIDs[display], displayModeValues);
163 
164  return /*err == CGDisplayNoErr ?*/ GHOST_kSuccess /*: GHOST_kFailure*/;
165 }
#define GHOST_ASSERT(x, info)
Definition: GHOST_Debug.h:79
int GHOST_TInt32
Definition: GHOST_Types.h:63
GHOST_TSuccess
Definition: GHOST_Types.h:91
@ GHOST_kFailure
Definition: GHOST_Types.h:91
@ GHOST_kSuccess
Definition: GHOST_Types.h:91
unsigned char GHOST_TUns8
Definition: GHOST_Types.h:60
GHOST_TSuccess getNumDisplays(GHOST_TUns8 &numDisplays) const
GHOST_TSuccess getCurrentDisplaySetting(GHOST_TUns8 display, GHOST_DisplaySetting &setting) const
GHOST_TSuccess getNumDisplaySettings(GHOST_TUns8 display, GHOST_TInt32 &numSettings) const
GHOST_TSuccess getDisplaySetting(GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting &setting) const
GHOST_TSuccess setCurrentDisplaySetting(GHOST_TUns8 display, const GHOST_DisplaySetting &setting)
int count
GHOST_TUns32 bpp
Definition: GHOST_Types.h:584
GHOST_TUns32 xPixels
Definition: GHOST_Types.h:580
GHOST_TUns32 frequency
Definition: GHOST_Types.h:586
GHOST_TUns32 yPixels
Definition: GHOST_Types.h:582