Disable DispSync resync when not needed

If app and SF events aren't using phase offsets, we don't need
to maintain the DispSync model.  We just turn hardware VSYNC on
whenever something wants to draw.  This avoids some edge cases
where we were doing too much resync work.

Also, updated the systrace output.  The "VsyncOn" line was a
combination of SF and app event threads, and would occasionally
be very weird.  Removed VsyncOn, renamed VSYNC to VSYNC-app,
and added VSYNC-sf.

Also, added more details to the --dispsync dumpsys output.

Also, renamed global constants to not look like local variables.

Bug 15516453

Change-Id: I0da10b72f0d9a7b7eb5202d87cc18967f698adbd
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 7152f93..3bdbb4f 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -88,14 +88,6 @@
 
 namespace android {
 
-// This works around the lack of support for the sync framework on some
-// devices.
-#ifdef RUNNING_WITHOUT_SYNC_FRAMEWORK
-static const bool runningWithoutSyncFramework = true;
-#else
-static const bool runningWithoutSyncFramework = false;
-#endif
-
 // This is the phase offset in nanoseconds of the software vsync event
 // relative to the vsync event reported by HWComposer.  The software vsync
 // event is when SurfaceFlinger and Choreographer-based applications run each
@@ -322,10 +314,13 @@
 
 class DispSyncSource : public VSyncSource, private DispSync::Callback {
 public:
-    DispSyncSource(DispSync* dispSync, nsecs_t phaseOffset, bool traceVsync) :
+    DispSyncSource(DispSync* dispSync, nsecs_t phaseOffset, bool traceVsync,
+        const char* label) :
             mValue(0),
             mPhaseOffset(phaseOffset),
             mTraceVsync(traceVsync),
+            mVsyncOnLabel(String8::format("VsyncOn-%s", label)),
+            mVsyncEventLabel(String8::format("VSYNC-%s", label)),
             mDispSync(dispSync) {}
 
     virtual ~DispSyncSource() {}
@@ -340,7 +335,7 @@
                 ALOGE("error registering vsync callback: %s (%d)",
                         strerror(-err), err);
             }
-            ATRACE_INT("VsyncOn", 1);
+            //ATRACE_INT(mVsyncOnLabel.string(), 1);
         } else {
             status_t err = mDispSync->removeEventListener(
                     static_cast<DispSync::Callback*>(this));
@@ -348,7 +343,7 @@
                 ALOGE("error unregistering vsync callback: %s (%d)",
                         strerror(-err), err);
             }
-            ATRACE_INT("VsyncOn", 0);
+            //ATRACE_INT(mVsyncOnLabel.string(), 0);
         }
     }
 
@@ -366,7 +361,7 @@
 
             if (mTraceVsync) {
                 mValue = (mValue + 1) % 2;
-                ATRACE_INT("VSYNC", mValue);
+                ATRACE_INT(mVsyncEventLabel.string(), mValue);
             }
         }
 
@@ -379,6 +374,8 @@
 
     const nsecs_t mPhaseOffset;
     const bool mTraceVsync;
+    const String8 mVsyncOnLabel;
+    const String8 mVsyncEventLabel;
 
     DispSync* mDispSync;
     sp<VSyncSource::Callback> mCallback;
@@ -449,10 +446,10 @@
 
     // start the EventThread
     sp<VSyncSource> vsyncSrc = new DispSyncSource(&mPrimaryDispSync,
-            vsyncPhaseOffsetNs, true);
+            vsyncPhaseOffsetNs, true, "app");
     mEventThread = new EventThread(vsyncSrc);
     sp<VSyncSource> sfVsyncSrc = new DispSyncSource(&mPrimaryDispSync,
-            sfVsyncPhaseOffsetNs, false);
+            sfVsyncPhaseOffsetNs, true, "sf");
     mSFEventThread = new EventThread(sfVsyncSrc);
     mEventQueue.setEventThread(mSFEventThread);
 
@@ -858,7 +855,7 @@
         }
     }
 
-    if (runningWithoutSyncFramework) {
+    if (kIgnorePresentFences) {
         const sp<const DisplayDevice> hw(getDefaultDisplayDevice());
         if (hw->isScreenAcquired()) {
             enableHardwareVsync();