Bug 1155797 - Part 3: Turn on vsync for kk, l and up. r=mchange, a=jocheng
authorJerryShih <hshih@mozilla.com>
Tue, 19 May 2015 01:10:00 -0400
changeset 238445 9f090b47fed8b579e2e2b606522e35796b25b2ad
parent 238444 31a8e155e4906ae05957b36ea54acdbbc5e0c970
child 238446 6e4eaf59efda9d59d034aac13d740d0e229c5f96
push id624
push userryanvm@gmail.com
push dateThu, 21 May 2015 01:28:21 +0000
treeherdermozilla-b2g37_v2_2@6e4eaf59efda [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmchange, jocheng
bugs1155797
milestone37.0
Bug 1155797 - Part 3: Turn on vsync for kk, l and up. r=mchange, a=jocheng
b2g/app/b2g.js
widget/gonk/HwcComposer2D.cpp
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -1097,21 +1097,20 @@ pref("dom.mozSettings.SettingsService.ve
 // Controlling whether we want to allow forcing some Settings
 // IndexedDB transactions to be opened as readonly or keep everything as
 // readwrite.
 pref("dom.mozSettings.allowForceReadOnly", false);
 
 // RequestSync API is enabled by default on B2G.
 pref("dom.requestSync.enabled", true);
 
-// Bug 1147753 - Weird issues with vsync on L devices
-// so disable them on L, but enable on KK and ICS
-// kit kat == 19, L = 21, 20 is kit-kat for wearables
-// 15 is for the ICS emulators which will fallback to software vsync
-#if ANDROID_VERSION == 19 || ANDROID_VERSION == 15
+// Only enable for kit kat and above devices
+// kit kat == 19, L = 21, L-MR1 = 22, 20 is kit-kat for wearables.
+// 15 is for the ICS emulators which will fallback to software vsync.
+#if ANDROID_VERSION == 19 || ANDROID_VERSION == 21 || ANDROID_VERSION == 22 || ANDROID_VERSION == 15
 pref("gfx.vsync.hw-vsync.enabled", true);
 pref("gfx.vsync.compositor", true);
 pref("gfx.touch.resample", true);
 pref("gfx.vsync.refreshdriver", true);
 #else
 pref("gfx.vsync.hw-vsync.enabled", false);
 pref("gfx.vsync.compositor", false);
 pref("gfx.touch.resample", false);
--- a/widget/gonk/HwcComposer2D.cpp
+++ b/widget/gonk/HwcComposer2D.cpp
@@ -186,17 +186,19 @@ HwcComposer2D::GetInstance()
         sInstance = new HwcComposer2D();
     }
     return sInstance;
 }
 
 bool
 HwcComposer2D::EnableVsync(bool aEnable)
 {
-#if ANDROID_VERSION >= 17
+    // Only support hardware vsync on kitkat, L and up due to inaccurate timings
+    // with JellyBean.
+#if (ANDROID_VERSION == 19 || ANDROID_VERSION >= 21)
     MOZ_ASSERT(NS_IsMainThread());
     if (!mHasHWVsync) {
       return false;
     }
 
     HwcDevice* device = (HwcDevice*)GetGonkDisplay()->GetHWCDevice();
     if (!device) {
       return false;
@@ -216,31 +218,45 @@ HwcComposer2D::RegisterHwcEventCallback(
     if (!device || !device->registerProcs) {
         LOGE("Failed to get hwc");
         return false;
     }
 
     // Disable Vsync first, and then register callback functions.
     device->eventControl(device, HWC_DISPLAY_PRIMARY, HWC_EVENT_VSYNC, false);
     device->registerProcs(device, &sHWCProcs);
+
+    // Only support hardware vsync on kitkat, L and up due to inaccurate timings
+    // with JellyBean.
+#if (ANDROID_VERSION == 19 || ANDROID_VERSION >= 21)
     mHasHWVsync = gfxPrefs::HardwareVsyncEnabled();
+#else
+    mHasHWVsync = false;
+#endif
     return mHasHWVsync;
 }
 
 void
 HwcComposer2D::Vsync(int aDisplay, nsecs_t aVsyncTimestamp)
 {
+    // Only support hardware vsync on kitkat, L and up due to inaccurate timings
+    // with JellyBean.
+#if (ANDROID_VERSION == 19 || ANDROID_VERSION >= 21)
     TimeStamp vsyncTime = mozilla::TimeStamp::FromSystemTime(aVsyncTimestamp);
     nsecs_t vsyncInterval = aVsyncTimestamp - mLastVsyncTime;
     if (vsyncInterval < 16000000 || vsyncInterval > 17000000) {
       LOGE("Non-uniform vsync interval: %lld\n", vsyncInterval);
     }
     mLastVsyncTime = aVsyncTimestamp;
 
     gfxPlatform::GetPlatform()->GetHardwareVsync()->GetGlobalDisplay().NotifyVsync(vsyncTime);
+#else
+    // If this device doesn't support vsync, this function should not be used.
+    MOZ_ASSERT(false);
+#endif
 }
 
 // Called on the "invalidator" thread (run from HAL).
 void
 HwcComposer2D::Invalidate()
 {
     if (!Initialized()) {
         LOGE("HwcComposer2D::Invalidate failed!");