[HWUI] Remove hardcoding around wide color gamut.
Previously we hardcode wide color gamut in HWUI as scRGB color space with FP16
pixel format. However, the hardware composer doesn't support this combination.
This patch plumbs wide color gamut composition preference from composer API to
HWUI such that HWUI can now pick the combination of color space and pixel
format for the surface.
BUG: 111436479
Test: Build, flash and boot, verify with a demo app.
Change-Id: I7a8b4d8deca72ef40069dba9d23a3f5e90dbfe5a
diff --git a/libs/hwui/DeviceInfo.cpp b/libs/hwui/DeviceInfo.cpp
index 0b9d82b..ed167e5 100644
--- a/libs/hwui/DeviceInfo.cpp
+++ b/libs/hwui/DeviceInfo.cpp
@@ -20,6 +20,7 @@
#include <gui/ISurfaceComposer.h>
#include <gui/SurfaceComposerClient.h>
+#include <ui/GraphicTypes.h>
#include <mutex>
#include <thread>
@@ -61,6 +62,50 @@
return displayInfo;
}
+static void queryWideColorGamutPreference(SkColorSpace::Gamut* colorGamut,
+ sk_sp<SkColorSpace>* colorSpace, SkColorType* colorType) {
+ if (Properties::isolatedProcess) {
+ *colorGamut = SkColorSpace::Gamut::kSRGB_Gamut;
+ *colorSpace = SkColorSpace::MakeSRGB();
+ *colorType = SkColorType::kN32_SkColorType;
+ return;
+ }
+ ui::Dataspace defaultDataspace, wcgDataspace;
+ ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
+ status_t status =
+ SurfaceComposerClient::getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
+ &wcgDataspace, &wcgPixelFormat);
+ LOG_ALWAYS_FATAL_IF(status, "Failed to get composition preference, error %d", status);
+ switch (wcgDataspace) {
+ case ui::Dataspace::DISPLAY_P3:
+ *colorGamut = SkColorSpace::Gamut::kDCIP3_D65_Gamut;
+ *colorSpace = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
+ SkColorSpace::Gamut::kDCIP3_D65_Gamut);
+ break;
+ case ui::Dataspace::V0_SCRGB:
+ *colorGamut = SkColorSpace::Gamut::kSRGB_Gamut;
+ *colorSpace = SkColorSpace::MakeSRGB();
+ break;
+ case ui::Dataspace::V0_SRGB:
+ // when sRGB is returned, it means wide color gamut is not supported.
+ *colorGamut = SkColorSpace::Gamut::kSRGB_Gamut;
+ *colorSpace = SkColorSpace::MakeSRGB();
+ break;
+ default:
+ LOG_ALWAYS_FATAL("Unreachable: unsupported wide color space.");
+ }
+ switch (wcgPixelFormat) {
+ case ui::PixelFormat::RGBA_8888:
+ *colorType = SkColorType::kN32_SkColorType;
+ break;
+ case ui::PixelFormat::RGBA_FP16:
+ *colorType = SkColorType::kRGBA_F16_SkColorType;
+ break;
+ default:
+ LOG_ALWAYS_FATAL("Unreachable: unsupported pixel format.");
+ }
+}
+
DeviceInfo::DeviceInfo() {
#if HWUI_NULL_GPU
mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE;
@@ -68,6 +113,7 @@
mMaxTextureSize = -1;
#endif
mDisplayInfo = QueryDisplayInfo();
+ queryWideColorGamutPreference(&mWideColorGamut, &mWideColorSpace, &mWideColorType);
}
int DeviceInfo::maxTextureSize() const {