Use wide gamut only when necessary
Set the dataspace of the screenshot based on the result of
the composition. When no wide gamut app is visible, the screenshot
will be in sRGB, otherwise in Display P3. On device that do not
support wide gamut, the color space will be unknown (native).
Bug: 29940137
Test: screencap and Android Studio
Change-Id: I93f3f8e5afebb9f3f17b835fdf5bc215b0856d55
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index beefc50..000b4c6 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -152,7 +152,6 @@
mPrimaryDispSync("PrimaryDispSync"),
mPrimaryHWVsyncEnabled(false),
mHWVsyncAvailable(false),
- mHasColorMatrix(false),
mHasPoweredOff(false),
mFrameBuckets(),
mTotalTime(0),
@@ -4331,8 +4330,6 @@
err |= native_window_set_scaling_mode(window, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW);
err |= native_window_set_buffers_format(window, HAL_PIXEL_FORMAT_RGBA_8888);
err |= native_window_set_usage(window, usage);
- err |= native_window_set_buffers_data_space(window, hw->getWideColorSupport()
- ? HAL_DATASPACE_DISPLAY_P3 : HAL_DATASPACE_V0_SRGB);
if (err == NO_ERROR) {
ANativeWindowBuffer* buffer;
@@ -4359,6 +4356,14 @@
hw, sourceCrop, reqWidth, reqHeight, minLayerZ, maxLayerZ, true,
useIdentityTransform, rotation);
+#ifdef USE_HWC2
+ if (hasWideColorDisplay) {
+ native_window_set_buffers_data_space(window,
+ getRenderEngine().usesWideColor() ?
+ HAL_DATASPACE_DISPLAY_P3 : HAL_DATASPACE_V0_SRGB);
+ }
+#endif
+
// Attempt to create a sync khr object that can produce a sync point. If that
// isn't available, create a non-dupable sync object in the fallback path and
// wait on it directly.