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

Commit 7d7ae734 authored by Dan Stoza's avatar Dan Stoza
Browse files

HWC2: Add getHdrCapabilities to C++ shim

Adds support for the getHdrCapabilities call to the HWC2 C++ shim.

Bug: 25684127
Change-Id: Ib4635ee437a06b48945e7f0328492c1e74e27aaa
parent ed40eba4
Loading
Loading
Loading
Loading
+66 −0
Original line number Diff line number Diff line
/*
 * Copyright 2016 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.
 */

#ifndef ANDROID_UI_HDR_CAPABILTIES_H
#define ANDROID_UI_HDR_CAPABILTIES_H

#include <binder/Parcelable.h>

namespace android {

class HdrCapabilities : public Parcelable
{
public:
    HdrCapabilities(const std::vector<int32_t /*android_hdr_t*/>& types,
            float maxLuminance, float maxAverageLuminance, float minLuminance)
      : mSupportedHdrTypes(types),
        mMaxLuminance(maxLuminance),
        mMaxAverageLuminance(maxAverageLuminance),
        mMinLuminance(minLuminance) {}

    // Make this move-constructable and move-assignable
    HdrCapabilities(HdrCapabilities&& other) = default;
    HdrCapabilities& operator=(HdrCapabilities&& other) = default;

    HdrCapabilities()
      : mSupportedHdrTypes(),
        mMaxLuminance(-1.0f),
        mMaxAverageLuminance(-1.0f),
        mMinLuminance(-1.0f) {}

    virtual ~HdrCapabilities() = default;

    const std::vector<int32_t /*android_hdr_t*/>& getSupportedHdrTypes() const {
        return mSupportedHdrTypes;
    }
    float getDesiredMaxLuminance() const { return mMaxLuminance; }
    float getDesiredMaxAverageLuminance() const { return mMaxAverageLuminance; }
    float getDesiredMinLuminance() const { return mMinLuminance; }

    // Parcelable interface
    virtual status_t writeToParcel(Parcel* parcel) const override;
    virtual status_t readFromParcel(const Parcel* parcel) override;

private:
    std::vector<int32_t /*android_hdr_t*/> mSupportedHdrTypes;
    float mMaxLuminance;
    float mMaxAverageLuminance;
    float mMinLuminance;
};

} // namespace android

#endif
+2 −0
Original line number Diff line number Diff line
@@ -40,12 +40,14 @@ LOCAL_SRC_FILES := \
	GraphicBuffer.cpp \
	GraphicBufferAllocator.cpp \
	GraphicBufferMapper.cpp \
	HdrCapabilities.cpp \
	PixelFormat.cpp \
	Rect.cpp \
	Region.cpp \
	UiConfig.cpp

LOCAL_SHARED_LIBRARIES := \
	libbinder \
	libcutils \
	libhardware \
	libsync \
+59 −0
Original line number Diff line number Diff line
/*
 * Copyright 2016 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/HdrCapabilities.h>

#include <binder/Parcel.h>

namespace android {

status_t HdrCapabilities::writeToParcel(Parcel* parcel) const
{
    status_t result = parcel->writeInt32Vector(mSupportedHdrTypes);
    if (result != OK) {
        return result;
    }
    result = parcel->writeFloat(mMaxLuminance);
    if (result != OK) {
        return result;
    }
    result = parcel->writeFloat(mMaxAverageLuminance);
    if (result != OK) {
        return result;
    }
    result = parcel->writeFloat(mMinLuminance);
    return result;
}

status_t HdrCapabilities::readFromParcel(const Parcel* parcel)
{
    status_t result = parcel->readInt32Vector(&mSupportedHdrTypes);
    if (result != OK) {
        return result;
    }
    result = parcel->readFloat(&mMaxLuminance);
    if (result != OK) {
        return result;
    }
    result = parcel->readFloat(&mMaxAverageLuminance);
    if (result != OK) {
        return result;
    }
    result = parcel->readFloat(&mMinLuminance);
    return result;
}

} // namespace android
+69 −37
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ extern "C" {
using android::Fence;
using android::FloatRect;
using android::GraphicBuffer;
using android::HdrCapabilities;
using android::Rect;
using android::Region;
using android::sp;
@@ -100,6 +101,7 @@ Device::Device(hwc2_device_t* device)
    mGetDisplayRequests(nullptr),
    mGetDisplayType(nullptr),
    mGetDozeSupport(nullptr),
    mGetHdrCapabilities(nullptr),
    mGetReleaseFences(nullptr),
    mPresentDisplay(nullptr),
    mSetActiveConfig(nullptr),
@@ -340,6 +342,8 @@ void Device::loadFunctionPointers()
            mGetDisplayType)) return;
    if (!loadFunctionPointer(FunctionDescriptor::GetDozeSupport,
            mGetDozeSupport)) return;
    if (!loadFunctionPointer(FunctionDescriptor::GetHdrCapabilities,
            mGetHdrCapabilities)) return;
    if (!loadFunctionPointer(FunctionDescriptor::GetReleaseFences,
            mGetReleaseFences)) return;
    if (!loadFunctionPointer(FunctionDescriptor::PresentDisplay,
@@ -637,6 +641,34 @@ Error Display::supportsDoze(bool* outSupport) const
    return Error::None;
}

Error Display::getHdrCapabilities(
        std::unique_ptr<HdrCapabilities>* outCapabilities) const
{
    uint32_t numTypes = 0;
    float maxLuminance = -1.0f;
    float maxAverageLuminance = -1.0f;
    float minLuminance = -1.0f;
    int32_t intError = mDevice.mGetHdrCapabilities(mDevice.mHwcDevice, mId,
            &numTypes, nullptr, &maxLuminance, &maxAverageLuminance,
            &minLuminance);
    auto error = static_cast<HWC2::Error>(intError);
    if (error != Error::None) {
        return error;
    }

    std::vector<int32_t> types(numTypes);
    intError = mDevice.mGetHdrCapabilities(mDevice.mHwcDevice, mId, &numTypes,
            types.data(), &maxLuminance, &maxAverageLuminance, &minLuminance);
    error = static_cast<HWC2::Error>(intError);
    if (error != Error::None) {
        return error;
    }

    *outCapabilities = std::make_unique<HdrCapabilities>(std::move(types),
            maxLuminance, maxAverageLuminance, minLuminance);
    return Error::None;
}

Error Display::getReleaseFences(
        std::unordered_map<std::shared_ptr<Layer>, sp<Fence>>* outFences) const
{
+5 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@
#undef HWC2_INCLUDE_STRINGIFICATION
#undef HWC2_USE_CPP11

#include <ui/HdrCapabilities.h>

#include <utils/Log.h>
#include <utils/StrongPointer.h>
#include <utils/Timers.h>
@@ -145,6 +147,7 @@ private:
    HWC2_PFN_GET_DISPLAY_REQUESTS mGetDisplayRequests;
    HWC2_PFN_GET_DISPLAY_TYPE mGetDisplayType;
    HWC2_PFN_GET_DOZE_SUPPORT mGetDozeSupport;
    HWC2_PFN_GET_HDR_CAPABILITIES mGetHdrCapabilities;
    HWC2_PFN_GET_RELEASE_FENCES mGetReleaseFences;
    HWC2_PFN_PRESENT_DISPLAY mPresentDisplay;
    HWC2_PFN_SET_ACTIVE_CONFIG mSetActiveConfig;
@@ -279,6 +282,8 @@ public:
                    outLayerRequests);
    [[clang::warn_unused_result]] Error getType(DisplayType* outType) const;
    [[clang::warn_unused_result]] Error supportsDoze(bool* outSupport) const;
    [[clang::warn_unused_result]] Error getHdrCapabilities(
            std::unique_ptr<android::HdrCapabilities>* outCapabilities) const;
    [[clang::warn_unused_result]] Error getReleaseFences(
            std::unordered_map<std::shared_ptr<Layer>,
                    android::sp<android::Fence>>* outFences) const;