OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/host/desktop_resizer.h" | 5 #include "remoting/host/desktop_resizer.h" |
6 | 6 |
7 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 const SkISize& preferred) OVERRIDE; | 24 const SkISize& preferred) OVERRIDE; |
25 virtual void SetSize(const SkISize& size) OVERRIDE; | 25 virtual void SetSize(const SkISize& size) OVERRIDE; |
26 virtual void RestoreSize(const SkISize& original) OVERRIDE; | 26 virtual void RestoreSize(const SkISize& original) OVERRIDE; |
27 | 27 |
28 private: | 28 private: |
29 // If there is a single display, get its id and return true, otherwise return | 29 // If there is a single display, get its id and return true, otherwise return |
30 // false. We don't currently support resize-to-client on multi-monitor Macs. | 30 // false. We don't currently support resize-to-client on multi-monitor Macs. |
31 bool GetSoleDisplayId(CGDirectDisplayID* display); | 31 bool GetSoleDisplayId(CGDirectDisplayID* display); |
32 | 32 |
33 void GetSupportedModesAndSizes( | 33 void GetSupportedModesAndSizes( |
34 base::mac::ScopedCFTypeRef<CFMutableArrayRef>* modes, | 34 base::ScopedCFTypeRef<CFMutableArrayRef>* modes, |
35 std::list<SkISize>* sizes); | 35 std::list<SkISize>* sizes); |
36 | 36 |
37 DISALLOW_COPY_AND_ASSIGN(DesktopResizerMac); | 37 DISALLOW_COPY_AND_ASSIGN(DesktopResizerMac); |
38 }; | 38 }; |
39 | 39 |
40 DesktopResizerMac::DesktopResizerMac() {} | 40 DesktopResizerMac::DesktopResizerMac() {} |
41 | 41 |
42 SkISize DesktopResizerMac::GetCurrentSize() { | 42 SkISize DesktopResizerMac::GetCurrentSize() { |
43 CGDirectDisplayID display; | 43 CGDirectDisplayID display; |
44 if (!base::mac::IsOSSnowLeopard() && GetSoleDisplayId(&display)) { | 44 if (!base::mac::IsOSSnowLeopard() && GetSoleDisplayId(&display)) { |
45 CGRect rect = CGDisplayBounds(display); | 45 CGRect rect = CGDisplayBounds(display); |
46 return SkISize::Make(rect.size.width, rect.size.height); | 46 return SkISize::Make(rect.size.width, rect.size.height); |
47 } | 47 } |
48 return SkISize::Make(0, 0); | 48 return SkISize::Make(0, 0); |
49 } | 49 } |
50 | 50 |
51 std::list<SkISize> DesktopResizerMac::GetSupportedSizes( | 51 std::list<SkISize> DesktopResizerMac::GetSupportedSizes( |
52 const SkISize& preferred) { | 52 const SkISize& preferred) { |
53 base::mac::ScopedCFTypeRef<CFMutableArrayRef> modes; | 53 base::ScopedCFTypeRef<CFMutableArrayRef> modes; |
54 std::list<SkISize> sizes; | 54 std::list<SkISize> sizes; |
55 GetSupportedModesAndSizes(&modes, &sizes); | 55 GetSupportedModesAndSizes(&modes, &sizes); |
56 return sizes; | 56 return sizes; |
57 } | 57 } |
58 | 58 |
59 void DesktopResizerMac::SetSize(const SkISize& size) { | 59 void DesktopResizerMac::SetSize(const SkISize& size) { |
60 CGDirectDisplayID display; | 60 CGDirectDisplayID display; |
61 if (base::mac::IsOSSnowLeopard() || !GetSoleDisplayId(&display)) { | 61 if (base::mac::IsOSSnowLeopard() || !GetSoleDisplayId(&display)) { |
62 return; | 62 return; |
63 } | 63 } |
64 | 64 |
65 base::mac::ScopedCFTypeRef<CFMutableArrayRef> modes; | 65 base::ScopedCFTypeRef<CFMutableArrayRef> modes; |
66 std::list<SkISize> sizes; | 66 std::list<SkISize> sizes; |
67 GetSupportedModesAndSizes(&modes, &sizes); | 67 GetSupportedModesAndSizes(&modes, &sizes); |
68 // There may be many modes with the requested size. Pick the one with the | 68 // There may be many modes with the requested size. Pick the one with the |
69 // highest color depth. | 69 // highest color depth. |
70 int index = 0, best_depth = 0; | 70 int index = 0, best_depth = 0; |
71 CGDisplayModeRef best_mode = NULL; | 71 CGDisplayModeRef best_mode = NULL; |
72 for (std::list<SkISize>::const_iterator i = sizes.begin(); i != sizes.end(); | 72 for (std::list<SkISize>::const_iterator i = sizes.begin(); i != sizes.end(); |
73 ++i, ++index) { | 73 ++i, ++index) { |
74 if (*i == size) { | 74 if (*i == size) { |
75 CGDisplayModeRef mode = const_cast<CGDisplayModeRef>( | 75 CGDisplayModeRef mode = const_cast<CGDisplayModeRef>( |
76 static_cast<const CGDisplayMode*>( | 76 static_cast<const CGDisplayMode*>( |
77 CFArrayGetValueAtIndex(modes, index))); | 77 CFArrayGetValueAtIndex(modes, index))); |
78 int depth = 0; | 78 int depth = 0; |
79 base::mac::ScopedCFTypeRef<CFStringRef> encoding( | 79 base::ScopedCFTypeRef<CFStringRef> encoding( |
80 CGDisplayModeCopyPixelEncoding(mode)); | 80 CGDisplayModeCopyPixelEncoding(mode)); |
81 if (CFStringCompare(encoding, CFSTR(IO32BitDirectPixels), | 81 if (CFStringCompare(encoding, CFSTR(IO32BitDirectPixels), |
82 kCFCompareCaseInsensitive) == kCFCompareEqualTo) { | 82 kCFCompareCaseInsensitive) == kCFCompareEqualTo) { |
83 depth = 32; | 83 depth = 32; |
84 } else if (CFStringCompare( | 84 } else if (CFStringCompare( |
85 encoding, CFSTR(IO16BitDirectPixels), | 85 encoding, CFSTR(IO16BitDirectPixels), |
86 kCFCompareCaseInsensitive) == kCFCompareEqualTo) { | 86 kCFCompareCaseInsensitive) == kCFCompareEqualTo) { |
87 depth = 16; | 87 depth = 16; |
88 } else if(CFStringCompare( | 88 } else if(CFStringCompare( |
89 encoding, CFSTR(IO8BitIndexedPixels), | 89 encoding, CFSTR(IO8BitIndexedPixels), |
(...skipping 11 matching lines...) Expand all Loading... |
101 << "x" << size.height() << "x" << best_depth << ")"; | 101 << "x" << size.height() << "x" << best_depth << ")"; |
102 CGDisplaySetDisplayMode(display, best_mode, NULL); | 102 CGDisplaySetDisplayMode(display, best_mode, NULL); |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 void DesktopResizerMac::RestoreSize(const SkISize& original) { | 106 void DesktopResizerMac::RestoreSize(const SkISize& original) { |
107 SetSize(original); | 107 SetSize(original); |
108 } | 108 } |
109 | 109 |
110 void DesktopResizerMac::GetSupportedModesAndSizes( | 110 void DesktopResizerMac::GetSupportedModesAndSizes( |
111 base::mac::ScopedCFTypeRef<CFMutableArrayRef>* modes, | 111 base::ScopedCFTypeRef<CFMutableArrayRef>* modes, |
112 std::list<SkISize>* sizes) { | 112 std::list<SkISize>* sizes) { |
113 CGDirectDisplayID display; | 113 CGDirectDisplayID display; |
114 if (GetSoleDisplayId(&display)) { | 114 if (GetSoleDisplayId(&display)) { |
115 base::mac::ScopedCFTypeRef<CFArrayRef> | 115 base::ScopedCFTypeRef<CFArrayRef> all_modes( |
116 all_modes(CGDisplayCopyAllDisplayModes(display, NULL)); | 116 CGDisplayCopyAllDisplayModes(display, NULL)); |
117 modes->reset(CFArrayCreateMutableCopy(NULL, 0, all_modes)); | 117 modes->reset(CFArrayCreateMutableCopy(NULL, 0, all_modes)); |
118 CFIndex count = CFArrayGetCount(*modes); | 118 CFIndex count = CFArrayGetCount(*modes); |
119 for (CFIndex i = 0; i < count; ++i) { | 119 for (CFIndex i = 0; i < count; ++i) { |
120 CGDisplayModeRef mode = const_cast<CGDisplayModeRef>( | 120 CGDisplayModeRef mode = const_cast<CGDisplayModeRef>( |
121 static_cast<const CGDisplayMode*>( | 121 static_cast<const CGDisplayMode*>( |
122 CFArrayGetValueAtIndex(*modes, i))); | 122 CFArrayGetValueAtIndex(*modes, i))); |
123 if (CGDisplayModeIsUsableForDesktopGUI(mode)) { | 123 if (CGDisplayModeIsUsableForDesktopGUI(mode)) { |
124 SkISize size = SkISize::Make(CGDisplayModeGetWidth(mode), | 124 SkISize size = SkISize::Make(CGDisplayModeGetWidth(mode), |
125 CGDisplayModeGetHeight(mode)); | 125 CGDisplayModeGetHeight(mode)); |
126 sizes->push_back(size); | 126 sizes->push_back(size); |
(...skipping 18 matching lines...) Expand all Loading... |
145 } | 145 } |
146 *display = displays[0]; | 146 *display = displays[0]; |
147 return true; | 147 return true; |
148 } | 148 } |
149 | 149 |
150 scoped_ptr<DesktopResizer> DesktopResizer::Create() { | 150 scoped_ptr<DesktopResizer> DesktopResizer::Create() { |
151 return scoped_ptr<DesktopResizer>(new DesktopResizerMac); | 151 return scoped_ptr<DesktopResizer>(new DesktopResizerMac); |
152 } | 152 } |
153 | 153 |
154 } // namespace remoting | 154 } // namespace remoting |
OLD | NEW |