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

Commit 3d0c02e7 authored by Lloyd Pique's avatar Lloyd Pique
Browse files

SF: Separate out display color handling

This creates a new class for the purpose of holding all the
functionality related to how colors are handled on the output display.

Test: atest libsurfaceflinger_unittest libcompositionengine_test
Bug: 121291683
Change-Id: Idcd4808c42d17ca37656993131d280ead3137a52
parent 31cb2945
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ cc_library {
    srcs: [
        "src/CompositionEngine.cpp",
        "src/Display.cpp",
        "src/DisplayColorProfile.cpp",
        "src/DisplaySurface.cpp",
        "src/DumpHelpers.cpp",
        "src/Output.cpp",
@@ -54,6 +55,7 @@ cc_library {
    srcs: [
        "mock/CompositionEngine.cpp",
        "mock/Display.cpp",
        "mock/DisplayColorProfile.cpp",
        "mock/DisplaySurface.cpp",
        "mock/Output.cpp",
        "mock/RenderSurface.cpp",
@@ -73,9 +75,10 @@ cc_test {
    defaults: ["libcompositionengine_defaults"],
    srcs: [
        "tests/CompositionEngineTest.cpp",
        "tests/DisplayColorProfileTest.cpp",
        "tests/DisplayTest.cpp",
        "tests/OutputTest.cpp",
        "tests/MockHWComposer.cpp",
        "tests/OutputTest.cpp",
        "tests/RenderSurfaceTest.cpp",
    ],
    static_libs: [
+5 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
namespace android::compositionengine {

struct RenderSurfaceCreationArgs;
struct DisplayColorProfileCreationArgs;

/**
 * A display is a composition target which may be backed by a hardware composer
@@ -45,6 +46,10 @@ public:
    // Releases the use of the HWC display, if any
    virtual void disconnect() = 0;

    // Creates a render color mode for the display
    virtual void createDisplayColorProfile(DisplayColorProfileCreationArgs&&) = 0;

    // Creates a render surface for the display
    virtual void createRenderSurface(RenderSurfaceCreationArgs&&) = 0;

protected:
+83 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 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.
 */

#pragma once

#include <cstdint>

#include <ui/GraphicTypes.h>

namespace android {

class HdrCapabilities;

namespace compositionengine {

/**
 * Encapsulates all the state and functionality for how colors should be
 * transformed for a display
 */
class DisplayColorProfile {
public:
    constexpr static float sDefaultMinLumiance = 0.0;
    constexpr static float sDefaultMaxLumiance = 500.0;

    virtual ~DisplayColorProfile();

    // Returns true if the profile is valid. This is meant to be checked post-
    // construction and prior to use, as not everything is set up by the
    // constructor.
    virtual bool isValid() const = 0;

    // Returns true if the profile supports the indicated render intent
    virtual bool hasRenderIntent(ui::RenderIntent) const = 0;

    // Returns true if the profile supports the indicated dataspace
    virtual bool hasLegacyHdrSupport(ui::Dataspace) const = 0;

    // Obtains the best combination of color mode and render intent for the
    // input values
    virtual void getBestColorMode(ui::Dataspace dataspace, ui::RenderIntent intent,
                                  ui::Dataspace* outDataspace, ui::ColorMode* outMode,
                                  ui::RenderIntent* outIntent) const = 0;

    // Returns true if the profile supports a wide color gamut
    virtual bool hasWideColorGamut() const = 0;

    // Returns the per-frame metadata value for this profile
    virtual int32_t getSupportedPerFrameMetadata() const = 0;

    // Returns true if HWC for this profile supports HDR10Plus
    virtual bool hasHDR10PlusSupport() const = 0;

    // Returns true if HWC for this profile supports HDR10
    virtual bool hasHDR10Support() const = 0;

    // Returns true if HWC for this profile supports HLG
    virtual bool hasHLGSupport() const = 0;

    // Returns true if HWC for this profile supports DolbyVision
    virtual bool hasDolbyVisionSupport() const = 0;

    // Gets the supported HDR capabilities for the profile
    virtual const HdrCapabilities& getHdrCapabilities() const = 0;

    // Debugging
    virtual void dump(std::string&) const = 0;
};

} // namespace compositionengine
} // namespace android
+89 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 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.
 */

#pragma once

#include <cstdint>
#include <unordered_map>
#include <vector>

#include <ui/GraphicTypes.h>
#include <ui/HdrCapabilities.h>

namespace android::compositionengine {

/**
 * A parameter object for creating DisplayColorProfile instances
 */
struct DisplayColorProfileCreationArgs {
    using HwcColorModes = std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>;

    // True if this display supports a wide color gamut
    bool hasWideColorGamut;

    // The HDR capabilities supported by the HWC
    HdrCapabilities hdrCapabilities;

    // The per-frame metadata supported by the HWC
    int32_t supportedPerFrameMetadata;

    // The mapping of color modes and render intents supported by the HWC
    HwcColorModes hwcColorModes;
};

/**
 * A helper for setting up a DisplayColorProfileCreationArgs value in-line.
 *
 * Prefer this builder over raw structure initialization.
 *
 * Instead of:
 *
 *   DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
 *                                   HwcColorModes()}
 *
 * Prefer:
 *
 *  DisplayColorProfileCreationArgsBuilder().setHasWideColorGamut(false)
 *      .setIsVirtual(false).setDisplayId(displayId).Build();
 */
class DisplayColorProfileCreationArgsBuilder {
public:
    DisplayColorProfileCreationArgs Build() { return std::move(mArgs); }

    DisplayColorProfileCreationArgsBuilder& setHasWideColorGamut(bool hasWideColorGamut) {
        mArgs.hasWideColorGamut = hasWideColorGamut;
        return *this;
    }
    DisplayColorProfileCreationArgsBuilder& setHdrCapabilities(HdrCapabilities&& hdrCapabilities) {
        mArgs.hdrCapabilities = std::move(hdrCapabilities);
        return *this;
    }
    DisplayColorProfileCreationArgsBuilder& setSupportedPerFrameMetadata(
            int32_t supportedPerFrameMetadata) {
        mArgs.supportedPerFrameMetadata = supportedPerFrameMetadata;
        return *this;
    }
    DisplayColorProfileCreationArgsBuilder& setHwcColorModes(
            DisplayColorProfileCreationArgs::HwcColorModes&& hwcColorModes) {
        mArgs.hwcColorModes = std::move(hwcColorModes);
        return *this;
    }

private:
    DisplayColorProfileCreationArgs mArgs;
};

} // namespace android::compositionengine
+6 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@

namespace android::compositionengine {

class DisplayColorProfile;
class RenderSurface;

namespace impl {
@@ -72,6 +73,9 @@ public:
    // Sets a debug name for the output
    virtual void setName(const std::string&) = 0;

    // Gets the current render color mode for the output
    virtual DisplayColorProfile* getDisplayColorProfile() const = 0;

    // Gets the current render surface for the output
    virtual RenderSurface* getRenderSurface() const = 0;

@@ -98,7 +102,8 @@ public:
protected:
    ~Output() = default;

    virtual void setRenderSurface(std::unique_ptr<RenderSurface> surface) = 0;
    virtual void setDisplayColorProfile(std::unique_ptr<DisplayColorProfile>) = 0;
    virtual void setRenderSurface(std::unique_ptr<RenderSurface>) = 0;
};

} // namespace android::compositionengine
Loading