[HWUI] provide supportMixedColorSpaces() function for hwui.

Bug: 242588489
Test: build and flash
Change-Id: I9c6840e23891a95fdbae8e9adcfcabee33b37b07
diff --git a/core/java/android/hardware/OverlayProperties.java b/core/java/android/hardware/OverlayProperties.java
index 1ce1361..8bfc2f7 100644
--- a/core/java/android/hardware/OverlayProperties.java
+++ b/core/java/android/hardware/OverlayProperties.java
@@ -59,6 +59,16 @@
     }
 
     /**
+     * @return True if the device can support mixed colorspaces, false otherwise.
+     */
+    public boolean supportMixedColorSpaces() {
+        if (mNativeObject == 0) {
+            return false;
+        }
+        return nSupportMixedColorSpaces(mNativeObject);
+    }
+
+    /**
      * Release the local reference.
      */
     public void release() {
@@ -106,6 +116,7 @@
 
     private static native long nGetDestructor();
     private static native boolean nSupportFp16ForHdr(long nativeObject);
+    private static native boolean nSupportMixedColorSpaces(long nativeObject);
     private static native void nWriteOverlayPropertiesToParcel(long nativeObject, Parcel dest);
     private static native long nReadOverlayPropertiesFromParcel(Parcel in);
 }
diff --git a/core/jni/android_hardware_OverlayProperties.cpp b/core/jni/android_hardware_OverlayProperties.cpp
index a96af86..9941ca4 100644
--- a/core/jni/android_hardware_OverlayProperties.cpp
+++ b/core/jni/android_hardware_OverlayProperties.cpp
@@ -69,6 +69,16 @@
     return false;
 }
 
+static jboolean android_hardware_OverlayProperties_supportMixedColorSpaces(JNIEnv* env,
+                                                                           jobject thiz,
+                                                                           jlong nativeObject) {
+    gui::OverlayProperties* properties = reinterpret_cast<gui::OverlayProperties*>(nativeObject);
+    if (properties != nullptr && properties->supportMixedColorSpaces) {
+        return true;
+    }
+    return false;
+}
+
 // ----------------------------------------------------------------------------
 // Serialization
 // ----------------------------------------------------------------------------
@@ -128,6 +138,8 @@
     { "nGetDestructor", "()J", (void*) android_hardware_OverlayProperties_getDestructor },
     { "nSupportFp16ForHdr",  "(J)Z",
             (void*)  android_hardware_OverlayProperties_supportFp16ForHdr },
+    { "nSupportMixedColorSpaces", "(J)Z",
+            (void*) android_hardware_OverlayProperties_supportMixedColorSpaces },
     { "nWriteOverlayPropertiesToParcel", "(JLandroid/os/Parcel;)V",
             (void*) android_hardware_OverlayProperties_write },
     { "nReadOverlayPropertiesFromParcel", "(Landroid/os/Parcel;)J",
diff --git a/graphics/java/android/graphics/HardwareRenderer.java b/graphics/java/android/graphics/HardwareRenderer.java
index c7c97e0..89d6304 100644
--- a/graphics/java/android/graphics/HardwareRenderer.java
+++ b/graphics/java/android/graphics/HardwareRenderer.java
@@ -1334,6 +1334,8 @@
             final OverlayProperties overlayProperties = defaultDisplay.getOverlaySupport();
             boolean supportFp16ForHdr = overlayProperties != null
                     ? overlayProperties.supportFp16ForHdr() : false;
+            boolean supportMixedColorSpaces = overlayProperties != null
+                    ? overlayProperties.supportMixedColorSpaces() : false;
 
             for (int i = 0; i < allDisplays.length; i++) {
                 final Display display = allDisplays[i];
@@ -1361,7 +1363,7 @@
             nInitDisplayInfo(largestWidth, largestHeight, defaultDisplay.getRefreshRate(),
                     wideColorDataspace, defaultDisplay.getAppVsyncOffsetNanos(),
                     defaultDisplay.getPresentationDeadlineNanos(),
-                    supportFp16ForHdr);
+                    supportFp16ForHdr, supportMixedColorSpaces);
 
             mDisplayInitialized = true;
         }
@@ -1542,7 +1544,7 @@
 
     private static native void nInitDisplayInfo(int width, int height, float refreshRate,
             int wideColorDataspace, long appVsyncOffsetNanos, long presentationDeadlineNanos,
-            boolean supportsFp16ForHdr);
+            boolean supportsFp16ForHdr, boolean nInitDisplayInfo);
 
     private static native void nSetDrawingEnabled(boolean drawingEnabled);
 
diff --git a/libs/hwui/DeviceInfo.cpp b/libs/hwui/DeviceInfo.cpp
index 0240c86..32bc122 100644
--- a/libs/hwui/DeviceInfo.cpp
+++ b/libs/hwui/DeviceInfo.cpp
@@ -108,6 +108,10 @@
     get()->mSupportFp16ForHdr = supportFp16ForHdr;
 }
 
+void DeviceInfo::setSupportMixedColorSpaces(bool supportMixedColorSpaces) {
+    get()->mSupportMixedColorSpaces = supportMixedColorSpaces;
+}
+
 void DeviceInfo::onRefreshRateChanged(int64_t vsyncPeriod) {
     mVsyncPeriod = vsyncPeriod;
 }
diff --git a/libs/hwui/DeviceInfo.h b/libs/hwui/DeviceInfo.h
index 577780b..d4af087 100644
--- a/libs/hwui/DeviceInfo.h
+++ b/libs/hwui/DeviceInfo.h
@@ -62,6 +62,9 @@
     static void setSupportFp16ForHdr(bool supportFp16ForHdr);
     static bool isSupportFp16ForHdr() { return get()->mSupportFp16ForHdr; };
 
+    static void setSupportMixedColorSpaces(bool supportMixedColorSpaces);
+    static bool isSupportMixedColorSpaces() { return get()->mSupportMixedColorSpaces; };
+
     // this value is only valid after the GPU has been initialized and there is a valid graphics
     // context or if you are using the HWUI_NULL_GPU
     int maxTextureSize() const;
@@ -92,6 +95,7 @@
     int mMaxTextureSize;
     sk_sp<SkColorSpace> mWideColorSpace = SkColorSpace::MakeSRGB();
     bool mSupportFp16ForHdr = false;
+    bool mSupportMixedColorSpaces = false;
     SkColorType mWideColorType = SkColorType::kN32_SkColorType;
     int mDisplaysSize = 0;
     int mPhysicalDisplayIndex = -1;
diff --git a/libs/hwui/jni/android_graphics_HardwareRenderer.cpp b/libs/hwui/jni/android_graphics_HardwareRenderer.cpp
index 0663121..53ef491 100644
--- a/libs/hwui/jni/android_graphics_HardwareRenderer.cpp
+++ b/libs/hwui/jni/android_graphics_HardwareRenderer.cpp
@@ -872,12 +872,10 @@
     DeviceInfo::setDensity(density);
 }
 
-static void android_view_ThreadedRenderer_initDisplayInfo(JNIEnv* env, jclass, jint physicalWidth,
-                                                          jint physicalHeight, jfloat refreshRate,
-                                                          jint wideColorDataspace,
-                                                          jlong appVsyncOffsetNanos,
-                                                          jlong presentationDeadlineNanos,
-                                                          jboolean supportFp16ForHdr) {
+static void android_view_ThreadedRenderer_initDisplayInfo(
+        JNIEnv* env, jclass, jint physicalWidth, jint physicalHeight, jfloat refreshRate,
+        jint wideColorDataspace, jlong appVsyncOffsetNanos, jlong presentationDeadlineNanos,
+        jboolean supportFp16ForHdr, jboolean supportMixedColorSpaces) {
     DeviceInfo::setWidth(physicalWidth);
     DeviceInfo::setHeight(physicalHeight);
     DeviceInfo::setRefreshRate(refreshRate);
@@ -885,6 +883,7 @@
     DeviceInfo::setAppVsyncOffsetNanos(appVsyncOffsetNanos);
     DeviceInfo::setPresentationDeadlineNanos(presentationDeadlineNanos);
     DeviceInfo::setSupportFp16ForHdr(supportFp16ForHdr);
+    DeviceInfo::setSupportMixedColorSpaces(supportMixedColorSpaces);
 }
 
 static void android_view_ThreadedRenderer_setDrawingEnabled(JNIEnv*, jclass, jboolean enabled) {
@@ -1034,7 +1033,7 @@
         {"nSetForceDark", "(JZ)V", (void*)android_view_ThreadedRenderer_setForceDark},
         {"nSetDisplayDensityDpi", "(I)V",
          (void*)android_view_ThreadedRenderer_setDisplayDensityDpi},
-        {"nInitDisplayInfo", "(IIFIJJZ)V", (void*)android_view_ThreadedRenderer_initDisplayInfo},
+        {"nInitDisplayInfo", "(IIFIJJZZ)V", (void*)android_view_ThreadedRenderer_initDisplayInfo},
         {"preload", "()V", (void*)android_view_ThreadedRenderer_preload},
         {"isWebViewOverlaysEnabled", "()Z",
          (void*)android_view_ThreadedRenderer_isWebViewOverlaysEnabled},