Cocoa/VideoModeSupport.cpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
26// Headers
28#include <SFML/Window/Cocoa/VideoModeSupport.hpp>
29#include <ApplicationServices/ApplicationServices.h>
30#include <algorithm>
31
32namespace sf
33{
34namespace priv
35{
39void VideoModeSupport::GetSupportedVideoModes(std::vector<VideoMode>& Modes)
40{
41 // Ceylo -- using same implementation as in OSXCarbon
42
43 // First, clear array to fill
44 Modes.clear();
45
46 // Enumerate all available video modes for primary display adapter
47 CFArrayRef DisplayModes = CGDisplayAvailableModes( kCGDirectMainDisplay );
48 CFIndex DisplayModeCount = CFArrayGetCount( DisplayModes );
49 CFDictionaryRef CurrentMode;
50
51 for (int Count = 0; Count < DisplayModeCount; ++Count)
52 {
53 CurrentMode = (CFDictionaryRef)CFArrayGetValueAtIndex( DisplayModes, Count );
54
55 VideoMode Mode;
56
57 CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentMode, kCGDisplayWidth), kCFNumberIntType, &(Mode.Width));
58 CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentMode, kCGDisplayHeight), kCFNumberIntType, &(Mode.Height));
59 CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentMode, kCGDisplayBitsPerPixel), kCFNumberIntType, &(Mode.BitsPerPixel));
60
61 // Add it only if it is not already in the array
62 if (std::find(Modes.begin(), Modes.end(), Mode) == Modes.end())
63 Modes.push_back(Mode);
64 }
65}
66
67
71VideoMode VideoModeSupport::GetDesktopVideoMode()
72{
73 // Ceylo -- using same implementation as in OSXCarbon
74
75 CFDictionaryRef CurrentVideoMode = CGDisplayCurrentMode(kCGDirectMainDisplay);
76
77 VideoMode DesktopMode;
78
79
80 // Get video mode width
81 CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentVideoMode, kCGDisplayWidth),
82 kCFNumberIntType,
83 &(DesktopMode.Width));
84
85 // Get video mode height
86 CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentVideoMode, kCGDisplayHeight),
87 kCFNumberIntType,
88 &(DesktopMode.Height));
89
90 // Get video mode depth
91 CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentVideoMode, kCGDisplayBitsPerPixel),
92 kCFNumberIntType,
93 &(DesktopMode.BitsPerPixel));
94
95
96 return DesktopMode;
97}
98
99} // namespace priv
100
101} // namespace sf