Surface unit tests for getFrameTimestamps.

Verifies the following:

1) The timestamps and fences aren't transferred if the
   feature isn't explicitly enabled.
2) Attempts to get the timestamps will fail if not enabled.
3) Timestamps are transferred if enabled.
4) The support for Present/Retire timestamps are properly
   queried from the ISurfaceComposer.
5) Timestamps correspond to the correct frame.
6) The consumer doesn't send the acquire fence back to the
   producer and a sync call isn't made to try and get it
   from the producer.
7) A sync call isn't made when no timestamps are requested.
8) If the consumer sent the producer fences, the consumer
   can get the timestamps without a sync call.
9) If there was no GL composite performed, a sync call
   isn't made to get a non-existant fence/time.
10) When asking for the retire or release time of the most
   recent frame, a sync call isn't made.
11) Requests for unsupported timestamps return an error and
   do not result in a sync call.

Test: Test: adb shell /data/nativetest/libgui_test/libgui_test
--gtest_filter=*GetFrameTimestamps*

Change-Id: I6f728af0d4a0f431c9e47131da64584a589559e7
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index a172c32..ead8ecb 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -52,7 +52,8 @@
       mQueriedSupportedTimestamps(false),
       mFrameTimestampsSupportsPresent(false),
       mFrameTimestampsSupportsRetire(false),
-      mEnableFrameTimestamps(false)
+      mEnableFrameTimestamps(false),
+      mFrameEventHistory(std::make_unique<ProducerFrameEventHistory>())
 {
     // Initialize the ANativeWindow function pointers.
     ANativeWindow::setSwapInterval  = hook_setSwapInterval;
@@ -96,6 +97,10 @@
     }
 }
 
+sp<ISurfaceComposer> Surface::composerService() const {
+    return ComposerService::getComposerService();
+}
+
 sp<IGraphicBufferProducer> Surface::getIGraphicBufferProducer() const {
     return mGraphicBufferProducer;
 }
@@ -203,7 +208,7 @@
         return BAD_VALUE;
     }
 
-    FrameEvents* events = mFrameEventHistory.getFrame(frameNumber);
+    FrameEvents* events = mFrameEventHistory->getFrame(frameNumber);
     if (events == nullptr) {
         // If the entry isn't available in the producer, it's definitely not
         // available in the consumer.
@@ -216,8 +221,8 @@
             outDisplayPresentTime, outDisplayRetireTime, outReleaseTime)) {
         FrameEventHistoryDelta delta;
         mGraphicBufferProducer->getFrameTimestamps(&delta);
-        mFrameEventHistory.applyDelta(delta);
-        events = mFrameEventHistory.getFrame(frameNumber);
+        mFrameEventHistory->applyDelta(delta);
+        events = mFrameEventHistory->getFrame(frameNumber);
     }
 
     if (events == nullptr) {
@@ -396,7 +401,7 @@
     }
 
     if (enableFrameTimestamps) {
-         mFrameEventHistory.applyDelta(frameTimestamps);
+         mFrameEventHistory->applyDelta(frameTimestamps);
     }
 
     if ((result & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) {
@@ -590,16 +595,16 @@
     }
 
     if (mEnableFrameTimestamps) {
-        mFrameEventHistory.applyDelta(output.frameTimestamps);
+        mFrameEventHistory->applyDelta(output.frameTimestamps);
         // Update timestamps with the local acquire fence.
         // The consumer doesn't send it back to prevent us from having two
         // file descriptors of the same fence.
-        mFrameEventHistory.updateAcquireFence(mNextFrameNumber,
+        mFrameEventHistory->updateAcquireFence(mNextFrameNumber,
                 std::make_shared<FenceTime>(std::move(fence)));
 
         // Cache timestamps of signaled fences so we can close their file
         // descriptors.
-        mFrameEventHistory.updateSignalTimes();
+        mFrameEventHistory->updateSignalTimes();
     }
 
     mLastFrameNumber = mNextFrameNumber;
@@ -638,8 +643,7 @@
     mQueriedSupportedTimestamps = true;
 
     std::vector<FrameEvent> supportedFrameTimestamps;
-    sp<ISurfaceComposer> composer(ComposerService::getComposerService());
-    status_t err = composer->getSupportedFrameTimestamps(
+    status_t err = composerService()->getSupportedFrameTimestamps(
             &supportedFrameTimestamps);
 
     if (err != NO_ERROR) {
@@ -668,9 +672,8 @@
                 }
                 break;
             case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: {
-                sp<ISurfaceComposer> composer(
-                        ComposerService::getComposerService());
-                if (composer->authenticateSurfaceTexture(mGraphicBufferProducer)) {
+                if (composerService()->authenticateSurfaceTexture(
+                        mGraphicBufferProducer)) {
                     *value = 1;
                 } else {
                     *value = 0;