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

Commit 7604c41a authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Merge changes I6c5e8c8b,I3642995e,Id281c732 into main

* changes:
  Remove allocator from composer2.1-4 VTS
  Remove mapper from composer2.1 VTS
  Remove mapper from composer2.2 VTS
parents 496e17d5 631dc15b
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -29,20 +29,15 @@ cc_library {
    vendor_available: true,
    shared_libs: [
        "android.hardware.graphics.composer@2.1",
        "android.hardware.graphics.mapper@2.0",
        "android.hardware.graphics.mapper@3.0",
        "android.hardware.graphics.mapper@4.0",
        "libcutils",
        "libhardware", // TODO remove hwcomposer2.h dependency
        "libhidlbase",
        "liblog",
        "libui",
        "libutils",
    ],
    export_shared_lib_headers: [
        "android.hardware.graphics.composer@2.1",
        "android.hardware.graphics.mapper@2.0",
        "android.hardware.graphics.mapper@3.0",
        "android.hardware.graphics.mapper@4.0",
        "libhardware",
        "libhidlbase",
        "liblog",
+11 −56
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@

#include "composer-resources/2.1/ComposerResources.h"

#include <ui/GraphicBufferMapper.h>

namespace android {
namespace hardware {
namespace graphics {
@@ -25,24 +27,11 @@ namespace composer {
namespace V2_1 {
namespace hal {

bool ComposerHandleImporter::init() {
    mMapper4 = mapper::V4_0::IMapper::getService();
    if (mMapper4) {
        return true;
    }
    ALOGI_IF(!mMapper4, "failed to get mapper 4.0 service, falling back to mapper 3.0");
ComposerHandleImporter::ComposerHandleImporter() : mMapper{GraphicBufferMapper::get()} {}

    mMapper3 = mapper::V3_0::IMapper::getService();
    if (mMapper3) {
bool ComposerHandleImporter::init() {
    return true;
}
    ALOGI_IF(!mMapper3, "failed to get mapper 3.0 service, falling back to mapper 2.0");

    mMapper2 = mapper::V2_0::IMapper::getService();
    ALOGE_IF(!mMapper2, "failed to get mapper 2.0 service");

    return mMapper2 != nullptr;
}

Error ComposerHandleImporter::importBuffer(const native_handle_t* rawHandle,
                                           const native_handle_t** outBufferHandle) {
@@ -51,51 +40,17 @@ Error ComposerHandleImporter::importBuffer(const native_handle_t* rawHandle,
        return Error::NONE;
    }

    const native_handle_t* bufferHandle;
    if (mMapper2) {
        mapper::V2_0::Error error;
        mMapper2->importBuffer(rawHandle, [&](const auto& tmpError, const auto& tmpBufferHandle) {
            error = tmpError;
            bufferHandle = static_cast<const native_handle_t*>(tmpBufferHandle);
        });
        if (error != mapper::V2_0::Error::NONE) {
            return Error::NO_RESOURCES;
        }
    }
    if (mMapper3) {
        mapper::V3_0::Error error;
        mMapper3->importBuffer(rawHandle, [&](const auto& tmpError, const auto& tmpBufferHandle) {
            error = tmpError;
            bufferHandle = static_cast<const native_handle_t*>(tmpBufferHandle);
        });
        if (error != mapper::V3_0::Error::NONE) {
            return Error::NO_RESOURCES;
        }
    }
    if (mMapper4) {
        mapper::V4_0::Error error;
        mMapper4->importBuffer(rawHandle, [&](const auto& tmpError, const auto& tmpBufferHandle) {
            error = tmpError;
            bufferHandle = static_cast<const native_handle_t*>(tmpBufferHandle);
        });
        if (error != mapper::V4_0::Error::NONE) {
    status_t status = mMapper.importBufferNoValidate(rawHandle, outBufferHandle);
    if (status == STATUS_OK) {
        return Error::NONE;
    } else {
        return Error::NO_RESOURCES;
    }
}

    *outBufferHandle = bufferHandle;
    return Error::NONE;
}

void ComposerHandleImporter::freeBuffer(const native_handle_t* bufferHandle) {
    if (bufferHandle) {
        if (mMapper2) {
            mMapper2->freeBuffer(static_cast<void*>(const_cast<native_handle_t*>(bufferHandle)));
        } else if (mMapper3) {
            mMapper3->freeBuffer(static_cast<void*>(const_cast<native_handle_t*>(bufferHandle)));
        } else if (mMapper4) {
            mMapper4->freeBuffer(static_cast<void*>(const_cast<native_handle_t*>(bufferHandle)));
        }
        mMapper.freeBuffer(bufferHandle);
    }
}

+3 −6
Original line number Diff line number Diff line
@@ -27,12 +27,10 @@

#include <android/hardware/graphics/composer/2.1/types.h>

#include <android/hardware/graphics/mapper/2.0/IMapper.h>
#include <android/hardware/graphics/mapper/3.0/IMapper.h>
#include <android/hardware/graphics/mapper/4.0/IMapper.h>
#include <log/log.h>

namespace android {
class GraphicBufferMapper;
namespace hardware {
namespace graphics {
namespace composer {
@@ -42,6 +40,7 @@ namespace hal {
// wrapper for IMapper to import buffers and sideband streams
class ComposerHandleImporter {
  public:
    ComposerHandleImporter();
    bool init();

    Error importBuffer(const native_handle_t* rawHandle, const native_handle_t** outBufferHandle);
@@ -50,9 +49,7 @@ class ComposerHandleImporter {
    void freeStream(const native_handle_t* streamHandle);

  private:
    sp<mapper::V2_0::IMapper> mMapper2;
    sp<mapper::V3_0::IMapper> mMapper3;
    sp<mapper::V4_0::IMapper> mMapper4;
    GraphicBufferMapper& mMapper;
};

class ComposerHandleCache {
+3 −7
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ package {
cc_library_static {
    name: "android.hardware.graphics.composer@2.1-vts",
    defaults: [
        "android.hardware.graphics.allocator-ndk_static",
        "hidl_defaults",
    ],
    srcs: [
@@ -34,18 +33,15 @@ cc_library_static {
        "GraphicsComposerCallback.cpp",
        "TestCommandReader.cpp",
    ],
    shared_libs: [
        "libui",
    ],
    static_libs: [
        "android.hardware.graphics.composer@2.1",
        "android.hardware.graphics.mapper@2.0-vts",
        "android.hardware.graphics.mapper@3.0-vts",
        "android.hardware.graphics.mapper@4.0-vts",
        "libgtest",
    ],
    export_static_lib_headers: [
        "android.hardware.graphics.composer@2.1",
        "android.hardware.graphics.mapper@2.0-vts",
        "android.hardware.graphics.mapper@3.0-vts",
        "android.hardware.graphics.mapper@4.0-vts",
    ],
    header_libs: [
        "android.hardware.graphics.composer@2.1-command-buffer",
+0 −107
Original line number Diff line number Diff line
@@ -308,113 +308,6 @@ void ComposerClient::execute(TestCommandReader* reader, CommandWriterBase* write
    writer->reset();
}

NativeHandleWrapper::~NativeHandleWrapper() {
    if (mHandle) {
        mGralloc.freeBuffer(mHandle);
    }
}

Gralloc::Gralloc() {
    [this] {
        ASSERT_NO_FATAL_FAILURE(mGralloc4 = std::make_shared<Gralloc4>(
                                        /*aidlAllocatorServiceName*/ IAllocator::descriptor +
                                                std::string("/default"),
                                        /*hidlAllocatorServiceName*/ "default",
                                        /*mapperServiceName*/ "default",
                                        /*errOnFailure=*/false));
        if (!mGralloc4->hasAllocator() || mGralloc4->getMapper() == nullptr) {
            mGralloc4 = nullptr;
            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 NativeHandleWrapper Gralloc::allocate(uint32_t width, uint32_t height, uint32_t layerCount,
                                            PixelFormat format, uint64_t usage, bool import,
                                            uint32_t* outStride) {
    const native_handle_t* handle;
    if (mGralloc4) {
        IMapper4::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;
        handle = mGralloc4->allocate(info, import, outStride);
    } else 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;
        handle = mGralloc3->allocate(info, import, outStride);
    } else {
        IMapper2::BufferDescriptorInfo info{};
        info.width = width;
        info.height = height;
        info.layerCount = layerCount;
        info.format = format;
        info.usage = usage;
        handle = mGralloc2->allocate(info, import, outStride);
    }
    return NativeHandleWrapper(*this, handle);
}

void* Gralloc::lock(const native_handle_t* bufferHandle, uint64_t cpuUsage,
                    const AccessRegion& accessRegionRect, int acquireFence) {
    if (mGralloc4) {
        IMapper4::Rect accessRegion;
        accessRegion.left = accessRegionRect.left;
        accessRegion.top = accessRegionRect.top;
        accessRegion.width = accessRegionRect.width;
        accessRegion.height = accessRegionRect.height;
        return mGralloc4->lock(bufferHandle, cpuUsage, accessRegion, acquireFence);
    } else 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 (mGralloc4) {
        return mGralloc4->unlock(bufferHandle);
    } else if (mGralloc3) {
        return mGralloc3->unlock(bufferHandle);
    } else {
        return mGralloc2->unlock(bufferHandle);
    }
}

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

}  // namespace vts
}  // namespace V2_1
}  // namespace composer
Loading