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/libs/renderengine/skia/SkiaRenderEngine.cpp b/libs/renderengine/skia/SkiaRenderEngine.cpp
index 29d8ba7..8ea9ee7 100644
--- a/libs/renderengine/skia/SkiaRenderEngine.cpp
+++ b/libs/renderengine/skia/SkiaRenderEngine.cpp
@@ -20,7 +20,6 @@
#include "SkiaRenderEngine.h"
-#include <include/gpu/ganesh/SkSurfaceGanesh.h>
#include <GrBackendSemaphore.h>
#include <GrContextOptions.h>
#include <SkBlendMode.h>
@@ -55,13 +54,14 @@
#include <android-base/stringprintf.h>
#include <gui/FenceMonitor.h>
#include <gui/TraceUtils.h>
+#include <include/gpu/ganesh/SkSurfaceGanesh.h>
#include <pthread.h>
#include <src/core/SkTraceEventCommon.h>
#include <sync/sync.h>
#include <ui/BlurRegion.h>
-#include <ui/DataspaceUtils.h>
#include <ui/DebugUtils.h>
#include <ui/GraphicBuffer.h>
+#include <ui/HdrRenderTypeUtils.h>
#include <utils/Trace.h>
#include <cmath>
@@ -1027,7 +1027,10 @@
// Most HDR standards require at least 10-bits of color depth for source content, so we
// can just extract the transfer function rather than dig into precise gralloc layout.
// Furthermore, we can assume that the only 8-bit target we support is RGBA8888.
- const bool requiresDownsample = isHdrDataspace(layer.sourceDataspace) &&
+ const bool requiresDownsample =
+ getHdrRenderType(layer.sourceDataspace,
+ std::optional<ui::PixelFormat>(static_cast<ui::PixelFormat>(
+ buffer->getPixelFormat()))) != HdrRenderType::SDR &&
buffer->getPixelFormat() == PIXEL_FORMAT_RGBA_8888;
if (layerDimmingRatio <= kDimmingThreshold || requiresDownsample) {
paint.setDither(true);