Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d7f3f3a2 authored by Sally Qi's avatar Sally Qi Committed by Android (Google) Code Review
Browse files

Merge "Refactor `isHdrDataspace` function." into main

parents eabdb615 f6918d4a
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -20,7 +20,6 @@


#include "SkiaRenderEngine.h"
#include "SkiaRenderEngine.h"


#include <include/gpu/ganesh/SkSurfaceGanesh.h>
#include <GrBackendSemaphore.h>
#include <GrBackendSemaphore.h>
#include <GrContextOptions.h>
#include <GrContextOptions.h>
#include <SkBlendMode.h>
#include <SkBlendMode.h>
@@ -55,13 +54,14 @@
#include <android-base/stringprintf.h>
#include <android-base/stringprintf.h>
#include <gui/FenceMonitor.h>
#include <gui/FenceMonitor.h>
#include <gui/TraceUtils.h>
#include <gui/TraceUtils.h>
#include <include/gpu/ganesh/SkSurfaceGanesh.h>
#include <pthread.h>
#include <pthread.h>
#include <src/core/SkTraceEventCommon.h>
#include <src/core/SkTraceEventCommon.h>
#include <sync/sync.h>
#include <sync/sync.h>
#include <ui/BlurRegion.h>
#include <ui/BlurRegion.h>
#include <ui/DataspaceUtils.h>
#include <ui/DebugUtils.h>
#include <ui/DebugUtils.h>
#include <ui/GraphicBuffer.h>
#include <ui/GraphicBuffer.h>
#include <ui/HdrRenderTypeUtils.h>
#include <utils/Trace.h>
#include <utils/Trace.h>


#include <cmath>
#include <cmath>
@@ -1025,7 +1025,10 @@ void SkiaRenderEngine::drawLayersInternal(
            // Most HDR standards require at least 10-bits of color depth for source content, so we
            // 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.
            // 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.
            // 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;
                    buffer->getPixelFormat() == PIXEL_FORMAT_RGBA_8888;
            if (layerDimmingRatio <= kDimmingThreshold || requiresDownsample) {
            if (layerDimmingRatio <= kDimmingThreshold || requiresDownsample) {
                paint.setDither(true);
                paint.setDither(true);
+64 −0
Original line number Original line Diff line number Diff line
@@ -20,10 +20,45 @@


namespace android {
namespace android {


inline bool isHdrDataspace(ui::Dataspace dataspace) {
enum class HdrRenderType {
    SDR,         // just render to SDR
    DISPLAY_HDR, // HDR by extended brightness
    GENERIC_HDR  // tonemapped HDR
};

/***
 * A helper function to classify how we treat the result based on params.
 *
 * @param dataspace the dataspace
 * @param pixelFormat optional, in case there is no source buffer.
 * @param hdrSdrRatio default is 1.f, render engine side doesn't take care of it.
 * @return HdrRenderType
 */
inline HdrRenderType getHdrRenderType(ui::Dataspace dataspace,
                                      std::optional<ui::PixelFormat> pixelFormat,
                                      float hdrSdrRatio = 1.f) {
    const auto transfer = dataspace & HAL_DATASPACE_TRANSFER_MASK;
    const auto transfer = dataspace & HAL_DATASPACE_TRANSFER_MASK;
    const auto range = dataspace & HAL_DATASPACE_RANGE_MASK;

    if (transfer == HAL_DATASPACE_TRANSFER_ST2084 || transfer == HAL_DATASPACE_TRANSFER_HLG) {
        return HdrRenderType::GENERIC_HDR;
    }

    static const auto BT2020_LINEAR_EXT = static_cast<ui::Dataspace>(HAL_DATASPACE_STANDARD_BT2020 |
                                                                     HAL_DATASPACE_TRANSFER_LINEAR |
                                                                     HAL_DATASPACE_RANGE_EXTENDED);

    if ((dataspace == BT2020_LINEAR_EXT || dataspace == ui::Dataspace::V0_SCRGB) &&
        pixelFormat.has_value() && pixelFormat.value() == ui::PixelFormat::RGBA_FP16) {
        return HdrRenderType::GENERIC_HDR;
    }

    // Extended range layer with an hdr/sdr ratio of > 1.01f can "self-promote" to HDR.
    if (range == HAL_DATASPACE_RANGE_EXTENDED && hdrSdrRatio > 1.01f) {
        return HdrRenderType::DISPLAY_HDR;
    }


    return transfer == HAL_DATASPACE_TRANSFER_ST2084 || transfer == HAL_DATASPACE_TRANSFER_HLG;
    return HdrRenderType::SDR;
}
}


} // namespace android
} // namespace android
 No newline at end of file
+2 −2
Original line number Original line Diff line number Diff line
@@ -164,9 +164,9 @@ cc_test {
}
}


cc_test {
cc_test {
    name: "DataspaceUtils_test",
    name: "HdrRenderTypeUtils_test",
    shared_libs: ["libui"],
    shared_libs: ["libui"],
    srcs: ["DataspaceUtils_test.cpp"],
    srcs: ["HdrRenderTypeUtils_test.cpp"],
    cflags: [
    cflags: [
        "-Wall",
        "-Wall",
        "-Werror",
        "-Werror",
+0 −53
Original line number Original line Diff line number Diff line
/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#undef LOG_TAG
#define LOG_TAG "DataspaceUtilsTest"

#include <gtest/gtest.h>
#include <ui/DataspaceUtils.h>

namespace android {

class DataspaceUtilsTest : public testing::Test {};

TEST_F(DataspaceUtilsTest, isHdrDataspace) {
    EXPECT_TRUE(isHdrDataspace(ui::Dataspace::BT2020_ITU_HLG));
    EXPECT_TRUE(isHdrDataspace(ui::Dataspace::BT2020_ITU_PQ));
    EXPECT_TRUE(isHdrDataspace(ui::Dataspace::BT2020_PQ));
    EXPECT_TRUE(isHdrDataspace(ui::Dataspace::BT2020_HLG));

    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::V0_SRGB_LINEAR));
    // scRGB defines a very wide gamut but not an expanded luminance range
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::V0_SCRGB_LINEAR));
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::V0_SRGB));
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::V0_SCRGB));
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::V0_JFIF));
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::V0_BT601_625));
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::V0_BT601_525));
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::V0_BT709));
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::DCI_P3_LINEAR));
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::DCI_P3));
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::DISPLAY_P3_LINEAR));
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::DISPLAY_P3));
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::ADOBE_RGB));
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::BT2020_LINEAR));
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::BT2020));
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::BT2020_ITU));
    EXPECT_FALSE(isHdrDataspace(ui::Dataspace::DISPLAY_BT2020));
}

} // namespace android
+65 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#undef LOG_TAG
#define LOG_TAG "HdrRenderTypeUtilsTest"

#include <gtest/gtest.h>
#include <ui/HdrRenderTypeUtils.h>

namespace android {

class HdrRenderTypeUtilsTest : public testing::Test {};

TEST_F(HdrRenderTypeUtilsTest, getHdrRenderType) {
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::BT2020_ITU_HLG, std::nullopt),
              HdrRenderType::GENERIC_HDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::BT2020_ITU_PQ, std::nullopt),
              HdrRenderType::GENERIC_HDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::BT2020_PQ, std::nullopt), HdrRenderType::GENERIC_HDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::BT2020_HLG, std::nullopt),
              HdrRenderType::GENERIC_HDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::V0_SCRGB,
                               std::optional<ui::PixelFormat>(ui::PixelFormat::RGBA_FP16)),
              HdrRenderType::GENERIC_HDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::V0_SCRGB,
                               std::optional<ui::PixelFormat>(ui::PixelFormat::RGBA_8888), 2.f),
              HdrRenderType::DISPLAY_HDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::V0_SCRGB_LINEAR,
                               std::optional<ui::PixelFormat>(ui::PixelFormat::RGBA_8888), 2.f),
              HdrRenderType::DISPLAY_HDR);

    EXPECT_EQ(getHdrRenderType(ui::Dataspace::V0_SRGB_LINEAR, std::nullopt), HdrRenderType::SDR);
    // scRGB defines a very wide gamut but not an expanded luminance range
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::V0_SCRGB_LINEAR, std::nullopt), HdrRenderType::SDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::V0_SCRGB, std::nullopt), HdrRenderType::SDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::V0_SRGB, std::nullopt), HdrRenderType::SDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::V0_JFIF, std::nullopt), HdrRenderType::SDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::V0_BT601_625, std::nullopt), HdrRenderType::SDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::V0_BT601_525, std::nullopt), HdrRenderType::SDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::V0_BT709, std::nullopt), HdrRenderType::SDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::DCI_P3_LINEAR, std::nullopt), HdrRenderType::SDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::DCI_P3, std::nullopt), HdrRenderType::SDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::DISPLAY_P3_LINEAR, std::nullopt), HdrRenderType::SDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::DISPLAY_P3, std::nullopt), HdrRenderType::SDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::ADOBE_RGB, std::nullopt), HdrRenderType::SDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::BT2020_LINEAR, std::nullopt), HdrRenderType::SDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::BT2020, std::nullopt), HdrRenderType::SDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::BT2020_ITU, std::nullopt), HdrRenderType::SDR);
    EXPECT_EQ(getHdrRenderType(ui::Dataspace::DISPLAY_BT2020, std::nullopt), HdrRenderType::SDR);
}

} // namespace android
Loading