[SurfaceFlinger] Use GPU composition for per layer color transform when necessary.

Previously we moved the fallback mechanism to composer@2.3 passthrough, as a
result composer before 2.3 can't trigger GPU composition. This patch help
proactively set the composition type to CLIENT on devices that don't upgrade to
composer@2.3.

BUG: 130621073
Test: Verify with customized grayscaled matrix.
Change-Id: I08e6a215872a62008deef708444245bd50807640
diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
index a08ae8c..4ea587d 100644
--- a/services/surfaceflinger/BufferLayer.cpp
+++ b/services/surfaceflinger/BufferLayer.cpp
@@ -321,7 +321,10 @@
     }
 
     error = hwcLayer->setColorTransform(getColorTransform());
-    if (error != HWC2::Error::None) {
+    if (error == HWC2::Error::Unsupported) {
+        // If per layer color transform is not supported, we use GPU composition.
+        setCompositionType(displayDevice, Hwc2::IComposerClient::Composition::CLIENT);
+    } else if (error != HWC2::Error::None) {
         ALOGE("[%s] Failed to setColorTransform: %s (%d)", mName.string(),
                 to_string(error).c_str(), static_cast<int32_t>(error));
     }
diff --git a/services/surfaceflinger/DisplayHardware/HWC2.cpp b/services/surfaceflinger/DisplayHardware/HWC2.cpp
index 9690605..3012ed8 100644
--- a/services/surfaceflinger/DisplayHardware/HWC2.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWC2.cpp
@@ -1029,9 +1029,13 @@
     if (matrix == mColorMatrix) {
         return Error::None;
     }
-    mColorMatrix = matrix;
     auto intError = mComposer.setLayerColorTransform(mDisplayId, mId, matrix.asArray());
-    return static_cast<Error>(intError);
+    Error error = static_cast<Error>(intError);
+    if (error != Error::None) {
+        return error;
+    }
+    mColorMatrix = matrix;
+    return error;
 }
 
 } // namespace impl