cros_gralloc: add support for mt8186
Add build changes for mt8186. Add ARM metadata types: compression, plane fds and data type. Add mediatek_drm.h which is not available. Bug: 388092228 Test: boot corsola with minigbm gralloc/mapper Change-Id: I1f1e8a57f37e26694320c3ddee01fbad453f854b
This commit is contained in:
parent
a733122a10
commit
a1e715acd8
10 changed files with 322 additions and 7 deletions
69
cros_gralloc/cros_gralloc_arm.h
Normal file
69
cros_gralloc/cros_gralloc_arm.h
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#ifndef CROS_GRALLOC_ARM_H
|
||||
#define CROS_GRALLOC_ARM_H
|
||||
|
||||
#include "../drv.h"
|
||||
#include "aidl/android/hardware/graphics/common/ExtendableType.h"
|
||||
|
||||
using aidl::android::hardware::graphics::common::ExtendableType;
|
||||
|
||||
/* from AIDL interface */
|
||||
typedef enum {
|
||||
INVALID = 0,
|
||||
PLANE_FDS = 1,
|
||||
FORMAT_DATA_TYPE = 2,
|
||||
} ArmMetadataType;
|
||||
|
||||
typedef enum {
|
||||
UNORM = 0,
|
||||
SNORM = 1,
|
||||
UINT = 2,
|
||||
SINT = 3,
|
||||
SFLOAT = 4,
|
||||
UNKNOWN = 0xFF,
|
||||
} ArmDataType;
|
||||
|
||||
typedef enum {
|
||||
AFBC = 0,
|
||||
AFRC = 1,
|
||||
} ArmCompression;
|
||||
|
||||
#define GRALLOC_ARM_COMPRESSION_TYPE_NAME "arm.graphics.Compression"
|
||||
const static ExtendableType Compression_AFBC{ GRALLOC_ARM_COMPRESSION_TYPE_NAME,
|
||||
static_cast<int64_t>(ArmCompression::AFBC) };
|
||||
|
||||
const static ExtendableType Compression_AFRC{ GRALLOC_ARM_COMPRESSION_TYPE_NAME,
|
||||
static_cast<int64_t>(ArmCompression::AFRC) };
|
||||
|
||||
#define GRALLOC_ARM_METADATA_TYPE_NAME "arm.graphics.ArmMetadataType"
|
||||
|
||||
#define GRALLOC_ARM_FORMAT_DATA_TYPE_NAME "arm.graphics.DataType"
|
||||
|
||||
static ArmDataType DataTypeFromDrmPixelFormat(uint32_t pf)
|
||||
{
|
||||
switch (pf) {
|
||||
case DRM_FORMAT_R8:
|
||||
case DRM_FORMAT_GR88:
|
||||
case DRM_FORMAT_RGB565:
|
||||
case DRM_FORMAT_XRGB8888:
|
||||
case DRM_FORMAT_ARGB8888:
|
||||
case DRM_FORMAT_XBGR8888:
|
||||
case DRM_FORMAT_ABGR8888:
|
||||
case DRM_FORMAT_XRGB2101010:
|
||||
case DRM_FORMAT_XBGR2101010:
|
||||
case DRM_FORMAT_ARGB2101010:
|
||||
case DRM_FORMAT_ABGR2101010:
|
||||
case DRM_FORMAT_NV12:
|
||||
case DRM_FORMAT_NV21:
|
||||
case DRM_FORMAT_YUYV:
|
||||
case DRM_FORMAT_YVU420:
|
||||
case DRM_FORMAT_YVU420_ANDROID:
|
||||
case DRM_FORMAT_P010:
|
||||
return ArmDataType::UNORM;
|
||||
case DRM_FORMAT_ABGR16161616F:
|
||||
return ArmDataType::SFLOAT;
|
||||
default:
|
||||
return ArmDataType::UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CROS_GRALLOC_ARM_H
|
||||
|
|
@ -142,6 +142,14 @@ uint32_t cros_gralloc_buffer::get_plane_size(uint32_t plane) const
|
|||
return hnd_->sizes[plane];
|
||||
}
|
||||
|
||||
int64_t cros_gralloc_buffer::get_plane_fd(uint32_t plane) const
|
||||
{
|
||||
if (plane >= hnd_->num_planes) {
|
||||
return -1;
|
||||
}
|
||||
return hnd_->fds[plane];
|
||||
}
|
||||
|
||||
int32_t cros_gralloc_buffer::get_android_format() const
|
||||
{
|
||||
return hnd_->droid_format;
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ class cros_gralloc_buffer
|
|||
uint32_t get_plane_offset(uint32_t plane) const;
|
||||
uint32_t get_plane_stride(uint32_t plane) const;
|
||||
uint32_t get_plane_size(uint32_t plane) const;
|
||||
int64_t get_plane_fd(uint32_t plane) const;
|
||||
int32_t get_android_format() const;
|
||||
int64_t get_android_usage() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -126,6 +126,14 @@ cc_binary {
|
|||
},
|
||||
}
|
||||
|
||||
cc_binary {
|
||||
name: "android.hardware.graphics.allocator@4.0-service.minigbm_mediatek",
|
||||
defaults: ["minigbm_gralloc4_allocator_defaults"],
|
||||
shared_libs: ["libminigbm_gralloc_mediatek"],
|
||||
vintf_fragment_modules: ["android.hardware.graphics.allocator@4.0.xml"],
|
||||
init_rc: ["android.hardware.graphics.allocator@4.0-service.minigbm_mediatek.rc"],
|
||||
}
|
||||
|
||||
vintf_fragment {
|
||||
name: "android.hardware.graphics.mapper@4.0.xml",
|
||||
src: "android.hardware.graphics.mapper@4.0.xml",
|
||||
|
|
@ -172,3 +180,11 @@ cc_library_shared {
|
|||
},
|
||||
},
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "android.hardware.graphics.mapper@4.0-impl.minigbm_mediatek",
|
||||
defaults: ["minigbm_gralloc4_common_defaults"],
|
||||
shared_libs: ["libminigbm_gralloc_mediatek"],
|
||||
vintf_fragment_modules: ["android.hardware.graphics.mapper@4.0.xml"],
|
||||
srcs: [":minigbm_gralloc4_mapper_files"],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include <cutils/native_handle.h>
|
||||
#include <gralloctypes/Gralloc4.h>
|
||||
|
||||
#include "cros_gralloc/cros_gralloc_arm.h"
|
||||
#include "cros_gralloc/cros_gralloc_helpers.h"
|
||||
#include "cros_gralloc/gralloc4/CrosGralloc4Utils.h"
|
||||
|
||||
|
|
@ -34,6 +35,11 @@ using android::hardware::graphics::common::V1_2::PixelFormat;
|
|||
using android::hardware::graphics::mapper::V4_0::Error;
|
||||
using android::hardware::graphics::mapper::V4_0::IMapper;
|
||||
|
||||
const static IMapper::MetadataType kArmMetadataTypePlaneFds{
|
||||
GRALLOC_ARM_METADATA_TYPE_NAME, static_cast<int64_t>(ArmMetadataType::PLANE_FDS)};
|
||||
const static IMapper::MetadataType kArmMetadataTypeFormatDataType{
|
||||
GRALLOC_ARM_METADATA_TYPE_NAME, static_cast<int64_t>(ArmMetadataType::FORMAT_DATA_TYPE)};
|
||||
|
||||
Return<void> CrosGralloc4Mapper::createDescriptor(const BufferDescriptorInfo& description,
|
||||
createDescriptor_cb hidlCb) {
|
||||
hidl_vec<uint8_t> descriptor;
|
||||
|
|
@ -480,8 +486,18 @@ Return<void> CrosGralloc4Mapper::get(const cros_gralloc_buffer* crosBuffer,
|
|||
crosBuffer->get_android_usage() & BufferUsage::PROTECTED ? 1 : 0;
|
||||
status = android::gralloc4::encodeProtectedContent(hasProtectedContent, &encodedMetadata);
|
||||
} else if (metadataType == android::gralloc4::MetadataType_Compression) {
|
||||
status = android::gralloc4::encodeCompression(android::gralloc4::Compression_None,
|
||||
&encodedMetadata);
|
||||
ExtendableType compression = android::gralloc4::Compression_None;
|
||||
uint64_t modifier = crosBuffer->get_format_modifier();
|
||||
|
||||
if (fourcc_mod_is_vendor(modifier, ARM)) {
|
||||
if (((modifier >> 52) & 0xF) == DRM_FORMAT_MOD_ARM_TYPE_AFBC) {
|
||||
compression = Compression_AFBC;
|
||||
} else if (((modifier >> 52) & 0xF) == DRM_FORMAT_MOD_ARM_TYPE_AFRC) {
|
||||
compression = Compression_AFRC;
|
||||
}
|
||||
}
|
||||
|
||||
status = android::gralloc4::encodeCompression(compression, &encodedMetadata);
|
||||
} else if (metadataType == android::gralloc4::MetadataType_Interlaced) {
|
||||
status = android::gralloc4::encodeInterlaced(android::gralloc4::Interlaced_None,
|
||||
&encodedMetadata);
|
||||
|
|
@ -557,6 +573,20 @@ Return<void> CrosGralloc4Mapper::get(const cros_gralloc_buffer* crosBuffer,
|
|||
}
|
||||
} else if (metadataType == android::gralloc4::MetadataType_Smpte2094_40) {
|
||||
status = android::gralloc4::encodeSmpte2094_40(std::nullopt, &encodedMetadata);
|
||||
} else if (metadataType == kArmMetadataTypePlaneFds) {
|
||||
uint32_t num_planes = crosBuffer->get_num_planes();
|
||||
int64_t plane_fds[5];
|
||||
plane_fds[0] = num_planes;
|
||||
for (auto plane = 0; plane < num_planes; plane++) {
|
||||
plane_fds[1 + plane] = crosBuffer->get_plane_fd(plane);
|
||||
}
|
||||
encodedMetadata.resize(sizeof(uint64_t) * (1 + num_planes));
|
||||
memcpy(encodedMetadata.data(), plane_fds, encodedMetadata.size());
|
||||
} else if (metadataType == kArmMetadataTypeFormatDataType) {
|
||||
uint32_t pf = crosBuffer->get_format();
|
||||
int64_t fdt = static_cast<int64_t>(DataTypeFromDrmPixelFormat(pf));
|
||||
encodedMetadata.resize(sizeof(fdt));
|
||||
memcpy(encodedMetadata.data(), &fdt, encodedMetadata.size());
|
||||
} else {
|
||||
hidlCb(Error::UNSUPPORTED, encodedMetadata);
|
||||
return Void();
|
||||
|
|
@ -940,6 +970,18 @@ Return<void> CrosGralloc4Mapper::listSupportedMetadataTypes(listSupportedMetadat
|
|||
/*isGettable=*/true,
|
||||
/*isSettable=*/false,
|
||||
},
|
||||
{
|
||||
kArmMetadataTypePlaneFds,
|
||||
"Vector of file descriptors of each plane",
|
||||
/*isGettable=*/true,
|
||||
/*isSettable=*/false,
|
||||
},
|
||||
{
|
||||
kArmMetadataTypeFormatDataType,
|
||||
"Format data type",
|
||||
/*isGettable=*/true,
|
||||
/*isSettable=*/false,
|
||||
},
|
||||
});
|
||||
|
||||
hidlCb(Error::NONE, supported);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# Copyright 2025 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
service vendor.graphics.allocator-4-0 /vendor/bin/hw/android.hardware.graphics.allocator@4.0-service.minigbm_mediatek
|
||||
interface android.hardware.graphics.allocator@4.0::IAllocator default
|
||||
class hal animation
|
||||
user system
|
||||
group graphics drmrpc
|
||||
capabilities SYS_NICE
|
||||
onrestart restart surfaceflinger
|
||||
task_profiles ServiceCapacityLow
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
#include "cros_gralloc/cros_gralloc_arm.h"
|
||||
#include "cros_gralloc/cros_gralloc_driver.h"
|
||||
#include "cros_gralloc/cros_gralloc_handle.h"
|
||||
#include "cros_gralloc/gralloc4/CrosGralloc4Utils.h"
|
||||
|
|
@ -49,10 +50,19 @@ static_assert(CROS_GRALLOC_BUFFER_METADATA_MAX_NAME_SIZE >=
|
|||
constexpr const char* STANDARD_METADATA_NAME =
|
||||
"android.hardware.graphics.common.StandardMetadataType";
|
||||
|
||||
constexpr const AIMapper_MetadataType kArmMetadataTypePlaneFds{
|
||||
GRALLOC_ARM_METADATA_TYPE_NAME, static_cast<int64_t>(ArmMetadataType::PLANE_FDS)};
|
||||
constexpr const AIMapper_MetadataType kArmMetadataTypeFormatDataType{
|
||||
GRALLOC_ARM_METADATA_TYPE_NAME, static_cast<int64_t>(ArmMetadataType::FORMAT_DATA_TYPE)};
|
||||
|
||||
static bool isStandardMetadata(AIMapper_MetadataType metadataType) {
|
||||
return strcmp(STANDARD_METADATA_NAME, metadataType.name) == 0;
|
||||
}
|
||||
|
||||
static bool isArmMetadata(AIMapper_MetadataType metadataType) {
|
||||
return strcmp(GRALLOC_ARM_METADATA_TYPE_NAME, metadataType.name) == 0;
|
||||
}
|
||||
|
||||
class CrosGrallocMapperV5 final : public vendor::mapper::IMapperV5Impl {
|
||||
private:
|
||||
std::shared_ptr<cros_gralloc_driver> mDriver = cros_gralloc_driver::get_instance();
|
||||
|
|
@ -119,6 +129,9 @@ class CrosGrallocMapperV5 final : public vendor::mapper::IMapperV5Impl {
|
|||
void dumpBuffer(
|
||||
const cros_gralloc_buffer* crosBuffer,
|
||||
std::function<void(AIMapper_MetadataType, const std::vector<uint8_t>&)> callback);
|
||||
|
||||
int32_t getArmMetadata(buffer_handle_t _Nonnull buffer, int64_t armMetadataType,
|
||||
void* _Nonnull outData, size_t outDataSize);
|
||||
};
|
||||
|
||||
AIMapper_Error CrosGrallocMapperV5::importBuffer(
|
||||
|
|
@ -268,14 +281,67 @@ AIMapper_Error CrosGrallocMapperV5::rereadLockedBuffer(buffer_handle_t _Nonnull
|
|||
int32_t CrosGrallocMapperV5::getMetadata(buffer_handle_t _Nonnull buffer,
|
||||
AIMapper_MetadataType metadataType, void* _Nonnull outData,
|
||||
size_t outDataSize) {
|
||||
// We don't have any vendor-specific metadata, so divert to getStandardMetadata after validating
|
||||
// that this is a standard metadata request
|
||||
if (isStandardMetadata(metadataType)) {
|
||||
return getStandardMetadata(buffer, metadataType.value, outData, outDataSize);
|
||||
}
|
||||
|
||||
if (isArmMetadata(metadataType)) {
|
||||
return getArmMetadata(buffer, metadataType.value, outData, outDataSize);
|
||||
}
|
||||
return -AIMAPPER_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int32_t CrosGrallocMapperV5::getArmMetadata(buffer_handle_t _Nonnull buffer,
|
||||
int64_t armMetadataType, void* _Nonnull outData,
|
||||
size_t outDataSize) {
|
||||
cros_gralloc_handle_t crosHandle = cros_gralloc_convert_handle(buffer);
|
||||
if (!crosHandle) {
|
||||
ALOGE("Failed to get. Invalid handle.");
|
||||
return -AIMAPPER_ERROR_BAD_BUFFER;
|
||||
}
|
||||
int32_t retValue = -AIMAPPER_ERROR_UNSUPPORTED;
|
||||
switch (armMetadataType) {
|
||||
case ArmMetadataType::PLANE_FDS: {
|
||||
mDriver->with_buffer(crosHandle, [&](cros_gralloc_buffer* crosBuffer) {
|
||||
uint32_t num_planes = crosBuffer->get_num_planes();
|
||||
|
||||
if (outDataSize < sizeof(int64_t) * (1 + num_planes)) {
|
||||
retValue = sizeof(int64_t) * (1 + num_planes);
|
||||
} else {
|
||||
int64_t plane_fds[DRV_MAX_PLANES + 1];
|
||||
|
||||
plane_fds[0] = num_planes;
|
||||
for (auto plane = 0; plane < num_planes; plane++) {
|
||||
plane_fds[1 + plane] = crosBuffer->get_plane_fd(plane);
|
||||
}
|
||||
|
||||
memcpy(outData, plane_fds, sizeof(uint64_t) * (1 + num_planes));
|
||||
|
||||
retValue = -AIMAPPER_ERROR_NONE;
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
case ArmMetadataType::FORMAT_DATA_TYPE: {
|
||||
mDriver->with_buffer(crosHandle, [&](cros_gralloc_buffer* crosBuffer) {
|
||||
uint32_t pf = crosBuffer->get_format();
|
||||
int64_t fdt = static_cast<int64_t>(DataTypeFromDrmPixelFormat(pf));
|
||||
|
||||
if (outDataSize < sizeof(fdt)) {
|
||||
retValue = sizeof(fdt);
|
||||
} else {
|
||||
memcpy(outData, &fdt, sizeof(fdt));
|
||||
retValue = -AIMAPPER_ERROR_NONE;
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return -AIMAPPER_ERROR_UNSUPPORTED;
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
|
||||
int32_t CrosGrallocMapperV5::getStandardMetadata(buffer_handle_t _Nonnull bufferHandle,
|
||||
int64_t standardType, void* _Nonnull outData,
|
||||
size_t outDataSize) {
|
||||
|
|
@ -355,7 +421,18 @@ int32_t CrosGrallocMapperV5::getStandardMetadata(const cros_gralloc_buffer* cros
|
|||
return provide(hasProtectedContent);
|
||||
}
|
||||
if constexpr (metadataType == StandardMetadataType::COMPRESSION) {
|
||||
return provide(android::gralloc4::Compression_None);
|
||||
ExtendableType compression = android::gralloc4::Compression_None;
|
||||
uint64_t modifier = crosBuffer->get_format_modifier();
|
||||
|
||||
if (fourcc_mod_is_vendor(modifier, ARM)) {
|
||||
if (((modifier >> 52) & 0xF) == DRM_FORMAT_MOD_ARM_TYPE_AFBC) {
|
||||
compression = Compression_AFBC;
|
||||
} else if (((modifier >> 52) & 0xF) == DRM_FORMAT_MOD_ARM_TYPE_AFRC) {
|
||||
compression = Compression_AFRC;
|
||||
}
|
||||
}
|
||||
|
||||
return provide(compression);
|
||||
}
|
||||
if constexpr (metadataType == StandardMetadataType::INTERLACED) {
|
||||
return provide(android::gralloc4::Interlaced_None);
|
||||
|
|
@ -528,7 +605,7 @@ constexpr AIMapper_MetadataTypeDescription describeStandard(StandardMetadataType
|
|||
AIMapper_Error CrosGrallocMapperV5::listSupportedMetadataTypes(
|
||||
const AIMapper_MetadataTypeDescription* _Nullable* _Nonnull outDescriptionList,
|
||||
size_t* _Nonnull outNumberOfDescriptions) {
|
||||
static constexpr std::array<AIMapper_MetadataTypeDescription, 22> sSupportedMetadaTypes{
|
||||
static constexpr std::array<AIMapper_MetadataTypeDescription, 24> sSupportedMetadaTypes{
|
||||
describeStandard(StandardMetadataType::BUFFER_ID, true, false),
|
||||
describeStandard(StandardMetadataType::NAME, true, false),
|
||||
describeStandard(StandardMetadataType::WIDTH, true, false),
|
||||
|
|
@ -551,6 +628,8 @@ AIMapper_Error CrosGrallocMapperV5::listSupportedMetadataTypes(
|
|||
describeStandard(StandardMetadataType::SMPTE2086, true, true),
|
||||
describeStandard(StandardMetadataType::CTA861_3, true, true),
|
||||
describeStandard(StandardMetadataType::STRIDE, true, false),
|
||||
{kArmMetadataTypePlaneFds, "Vector of file descriptors of each plane", true, false, {0}},
|
||||
{kArmMetadataTypeFormatDataType, "Format data type", true, false, {0}},
|
||||
};
|
||||
*outDescriptionList = sSupportedMetadaTypes.data();
|
||||
*outNumberOfDescriptions = sSupportedMetadaTypes.size();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue