Remove hard code color space.
In general when there's a color space involved, we must explicitly
specify instead of hard coding.
Bug: N/A
Test: atest SurfaceFlinger_unittest
Change-Id: I87c84990b4ec4bd815d7d552346c5fc8c7274135
diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp
index bde73ba..8594ab3 100644
--- a/libs/gui/LayerState.cpp
+++ b/libs/gui/LayerState.cpp
@@ -592,19 +592,20 @@
SAFE_PARCEL(output.writeFloat, frameScale);
SAFE_PARCEL(output.writeBool, captureSecureLayers);
SAFE_PARCEL(output.writeInt32, uid);
- SAFE_PARCEL(output.writeBool, useRGBColorSpace);
+ SAFE_PARCEL(output.writeInt32, static_cast<int32_t>(dataspace));
return NO_ERROR;
}
status_t CaptureArgs::read(const Parcel& input) {
- int32_t format = 0;
- SAFE_PARCEL(input.readInt32, &format);
- pixelFormat = static_cast<ui::PixelFormat>(format);
+ int32_t value = 0;
+ SAFE_PARCEL(input.readInt32, &value);
+ pixelFormat = static_cast<ui::PixelFormat>(value);
SAFE_PARCEL(input.read, sourceCrop);
SAFE_PARCEL(input.readFloat, &frameScale);
SAFE_PARCEL(input.readBool, &captureSecureLayers);
SAFE_PARCEL(input.readInt32, &uid);
- SAFE_PARCEL(input.readBool, &useRGBColorSpace);
+ SAFE_PARCEL(input.readInt32, &value);
+ dataspace = static_cast<ui::Dataspace>(value);
return NO_ERROR;
}
diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h
index fed0ef3..ff395ec 100644
--- a/libs/gui/include/gui/LayerState.h
+++ b/libs/gui/include/gui/LayerState.h
@@ -312,12 +312,12 @@
float frameScale{1};
bool captureSecureLayers{false};
int32_t uid{UNSET_UID};
- // True to force using RGB color as the capture result.
+ // Force capture to be in a color space. If the value is ui::Dataspace::UNKNOWN, the captured
+ // result will be in the display's colorspace.
// The display may use non-RGB dataspace (ex. displayP3) that could cause pixel data could be
- // different from RGB (byte per color), and failed when checking colors.
- // NOTE: This should only be used for testing since in normal cases, we want the screen
- // capture's colorspace to match the display's colorspace
- bool useRGBColorSpace{false};
+ // different from SRGB (byte per color), and failed when checking colors in tests.
+ // NOTE: In normal cases, we want the screen to be captured in display's colorspace.
+ ui::Dataspace dataspace = ui::Dataspace::UNKNOWN;
virtual status_t write(Parcel& output) const;
virtual status_t read(const Parcel& input);
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 7edbcaa..575da26 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -5414,9 +5414,8 @@
// (ex. displayP3) to enhance the content, but some cases are checking native RGB in bytes,
// and failed if display is not in native mode. This provide a way to force using native
// colors when capture.
- if (args.useRGBColorSpace) {
- dataspace = Dataspace::V0_SRGB;
- } else {
+ dataspace = args.dataspace;
+ if (dataspace == ui::Dataspace::UNKNOWN) {
const ui::ColorMode colorMode = display->getCompositionDisplay()->getState().colorMode;
dataspace = pickDataspaceFromColorMode(colorMode);
}
@@ -5580,9 +5579,8 @@
// (ex. displayP3) to enhance the content, but some cases are checking native RGB in bytes,
// and failed if display is not in native mode. This provide a way to force using native
// colors when capture.
- if (args.useRGBColorSpace) {
- dataspace = Dataspace::V0_SRGB;
- } else {
+ dataspace = args.dataspace;
+ if (dataspace == ui::Dataspace::UNKNOWN) {
const ui::ColorMode colorMode = display->getCompositionDisplay()->getState().colorMode;
dataspace = pickDataspaceFromColorMode(colorMode);
}
diff --git a/services/surfaceflinger/tests/utils/ScreenshotUtils.h b/services/surfaceflinger/tests/utils/ScreenshotUtils.h
index ca3551e..a13f93b 100644
--- a/services/surfaceflinger/tests/utils/ScreenshotUtils.h
+++ b/services/surfaceflinger/tests/utils/ScreenshotUtils.h
@@ -34,7 +34,7 @@
const auto sf = ComposerService::getComposerService();
SurfaceComposerClient::Transaction().apply(true);
- captureArgs.useRGBColorSpace = true;
+ captureArgs.dataspace = ui::Dataspace::V0_SRGB;
const sp<SyncScreenCaptureListener> captureListener = new SyncScreenCaptureListener();
status_t status = sf->captureDisplay(captureArgs, captureListener);
@@ -67,7 +67,7 @@
const auto sf = ComposerService::getComposerService();
SurfaceComposerClient::Transaction().apply(true);
- captureArgs.useRGBColorSpace = true;
+ captureArgs.dataspace = ui::Dataspace::V0_SRGB;
const sp<SyncScreenCaptureListener> captureListener = new SyncScreenCaptureListener();
status_t status = sf->captureLayers(captureArgs, captureListener);
if (status != NO_ERROR) {