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 18 matching lines...) Expand all Loading... |
29 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 29 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
30 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 30 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
31 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | 31 #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
32 #include "webrtc/modules/desktop_capture/desktop_region.h" | 32 #include "webrtc/modules/desktop_capture/desktop_region.h" |
33 #include "webrtc/modules/desktop_capture/mac/desktop_configuration.h" | 33 #include "webrtc/modules/desktop_capture/mac/desktop_configuration.h" |
34 #include "webrtc/modules/desktop_capture/mac/desktop_configuration_monitor.h" | 34 #include "webrtc/modules/desktop_capture/mac/desktop_configuration_monitor.h" |
35 #include "webrtc/modules/desktop_capture/mac/scoped_pixel_buffer_object.h" | 35 #include "webrtc/modules/desktop_capture/mac/scoped_pixel_buffer_object.h" |
36 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" | 36 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" |
37 #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" | 37 #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" |
38 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" | 38 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" |
39 #include "webrtc/system_wrappers/include/logging.h" | |
40 | 39 |
41 // Once Chrome no longer supports OSX 10.8, everything within this | 40 // Once Chrome no longer supports OSX 10.8, everything within this |
42 // preprocessor block can be removed. https://crbug.com/579255 | 41 // preprocessor block can be removed. https://crbug.com/579255 |
43 #if !defined(MAC_OS_X_VERSION_10_9) || \ | 42 #if !defined(MAC_OS_X_VERSION_10_9) || \ |
44 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 | 43 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 |
45 CG_EXTERN const CGRect* CGDisplayStreamUpdateGetRects( | 44 CG_EXTERN const CGRect* CGDisplayStreamUpdateGetRects( |
46 CGDisplayStreamUpdateRef updateRef, | 45 CGDisplayStreamUpdateRef updateRef, |
47 CGDisplayStreamUpdateRectType rectType, | 46 CGDisplayStreamUpdateRectType rectType, |
48 size_t* rectCount); | 47 size_t* rectCount); |
49 CG_EXTERN CFRunLoopSourceRef | 48 CG_EXTERN CFRunLoopSourceRef |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 | 685 |
687 MacDisplayConfigurations displays_to_capture; | 686 MacDisplayConfigurations displays_to_capture; |
688 if (current_display_) { | 687 if (current_display_) { |
689 // Capturing a single screen. Note that the screen id may change when | 688 // Capturing a single screen. Note that the screen id may change when |
690 // screens are added or removed. | 689 // screens are added or removed. |
691 const MacDisplayConfiguration* config = | 690 const MacDisplayConfiguration* config = |
692 desktop_config_.FindDisplayConfigurationById(current_display_); | 691 desktop_config_.FindDisplayConfigurationById(current_display_); |
693 if (config) { | 692 if (config) { |
694 displays_to_capture.push_back(*config); | 693 displays_to_capture.push_back(*config); |
695 } else { | 694 } else { |
696 LOG(LS_ERROR) << "The selected screen cannot be found for capturing."; | |
697 return false; | 695 return false; |
698 } | 696 } |
699 } else { | 697 } else { |
700 // Capturing the whole desktop. | 698 // Capturing the whole desktop. |
701 displays_to_capture = desktop_config_.displays; | 699 displays_to_capture = desktop_config_.displays; |
702 } | 700 } |
703 | 701 |
704 // Create the window list once for all displays. | 702 // Create the window list once for all displays. |
705 CFArrayRef window_list = CreateWindowListWithExclusion(excluded_window_); | 703 CFArrayRef window_list = CreateWindowListWithExclusion(excluded_window_); |
706 | 704 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 CGImageRef image = CGDisplayCreateImage(display_config.id); | 747 CGImageRef image = CGDisplayCreateImage(display_config.id); |
750 if (!image) { | 748 if (!image) { |
751 if (excluded_image) | 749 if (excluded_image) |
752 CFRelease(excluded_image); | 750 CFRelease(excluded_image); |
753 continue; | 751 continue; |
754 } | 752 } |
755 | 753 |
756 // Verify that the image has 32-bit depth. | 754 // Verify that the image has 32-bit depth. |
757 int bits_per_pixel = CGImageGetBitsPerPixel(image); | 755 int bits_per_pixel = CGImageGetBitsPerPixel(image); |
758 if (bits_per_pixel / 8 != DesktopFrame::kBytesPerPixel) { | 756 if (bits_per_pixel / 8 != DesktopFrame::kBytesPerPixel) { |
759 LOG(LS_ERROR) << "CGDisplayCreateImage() returned imaged with " | |
760 << bits_per_pixel | |
761 << " bits per pixel. Only 32-bit depth is supported."; | |
762 CFRelease(image); | 757 CFRelease(image); |
763 if (excluded_image) | 758 if (excluded_image) |
764 CFRelease(excluded_image); | 759 CFRelease(excluded_image); |
765 return false; | 760 return false; |
766 } | 761 } |
767 | 762 |
768 // Request access to the raw pixel data via the image's DataProvider. | 763 // Request access to the raw pixel data via the image's DataProvider. |
769 CGDataProviderRef provider = CGImageGetDataProvider(image); | 764 CGDataProviderRef provider = CGImageGetDataProvider(image); |
770 CFDataRef data = CGDataProviderCopyData(provider); | 765 CFDataRef data = CGDataProviderCopyData(provider); |
771 assert(data); | 766 assert(data); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 helper_.InvalidateScreen(screen_pixel_bounds_.size()); | 839 helper_.InvalidateScreen(screen_pixel_bounds_.size()); |
845 | 840 |
846 // Make sure the frame buffers will be reallocated. | 841 // Make sure the frame buffers will be reallocated. |
847 queue_.Reset(); | 842 queue_.Reset(); |
848 | 843 |
849 // CgBlitPostLion uses CGDisplayCreateImage() to snapshot each display's | 844 // CgBlitPostLion uses CGDisplayCreateImage() to snapshot each display's |
850 // contents. Although the API exists in OS 10.6, it crashes the caller if | 845 // contents. Although the API exists in OS 10.6, it crashes the caller if |
851 // the machine has no monitor connected, so we fall back to depcreated APIs | 846 // the machine has no monitor connected, so we fall back to depcreated APIs |
852 // when running on 10.6. | 847 // when running on 10.6. |
853 if (rtc::GetOSVersionName() >= rtc::kMacOSLion) { | 848 if (rtc::GetOSVersionName() >= rtc::kMacOSLion) { |
854 LOG(LS_INFO) << "Using CgBlitPostLion."; | |
855 // No need for any OpenGL support on Lion | 849 // No need for any OpenGL support on Lion |
856 return; | 850 return; |
857 } | 851 } |
858 | 852 |
859 // Dynamically link to the deprecated pre-Lion capture APIs. | 853 // Dynamically link to the deprecated pre-Lion capture APIs. |
860 app_services_library_ = dlopen(kApplicationServicesLibraryName, | 854 app_services_library_ = dlopen(kApplicationServicesLibraryName, |
861 RTLD_LAZY); | 855 RTLD_LAZY); |
862 if (!app_services_library_) { | 856 if (!app_services_library_) { |
863 LOG_F(LS_ERROR) << "Failed to open " << kApplicationServicesLibraryName; | |
864 abort(); | 857 abort(); |
865 } | 858 } |
866 | 859 |
867 opengl_library_ = dlopen(kOpenGlLibraryName, RTLD_LAZY); | 860 opengl_library_ = dlopen(kOpenGlLibraryName, RTLD_LAZY); |
868 if (!opengl_library_) { | 861 if (!opengl_library_) { |
869 LOG_F(LS_ERROR) << "Failed to open " << kOpenGlLibraryName; | |
870 abort(); | 862 abort(); |
871 } | 863 } |
872 | 864 |
873 cg_display_base_address_ = reinterpret_cast<CGDisplayBaseAddressFunc>( | 865 cg_display_base_address_ = reinterpret_cast<CGDisplayBaseAddressFunc>( |
874 dlsym(app_services_library_, "CGDisplayBaseAddress")); | 866 dlsym(app_services_library_, "CGDisplayBaseAddress")); |
875 cg_display_bytes_per_row_ = reinterpret_cast<CGDisplayBytesPerRowFunc>( | 867 cg_display_bytes_per_row_ = reinterpret_cast<CGDisplayBytesPerRowFunc>( |
876 dlsym(app_services_library_, "CGDisplayBytesPerRow")); | 868 dlsym(app_services_library_, "CGDisplayBytesPerRow")); |
877 cg_display_bits_per_pixel_ = reinterpret_cast<CGDisplayBitsPerPixelFunc>( | 869 cg_display_bits_per_pixel_ = reinterpret_cast<CGDisplayBitsPerPixelFunc>( |
878 dlsym(app_services_library_, "CGDisplayBitsPerPixel")); | 870 dlsym(app_services_library_, "CGDisplayBitsPerPixel")); |
879 cgl_set_full_screen_ = reinterpret_cast<CGLSetFullScreenFunc>( | 871 cgl_set_full_screen_ = reinterpret_cast<CGLSetFullScreenFunc>( |
880 dlsym(opengl_library_, "CGLSetFullScreen")); | 872 dlsym(opengl_library_, "CGLSetFullScreen")); |
881 if (!(cg_display_base_address_ && cg_display_bytes_per_row_ && | 873 if (!(cg_display_base_address_ && cg_display_bytes_per_row_ && |
882 cg_display_bits_per_pixel_ && cgl_set_full_screen_)) { | 874 cg_display_bits_per_pixel_ && cgl_set_full_screen_)) { |
883 LOG_F(LS_ERROR); | |
884 abort(); | 875 abort(); |
885 } | 876 } |
886 | 877 |
887 if (desktop_config_.displays.size() > 1) { | 878 if (desktop_config_.displays.size() > 1) { |
888 LOG(LS_INFO) << "Using CgBlitPreLion (Multi-monitor)."; | |
889 return; | 879 return; |
890 } | 880 } |
891 | 881 |
892 CGDirectDisplayID mainDevice = CGMainDisplayID(); | 882 CGDirectDisplayID mainDevice = CGMainDisplayID(); |
893 if (!CGDisplayUsesOpenGLAcceleration(mainDevice)) { | 883 if (!CGDisplayUsesOpenGLAcceleration(mainDevice)) { |
894 LOG(LS_INFO) << "Using CgBlitPreLion (OpenGL unavailable)."; | |
895 return; | 884 return; |
896 } | 885 } |
897 | 886 |
898 LOG(LS_INFO) << "Using GlBlit"; | |
899 | |
900 CGLPixelFormatAttribute attributes[] = { | 887 CGLPixelFormatAttribute attributes[] = { |
901 // This function does an early return if GetOSVersionName() >= kMacOSLion, | 888 // This function does an early return if GetOSVersionName() >= kMacOSLion, |
902 // this code only runs on 10.6 and can be deleted once 10.6 support is | 889 // this code only runs on 10.6 and can be deleted once 10.6 support is |
903 // dropped. So just keep using kCGLPFAFullScreen even though it was | 890 // dropped. So just keep using kCGLPFAFullScreen even though it was |
904 // deprecated in 10.6 -- it's still functional there, and it's not used on | 891 // deprecated in 10.6 -- it's still functional there, and it's not used on |
905 // newer OS X versions. | 892 // newer OS X versions. |
906 #pragma clang diagnostic push | 893 #pragma clang diagnostic push |
907 #pragma clang diagnostic ignored "-Wdeprecated-declarations" | 894 #pragma clang diagnostic ignored "-Wdeprecated-declarations" |
908 kCGLPFAFullScreen, | 895 kCGLPFAFullScreen, |
909 #pragma clang diagnostic pop | 896 #pragma clang diagnostic pop |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 std::unique_ptr<ScreenCapturerMac> capturer( | 1023 std::unique_ptr<ScreenCapturerMac> capturer( |
1037 new ScreenCapturerMac(options.configuration_monitor())); | 1024 new ScreenCapturerMac(options.configuration_monitor())); |
1038 if (!capturer.get()->Init()) { | 1025 if (!capturer.get()->Init()) { |
1039 return nullptr; | 1026 return nullptr; |
1040 } | 1027 } |
1041 | 1028 |
1042 return capturer; | 1029 return capturer; |
1043 } | 1030 } |
1044 | 1031 |
1045 } // namespace webrtc | 1032 } // namespace webrtc |
OLD | NEW |