Index: remoting/host/capturer_mac.cc |
diff --git a/remoting/host/capturer_mac.cc b/remoting/host/capturer_mac.cc |
index 42b362afe3629843b6030a0a956235d9a9931d74..aae79923220001f8ec339fded8e1461714d636c2 100644 |
--- a/remoting/host/capturer_mac.cc |
+++ b/remoting/host/capturer_mac.cc |
@@ -6,6 +6,7 @@ |
#include <ApplicationServices/ApplicationServices.h> |
#include <dlfcn.h> |
+#include <IOKit/pwr_mgt/IOPMLib.h> |
#include <OpenGL/CGLMacro.h> |
#include <OpenGL/OpenGL.h> |
#include <stddef.h> |
@@ -15,6 +16,8 @@ |
#include "base/mac/scoped_cftyperef.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/synchronization/waitable_event.h" |
+#include "base/time.h" |
+#include "base/timer.h" |
#include "remoting/base/util.h" |
#include "remoting/host/capturer_helper.h" |
@@ -23,6 +26,8 @@ namespace remoting { |
namespace { |
+const int64 kPMAssertionTimeoutMs = 5 * 1000; // 30 seconds |
Wez
2012/04/14 00:08:22
This looks like five seconds, not thirty?
Wez
2012/04/14 00:08:22
See note below re naming.
dcaiafa
2012/04/14 00:21:41
Done.
dcaiafa
2012/04/14 00:21:41
Done.
|
+ |
SkIRect CGRectToSkIRect(const CGRect& rect) { |
SkIRect sk_rect = { |
SkScalarRound(rect.origin.x), |
@@ -192,6 +197,9 @@ class CapturerMac : public Capturer { |
void *user_parameter); |
void ReleaseBuffers(); |
+ void RefreshPowerManagementAssertion(); |
+ void ReleasePowerManagementAssertion(); |
+ |
CGLContextObj cgl_context_; |
static const int kNumBuffers = 2; |
scoped_pixel_buffer_object pixel_buffer_object_; |
@@ -221,6 +229,16 @@ class CapturerMac : public Capturer { |
// Will be non-null on lion. |
CGDisplayCreateImageFunc display_create_image_func_; |
+ // Power management assertion to prevent the screen from sleeping. |
+ IOPMAssertionID pm_assertion_id_; |
Wez
2012/04/14 00:08:22
Style guide requires that names not be abbreviated
dcaiafa
2012/04/14 00:21:41
Done.
|
+ |
+ // Indicates that a power management assertion was created and that |
+ // pm_assertion_id_ is valid. |
+ bool pm_assertion_created_; |
Wez
2012/04/14 00:08:22
Why not just check whether the timer is started, r
dcaiafa
2012/04/14 00:21:41
Because when ReleasePowerAssertion is called by th
Wez
2012/04/14 00:24:39
OK. Is zero a valid power management assertion Id
dcaiafa
2012/04/14 00:37:43
Turns out that there is a constant called kIOPMNul
|
+ |
+ // Timer to remove the power management assertion on inactivity |
+ base::OneShotTimer<CapturerMac> pm_assertion_timer_; |
+ |
DISALLOW_COPY_AND_ASSIGN(CapturerMac); |
}; |
@@ -230,7 +248,9 @@ CapturerMac::CapturerMac() |
last_buffer_(NULL), |
pixel_format_(media::VideoFrame::RGB32), |
display_configuration_capture_event_(false, true), |
- display_create_image_func_(NULL) { |
+ display_create_image_func_(NULL), |
+ pm_assertion_id_(0), |
+ pm_assertion_created_(false) { |
} |
CapturerMac::~CapturerMac() { |
@@ -242,6 +262,7 @@ CapturerMac::~CapturerMac() { |
if (err != kCGErrorSuccess) { |
LOG(ERROR) << "CGDisplayRemoveReconfigurationCallback " << err; |
} |
+ ReleasePowerManagementAssertion(); |
} |
bool CapturerMac::Init() { |
@@ -360,6 +381,8 @@ void CapturerMac::CaptureInvalidRegion( |
// Only allow captures when the display configuration is not occurring. |
scoped_refptr<CaptureData> data; |
+ RefreshPowerManagementAssertion(); |
+ |
// Critical section shared with DisplaysReconfigured(...). |
CHECK(display_configuration_capture_event_.TimedWait( |
base::TimeDelta::FromSeconds(kDisplayReconfigurationTimeoutInSeconds))); |
@@ -626,6 +649,38 @@ void CapturerMac::DisplaysReconfiguredCallback( |
capturer->DisplaysReconfigured(display, flags); |
} |
+// Creates or refreshes a power management assertion to prevent the display from |
+// going to sleep. |
+void CapturerMac::RefreshPowerManagementAssertion() { |
+ if (pm_assertion_timer_.IsRunning()) { |
+ DCHECK(pm_assertion_created_); |
+ pm_assertion_timer_.Reset(); |
+ return; |
+ } |
+ |
+ IOReturn result = IOPMAssertionCreateWithName( |
+ kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, |
+ CFSTR("Chromoting"), &pm_assertion_id_); |
+ |
+ if (result == kIOReturnSuccess) { |
+ pm_assertion_created_ = true; |
+ pm_assertion_timer_.Start(FROM_HERE, |
+ base::TimeDelta::FromMilliseconds( |
+ kPMAssertionTimeoutMs), |
+ this, |
+ &CapturerMac::ReleasePowerManagementAssertion); |
+ } |
+} |
+ |
+void CapturerMac::ReleasePowerManagementAssertion() { |
+ if (pm_assertion_created_) { |
+ IOPMAssertionRelease(pm_assertion_id_); |
+ pm_assertion_id_ = 0; |
Wez
2012/04/14 00:08:22
nit: Zeroing this when it's not started effectivel
dcaiafa
2012/04/14 00:21:41
Done.
|
+ pm_assertion_created_ = false; |
+ pm_assertion_timer_.Stop(); |
+ } |
+} |
+ |
} // namespace |
// static |