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

Commit d0bd4f11 authored by Yuriy Romanenko's avatar Yuriy Romanenko
Browse files

Common: Added lock() to camera HandleImporter

Effectively a counterpart to lockYCbCr() but for generic single-plane
buffers

Change-Id: I73d051c085fe2b96810a1ed761deac177db2733d
parent 4acd76e6
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -134,6 +134,38 @@ void HandleImporter::closeFence(int fd) const {
    }
}

void* HandleImporter::lock(
        buffer_handle_t& buf, uint64_t cpuUsage, size_t size) {
    Mutex::Autolock lock(mLock);
    void *ret = 0;
    IMapper::Rect accessRegion { 0, 0, static_cast<int>(size), 1 };

    if (!mInitialized) {
        initializeLocked();
    }

    if (mMapper == nullptr) {
        ALOGE("%s: mMapper is null!", __FUNCTION__);
        return ret;
    }

    hidl_handle acquireFenceHandle;
    auto buffer = const_cast<native_handle_t*>(buf);
    mMapper->lock(buffer, cpuUsage, accessRegion, acquireFenceHandle,
            [&](const auto& tmpError, const auto& tmpPtr) {
                if (tmpError == MapperError::NONE) {
                    ret = tmpPtr;
                } else {
                    ALOGE("%s: failed to lock error %d!",
                          __FUNCTION__, tmpError);
                }
           });

    ALOGV("%s: ptr %p size: %zu", __FUNCTION__, ret, size);
    return ret;
}


YCbCrLayout HandleImporter::lockYCbCr(
        buffer_handle_t& buf, uint64_t cpuUsage,
        const IMapper::Rect& accessRegion) {
+3 −0
Original line number Diff line number Diff line
@@ -44,6 +44,9 @@ public:
    bool importFence(const native_handle_t* handle, int& fd) const;
    void closeFence(int fd) const;

    // Assume caller has done waiting for acquire fences
    void* lock(buffer_handle_t& buf, uint64_t cpuUsage, size_t size);

    // Assume caller has done waiting for acquire fences
    YCbCrLayout lockYCbCr(buffer_handle_t& buf, uint64_t cpuUsage,
                          const IMapper::Rect& accessRegion);