Bug 1160102 - use VsyncDisplay interface to turn on/off vsync. r=kats
authorJerryShih <hshih@mozilla.com>
Mon, 04 May 2015 03:33:00 +0200
changeset 273953 8cb1e6f993a7b19d2eafd93cd7fc479e9d8e3ac7
parent 273952 aaa5e4221fd123fc9b96c4f977ef097ece052125
child 273954 c92c76073e9cb2294cdac7dfc80431b2224c4c93
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1160102
milestone40.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 1160102 - use VsyncDisplay interface to turn on/off vsync. r=kats
widget/gonk/nsScreenManagerGonk.h
widget/gonk/nsWindow.cpp
--- a/widget/gonk/nsScreenManagerGonk.h
+++ b/widget/gonk/nsScreenManagerGonk.h
@@ -74,16 +74,17 @@ public:
     static already_AddRefed<nsScreenManagerGonk> GetInstance();
     static already_AddRefed<nsScreenGonk> GetPrimaryScreen();
 
     void Initialize();
     void DisplayEnabled(bool aEnabled);
 
 protected:
     ~nsScreenManagerGonk();
+    void VsyncControl(bool aEnabled);
 
     bool mInitialized;
     nsCOMPtr<nsIScreen> mOneScreen;
     nsRefPtr<nsRunnable> mScreenOnEvent;
     nsRefPtr<nsRunnable> mScreenOffEvent;
 };
 
 #endif /* nsScreenManagerGonk_h___ */
--- a/widget/gonk/nsWindow.cpp
+++ b/widget/gonk/nsWindow.cpp
@@ -51,16 +51,17 @@
 #include "mozilla/layers/APZCTreeManager.h"
 #include "mozilla/layers/APZThreadUtils.h"
 #include "mozilla/layers/CompositorParent.h"
 #include "mozilla/layers/InputAPZContext.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "nsThreadUtils.h"
 #include "HwcComposer2D.h"
+#include "VsyncSource.h"
 
 #define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "Gonk" , ## args)
 #define LOGW(args...) __android_log_print(ANDROID_LOG_WARN, "Gonk", ## args)
 #define LOGE(args...) __android_log_print(ANDROID_LOG_ERROR, "Gonk", ## args)
 
 #define IS_TOPLEVEL() (mWindowType == eWindowType_toplevel || mWindowType == eWindowType_dialog)
 
 using namespace mozilla;
@@ -1111,17 +1112,20 @@ nsScreenManagerGonk::Initialize()
 
     nsAppShell::NotifyScreenInitialized();
     mInitialized = true;
 }
 
 void
 nsScreenManagerGonk::DisplayEnabled(bool aEnabled)
 {
-    HwcComposer2D::GetInstance()->EnableVsync(aEnabled);
+    if (gfxPrefs::HardwareVsyncEnabled()) {
+        VsyncControl(aEnabled);
+    }
+
     NS_DispatchToMainThread(aEnabled ? mScreenOnEvent : mScreenOffEvent);
 }
 
 NS_IMETHODIMP
 nsScreenManagerGonk::GetPrimaryScreen(nsIScreen **outScreen)
 {
     NS_IF_ADDREF(*outScreen = mOneScreen.get());
     return NS_OK;
@@ -1158,8 +1162,30 @@ nsScreenManagerGonk::GetNumberOfScreens(
 }
 
 NS_IMETHODIMP
 nsScreenManagerGonk::GetSystemDefaultScale(float *aDefaultScale)
 {
     *aDefaultScale = 1.0f;
     return NS_OK;
 }
+
+void
+nsScreenManagerGonk::VsyncControl(bool aEnabled)
+{
+    MOZ_ASSERT(gfxPrefs::HardwareVsyncEnabled());
+
+    if (!NS_IsMainThread()) {
+        NS_DispatchToMainThread(
+            NS_NewRunnableMethodWithArgs<bool>(this,
+                                               &nsScreenManagerGonk::VsyncControl,
+                                               aEnabled));
+        return;
+    }
+
+    MOZ_ASSERT(NS_IsMainThread());
+    VsyncSource::Display &display = gfxPlatform::GetPlatform()->GetHardwareVsync()->GetGlobalDisplay();
+    if (aEnabled) {
+        display.EnableVsync();
+    } else {
+        display.DisableVsync();
+    }
+}