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

Commit c1dc3134 authored by Valerie Hau's avatar Valerie Hau
Browse files

Adding support for different Mapper versions in IComposer VTS tests

Bug: 135139498
Test: build, boot, VtsHalGraphicsComposerV2_<1,2,3>TargetTest,
Change-Id: I05e2832c64d4c06eb4afd64c3323d7edbd19a5f4
parent c327806d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ cc_library_static {
    static_libs: [
        "VtsHalHidlTargetTestBase",
        "android.hardware.graphics.composer@2.1",
        "android.hardware.graphics.mapper@2.0-vts",
        "android.hardware.graphics.mapper@3.0-vts",
    ],
    header_libs: [
        "android.hardware.graphics.composer@2.1-command-buffer",
+71 −0
Original line number Diff line number Diff line
@@ -315,6 +315,77 @@ void ComposerClient::execute(TestCommandReader* reader, CommandWriterBase* write
    writer->reset();
}

Gralloc::Gralloc() {
    [this] {
        ASSERT_NO_FATAL_FAILURE(mGralloc3 = std::make_shared<Gralloc3>("default", "default",
                                                                       /*errOnFailure=*/false));
        if (mGralloc3->getAllocator() == nullptr || mGralloc3->getMapper() == nullptr) {
            mGralloc3 = nullptr;
            ASSERT_NO_FATAL_FAILURE(mGralloc2 = std::make_shared<Gralloc2>());
        }
    }();
}

const native_handle_t* Gralloc::allocate(uint32_t width, uint32_t height, uint32_t layerCount,
                                         PixelFormat format, uint64_t usage, bool import,
                                         uint32_t* outStride) {
    if (mGralloc3) {
        IMapper3::BufferDescriptorInfo info{};
        info.width = width;
        info.height = height;
        info.layerCount = layerCount;
        info.format = static_cast<android::hardware::graphics::common::V1_2::PixelFormat>(format);
        info.usage = usage;
        return mGralloc3->allocate(info, import, outStride);
    } else {
        IMapper2::BufferDescriptorInfo info{};
        info.width = width;
        info.height = height;
        info.layerCount = layerCount;
        info.format = format;
        info.usage = usage;
        return mGralloc2->allocate(info, import, outStride);
    }
}

void* Gralloc::lock(const native_handle_t* bufferHandle, uint64_t cpuUsage,
                    const AccessRegion& accessRegionRect, int acquireFence) {
    if (mGralloc3) {
        IMapper3::Rect accessRegion;
        accessRegion.left = accessRegionRect.left;
        accessRegion.top = accessRegionRect.top;
        accessRegion.width = accessRegionRect.width;
        accessRegion.height = accessRegionRect.height;
        int32_t bytesPerPixel;
        int32_t bytesPerStride;
        return mGralloc3->lock(bufferHandle, cpuUsage, accessRegion, acquireFence, &bytesPerPixel,
                               &bytesPerStride);
    } else {
        IMapper2::Rect accessRegion;
        accessRegion.left = accessRegionRect.left;
        accessRegion.top = accessRegionRect.top;
        accessRegion.width = accessRegionRect.width;
        accessRegion.height = accessRegionRect.height;
        return mGralloc2->lock(bufferHandle, cpuUsage, accessRegion, acquireFence);
    }
}

int Gralloc::unlock(const native_handle_t* bufferHandle) {
    if (mGralloc3) {
        return mGralloc3->unlock(bufferHandle);
    } else {
        return mGralloc2->unlock(bufferHandle);
    }
}

void Gralloc::freeBuffer(const native_handle_t* bufferHandle) {
    if (mGralloc3) {
        mGralloc3->freeBuffer(bufferHandle);
    } else {
        mGralloc2->freeBuffer(bufferHandle);
    }
}

}  // namespace vts
}  // namespace V2_1
}  // namespace composer
+36 −0
Original line number Diff line number Diff line
@@ -25,8 +25,12 @@
#include <android/hardware/graphics/composer/2.1/IComposer.h>
#include <composer-command-buffer/2.1/ComposerCommandBuffer.h>
#include <composer-vts/2.1/TestCommandReader.h>
#include <mapper-vts/2.0/MapperVts.h>
#include <mapper-vts/3.0/MapperVts.h>
#include <utils/StrongPointer.h>

#include "gtest/gtest.h"

namespace android {
namespace hardware {
namespace graphics {
@@ -38,6 +42,10 @@ using android::hardware::graphics::common::V1_0::ColorMode;
using android::hardware::graphics::common::V1_0::Dataspace;
using android::hardware::graphics::common::V1_0::Hdr;
using android::hardware::graphics::common::V1_0::PixelFormat;
using IMapper2 = android::hardware::graphics::mapper::V2_0::IMapper;
using IMapper3 = android::hardware::graphics::mapper::V3_0::IMapper;
using Gralloc2 = android::hardware::graphics::mapper::V2_0::vts::Gralloc;
using Gralloc3 = android::hardware::graphics::mapper::V3_0::vts::Gralloc;

class ComposerClient;

@@ -119,6 +127,34 @@ class ComposerClient {
    const sp<IComposerClient> mClient;
};

class AccessRegion {
  public:
    int32_t left;
    int32_t top;
    int32_t width;
    int32_t height;
};

class Gralloc {
  public:
    explicit Gralloc();

    const native_handle_t* allocate(uint32_t width, uint32_t height, uint32_t layerCount,
                                    PixelFormat format, uint64_t usage, bool import = true,
                                    uint32_t* outStride = nullptr);

    void* lock(const native_handle_t* bufferHandle, uint64_t cpuUsage,
               const AccessRegion& accessRegionRect, int acquireFence);

    int unlock(const native_handle_t* bufferHandle);

    void freeBuffer(const native_handle_t* bufferHandle);

  protected:
    std::shared_ptr<Gralloc2> mGralloc2 = nullptr;
    std::shared_ptr<Gralloc3> mGralloc3 = nullptr;
};

}  // namespace vts
}  // namespace V2_1
}  // namespace composer
+3 −0
Original line number Diff line number Diff line
@@ -26,10 +26,13 @@ cc_test {
    ],
    static_libs: [
        "android.hardware.graphics.allocator@2.0",
        "android.hardware.graphics.allocator@3.0",
        "android.hardware.graphics.composer@2.1",
        "android.hardware.graphics.composer@2.1-vts",
        "android.hardware.graphics.mapper@2.0",
        "android.hardware.graphics.mapper@2.0-vts",
        "android.hardware.graphics.mapper@3.0",
        "android.hardware.graphics.mapper@3.0-vts",
    ],
    header_libs: [
        "android.hardware.graphics.composer@2.1-command-buffer",
+6 −14
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <composer-vts/2.1/GraphicsComposerCallback.h>
#include <composer-vts/2.1/TestCommandReader.h>
#include <mapper-vts/2.0/MapperVts.h>
#include <mapper-vts/3.0/MapperVts.h>

#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
@@ -47,8 +48,6 @@ using android::hardware::graphics::common::V1_0::ColorTransform;
using android::hardware::graphics::common::V1_0::Dataspace;
using android::hardware::graphics::common::V1_0::PixelFormat;
using android::hardware::graphics::common::V1_0::Transform;
using android::hardware::graphics::mapper::V2_0::IMapper;
using android::hardware::graphics::mapper::V2_0::vts::Gralloc;
using GrallocError = android::hardware::graphics::mapper::V2_0::Error;

// Test environment for graphics.composer
@@ -669,7 +668,6 @@ class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest {
        ASSERT_NO_FATAL_FAILURE(GraphicsComposerHidlTest::SetUp());

        ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique<Gralloc>());

        Config activeConfig = mComposerClient->getActiveConfig(mPrimaryDisplay);
        mDisplayWidth = mComposerClient->getDisplayAttribute(mPrimaryDisplay, activeConfig,
                                                             IComposerClient::Attribute::WIDTH);
@@ -685,16 +683,10 @@ class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest {
    }

    const native_handle_t* allocate() {
        IMapper::BufferDescriptorInfo info{};
        info.width = mDisplayWidth;
        info.height = mDisplayHeight;
        info.layerCount = 1;
        info.format = PixelFormat::RGBA_8888;
        info.usage =
        uint64_t usage =
                static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN | BufferUsage::CPU_READ_OFTEN |
                                      BufferUsage::COMPOSER_OVERLAY);

        return mGralloc->allocate(info);
        return mGralloc->allocate(mDisplayWidth, mDisplayHeight, 1, PixelFormat::RGBA_8888, usage);
    }

    void execute() { mComposerClient->execute(mReader.get(), mWriter.get()); }
Loading