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

Commit 25a514b1 authored by Dan Stoza's avatar Dan Stoza Committed by android-build-merger
Browse files

Merge \"gralloc1: Add mutexes\" into nyc-mr1-dev

am: 09c53ae0

Change-Id: I73ff20c45bb54f1a33605062603da5a0bc6b83aa
parents 7920c657 09c53ae0
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@


#include <hardware/gralloc1.h>
#include <hardware/gralloc1.h>


#include <mutex>
#include <string>
#include <string>
#include <unordered_map>
#include <unordered_map>
#include <vector>
#include <vector>
@@ -468,8 +469,10 @@ private:
    std::shared_ptr<Buffer> getBuffer(buffer_handle_t bufferHandle);
    std::shared_ptr<Buffer> getBuffer(buffer_handle_t bufferHandle);


    static std::atomic<gralloc1_buffer_descriptor_t> sNextBufferDescriptorId;
    static std::atomic<gralloc1_buffer_descriptor_t> sNextBufferDescriptorId;
    std::mutex mDescriptorMutex;
    std::unordered_map<gralloc1_buffer_descriptor_t,
    std::unordered_map<gralloc1_buffer_descriptor_t,
            std::shared_ptr<Descriptor>> mDescriptors;
            std::shared_ptr<Descriptor>> mDescriptors;
    std::mutex mBufferMutex;
    std::unordered_map<buffer_handle_t, std::shared_ptr<Buffer>> mBuffers;
    std::unordered_map<buffer_handle_t, std::shared_ptr<Buffer>> mBuffers;
};
};


+9 −0
Original line number Original line Diff line number Diff line
@@ -193,6 +193,7 @@ gralloc1_error_t Gralloc1On0Adapter::createDescriptor(
        gralloc1_buffer_descriptor_t* outDescriptor)
        gralloc1_buffer_descriptor_t* outDescriptor)
{
{
    auto descriptorId = sNextBufferDescriptorId++;
    auto descriptorId = sNextBufferDescriptorId++;
    std::lock_guard<std::mutex> lock(mDescriptorMutex);
    mDescriptors.emplace(descriptorId,
    mDescriptors.emplace(descriptorId,
            std::make_shared<Descriptor>(this, descriptorId));
            std::make_shared<Descriptor>(this, descriptorId));


@@ -207,6 +208,7 @@ gralloc1_error_t Gralloc1On0Adapter::destroyDescriptor(
{
{
    ALOGV("Destroying descriptor %" PRIu64, descriptor);
    ALOGV("Destroying descriptor %" PRIu64, descriptor);


    std::lock_guard<std::mutex> lock(mDescriptorMutex);
    if (mDescriptors.count(descriptor) == 0) {
    if (mDescriptors.count(descriptor) == 0) {
        return GRALLOC1_ERROR_BAD_DESCRIPTOR;
        return GRALLOC1_ERROR_BAD_DESCRIPTOR;
    }
    }
@@ -255,6 +257,8 @@ gralloc1_error_t Gralloc1On0Adapter::allocate(
    *outBufferHandle = handle;
    *outBufferHandle = handle;
    auto buffer = std::make_shared<Buffer>(handle, store, *descriptor, stride,
    auto buffer = std::make_shared<Buffer>(handle, store, *descriptor, stride,
            true);
            true);

    std::lock_guard<std::mutex> lock(mBufferMutex);
    mBuffers.emplace(handle, std::move(buffer));
    mBuffers.emplace(handle, std::move(buffer));


    return GRALLOC1_ERROR_NONE;
    return GRALLOC1_ERROR_NONE;
@@ -309,6 +313,8 @@ gralloc1_error_t Gralloc1On0Adapter::release(
            ALOGE("gralloc0 unregister failed: %d", result);
            ALOGE("gralloc0 unregister failed: %d", result);
        }
        }
    }
    }

    std::lock_guard<std::mutex> lock(mBufferMutex);
    mBuffers.erase(handle);
    mBuffers.erase(handle);
    return GRALLOC1_ERROR_NONE;
    return GRALLOC1_ERROR_NONE;
}
}
@@ -320,6 +326,7 @@ gralloc1_error_t Gralloc1On0Adapter::retain(
            graphicBuffer->getNativeBuffer()->handle, graphicBuffer->getId());
            graphicBuffer->getNativeBuffer()->handle, graphicBuffer->getId());


    buffer_handle_t handle = graphicBuffer->getNativeBuffer()->handle;
    buffer_handle_t handle = graphicBuffer->getNativeBuffer()->handle;
    std::lock_guard<std::mutex> lock(mBufferMutex);
    if (mBuffers.count(handle) != 0) {
    if (mBuffers.count(handle) != 0) {
        mBuffers[handle]->retain();
        mBuffers[handle]->retain();
        return GRALLOC1_ERROR_NONE;
        return GRALLOC1_ERROR_NONE;
@@ -446,6 +453,7 @@ gralloc1_error_t Gralloc1On0Adapter::unlock(
std::shared_ptr<Gralloc1On0Adapter::Descriptor>
std::shared_ptr<Gralloc1On0Adapter::Descriptor>
Gralloc1On0Adapter::getDescriptor(gralloc1_buffer_descriptor_t descriptorId)
Gralloc1On0Adapter::getDescriptor(gralloc1_buffer_descriptor_t descriptorId)
{
{
    std::lock_guard<std::mutex> lock(mDescriptorMutex);
    if (mDescriptors.count(descriptorId) == 0) {
    if (mDescriptors.count(descriptorId) == 0) {
        return nullptr;
        return nullptr;
    }
    }
@@ -456,6 +464,7 @@ Gralloc1On0Adapter::getDescriptor(gralloc1_buffer_descriptor_t descriptorId)
std::shared_ptr<Gralloc1On0Adapter::Buffer> Gralloc1On0Adapter::getBuffer(
std::shared_ptr<Gralloc1On0Adapter::Buffer> Gralloc1On0Adapter::getBuffer(
        buffer_handle_t bufferHandle)
        buffer_handle_t bufferHandle)
{
{
    std::lock_guard<std::mutex> lock(mBufferMutex);
    if (mBuffers.count(bufferHandle) == 0) {
    if (mBuffers.count(bufferHandle) == 0) {
        return nullptr;
        return nullptr;
    }
    }