diff options
author | dcaiafa@chromium.org <dcaiafa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-16 22:15:23 +0000 |
---|---|---|
committer | dcaiafa@chromium.org <dcaiafa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-16 22:15:23 +0000 |
commit | 7977afd39dc5367aa104a1a4bff7025d456d930a (patch) | |
tree | b876677e48d22ecb54499055c8a581aec036349b /remoting/host/capturer_mac.cc | |
parent | d6bad8d5c7c2882f9ca62e70bef3d9ea60a10ca1 (diff) | |
download | chromium_src-7977afd39dc5367aa104a1a4bff7025d456d930a.zip chromium_src-7977afd39dc5367aa104a1a4bff7025d456d930a.tar.gz chromium_src-7977afd39dc5367aa104a1a4bff7025d456d930a.tar.bz2 |
Wake Mac host display when remote session starts.
Create a power management assertion when a remote session starts. The power
assertion will wake the display if it's asleep and will keep it awake while the
remote session is in progress.
BUG=120429
TEST=manual
Review URL: http://codereview.chromium.org/10082032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132475 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/capturer_mac.cc')
-rw-r--r-- | remoting/host/capturer_mac.cc | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/remoting/host/capturer_mac.cc b/remoting/host/capturer_mac.cc index 42b362a..d24932c 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 kPowerAssertionTimeoutMs = 5 * 1000; // 5 seconds + 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 RefreshPowerAssertion(); + void ReleasePowerAssertion(); + CGLContextObj cgl_context_; static const int kNumBuffers = 2; scoped_pixel_buffer_object pixel_buffer_object_; @@ -221,6 +229,12 @@ 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 power_assertion_id_; + + // Timer to remove the power management assertion on inactivity + base::OneShotTimer<CapturerMac> power_assertion_timer_; + DISALLOW_COPY_AND_ASSIGN(CapturerMac); }; @@ -230,7 +244,8 @@ 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), + power_assertion_id_(kIOPMNullAssertionID) { } CapturerMac::~CapturerMac() { @@ -242,6 +257,7 @@ CapturerMac::~CapturerMac() { if (err != kCGErrorSuccess) { LOG(ERROR) << "CGDisplayRemoveReconfigurationCallback " << err; } + ReleasePowerAssertion(); } bool CapturerMac::Init() { @@ -360,6 +376,8 @@ void CapturerMac::CaptureInvalidRegion( // Only allow captures when the display configuration is not occurring. scoped_refptr<CaptureData> data; + RefreshPowerAssertion(); + // Critical section shared with DisplaysReconfigured(...). CHECK(display_configuration_capture_event_.TimedWait( base::TimeDelta::FromSeconds(kDisplayReconfigurationTimeoutInSeconds))); @@ -626,6 +644,36 @@ void CapturerMac::DisplaysReconfiguredCallback( capturer->DisplaysReconfigured(display, flags); } +// Creates or refreshes a power management assertion to prevent the display from +// going to sleep. +void CapturerMac::RefreshPowerAssertion() { + if (power_assertion_timer_.IsRunning()) { + DCHECK(power_assertion_id_ != kIOPMNullAssertionID); + power_assertion_timer_.Reset(); + return; + } + + IOReturn result = IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, + kIOPMAssertionLevelOn, + &power_assertion_id_); + + if (result == kIOReturnSuccess) { + power_assertion_timer_.Start(FROM_HERE, + base::TimeDelta::FromMilliseconds( + kPowerAssertionTimeoutMs), + this, + &CapturerMac::ReleasePowerAssertion); + } +} + +void CapturerMac::ReleasePowerAssertion() { + if (power_assertion_id_ != kIOPMNullAssertionID) { + IOPMAssertionRelease(power_assertion_id_); + power_assertion_id_ = kIOPMNullAssertionID; + power_assertion_timer_.Stop(); + } +} + } // namespace // static |