Bug 1158321. Normalize OS X vsync timestamp if CVDisplayLinkCallback executes early. r=mstange
authorMason Chang <mchang@mozilla.com>
Tue, 02 Jun 2015 13:16:41 -0700
changeset 246851 dc416c09c90a76cc280f745f4be4d7054f44eb22
parent 246850 a13e7c53ea2e4b4fc1b0b385f450eb306f204a2a
child 246852 582fcb5a63d3ba0624968177b96de3ae27880d83
push id28843
push usercbook@mozilla.com
push dateWed, 03 Jun 2015 11:50:02 +0000
treeherdermozilla-central@6c612d7adbf5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1158321
milestone41.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 1158321. Normalize OS X vsync timestamp if CVDisplayLinkCallback executes early. r=mstange
gfx/thebes/gfxPlatformMac.cpp
--- a/gfx/thebes/gfxPlatformMac.cpp
+++ b/gfx/thebes/gfxPlatformMac.cpp
@@ -571,17 +571,26 @@ static CVReturn VsyncCallback(CVDisplayL
 {
   // Executed on OS X hardware vsync thread
   OSXVsyncSource::OSXDisplay* display = (OSXVsyncSource::OSXDisplay*) aDisplayLinkContext;
   int64_t nextVsyncTimestamp = aOutputTime->hostTime;
   mozilla::TimeStamp nextVsync = mozilla::TimeStamp::FromSystemTime(nextVsyncTimestamp);
 
   mozilla::TimeStamp previousVsync = display->mPreviousTimestamp;
   display->mPreviousTimestamp = nextVsync;
-  MOZ_ASSERT(TimeStamp::Now() > previousVsync);
+  mozilla::TimeStamp now = TimeStamp::Now();
+  MOZ_ASSERT(nextVsync > previousVsync);
+
+  // Bug 1158321 - The VsyncCallback can sometimes execute before the reported
+  // vsync time. In those cases, normalize the timestamp to Now() as sending
+  // timestamps in the future has undefined behavior. See the comment above
+  // OSXDisplay::mPreviousTimestamp
+  if (now < previousVsync) {
+    previousVsync = now;
+  }
 
   display->NotifyVsync(previousVsync);
   return kCVReturnSuccess;
 }
 
 already_AddRefed<mozilla::gfx::VsyncSource>
 gfxPlatformMac::CreateHardwareVsyncSource()
 {