Bug 1142708. Fallback to main display CVDisplayLink if active displays aren't available. r=mstange
☠☠ backed out by 50c59dfbe392 ☠ ☠
authorMason Chang <mchang@mozilla.com>
Sat, 14 Mar 2015 13:55:35 -0700
changeset 233697 8545a7f27c8c8d6003180cc4971365190b1bbfd2
parent 233696 3f0355067f0f07b8633e50744cb2e769ec275efc
child 233698 7f1f85ee4ba664076033dec5fc2d6db0b7d3e8f7
push id56919
push usermchang@mozilla.com
push dateSat, 14 Mar 2015 20:56:17 +0000
treeherdermozilla-inbound@8545a7f27c8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1142708
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1142708. Fallback to main display CVDisplayLink if active displays aren't available. r=mstange
gfx/thebes/VsyncSource.cpp
gfx/thebes/gfxPlatformMac.cpp
--- a/gfx/thebes/VsyncSource.cpp
+++ b/gfx/thebes/VsyncSource.cpp
@@ -119,16 +119,20 @@ VsyncSource::Display::UpdateVsyncStatus(
     enableVsync = !mCompositorVsyncDispatchers.IsEmpty() || mRefreshTimerNeedsVsync;
   }
 
   if (enableVsync) {
     EnableVsync();
   } else {
     DisableVsync();
   }
+
+  if (IsVsyncEnabled() != enableVsync) {
+    NS_WARNING("Vsync status did not change.");
+  }
 }
 
 nsRefPtr<RefreshTimerVsyncDispatcher>
 VsyncSource::Display::GetRefreshTimerVsyncDispatcher()
 {
   return mRefreshTimerVsyncDispatcher;
 }
 
--- a/gfx/thebes/gfxPlatformMac.cpp
+++ b/gfx/thebes/gfxPlatformMac.cpp
@@ -464,22 +464,32 @@ public:
         return;
       }
 
       // Create a display link capable of being used with all active displays
       // TODO: See if we need to create an active DisplayLink for each monitor in multi-monitor
       // situations. According to the docs, it is compatible with all displays running on the computer
       // But if we have different monitors at different display rates, we may hit issues.
       if (CVDisplayLinkCreateWithActiveCGDisplays(&mDisplayLink) != kCVReturnSuccess) {
-        NS_WARNING("Could not create a display link, returning");
-        return;
+        NS_WARNING("Could not create a display link with all active displays. Falling back to main display\n");
+
+        // bug 1142708 - When coming back from sleep, there may be no active displays ready yet,
+        // even if listening for the kIOMessageSystemHasPoweredOn event from OS X sleep notifications.
+        // Active displays are those that are drawable.
+        // In these cases, default back to the main display to try to get a vsync event.
+        // The alternative would be to keep polling the CGActiveDisplayList for the displays to be ready.
+        if (CVDisplayLinkCreateWithCGDisplay(CGMainDisplayID(), &mDisplayLink) != kCVReturnSuccess) {
+          MOZ_CRASH("Could not create a CVDisplayLink with either active displays or the main display");
+        }
+        NS_WARNING("Using the CVDisplayLink from the main display\n");
       }
 
       if (CVDisplayLinkSetOutputCallback(mDisplayLink, &VsyncCallback, this) != kCVReturnSuccess) {
         NS_WARNING("Could not set displaylink output callback");
+        mDisplayLink = nullptr;
         return;
       }
 
       mPreviousTimestamp = TimeStamp::Now();
       if (CVDisplayLinkStart(mDisplayLink) != kCVReturnSuccess) {
         NS_WARNING("Could not activate the display link");
         mDisplayLink = nullptr;
       }