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

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

Issue 2588973002: Fix a screen capture issue on retina macOS devices. (Closed)
Patch Set: Fix. Created 4 years 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 ScreenUpdateMove(CGFloat delta_x,
308 CGFloat delta_y,
309 CGRectCount count,
310 const CGRect* rect_array);
307 void ScreenRefresh(CGRectCount count, const CGRect *rect_array); 311 void ScreenRefresh(CGRectCount count, const CGRect *rect_array);
308 void ReleaseBuffers(); 312 void ReleaseBuffers();
309 313
310 std::unique_ptr<DesktopFrame> CreateFrame(); 314 std::unique_ptr<DesktopFrame> CreateFrame();
311 315
312 Callback* callback_ = nullptr; 316 Callback* callback_ = nullptr;
313 317
314 CGLContextObj cgl_context_ = nullptr; 318 CGLContextObj cgl_context_ = nullptr;
315 ScopedPixelBufferObject pixel_buffer_object_; 319 ScopedPixelBufferObject pixel_buffer_object_;
316 320
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, kCGDisplayStreamUpdateMovedRects, &count);
Sergey Ulanov 2016/12/20 18:56:51 I would still prefer to use kCGDisplayStreamUpdate
959 if (count != 0) { 963 if (count != 0) {
960 // According to CGDisplayStream.h, it's safe to call 964 CGFloat dx = 0;
961 // CGDisplayStreamStop() from within the callback. 965 CGFloat dy = 0;
966 CGDisplayStreamUpdateGetMovedRectsDelta(updateRef, &dx, &dy);
967 ScreenUpdateMove(dx, dy, count, rects);
968 }
969
970 count = 0;
971 rects = CGDisplayStreamUpdateGetRects(
972 updateRef, kCGDisplayStreamUpdateRefreshedRects, &count);
973 if (count != 0) {
962 ScreenRefresh(count, rects); 974 ScreenRefresh(count, rects);
963 } 975 }
964 }; 976 };
965 CGDisplayStreamRef display_stream = CGDisplayStreamCreate( 977 CGDisplayStreamRef display_stream = CGDisplayStreamCreate(
966 display_id, pixel_width, pixel_height, 'BGRA', nullptr, handler); 978 display_id, pixel_width, pixel_height, 'BGRA', nullptr, handler);
967 979
968 if (display_stream) { 980 if (display_stream) {
969 CGError error = CGDisplayStreamStart(display_stream); 981 CGError error = CGDisplayStreamStart(display_stream);
970 if (error != kCGErrorSuccess) 982 if (error != kCGErrorSuccess)
971 return false; 983 return false;
972 984
973 CFRunLoopSourceRef source = 985 CFRunLoopSourceRef source =
974 CGDisplayStreamGetRunLoopSource(display_stream); 986 CGDisplayStreamGetRunLoopSource(display_stream);
975 CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode); 987 CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
976 display_stream_manager_->SaveStream(unique_id, display_stream); 988 display_stream_manager_->SaveStream(unique_id, display_stream);
977 } 989 }
978 } 990 }
979 991
980 return true; 992 return true;
981 } 993 }
982 994
983 void ScreenCapturerMac::UnregisterRefreshAndMoveHandlers() { 995 void ScreenCapturerMac::UnregisterRefreshAndMoveHandlers() {
984 display_stream_manager_->UnregisterActiveStreams(); 996 display_stream_manager_->UnregisterActiveStreams();
985 } 997 }
986 998
999 void ScreenCapturerMac::ScreenUpdateMove(CGFloat delta_x,
1000 CGFloat delta_y,
1001 CGRectCount count,
1002 const CGRect* rect_array) {
1003 // Refresh the source rects.
1004 ScreenRefresh(count, rect_array);
1005
1006 // Refresh the destination rects.
1007 CGRect refresh_rects[count];
1008 for (CGRectCount i = 0; i < count; ++i)
1009 refresh_rects[i] = CGRectOffset(rect_array[i], delta_x, delta_y);
1010 ScreenRefresh(count, refresh_rects);
1011 }
1012
987 void ScreenCapturerMac::ScreenRefresh(CGRectCount count, 1013 void ScreenCapturerMac::ScreenRefresh(CGRectCount count,
988 const CGRect* rect_array) { 1014 const CGRect* rect_array) {
989 if (screen_pixel_bounds_.is_empty()) 1015 if (screen_pixel_bounds_.is_empty())
990 ScreenConfigurationChanged(); 1016 ScreenConfigurationChanged();
991 1017
992 DesktopRegion region; 1018 DesktopRegion region;
993 for (CGRectCount i = 0; i < count; ++i) { 1019 for (CGRectCount i = 0; i < count; ++i) {
994 // Convert from Density-Independent Pixel to physical pixel coordinates. 1020 // All rects are already in physical pixel coordinates.
995 DesktopRect rect = ScaleAndRoundCGRect(rect_array[i], dip_to_pixel_scale_); 1021 DesktopRect rect = ScaleAndRoundCGRect(rect_array[i], 1.0);
Sergey Ulanov 2016/12/20 18:56:51 It would be cleaner to write this as DesktopRect:
996 region.AddRect(rect); 1022 region.AddRect(rect);
997 } 1023 }
998 1024
999 helper_.InvalidateRegion(region); 1025 helper_.InvalidateRegion(region);
1000 } 1026 }
1001 1027
1002 std::unique_ptr<DesktopFrame> ScreenCapturerMac::CreateFrame() { 1028 std::unique_ptr<DesktopFrame> ScreenCapturerMac::CreateFrame() {
1003 std::unique_ptr<DesktopFrame> frame( 1029 std::unique_ptr<DesktopFrame> frame(
1004 new BasicDesktopFrame(screen_pixel_bounds_.size())); 1030 new BasicDesktopFrame(screen_pixel_bounds_.size()));
1005 frame->set_dpi(DesktopVector(kStandardDPI * dip_to_pixel_scale_, 1031 frame->set_dpi(DesktopVector(kStandardDPI * dip_to_pixel_scale_,
(...skipping 12 matching lines...) Expand all
1018 std::unique_ptr<ScreenCapturerMac> capturer( 1044 std::unique_ptr<ScreenCapturerMac> capturer(
1019 new ScreenCapturerMac(options.configuration_monitor())); 1045 new ScreenCapturerMac(options.configuration_monitor()));
1020 if (!capturer.get()->Init()) { 1046 if (!capturer.get()->Init()) {
1021 return nullptr; 1047 return nullptr;
1022 } 1048 }
1023 1049
1024 return capturer; 1050 return capturer;
1025 } 1051 }
1026 1052
1027 } // namespace webrtc 1053 } // 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