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

Commit 0d711268 authored by Chia-I Wu's avatar Chia-I Wu
Browse files

surfaceflinger: allow unknown render intents

Allow render intents that are unknown to SurfaceFlinger.

Bug: 79843697
Bug: 75981986
Test: manual
Change-Id: Ia81436747b1d2fe9f44e749b93a9c1a5a7f1f6cb
parent bbb44464
Loading
Loading
Loading
Loading
+11 −1
Original line number Original line Diff line number Diff line
@@ -708,8 +708,18 @@ void DisplayDevice::populateColorModes(
        return;
        return;
    }
    }


    // collect all known SDR render intents
    std::unordered_set<RenderIntent> sdrRenderIntents(sSdrRenderIntents.begin(),
                                                      sSdrRenderIntents.end());
    auto iter = hwcColorModes.find(ColorMode::SRGB);
    if (iter != hwcColorModes.end()) {
        for (auto intent : iter->second) {
            sdrRenderIntents.insert(intent);
        }
    }

    // add known SDR combinations
    // add known SDR combinations
    for (auto intent : sSdrRenderIntents) {
    for (auto intent : sdrRenderIntents) {
        for (auto mode : sSdrColorModes) {
        for (auto mode : sSdrColorModes) {
            addColorMode(hwcColorModes, mode, intent);
            addColorMode(hwcColorModes, mode, intent);
        }
        }
+42 −48
Original line number Original line Diff line number Diff line
@@ -158,29 +158,18 @@ bool useTrebleTestingOverride() {
    return std::string(value) == "true";
    return std::string(value) == "true";
}
}


DisplayColorSetting toDisplayColorSetting(int value) {
    switch(value) {
        case 0:
            return DisplayColorSetting::MANAGED;
        case 1:
            return DisplayColorSetting::UNMANAGED;
        case 2:
            return DisplayColorSetting::ENHANCED;
        default:
            return DisplayColorSetting::MANAGED;
    }
}

std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) {
std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) {
    switch(displayColorSetting) {
    switch(displayColorSetting) {
        case DisplayColorSetting::MANAGED:
        case DisplayColorSetting::MANAGED:
            return std::string("Natural Mode");
            return std::string("Managed");
        case DisplayColorSetting::UNMANAGED:
        case DisplayColorSetting::UNMANAGED:
            return std::string("Saturated Mode");
            return std::string("Unmanaged");
        case DisplayColorSetting::ENHANCED:
        case DisplayColorSetting::ENHANCED:
            return std::string("Auto Color Mode");
            return std::string("Enhanced");
        default:
            return std::string("Unknown ") +
                std::to_string(static_cast<int>(displayColorSetting));
    }
    }
    return std::string("Unknown Display Color Setting");
}
}


NativeWindowSurface::~NativeWindowSurface() = default;
NativeWindowSurface::~NativeWindowSurface() = default;
@@ -738,9 +727,7 @@ void SurfaceFlinger::readPersistentProperties() {
    ALOGV("Saturation is set to %.2f", mGlobalSaturationFactor);
    ALOGV("Saturation is set to %.2f", mGlobalSaturationFactor);


    property_get("persist.sys.sf.native_mode", value, "0");
    property_get("persist.sys.sf.native_mode", value, "0");
    mDisplayColorSetting = toDisplayColorSetting(atoi(value));
    mDisplayColorSetting = static_cast<DisplayColorSetting>(atoi(value));
    ALOGV("Display Color Setting is set to %s.",
          decodeDisplayColorSetting(mDisplayColorSetting).c_str());
}
}


void SurfaceFlinger::startBootAnim() {
void SurfaceFlinger::startBootAnim() {
@@ -1918,8 +1905,19 @@ void SurfaceFlinger::pickColorMode(const sp<DisplayDevice>& displayDevice,
    Dataspace hdrDataSpace;
    Dataspace hdrDataSpace;
    Dataspace bestDataSpace = getBestDataspace(displayDevice, &hdrDataSpace);
    Dataspace bestDataSpace = getBestDataspace(displayDevice, &hdrDataSpace);


    RenderIntent intent = mDisplayColorSetting == DisplayColorSetting::ENHANCED ?
    RenderIntent intent;
        RenderIntent::ENHANCE : RenderIntent::COLORIMETRIC;
    switch (mDisplayColorSetting) {
        case DisplayColorSetting::MANAGED:
        case DisplayColorSetting::UNMANAGED:
            intent = RenderIntent::COLORIMETRIC;
            break;
        case DisplayColorSetting::ENHANCED:
            intent = RenderIntent::ENHANCE;
            break;
        default: // vendor display color setting
            intent = static_cast<RenderIntent>(mDisplayColorSetting);
            break;
    }


    // respect hdrDataSpace only when there is modern HDR support
    // respect hdrDataSpace only when there is modern HDR support
    if (hdrDataSpace != Dataspace::UNKNOWN && displayDevice->hasModernHdrSupport(hdrDataSpace)) {
    if (hdrDataSpace != Dataspace::UNKNOWN && displayDevice->hasModernHdrSupport(hdrDataSpace)) {
@@ -2303,10 +2301,6 @@ sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal(
        nativeWindowSurface->preallocateBuffers();
        nativeWindowSurface->preallocateBuffers();
    }
    }


    if (hw->isPrimary() && hw->hasRenderIntent(RenderIntent::ENHANCE)) {
        mBuiltinDisplaySupportsEnhance = true;
    }

    ColorMode defaultColorMode = ColorMode::NATIVE;
    ColorMode defaultColorMode = ColorMode::NATIVE;
    Dataspace defaultDataSpace = Dataspace::UNKNOWN;
    Dataspace defaultDataSpace = Dataspace::UNKNOWN;
    if (hasWideColorGamut) {
    if (hasWideColorGamut) {
@@ -2899,7 +2893,7 @@ bool SurfaceFlinger::doComposeSurfaces(const sp<const DisplayDevice>& displayDev
        }
        }


        needsLegacyColorMatrix =
        needsLegacyColorMatrix =
            (displayDevice->getActiveRenderIntent() == RenderIntent::ENHANCE &&
            (displayDevice->getActiveRenderIntent() >= RenderIntent::ENHANCE &&
             outputDataspace != Dataspace::UNKNOWN &&
             outputDataspace != Dataspace::UNKNOWN &&
             outputDataspace != Dataspace::SRGB);
             outputDataspace != Dataspace::SRGB);


@@ -4073,7 +4067,8 @@ void SurfaceFlinger::dumpBufferingStats(String8& result) const {


void SurfaceFlinger::dumpWideColorInfo(String8& result) const {
void SurfaceFlinger::dumpWideColorInfo(String8& result) const {
    result.appendFormat("hasWideColorDisplay: %d\n", hasWideColorDisplay);
    result.appendFormat("hasWideColorDisplay: %d\n", hasWideColorDisplay);
    result.appendFormat("DisplayColorSetting: %d\n", mDisplayColorSetting);
    result.appendFormat("DisplayColorSetting: %s\n",
            decodeDisplayColorSetting(mDisplayColorSetting).c_str());


    // TODO: print out if wide-color mode is active or not
    // TODO: print out if wide-color mode is active or not


@@ -4601,15 +4596,7 @@ status_t SurfaceFlinger::onTransact(
                return NO_ERROR;
                return NO_ERROR;
            }
            }
            case 1023: { // Set native mode
            case 1023: { // Set native mode
                int32_t value = data.readInt32();
                mDisplayColorSetting = static_cast<DisplayColorSetting>(data.readInt32());
                if (value > 2) {
                    return BAD_VALUE;
                }
                if (value == 2 && !mBuiltinDisplaySupportsEnhance) {
                    return BAD_VALUE;
                }

                mDisplayColorSetting = toDisplayColorSetting(value);
                invalidateHwcGeometry();
                invalidateHwcGeometry();
                repaintEverything();
                repaintEverything();
                return NO_ERROR;
                return NO_ERROR;
@@ -4638,20 +4625,27 @@ status_t SurfaceFlinger::onTransact(
            }
            }
            // Is a DisplayColorSetting supported?
            // Is a DisplayColorSetting supported?
            case 1027: {
            case 1027: {
                int32_t value = data.readInt32();
                sp<const DisplayDevice> hw(getDefaultDisplayDevice());
                switch (value) {
                if (!hw) {
                    case 0:
                    return NAME_NOT_FOUND;
                }

                DisplayColorSetting setting = static_cast<DisplayColorSetting>(data.readInt32());
                switch (setting) {
                    case DisplayColorSetting::MANAGED:
                        reply->writeBool(hasWideColorDisplay);
                        reply->writeBool(hasWideColorDisplay);
                        return NO_ERROR;
                        break;
                    case 1:
                    case DisplayColorSetting::UNMANAGED:
                        reply->writeBool(true);
                        reply->writeBool(true);
                        return NO_ERROR;
                        break;
                    case 2:
                    case DisplayColorSetting::ENHANCED:
                        reply->writeBool(mBuiltinDisplaySupportsEnhance);
                        reply->writeBool(hw->hasRenderIntent(RenderIntent::ENHANCE));
                        return NO_ERROR;
                        break;
                    default:
                    default: // vendor display color setting
                        return BAD_VALUE;
                        reply->writeBool(hw->hasRenderIntent(static_cast<RenderIntent>(setting)));
                        break;
                }
                }
                return NO_ERROR;
            }
            }
        }
        }
    }
    }
+0 −1
Original line number Original line Diff line number Diff line
@@ -878,7 +878,6 @@ private:
    DisplayColorSetting mDisplayColorSetting = DisplayColorSetting::MANAGED;
    DisplayColorSetting mDisplayColorSetting = DisplayColorSetting::MANAGED;
    // Applied on sRGB layers when the render intent is non-colorimetric.
    // Applied on sRGB layers when the render intent is non-colorimetric.
    mat4 mLegacySrgbSaturationMatrix;
    mat4 mLegacySrgbSaturationMatrix;
    bool mBuiltinDisplaySupportsEnhance = false;


    using CreateBufferQueueFunction =
    using CreateBufferQueueFunction =
            std::function<void(sp<IGraphicBufferProducer>* /* outProducer */,
            std::function<void(sp<IGraphicBufferProducer>* /* outProducer */,