OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/host/video_frame_capturer.h" | 5 #include "remoting/host/video_frame_capturer.h" |
6 | 6 |
7 #include <ApplicationServices/ApplicationServices.h> | 7 #include <ApplicationServices/ApplicationServices.h> |
8 #include <Cocoa/Cocoa.h> | 8 #include <Cocoa/Cocoa.h> |
9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
10 #include <IOKit/pwr_mgt/IOPMLib.h> | 10 #include <IOKit/pwr_mgt/IOPMLib.h> |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
650 // Release existing buffers, which will be of the wrong size. | 650 // Release existing buffers, which will be of the wrong size. |
651 ReleaseBuffers(); | 651 ReleaseBuffers(); |
652 last_buffer_ = NULL; | 652 last_buffer_ = NULL; |
653 | 653 |
654 // Clear the dirty region, in case the display is down-sizing. | 654 // Clear the dirty region, in case the display is down-sizing. |
655 helper_.ClearInvalidRegion(); | 655 helper_.ClearInvalidRegion(); |
656 | 656 |
657 // Fetch the list if active displays and calculate their bounds. | 657 // Fetch the list if active displays and calculate their bounds. |
658 CGDisplayCount display_count; | 658 CGDisplayCount display_count; |
659 CGError error = CGGetActiveDisplayList(0, NULL, &display_count); | 659 CGError error = CGGetActiveDisplayList(0, NULL, &display_count); |
660 CHECK_EQ(error, CGDisplayNoErr); | 660 CHECK_EQ(error, CGDisplayNoErr); |
Wez
2012/10/22 23:40:43
Add a DLOG_IF() here that logs when |display_count
| |
661 | 661 |
662 display_ids_.resize(display_count); | 662 display_ids_.resize(display_count); |
663 error = CGGetActiveDisplayList(display_count, &display_ids_[0], | 663 error = CGGetActiveDisplayList(display_count, &display_ids_[0], |
664 &display_count); | 664 &display_count); |
665 CHECK_EQ(error, CGDisplayNoErr); | 665 CHECK_EQ(error, CGDisplayNoErr); |
666 CHECK_EQ(display_count, display_ids_.size()); | 666 CHECK_EQ(display_count, display_ids_.size()); |
667 | 667 |
668 desktop_bounds_ = SkIRect::MakeEmpty(); | 668 desktop_bounds_ = SkIRect::MakeEmpty(); |
669 for (unsigned int d = 0; d < display_count; ++d) { | 669 for (unsigned int d = 0; d < display_count; ++d) { |
670 CGRect display_bounds = CGDisplayBounds(display_ids_[d]); | 670 CGRect display_bounds = CGDisplayBounds(display_ids_[d]); |
Wez
2012/10/22 23:40:43
Add a DLOG_IF() here that logs if |display_bounds.
| |
671 desktop_bounds_.join(CGRectToSkIRect(display_bounds)); | 671 desktop_bounds_.join(CGRectToSkIRect(display_bounds)); |
672 } | 672 } |
673 | 673 |
674 // Re-mark the entire desktop as dirty. | 674 // Re-mark the entire desktop as dirty. |
675 helper_.InvalidateScreen(SkISize::Make(desktop_bounds_.width(), | 675 helper_.InvalidateScreen(SkISize::Make(desktop_bounds_.width(), |
676 desktop_bounds_.height())); | 676 desktop_bounds_.height())); |
677 | 677 |
678 // CgBlitPostLion uses CGDisplayCreateImage() to snapshot each display's | 678 // CgBlitPostLion uses CGDisplayCreateImage() to snapshot each display's |
679 // contents. Although the API exists in OS 10.6, it crashes the caller if | 679 // contents. Although the API exists in OS 10.6, it crashes the caller if |
680 // the machine has no monitor connected, so we fall back to depcreated APIs | 680 // the machine has no monitor connected, so we fall back to depcreated APIs |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
740 (*cgl_set_full_screen_)(cgl_context_); | 740 (*cgl_set_full_screen_)(cgl_context_); |
741 CGLSetCurrentContext(cgl_context_); | 741 CGLSetCurrentContext(cgl_context_); |
742 | 742 |
743 size_t buffer_size = desktop_bounds_.width() * desktop_bounds_.height() * | 743 size_t buffer_size = desktop_bounds_.width() * desktop_bounds_.height() * |
744 sizeof(uint32_t); | 744 sizeof(uint32_t); |
745 pixel_buffer_object_.Init(cgl_context_, buffer_size); | 745 pixel_buffer_object_.Init(cgl_context_, buffer_size); |
746 } | 746 } |
747 | 747 |
748 void VideoFrameCapturerMac::ScreenRefresh(CGRectCount count, | 748 void VideoFrameCapturerMac::ScreenRefresh(CGRectCount count, |
749 const CGRect* rect_array) { | 749 const CGRect* rect_array) { |
750 DCHECK(!desktop_bounds_.isEmpty()); | |
750 SkIRect skirect_array[count]; | 751 SkIRect skirect_array[count]; |
751 for (CGRectCount i = 0; i < count; ++i) { | 752 for (CGRectCount i = 0; i < count; ++i) { |
752 skirect_array[i] = CGRectToSkIRect(rect_array[i]); | 753 skirect_array[i] = CGRectToSkIRect(rect_array[i]); |
753 skirect_array[i].offset(-desktop_bounds_.left(), -desktop_bounds_.top()); | 754 skirect_array[i].offset(-desktop_bounds_.left(), -desktop_bounds_.top()); |
754 } | 755 } |
755 SkRegion region; | 756 SkRegion region; |
756 region.setRects(skirect_array, count); | 757 region.setRects(skirect_array, count); |
757 InvalidateRegion(region); | 758 InvalidateRegion(region); |
758 } | 759 } |
759 | 760 |
(...skipping 29 matching lines...) Expand all Loading... | |
789 display_configuration_capture_event_.Signal(); | 790 display_configuration_capture_event_.Signal(); |
790 } | 791 } |
791 } | 792 } |
792 } | 793 } |
793 | 794 |
794 void VideoFrameCapturerMac::ScreenRefreshCallback(CGRectCount count, | 795 void VideoFrameCapturerMac::ScreenRefreshCallback(CGRectCount count, |
795 const CGRect* rect_array, | 796 const CGRect* rect_array, |
796 void* user_parameter) { | 797 void* user_parameter) { |
797 VideoFrameCapturerMac* capturer = reinterpret_cast<VideoFrameCapturerMac*>( | 798 VideoFrameCapturerMac* capturer = reinterpret_cast<VideoFrameCapturerMac*>( |
798 user_parameter); | 799 user_parameter); |
800 if (capturer->desktop_bounds_.isEmpty()) { | |
801 capturer->ScreenConfigurationChanged(); | |
802 } | |
Jamie
2012/10/22 21:14:25
ScreenConfigurationChanged is supposed to be calle
| |
799 capturer->ScreenRefresh(count, rect_array); | 803 capturer->ScreenRefresh(count, rect_array); |
800 } | 804 } |
801 | 805 |
802 void VideoFrameCapturerMac::ScreenUpdateMoveCallback( | 806 void VideoFrameCapturerMac::ScreenUpdateMoveCallback( |
803 CGScreenUpdateMoveDelta delta, | 807 CGScreenUpdateMoveDelta delta, |
804 size_t count, | 808 size_t count, |
805 const CGRect* rect_array, | 809 const CGRect* rect_array, |
806 void* user_parameter) { | 810 void* user_parameter) { |
807 VideoFrameCapturerMac* capturer = reinterpret_cast<VideoFrameCapturerMac*>( | 811 VideoFrameCapturerMac* capturer = reinterpret_cast<VideoFrameCapturerMac*>( |
808 user_parameter); | 812 user_parameter); |
(...skipping 15 matching lines...) Expand all Loading... | |
824 VideoFrameCapturer* VideoFrameCapturer::Create() { | 828 VideoFrameCapturer* VideoFrameCapturer::Create() { |
825 VideoFrameCapturerMac* capturer = new VideoFrameCapturerMac(); | 829 VideoFrameCapturerMac* capturer = new VideoFrameCapturerMac(); |
826 if (!capturer->Init()) { | 830 if (!capturer->Init()) { |
827 delete capturer; | 831 delete capturer; |
828 capturer = NULL; | 832 capturer = NULL; |
829 } | 833 } |
830 return capturer; | 834 return capturer; |
831 } | 835 } |
832 | 836 |
833 } // namespace remoting | 837 } // namespace remoting |
OLD | NEW |