| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 return valid; | 42 return valid; |
| 43 } | 43 } |
| 44 | 44 |
| 45 class WindowCapturerMac : public WindowCapturer { | 45 class WindowCapturerMac : public WindowCapturer { |
| 46 public: | 46 public: |
| 47 explicit WindowCapturerMac(rtc::scoped_refptr<FullScreenChromeWindowDetector> | 47 explicit WindowCapturerMac(rtc::scoped_refptr<FullScreenChromeWindowDetector> |
| 48 full_screen_chrome_window_detector); | 48 full_screen_chrome_window_detector); |
| 49 ~WindowCapturerMac() override; | 49 ~WindowCapturerMac() override; |
| 50 | 50 |
| 51 // WindowCapturer interface. | |
| 52 bool GetWindowList(WindowList* windows) override; | |
| 53 bool SelectWindow(WindowId id) override; | |
| 54 bool BringSelectedWindowToFront() override; | |
| 55 | |
| 56 // DesktopCapturer interface. | 51 // DesktopCapturer interface. |
| 57 void Start(Callback* callback) override; | 52 void Start(Callback* callback) override; |
| 58 void CaptureFrame() override; | 53 void CaptureFrame() override; |
| 54 bool GetSourceList(SourceList* sources) override; |
| 55 bool SelectSource(SourceId id) override; |
| 56 bool FocusOnSelectedSource() override; |
| 59 | 57 |
| 60 private: | 58 private: |
| 61 Callback* callback_ = nullptr; | 59 Callback* callback_ = nullptr; |
| 62 | 60 |
| 63 // The window being captured. | 61 // The window being captured. |
| 64 CGWindowID window_id_ = 0; | 62 CGWindowID window_id_ = 0; |
| 65 | 63 |
| 66 rtc::scoped_refptr<FullScreenChromeWindowDetector> | 64 rtc::scoped_refptr<FullScreenChromeWindowDetector> |
| 67 full_screen_chrome_window_detector_; | 65 full_screen_chrome_window_detector_; |
| 68 | 66 |
| 69 RTC_DISALLOW_COPY_AND_ASSIGN(WindowCapturerMac); | 67 RTC_DISALLOW_COPY_AND_ASSIGN(WindowCapturerMac); |
| 70 }; | 68 }; |
| 71 | 69 |
| 72 WindowCapturerMac::WindowCapturerMac( | 70 WindowCapturerMac::WindowCapturerMac( |
| 73 rtc::scoped_refptr<FullScreenChromeWindowDetector> | 71 rtc::scoped_refptr<FullScreenChromeWindowDetector> |
| 74 full_screen_chrome_window_detector) | 72 full_screen_chrome_window_detector) |
| 75 : full_screen_chrome_window_detector_(full_screen_chrome_window_detector) {} | 73 : full_screen_chrome_window_detector_(full_screen_chrome_window_detector) {} |
| 76 | 74 |
| 77 WindowCapturerMac::~WindowCapturerMac() {} | 75 WindowCapturerMac::~WindowCapturerMac() {} |
| 78 | 76 |
| 79 bool WindowCapturerMac::GetWindowList(WindowList* windows) { | 77 bool WindowCapturerMac::GetSourceList(SourceList* sources) { |
| 80 // Only get on screen, non-desktop windows. | 78 return webrtc::GetWindowList(sources, true); |
| 81 CFArrayRef window_array = CGWindowListCopyWindowInfo( | |
| 82 kCGWindowListExcludeDesktopElements, | |
| 83 kCGNullWindowID); | |
| 84 if (!window_array) | |
| 85 return false; | |
| 86 MacDesktopConfiguration desktop_config = MacDesktopConfiguration::GetCurrent( | |
| 87 MacDesktopConfiguration::TopLeftOrigin); | |
| 88 // Check windows to make sure they have an id, title, and use window layer | |
| 89 // other than 0. | |
| 90 CFIndex count = CFArrayGetCount(window_array); | |
| 91 for (CFIndex i = 0; i < count; ++i) { | |
| 92 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>( | |
| 93 CFArrayGetValueAtIndex(window_array, i)); | |
| 94 CFStringRef window_title = reinterpret_cast<CFStringRef>( | |
| 95 CFDictionaryGetValue(window, kCGWindowName)); | |
| 96 CFNumberRef window_id = reinterpret_cast<CFNumberRef>( | |
| 97 CFDictionaryGetValue(window, kCGWindowNumber)); | |
| 98 CFNumberRef window_layer = reinterpret_cast<CFNumberRef>( | |
| 99 CFDictionaryGetValue(window, kCGWindowLayer)); | |
| 100 if (window_title && window_id && window_layer) { | |
| 101 // Skip windows with layer=0 (menu, dock). | |
| 102 int layer; | |
| 103 CFNumberGetValue(window_layer, kCFNumberIntType, &layer); | |
| 104 if (layer != 0) | |
| 105 continue; | |
| 106 | |
| 107 int id; | |
| 108 CFNumberGetValue(window_id, kCFNumberIntType, &id); | |
| 109 | |
| 110 // Skip windows that are minimized and not full screen. | |
| 111 if (IsWindowMinimized(id) && | |
| 112 !IsWindowFullScreen(desktop_config, window)) { continue;} | |
| 113 | |
| 114 WindowCapturer::Window window; | |
| 115 window.id = id; | |
| 116 if (!rtc::ToUtf8(window_title, &(window.title)) || | |
| 117 window.title.empty()) { | |
| 118 continue; | |
| 119 } | |
| 120 windows->push_back(window); | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 CFRelease(window_array); | |
| 125 return true; | |
| 126 } | 79 } |
| 127 | 80 |
| 128 bool WindowCapturerMac::SelectWindow(WindowId id) { | 81 bool WindowCapturerMac::SelectSource(SourceId id) { |
| 129 if (!IsWindowValid(id)) | 82 if (!IsWindowValid(id)) |
| 130 return false; | 83 return false; |
| 131 window_id_ = id; | 84 window_id_ = id; |
| 132 return true; | 85 return true; |
| 133 } | 86 } |
| 134 | 87 |
| 135 bool WindowCapturerMac::BringSelectedWindowToFront() { | 88 bool WindowCapturerMac::FocusOnSelectedSource() { |
| 136 if (!window_id_) | 89 if (!window_id_) |
| 137 return false; | 90 return false; |
| 138 | 91 |
| 139 CGWindowID ids[1]; | 92 CGWindowID ids[1]; |
| 140 ids[0] = window_id_; | 93 ids[0] = window_id_; |
| 141 CFArrayRef window_id_array = | 94 CFArrayRef window_id_array = |
| 142 CFArrayCreate(nullptr, reinterpret_cast<const void**>(&ids), 1, nullptr); | 95 CFArrayCreate(nullptr, reinterpret_cast<const void**>(&ids), 1, nullptr); |
| 143 | 96 |
| 144 CFArrayRef window_array = | 97 CFArrayRef window_array = |
| 145 CGWindowListCreateDescriptionFromArray(window_id_array); | 98 CGWindowListCreateDescriptionFromArray(window_id_array); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 } | 195 } |
| 243 | 196 |
| 244 // static | 197 // static |
| 245 std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer( | 198 std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer( |
| 246 const DesktopCaptureOptions& options) { | 199 const DesktopCaptureOptions& options) { |
| 247 return std::unique_ptr<DesktopCapturer>( | 200 return std::unique_ptr<DesktopCapturer>( |
| 248 new WindowCapturerMac(options.full_screen_chrome_window_detector())); | 201 new WindowCapturerMac(options.full_screen_chrome_window_detector())); |
| 249 } | 202 } |
| 250 | 203 |
| 251 } // namespace webrtc | 204 } // namespace webrtc |
| OLD | NEW |