summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authordcaiafa@chromium.org <dcaiafa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-16 22:15:23 +0000
committerdcaiafa@chromium.org <dcaiafa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-16 22:15:23 +0000
commit7977afd39dc5367aa104a1a4bff7025d456d930a (patch)
treeb876677e48d22ecb54499055c8a581aec036349b /remoting
parentd6bad8d5c7c2882f9ca62e70bef3d9ea60a10ca1 (diff)
downloadchromium_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')
-rw-r--r--remoting/host/capturer_mac.cc50
-rw-r--r--remoting/host/capturer_mac_unittest.cc5
2 files changed, 53 insertions, 2 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
diff --git a/remoting/host/capturer_mac_unittest.cc b/remoting/host/capturer_mac_unittest.cc
index e6224ba..d5880e9 100644
--- a/remoting/host/capturer_mac_unittest.cc
+++ b/remoting/host/capturer_mac_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,6 +11,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace remoting {
@@ -28,6 +29,7 @@ class CapturerMacTest : public testing::Test {
scoped_ptr<Capturer> capturer_;
SkRegion region_;
+ MessageLoop message_loop_;
};
// CapturerCallback1 verifies that the whole screen is initially dirty.
@@ -97,6 +99,7 @@ TEST_F(CapturerMacTest, Capture) {
capturer_->InvalidateRegion(region_);
capturer_->CaptureInvalidRegion(base::Bind(
&CapturerCallback2::CaptureDoneCallback, base::Unretained(&callback2)));
+ message_loop_.RunAllPending();
}
} // namespace remoting