Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Unified Diff: remoting/host/capturer_mac.cc

Issue 10082032: Awake Mac host display when remote session starts. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed power_assertion_created_. Checking power_assertion_id_ against kIOPMNullAssertionID. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/capturer_mac.cc
diff --git a/remoting/host/capturer_mac.cc b/remoting/host/capturer_mac.cc
index 42b362afe3629843b6030a0a956235d9a9931d74..0e5ea27b7c7aad2f118de699af9f42fecb706ce0 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 = IOPMAssertionCreateWithName(
Avi (use Gerrit) 2012/04/14 00:42:33 This is only available in 10.6. Do you not require
Jamie 2012/04/14 01:26:36 On 10.5, moving the mouse will wake up the display
+ kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn,
+ CFSTR("Chromoting"), &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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698