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

Commit c859147d authored by Fabien Sanglard's avatar Fabien Sanglard
Browse files

Add MiniFence to drop HWC2on1Adapter libui dep

This class will soon become a library used by devices with no support
for HWC2. They will link against libhwc2on1adapter. Drivers should have
no depedencies on libui.

Test:Manual
Change-Id: Iabd2aa89fc3b737a999632a16c4f6c30464787c4
parent d07fc91a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ LOCAL_SRC_FILES := \
    DisplayHardware/FramebufferSurface.cpp \
    DisplayHardware/HWC2.cpp \
    DisplayHardware/HWC2On1Adapter.cpp \
    DisplayHardware/MiniFence.cpp \
    DisplayHardware/PowerHAL.cpp \
    DisplayHardware/VirtualDisplaySurface.cpp \
    Effects/Daltonizer.cpp \
+2 −2
Original line number Diff line number Diff line
@@ -724,7 +724,7 @@ Error HWC2On1Adapter::Display::getReleaseFences(uint32_t* outNumElements,
        }

        auto releaseFence = layer->getReleaseFence();
        if (releaseFence != Fence::NO_FENCE) {
        if (releaseFence != MiniFence::NO_FENCE) {
            if (outputsNonNull) {
                outLayers[numWritten] = layer->getId();
                outFences[numWritten] = releaseFence->dup();
@@ -2003,7 +2003,7 @@ void HWC2On1Adapter::Layer::addReleaseFence(int fenceFd) {
    mReleaseFence.add(fenceFd);
}

const sp<Fence>& HWC2On1Adapter::Layer::getReleaseFence() const {
const sp<MiniFence>& HWC2On1Adapter::Layer::getReleaseFence() const {
    return mReleaseFence.get();
}

+9 −9
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
#undef HWC2_INCLUDE_STRINGIFICATION
#undef HWC2_USE_CPP11

#include <ui/Fence.h>
#include "MiniFence.h"

#include <atomic>
#include <map>
@@ -155,35 +155,35 @@ private:
    class DeferredFence {
        public:
            DeferredFence()
              : mFences({Fence::NO_FENCE, Fence::NO_FENCE}) {}
              : mFences({MiniFence::NO_FENCE, MiniFence::NO_FENCE}) {}

            void add(int32_t fenceFd) {
                mFences.emplace(new Fence(fenceFd));
                mFences.emplace(new MiniFence(fenceFd));
                mFences.pop();
            }

            const sp<Fence>& get() const {
            const sp<MiniFence>& get() const {
                return mFences.front();
            }

        private:
            // There are always two fences in this queue.
            std::queue<sp<Fence>> mFences;
            std::queue<sp<MiniFence>> mFences;
    };

    class FencedBuffer {
        public:
            FencedBuffer() : mBuffer(nullptr), mFence(Fence::NO_FENCE) {}
            FencedBuffer() : mBuffer(nullptr), mFence(MiniFence::NO_FENCE) {}

            void setBuffer(buffer_handle_t buffer) { mBuffer = buffer; }
            void setFence(int fenceFd) { mFence = new Fence(fenceFd); }
            void setFence(int fenceFd) { mFence = new MiniFence(fenceFd); }

            buffer_handle_t getBuffer() const { return mBuffer; }
            int getFence() const { return mFence->dup(); }

        private:
            buffer_handle_t mBuffer;
            sp<Fence> mFence;
            sp<MiniFence> mFence;
    };

    class Display {
@@ -552,7 +552,7 @@ private:
            uint32_t getZ() const { return mZ; }

            void addReleaseFence(int fenceFd);
            const sp<Fence>& getReleaseFence() const;
            const sp<MiniFence>& getReleaseFence() const;

            void setHwc1Id(size_t id) { mHwc1Id = id; }
            size_t getHwc1Id() const { return mHwc1Id; }
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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 "MiniFence.h"

#include <unistd.h>

namespace android {

const sp<MiniFence> MiniFence::NO_FENCE = sp<MiniFence>(new MiniFence);

MiniFence::MiniFence() :
    mFenceFd(-1) {
}

MiniFence::MiniFence(int fenceFd) :
    mFenceFd(fenceFd) {
}

MiniFence::~MiniFence() {
    if (mFenceFd != -1) {
        close(mFenceFd);
    }
}

int MiniFence::dup() const {
    return ::dup(mFenceFd);
}
}
+59 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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 MINIFENCE_H
#define MINIFENCE_H

#include <utils/RefBase.h>

namespace android {

/* MiniFence is a minimal re-implementation of Fence from libui. It exists to
 * avoid linking the HWC2on1Adapter to libui and satisfy Treble requirements.
 */
class MiniFence : public LightRefBase<MiniFence> {
public:
    static const sp<MiniFence> NO_FENCE;

    // Construct a new MiniFence object with an invalid file descriptor.
    MiniFence();

    // Construct a new MiniFence object to manage a given fence file descriptor.
    // When the new MiniFence object is destructed the file descriptor will be
    // closed.
    explicit MiniFence(int fenceFd);

    // Not copyable or movable.
    MiniFence(const MiniFence& rhs) = delete;
    MiniFence& operator=(const MiniFence& rhs) = delete;
    MiniFence(MiniFence&& rhs) = delete;
    MiniFence& operator=(MiniFence&& rhs) = delete;

    // Return a duplicate of the fence file descriptor. The caller is
    // responsible for closing the returned file descriptor. On error, -1 will
    // be returned and errno will indicate the problem.
    int dup() const;

private:
    // Only allow instantiation using ref counting.
    friend class LightRefBase<MiniFence>;
    ~MiniFence();

    int mFenceFd;

};
}
#endif //MINIFENCE_H