Partially revert "[HWUI] Implement legacy color mode."

Reason for partially revert: Step back a little bit to think about how we want
to move the view system forward.

This patch removes the legacy mode we have added, as well as move color type
and color space of the surface to SkiaPipeline.

BUG: 111436479
BUG: 113530681
Test: Build, flash, boot and check dumpsys SurfaceFlinger

Change-Id: I1ab7b88d41347284d87649618e5a15f5c6bcf8fe
diff --git a/libs/hwui/DeviceInfo.cpp b/libs/hwui/DeviceInfo.cpp
index 21fbbdc..0b9d82b 100644
--- a/libs/hwui/DeviceInfo.cpp
+++ b/libs/hwui/DeviceInfo.cpp
@@ -61,18 +61,6 @@
     return displayInfo;
 }
 
-void QueryCompositionPreference(ui::Dataspace* dataSpace,
-                                ui::PixelFormat* pixelFormat) {
-    if (Properties::isolatedProcess) {
-        *dataSpace = ui::Dataspace::V0_SRGB;
-        *pixelFormat = ui::PixelFormat::RGBA_8888;
-    }
-
-    status_t status =
-            SurfaceComposerClient::getCompositionPreference(dataSpace, pixelFormat);
-    LOG_ALWAYS_FATAL_IF(status, "Failed to get composition preference, error %d", status);
-}
-
 DeviceInfo::DeviceInfo() {
 #if HWUI_NULL_GPU
         mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE;
@@ -80,7 +68,6 @@
         mMaxTextureSize = -1;
 #endif
     mDisplayInfo = QueryDisplayInfo();
-    QueryCompositionPreference(&mTargetDataSpace, &mTargetPixelFormat);
 }
 
 int DeviceInfo::maxTextureSize() const {
diff --git a/libs/hwui/DeviceInfo.h b/libs/hwui/DeviceInfo.h
index 1d747741..5956215 100644
--- a/libs/hwui/DeviceInfo.h
+++ b/libs/hwui/DeviceInfo.h
@@ -17,7 +17,6 @@
 #define DEVICEINFO_H
 
 #include <ui/DisplayInfo.h>
-#include <ui/GraphicTypes.h>
 
 #include "utils/Macros.h"
 
@@ -37,9 +36,6 @@
     // 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;
-
-    ui::Dataspace getTargetDataSpace() const { return mTargetDataSpace; }
-    ui::PixelFormat getTargetPixelFormat() const { return mTargetPixelFormat; }
     const DisplayInfo& displayInfo() const { return mDisplayInfo; }
 
 private:
@@ -50,10 +46,6 @@
 
     int mMaxTextureSize;
     DisplayInfo mDisplayInfo;
-
-    // TODO(lpy) Replace below with android_ prefix types.
-    ui::Dataspace mTargetDataSpace;
-    ui::PixelFormat mTargetPixelFormat;
 };
 
 } /* namespace uirenderer */
diff --git a/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp b/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp
index e8bf492..d401b38 100644
--- a/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp
+++ b/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp
@@ -167,6 +167,12 @@
         mEglSurface = mEglManager.createSurface(surface, colorMode);
     }
 
+    if (colorMode == ColorMode::SRGB) {
+        mSurfaceColorType = SkColorType::kN32_SkColorType;
+    } else if (colorMode == ColorMode::WideColorGamut) {
+        mSurfaceColorType = SkColorType::kRGBA_F16_SkColorType;
+    }
+
     if (mEglSurface != EGL_NO_SURFACE) {
         const bool preserveBuffer = (swapBehavior != SwapBehavior::kSwap_discardBuffer);
         mBufferPreserved = mEglManager.setPreserveBuffer(mEglSurface, preserveBuffer);
@@ -184,14 +190,6 @@
     return CC_LIKELY(mEglManager.hasEglContext());
 }
 
-SkColorType SkiaOpenGLPipeline::getSurfaceColorType() const {
-    return mEglManager.getSurfaceColorType();
-}
-
-sk_sp<SkColorSpace> SkiaOpenGLPipeline::getSurfaceColorSpace() {
-    return mEglManager.getSurfaceColorSpace();
-}
-
 void SkiaOpenGLPipeline::invokeFunctor(const RenderThread& thread, Functor* functor) {
     DrawGlInfo::Mode mode = DrawGlInfo::kModeProcessNoContext;
     if (thread.eglManager().hasEglContext()) {
diff --git a/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.h b/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.h
index 086a760..4ab3541 100644
--- a/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.h
+++ b/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.h
@@ -47,8 +47,6 @@
     void onStop() override;
     bool isSurfaceReady() override;
     bool isContextReady() override;
-    SkColorType getSurfaceColorType() const override;
-    sk_sp<SkColorSpace> getSurfaceColorSpace() override;
 
     static void invokeFunctor(const renderthread::RenderThread& thread, Functor* functor);
 
diff --git a/libs/hwui/pipeline/skia/SkiaPipeline.h b/libs/hwui/pipeline/skia/SkiaPipeline.h
index ee9158c..42a411a 100644
--- a/libs/hwui/pipeline/skia/SkiaPipeline.h
+++ b/libs/hwui/pipeline/skia/SkiaPipeline.h
@@ -48,6 +48,9 @@
     bool createOrUpdateLayer(RenderNode* node, const DamageAccumulator& damageAccumulator,
                              ErrorHandler* errorHandler) override;
 
+    SkColorType getSurfaceColorType() const { return mSurfaceColorType; }
+    sk_sp<SkColorSpace> getSurfaceColorSpace() override { return mSurfaceColorSpace; }
+
     void renderFrame(const LayerUpdateQueue& layers, const SkRect& clip,
                      const std::vector<sp<RenderNode>>& nodes, bool opaque,
                      const Rect& contentDrawBounds, sk_sp<SkSurface> surface);
@@ -106,6 +109,8 @@
     void dumpResourceCacheUsage() const;
 
     renderthread::RenderThread& mRenderThread;
+    SkColorType mSurfaceColorType;
+    sk_sp<SkColorSpace> mSurfaceColorSpace;
 
 private:
     void renderFrameImpl(const LayerUpdateQueue& layers, const SkRect& clip,
diff --git a/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp b/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp
index e34f160..8e15b8a 100644
--- a/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp
+++ b/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp
@@ -138,14 +138,6 @@
     return CC_LIKELY(mVkManager.hasVkContext());
 }
 
-SkColorType SkiaVulkanPipeline::getSurfaceColorType() const {
-    return mVkManager.getSurfaceColorType();
-}
-
-sk_sp<SkColorSpace> SkiaVulkanPipeline::getSurfaceColorSpace() {
-    return mVkManager.getSurfaceColorSpace();
-}
-
 void SkiaVulkanPipeline::invokeFunctor(const RenderThread& thread, Functor* functor) {
     VkFunctorDrawable::vkInvokeFunctor(functor);
 }
diff --git a/libs/hwui/pipeline/skia/SkiaVulkanPipeline.h b/libs/hwui/pipeline/skia/SkiaVulkanPipeline.h
index 6e723a8..14c0d69 100644
--- a/libs/hwui/pipeline/skia/SkiaVulkanPipeline.h
+++ b/libs/hwui/pipeline/skia/SkiaVulkanPipeline.h
@@ -43,8 +43,6 @@
     void onStop() override;
     bool isSurfaceReady() override;
     bool isContextReady() override;
-    SkColorType getSurfaceColorType() const override;
-    sk_sp<SkColorSpace> getSurfaceColorSpace() override;
 
     static void invokeFunctor(const renderthread::RenderThread& thread, Functor* functor);
     static sk_sp<Bitmap> allocateHardwareBitmap(renderthread::RenderThread& thread,
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index c8c394a..92a749f 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -144,8 +144,7 @@
 
     mNativeSurface = std::move(surface);
 
-    // TODO(b/111436479) Introduce a way for app to specify DisplayColorGamut mode.
-    ColorMode colorMode = mWideColorGamut ? ColorMode::WideColorGamut : ColorMode::Legacy;
+    ColorMode colorMode = mWideColorGamut ? ColorMode::WideColorGamut : ColorMode::SRGB;
     bool hasSurface = mRenderPipeline->setSurface(mNativeSurface.get(), mSwapBehavior, colorMode);
 
     mFrameNumber = -1;
diff --git a/libs/hwui/renderthread/EglManager.cpp b/libs/hwui/renderthread/EglManager.cpp
index 0cb23e5..d4ffddd 100644
--- a/libs/hwui/renderthread/EglManager.cpp
+++ b/libs/hwui/renderthread/EglManager.cpp
@@ -126,17 +126,6 @@
     createContext();
     createPBufferSurface();
     makeCurrent(mPBufferSurface, nullptr, /* force */ true);
-
-    mSurfaceColorGamut = DataSpaceToColorGamut(
-        static_cast<android_dataspace>(DeviceInfo::get()->getTargetDataSpace()));
-
-    LOG_ALWAYS_FATAL_IF(mSurfaceColorGamut == SkColorSpace::kDCIP3_D65_Gamut &&
-                        !EglExtensions.displayP3, "EGL doesn't support Display P3.");
-
-    mSurfaceColorType = PixelFormatToColorType(
-        static_cast<android_pixel_format>(DeviceInfo::get()->getTargetPixelFormat()));
-    mSurfaceColorSpace = DataSpaceToColorSpace(
-        static_cast<android_dataspace>(DeviceInfo::get()->getTargetDataSpace()));
 }
 
 void EglManager::initExtensions() {
@@ -309,21 +298,13 @@
         if (wideColorGamut) {
             attribs[1] = EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT;
         } else {
-            if (mSurfaceColorGamut == SkColorSpace::kDCIP3_D65_Gamut) {
-                attribs[1] = EGL_GL_COLORSPACE_DISPLAY_P3_EXT;
-            } else {
-                attribs[1] = EGL_GL_COLORSPACE_SRGB_KHR;
-            }
+            attribs[1] = EGL_GL_COLORSPACE_SRGB_KHR;
         }
 #else
         if (wideColorGamut) {
             attribs[1] = EGL_GL_COLORSPACE_SCRGB_EXT;
         } else {
-            if (mSurfaceColorGamut == SkColorSpace::kDCIP3_D65_Gamut) {
-                attribs[1] = EGL_GL_COLORSPACE_DISPLAY_P3_EXT;
-            } else {
-                attribs[1] = EGL_GL_COLORSPACE_LINEAR_KHR;
-            }
+            attribs[1] = EGL_GL_COLORSPACE_LINEAR_KHR;
         }
 #endif
     }
diff --git a/libs/hwui/renderthread/EglManager.h b/libs/hwui/renderthread/EglManager.h
index e97228c..55c81d4 100644
--- a/libs/hwui/renderthread/EglManager.h
+++ b/libs/hwui/renderthread/EglManager.h
@@ -78,9 +78,6 @@
     // Depending on installed extensions, the result is either Android native fence or EGL fence.
     status_t createReleaseFence(bool useFenceSync, EGLSyncKHR* eglFence, sp<Fence>& nativeFence);
 
-    SkColorType getSurfaceColorType() const { return mSurfaceColorType; }
-    sk_sp<SkColorSpace> getSurfaceColorSpace() { return mSurfaceColorSpace; }
-
 private:
 
     void initExtensions();
@@ -95,9 +92,6 @@
     EGLContext mEglContext;
     EGLSurface mPBufferSurface;
     EGLSurface mCurrentSurface;
-    SkColorSpace::Gamut mSurfaceColorGamut;
-    SkColorType mSurfaceColorType;
-    sk_sp<SkColorSpace> mSurfaceColorSpace;
 
     enum class SwapBehavior {
         Discard,
diff --git a/libs/hwui/renderthread/IRenderPipeline.h b/libs/hwui/renderthread/IRenderPipeline.h
index 0297c9c..4972554 100644
--- a/libs/hwui/renderthread/IRenderPipeline.h
+++ b/libs/hwui/renderthread/IRenderPipeline.h
@@ -43,15 +43,8 @@
 enum class MakeCurrentResult { AlreadyCurrent, Failed, Succeeded };
 
 enum class ColorMode {
-    // Legacy means HWUI will produce buffer with whatever platform prefers
-    // HWUI to produce, however, HWUI doesn't accurately convert color from
-    // source color space to destination color space, instead HWUI will take
-    // the pixel value directly and interpret it destination color space.
-    Legacy,
-    // DisplayColorGamut means HWUI will produce buffer with whatever platform
-    // prefers HWUI to produce and accurately convert color from source color
-    // space to destination color space.
-    DisplayColorGamut,
+    // SRGB means HWUI will produce buffer in SRGB color space.
+    SRGB,
     // WideColorGamut means HWUI would support rendering scRGB non-linear into
     // a signed buffer with enough range to support the wide color gamut of the
     // display.
diff --git a/libs/hwui/renderthread/VulkanManager.h b/libs/hwui/renderthread/VulkanManager.h
index 7a539ae..ebc11a5 100644
--- a/libs/hwui/renderthread/VulkanManager.h
+++ b/libs/hwui/renderthread/VulkanManager.h
@@ -118,10 +118,6 @@
     // Creates a fence that is signaled, when all the pending Vulkan commands are flushed.
     status_t createReleaseFence(sp<Fence>& nativeFence);
 
-    // TODO(b/115636873): Handle composition preference.
-    SkColorType getSurfaceColorType() const { return SkColorType::kN32_SkColorType; }
-    sk_sp<SkColorSpace> getSurfaceColorSpace() { return SkColorSpace::MakeSRGB(); }
-
 private:
     friend class RenderThread;
 
diff --git a/libs/hwui/tests/unit/SkiaPipelineTests.cpp b/libs/hwui/tests/unit/SkiaPipelineTests.cpp
index 680fcb3..cdf31da 100644
--- a/libs/hwui/tests/unit/SkiaPipelineTests.cpp
+++ b/libs/hwui/tests/unit/SkiaPipelineTests.cpp
@@ -386,7 +386,7 @@
 RENDERTHREAD_SKIA_PIPELINE_TEST(SkiaPipeline, context_lost) {
     auto pipeline = std::make_unique<SkiaOpenGLPipeline>(renderThread);
     EXPECT_FALSE(pipeline->isSurfaceReady());
-    EXPECT_TRUE(pipeline->setSurface((Surface*)0x01, SwapBehavior::kSwap_default, ColorMode::Legacy));
+    EXPECT_TRUE(pipeline->setSurface((Surface*)0x01, SwapBehavior::kSwap_default, ColorMode::SRGB));
     EXPECT_TRUE(pipeline->isSurfaceReady());
     renderThread.destroyGlContext();
     EXPECT_FALSE(pipeline->isSurfaceReady());
diff --git a/libs/hwui/utils/Color.cpp b/libs/hwui/utils/Color.cpp
index 9f71e91..3fb6a31 100644
--- a/libs/hwui/utils/Color.cpp
+++ b/libs/hwui/utils/Color.cpp
@@ -57,21 +57,6 @@
     return false;
 }
 
-SkColorType PixelFormatToColorType(android_pixel_format pixelFormat) {
-    switch (pixelFormat) {
-        case HAL_PIXEL_FORMAT_RGBA_8888:
-        case HAL_PIXEL_FORMAT_BGRA_8888:
-            return SkColorType::kN32_SkColorType;
-        case HAL_PIXEL_FORMAT_RGBA_FP16:
-            return SkColorType::kRGBA_F16_SkColorType;
-        case HAL_PIXEL_FORMAT_RGBA_1010102:
-            return SkColorType::kRGBA_1010102_SkColorType;
-        default:
-            ALOGW("Unsupported pixel format: %d, return kN32 by default", pixelFormat);
-            return SkColorType::kN32_SkColorType;
-    }
-}
-
 android::PixelFormat ColorTypeToPixelFormat(SkColorType colorType) {
     switch (colorType) {
         case kRGBA_8888_SkColorType:
@@ -92,30 +77,6 @@
     }
 }
 
-SkColorSpace::Gamut DataSpaceToColorGamut(android_dataspace dataSpace) {
-    switch (dataSpace & HAL_DATASPACE_STANDARD_MASK) {
-        case HAL_DATASPACE_STANDARD_BT709:
-            return SkColorSpace::kSRGB_Gamut;
-        case HAL_DATASPACE_STANDARD_BT2020:
-            return SkColorSpace::kRec2020_Gamut;
-        case HAL_DATASPACE_STANDARD_DCI_P3:
-            return SkColorSpace::kDCIP3_D65_Gamut;
-        case HAL_DATASPACE_STANDARD_ADOBE_RGB:
-            return SkColorSpace::kAdobeRGB_Gamut;
-        case HAL_DATASPACE_STANDARD_UNSPECIFIED:
-        case HAL_DATASPACE_STANDARD_BT601_625:
-        case HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED:
-        case HAL_DATASPACE_STANDARD_BT601_525:
-        case HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED:
-        case HAL_DATASPACE_STANDARD_BT2020_CONSTANT_LUMINANCE:
-        case HAL_DATASPACE_STANDARD_BT470M:
-        case HAL_DATASPACE_STANDARD_FILM:
-        default:
-            ALOGW("Unsupported Gamut: %d, return SRGB gamut by default", dataSpace);
-            return SkColorSpace::kSRGB_Gamut;
-    }
-}
-
 sk_sp<SkColorSpace> DataSpaceToColorSpace(android_dataspace dataspace) {
 
     SkColorSpace::Gamut gamut;
diff --git a/libs/hwui/utils/Color.h b/libs/hwui/utils/Color.h
index e935a0d..4daccda 100644
--- a/libs/hwui/utils/Color.h
+++ b/libs/hwui/utils/Color.h
@@ -115,12 +115,8 @@
 // returns true for sRGB, gamma 2.2 and Display P3 for instance
 bool transferFunctionCloseToSRGB(const SkColorSpace* colorSpace);
 
-SkColorType PixelFormatToColorType(android_pixel_format pixelFormat);
-
 android::PixelFormat ColorTypeToPixelFormat(SkColorType colorType);
 
-SkColorSpace::Gamut DataSpaceToColorGamut(android_dataspace dataSpace);
-
 sk_sp<SkColorSpace> DataSpaceToColorSpace(android_dataspace dataspace);
 
 struct Lab {