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

Commit 7f96780b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "libui: use unique_fd in Fence"

parents 93d120d6 df1baddb
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ cc_library_shared {
    ],

    header_libs: [
        "libbase_headers",
        "libnativebase_headers",
        "libhardware_headers",
    ],
@@ -107,6 +108,7 @@ cc_library_shared {
    ],

    export_header_lib_headers: [
        "libbase_headers",
        "libnativebase_headers",
        "libhardware_headers",
    ],
+6 −12
Original line number Diff line number Diff line
@@ -37,18 +37,12 @@ namespace android {

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

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

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

Fence::~Fence() {
    if (mFenceFd != -1) {
        close(mFenceFd);
    }
Fence::Fence(base::unique_fd fenceFd) :
    mFenceFd(std::move(fenceFd)) {
}

status_t Fence::wait(int timeout) {
@@ -68,7 +62,7 @@ status_t Fence::waitForever(const char* logname) {
    int warningTimeout = 3000;
    int err = sync_wait(mFenceFd, warningTimeout);
    if (err < 0 && errno == ETIME) {
        ALOGE("%s: fence %d didn't signal in %u ms", logname, mFenceFd,
        ALOGE("%s: fence %d didn't signal in %u ms", logname, mFenceFd.get(),
                warningTimeout);
        err = sync_wait(mFenceFd, TIMEOUT_NEVER);
    }
@@ -94,7 +88,7 @@ sp<Fence> Fence::merge(const char* name, const sp<Fence>& f1,
    if (result == -1) {
        status_t err = -errno;
        ALOGE("merge: sync_merge(\"%s\", %d, %d) returned an error: %s (%d)",
                name, f1->mFenceFd, f2->mFenceFd,
                name, f1->mFenceFd.get(), f2->mFenceFd.get(),
                strerror(-err), err);
        return NO_FENCE;
    }
@@ -117,7 +111,7 @@ nsecs_t Fence::getSignalTime() const {

    struct sync_fence_info_data* finfo = sync_fence_info(mFenceFd);
    if (finfo == NULL) {
        ALOGE("sync_fence_info returned NULL for fd %d", mFenceFd);
        ALOGE("sync_fence_info returned NULL for fd %d", mFenceFd.get());
        return SIGNAL_TIME_INVALID;
    }
    if (finfo->status != 1) {
@@ -181,7 +175,7 @@ status_t Fence::unflatten(void const*& buffer, size_t& size, int const*& fds, si
    }

    if (numFds) {
        mFenceFd = *fds++;
        mFenceFd.reset(*fds++);
        count--;
    }

+5 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

#include <stdint.h>

#include <android-base/unique_fd.h>
#include <utils/Flattenable.h>
#include <utils/RefBase.h>
#include <utils/Timers.h>
@@ -49,12 +50,13 @@ public:
    // Construct a new Fence object with an invalid file descriptor.  This
    // should be done when the Fence object will be set up by unflattening
    // serialized data.
    Fence();
    Fence() = default;

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

    // Not copyable or movable.
    Fence(const Fence& rhs) = delete;
@@ -136,9 +138,9 @@ public:
private:
    // Only allow instantiation using ref counting.
    friend class LightRefBase<Fence>;
    ~Fence();
    ~Fence() = default;

    int mFenceFd;
    base::unique_fd mFenceFd;
};

}; // namespace android
+2 −2
Original line number Diff line number Diff line
@@ -379,12 +379,12 @@ status_t BufferLayerConsumer::syncForReleaseLocked() {

    if (mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) {
        if (SyncFeatures::getInstance().useNativeFenceSync()) {
            int fenceFd = mRE.flush().release();
            base::unique_fd fenceFd = mRE.flush();
            if (fenceFd == -1) {
                BLC_LOGE("syncForReleaseLocked: failed to flush RenderEngine");
                return UNKNOWN_ERROR;
            }
            sp<Fence> fence(new Fence(fenceFd));
            sp<Fence> fence(new Fence(std::move(fenceFd)));
            status_t err = addReleaseFenceLocked(mCurrentTexture,
                                                 mCurrentTextureImage->graphicBuffer(), fence);
            if (err != OK) {