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

Commit cb8405e7 authored by Chia-I Wu's avatar Chia-I Wu
Browse files

libui: remove gralloc0/gralloc1 support

We now talk to HIDL gralloc exclusively.

Bug: 37433368
Test: boots
Change-Id: Iecd2f9a02c7066b2f33f24c1de57e9c4af8e28f5
parent c4ced4f0
Loading
Loading
Loading
Loading

include/ui/Gralloc1.h

deleted100644 → 0
+0 −295
Original line number Original line Diff line number Diff line
/*
 * Copyright 2016 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 ANDROID_UI_GRALLOC1_H
#define ANDROID_UI_GRALLOC1_H

#define GRALLOC1_LOG_TAG "Gralloc1"

#include <functional>
#include <memory>
#include <unordered_set>

#include <log/log.h>

#include <ui/Fence.h>

#include <hardware/gralloc1.h>


namespace std {
    template <>
    struct hash<gralloc1_capability_t> {
        size_t operator()(gralloc1_capability_t capability) const {
            return std::hash<int32_t>()(static_cast<int32_t>(capability));
        }
    };
}

namespace android {
class GraphicBuffer;
class Fence;
class GraphicBuffer;
class Gralloc1On0Adapter;
} // namespace android


// This is not an "official" capability (i.e., it is not found in gralloc1.h),
// but we will use it to detect that we are running through the adapter, which
// is capable of collaborating with GraphicBuffer such that queries on a
// buffer_handle_t succeed
static const auto GRALLOC1_CAPABILITY_ON_ADAPTER =
        static_cast<gralloc1_capability_t>(GRALLOC1_LAST_CAPABILITY + 1);

static const auto GRALLOC1_FUNCTION_RETAIN_GRAPHIC_BUFFER =
        static_cast<gralloc1_function_descriptor_t>(GRALLOC1_LAST_FUNCTION + 1);
static const auto GRALLOC1_FUNCTION_ALLOCATE_WITH_ID =
        static_cast<gralloc1_function_descriptor_t>(GRALLOC1_LAST_FUNCTION + 2);
static const auto GRALLOC1_FUNCTION_LOCK_YCBCR =
        static_cast<gralloc1_function_descriptor_t>(GRALLOC1_LAST_FUNCTION + 3);
static const auto GRALLOC1_LAST_ADAPTER_FUNCTION = GRALLOC1_FUNCTION_LOCK_YCBCR;

typedef gralloc1_error_t (*GRALLOC1_PFN_RETAIN_GRAPHIC_BUFFER)(
        gralloc1_device_t* device, const android::GraphicBuffer* buffer);
typedef gralloc1_error_t (*GRALLOC1_PFN_ALLOCATE_WITH_ID)(
        gralloc1_device_t* device, gralloc1_buffer_descriptor_t descriptor,
        gralloc1_backing_store_t id, buffer_handle_t* outBuffer);
typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_LOCK_YCBCR)(
        gralloc1_device_t* device, buffer_handle_t buffer,
        uint64_t /*gralloc1_producer_usage_t*/ producerUsage,
        uint64_t /*gralloc1_consumer_usage_t*/ consumerUsage,
        const gralloc1_rect_t* accessRegion, struct android_ycbcr* outYCbCr,
        int32_t acquireFence);


namespace android {
namespace Gralloc1 {

class Device;

class Descriptor {
public:
    Descriptor(Device& device, gralloc1_buffer_descriptor_t deviceId)
      : mShimDevice(device),
        mDeviceId(deviceId),
        mWidth(0),
        mHeight(0),
        mFormat(static_cast<android_pixel_format_t>(0)),
        mLayerCount(0),
        mProducerUsage(GRALLOC1_PRODUCER_USAGE_NONE),
        mConsumerUsage(GRALLOC1_CONSUMER_USAGE_NONE) {}

    ~Descriptor();

    gralloc1_buffer_descriptor_t getDeviceId() const { return mDeviceId; }

    gralloc1_error_t setDimensions(uint32_t width, uint32_t height);
    gralloc1_error_t setFormat(android_pixel_format_t format);
    gralloc1_error_t setLayerCount(uint32_t layerCount);
    gralloc1_error_t setProducerUsage(gralloc1_producer_usage_t usage);
    gralloc1_error_t setConsumerUsage(gralloc1_consumer_usage_t usage);

private:
    Device& mShimDevice;
    const gralloc1_buffer_descriptor_t mDeviceId;

    uint32_t mWidth;
    uint32_t mHeight;
    android_pixel_format_t mFormat;
    uint32_t mLayerCount;
    gralloc1_producer_usage_t mProducerUsage;
    gralloc1_consumer_usage_t mConsumerUsage;

}; // Descriptor

class Device {
    friend class Gralloc1::Descriptor;

public:
    Device(gralloc1_device_t* device);

    bool hasCapability(gralloc1_capability_t capability) const;

    std::string dump();

    std::shared_ptr<Descriptor> createDescriptor();

    gralloc1_error_t allocate(
            const std::vector<std::shared_ptr<const Descriptor>>& descriptors,
            std::vector<buffer_handle_t>* outBuffers);
    gralloc1_error_t allocate(
            const std::shared_ptr<const Descriptor>& descriptor,
            gralloc1_backing_store_t id, buffer_handle_t* outBuffer);

    gralloc1_error_t retain(buffer_handle_t buffer);
    gralloc1_error_t retain(const GraphicBuffer* buffer);

    gralloc1_error_t release(buffer_handle_t buffer);

    gralloc1_error_t getDimensions(buffer_handle_t buffer,
            uint32_t* outWidth, uint32_t* outHeight);
    gralloc1_error_t getFormat(buffer_handle_t buffer,
            int32_t* outFormat);
    gralloc1_error_t getLayerCount(buffer_handle_t buffer,
            uint32_t* outLayerCount);
    gralloc1_error_t getProducerUsage(buffer_handle_t buffer,
            uint64_t* outProducerUsage);
    gralloc1_error_t getConsumerUsage(buffer_handle_t buffer,
            uint64_t* outConsumerUsage);
    gralloc1_error_t getBackingStore(buffer_handle_t buffer,
            uint64_t* outBackingStore);
    gralloc1_error_t getStride(buffer_handle_t buffer, uint32_t* outStride);
    gralloc1_error_t getNumFlexPlanes(buffer_handle_t buffer,
            uint32_t* outNumPlanes);

    gralloc1_error_t lock(buffer_handle_t buffer,
            gralloc1_producer_usage_t producerUsage,
            gralloc1_consumer_usage_t consumerUsage,
            const gralloc1_rect_t* accessRegion, void** outData,
            const sp<Fence>& acquireFence);
    gralloc1_error_t lockFlex(buffer_handle_t buffer,
            gralloc1_producer_usage_t producerUsage,
            gralloc1_consumer_usage_t consumerUsage,
            const gralloc1_rect_t* accessRegion,
            struct android_flex_layout* outData, const sp<Fence>& acquireFence);
    gralloc1_error_t lockYCbCr(buffer_handle_t buffer,
            gralloc1_producer_usage_t producerUsage,
            gralloc1_consumer_usage_t consumerUsage,
            const gralloc1_rect_t* accessRegion, struct android_ycbcr* outData,
            const sp<Fence>& acquireFence);

    gralloc1_error_t unlock(buffer_handle_t buffer, sp<Fence>* outFence);

private:
    std::unordered_set<gralloc1_capability_t> loadCapabilities();

    bool loadFunctions();

    template <typename LockType, typename OutType>
    gralloc1_error_t lockHelper(LockType pfn, buffer_handle_t buffer,
            gralloc1_producer_usage_t producerUsage,
            gralloc1_consumer_usage_t consumerUsage,
            const gralloc1_rect_t* accessRegion, OutType* outData,
            const sp<Fence>& acquireFence) {
        int32_t intError = pfn(mDevice, buffer,
                static_cast<uint64_t>(producerUsage),
                static_cast<uint64_t>(consumerUsage), accessRegion, outData,
                acquireFence->dup());
        return static_cast<gralloc1_error_t>(intError);
    }

    gralloc1_device_t* const mDevice;

    const std::unordered_set<gralloc1_capability_t> mCapabilities;

    template <typename PFN, gralloc1_function_descriptor_t descriptor>
    struct FunctionLoader {
        FunctionLoader() : pfn(nullptr) {}

        bool load(gralloc1_device_t* device, bool errorIfNull) {
            gralloc1_function_pointer_t rawPointer =
                    device->getFunction(device, descriptor);
            pfn = reinterpret_cast<PFN>(rawPointer);
            if (errorIfNull && !rawPointer) {
                ALOG(LOG_ERROR, GRALLOC1_LOG_TAG,
                        "Failed to load function pointer %d", descriptor);
            }
            return rawPointer != nullptr;
        }

        template <typename ...Args>
        typename std::result_of<PFN(Args...)>::type operator()(Args... args) {
            return pfn(args...);
        }

        PFN pfn;
    };

    // Function pointers
    struct Functions {
        FunctionLoader<GRALLOC1_PFN_DUMP, GRALLOC1_FUNCTION_DUMP> dump;
        FunctionLoader<GRALLOC1_PFN_CREATE_DESCRIPTOR,
                GRALLOC1_FUNCTION_CREATE_DESCRIPTOR> createDescriptor;
        FunctionLoader<GRALLOC1_PFN_DESTROY_DESCRIPTOR,
                GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR> destroyDescriptor;
        FunctionLoader<GRALLOC1_PFN_SET_CONSUMER_USAGE,
                GRALLOC1_FUNCTION_SET_CONSUMER_USAGE> setConsumerUsage;
        FunctionLoader<GRALLOC1_PFN_SET_DIMENSIONS,
                GRALLOC1_FUNCTION_SET_DIMENSIONS> setDimensions;
        FunctionLoader<GRALLOC1_PFN_SET_FORMAT,
                GRALLOC1_FUNCTION_SET_FORMAT> setFormat;
        FunctionLoader<GRALLOC1_PFN_SET_LAYER_COUNT,
                GRALLOC1_FUNCTION_SET_LAYER_COUNT> setLayerCount;
        FunctionLoader<GRALLOC1_PFN_SET_PRODUCER_USAGE,
                GRALLOC1_FUNCTION_SET_PRODUCER_USAGE> setProducerUsage;
        FunctionLoader<GRALLOC1_PFN_GET_BACKING_STORE,
                GRALLOC1_FUNCTION_GET_BACKING_STORE> getBackingStore;
        FunctionLoader<GRALLOC1_PFN_GET_CONSUMER_USAGE,
                GRALLOC1_FUNCTION_GET_CONSUMER_USAGE> getConsumerUsage;
        FunctionLoader<GRALLOC1_PFN_GET_DIMENSIONS,
                GRALLOC1_FUNCTION_GET_DIMENSIONS> getDimensions;
        FunctionLoader<GRALLOC1_PFN_GET_FORMAT,
                GRALLOC1_FUNCTION_GET_FORMAT> getFormat;
        FunctionLoader<GRALLOC1_PFN_GET_LAYER_COUNT,
                GRALLOC1_FUNCTION_GET_LAYER_COUNT> getLayerCount;
        FunctionLoader<GRALLOC1_PFN_GET_PRODUCER_USAGE,
                GRALLOC1_FUNCTION_GET_PRODUCER_USAGE> getProducerUsage;
        FunctionLoader<GRALLOC1_PFN_GET_STRIDE,
                GRALLOC1_FUNCTION_GET_STRIDE> getStride;
        FunctionLoader<GRALLOC1_PFN_ALLOCATE,
                GRALLOC1_FUNCTION_ALLOCATE> allocate;
        FunctionLoader<GRALLOC1_PFN_RETAIN,
                GRALLOC1_FUNCTION_RETAIN> retain;
        FunctionLoader<GRALLOC1_PFN_RELEASE,
                GRALLOC1_FUNCTION_RELEASE> release;
        FunctionLoader<GRALLOC1_PFN_GET_NUM_FLEX_PLANES,
                GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES> getNumFlexPlanes;
        FunctionLoader<GRALLOC1_PFN_LOCK,
                GRALLOC1_FUNCTION_LOCK> lock;
        FunctionLoader<GRALLOC1_PFN_LOCK_FLEX,
                GRALLOC1_FUNCTION_LOCK_FLEX> lockFlex;
        FunctionLoader<GRALLOC1_PFN_LOCK_YCBCR,
                GRALLOC1_FUNCTION_LOCK_YCBCR> lockYCbCr;
        FunctionLoader<GRALLOC1_PFN_UNLOCK,
                GRALLOC1_FUNCTION_UNLOCK> unlock;

        // Adapter-only functions
        FunctionLoader<GRALLOC1_PFN_RETAIN_GRAPHIC_BUFFER,
                GRALLOC1_FUNCTION_RETAIN_GRAPHIC_BUFFER> retainGraphicBuffer;
        FunctionLoader<GRALLOC1_PFN_ALLOCATE_WITH_ID,
                GRALLOC1_FUNCTION_ALLOCATE_WITH_ID> allocateWithId;
    } mFunctions;

}; // class android::Gralloc1::Device

class Loader
{
public:
    Loader();
    ~Loader();

    std::unique_ptr<Device> getDevice();

private:
    static std::unique_ptr<Gralloc1On0Adapter> mAdapter;
    std::unique_ptr<Device> mDevice;
};

} // namespace android::Gralloc1

} // namespace android

#endif

include/ui/Gralloc1On0Adapter.h

deleted100644 → 0
+0 −478

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −6
Original line number Original line Diff line number Diff line
@@ -41,9 +41,6 @@ class Mapper {
public:
public:
    Mapper();
    Mapper();


    // this will be removed and Mapper will be always valid
    bool valid() const { return (mMapper != nullptr); }

    Error createDescriptor(
    Error createDescriptor(
            const IMapper::BufferDescriptorInfo& descriptorInfo,
            const IMapper::BufferDescriptorInfo& descriptorInfo,
            BufferDescriptor* outDescriptor) const;
            BufferDescriptor* outDescriptor) const;
@@ -84,9 +81,6 @@ public:
    // time.
    // time.
    Allocator(const Mapper& mapper);
    Allocator(const Mapper& mapper);


    // this will be removed and Allocator will be always valid
    bool valid() const { return (mAllocator != nullptr); }

    std::string dumpDebugInfo() const;
    std::string dumpDebugInfo() const;


    /*
    /*
+4 −25
Original line number Original line Diff line number Diff line
@@ -25,14 +25,15 @@


#include <cutils/native_handle.h>
#include <cutils/native_handle.h>


#include <system/window.h>

#include <ui/PixelFormat.h>

#include <utils/Errors.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
#include <utils/KeyedVector.h>
#include <utils/Mutex.h>
#include <utils/Mutex.h>
#include <utils/Singleton.h>
#include <utils/Singleton.h>


#include <ui/Gralloc1.h>
#include <ui/PixelFormat.h>

namespace android {
namespace android {


namespace Gralloc2 {
namespace Gralloc2 {
@@ -45,25 +46,6 @@ class String8;
class GraphicBufferAllocator : public Singleton<GraphicBufferAllocator>
class GraphicBufferAllocator : public Singleton<GraphicBufferAllocator>
{
{
public:
public:
    enum {
        USAGE_SW_READ_NEVER     = GRALLOC1_CONSUMER_USAGE_CPU_READ_NEVER,
        USAGE_SW_READ_RARELY    = GRALLOC1_CONSUMER_USAGE_CPU_READ,
        USAGE_SW_READ_OFTEN     = GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN,
        USAGE_SW_READ_MASK      = GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN,

        USAGE_SW_WRITE_NEVER    = GRALLOC1_PRODUCER_USAGE_CPU_WRITE_NEVER,
        USAGE_SW_WRITE_RARELY   = GRALLOC1_PRODUCER_USAGE_CPU_WRITE,
        USAGE_SW_WRITE_OFTEN    = GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN,
        USAGE_SW_WRITE_MASK     = GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN,

        USAGE_SOFTWARE_MASK     = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK,

        USAGE_HW_TEXTURE        = GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE,
        USAGE_HW_RENDER         = GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET,
        USAGE_HW_2D             = 0x00000400, // Deprecated
        USAGE_HW_MASK           = 0x00071F00, // Deprecated
    };

    static inline GraphicBufferAllocator& get() { return getInstance(); }
    static inline GraphicBufferAllocator& get() { return getInstance(); }


    status_t allocate(uint32_t w, uint32_t h, PixelFormat format,
    status_t allocate(uint32_t w, uint32_t h, PixelFormat format,
@@ -98,9 +80,6 @@ private:


    GraphicBufferMapper& mMapper;
    GraphicBufferMapper& mMapper;
    const std::unique_ptr<const Gralloc2::Allocator> mAllocator;
    const std::unique_ptr<const Gralloc2::Allocator> mAllocator;

    std::unique_ptr<Gralloc1::Loader> mLoader;
    std::unique_ptr<Gralloc1::Device> mDevice;
};
};


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
+0 −8
Original line number Original line Diff line number Diff line
@@ -22,8 +22,6 @@


#include <memory>
#include <memory>


#include <ui/Gralloc1.h>

#include <utils/Singleton.h>
#include <utils/Singleton.h>




@@ -52,9 +50,6 @@ public:
    status_t importBuffer(buffer_handle_t rawHandle,
    status_t importBuffer(buffer_handle_t rawHandle,
            buffer_handle_t* outHandle);
            buffer_handle_t* outHandle);


    // This is temporary and will be removed soon
    status_t importBuffer(const GraphicBuffer* buffer);

    status_t freeBuffer(buffer_handle_t handle);
    status_t freeBuffer(buffer_handle_t handle);


    status_t lock(buffer_handle_t handle,
    status_t lock(buffer_handle_t handle,
@@ -89,9 +84,6 @@ private:
    GraphicBufferMapper();
    GraphicBufferMapper();


    const std::unique_ptr<const Gralloc2::Mapper> mMapper;
    const std::unique_ptr<const Gralloc2::Mapper> mMapper;

    std::unique_ptr<Gralloc1::Loader> mLoader;
    std::unique_ptr<Gralloc1::Device> mDevice;
};
};


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
Loading