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

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

[Graphics] Only validate display in PresentOrValidateDisplay.

Previously we require display to be validated in onRefresh, however, onRefresh
can be called while validateDisplay is executing, results in next
presentDisplay being skipped. This patch makes sure we don't check validation
state when presentDisplay is called.

BUG: 80063800
Test: build, flash, boot and play Youtube videos.
Change-Id: I3d8686db3274436afb6605812641768296f1af0e
parent c93640c1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ class ComposerClientImpl : public Interface {
        }

        void onRefresh(Display display) {
            mResources->setDisplayMustValidateState(display, true);
            auto ret = mCallback->onRefresh(display);
            ALOGE_IF(!ret.isOk(), "failed to send onRefresh: %s", ret.description().c_str());
        }
+5 −1
Original line number Diff line number Diff line
@@ -258,6 +258,7 @@ class ComposerCommandEngine : protected CommandReaderBase {

        auto err = mHal->validateDisplay(mCurrentDisplay, &changedLayers, &compositionTypes,
                                         &displayRequestMask, &requestedLayers, &requestMasks);
        mResources->setDisplayMustValidateState(mCurrentDisplay, false);
        if (err == Error::NONE) {
            mWriter.setChangedCompositionTypes(changedLayers, compositionTypes);
            mWriter.setDisplayRequests(displayRequestMask, requestedLayers, requestMasks);
@@ -278,7 +279,9 @@ class ComposerCommandEngine : protected CommandReaderBase {
            int presentFence = -1;
            std::vector<Layer> layers;
            std::vector<int> fences;
            auto err = mHal->presentDisplay(mCurrentDisplay, &presentFence, &layers, &fences);
            auto err = mResources->mustValidateDisplay(mCurrentDisplay)
                           ? Error::NOT_VALIDATED
                           : mHal->presentDisplay(mCurrentDisplay, &presentFence, &layers, &fences);
            if (err == Error::NONE) {
                mWriter.setPresentOrValidateResult(1);
                mWriter.setPresentFence(presentFence);
@@ -296,6 +299,7 @@ class ComposerCommandEngine : protected CommandReaderBase {

        auto err = mHal->validateDisplay(mCurrentDisplay, &changedLayers, &compositionTypes,
                                         &displayRequestMask, &requestedLayers, &requestMasks);
        mResources->setDisplayMustValidateState(mCurrentDisplay, false);
        if (err == Error::NONE) {
            mWriter.setPresentOrValidateResult(0);
            mWriter.setChangedCompositionTypes(changedLayers, compositionTypes);
+24 −1
Original line number Diff line number Diff line
@@ -216,7 +216,8 @@ class ComposerDisplayResource {
        : mType(type),
          mClientTargetCache(importer),
          mOutputBufferCache(importer, ComposerHandleCache::HandleType::BUFFER,
                             outputBufferCacheSize) {}
                             outputBufferCacheSize),
          mMustValidate(true) {}

    bool initClientTargetCache(uint32_t cacheSize) {
        return mClientTargetCache.initCache(ComposerHandleCache::HandleType::BUFFER, cacheSize);
@@ -263,10 +264,15 @@ class ComposerDisplayResource {
        return layers;
    }

    void setMustValidateState(bool mustValidate) { mMustValidate = mustValidate; }

    bool mustValidate() const { return mMustValidate; }

   protected:
    const DisplayType mType;
    ComposerHandleCache mClientTargetCache;
    ComposerHandleCache mOutputBufferCache;
    bool mMustValidate;

    std::unordered_map<Layer, std::unique_ptr<ComposerLayerResource>> mLayerResources;
};
@@ -389,6 +395,23 @@ class ComposerResources {
                                                       outStreamHandle, outReplacedStream);
    }

    void setDisplayMustValidateState(Display display, bool mustValidate) {
        std::lock_guard<std::mutex> lock(mDisplayResourcesMutex);
        auto* displayResource = findDisplayResourceLocked(display);
        if (displayResource) {
            displayResource->setMustValidateState(mustValidate);
        }
    }

    bool mustValidateDisplay(Display display) {
        std::lock_guard<std::mutex> lock(mDisplayResourcesMutex);
        auto* displayResource = findDisplayResourceLocked(display);
        if (displayResource) {
            return displayResource->mustValidate();
        }
        return false;
    }

   protected:
    virtual std::unique_ptr<ComposerDisplayResource> createDisplayResource(
        ComposerDisplayResource::DisplayType type, uint32_t outputBufferCacheSize) {
+0 −9
Original line number Diff line number Diff line
@@ -111,7 +111,6 @@ class HwcHalImpl : public Hal {
    }

    void registerEventCallback(hal::ComposerHal::EventCallback* callback) override {
        mMustValidateDisplay = true;
        mEventCallback = callback;

        mDispatch.registerCallback(mDevice, HWC2_CALLBACK_HOTPLUG, this,
@@ -331,7 +330,6 @@ class HwcHalImpl : public Hal {
        uint32_t typesCount = 0;
        uint32_t reqsCount = 0;
        int32_t err = mDispatch.validateDisplay(mDevice, display, &typesCount, &reqsCount);
        mMustValidateDisplay = false;

        if (err != HWC2_ERROR_NONE && err != HWC2_ERROR_HAS_CHANGES) {
            return static_cast<Error>(err);
@@ -384,10 +382,6 @@ class HwcHalImpl : public Hal {

    Error presentDisplay(Display display, int32_t* outPresentFence, std::vector<Layer>* outLayers,
                         std::vector<int32_t>* outReleaseFences) override {
        if (mMustValidateDisplay) {
            return Error::NOT_VALIDATED;
        }

        *outPresentFence = -1;
        int32_t err = mDispatch.presentDisplay(mDevice, display, outPresentFence);
        if (err != HWC2_ERROR_NONE) {
@@ -593,7 +587,6 @@ class HwcHalImpl : public Hal {

    static void refreshHook(hwc2_callback_data_t callbackData, hwc2_display_t display) {
        auto hal = static_cast<HwcHalImpl*>(callbackData);
        hal->mMustValidateDisplay = true;
        hal->mEventCallback->onRefresh(display);
    }

@@ -654,8 +647,6 @@ class HwcHalImpl : public Hal {
    } mDispatch = {};

    hal::ComposerHal::EventCallback* mEventCallback = nullptr;

    std::atomic<bool> mMustValidateDisplay{true};
};

}  // namespace detail