Add minimal post processing API to framework

This API allows applications to instruct the connected display to do minimal
post processing on the produced image or video frames. This will switch the
display to a low latency mode (ALLM, Game mode or some other custom
implementation thereof), reducing lag in the final images. Thus, minimal post
processing would greatly enhance performance for gaming and video
conferencing applications. It would not, however, suit applications that
prioritise image quality over performance.

This CL adds 2 public method:
 - Window.setPreferMinimalPostProcessing()
(this can also be set in WindowManager.LayoutParams.preferMinimalPostProcessing)
If minimal post processing is preferred, the connected display will be requested
to go into low latency mode, which reduces image processing, resulting in better
performance for gaming applications. If the Display sink is connected via HDMI,
the device will begin to send infoframes with Auto Low Latency Mode enabled and
Game Content Type. This will switch the connected display to a lower latency
mode (if available).
For more information, see HDMI 2.1 specification.

If the Display sink has an internal connection or uses some other protocol than
HDMI, effects may be similar but implementation-defined.

 - Display.isMinimalPostProcessingPreferred()
Returns true if the connected display supports either Low Latency Mode (ALLM or
some other custom low latency implementation) or Game content type.

Bug: 135116095

Test: make -> flash on ATV OTT device -> open an activity which requests minimal
post processing -> check SurfaceControl logs -> verify correct signals are
passed to native

Change-Id: I5508bb9e5c138b0f2b42d8f8fab10e1915ba3cb6
diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java
index ea03131..10386e7 100644
--- a/services/core/java/com/android/server/display/DisplayManagerService.java
+++ b/services/core/java/com/android/server/display/DisplayManagerService.java
@@ -1193,12 +1193,16 @@
     }
 
     private void setDisplayPropertiesInternal(int displayId, boolean hasContent,
-            float requestedRefreshRate, int requestedModeId, boolean inTraversal) {
+            float requestedRefreshRate, int requestedModeId, boolean requestedMinimalPostProcessing,
+            boolean inTraversal) {
         synchronized (mSyncRoot) {
             LogicalDisplay display = mLogicalDisplays.get(displayId);
             if (display == null) {
                 return;
             }
+
+            boolean shouldScheduleTraversal = false;
+
             if (display.hasContentLocked() != hasContent) {
                 if (DEBUG) {
                     Slog.d(TAG, "Display " + displayId + " hasContent flag changed: "
@@ -1206,7 +1210,7 @@
                 }
 
                 display.setHasContentLocked(hasContent);
-                scheduleTraversalLocked(inTraversal);
+                shouldScheduleTraversal = true;
             }
             if (requestedModeId == 0 && requestedRefreshRate != 0) {
                 // Scan supported modes returned by display.getInfo() to find a mode with the same
@@ -1216,6 +1220,20 @@
             }
             mDisplayModeDirector.getAppRequestObserver().setAppRequestedMode(
                     displayId, requestedModeId);
+
+
+            if (display.getDisplayInfoLocked().minimalPostProcessingSupported
+                    && (display.getRequestedMinimalPostProcessingLocked()
+                    != requestedMinimalPostProcessing)) {
+
+                display.setRequestedMinimalPostProcessingLocked(requestedMinimalPostProcessing);
+
+                shouldScheduleTraversal = true;
+            }
+
+            if (shouldScheduleTraversal) {
+                scheduleTraversalLocked(inTraversal);
+            }
         }
     }
 
@@ -2349,6 +2367,7 @@
     }
 
     private final class LocalService extends DisplayManagerInternal {
+
         @Override
         public void initPowerManagement(final DisplayPowerCallbacks callbacks, Handler handler,
                 SensorManager sensorManager) {
@@ -2437,9 +2456,10 @@
 
         @Override
         public void setDisplayProperties(int displayId, boolean hasContent,
-                float requestedRefreshRate, int requestedMode, boolean inTraversal) {
+                float requestedRefreshRate, int requestedMode,
+                boolean requestedMinimalPostProcessing, boolean inTraversal) {
             setDisplayPropertiesInternal(displayId, hasContent, requestedRefreshRate,
-                    requestedMode, inTraversal);
+                    requestedMode, requestedMinimalPostProcessing, inTraversal);
         }
 
         @Override