Refactor `isHdrDataspace` function.
- Rename it to `getHdrRenderType` and return a ternary enum.
- return the hdr type that we want to treat based on the dataspace,
format and hdr/sdr ratio.
- pixelformat is optional, in case no source buffer but there is a
source color.
- hdr/sdr ratio is 1.0f by default, render rengine doesn't take care
this param.
- The ternary enum has 3 types: just SDR; generic hdr, namely those we
need to tonemap; display hdr, namely those self-promoting to HDR by
using extended brightness API.
Bug: 261485283
Test: HdrRenderTypeUtils_test, TextureViewTest#testSDRFromSurfaceViewAndTextureView, OutputLayerUpdateCompositionStateTest
Change-Id: I281687a010bbf5bff555f6fa893002c2a9b324d1
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index ef483f6..13a457e 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -81,7 +81,6 @@
#include <scheduler/FrameTargeter.h>
#include <sys/types.h>
#include <ui/ColorSpace.h>
-#include <ui/DataspaceUtils.h>
#include <ui/DebugUtils.h>
#include <ui/DisplayId.h>
#include <ui/DisplayMode.h>
@@ -89,6 +88,7 @@
#include <ui/DisplayState.h>
#include <ui/DynamicDisplayInfo.h>
#include <ui/GraphicBufferAllocator.h>
+#include <ui/HdrRenderTypeUtils.h>
#include <ui/LayerStack.h>
#include <ui/PixelFormat.h>
#include <ui/StaticDisplayInfo.h>
@@ -2796,7 +2796,14 @@
return false;
}
}
- if (isHdrDataspace(snapshot.dataspace)) {
+ // RANGE_EXTENDED layer may identify themselves as being "HDR"
+ // via a desired hdr/sdr ratio
+ auto pixelFormat = snapshot.buffer
+ ? std::make_optional(static_cast<ui::PixelFormat>(snapshot.buffer->getPixelFormat()))
+ : std::nullopt;
+
+ if (getHdrRenderType(snapshot.dataspace, pixelFormat, snapshot.desiredHdrSdrRatio) !=
+ HdrRenderType::SDR) {
return true;
}
// If the layer is not allowed to be dimmed, treat it as HDR. WindowManager may disable
@@ -2806,12 +2813,6 @@
if (!snapshot.dimmingEnabled) {
return true;
}
- // RANGE_EXTENDED layers may identify themselves as being "HDR" via a desired sdr/hdr ratio
- if ((snapshot.dataspace & (int32_t)Dataspace::RANGE_MASK) ==
- (int32_t)Dataspace::RANGE_EXTENDED &&
- snapshot.desiredHdrSdrRatio > 1.01f) {
- return true;
- }
return false;
}