Remove mapper from composer2.1 VTS

Bug: 292584923
Test: make VtsHalGraphicsComposerV2_3TargetTest VtsHalGraphicsComposerV2_4TargetTest VtsHalGraphicsComposerV2_2TargetTest VtsHalGraphicsComposerV2_1TargetTest
Change-Id: I3642995e7236a3b9b08ad5419c9d02b67243b24a
This commit is contained in:
John Reck 2023-07-26 15:54:47 -04:00
parent 82c666bd8c
commit 6d0abbb439
12 changed files with 42 additions and 278 deletions

View file

@ -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",

View file

@ -18,6 +18,8 @@
#include "composer-resources/2.1/ComposerResources.h"
#include <ui/GraphicBufferMapper.h>
namespace android {
namespace hardware {
namespace graphics {
@ -25,23 +27,10 @@ namespace composer {
namespace V2_1 {
namespace hal {
ComposerHandleImporter::ComposerHandleImporter() : mMapper{GraphicBufferMapper::get()} {}
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");
mMapper3 = mapper::V3_0::IMapper::getService();
if (mMapper3) {
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,
@ -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) {
return Error::NO_RESOURCES;
}
}
*outBufferHandle = bufferHandle;
status_t status = mMapper.importBufferNoValidate(rawHandle, outBufferHandle);
if (status == STATUS_OK) {
return Error::NONE;
} else {
return Error::NO_RESOURCES;
}
}
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);
}
}

View file

@ -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 {

View file

@ -34,18 +34,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",

View file

@ -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

View file

@ -25,9 +25,6 @@
#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 <mapper-vts/4.0/MapperVts.h>
#include <utils/StrongPointer.h>
#include "gtest/gtest.h"
@ -43,13 +40,6 @@ 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 IMapper4 = android::hardware::graphics::mapper::V4_0::IMapper;
using Gralloc2 = android::hardware::graphics::mapper::V2_0::vts::Gralloc;
using Gralloc3 = android::hardware::graphics::mapper::V3_0::vts::Gralloc;
using Gralloc4 = android::hardware::graphics::mapper::V4_0::vts::Gralloc;
using IAllocator = aidl::android::hardware::graphics::allocator::IAllocator;
class ComposerClient;
@ -129,52 +119,6 @@ class ComposerClient {
const sp<IComposerClient> mClient;
};
class AccessRegion {
public:
int32_t left;
int32_t top;
int32_t width;
int32_t height;
};
class Gralloc;
// RAII wrapper around native_handle_t*
class NativeHandleWrapper {
public:
NativeHandleWrapper(Gralloc& gralloc, const native_handle_t* handle)
: mGralloc(gralloc), mHandle(handle) {}
~NativeHandleWrapper();
const native_handle_t* get() { return mHandle; }
private:
Gralloc& mGralloc;
const native_handle_t* mHandle;
};
class Gralloc {
public:
explicit Gralloc();
const NativeHandleWrapper 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;
std::shared_ptr<Gralloc4> mGralloc4 = nullptr;
};
} // namespace vts
} // namespace V2_1
} // namespace composer

View file

@ -38,22 +38,12 @@ cc_test {
"libbinder_ndk",
"libfmq",
"libsync",
"libui",
"android.hardware.common-V2-ndk",
"android.hardware.graphics.mapper@2.0",
"android.hardware.graphics.mapper@2.1",
"android.hardware.graphics.mapper@3.0",
"android.hardware.graphics.mapper@4.0",
],
static_libs: [
"android.hardware.graphics.allocator@2.0",
"android.hardware.graphics.allocator@3.0",
"android.hardware.graphics.allocator@4.0",
"android.hardware.graphics.composer@2.1",
"android.hardware.graphics.composer@2.1-vts",
"android.hardware.graphics.mapper@2.0-vts",
"android.hardware.graphics.mapper@2.1-vts",
"android.hardware.graphics.mapper@3.0-vts",
"android.hardware.graphics.mapper@4.0-vts",
"libaidlcommonsupport",
],
header_libs: [

View file

@ -25,9 +25,7 @@
#include <hardware/hwcomposer2.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <mapper-vts/2.0/MapperVts.h>
#include <mapper-vts/3.0/MapperVts.h>
#include <mapper-vts/4.0/MapperVts.h>
#include <ui/GraphicBuffer.h>
#include <unistd.h>
@ -52,7 +50,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 GrallocError = android::hardware::graphics::mapper::V2_0::Error;
class GraphicsComposerHidlTest : public ::testing::TestWithParam<std::string> {
protected:
@ -651,7 +648,6 @@ class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest {
void SetUp() override {
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);
@ -666,13 +662,17 @@ class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest {
ASSERT_NO_FATAL_FAILURE(GraphicsComposerHidlTest::TearDown());
}
NativeHandleWrapper allocate() { return allocate(mDisplayWidth, mDisplayHeight); }
sp<GraphicBuffer> allocate() { return allocate(mDisplayWidth, mDisplayHeight); }
NativeHandleWrapper allocate(uint32_t width, uint32_t height) {
uint64_t usage =
sp<GraphicBuffer> allocate(int32_t width, int32_t height) {
auto result = sp<GraphicBuffer>::make(
width, height, static_cast<int32_t>(PixelFormat::RGBA_8888), /*layerCount*/ 1,
static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN | BufferUsage::CPU_READ_OFTEN |
BufferUsage::COMPOSER_OVERLAY);
return mGralloc->allocate(width, height, 1, PixelFormat::RGBA_8888, usage);
BufferUsage::COMPOSER_OVERLAY));
if (result->initCheck() != STATUS_OK) {
return nullptr;
}
return result;
}
void execute() { mComposerClient->execute(mReader.get(), mWriter.get()); }
@ -681,9 +681,6 @@ class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest {
std::unique_ptr<TestCommandReader> mReader;
int32_t mDisplayWidth;
int32_t mDisplayHeight;
private:
std::unique_ptr<Gralloc> mGralloc;
};
/**
@ -729,11 +726,11 @@ TEST_P(GraphicsComposerHidlCommandTest, SET_OUTPUT_BUFFER) {
display = mComposerClient->createVirtualDisplay(64, 64, PixelFormat::IMPLEMENTATION_DEFINED,
kBufferSlotCount, &format));
std::unique_ptr<NativeHandleWrapper> handle;
ASSERT_NO_FATAL_FAILURE(handle.reset(new NativeHandleWrapper(allocate())));
auto handle = allocate();
ASSERT_TRUE(handle);
mWriter->selectDisplay(display);
mWriter->setOutputBuffer(0, handle->get(), -1);
mWriter->setOutputBuffer(0, handle->handle, -1);
execute();
}
@ -802,7 +799,7 @@ TEST_P(GraphicsComposerHidlCommandTest, PRESENT_DISPLAY_NO_LAYER_STATE_CHANGES)
mWriter->setLayerZOrder(10);
mWriter->setLayerBlendMode(IComposerClient::BlendMode::NONE);
mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>(1, displayFrame));
mWriter->setLayerBuffer(0, handle.get(), -1);
mWriter->setLayerBuffer(0, handle->handle, -1);
mWriter->setLayerDataspace(Dataspace::UNKNOWN);
mWriter->validateDisplay();
@ -820,7 +817,7 @@ TEST_P(GraphicsComposerHidlCommandTest, PRESENT_DISPLAY_NO_LAYER_STATE_CHANGES)
mWriter->selectLayer(layer);
auto handle2 = allocate();
ASSERT_NE(nullptr, handle2.get());
mWriter->setLayerBuffer(0, handle2.get(), -1);
mWriter->setLayerBuffer(0, handle2->handle, -1);
mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>(1, {0, 0, 10, 10}));
mWriter->presentDisplay();
execute();
@ -840,7 +837,7 @@ TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_CURSOR_POSITION) {
mWriter->selectDisplay(mPrimaryDisplay);
mWriter->selectLayer(layer);
mWriter->setLayerBuffer(0, handle.get(), -1);
mWriter->setLayerBuffer(0, handle->handle, -1);
mWriter->setLayerCompositionType(IComposerClient::Composition::CURSOR);
mWriter->setLayerDisplayFrame(displayFrame);
mWriter->setLayerPlaneAlpha(1);
@ -881,7 +878,7 @@ TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_BUFFER) {
mWriter->selectDisplay(mPrimaryDisplay);
mWriter->selectLayer(layer);
mWriter->setLayerBuffer(0, handle.get(), -1);
mWriter->setLayerBuffer(0, handle->handle, -1);
execute();
}
@ -905,7 +902,7 @@ TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_BUFFER_multipleTimes) {
mWriter->selectLayer(layer);
mWriter->setLayerCompositionType(IComposerClient::Composition::DEVICE);
mWriter->setLayerDisplayFrame(displayFrame);
mWriter->setLayerBuffer(0, handle1.get(), -1);
mWriter->setLayerBuffer(0, handle1->handle, -1);
mWriter->setLayerDataspace(Dataspace::UNKNOWN);
mWriter->validateDisplay();
execute();
@ -928,7 +925,7 @@ TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_BUFFER_multipleTimes) {
mWriter->selectLayer(layer);
mWriter->setLayerCompositionType(IComposerClient::Composition::DEVICE);
mWriter->setLayerDisplayFrame(displayFrame);
mWriter->setLayerBuffer(1, handle2.get(), -1);
mWriter->setLayerBuffer(1, handle2->handle, -1);
mWriter->setLayerDataspace(Dataspace::UNKNOWN);
mWriter->validateDisplay();
execute();
@ -951,7 +948,7 @@ TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_BUFFER_multipleTimes) {
mWriter->selectLayer(layer);
mWriter->setLayerCompositionType(IComposerClient::Composition::DEVICE);
mWriter->setLayerDisplayFrame(displayFrame);
mWriter->setLayerBuffer(2, handle3.get(), -1);
mWriter->setLayerBuffer(2, handle3->handle, -1);
mWriter->setLayerDataspace(Dataspace::UNKNOWN);
mWriter->validateDisplay();
execute();
@ -968,10 +965,10 @@ TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_BUFFER_multipleTimes) {
// Ensure we can clear multiple buffer slots and then restore the active buffer at the end
mWriter->selectDisplay(mPrimaryDisplay);
mWriter->selectLayer(layer);
mWriter->setLayerBuffer(0, clearSlotBuffer.get(), -1);
mWriter->setLayerBuffer(0, clearSlotBuffer->handle, -1);
mWriter->selectDisplay(mPrimaryDisplay);
mWriter->selectLayer(layer);
mWriter->setLayerBuffer(1, clearSlotBuffer.get(), -1);
mWriter->setLayerBuffer(1, clearSlotBuffer->handle, -1);
mWriter->selectDisplay(mPrimaryDisplay);
mWriter->selectLayer(layer);
mWriter->setLayerBuffer(2, nullptr, -1);
@ -1113,7 +1110,7 @@ TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_SIDEBAND_STREAM) {
mWriter->selectDisplay(mPrimaryDisplay);
mWriter->selectLayer(layer);
mWriter->setLayerSidebandStream(handle.get());
mWriter->setLayerSidebandStream(handle->handle);
execute();
}

View file

@ -40,7 +40,6 @@ using common::V1_1::PixelFormat;
using renderengine::LayerSettings;
using V2_1::Display;
using V2_1::Layer;
using V2_1::vts::AccessRegion;
using V2_1::vts::TestCommandReader;
static const IComposerClient::Color BLACK = {0, 0, 0, 0xff};

View file

@ -45,7 +45,6 @@ using common::V1_1::Dataspace;
using common::V1_1::PixelFormat;
using V2_1::Config;
using V2_1::Display;
using V2_1::vts::NativeHandleWrapper;
using V2_1::vts::TestCommandReader;
class GraphicsCompositionTestBase : public ::testing::Test {

View file

@ -39,7 +39,6 @@ using common::V1_1::ColorMode;
using common::V1_1::Dataspace;
using common::V1_1::PixelFormat;
using common::V1_1::RenderIntent;
using V2_1::vts::NativeHandleWrapper;
class GraphicsComposerHidlTest : public ::testing::TestWithParam<std::string> {
protected:

View file

@ -48,7 +48,6 @@ using common::V1_2::ColorMode;
using common::V1_2::Dataspace;
using common::V1_2::PixelFormat;
using V2_1::Layer;
using V2_1::vts::NativeHandleWrapper;
using V2_2::Transform;
using ContentType = IComposerClient::ContentType;