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

Commit 4603f3c2 authored by Lloyd Pique's avatar Lloyd Pique
Browse files

[sf] Add support for generic layer metadata to HWComposer and HWC2

HWComposer construction is slightly modified to make it easier to test.
Data is retrieved about the device on the call SurfaceFlinger makes
right after creaton (was registerCallbacks, now called
setConfiguration). This now includes obtaining the supported layer
metadata information from the HAL implementation.

Since getting capabilities is now no longer done by just construction,
the existing tests were adjusted to not expect the call, especially as
none of them were testing any variance in capabilities.

A HWC2::Layer::setLayerGenericMetadata function is also added to set
the metadata.

Tests are explicitly added for both retrieving the supported metadata
and for setting layer generic metadata.

Bug: 139747351
Test: atest libsurfaceflinger_unittest
Change-Id: I3e95be932d94d4e9f200b870acea965744c68d2c
parent 314dc6c2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ public:
    MOCK_METHOD2(setInfo, Error(uint32_t, uint32_t));

    MOCK_METHOD1(setColorTransform, Error(const android::mat4&));
    MOCK_METHOD3(setLayerGenericMetadata,
                 Error(const std::string&, bool, const std::vector<uint8_t>&));
};

} // namespace mock
+3 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ public:
    HWComposer();
    ~HWComposer() override;

    MOCK_METHOD2(registerCallback, void(HWC2::ComposerCallback*, int32_t));
    MOCK_METHOD2(setConfiguration, void(HWC2::ComposerCallback*, int32_t));
    MOCK_CONST_METHOD3(getDisplayIdentificationData,
                       bool(hwc2_display_t, uint8_t*, DisplayIdentificationData*));
    MOCK_CONST_METHOD1(hasCapability, bool(HWC2::Capability));
@@ -96,6 +96,8 @@ public:
    MOCK_METHOD2(setAutoLowLatencyMode, status_t(DisplayId, bool));
    MOCK_METHOD2(getSupportedContentTypes, status_t(DisplayId, std::vector<HWC2::ContentType>*));
    MOCK_METHOD2(setContentType, status_t(DisplayId, HWC2::ContentType));
    MOCK_CONST_METHOD0(getSupportedLayerGenericMetadata,
                       const std::unordered_map<std::string, bool>&());

    MOCK_CONST_METHOD1(dump, void(std::string&));
    MOCK_CONST_METHOD0(getComposer, android::Hwc2::Composer*());
+12 −6
Original line number Diff line number Diff line
@@ -738,8 +738,7 @@ Layer::Layer(android::Hwc2::Composer& composer, const std::unordered_set<Capabil
        mCapabilities(capabilities),
        mDisplayId(displayId),
        mId(layerId),
    mColorMatrix(android::mat4())
{
        mColorMatrix(android::mat4()) {
    ALOGV("Created layer %" PRIu64 " on display %" PRIu64, layerId, displayId);
}

@@ -979,6 +978,13 @@ Error Layer::setColorTransform(const android::mat4& matrix) {
    return error;
}

// Composer HAL 2.4
Error Layer::setLayerGenericMetadata(const std::string& name, bool mandatory,
                                     const std::vector<uint8_t>& value) {
    auto intError = mComposer.setLayerGenericMetadata(mDisplayId, mId, name, mandatory, value);
    return static_cast<Error>(intError);
}

} // namespace impl
} // namespace HWC2

+9 −2
Original line number Diff line number Diff line
@@ -374,6 +374,10 @@ public:

    // Composer HAL 2.3
    [[clang::warn_unused_result]] virtual Error setColorTransform(const android::mat4& matrix) = 0;

    // Composer HAL 2.4
    [[clang::warn_unused_result]] virtual Error setLayerGenericMetadata(
            const std::string& name, bool mandatory, const std::vector<uint8_t>& value) = 0;
};

namespace impl {
@@ -382,8 +386,7 @@ namespace impl {

class Layer : public HWC2::Layer {
public:
    Layer(android::Hwc2::Composer& composer,
          const std::unordered_set<Capability>& capabilities,
    Layer(android::Hwc2::Composer& composer, const std::unordered_set<Capability>& capabilities,
          hwc2_display_t displayId, hwc2_layer_t layerId);
    ~Layer() override;

@@ -412,6 +415,10 @@ public:
    // Composer HAL 2.3
    Error setColorTransform(const android::mat4& matrix) override;

    // Composer HAL 2.4
    Error setLayerGenericMetadata(const std::string& name, bool mandatory,
                                  const std::vector<uint8_t>& value) override;

private:
    // These are references to data owned by HWC2::Device, which will outlive
    // this HWC2::Layer, so these references are guaranteed to be valid for
+24 −4
Original line number Diff line number Diff line
@@ -148,20 +148,20 @@ HWComposer::~HWComposer() = default;
namespace impl {

HWComposer::HWComposer(std::unique_ptr<Hwc2::Composer> composer) : mComposer(std::move(composer)) {
    loadCapabilities();
}

HWComposer::HWComposer(const std::string& composerServiceName)
      : mComposer(std::make_unique<Hwc2::impl::Composer>(composerServiceName)) {
    loadCapabilities();
}

HWComposer::~HWComposer() {
    mDisplayData.clear();
}

void HWComposer::registerCallback(HWC2::ComposerCallback* callback,
                                  int32_t sequenceId) {
void HWComposer::setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) {
    loadCapabilities();
    loadLayerMetadataSupport();

    if (mRegisteredCallback) {
        ALOGW("Callback already registered. Ignored extra registration attempt.");
        return;
@@ -871,6 +871,10 @@ status_t HWComposer::setContentType(DisplayId displayId, HWC2::ContentType conte
    return NO_ERROR;
}

const std::unordered_map<std::string, bool>& HWComposer::getSupportedLayerGenericMetadata() const {
    return mSupportedLayerGenericMetadata;
}

void HWComposer::dump(std::string& result) const {
    result.append(mComposer->dumpDebugInfo());
}
@@ -946,6 +950,22 @@ void HWComposer::loadCapabilities() {
    }
}

void HWComposer::loadLayerMetadataSupport() {
    mSupportedLayerGenericMetadata.clear();

    std::vector<Hwc2::IComposerClient::LayerGenericMetadataKey> supportedMetadataKeyInfo;
    const auto error = mComposer->getLayerGenericMetadataKeys(&supportedMetadataKeyInfo);
    if (error != hardware::graphics::composer::V2_4::Error::NONE) {
        ALOGE("%s: %s failed: %s (%d)", __FUNCTION__, "getLayerGenericMetadataKeys",
              toString(error).c_str(), static_cast<int32_t>(error));
        return;
    }

    for (const auto& [name, mandatory] : supportedMetadataKeyInfo) {
        mSupportedLayerGenericMetadata.emplace(name, mandatory);
    }
}

uint32_t HWComposer::getMaxVirtualDisplayCount() const {
    return mComposer->getMaxVirtualDisplayCount();
}
Loading