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

Commit da540916 authored by Marissa Wall's avatar Marissa Wall
Browse files

gralloc: move VtsHalCameraProviderV2_4TargetTest to GraphicBufferAllocator/Mapper

libui's GraphicBufferAllocator/Mapper already wrap the different
gralloc functions and hide the details from the caller. There is no
reason VtsHalCameraProviderV2_4TargetTest needs to directly talk to
gralloc. This patch updates VtsHalCameraProviderV2_4TargetTest to
use libui.

Bug: 145139476
Test: adb shell /system/bin/VtsHalCameraProviderV2_4TargetTest
--hal_service_instance=android.hardware.camera.provider@2.4::ICameraProvider/internal/0

Change-Id: I2c2a913f6c5aea2ce7260b68293df404f40e0ddd
parent 655675db
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ cc_test {
        "libcamera_metadata",
        "libcutils",
        "libfmq",
        "libgralloctypes",
        "libgui",
        "libui",
    ],
@@ -41,13 +42,7 @@ cc_test {
	"android.hardware.camera.metadata@3.4",
        "android.hardware.camera.provider@2.4",
        "android.hardware.camera.provider@2.5",
        "android.hardware.graphics.allocator@2.0",
        "android.hardware.graphics.allocator@3.0",
        "android.hardware.graphics.allocator@4.0",
        "android.hardware.graphics.common@1.0",
        "android.hardware.graphics.mapper@2.0",
        "android.hardware.graphics.mapper@3.0",
        "android.hardware.graphics.mapper@4.0",
        "android.hidl.allocator@1.0",
        "libgrallocusage",
        "libhidlmemory",
+15 −107
Original line number Diff line number Diff line
@@ -26,21 +26,21 @@

#include <inttypes.h>

#include <CameraMetadata.h>
#include <CameraParameters.h>
#include <android/hardware/camera/device/1.0/ICameraDevice.h>
#include <android/hardware/camera/device/3.2/ICameraDevice.h>
#include <android/hardware/camera/device/3.5/ICameraDevice.h>
#include <android/hardware/camera/device/3.3/ICameraDeviceSession.h>
#include <android/hardware/camera/device/3.4/ICameraDeviceSession.h>
#include <android/hardware/camera/device/3.5/ICameraDeviceSession.h>
#include <android/hardware/camera/device/3.4/ICameraDeviceCallback.h>
#include <android/hardware/camera/device/3.4/ICameraDeviceSession.h>
#include <android/hardware/camera/device/3.5/ICameraDevice.h>
#include <android/hardware/camera/device/3.5/ICameraDeviceCallback.h>
#include <android/hardware/camera/device/3.5/ICameraDeviceSession.h>
#include <android/hardware/camera/metadata/3.4/types.h>
#include <android/hardware/camera/provider/2.4/ICameraProvider.h>
#include <android/hardware/camera/provider/2.5/ICameraProvider.h>
#include <android/hardware/camera/metadata/3.4/types.h>
#include <android/hidl/manager/1.0/IServiceManager.h>
#include <binder/MemoryHeapBase.h>
#include <CameraMetadata.h>
#include <CameraParameters.h>
#include <cutils/properties.h>
#include <fmq/MessageQueue.h>
#include <grallocusage/GrallocUsageConversion.h>
@@ -52,14 +52,9 @@
#include <system/camera.h>
#include <system/camera_metadata.h>
#include <ui/GraphicBuffer.h>
#include <ui/GraphicBufferAllocator.h>
#include <ui/GraphicBufferMapper.h>

#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
#include <android/hardware/graphics/allocator/3.0/IAllocator.h>
#include <android/hardware/graphics/allocator/4.0/IAllocator.h>
#include <android/hardware/graphics/mapper/2.0/IMapper.h>
#include <android/hardware/graphics/mapper/2.0/types.h>
#include <android/hardware/graphics/mapper/3.0/IMapper.h>
#include <android/hardware/graphics/mapper/4.0/IMapper.h>
#include <android/hidl/allocator/1.0/IAllocator.h>
#include <android/hidl/memory/1.0/IMapper.h>
#include <android/hidl/memory/1.0/IMemory.h>
@@ -6311,102 +6306,15 @@ void CameraHidlTest::allocateGraphicBuffer(uint32_t width, uint32_t height, uint
        PixelFormat format, hidl_handle *buffer_handle /*out*/) {
    ASSERT_NE(buffer_handle, nullptr);

    sp<android::hardware::graphics::allocator::V2_0::IAllocator> allocator =
        android::hardware::graphics::allocator::V2_0::IAllocator::getService();
    sp<android::hardware::graphics::allocator::V3_0::IAllocator> allocatorV3 =
        android::hardware::graphics::allocator::V3_0::IAllocator::getService();
    sp<android::hardware::graphics::allocator::V4_0::IAllocator> allocatorV4 =
            android::hardware::graphics::allocator::V4_0::IAllocator::getService();

    sp<android::hardware::graphics::mapper::V4_0::IMapper> mapperV4 =
            android::hardware::graphics::mapper::V4_0::IMapper::getService();
    sp<android::hardware::graphics::mapper::V3_0::IMapper> mapperV3 =
        android::hardware::graphics::mapper::V3_0::IMapper::getService();
    sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper =
        android::hardware::graphics::mapper::V2_0::IMapper::getService();
    if (mapperV4 != nullptr && allocatorV4 != nullptr) {
        ::android::hardware::hidl_vec<uint8_t> descriptor;
        android::hardware::graphics::mapper::V4_0::IMapper::BufferDescriptorInfo descriptorInfo{};
        descriptorInfo.name = "VtsHalCameraProviderV2_4";
        descriptorInfo.width = width;
        descriptorInfo.height = height;
        descriptorInfo.layerCount = 1;
        descriptorInfo.format =
                static_cast<android::hardware::graphics::common::V1_2::PixelFormat>(format);
        descriptorInfo.usage = usage;

        auto ret = mapperV4->createDescriptor(
                descriptorInfo, [&descriptor](android::hardware::graphics::mapper::V4_0::Error err,
                                              ::android::hardware::hidl_vec<uint8_t> desc) {
                    ASSERT_EQ(err, android::hardware::graphics::mapper::V4_0::Error::NONE);
                    descriptor = desc;
                });
        ASSERT_TRUE(ret.isOk());
    buffer_handle_t buffer;
    uint32_t stride;

        ret = allocatorV4->allocate(
                descriptor, 1u,
                [&](android::hardware::graphics::mapper::V4_0::Error err, uint32_t /*stride*/,
                    const ::android::hardware::hidl_vec<::android::hardware::hidl_handle>&
                            buffers) {
                    ASSERT_EQ(android::hardware::graphics::mapper::V4_0::Error::NONE, err);
                    ASSERT_EQ(buffers.size(), 1u);
                    *buffer_handle = buffers[0];
                });
        ASSERT_TRUE(ret.isOk());
    } else if (mapperV3 != nullptr && allocatorV3 != nullptr) {
        ::android::hardware::hidl_vec<uint32_t> descriptor;
        android::hardware::graphics::mapper::V3_0::IMapper::BufferDescriptorInfo descriptorInfo {};
        descriptorInfo.width = width;
        descriptorInfo.height = height;
        descriptorInfo.layerCount = 1;
        descriptorInfo.format =
                static_cast<android::hardware::graphics::common::V1_2::PixelFormat>(format);
        descriptorInfo.usage = usage;

        auto ret = mapperV3->createDescriptor(
            descriptorInfo, [&descriptor](android::hardware::graphics::mapper::V3_0::Error err,
                                ::android::hardware::hidl_vec<uint32_t> desc) {
                ASSERT_EQ(err, android::hardware::graphics::mapper::V3_0::Error::NONE);
                descriptor = desc;
            });
        ASSERT_TRUE(ret.isOk());
    android::status_t err = android::GraphicBufferAllocator::get().allocate(
            width, height, static_cast<int32_t>(format), 1u /*layerCount*/, usage, &buffer, &stride,
            "VtsHalCameraProviderV2_4");
    ASSERT_EQ(err, android::NO_ERROR);

        ret = allocatorV3->allocate(descriptor, 1u,
            [&](android::hardware::graphics::mapper::V3_0::Error err, uint32_t /*stride*/,
                const ::android::hardware::hidl_vec<::android::hardware::hidl_handle>& buffers) {
                ASSERT_EQ(android::hardware::graphics::mapper::V3_0::Error::NONE, err);
                ASSERT_EQ(buffers.size(), 1u);
                *buffer_handle = buffers[0];
            });
        ASSERT_TRUE(ret.isOk());
    } else {
        ::android::hardware::hidl_vec<uint32_t> descriptor;
        ASSERT_NE(mapper.get(), nullptr);
        ASSERT_NE(allocator.get(), nullptr);
        android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo descriptorInfo {};
        descriptorInfo.width = width;
        descriptorInfo.height = height;
        descriptorInfo.layerCount = 1;
        descriptorInfo.format = format;
        descriptorInfo.usage = usage;

        auto ret = mapper->createDescriptor(
            descriptorInfo, [&descriptor](android::hardware::graphics::mapper::V2_0::Error err,
                                ::android::hardware::hidl_vec<uint32_t> desc) {
                ASSERT_EQ(err, android::hardware::graphics::mapper::V2_0::Error::NONE);
                descriptor = desc;
            });
        ASSERT_TRUE(ret.isOk());

        ret = allocator->allocate(descriptor, 1u,
            [&](android::hardware::graphics::mapper::V2_0::Error err, uint32_t /*stride*/,
                const ::android::hardware::hidl_vec<::android::hardware::hidl_handle>& buffers) {
                ASSERT_EQ(android::hardware::graphics::mapper::V2_0::Error::NONE, err);
                ASSERT_EQ(buffers.size(), 1u);
                *buffer_handle = buffers[0];
            });
        ASSERT_TRUE(ret.isOk());
    }
    buffer_handle->setTo(const_cast<native_handle_t*>(buffer), true /*shouldOwn*/);
}

void CameraHidlTest::verifyRecommendedConfigs(const CameraMetadata& chars) {