Bug 1119850 - Modify Vsync Timestamp on Mac to be the previous vsync timestamp. r=mstange

This commit is contained in:
Mason Chang 2015-01-09 09:37:00 +01:00
parent b58326c911
commit 6be059f6cd
3 changed files with 37 additions and 14 deletions

View File

@ -30,6 +30,14 @@ public:
void AddCompositorVsyncDispatcher(mozilla::CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
void RemoveCompositorVsyncDispatcher(mozilla::CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
// Notified when this display's vsync occurs, on the vsync thread
// The aVsyncTimestamp should normalize to the Vsync time that just occured
// However, different platforms give different vsync notification times.
// b2g - The vsync timestamp of the previous frame that was just displayed
// OSX - The vsync timestamp of the upcoming frame, in the future
// TODO: Windows / Linux. DOCUMENT THIS WHEN IMPLEMENTING ON THOSE PLATFORMS
// Android: TODO
// All platforms should normalize to the vsync that just occured.
// Large parts of Gecko assume TimeStamps should not be in the future such as animations
virtual void NotifyVsync(mozilla::TimeStamp aVsyncTimestamp);
// These should all only be called on the main thread

View File

@ -418,14 +418,7 @@ static CVReturn VsyncCallback(CVDisplayLinkRef aDisplayLink,
const CVTimeStamp* aOutputTime,
CVOptionFlags aFlagsIn,
CVOptionFlags* aFlagsOut,
void* aDisplayLinkContext)
{
VsyncSource::Display* display = (VsyncSource::Display*) aDisplayLinkContext;
int64_t timestamp = aOutputTime->hostTime;
mozilla::TimeStamp vsyncTime = mozilla::TimeStamp::FromSystemTime(timestamp);
display->NotifyVsync(vsyncTime);
return kCVReturnSuccess;
}
void* aDisplayLinkContext);
class OSXVsyncSource MOZ_FINAL : public VsyncSource
{
@ -439,7 +432,6 @@ public:
return mGlobalDisplay;
}
protected:
class OSXDisplay MOZ_FINAL : public VsyncSource::Display
{
public:
@ -471,6 +463,7 @@ protected:
return;
}
mPreviousTimestamp = TimeStamp::Now();
if (CVDisplayLinkStart(mDisplayLink) != kCVReturnSuccess) {
NS_WARNING("Could not activate the display link");
mDisplayLink = nullptr;
@ -494,6 +487,13 @@ protected:
return mDisplayLink != nullptr;
}
// The vsync timestamps given by the CVDisplayLinkCallback are
// in the future for the NEXT frame. Large parts of Gecko, such
// as animations assume a timestamp at either now or in the past.
// Normalize the timestamps given to the VsyncDispatchers to the vsync
// that just occured, not the vsync that is upcoming.
TimeStamp mPreviousTimestamp;
private:
// Manages the display link render thread
CVDisplayLinkRef mDisplayLink;
@ -507,6 +507,26 @@ private:
OSXDisplay mGlobalDisplay;
}; // OSXVsyncSource
static CVReturn VsyncCallback(CVDisplayLinkRef aDisplayLink,
const CVTimeStamp* aNow,
const CVTimeStamp* aOutputTime,
CVOptionFlags aFlagsIn,
CVOptionFlags* aFlagsOut,
void* aDisplayLinkContext)
{
// 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);
display->NotifyVsync(previousVsync);
return kCVReturnSuccess;
}
already_AddRefed<mozilla::gfx::VsyncSource>
gfxPlatformMac::CreateHardwareVsyncSource()
{

View File

@ -40,11 +40,6 @@ public:
CompositorVsyncDispatcher();
// Called on the vsync thread when a hardware vsync occurs
// The aVsyncTimestamp can mean different things depending on the platform:
// b2g - The vsync timestamp of the previous frame that was just displayed
// OSX - The vsync timestamp of the upcoming frame
// TODO: Windows / Linux. DOCUMENT THIS WHEN IMPLEMENTING ON THOSE PLATFORMS
// Android: TODO
void NotifyVsync(TimeStamp aVsyncTimestamp);
// Compositor vsync observers must be added/removed on the compositor thread