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

Commit fd046498 authored by Valerie Hau's avatar Valerie Hau Committed by android-build-merger
Browse files

Merge "Adding support for different Mapper versions in IComposer VTS tests" into qt-dev

am: 29594d2d

Change-Id: I1c52edfee963a404e29e2d2ace60771609c8541a
parents 094d43cf 29594d2d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -80,7 +80,8 @@ class ComposerImpl : public Interface {

    Return<void> createClient(IComposer::createClient_cb hidl_cb) override {
        std::unique_lock<std::mutex> lock(mClientMutex);
        if (!waitForClientDestroyedLocked(lock)) {
        bool destroyed = waitForClientDestroyedLocked(lock);
        if (!destroyed) {
            hidl_cb(Error::NO_RESOURCES, nullptr);
            return Void();
        }
+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",
Loading