| 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 |
| 11 #include "webrtc/modules/desktop_capture/screen_capturer.h" | 11 #include "webrtc/modules/desktop_capture/screen_capturer.h" |
| 12 | 12 |
| 13 #include <stddef.h> | 13 #include <stddef.h> |
| 14 | 14 |
| 15 #include <memory> | 15 #include <memory> |
| 16 #include <set> | 16 #include <set> |
| 17 | 17 |
| 18 #include <ApplicationServices/ApplicationServices.h> | 18 #include <ApplicationServices/ApplicationServices.h> |
| 19 #include <Cocoa/Cocoa.h> | 19 #include <Cocoa/Cocoa.h> |
| 20 #include <dlfcn.h> | 20 #include <dlfcn.h> |
| 21 #include <IOKit/pwr_mgt/IOPMLib.h> | 21 #include <IOKit/pwr_mgt/IOPMLib.h> |
| 22 #include <OpenGL/CGLMacro.h> | 22 #include <OpenGL/CGLMacro.h> |
| 23 #include <OpenGL/OpenGL.h> | 23 #include <OpenGL/OpenGL.h> |
| 24 | 24 |
| 25 #include "webrtc/base/checks.h" |
| 25 #include "webrtc/base/macutils.h" | 26 #include "webrtc/base/macutils.h" |
| 26 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 27 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
| 27 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 28 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
| 28 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | 29 #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| 29 #include "webrtc/modules/desktop_capture/desktop_region.h" | 30 #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 30 #include "webrtc/modules/desktop_capture/mac/desktop_configuration.h" | 31 #include "webrtc/modules/desktop_capture/mac/desktop_configuration.h" |
| 31 #include "webrtc/modules/desktop_capture/mac/desktop_configuration_monitor.h" | 32 #include "webrtc/modules/desktop_capture/mac/desktop_configuration_monitor.h" |
| 32 #include "webrtc/modules/desktop_capture/mac/scoped_pixel_buffer_object.h" | 33 #include "webrtc/modules/desktop_capture/mac/scoped_pixel_buffer_object.h" |
| 33 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" | 34 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" |
| 34 #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" | 35 #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" |
| 36 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" |
| 35 #include "webrtc/system_wrappers/include/logging.h" | 37 #include "webrtc/system_wrappers/include/logging.h" |
| 36 #include "webrtc/system_wrappers/include/tick_util.h" | 38 #include "webrtc/system_wrappers/include/tick_util.h" |
| 37 | 39 |
| 38 namespace webrtc { | 40 namespace webrtc { |
| 39 | 41 |
| 40 namespace { | 42 namespace { |
| 41 | 43 |
| 42 // Definitions used to dynamic-link to deprecated OS 10.6 functions. | 44 // Definitions used to dynamic-link to deprecated OS 10.6 functions. |
| 43 const char* kApplicationServicesLibraryName = | 45 const char* kApplicationServicesLibraryName = |
| 44 "/System/Library/Frameworks/ApplicationServices.framework/" | 46 "/System/Library/Frameworks/ApplicationServices.framework/" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 void ReleaseBuffers(); | 229 void ReleaseBuffers(); |
| 228 | 230 |
| 229 DesktopFrame* CreateFrame(); | 231 DesktopFrame* CreateFrame(); |
| 230 | 232 |
| 231 Callback* callback_; | 233 Callback* callback_; |
| 232 | 234 |
| 233 CGLContextObj cgl_context_; | 235 CGLContextObj cgl_context_; |
| 234 ScopedPixelBufferObject pixel_buffer_object_; | 236 ScopedPixelBufferObject pixel_buffer_object_; |
| 235 | 237 |
| 236 // Queue of the frames buffers. | 238 // Queue of the frames buffers. |
| 237 ScreenCaptureFrameQueue queue_; | 239 ScreenCaptureFrameQueue<SharedDesktopFrame> queue_; |
| 238 | 240 |
| 239 // Current display configuration. | 241 // Current display configuration. |
| 240 MacDesktopConfiguration desktop_config_; | 242 MacDesktopConfiguration desktop_config_; |
| 241 | 243 |
| 242 // Currently selected display, or 0 if the full desktop is selected. On OS X | 244 // Currently selected display, or 0 if the full desktop is selected. On OS X |
| 243 // 10.6 and before, this is always 0. | 245 // 10.6 and before, this is always 0. |
| 244 CGDirectDisplayID current_display_; | 246 CGDirectDisplayID current_display_; |
| 245 | 247 |
| 246 // The physical pixel bounds of the current screen. | 248 // The physical pixel bounds of the current screen. |
| 247 DesktopRect screen_pixel_bounds_; | 249 DesktopRect screen_pixel_bounds_; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 IOPMAssertionCreateWithName(CFSTR("UserIsActive"), | 379 IOPMAssertionCreateWithName(CFSTR("UserIsActive"), |
| 378 kIOPMAssertionLevelOn, | 380 kIOPMAssertionLevelOn, |
| 379 CFSTR("Chrome Remote Desktop connection active"), | 381 CFSTR("Chrome Remote Desktop connection active"), |
| 380 &power_assertion_id_user_); | 382 &power_assertion_id_user_); |
| 381 } | 383 } |
| 382 | 384 |
| 383 void ScreenCapturerMac::Capture(const DesktopRegion& region_to_capture) { | 385 void ScreenCapturerMac::Capture(const DesktopRegion& region_to_capture) { |
| 384 TickTime capture_start_time = TickTime::Now(); | 386 TickTime capture_start_time = TickTime::Now(); |
| 385 | 387 |
| 386 queue_.MoveToNextFrame(); | 388 queue_.MoveToNextFrame(); |
| 389 RTC_DCHECK(!queue_.current_frame() || !queue_.current_frame()->IsShared()); |
| 387 | 390 |
| 388 desktop_config_monitor_->Lock(); | 391 desktop_config_monitor_->Lock(); |
| 389 MacDesktopConfiguration new_config = | 392 MacDesktopConfiguration new_config = |
| 390 desktop_config_monitor_->desktop_configuration(); | 393 desktop_config_monitor_->desktop_configuration(); |
| 391 if (!desktop_config_.Equals(new_config)) { | 394 if (!desktop_config_.Equals(new_config)) { |
| 392 desktop_config_ = new_config; | 395 desktop_config_ = new_config; |
| 393 // If the display configuraiton has changed then refresh capturer data | 396 // If the display configuraiton has changed then refresh capturer data |
| 394 // structures. Occasionally, the refresh and move handlers are lost when | 397 // structures. Occasionally, the refresh and move handlers are lost when |
| 395 // the screen mode changes, so re-register them here. | 398 // the screen mode changes, so re-register them here. |
| 396 UnregisterRefreshAndMoveHandlers(); | 399 UnregisterRefreshAndMoveHandlers(); |
| 397 RegisterRefreshAndMoveHandlers(); | 400 RegisterRefreshAndMoveHandlers(); |
| 398 ScreenConfigurationChanged(); | 401 ScreenConfigurationChanged(); |
| 399 } | 402 } |
| 400 | 403 |
| 401 DesktopRegion region; | 404 DesktopRegion region; |
| 402 helper_.TakeInvalidRegion(®ion); | 405 helper_.TakeInvalidRegion(®ion); |
| 403 | 406 |
| 404 // If the current buffer is from an older generation then allocate a new one. | 407 // If the current buffer is from an older generation then allocate a new one. |
| 405 // Note that we can't reallocate other buffers at this point, since the caller | 408 // Note that we can't reallocate other buffers at this point, since the caller |
| 406 // may still be reading from them. | 409 // may still be reading from them. |
| 407 if (!queue_.current_frame()) | 410 if (!queue_.current_frame()) |
| 408 queue_.ReplaceCurrentFrame(CreateFrame()); | 411 queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(CreateFrame())); |
| 409 | 412 |
| 410 DesktopFrame* current_frame = queue_.current_frame(); | 413 DesktopFrame* current_frame = queue_.current_frame(); |
| 411 | 414 |
| 412 bool flip = false; // GL capturers need flipping. | 415 bool flip = false; // GL capturers need flipping. |
| 413 if (rtc::GetOSVersionName() >= rtc::kMacOSLion) { | 416 if (rtc::GetOSVersionName() >= rtc::kMacOSLion) { |
| 414 // Lion requires us to use their new APIs for doing screen capture. These | 417 // Lion requires us to use their new APIs for doing screen capture. These |
| 415 // APIS currently crash on 10.6.8 if there is no monitor attached. | 418 // APIS currently crash on 10.6.8 if there is no monitor attached. |
| 416 if (!CgBlitPostLion(*current_frame, region)) { | 419 if (!CgBlitPostLion(*current_frame, region)) { |
| 417 desktop_config_monitor_->Unlock(); | 420 desktop_config_monitor_->Unlock(); |
| 418 callback_->OnCaptureCompleted(NULL); | 421 callback_->OnCaptureCompleted(NULL); |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 return NULL; | 984 return NULL; |
| 982 | 985 |
| 983 std::unique_ptr<ScreenCapturerMac> capturer( | 986 std::unique_ptr<ScreenCapturerMac> capturer( |
| 984 new ScreenCapturerMac(options.configuration_monitor())); | 987 new ScreenCapturerMac(options.configuration_monitor())); |
| 985 if (!capturer->Init()) | 988 if (!capturer->Init()) |
| 986 capturer.reset(); | 989 capturer.reset(); |
| 987 return capturer.release(); | 990 return capturer.release(); |
| 988 } | 991 } |
| 989 | 992 |
| 990 } // namespace webrtc | 993 } // namespace webrtc |
| OLD | NEW |