Add GPU completion to FrameMetrics (1/3)

- Add SurfaceStatsCallback to TransactionCompletedListener
- Register a callback in RenderProxy to be called when we have
surface stats from SF via the BLAST callback.
- Instead of finishing a frame for frame metrics reporting
immediately, wait until BLAST callback fires, note GPU completion
time and finish frame.
- Expose GPU_COMPLETION in FrameMetrics
- Modify TOTAL_DURATION to also include GPU_COMPLETION

Test: FrameMetricsListenerTest
Fixes: 171046219
Change-Id: I16fa1d80cfc4e7a5527c18fec7e885409f17ee4d
diff --git a/libs/hwui/ProfileDataContainer.h b/libs/hwui/ProfileDataContainer.h
index a398694..a61b8dc 100644
--- a/libs/hwui/ProfileDataContainer.h
+++ b/libs/hwui/ProfileDataContainer.h
@@ -19,6 +19,9 @@
 #include "ProfileData.h"
 #include "utils/Macros.h"
 
+#include <mutex>
+#include <utils/Mutex.h>
+
 namespace android {
 namespace uirenderer {
 
@@ -26,7 +29,8 @@
     PREVENT_COPY_AND_ASSIGN(ProfileDataContainer);
 
 public:
-    explicit ProfileDataContainer() {}
+    explicit ProfileDataContainer(std::mutex& jankDataMutex)
+            : mData(new ProfileData()), mJankDataMutex(jankDataMutex) {}
 
     ~ProfileDataContainer() { freeData(); }
 
@@ -36,13 +40,16 @@
     ProfileData* get() { return mData; }
     ProfileData* operator->() { return mData; }
 
+    std::mutex& getDataMutex() { return mJankDataMutex; }
+
 private:
     void freeData();
 
     // By default this will use malloc memory. It may be moved later to ashmem
     // if there is shared space for it and a request comes in to do that.
-    ProfileData* mData = new ProfileData;
+    ProfileData* mData GUARDED_BY(mJankDataMutex);
     bool mIsMapped = false;
+    std::mutex& mJankDataMutex;
 };
 
 } /* namespace uirenderer */