Merge "Adding support for different Mapper versions in IComposer VTS tests"

This commit is contained in:
Valerie Hau 2019-06-19 23:12:47 +00:00 committed by Android (Google) Code Review
commit 5bb66a6948
20 changed files with 371 additions and 181 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -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()); }

View file

@ -28,6 +28,8 @@ cc_library_static {
"android.hardware.graphics.composer@2.2",
"android.hardware.graphics.mapper@2.1",
"android.hardware.graphics.mapper@2.1-vts",
"android.hardware.graphics.mapper@3.0",
"android.hardware.graphics.mapper@3.0-vts",
],
export_static_lib_headers: [
"android.hardware.graphics.composer@2.1-vts",

View file

@ -180,6 +180,48 @@ std::array<float, 16> ComposerClient::getDataspaceSaturationMatrix(Dataspace dat
return matrix;
}
Gralloc::Gralloc() {
[this] {
ALOGD("Attempting to initialize gralloc3");
ASSERT_NO_FATAL_FAILURE(mGralloc3 = std::make_shared<Gralloc3>("default", "default",
/*errOnFailure=*/false));
if (mGralloc3->getMapper() == nullptr || mGralloc3->getAllocator() == nullptr) {
mGralloc3 = nullptr;
ALOGD("Failed to initialize gralloc3, initializing gralloc2_1");
mGralloc2_1 = std::make_shared<Gralloc2_1>(/*errOnFailure*/ false);
if (!mGralloc2_1->getMapper()) {
mGralloc2_1 = nullptr;
ALOGD("Failed to initialize gralloc2_1, initializing gralloc2");
ASSERT_NO_FATAL_FAILURE(mGralloc2 = std::make_shared<Gralloc2>());
}
}
}();
}
bool Gralloc::validateBufferSize(const native_handle_t* bufferHandle, uint32_t width,
uint32_t height, uint32_t layerCount, PixelFormat format,
uint64_t usage, uint32_t stride) {
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->validateBufferSize(bufferHandle, info, stride);
} else if (mGralloc2_1) {
IMapper2_1::BufferDescriptorInfo info{};
info.width = width;
info.height = height;
info.layerCount = layerCount;
info.format = static_cast<android::hardware::graphics::common::V1_1::PixelFormat>(format);
info.usage = usage;
return mGralloc2_1->validateBufferSize(bufferHandle, info, stride);
} else {
return true;
}
}
} // namespace vts
} // namespace V2_2
} // namespace composer

View file

@ -116,11 +116,11 @@ ReadbackBuffer::ReadbackBuffer(Display display, const std::shared_ptr<ComposerCl
mPixelFormat = pixelFormat;
mDataspace = dataspace;
mInfo.width = width;
mInfo.height = height;
mInfo.layerCount = 1;
mInfo.format = mPixelFormat;
mInfo.usage = static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN | BufferUsage::GPU_TEXTURE);
mWidth = width;
mHeight = height;
mLayerCount = 1;
mFormat = mPixelFormat;
mUsage = static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN | BufferUsage::GPU_TEXTURE);
mAccessRegion.top = 0;
mAccessRegion.left = 0;
@ -139,8 +139,10 @@ void ReadbackBuffer::setReadbackBuffer() {
mGralloc->freeBuffer(mBufferHandle);
mBufferHandle = nullptr;
}
mBufferHandle = mGralloc->allocate(mInfo, /*import*/ true, &mStride);
ASSERT_NE(false, mGralloc->validateBufferSize(mBufferHandle, mInfo, mStride));
mBufferHandle = mGralloc->allocate(mWidth, mHeight, mLayerCount, mFormat, mUsage,
/*import*/ true, &mStride);
ASSERT_NE(false, mGralloc->validateBufferSize(mBufferHandle, mWidth, mHeight, mLayerCount,
mFormat, mUsage, mStride));
ASSERT_NO_FATAL_FAILURE(mComposerClient->setReadbackBuffer(mDisplay, mBufferHandle, -1));
}
@ -149,13 +151,13 @@ void ReadbackBuffer::checkReadbackBuffer(std::vector<IComposerClient::Color> exp
int32_t fenceHandle;
ASSERT_NO_FATAL_FAILURE(mComposerClient->getReadbackBufferFence(mDisplay, &fenceHandle));
void* bufData = mGralloc->lock(mBufferHandle, mInfo.usage, mAccessRegion, fenceHandle);
void* bufData = mGralloc->lock(mBufferHandle, mUsage, mAccessRegion, fenceHandle);
ASSERT_TRUE(mPixelFormat == PixelFormat::RGB_888 || mPixelFormat == PixelFormat::RGBA_8888);
int32_t bytesPerPixel = ReadbackHelper::GetBytesPerPixel(mPixelFormat);
ASSERT_NE(-1, bytesPerPixel);
for (int row = 0; row < mInfo.height; row++) {
for (int col = 0; col < mInfo.width; col++) {
int pixel = row * mInfo.width + col;
for (int row = 0; row < mHeight; row++) {
for (int col = 0; col < mWidth; col++) {
int pixel = row * mWidth + col;
int offset = (row * mStride + col) * bytesPerPixel;
uint8_t* pixelColor = (uint8_t*)bufData + offset;
@ -184,11 +186,11 @@ TestBufferLayer::TestBufferLayer(const std::shared_ptr<ComposerClient>& client,
: TestLayer{client, display} {
mGralloc = gralloc;
mComposition = composition;
mInfo.width = width;
mInfo.height = height;
mInfo.layerCount = 1;
mInfo.format = format;
mInfo.usage = static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
mWidth = width;
mHeight = height;
mLayerCount = 1;
mFormat = format;
mUsage = static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
BufferUsage::COMPOSER_OVERLAY);
mAccessRegion.top = 0;
@ -214,9 +216,9 @@ void TestBufferLayer::write(const std::shared_ptr<CommandWriterBase>& writer) {
}
void TestBufferLayer::fillBuffer(std::vector<IComposerClient::Color> expectedColors) {
void* bufData = mGralloc->lock(mBufferHandle, mInfo.usage, mAccessRegion, -1);
ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(mInfo.width, mInfo.height, mStride, bufData,
mInfo.format, expectedColors));
void* bufData = mGralloc->lock(mBufferHandle, mUsage, mAccessRegion, -1);
ASSERT_NO_FATAL_FAILURE(
ReadbackHelper::fillBuffer(mWidth, mHeight, mStride, bufData, mFormat, expectedColors));
mFillFence = mGralloc->unlock(mBufferHandle);
if (mFillFence != -1) {
sync_wait(mFillFence, -1);
@ -228,10 +230,12 @@ void TestBufferLayer::setBuffer(std::vector<IComposerClient::Color> colors) {
mGralloc->freeBuffer(mBufferHandle);
mBufferHandle = nullptr;
}
mBufferHandle = mGralloc->allocate(mInfo, /*import*/ true, &mStride);
mBufferHandle = mGralloc->allocate(mWidth, mHeight, mLayerCount, mFormat, mUsage,
/*import*/ true, &mStride);
ASSERT_NE(nullptr, mBufferHandle);
ASSERT_NO_FATAL_FAILURE(fillBuffer(colors));
ASSERT_NE(false, mGralloc->validateBufferSize(mBufferHandle, mInfo, mStride));
ASSERT_NE(false, mGralloc->validateBufferSize(mBufferHandle, mWidth, mHeight, mLayerCount,
mFormat, mUsage, mStride));
}
void TestBufferLayer::setToClientComposition(const std::shared_ptr<CommandWriterBase>& writer) {

View file

@ -27,6 +27,7 @@
#include <android/hardware/graphics/composer/2.2/IComposerClient.h>
#include <composer-command-buffer/2.2/ComposerCommandBuffer.h>
#include <composer-vts/2.1/ComposerVts.h>
#include <mapper-vts/2.1/MapperVts.h>
#include <utils/StrongPointer.h>
namespace android {
@ -41,6 +42,11 @@ using common::V1_1::ColorMode;
using common::V1_1::Dataspace;
using common::V1_1::PixelFormat;
using common::V1_1::RenderIntent;
using IMapper2_1 = android::hardware::graphics::mapper::V2_1::IMapper;
using IMapper3 = android::hardware::graphics::mapper::V3_0::IMapper;
using Gralloc2 = android::hardware::graphics::mapper::V2_0::vts::Gralloc;
using Gralloc2_1 = android::hardware::graphics::mapper::V2_1::vts::Gralloc;
using Gralloc3 = android::hardware::graphics::mapper::V3_0::vts::Gralloc;
class ComposerClient;
@ -84,6 +90,26 @@ class ComposerClient : public V2_1::vts::ComposerClient {
const sp<IComposerClient> mClient;
};
class Gralloc : public V2_1::vts::Gralloc {
public:
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) {
return V2_1::vts::Gralloc::allocate(
width, height, layerCount,
static_cast<android::hardware::graphics::common::V1_0::PixelFormat>(format), usage,
import, outStride);
}
bool validateBufferSize(const native_handle_t* bufferHandle, uint32_t width, uint32_t height,
uint32_t layerCount, PixelFormat format, uint64_t usage,
uint32_t stride);
protected:
std::shared_ptr<Gralloc2_1> mGralloc2_1 = nullptr;
};
} // namespace vts
} // namespace V2_2
} // namespace composer

View file

@ -33,10 +33,11 @@ using android::hardware::hidl_handle;
using common::V1_1::BufferUsage;
using common::V1_1::Dataspace;
using common::V1_1::PixelFormat;
using mapper::V2_1::IMapper;
using mapper::V2_1::vts::Gralloc;
using IMapper2_1 = mapper::V2_1::IMapper;
using Gralloc2_1 = mapper::V2_1::vts::Gralloc;
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};
@ -115,8 +116,12 @@ class TestBufferLayer : public TestLayer {
void setToClientComposition(const std::shared_ptr<CommandWriterBase>& writer);
IMapper::BufferDescriptorInfo mInfo;
IMapper::Rect mAccessRegion;
uint32_t mWidth;
uint32_t mHeight;
uint32_t mLayerCount;
PixelFormat mFormat;
uint64_t mUsage;
AccessRegion mAccessRegion;
uint32_t mStride;
protected:
@ -156,8 +161,12 @@ class ReadbackBuffer {
void checkReadbackBuffer(std::vector<IComposerClient::Color> expectedColors);
protected:
IMapper::BufferDescriptorInfo mInfo;
IMapper::Rect mAccessRegion;
uint32_t mWidth;
uint32_t mHeight;
uint32_t mLayerCount;
PixelFormat mFormat;
uint64_t mUsage;
AccessRegion mAccessRegion;
uint32_t mStride;
const native_handle_t* mBufferHandle = nullptr;
PixelFormat mPixelFormat;

View file

@ -31,6 +31,7 @@ cc_test {
],
static_libs: [
"android.hardware.graphics.allocator@2.0",
"android.hardware.graphics.allocator@3.0",
"android.hardware.graphics.common@1.1",
"android.hardware.graphics.composer@2.1",
"android.hardware.graphics.composer@2.1-vts",
@ -40,6 +41,8 @@ cc_test {
"android.hardware.graphics.mapper@2.0-vts",
"android.hardware.graphics.mapper@2.1",
"android.hardware.graphics.mapper@2.1-vts",
"android.hardware.graphics.mapper@3.0",
"android.hardware.graphics.mapper@3.0-vts",
],
header_libs: [
"android.hardware.graphics.composer@2.1-command-buffer",

View file

@ -36,7 +36,6 @@ using common::V1_1::BufferUsage;
using common::V1_1::Dataspace;
using common::V1_1::PixelFormat;
using mapper::V2_1::IMapper;
using mapper::V2_1::vts::Gralloc;
using V2_1::Display;
using V2_1::Layer;
using V2_1::vts::TestCommandReader;
@ -269,14 +268,11 @@ TEST_F(GraphicsComposerReadbackTest, SetLayerBufferNoEffect) {
layer->write(mWriter);
// This following buffer call should have no effect
IMapper::BufferDescriptorInfo bufferInfo{};
bufferInfo.width = mDisplayWidth;
bufferInfo.height = mDisplayHeight;
bufferInfo.layerCount = 1;
bufferInfo.format = PixelFormat::RGBA_8888;
bufferInfo.usage =
PixelFormat format = PixelFormat::RGBA_8888;
uint64_t usage =
static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN);
const native_handle_t* bufferHandle = mGralloc->allocate(bufferInfo);
const native_handle_t* bufferHandle =
mGralloc->allocate(mDisplayWidth, mDisplayHeight, 1, format, usage);
mWriter->setLayerBuffer(0, bufferHandle, -1);
// expected color for each pixel
@ -345,24 +341,21 @@ TEST_F(GraphicsComposerReadbackTest, ClientComposition) {
// create client target buffer
uint32_t clientStride;
IMapper::BufferDescriptorInfo clientInfo;
clientInfo.width = layer->mInfo.width;
clientInfo.height = layer->mInfo.height;
clientInfo.layerCount = layer->mInfo.layerCount;
clientInfo.format = PixelFormat::RGBA_8888;
clientInfo.usage =
PixelFormat clientFormat = PixelFormat::RGBA_8888;
uint64_t clientUsage =
static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
BufferUsage::COMPOSER_CLIENT_TARGET);
const native_handle_t* clientBufferHandle =
mGralloc->allocate(clientInfo, /*import*/ true, &clientStride);
mGralloc->allocate(layer->mWidth, layer->mHeight, layer->mLayerCount, clientFormat,
clientUsage, /*import*/ true, &clientStride);
ASSERT_NE(nullptr, clientBufferHandle);
void* clientBufData =
mGralloc->lock(clientBufferHandle, clientInfo.usage, layer->mAccessRegion, -1);
mGralloc->lock(clientBufferHandle, clientUsage, layer->mAccessRegion, -1);
ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(clientInfo.width, clientInfo.height,
ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(layer->mWidth, layer->mHeight,
clientStride, clientBufData,
clientInfo.format, expectedColors));
clientFormat, expectedColors));
int clientFence = mGralloc->unlock(clientBufferHandle);
if (clientFence != -1) {
sync_wait(clientFence, -1);
@ -411,14 +404,13 @@ TEST_F(GraphicsComposerReadbackTest, DeviceAndClientComposition) {
auto deviceLayer =
std::make_shared<TestBufferLayer>(mComposerClient, mGralloc, mPrimaryDisplay, mDisplayWidth,
mDisplayHeight / 2, PixelFormat::RGBA_8888);
std::vector<IComposerClient::Color> deviceColors(deviceLayer->mInfo.width *
deviceLayer->mInfo.height);
ReadbackHelper::fillColorsArea(deviceColors, deviceLayer->mInfo.width,
{0, 0, static_cast<int32_t>(deviceLayer->mInfo.width),
static_cast<int32_t>(deviceLayer->mInfo.height)},
std::vector<IComposerClient::Color> deviceColors(deviceLayer->mWidth * deviceLayer->mHeight);
ReadbackHelper::fillColorsArea(deviceColors, deviceLayer->mWidth,
{0, 0, static_cast<int32_t>(deviceLayer->mWidth),
static_cast<int32_t>(deviceLayer->mHeight)},
GREEN);
deviceLayer->setDisplayFrame({0, 0, static_cast<int32_t>(deviceLayer->mInfo.width),
static_cast<int32_t>(deviceLayer->mInfo.height)});
deviceLayer->setDisplayFrame({0, 0, static_cast<int32_t>(deviceLayer->mWidth),
static_cast<int32_t>(deviceLayer->mHeight)});
deviceLayer->setZOrder(10);
ASSERT_NO_FATAL_FAILURE(deviceLayer->setBuffer(deviceColors));
deviceLayer->write(mWriter);
@ -433,30 +425,25 @@ TEST_F(GraphicsComposerReadbackTest, DeviceAndClientComposition) {
execute();
ASSERT_EQ(0, mReader->mErrors.size());
IMapper::BufferDescriptorInfo clientInfo;
clientInfo.width = mDisplayWidth;
clientInfo.height = mDisplayHeight;
clientInfo.layerCount = 1;
clientInfo.format = PixelFormat::RGBA_8888;
clientInfo.usage =
uint64_t clientUsage =
static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
BufferUsage::COMPOSER_CLIENT_TARGET);
uint32_t clientStride;
const native_handle_t* clientBufferHandle =
mGralloc->allocate(clientInfo, /*import*/ true, &clientStride);
mGralloc->allocate(mDisplayWidth, mDisplayHeight, 1, PixelFormat::RGBA_8888,
clientUsage, /*import*/ true, &clientStride);
ASSERT_NE(nullptr, clientBufferHandle);
IMapper::Rect clientAccessRegion;
AccessRegion clientAccessRegion;
clientAccessRegion.left = 0;
clientAccessRegion.top = 0;
clientAccessRegion.width = mDisplayWidth;
clientAccessRegion.height = mDisplayHeight;
void* clientData = mGralloc->lock(clientBufferHandle, clientInfo.usage, clientAccessRegion, -1);
std::vector<IComposerClient::Color> clientColors(clientInfo.width * clientInfo.height);
ReadbackHelper::fillColorsArea(clientColors, clientInfo.width, clientFrame, RED);
ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(clientInfo.width, clientInfo.height,
clientStride, clientData, clientInfo.format,
void* clientData = mGralloc->lock(clientBufferHandle, clientUsage, clientAccessRegion, -1);
std::vector<IComposerClient::Color> clientColors(mDisplayWidth * mDisplayHeight);
ReadbackHelper::fillColorsArea(clientColors, mDisplayWidth, clientFrame, RED);
ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(mDisplayWidth, mDisplayHeight, clientStride,
clientData, PixelFormat::RGBA_8888,
clientColors));
int clientFence = mGralloc->unlock(clientBufferHandle);
if (clientFence != -1) {

View file

@ -40,7 +40,6 @@ using common::V1_1::Dataspace;
using common::V1_1::PixelFormat;
using common::V1_1::RenderIntent;
using mapper::V2_0::IMapper;
using mapper::V2_0::vts::Gralloc;
// Test environment for graphics.composer
class GraphicsComposerHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
@ -171,15 +170,10 @@ class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest {
}
const native_handle_t* allocate() {
IMapper::BufferDescriptorInfo info{};
info.width = 64;
info.height = 64;
info.layerCount = 1;
info.format = static_cast<common::V1_0::PixelFormat>(PixelFormat::RGBA_8888);
info.usage =
uint64_t usage =
static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN | BufferUsage::CPU_READ_OFTEN);
return mGralloc->allocate(info);
return mGralloc->allocate(/*width*/ 64, /*height*/ 64, /*layerCount*/ 1,
PixelFormat::RGBA_8888, usage);
}
void execute() { mComposerClient->execute(mReader.get(), mWriter.get()); }
@ -456,18 +450,15 @@ TEST_F(GraphicsComposerHidlTest, SetReadbackBuffer) {
return;
}
IMapper::BufferDescriptorInfo info{};
info.width = mDisplayWidth;
info.height = mDisplayHeight;
info.layerCount = 1;
info.format = static_cast<common::V1_0::PixelFormat>(mReadbackPixelFormat);
// BufferUsage::COMPOSER_OUTPUT is missing
info.usage = static_cast<uint64_t>(BufferUsage::COMPOSER_OVERLAY | BufferUsage::CPU_READ_OFTEN);
uint64_t usage =
static_cast<uint64_t>(BufferUsage::COMPOSER_OVERLAY | BufferUsage::CPU_READ_OFTEN);
std::unique_ptr<Gralloc> gralloc;
const native_handle_t* buffer;
ASSERT_NO_FATAL_FAILURE(gralloc = std::make_unique<Gralloc>());
ASSERT_NO_FATAL_FAILURE(buffer = gralloc->allocate(info));
ASSERT_NO_FATAL_FAILURE(buffer = gralloc->allocate(mDisplayWidth, mDisplayHeight, 1,
mReadbackPixelFormat, usage));
mComposerClient->setReadbackBuffer(mPrimaryDisplay, buffer, -1);
}
@ -483,17 +474,14 @@ TEST_F(GraphicsComposerHidlTest, SetReadbackBufferBadDisplay) {
return;
}
IMapper::BufferDescriptorInfo info{};
info.width = mDisplayWidth;
info.height = mDisplayHeight;
info.layerCount = 1;
info.format = static_cast<common::V1_0::PixelFormat>(mReadbackPixelFormat);
info.usage = static_cast<uint64_t>(BufferUsage::COMPOSER_OVERLAY | BufferUsage::CPU_READ_OFTEN);
uint64_t usage =
static_cast<uint64_t>(BufferUsage::COMPOSER_OVERLAY | BufferUsage::CPU_READ_OFTEN);
std::unique_ptr<Gralloc> gralloc;
const native_handle_t* buffer;
ASSERT_NO_FATAL_FAILURE(gralloc = std::make_unique<Gralloc>());
ASSERT_NO_FATAL_FAILURE(buffer = gralloc->allocate(info));
ASSERT_NO_FATAL_FAILURE(buffer = gralloc->allocate(mDisplayWidth, mDisplayHeight, 1,
mReadbackPixelFormat, usage));
Error error = mComposerClient->getRaw()->setReadbackBuffer(mInvalidDisplayId, buffer, nullptr);
ASSERT_EQ(Error::BAD_DISPLAY, error);

View file

@ -27,6 +27,12 @@ cc_library_static {
"android.hardware.graphics.composer@2.2",
"android.hardware.graphics.composer@2.2-vts",
"android.hardware.graphics.composer@2.3",
"android.hardware.graphics.mapper@2.0",
"android.hardware.graphics.mapper@2.0-vts",
"android.hardware.graphics.mapper@2.1",
"android.hardware.graphics.mapper@2.1-vts",
"android.hardware.graphics.mapper@3.0",
"android.hardware.graphics.mapper@3.0-vts",
],
header_libs: [
"android.hardware.graphics.composer@2.1-command-buffer",

View file

@ -28,6 +28,7 @@ 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.composer@2.2",
@ -37,6 +38,9 @@ cc_test {
"android.hardware.graphics.mapper@2.0",
"android.hardware.graphics.mapper@2.0-vts",
"android.hardware.graphics.mapper@2.1",
"android.hardware.graphics.mapper@2.1-vts",
"android.hardware.graphics.mapper@3.0",
"android.hardware.graphics.mapper@3.0-vts",
],
header_libs: [
"android.hardware.graphics.composer@2.1-command-buffer",

View file

@ -41,7 +41,7 @@ using common::V1_2::ColorMode;
using common::V1_2::Dataspace;
using common::V1_2::PixelFormat;
using mapper::V2_0::IMapper;
using mapper::V2_0::vts::Gralloc;
using V2_2::vts::Gralloc;
// Test environment for graphics.composer
class GraphicsComposerHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
@ -156,15 +156,9 @@ class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest {
}
const native_handle_t* allocate() {
IMapper::BufferDescriptorInfo info{};
info.width = 64;
info.height = 64;
info.layerCount = 1;
info.format = static_cast<common::V1_0::PixelFormat>(PixelFormat::RGBA_8888);
info.usage =
static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN | BufferUsage::CPU_READ_OFTEN);
return mGralloc->allocate(info);
return mGralloc->allocate(
64, 64, 1, static_cast<common::V1_1::PixelFormat>(PixelFormat::RGBA_8888),
static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN | BufferUsage::CPU_READ_OFTEN));
}
void execute() { mComposerClient->execute(mReader.get(), mWriter.get()); }

View file

@ -43,24 +43,25 @@ static_assert(sizeof(OldBufferDescriptorInfo) == sizeof(IMapper::BufferDescripto
offsetof(IMapper::BufferDescriptorInfo, usage),
"");
Gralloc::Gralloc() : V2_0::vts::Gralloc() {
Gralloc::Gralloc(bool errOnFailure) : V2_0::vts::Gralloc() {
if (::testing::Test::HasFatalFailure()) {
return;
}
init();
init(errOnFailure);
}
Gralloc::Gralloc(const std::string& allocatorServiceName, const std::string& mapperServiceName)
Gralloc::Gralloc(const std::string& allocatorServiceName, const std::string& mapperServiceName,
bool errOnFailure)
: V2_0::vts::Gralloc(allocatorServiceName, mapperServiceName) {
if (::testing::Test::HasFatalFailure()) {
return;
}
init();
init(errOnFailure);
}
void Gralloc::init() {
void Gralloc::init(bool errOnFailure) {
mMapperV2_1 = IMapper::castFrom(V2_0::vts::Gralloc::getMapper());
ASSERT_NE(nullptr, mMapperV2_1.get()) << "failed to get mapper 2.1 service";
if (errOnFailure) ASSERT_NE(nullptr, mMapperV2_1.get()) << "failed to get mapper 2.1 service";
}
sp<IMapper> Gralloc::getMapper() const {

View file

@ -32,8 +32,9 @@ using V2_0::BufferDescriptor;
// A wrapper to IAllocator and IMapper.
class Gralloc : public V2_0::vts::Gralloc {
public:
Gralloc();
Gralloc(const std::string& allocatorServiceName, const std::string& mapperServiceName);
Gralloc(bool errOnFailure = true);
Gralloc(const std::string& allocatorServiceName, const std::string& mapperServiceName,
bool errOnFailure = true);
sp<IMapper> getMapper() const;
@ -48,7 +49,7 @@ class Gralloc : public V2_0::vts::Gralloc {
bool import = true, uint32_t* outStride = nullptr);
protected:
void init();
void init(bool errOnFailure = true);
sp<IMapper> mMapperV2_1;
};

View file

@ -25,8 +25,13 @@ namespace mapper {
namespace V3_0 {
namespace vts {
Gralloc::Gralloc(const std::string& allocatorServiceName, const std::string& mapperServiceName) {
Gralloc::Gralloc(const std::string& allocatorServiceName, const std::string& mapperServiceName,
bool errOnFailure) {
if (errOnFailure) {
init(allocatorServiceName, mapperServiceName);
} else {
initNoErr(allocatorServiceName, mapperServiceName);
}
}
void Gralloc::init(const std::string& allocatorServiceName, const std::string& mapperServiceName) {
@ -38,6 +43,16 @@ void Gralloc::init(const std::string& allocatorServiceName, const std::string& m
ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode";
}
void Gralloc::initNoErr(const std::string& allocatorServiceName,
const std::string& mapperServiceName) {
mAllocator = ::testing::VtsHalHidlTargetTestBase::getService<IAllocator>(allocatorServiceName);
mMapper = ::testing::VtsHalHidlTargetTestBase::getService<IMapper>(mapperServiceName);
if (mMapper.get()) {
ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode";
}
}
Gralloc::~Gralloc() {
for (auto bufferHandle : mClonedBuffers) {
auto buffer = const_cast<native_handle_t*>(bufferHandle);

View file

@ -37,7 +37,7 @@ using android::hardware::graphics::allocator::V3_0::IAllocator;
class Gralloc {
public:
Gralloc(const std::string& allocatorServiceName = "default",
const std::string& mapperServiceName = "default");
const std::string& mapperServiceName = "default", bool errOnFailure = true);
~Gralloc();
// IAllocator methods
@ -50,8 +50,9 @@ class Gralloc {
// is true, the returned buffers are also imported into the mapper.
//
// Either case, the returned buffers must be freed with freeBuffer.
std::vector<const native_handle_t*> allocate(const BufferDescriptor& descriptor, uint32_t count,
bool import = true, uint32_t* outStride = nullptr);
std::vector<const native_handle_t*> allocate(const BufferDescriptor& descriptor,
uint32_t count, bool import = true,
uint32_t* outStride = nullptr);
const native_handle_t* allocate(const IMapper::BufferDescriptorInfo& descriptorInfo,
bool import = true, uint32_t* outStride = nullptr);
@ -83,6 +84,9 @@ class Gralloc {
private:
void init(const std::string& allocatorServiceName, const std::string& mapperServiceName);
// initialize without checking for failure to get service
void initNoErr(const std::string& allocatorServiceName, const std::string& mapperServiceName);
const native_handle_t* cloneBuffer(const hidl_handle& rawHandle);
sp<IAllocator> mAllocator;