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 "media/video/capture/screen/screen_capturer.h" | 5 #include "media/video/capture/screen/screen_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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // A class to perform video frame capturing for mac. | 113 // A class to perform video frame capturing for mac. |
114 class ScreenCapturerMac : public ScreenCapturer { | 114 class ScreenCapturerMac : public ScreenCapturer { |
115 public: | 115 public: |
116 ScreenCapturerMac(); | 116 ScreenCapturerMac(); |
117 virtual ~ScreenCapturerMac(); | 117 virtual ~ScreenCapturerMac(); |
118 | 118 |
119 bool Init(); | 119 bool Init(); |
120 | 120 |
121 // Overridden from ScreenCapturer: | 121 // Overridden from ScreenCapturer: |
122 virtual void Start(Delegate* delegate) OVERRIDE; | 122 virtual void Start(Delegate* delegate) OVERRIDE; |
123 virtual void Stop() OVERRIDE; | |
124 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; | |
125 virtual void CaptureFrame() OVERRIDE; | 123 virtual void CaptureFrame() OVERRIDE; |
126 | 124 |
127 private: | 125 private: |
128 void CaptureCursor(); | 126 void CaptureCursor(); |
129 | 127 |
130 void GlBlitFast(const ScreenCaptureFrame& buffer, const SkRegion& region); | 128 void GlBlitFast(const ScreenCaptureFrame& buffer, const SkRegion& region); |
131 void GlBlitSlow(const ScreenCaptureFrame& buffer); | 129 void GlBlitSlow(const ScreenCaptureFrame& buffer); |
132 void CgBlitPreLion(const ScreenCaptureFrame& buffer, const SkRegion& region); | 130 void CgBlitPreLion(const ScreenCaptureFrame& buffer, const SkRegion& region); |
133 void CgBlitPostLion(const ScreenCaptureFrame& buffer, const SkRegion& region); | 131 void CgBlitPostLion(const ScreenCaptureFrame& buffer, const SkRegion& region); |
134 | 132 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 power_assertion_id_display_(kIOPMNullAssertionID), | 226 power_assertion_id_display_(kIOPMNullAssertionID), |
229 power_assertion_id_user_(kIOPMNullAssertionID), | 227 power_assertion_id_user_(kIOPMNullAssertionID), |
230 cg_display_base_address_(NULL), | 228 cg_display_base_address_(NULL), |
231 cg_display_bytes_per_row_(NULL), | 229 cg_display_bytes_per_row_(NULL), |
232 cg_display_bits_per_pixel_(NULL), | 230 cg_display_bits_per_pixel_(NULL), |
233 cgl_set_full_screen_(NULL) | 231 cgl_set_full_screen_(NULL) |
234 { | 232 { |
235 } | 233 } |
236 | 234 |
237 ScreenCapturerMac::~ScreenCapturerMac() { | 235 ScreenCapturerMac::~ScreenCapturerMac() { |
| 236 if (power_assertion_id_display_ != kIOPMNullAssertionID) { |
| 237 IOPMAssertionRelease(power_assertion_id_display_); |
| 238 power_assertion_id_display_ = kIOPMNullAssertionID; |
| 239 } |
| 240 if (power_assertion_id_user_ != kIOPMNullAssertionID) { |
| 241 IOPMAssertionRelease(power_assertion_id_user_); |
| 242 power_assertion_id_user_ = kIOPMNullAssertionID; |
| 243 } |
| 244 |
238 ReleaseBuffers(); | 245 ReleaseBuffers(); |
239 UnregisterRefreshAndMoveHandlers(); | 246 UnregisterRefreshAndMoveHandlers(); |
240 CGError err = CGDisplayRemoveReconfigurationCallback( | 247 CGError err = CGDisplayRemoveReconfigurationCallback( |
241 ScreenCapturerMac::DisplaysReconfiguredCallback, this); | 248 ScreenCapturerMac::DisplaysReconfiguredCallback, this); |
242 if (err != kCGErrorSuccess) { | 249 if (err != kCGErrorSuccess) { |
243 LOG(ERROR) << "CGDisplayRemoveReconfigurationCallback " << err; | 250 LOG(ERROR) << "CGDisplayRemoveReconfigurationCallback " << err; |
244 } | 251 } |
245 } | 252 } |
246 | 253 |
247 bool ScreenCapturerMac::Init() { | 254 bool ScreenCapturerMac::Init() { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 CFSTR("Chrome Remote Desktop connection active"), | 293 CFSTR("Chrome Remote Desktop connection active"), |
287 &power_assertion_id_display_); | 294 &power_assertion_id_display_); |
288 // This assertion ensures that the display is woken up if it already asleep | 295 // This assertion ensures that the display is woken up if it already asleep |
289 // (as used by Apple Remote Desktop). | 296 // (as used by Apple Remote Desktop). |
290 IOPMAssertionCreateWithName(CFSTR("UserIsActive"), | 297 IOPMAssertionCreateWithName(CFSTR("UserIsActive"), |
291 kIOPMAssertionLevelOn, | 298 kIOPMAssertionLevelOn, |
292 CFSTR("Chrome Remote Desktop connection active"), | 299 CFSTR("Chrome Remote Desktop connection active"), |
293 &power_assertion_id_user_); | 300 &power_assertion_id_user_); |
294 } | 301 } |
295 | 302 |
296 void ScreenCapturerMac::Stop() { | |
297 if (power_assertion_id_display_ != kIOPMNullAssertionID) { | |
298 IOPMAssertionRelease(power_assertion_id_display_); | |
299 power_assertion_id_display_ = kIOPMNullAssertionID; | |
300 } | |
301 if (power_assertion_id_user_ != kIOPMNullAssertionID) { | |
302 IOPMAssertionRelease(power_assertion_id_user_); | |
303 power_assertion_id_user_ = kIOPMNullAssertionID; | |
304 } | |
305 } | |
306 | |
307 void ScreenCapturerMac::InvalidateRegion(const SkRegion& invalid_region) { | |
308 helper_.InvalidateRegion(invalid_region); | |
309 } | |
310 | |
311 void ScreenCapturerMac::CaptureFrame() { | 303 void ScreenCapturerMac::CaptureFrame() { |
312 // Only allow captures when the display configuration is not occurring. | 304 // Only allow captures when the display configuration is not occurring. |
313 scoped_refptr<ScreenCaptureData> data; | 305 scoped_refptr<ScreenCaptureData> data; |
314 | 306 |
315 base::Time capture_start_time = base::Time::Now(); | 307 base::Time capture_start_time = base::Time::Now(); |
316 | 308 |
317 // Wait until the display configuration is stable. If one or more displays | 309 // Wait until the display configuration is stable. If one or more displays |
318 // are reconfiguring then |display_configuration_capture_event_| will not be | 310 // are reconfiguring then |display_configuration_capture_event_| will not be |
319 // set until the reconfiguration completes. | 311 // set until the reconfiguration completes. |
320 // TODO(wez): Replace this with an early-exit (See crbug.com/104542). | 312 // TODO(wez): Replace this with an early-exit (See crbug.com/104542). |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 sk_rect = ScaleSkRect(sk_rect, desktop_config_.dip_to_pixel_scale); | 780 sk_rect = ScaleSkRect(sk_rect, desktop_config_.dip_to_pixel_scale); |
789 sk_rect.round(&skirect_array[i]); | 781 sk_rect.round(&skirect_array[i]); |
790 | 782 |
791 // Translate from local desktop to capturer framebuffer coordinates. | 783 // Translate from local desktop to capturer framebuffer coordinates. |
792 skirect_array[i].offset(-desktop_config_.pixel_bounds.left(), | 784 skirect_array[i].offset(-desktop_config_.pixel_bounds.left(), |
793 -desktop_config_.pixel_bounds.top()); | 785 -desktop_config_.pixel_bounds.top()); |
794 } | 786 } |
795 | 787 |
796 SkRegion region; | 788 SkRegion region; |
797 region.setRects(skirect_array, count); | 789 region.setRects(skirect_array, count); |
798 InvalidateRegion(region); | 790 helper_.InvalidateRegion(region); |
799 } | 791 } |
800 | 792 |
801 void ScreenCapturerMac::ScreenUpdateMove(CGScreenUpdateMoveDelta delta, | 793 void ScreenCapturerMac::ScreenUpdateMove(CGScreenUpdateMoveDelta delta, |
802 size_t count, | 794 size_t count, |
803 const CGRect* rect_array) { | 795 const CGRect* rect_array) { |
804 // Translate |rect_array| to identify the move's destination. | 796 // Translate |rect_array| to identify the move's destination. |
805 CGRect refresh_rects[count]; | 797 CGRect refresh_rects[count]; |
806 for (CGRectCount i = 0; i < count; ++i) { | 798 for (CGRectCount i = 0; i < count; ++i) { |
807 refresh_rects[i] = CGRectOffset(rect_array[i], delta.dX, delta.dY); | 799 refresh_rects[i] = CGRectOffset(rect_array[i], delta.dX, delta.dY); |
808 } | 800 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 | 877 |
886 // static | 878 // static |
887 scoped_ptr<ScreenCapturer> ScreenCapturer::Create() { | 879 scoped_ptr<ScreenCapturer> ScreenCapturer::Create() { |
888 scoped_ptr<ScreenCapturerMac> capturer(new ScreenCapturerMac()); | 880 scoped_ptr<ScreenCapturerMac> capturer(new ScreenCapturerMac()); |
889 if (!capturer->Init()) | 881 if (!capturer->Init()) |
890 capturer.reset(); | 882 capturer.reset(); |
891 return capturer.PassAs<ScreenCapturer>(); | 883 return capturer.PassAs<ScreenCapturer>(); |
892 } | 884 } |
893 | 885 |
894 } // namespace media | 886 } // namespace media |
OLD | NEW |