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

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

libui: update for revised HIDL gralloc

The revised HIDL gralloc is implementable on top of gralloc0 and
gralloc1, which enables us to remove all legacy code.

However, it lacks the ability to query buffer properties from a
buffer handle.  GetBufferFromHandle in VR always fails.

Bug: 36481301
Test: builds and boots on Pixel
Change-Id: Id7cfa2d2172dfc008803860f24fcf4f03ba05f11
parent 1a50a60a
Loading
Loading
Loading
Loading

include/ui/Gralloc2.h

0 → 100644
+132 −0
Original line number 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_GRALLOC2_H
#define ANDROID_UI_GRALLOC2_H

#include <string>

#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
#include <android/hardware/graphics/mapper/2.0/IMapper.h>
#include <system/window.h>
#include <utils/StrongPointer.h>

namespace android {

namespace Gralloc2 {

using hardware::graphics::allocator::V2_0::IAllocator;
using hardware::graphics::common::V1_0::BufferUsage;
using hardware::graphics::common::V1_0::PixelFormat;
using hardware::graphics::mapper::V2_0::BufferDescriptor;
using hardware::graphics::mapper::V2_0::Error;
using hardware::graphics::mapper::V2_0::IMapper;
using hardware::graphics::mapper::V2_0::YCbCrLayout;

// A wrapper to IMapper
class Mapper {
public:
    Mapper();

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

    Error createDescriptor(
            const IMapper::BufferDescriptorInfo& descriptorInfo,
            BufferDescriptor* outDescriptor) const;

    // Import a buffer that is from another HAL, another process, or is
    // cloned.
    //
    // The returned handle must be freed with freeBuffer.
    Error importBuffer(const hardware::hidl_handle& rawHandle,
            buffer_handle_t* outBufferHandle) const;

    void freeBuffer(buffer_handle_t bufferHandle) const;

    // The ownership of acquireFence is always transferred to the callee, even
    // on errors.
    Error lock(buffer_handle_t bufferHandle, uint64_t usage,
            const IMapper::Rect& accessRegion,
            int acquireFence, void** outData) const;

    // The ownership of acquireFence is always transferred to the callee, even
    // on errors.
    Error lock(buffer_handle_t bufferHandle, uint64_t usage,
            const IMapper::Rect& accessRegion,
            int acquireFence, YCbCrLayout* outLayout) const;

    // unlock returns a fence sync object (or -1) and the fence sync object is
    // owned by the caller
    int unlock(buffer_handle_t bufferHandle) const;

private:
    sp<IMapper> mMapper;
};

// A wrapper to IAllocator
class Allocator {
public:
    // An allocator relies on a mapper, and that mapper must be alive at all
    // time.
    Allocator(const Mapper& mapper);

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

    std::string dumpDebugInfo() const;

    /*
     * The returned buffers are already imported and must not be imported
     * again.  outBufferHandles must point to a space that can contain at
     * least "count" buffer_handle_t.
     */
    Error allocate(BufferDescriptor descriptor, uint32_t count,
            uint32_t* outStride, buffer_handle_t* outBufferHandles) const;

    Error allocate(BufferDescriptor descriptor,
            uint32_t* outStride, buffer_handle_t* outBufferHandle) const
    {
        return allocate(descriptor, 1, outStride, outBufferHandle);
    }

    Error allocate(const IMapper::BufferDescriptorInfo& descriptorInfo, uint32_t count,
            uint32_t* outStride, buffer_handle_t* outBufferHandles) const
    {
        BufferDescriptor descriptor;
        Error error = mMapper.createDescriptor(descriptorInfo, &descriptor);
        if (error == Error::NONE) {
            error = allocate(descriptor, count, outStride, outBufferHandles);
        }
        return error;
    }

    Error allocate(const IMapper::BufferDescriptorInfo& descriptorInfo,
            uint32_t* outStride, buffer_handle_t* outBufferHandle) const
    {
        return allocate(descriptorInfo, 1, outStride, outBufferHandle);
    }

private:
    const Mapper& mMapper;
    sp<IAllocator> mAllocator;
};

} // namespace Gralloc2

} // namespace android

#endif // ANDROID_UI_GRALLOC2_H

include/ui/GrallocAllocator.h

deleted100644 → 0
+0 −68
Original line number 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_GRALLOC_ALLOCATOR_H
#define ANDROID_UI_GRALLOC_ALLOCATOR_H

#include <string>

#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
#include <utils/StrongPointer.h>

namespace android {

namespace Gralloc2 {

using hardware::graphics::allocator::V2_0::Error;
using hardware::graphics::allocator::V2_0::ProducerUsage;
using hardware::graphics::allocator::V2_0::ConsumerUsage;
using hardware::graphics::allocator::V2_0::BufferDescriptor;
using hardware::graphics::allocator::V2_0::Buffer;
using hardware::graphics::allocator::V2_0::IAllocator;
using hardware::graphics::allocator::V2_0::IAllocatorClient;
using hardware::graphics::common::V1_0::PixelFormat;

// Allocator is a wrapper to IAllocator, a proxy to server-side allocator.
class Allocator {
public:
    Allocator();

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

    std::string dumpDebugInfo() const;

    Error createBufferDescriptor(
            const IAllocatorClient::BufferDescriptorInfo& descriptorInfo,
            BufferDescriptor* outDescriptor) const;
    void destroyBufferDescriptor(BufferDescriptor descriptor) const;

    Error allocate(BufferDescriptor descriptor, Buffer* outBuffer) const;
    void free(Buffer buffer) const;

    Error exportHandle(BufferDescriptor descriptor, Buffer buffer,
            native_handle_t** outBufferHandle) const;

private:
    sp<IAllocator> mAllocator;
    sp<IAllocatorClient> mClient;
};

} // namespace Gralloc2

} // namespace android

#endif // ANDROID_UI_GRALLOC_ALLOCATOR_H

include/ui/GrallocMapper.h

deleted100644 → 0
+0 −74
Original line number 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_GRALLOC_MAPPER_H
#define ANDROID_UI_GRALLOC_MAPPER_H

#include <android/hardware/graphics/mapper/2.0/IMapper.h>
#include <system/window.h>

namespace android {

namespace Gralloc2 {

using hardware::graphics::allocator::V2_0::Error;
using hardware::graphics::allocator::V2_0::ProducerUsage;
using hardware::graphics::allocator::V2_0::ConsumerUsage;
using hardware::graphics::common::V1_0::PixelFormat;
using hardware::graphics::mapper::V2_0::FlexLayout;
using hardware::graphics::mapper::V2_0::BackingStore;
using hardware::graphics::mapper::V2_0::IMapper;

// Mapper is a wrapper to IMapper, a client-side graphics buffer mapper.
class Mapper {
public:
    Mapper();

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

    Error retain(buffer_handle_t handle) const;
    void release(buffer_handle_t handle) const;

    Error getDimensions(buffer_handle_t handle,
            uint32_t* outWidth, uint32_t* outHeight) const;
    Error getFormat(buffer_handle_t handle, int32_t* outFormat) const;
    Error getLayerCount(buffer_handle_t handle, uint32_t* outLayerCount) const;
    Error getProducerUsage(buffer_handle_t handle,
            uint64_t* outProducerUsage) const;
    Error getConsumerUsage(buffer_handle_t handle,
            uint64_t* outConsumerUsage) const;
    Error getBackingStore(buffer_handle_t handle,
            uint64_t* outBackingStore) const;
    Error getStride(buffer_handle_t handle, uint32_t* outStride) const;

    Error lock(buffer_handle_t handle, uint64_t producerUsage,
            uint64_t consumerUsage, const IMapper::Rect& accessRegion,
            int acquireFence, void** outData) const;
    Error lock(buffer_handle_t handle, uint64_t producerUsage,
            uint64_t consumerUsage, const IMapper::Rect& accessRegion,
            int acquireFence, FlexLayout* outLayout) const;
    int unlock(buffer_handle_t handle) const;

private:
    sp<IMapper> mMapper;
};

} // namespace Gralloc2

} // namespace android

#endif // ANDROID_UI_GRALLOC_MAPPER_H
+1 −1
Original line number Diff line number Diff line
@@ -96,8 +96,8 @@ private:
    GraphicBufferAllocator();
    ~GraphicBufferAllocator();

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

    std::unique_ptr<Gralloc1::Loader> mLoader;
    std::unique_ptr<Gralloc1::Device> mDevice;
+7 −23
Original line number Diff line number Diff line
@@ -47,31 +47,15 @@ class GraphicBufferMapper : public Singleton<GraphicBufferMapper>
public:
    static inline GraphicBufferMapper& get() { return getInstance(); }

    // This may NOT work on devices without a valid Gralloc2::Mapper.
    status_t registerBuffer(buffer_handle_t handle);
    // The imported outHandle must be freed with freeBuffer when no longer
    // needed. rawHandle is owned by the caller.
    status_t importBuffer(buffer_handle_t rawHandle,
            buffer_handle_t* outHandle);

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

    status_t unregisterBuffer(buffer_handle_t handle);

    status_t getDimensions(buffer_handle_t handle,
            uint32_t* outWidth, uint32_t* outHeight) const;

    status_t getFormat(buffer_handle_t handle, int32_t* outFormat) const;

    status_t getLayerCount(buffer_handle_t handle,
            uint32_t* outLayerCount) const;

    status_t getProducerUsage(buffer_handle_t handle,
            uint64_t* outProducerUsage) const;

    status_t getConsumerUsage(buffer_handle_t handle,
            uint64_t* outConsumerUsage) const;

    status_t getBackingStore(buffer_handle_t handle,
            uint64_t* outBackingStore) const;

    status_t getStride(buffer_handle_t handle, uint32_t* outStride) const;
    status_t freeBuffer(buffer_handle_t handle);

    status_t lock(buffer_handle_t handle,
            uint32_t usage, const Rect& bounds, void** vaddr);
Loading