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

Commit 7a4cb7e1 authored by Brian Lindahl's avatar Brian Lindahl
Browse files

Add plumbing to pass picture profiles down to Composer HAL

Bug: 337330263
Test: atest OutputLayerWriteStateToHWCTest
Test: atest OutputUpdateAndWriteCompositionStateTest
Flag: com.android.graphics.libgui.flags.apply_picture_profiles
Change-Id: I082f4bc47c2d402e15fc3a3de5224889752272fa
parent 3a707e05
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -136,6 +136,7 @@ cc_library_shared {
        "GraphicBuffer.cpp",
        "GraphicBufferAllocator.cpp",
        "GraphicBufferMapper.cpp",
        "PictureProfileHandle.cpp",
        "PixelFormat.cpp",
        "PublicFormat.cpp",
        "StaticAsserts.cpp",
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 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.
 */

#include <ui/PictureProfileHandle.h>

#include <format>

namespace android {

const PictureProfileHandle PictureProfileHandle::NONE(0);

::std::string toString(const PictureProfileHandle& handle) {
    return std::format("{:#010x}", handle.getId());
}

} // namespace android
+60 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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 <stdint.h>
#include <array>
#include <string>

namespace android {

/**
 * An opaque value that uniquely identifies a picture profile, or a set of parameters, which
 * describes the configuration of a picture processing pipeline that is applied to a graphic buffer
 * to enhance its quality prior to rendering on the display.
 */
typedef int64_t PictureProfileId;

/**
 * A picture profile handle wraps the picture profile ID for type-safety, and represents an opaque
 * handle that doesn't have the performance drawbacks of Binders.
 */
class PictureProfileHandle {
public:
    // A profile that represents no picture processing.
    static const PictureProfileHandle NONE;

    PictureProfileHandle() { *this = NONE; }
    PictureProfileHandle(PictureProfileId id) : mId(id) {}

    PictureProfileId const& getId() const { return mId; }

    inline bool operator==(const PictureProfileHandle& rhs) { return mId == rhs.mId; }
    inline bool operator!=(const PictureProfileHandle& rhs) { return !(*this == rhs); }

    // Is the picture profile effectively null, or not-specified?
    inline bool operator!() const { return mId == NONE.mId; }

    operator bool() const { return !!*this; }

    friend ::std::string toString(const PictureProfileHandle& handle);

private:
    PictureProfileId mId;
};

} // namespace android
+2 −0
Original line number Diff line number Diff line
@@ -286,6 +286,8 @@ struct DisplayDeviceState {
    bool isProtected = false;
    // Refer to DisplayDevice::mRequestedRefreshRate, for virtual display only
    Fps requestedRefreshRate;
    int32_t maxLayerPictureProfiles = 0;
    bool hasPictureProcessing = false;

private:
    static std::atomic<int32_t> sNextSequenceId;
+36 −2
Original line number Diff line number Diff line
@@ -44,12 +44,11 @@ using hardware::Return;
using aidl::android::hardware::graphics::composer3::BnComposerCallback;
using aidl::android::hardware::graphics::composer3::Capability;
using aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness;
using aidl::android::hardware::graphics::composer3::CommandResultPayload;
using aidl::android::hardware::graphics::composer3::Luts;
using aidl::android::hardware::graphics::composer3::PowerMode;
using aidl::android::hardware::graphics::composer3::VirtualDisplay;

using aidl::android::hardware::graphics::composer3::CommandResultPayload;

using AidlColorMode = aidl::android::hardware::graphics::composer3::ColorMode;
using AidlContentType = aidl::android::hardware::graphics::composer3::ContentType;
using AidlDisplayIdentification =
@@ -1639,6 +1638,41 @@ Error AidlComposer::getPhysicalDisplayOrientation(Display displayId,
    return Error::NONE;
}

Error AidlComposer::getMaxLayerPictureProfiles(Display display, int32_t* outMaxProfiles) {
    const auto status = mAidlComposerClient->getMaxLayerPictureProfiles(translate<int64_t>(display),
                                                                        outMaxProfiles);
    if (!status.isOk()) {
        ALOGE("getMaxLayerPictureProfiles failed %s", status.getDescription().c_str());
        return static_cast<Error>(status.getServiceSpecificError());
    }
    return Error::NONE;
}

Error AidlComposer::setDisplayPictureProfileId(Display display, PictureProfileId id) {
    Error error = Error::NONE;
    mMutex.lock_shared();
    if (auto writer = getWriter(display)) {
        writer->get().setDisplayPictureProfileId(translate<int64_t>(display), id);
    } else {
        error = Error::BAD_DISPLAY;
    }
    mMutex.unlock_shared();
    return error;
}

Error AidlComposer::setLayerPictureProfileId(Display display, Layer layer, PictureProfileId id) {
    Error error = Error::NONE;
    mMutex.lock_shared();
    if (auto writer = getWriter(display)) {
        writer->get().setLayerPictureProfileId(translate<int64_t>(display),
                                               translate<int64_t>(layer), id);
    } else {
        error = Error::BAD_DISPLAY;
    }
    mMutex.unlock_shared();
    return error;
}

ftl::Optional<std::reference_wrapper<ComposerClientWriter>> AidlComposer::getWriter(Display display)
        REQUIRES_SHARED(mMutex) {
    return mWriters.get(display);
Loading