Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: webrtc/modules/desktop_capture/screen_capturer_mac.mm

Issue 2740823002: mac: Fix screen capture for whole-desktop capture. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 // Returns false if the selected screen is no longer valid. 297 // Returns false if the selected screen is no longer valid.
298 bool CgBlitPostLion(const DesktopFrame& frame, 298 bool CgBlitPostLion(const DesktopFrame& frame,
299 const DesktopRegion& region); 299 const DesktopRegion& region);
300 300
301 // Called when the screen configuration is changed. 301 // Called when the screen configuration is changed.
302 void ScreenConfigurationChanged(); 302 void ScreenConfigurationChanged();
303 303
304 bool RegisterRefreshAndMoveHandlers(); 304 bool RegisterRefreshAndMoveHandlers();
305 void UnregisterRefreshAndMoveHandlers(); 305 void UnregisterRefreshAndMoveHandlers();
306 306
307 void ScreenRefresh(CGRectCount count, const CGRect *rect_array); 307 void ScreenRefresh(CGRectCount count,
308 const CGRect *rect_array,
309 DesktopVector display_origin);
308 void ReleaseBuffers(); 310 void ReleaseBuffers();
309 311
310 std::unique_ptr<DesktopFrame> CreateFrame(); 312 std::unique_ptr<DesktopFrame> CreateFrame();
311 313
312 Callback* callback_ = nullptr; 314 Callback* callback_ = nullptr;
313 315
314 CGLContextObj cgl_context_ = nullptr; 316 CGLContextObj cgl_context_ = nullptr;
315 ScopedPixelBufferObject pixel_buffer_object_; 317 ScopedPixelBufferObject pixel_buffer_object_;
316 318
317 // Queue of the frames buffers. 319 // Queue of the frames buffers.
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 desktop_config_ = desktop_config_monitor_->desktop_configuration(); 933 desktop_config_ = desktop_config_monitor_->desktop_configuration();
932 for (const auto& config : desktop_config_.displays) { 934 for (const auto& config : desktop_config_.displays) {
933 size_t pixel_width = config.pixel_bounds.width(); 935 size_t pixel_width = config.pixel_bounds.width();
934 size_t pixel_height = config.pixel_bounds.height(); 936 size_t pixel_height = config.pixel_bounds.height();
935 if (pixel_width == 0 || pixel_height == 0) 937 if (pixel_width == 0 || pixel_height == 0)
936 continue; 938 continue;
937 // Using a local variable forces the block to capture the raw pointer. 939 // Using a local variable forces the block to capture the raw pointer.
938 DisplayStreamManager* manager = display_stream_manager_; 940 DisplayStreamManager* manager = display_stream_manager_;
939 int unique_id = manager->GetUniqueId(); 941 int unique_id = manager->GetUniqueId();
940 CGDirectDisplayID display_id = config.id; 942 CGDirectDisplayID display_id = config.id;
943 DesktopVector display_origin = config.pixel_bounds.top_left();
944
941 CGDisplayStreamFrameAvailableHandler handler = 945 CGDisplayStreamFrameAvailableHandler handler =
942 ^(CGDisplayStreamFrameStatus status, uint64_t display_time, 946 ^(CGDisplayStreamFrameStatus status, uint64_t display_time,
943 IOSurfaceRef frame_surface, CGDisplayStreamUpdateRef updateRef) { 947 IOSurfaceRef frame_surface, CGDisplayStreamUpdateRef updateRef) {
944 if (status == kCGDisplayStreamFrameStatusStopped) { 948 if (status == kCGDisplayStreamFrameStatusStopped) {
945 manager->DestroyStream(unique_id); 949 manager->DestroyStream(unique_id);
946 return; 950 return;
947 } 951 }
948 952
949 if (manager->ShouldIgnoreUpdates()) 953 if (manager->ShouldIgnoreUpdates())
950 return; 954 return;
951 955
952 // Only pay attention to frame updates. 956 // Only pay attention to frame updates.
953 if (status != kCGDisplayStreamFrameStatusFrameComplete) 957 if (status != kCGDisplayStreamFrameStatusFrameComplete)
954 return; 958 return;
955 959
956 size_t count = 0; 960 size_t count = 0;
957 const CGRect* rects = CGDisplayStreamUpdateGetRects( 961 const CGRect* rects = CGDisplayStreamUpdateGetRects(
958 updateRef, kCGDisplayStreamUpdateDirtyRects, &count); 962 updateRef, kCGDisplayStreamUpdateDirtyRects, &count);
959 if (count != 0) { 963 if (count != 0) {
960 // According to CGDisplayStream.h, it's safe to call 964 // According to CGDisplayStream.h, it's safe to call
961 // CGDisplayStreamStop() from within the callback. 965 // CGDisplayStreamStop() from within the callback.
962 ScreenRefresh(count, rects); 966 ScreenRefresh(count, rects, display_origin);
963 } 967 }
964 }; 968 };
965 CGDisplayStreamRef display_stream = CGDisplayStreamCreate( 969 CGDisplayStreamRef display_stream = CGDisplayStreamCreate(
966 display_id, pixel_width, pixel_height, 'BGRA', nullptr, handler); 970 display_id, pixel_width, pixel_height, 'BGRA', nullptr, handler);
967 971
968 if (display_stream) { 972 if (display_stream) {
969 CGError error = CGDisplayStreamStart(display_stream); 973 CGError error = CGDisplayStreamStart(display_stream);
970 if (error != kCGErrorSuccess) 974 if (error != kCGErrorSuccess)
971 return false; 975 return false;
972 976
973 CFRunLoopSourceRef source = 977 CFRunLoopSourceRef source =
974 CGDisplayStreamGetRunLoopSource(display_stream); 978 CGDisplayStreamGetRunLoopSource(display_stream);
975 CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode); 979 CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
976 display_stream_manager_->SaveStream(unique_id, display_stream); 980 display_stream_manager_->SaveStream(unique_id, display_stream);
977 } 981 }
978 } 982 }
979 983
980 return true; 984 return true;
981 } 985 }
982 986
983 void ScreenCapturerMac::UnregisterRefreshAndMoveHandlers() { 987 void ScreenCapturerMac::UnregisterRefreshAndMoveHandlers() {
984 display_stream_manager_->UnregisterActiveStreams(); 988 display_stream_manager_->UnregisterActiveStreams();
985 } 989 }
986 990
987 void ScreenCapturerMac::ScreenRefresh(CGRectCount count, 991 void ScreenCapturerMac::ScreenRefresh(CGRectCount count,
988 const CGRect* rect_array) { 992 const CGRect* rect_array,
993 DesktopVector display_origin) {
989 if (screen_pixel_bounds_.is_empty()) 994 if (screen_pixel_bounds_.is_empty())
990 ScreenConfigurationChanged(); 995 ScreenConfigurationChanged();
991 996
997 // The refresh rects are in display coordinates. We want to translate to
998 // framebuffer coordinates. If a specific display is being captured, then no
999 // change is necessary. If all displays are being captured, then we want to
1000 // translate by the origin of the display.
1001 DesktopVector translate_vector;
1002 if (!current_display_)
1003 translate_vector = display_origin;
1004
992 DesktopRegion region; 1005 DesktopRegion region;
993 for (CGRectCount i = 0; i < count; ++i) { 1006 for (CGRectCount i = 0; i < count; ++i) {
994 // All rects are already in physical pixel coordinates. 1007 // All rects are already in physical pixel coordinates.
995 DesktopRect rect = DesktopRect::MakeXYWH( 1008 DesktopRect rect = DesktopRect::MakeXYWH(
996 rect_array[i].origin.x, rect_array[i].origin.y, 1009 rect_array[i].origin.x, rect_array[i].origin.y,
997 rect_array[i].size.width, rect_array[i].size.height); 1010 rect_array[i].size.width, rect_array[i].size.height);
1011
1012 rect.Translate(translate_vector);
1013
998 region.AddRect(rect); 1014 region.AddRect(rect);
999 } 1015 }
1000 1016
1001 helper_.InvalidateRegion(region); 1017 helper_.InvalidateRegion(region);
1002 } 1018 }
1003 1019
1004 std::unique_ptr<DesktopFrame> ScreenCapturerMac::CreateFrame() { 1020 std::unique_ptr<DesktopFrame> ScreenCapturerMac::CreateFrame() {
1005 std::unique_ptr<DesktopFrame> frame( 1021 std::unique_ptr<DesktopFrame> frame(
1006 new BasicDesktopFrame(screen_pixel_bounds_.size())); 1022 new BasicDesktopFrame(screen_pixel_bounds_.size()));
1007 frame->set_dpi(DesktopVector(kStandardDPI * dip_to_pixel_scale_, 1023 frame->set_dpi(DesktopVector(kStandardDPI * dip_to_pixel_scale_,
(...skipping 12 matching lines...) Expand all
1020 std::unique_ptr<ScreenCapturerMac> capturer( 1036 std::unique_ptr<ScreenCapturerMac> capturer(
1021 new ScreenCapturerMac(options.configuration_monitor())); 1037 new ScreenCapturerMac(options.configuration_monitor()));
1022 if (!capturer.get()->Init()) { 1038 if (!capturer.get()->Init()) {
1023 return nullptr; 1039 return nullptr;
1024 } 1040 }
1025 1041
1026 return capturer; 1042 return capturer;
1027 } 1043 }
1028 1044
1029 } // namespace webrtc 1045 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698