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

Commit fb069305 authored by Peiyong Lin's avatar Peiyong Lin
Browse files

[SurfaceFlinger] Adapt min/max luminance from hardware composer.

The luminance capability of the display is very important to HDR content.
Previously, the minimum and maximum luminance were assumed as 0.0 and 500.0
respectively. This patch adapts the value returned from hardware composer and
plumbs the value to RenderEngine. If hardware composer doesn't return valid
values, 0.0 and 500.0 are still used as minimum and maximum luminance
respectively.

BUG: 73825729
BUG: 78574325
Test: Build, flash, watch video.
Change-Id: Ie1dc93f5cca7068580d6ae19da43346491196d7c
parent af0c7830
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ HdrCapabilities::~HdrCapabilities() = default;
HdrCapabilities::HdrCapabilities(HdrCapabilities&& other) = default;
HdrCapabilities& HdrCapabilities::operator=(HdrCapabilities&& other) = default;


size_t HdrCapabilities::getFlattenedSize() const {
    return  sizeof(mMaxLuminance) +
            sizeof(mMaxAverageLuminance) +
+22 −1
Original line number Diff line number Diff line
@@ -108,7 +108,8 @@ DisplayDevice::DisplayDevice(
      mSupportedPerFrameMetadata(supportedPerFrameMetadata)
{
    // clang-format on
    for (Hdr hdrType : hdrCapabilities.getSupportedHdrTypes()) {
    std::vector<Hdr> types = hdrCapabilities.getSupportedHdrTypes();
    for (Hdr hdrType : types) {
        switch (hdrType) {
            case Hdr::HDR10:
                mHasHdr10 = true;
@@ -124,6 +125,26 @@ DisplayDevice::DisplayDevice(
        }
    }

    float minLuminance = hdrCapabilities.getDesiredMinLuminance();
    float maxLuminance = hdrCapabilities.getDesiredMaxLuminance();
    float maxAverageLuminance = hdrCapabilities.getDesiredMaxAverageLuminance();

    minLuminance = minLuminance <= 0.0 ? sDefaultMinLumiance : minLuminance;
    maxLuminance = maxLuminance <= 0.0 ? sDefaultMaxLumiance : maxLuminance;
    maxAverageLuminance = maxAverageLuminance <= 0.0 ? sDefaultMaxLumiance : maxAverageLuminance;
    if (this->hasWideColorGamut()) {
        // insert HDR10/HLG as we will force client composition for HDR10/HLG
        // layers
        if (!hasHDR10Support()) {
          types.push_back(Hdr::HDR10);
        }

        if (!hasHLGSupport()) {
          types.push_back(Hdr::HLG);
        }
    }
    mHdrCapabilities = HdrCapabilities(types, maxLuminance, maxAverageLuminance, minLuminance);

    // initialize the display orientation transform.
    setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
}
+15 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <gui/ISurfaceComposer.h>
#include <hardware/hwcomposer_defs.h>
#include <ui/GraphicTypes.h>
#include <ui/HdrCapabilities.h>
#include <ui/Region.h>
#include <utils/RefBase.h>
#include <utils/Mutex.h>
@@ -53,6 +54,9 @@ class HWComposer;
class DisplayDevice : public LightRefBase<DisplayDevice>
{
public:
    constexpr static float sDefaultMinLumiance = 0.0;
    constexpr static float sDefaultMaxLumiance = 500.0;

    // region in layer-stack space
    mutable Region dirtyRegion;
    // region in screen space
@@ -141,6 +145,13 @@ public:
    bool hasHDR10Support() const { return mHasHdr10; }
    bool hasHLGSupport() const { return mHasHLG; }
    bool hasDolbyVisionSupport() const { return mHasDolbyVision; }
    // The returned HdrCapabilities is the combination of HDR capabilities from
    // hardware composer and RenderEngine. When the DisplayDevice supports wide
    // color gamut, RenderEngine is able to simulate HDR support in Display P3
    // color space for both PQ and HLG HDR contents. The minimum and maximum
    // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance
    // respectively if hardware composer doesn't return meaningful values.
    const HdrCapabilities& getHdrCapabilities() const { return mHdrCapabilities; }

    void swapBuffers(HWComposer& hwc) const;

@@ -261,7 +272,7 @@ private:
    bool mHasHdr10;
    bool mHasHLG;
    bool mHasDolbyVision;

    HdrCapabilities mHdrCapabilities;
    const int32_t mSupportedPerFrameMetadata;
};

@@ -309,6 +320,9 @@ public:
    ui::Dataspace getDataSpace() const override {
        return mDevice->getCompositionDataSpace();
    }
    float getDisplayMaxLuminance() const override {
        return mDevice->getHdrCapabilities().getDesiredMaxLuminance();
    }

private:
    const sp<const DisplayDevice> mDevice;
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ public:
    virtual Rect getSourceCrop() const = 0;
    virtual bool getWideColorSupport() const = 0;
    virtual ui::Dataspace getDataSpace() const = 0;
    virtual float getDisplayMaxLuminance() const = 0;

    virtual void render(std::function<void()> drawLayers) { drawLayers(); }

+4 −0
Original line number Diff line number Diff line
@@ -73,4 +73,8 @@ void Description::setOutputTransferFunction(TransferFunction transferFunction) {
    mOutputTransferFunction = transferFunction;
}

void Description::setDisplayMaxLuminance(const float maxLuminance) {
    mDisplayMaxLuminance = maxLuminance;
}

} /* namespace android */
Loading