Bug 1146691 - Create tests to check that the RefreshDriverVsyncObservers get vsync notifications. r=kats
authorMason Chang <mchang@mozilla.com>
Tue, 24 Mar 2015 08:50:58 -0700
changeset 265672 c0ca4235699b809e6c186c8d5e56b8ee5b4e247d
parent 265671 f12794ccc9882e6e8a8a728acbb771cec4c8b77a
child 265673 c8315bbbc1047c011db78b8fa1b3fd4c4787eb5f
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1146691
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 1146691 - Create tests to check that the RefreshDriverVsyncObservers get vsync notifications. r=kats
gfx/tests/gtest/TestVsync.cpp
--- a/gfx/tests/gtest/TestVsync.cpp
+++ b/gfx/tests/gtest/TestVsync.cpp
@@ -54,31 +54,38 @@ public:
   }
 
   bool DidGetVsyncNotification()
   {
     MonitorAutoLock lock(mVsyncMonitor);
     return mDidGetVsyncNotification;
   }
 
+  void ResetVsyncNotification()
+  {
+    MonitorAutoLock lock(mVsyncMonitor);
+    mDidGetVsyncNotification = false;
+  }
+
 private:
   bool mDidGetVsyncNotification;
 
 private:
   Monitor mVsyncMonitor;
 };
 
 class VsyncTester : public ::testing::Test {
 protected:
   explicit VsyncTester()
   {
     gfxPlatform::GetPlatform();
     gfxPrefs::GetSingleton();
     if (gfxPrefs::HardwareVsyncEnabled() ) {
       mVsyncSource = gfxPlatform::GetPlatform()->GetHardwareVsync();
+      MOZ_RELEASE_ASSERT(mVsyncSource);
     }
   }
 
   virtual ~VsyncTester()
   {
     mVsyncSource = nullptr;
   }
 
@@ -141,8 +148,68 @@ TEST_F(VsyncTester, CompositorGetVsyncNo
   ASSERT_TRUE(globalDisplay.IsVsyncEnabled());
 
   testVsyncObserver->WaitForVsyncNotification();
   ASSERT_TRUE(testVsyncObserver->DidGetVsyncNotification());
 
   vsyncDispatcher = nullptr;
   testVsyncObserver = nullptr;
 }
+
+// Test that if we have vsync enabled, the parent refresh driver should get notifications
+TEST_F(VsyncTester, ParentRefreshDriverGetVsyncNotifications)
+{
+  if (!gfxPrefs::HardwareVsyncEnabled() || !gfxPrefs::VsyncAlignedRefreshDriver()) {
+    return;
+  }
+
+  VsyncSource::Display& globalDisplay = mVsyncSource->GetGlobalDisplay();
+  globalDisplay.DisableVsync();
+  ASSERT_FALSE(globalDisplay.IsVsyncEnabled());
+
+  nsRefPtr<RefreshTimerVsyncDispatcher> vsyncDispatcher = globalDisplay.GetRefreshTimerVsyncDispatcher();
+  ASSERT_TRUE(vsyncDispatcher != nullptr);
+
+  nsRefPtr<TestVsyncObserver> testVsyncObserver = new TestVsyncObserver();
+  vsyncDispatcher->SetParentRefreshTimer(testVsyncObserver);
+  ASSERT_TRUE(globalDisplay.IsVsyncEnabled());
+
+  testVsyncObserver->WaitForVsyncNotification();
+  ASSERT_TRUE(testVsyncObserver->DidGetVsyncNotification());
+  vsyncDispatcher->SetParentRefreshTimer(nullptr);
+
+  testVsyncObserver->ResetVsyncNotification();
+  testVsyncObserver->WaitForVsyncNotification();
+  ASSERT_FALSE(testVsyncObserver->DidGetVsyncNotification());
+
+  vsyncDispatcher = nullptr;
+  testVsyncObserver = nullptr;
+}
+
+// Test that child refresh vsync observers get vsync notifications
+TEST_F(VsyncTester, ChildRefreshDriverGetVsyncNotifications)
+{
+  if (!gfxPrefs::HardwareVsyncEnabled() || !gfxPrefs::VsyncAlignedRefreshDriver()) {
+    return;
+  }
+
+  VsyncSource::Display& globalDisplay = mVsyncSource->GetGlobalDisplay();
+  globalDisplay.DisableVsync();
+  ASSERT_FALSE(globalDisplay.IsVsyncEnabled());
+
+  nsRefPtr<RefreshTimerVsyncDispatcher> vsyncDispatcher = globalDisplay.GetRefreshTimerVsyncDispatcher();
+  ASSERT_TRUE(vsyncDispatcher != nullptr);
+
+  nsRefPtr<TestVsyncObserver> testVsyncObserver = new TestVsyncObserver();
+  vsyncDispatcher->AddChildRefreshTimer(testVsyncObserver);
+  ASSERT_TRUE(globalDisplay.IsVsyncEnabled());
+
+  testVsyncObserver->WaitForVsyncNotification();
+  ASSERT_TRUE(testVsyncObserver->DidGetVsyncNotification());
+
+  vsyncDispatcher->RemoveChildRefreshTimer(testVsyncObserver);
+  testVsyncObserver->ResetVsyncNotification();
+  testVsyncObserver->WaitForVsyncNotification();
+  ASSERT_FALSE(testVsyncObserver->DidGetVsyncNotification());
+
+  vsyncDispatcher = nullptr;
+  testVsyncObserver = nullptr;
+}