minigbm: Adds Gralloc 4 support
Implements the Allocator 4.0 and Mapper 4.0 interfaces. Some notable features of the 4.0 interface: - buffer metadata getter/setters - buffer flushing - buffer debugging (buffer listing and buffer id) BUG=b:161909468 TEST=build and launch Cuttlefish with Gralloc4 Change-Id: I63bdc76604207e1fcfe0135c9b64fa62bfba5b27 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2404601 Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: Jason Macnak <natsu@google.com> Commit-Queue: Jason Macnak <natsu@google.com>
This commit is contained in:
parent
310cf97a92
commit
2a77d942ae
9 changed files with 2123 additions and 0 deletions
19
cros_gralloc/gralloc4/.clang-format
Normal file
19
cros_gralloc/gralloc4/.clang-format
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# Copyright 2020 The Chromium OS Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
#
|
||||
# This directory is formatted to match the format of the interfaces implemented.
|
||||
|
||||
BasedOnStyle: Google
|
||||
Standard: Cpp11
|
||||
AccessModifierOffset: -2
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
ColumnLimit: 100
|
||||
CommentPragmas: NOLINT:.*
|
||||
DerivePointerAlignment: false
|
||||
IncludeBlocks: Preserve
|
||||
IndentWidth: 4
|
||||
ContinuationIndentWidth: 8
|
||||
PointerAlignment: Left
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
122
cros_gralloc/gralloc4/CrosGralloc4Allocator.cc
Normal file
122
cros_gralloc/gralloc4/CrosGralloc4Allocator.cc
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Copyright 2020 The Chromium OS Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "cros_gralloc/gralloc4/CrosGralloc4Allocator.h"
|
||||
|
||||
#include <android/hardware/graphics/mapper/4.0/IMapper.h>
|
||||
#include <gralloctypes/Gralloc4.h>
|
||||
|
||||
#include "cros_gralloc/cros_gralloc_helpers.h"
|
||||
#include "cros_gralloc/gralloc4/CrosGralloc4Utils.h"
|
||||
|
||||
using android::hardware::hidl_handle;
|
||||
using android::hardware::hidl_vec;
|
||||
using android::hardware::Return;
|
||||
using android::hardware::Void;
|
||||
using android::hardware::graphics::common::V1_2::BufferUsage;
|
||||
using android::hardware::graphics::common::V1_2::PixelFormat;
|
||||
using android::hardware::graphics::mapper::V4_0::Error;
|
||||
|
||||
using BufferDescriptorInfo =
|
||||
android::hardware::graphics::mapper::V4_0::IMapper::BufferDescriptorInfo;
|
||||
|
||||
CrosGralloc4Allocator::CrosGralloc4Allocator() : mDriver(std::make_unique<cros_gralloc_driver>()) {
|
||||
if (mDriver->init()) {
|
||||
drv_log("Failed to initialize driver.\n");
|
||||
mDriver = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Error CrosGralloc4Allocator::allocate(const BufferDescriptorInfo& descriptor, uint32_t* outStride,
|
||||
hidl_handle* outHandle) {
|
||||
if (!mDriver) {
|
||||
drv_log("Failed to allocate. Driver is uninitialized.\n");
|
||||
return Error::NO_RESOURCES;
|
||||
}
|
||||
|
||||
if (!outStride || !outHandle) {
|
||||
return Error::NO_RESOURCES;
|
||||
}
|
||||
|
||||
struct cros_gralloc_buffer_descriptor crosDescriptor;
|
||||
if (convertToCrosDescriptor(descriptor, &crosDescriptor)) {
|
||||
return Error::UNSUPPORTED;
|
||||
}
|
||||
|
||||
bool supported = mDriver->is_supported(&crosDescriptor);
|
||||
if (!supported && (descriptor.usage & BufferUsage::COMPOSER_OVERLAY)) {
|
||||
crosDescriptor.use_flags &= ~BO_USE_SCANOUT;
|
||||
supported = mDriver->is_supported(&crosDescriptor);
|
||||
}
|
||||
|
||||
if (!supported) {
|
||||
std::string drmFormatString = getDrmFormatString(crosDescriptor.drm_format);
|
||||
std::string pixelFormatString = getPixelFormatString(descriptor.format);
|
||||
std::string usageString = getUsageString(descriptor.usage);
|
||||
drv_log("Unsupported combination -- pixel format: %s, drm format:%s, usage: %s\n",
|
||||
pixelFormatString.c_str(), drmFormatString.c_str(), usageString.c_str());
|
||||
return Error::UNSUPPORTED;
|
||||
}
|
||||
|
||||
buffer_handle_t handle;
|
||||
int ret = mDriver->allocate(&crosDescriptor, &handle);
|
||||
if (ret) {
|
||||
return Error::NO_RESOURCES;
|
||||
}
|
||||
|
||||
cros_gralloc_handle_t crosHandle = cros_gralloc_convert_handle(handle);
|
||||
if (!crosHandle) {
|
||||
return Error::NO_RESOURCES;
|
||||
}
|
||||
|
||||
*outHandle = handle;
|
||||
*outStride = crosHandle->pixel_stride;
|
||||
|
||||
return Error::NONE;
|
||||
}
|
||||
|
||||
Return<void> CrosGralloc4Allocator::allocate(const hidl_vec<uint8_t>& descriptor, uint32_t count,
|
||||
allocate_cb hidlCb) {
|
||||
hidl_vec<hidl_handle> handles;
|
||||
|
||||
if (!mDriver) {
|
||||
drv_log("Failed to allocate. Driver is uninitialized.\n");
|
||||
hidlCb(Error::NO_RESOURCES, 0, handles);
|
||||
return Void();
|
||||
}
|
||||
|
||||
BufferDescriptorInfo description;
|
||||
|
||||
int ret = android::gralloc4::decodeBufferDescriptorInfo(descriptor, &description);
|
||||
if (ret) {
|
||||
drv_log("Failed to allocate. Failed to decode buffer descriptor: %d.\n", ret);
|
||||
hidlCb(Error::BAD_DESCRIPTOR, 0, handles);
|
||||
return Void();
|
||||
}
|
||||
|
||||
handles.resize(count);
|
||||
|
||||
uint32_t stride = 0;
|
||||
for (int i = 0; i < handles.size(); i++) {
|
||||
Error err = allocate(description, &stride, &(handles[i]));
|
||||
if (err != Error::NONE) {
|
||||
for (int j = 0; j < i; j++) {
|
||||
mDriver->release(handles[j].getNativeHandle());
|
||||
}
|
||||
handles.resize(0);
|
||||
hidlCb(err, 0, handles);
|
||||
return Void();
|
||||
}
|
||||
}
|
||||
|
||||
hidlCb(Error::NONE, stride, handles);
|
||||
|
||||
for (const hidl_handle& handle : handles) {
|
||||
mDriver->release(handle.getNativeHandle());
|
||||
}
|
||||
|
||||
return Void();
|
||||
}
|
||||
26
cros_gralloc/gralloc4/CrosGralloc4Allocator.h
Normal file
26
cros_gralloc/gralloc4/CrosGralloc4Allocator.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright 2020 The Chromium OS Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include <android/hardware/graphics/allocator/4.0/IAllocator.h>
|
||||
#include <android/hardware/graphics/mapper/4.0/IMapper.h>
|
||||
|
||||
#include "cros_gralloc/cros_gralloc_driver.h"
|
||||
|
||||
class CrosGralloc4Allocator : public android::hardware::graphics::allocator::V4_0::IAllocator {
|
||||
public:
|
||||
CrosGralloc4Allocator();
|
||||
|
||||
android::hardware::Return<void> allocate(const android::hardware::hidl_vec<uint8_t>& descriptor,
|
||||
uint32_t count, allocate_cb hidl_cb) override;
|
||||
|
||||
private:
|
||||
android::hardware::graphics::mapper::V4_0::Error allocate(
|
||||
const android::hardware::graphics::mapper::V4_0::IMapper::BufferDescriptorInfo&
|
||||
description,
|
||||
uint32_t* outStride, android::hardware::hidl_handle* outHandle);
|
||||
|
||||
std::unique_ptr<cros_gralloc_driver> mDriver;
|
||||
};
|
||||
30
cros_gralloc/gralloc4/CrosGralloc4AllocatorService.cc
Normal file
30
cros_gralloc/gralloc4/CrosGralloc4AllocatorService.cc
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright 2020 The Chromium OS Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "AllocatorService"
|
||||
|
||||
#include <hidl/LegacySupport.h>
|
||||
|
||||
#include "cros_gralloc/gralloc4/CrosGralloc4Allocator.h"
|
||||
|
||||
using android::sp;
|
||||
using android::hardware::configureRpcThreadpool;
|
||||
using android::hardware::joinRpcThreadpool;
|
||||
using android::hardware::graphics::allocator::V4_0::IAllocator;
|
||||
|
||||
int main(int, char**) {
|
||||
sp<IAllocator> allocator = new CrosGralloc4Allocator();
|
||||
configureRpcThreadpool(4, true /* callerWillJoin */);
|
||||
if (allocator->registerAsService() != android::NO_ERROR) {
|
||||
ALOGE("failed to register graphics IAllocator 4.0 service");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ALOGI("graphics IAllocator 4.0 service is initialized");
|
||||
android::hardware::joinRpcThreadpool();
|
||||
ALOGI("graphics IAllocator 4.0 service is terminating");
|
||||
return 0;
|
||||
}
|
||||
1009
cros_gralloc/gralloc4/CrosGralloc4Mapper.cc
Normal file
1009
cros_gralloc/gralloc4/CrosGralloc4Mapper.cc
Normal file
File diff suppressed because it is too large
Load diff
80
cros_gralloc/gralloc4/CrosGralloc4Mapper.h
Normal file
80
cros_gralloc/gralloc4/CrosGralloc4Mapper.h
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright 2020 The Chromium OS Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include <android/hardware/graphics/mapper/4.0/IMapper.h>
|
||||
|
||||
#include "cros_gralloc/cros_gralloc_driver.h"
|
||||
#include "cros_gralloc/cros_gralloc_handle.h"
|
||||
|
||||
class CrosGralloc4Mapper : public android::hardware::graphics::mapper::V4_0::IMapper {
|
||||
public:
|
||||
CrosGralloc4Mapper();
|
||||
|
||||
android::hardware::Return<void> createDescriptor(const BufferDescriptorInfo& description,
|
||||
createDescriptor_cb hidlCb) override;
|
||||
|
||||
android::hardware::Return<void> importBuffer(const android::hardware::hidl_handle& rawHandle,
|
||||
importBuffer_cb hidlCb) override;
|
||||
|
||||
android::hardware::Return<android::hardware::graphics::mapper::V4_0::Error> freeBuffer(
|
||||
void* rawHandle) override;
|
||||
|
||||
android::hardware::Return<android::hardware::graphics::mapper::V4_0::Error> validateBufferSize(
|
||||
void* rawHandle, const BufferDescriptorInfo& descriptor, uint32_t stride) override;
|
||||
|
||||
android::hardware::Return<void> getTransportSize(void* rawHandle,
|
||||
getTransportSize_cb hidlCb) override;
|
||||
|
||||
android::hardware::Return<void> lock(void* rawHandle, uint64_t cpuUsage,
|
||||
const Rect& accessRegion,
|
||||
const android::hardware::hidl_handle& acquireFence,
|
||||
lock_cb hidlCb) override;
|
||||
|
||||
android::hardware::Return<void> unlock(void* rawHandle, unlock_cb hidlCb) override;
|
||||
|
||||
android::hardware::Return<void> flushLockedBuffer(void* rawHandle,
|
||||
flushLockedBuffer_cb hidlCb) override;
|
||||
|
||||
android::hardware::Return<android::hardware::graphics::mapper::V4_0::Error> rereadLockedBuffer(
|
||||
void* rawHandle) override;
|
||||
|
||||
android::hardware::Return<void> isSupported(const BufferDescriptorInfo& descriptor,
|
||||
isSupported_cb hidlCb) override;
|
||||
|
||||
android::hardware::Return<void> get(void* rawHandle, const MetadataType& metadataType,
|
||||
get_cb hidlCb) override;
|
||||
|
||||
android::hardware::Return<android::hardware::graphics::mapper::V4_0::Error> set(
|
||||
void* rawHandle, const MetadataType& metadataType,
|
||||
const android::hardware::hidl_vec<uint8_t>& metadata) override;
|
||||
|
||||
android::hardware::Return<void> getFromBufferDescriptorInfo(
|
||||
const BufferDescriptorInfo& descriptor, const MetadataType& metadataType,
|
||||
getFromBufferDescriptorInfo_cb hidlCb) override;
|
||||
|
||||
android::hardware::Return<void> listSupportedMetadataTypes(
|
||||
listSupportedMetadataTypes_cb hidlCb) override;
|
||||
|
||||
android::hardware::Return<void> dumpBuffer(void* rawHandle, dumpBuffer_cb hidlCb) override;
|
||||
android::hardware::Return<void> dumpBuffers(dumpBuffers_cb hidlCb) override;
|
||||
|
||||
android::hardware::Return<void> getReservedRegion(void* rawHandle,
|
||||
getReservedRegion_cb hidlCb) override;
|
||||
|
||||
private:
|
||||
android::hardware::Return<void> get(cros_gralloc_handle_t crosHandle,
|
||||
const MetadataType& metadataType, get_cb hidlCb);
|
||||
|
||||
android::hardware::Return<void> dumpBuffer(cros_gralloc_handle_t crosHandle,
|
||||
dumpBuffer_cb hidlCb);
|
||||
|
||||
int getResolvedDrmFormat(android::hardware::graphics::common::V1_2::PixelFormat pixelFormat,
|
||||
uint64_t bufferUsage, uint32_t* outDrmFormat);
|
||||
|
||||
std::unique_ptr<cros_gralloc_driver> mDriver;
|
||||
};
|
||||
|
||||
extern "C" android::hardware::graphics::mapper::V4_0::IMapper* HIDL_FETCH_IMapper(const char* name);
|
||||
772
cros_gralloc/gralloc4/CrosGralloc4Utils.cc
Normal file
772
cros_gralloc/gralloc4/CrosGralloc4Utils.cc
Normal file
|
|
@ -0,0 +1,772 @@
|
|||
/*
|
||||
* Copyright 2020 The Chromium OS Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "cros_gralloc/gralloc4/CrosGralloc4Utils.h"
|
||||
|
||||
#include <array>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <aidl/android/hardware/graphics/common/PlaneLayoutComponent.h>
|
||||
#include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h>
|
||||
#include <android-base/stringprintf.h>
|
||||
#include <android-base/strings.h>
|
||||
#include <cutils/native_handle.h>
|
||||
#include <gralloctypes/Gralloc4.h>
|
||||
|
||||
#include "cros_gralloc/cros_gralloc_helpers.h"
|
||||
|
||||
using aidl::android::hardware::graphics::common::PlaneLayout;
|
||||
using aidl::android::hardware::graphics::common::PlaneLayoutComponent;
|
||||
using aidl::android::hardware::graphics::common::PlaneLayoutComponentType;
|
||||
using android::hardware::hidl_bitfield;
|
||||
using android::hardware::hidl_handle;
|
||||
using android::hardware::graphics::common::V1_2::BufferUsage;
|
||||
using android::hardware::graphics::common::V1_2::PixelFormat;
|
||||
|
||||
using BufferDescriptorInfo =
|
||||
android::hardware::graphics::mapper::V4_0::IMapper::BufferDescriptorInfo;
|
||||
|
||||
std::string getDrmFormatString(uint32_t drmFormat) {
|
||||
switch (drmFormat) {
|
||||
case DRM_FORMAT_ABGR1555:
|
||||
return "DRM_FORMAT_ABGR1555";
|
||||
case DRM_FORMAT_ABGR2101010:
|
||||
return "DRM_FORMAT_ABGR2101010";
|
||||
case DRM_FORMAT_ABGR4444:
|
||||
return "DRM_FORMAT_ABGR4444";
|
||||
case DRM_FORMAT_ABGR8888:
|
||||
return "DRM_FORMAT_ABGR8888";
|
||||
case DRM_FORMAT_ARGB1555:
|
||||
return "DRM_FORMAT_ARGB1555";
|
||||
case DRM_FORMAT_ARGB2101010:
|
||||
return "DRM_FORMAT_ARGB2101010";
|
||||
case DRM_FORMAT_ARGB4444:
|
||||
return "DRM_FORMAT_ARGB4444";
|
||||
case DRM_FORMAT_ARGB8888:
|
||||
return "DRM_FORMAT_ARGB8888";
|
||||
case DRM_FORMAT_AYUV:
|
||||
return "DRM_FORMAT_AYUV";
|
||||
case DRM_FORMAT_BGR233:
|
||||
return "DRM_FORMAT_BGR233";
|
||||
case DRM_FORMAT_BGR565:
|
||||
return "DRM_FORMAT_BGR565";
|
||||
case DRM_FORMAT_BGR888:
|
||||
return "DRM_FORMAT_BGR888";
|
||||
case DRM_FORMAT_BGRA1010102:
|
||||
return "DRM_FORMAT_BGRA1010102";
|
||||
case DRM_FORMAT_BGRA4444:
|
||||
return "DRM_FORMAT_BGRA4444";
|
||||
case DRM_FORMAT_BGRA5551:
|
||||
return "DRM_FORMAT_BGRA5551";
|
||||
case DRM_FORMAT_BGRA8888:
|
||||
return "DRM_FORMAT_BGRA8888";
|
||||
case DRM_FORMAT_BGRX1010102:
|
||||
return "DRM_FORMAT_BGRX1010102";
|
||||
case DRM_FORMAT_BGRX4444:
|
||||
return "DRM_FORMAT_BGRX4444";
|
||||
case DRM_FORMAT_BGRX5551:
|
||||
return "DRM_FORMAT_BGRX5551";
|
||||
case DRM_FORMAT_BGRX8888:
|
||||
return "DRM_FORMAT_BGRX8888";
|
||||
case DRM_FORMAT_C8:
|
||||
return "DRM_FORMAT_C8";
|
||||
case DRM_FORMAT_GR88:
|
||||
return "DRM_FORMAT_GR88";
|
||||
case DRM_FORMAT_NV12:
|
||||
return "DRM_FORMAT_NV12";
|
||||
case DRM_FORMAT_NV21:
|
||||
return "DRM_FORMAT_NV21";
|
||||
case DRM_FORMAT_R8:
|
||||
return "DRM_FORMAT_R8";
|
||||
case DRM_FORMAT_RG88:
|
||||
return "DRM_FORMAT_RG88";
|
||||
case DRM_FORMAT_RGB332:
|
||||
return "DRM_FORMAT_RGB332";
|
||||
case DRM_FORMAT_RGB565:
|
||||
return "DRM_FORMAT_RGB565";
|
||||
case DRM_FORMAT_RGB888:
|
||||
return "DRM_FORMAT_RGB888";
|
||||
case DRM_FORMAT_RGBA1010102:
|
||||
return "DRM_FORMAT_RGBA1010102";
|
||||
case DRM_FORMAT_RGBA4444:
|
||||
return "DRM_FORMAT_RGBA4444";
|
||||
case DRM_FORMAT_RGBA5551:
|
||||
return "DRM_FORMAT_RGBA5551";
|
||||
case DRM_FORMAT_RGBA8888:
|
||||
return "DRM_FORMAT_RGBA8888";
|
||||
case DRM_FORMAT_RGBX1010102:
|
||||
return "DRM_FORMAT_RGBX1010102";
|
||||
case DRM_FORMAT_RGBX4444:
|
||||
return "DRM_FORMAT_RGBX4444";
|
||||
case DRM_FORMAT_RGBX5551:
|
||||
return "DRM_FORMAT_RGBX5551";
|
||||
case DRM_FORMAT_RGBX8888:
|
||||
return "DRM_FORMAT_RGBX8888";
|
||||
case DRM_FORMAT_UYVY:
|
||||
return "DRM_FORMAT_UYVY";
|
||||
case DRM_FORMAT_VYUY:
|
||||
return "DRM_FORMAT_VYUY";
|
||||
case DRM_FORMAT_XBGR1555:
|
||||
return "DRM_FORMAT_XBGR1555";
|
||||
case DRM_FORMAT_XBGR2101010:
|
||||
return "DRM_FORMAT_XBGR2101010";
|
||||
case DRM_FORMAT_XBGR4444:
|
||||
return "DRM_FORMAT_XBGR4444";
|
||||
case DRM_FORMAT_XBGR8888:
|
||||
return "DRM_FORMAT_XBGR8888";
|
||||
case DRM_FORMAT_XRGB1555:
|
||||
return "DRM_FORMAT_XRGB1555";
|
||||
case DRM_FORMAT_XRGB2101010:
|
||||
return "DRM_FORMAT_XRGB2101010";
|
||||
case DRM_FORMAT_XRGB4444:
|
||||
return "DRM_FORMAT_XRGB4444";
|
||||
case DRM_FORMAT_XRGB8888:
|
||||
return "DRM_FORMAT_XRGB8888";
|
||||
case DRM_FORMAT_YUYV:
|
||||
return "DRM_FORMAT_YUYV";
|
||||
case DRM_FORMAT_YVU420:
|
||||
return "DRM_FORMAT_YVU420";
|
||||
case DRM_FORMAT_YVYU:
|
||||
return "DRM_FORMAT_YVYU";
|
||||
}
|
||||
return android::base::StringPrintf("Unknown(%d)", drmFormat);
|
||||
}
|
||||
|
||||
std::string getPixelFormatString(PixelFormat format) {
|
||||
switch (format) {
|
||||
case PixelFormat::BGRA_8888:
|
||||
return "PixelFormat::BGRA_8888";
|
||||
case PixelFormat::BLOB:
|
||||
return "PixelFormat::BLOB";
|
||||
case PixelFormat::DEPTH_16:
|
||||
return "PixelFormat::DEPTH_16";
|
||||
case PixelFormat::DEPTH_24:
|
||||
return "PixelFormat::DEPTH_24";
|
||||
case PixelFormat::DEPTH_24_STENCIL_8:
|
||||
return "PixelFormat::DEPTH_24_STENCIL_8";
|
||||
case PixelFormat::DEPTH_32F:
|
||||
return "PixelFormat::DEPTH_24";
|
||||
case PixelFormat::DEPTH_32F_STENCIL_8:
|
||||
return "PixelFormat::DEPTH_24_STENCIL_8";
|
||||
case PixelFormat::HSV_888:
|
||||
return "PixelFormat::HSV_888";
|
||||
case PixelFormat::IMPLEMENTATION_DEFINED:
|
||||
return "PixelFormat::IMPLEMENTATION_DEFINED";
|
||||
case PixelFormat::RAW10:
|
||||
return "PixelFormat::RAW10";
|
||||
case PixelFormat::RAW12:
|
||||
return "PixelFormat::RAW12";
|
||||
case PixelFormat::RAW16:
|
||||
return "PixelFormat::RAW16";
|
||||
case PixelFormat::RAW_OPAQUE:
|
||||
return "PixelFormat::RAW_OPAQUE";
|
||||
case PixelFormat::RGBA_1010102:
|
||||
return "PixelFormat::RGBA_1010102";
|
||||
case PixelFormat::RGBA_8888:
|
||||
return "PixelFormat::RGBA_8888";
|
||||
case PixelFormat::RGBA_FP16:
|
||||
return "PixelFormat::RGBA_FP16";
|
||||
case PixelFormat::RGBX_8888:
|
||||
return "PixelFormat::RGBX_8888";
|
||||
case PixelFormat::RGB_565:
|
||||
return "PixelFormat::RGB_565";
|
||||
case PixelFormat::RGB_888:
|
||||
return "PixelFormat::RGB_888";
|
||||
case PixelFormat::STENCIL_8:
|
||||
return "PixelFormat::STENCIL_8";
|
||||
case PixelFormat::Y16:
|
||||
return "PixelFormat::Y16";
|
||||
case PixelFormat::Y8:
|
||||
return "PixelFormat::Y8";
|
||||
case PixelFormat::YCBCR_420_888:
|
||||
return "PixelFormat::YCBCR_420_888";
|
||||
case PixelFormat::YCBCR_422_I:
|
||||
return "PixelFormat::YCBCR_422_I";
|
||||
case PixelFormat::YCBCR_422_SP:
|
||||
return "PixelFormat::YCBCR_422_SP";
|
||||
case PixelFormat::YCBCR_P010:
|
||||
return "PixelFormat::YCBCR_P010";
|
||||
case PixelFormat::YCRCB_420_SP:
|
||||
return "PixelFormat::YCRCB_420_SP";
|
||||
case PixelFormat::YV12:
|
||||
return "PixelFormat::YV12";
|
||||
}
|
||||
return android::base::StringPrintf("PixelFormat::Unknown(%d)", static_cast<uint32_t>(format));
|
||||
}
|
||||
|
||||
std::string getUsageString(hidl_bitfield<BufferUsage> bufferUsage) {
|
||||
using Underlying = typename std::underlying_type<BufferUsage>::type;
|
||||
|
||||
Underlying usage = static_cast<Underlying>(bufferUsage);
|
||||
|
||||
std::vector<std::string> usages;
|
||||
if (usage & BufferUsage::CAMERA_INPUT) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::CAMERA_INPUT);
|
||||
usages.push_back("BufferUsage::CAMERA_INPUT");
|
||||
}
|
||||
if (usage & BufferUsage::CAMERA_OUTPUT) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::CAMERA_OUTPUT);
|
||||
usages.push_back("BufferUsage::CAMERA_OUTPUT");
|
||||
}
|
||||
if (usage & BufferUsage::COMPOSER_CURSOR) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::COMPOSER_CURSOR);
|
||||
usages.push_back("BufferUsage::COMPOSER_CURSOR");
|
||||
}
|
||||
if (usage & BufferUsage::COMPOSER_OVERLAY) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::COMPOSER_OVERLAY);
|
||||
usages.push_back("BufferUsage::COMPOSER_OVERLAY");
|
||||
}
|
||||
if (usage & BufferUsage::CPU_READ_OFTEN) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::CPU_READ_OFTEN);
|
||||
usages.push_back("BufferUsage::CPU_READ_OFTEN");
|
||||
}
|
||||
if (usage & BufferUsage::CPU_READ_NEVER) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::CPU_READ_NEVER);
|
||||
usages.push_back("BufferUsage::CPU_READ_NEVER");
|
||||
}
|
||||
if (usage & BufferUsage::CPU_READ_RARELY) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::CPU_READ_RARELY);
|
||||
usages.push_back("BufferUsage::CPU_READ_RARELY");
|
||||
}
|
||||
if (usage & BufferUsage::CPU_WRITE_NEVER) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::CPU_WRITE_NEVER);
|
||||
usages.push_back("BufferUsage::CPU_WRITE_NEVER");
|
||||
}
|
||||
if (usage & BufferUsage::CPU_WRITE_OFTEN) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::CPU_WRITE_OFTEN);
|
||||
usages.push_back("BufferUsage::CPU_WRITE_OFTEN");
|
||||
}
|
||||
if (usage & BufferUsage::CPU_WRITE_RARELY) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::CPU_WRITE_RARELY);
|
||||
usages.push_back("BufferUsage::CPU_WRITE_RARELY");
|
||||
}
|
||||
if (usage & BufferUsage::GPU_RENDER_TARGET) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::GPU_RENDER_TARGET);
|
||||
usages.push_back("BufferUsage::GPU_RENDER_TARGET");
|
||||
}
|
||||
if (usage & BufferUsage::GPU_TEXTURE) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::GPU_TEXTURE);
|
||||
usages.push_back("BufferUsage::GPU_TEXTURE");
|
||||
}
|
||||
if (usage & BufferUsage::PROTECTED) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::PROTECTED);
|
||||
usages.push_back("BufferUsage::PROTECTED");
|
||||
}
|
||||
if (usage & BufferUsage::RENDERSCRIPT) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::RENDERSCRIPT);
|
||||
usages.push_back("BufferUsage::RENDERSCRIPT");
|
||||
}
|
||||
if (usage & BufferUsage::VIDEO_DECODER) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::VIDEO_DECODER);
|
||||
usages.push_back("BufferUsage::VIDEO_DECODER");
|
||||
}
|
||||
if (usage & BufferUsage::VIDEO_ENCODER) {
|
||||
usage &= ~static_cast<Underlying>(BufferUsage::VIDEO_ENCODER);
|
||||
usages.push_back("BufferUsage::VIDEO_ENCODER");
|
||||
}
|
||||
|
||||
if (usage) {
|
||||
usages.push_back(android::base::StringPrintf("UnknownUsageBits-%" PRIu64, usage));
|
||||
}
|
||||
|
||||
return android::base::Join(usages, '|');
|
||||
}
|
||||
|
||||
int convertToDrmFormat(PixelFormat format, uint32_t* outDrmFormat) {
|
||||
switch (format) {
|
||||
case PixelFormat::BGRA_8888:
|
||||
*outDrmFormat = DRM_FORMAT_ARGB8888;
|
||||
return 0;
|
||||
/**
|
||||
* Choose DRM_FORMAT_R8 because <system/graphics.h> requires the buffers
|
||||
* with a format HAL_PIXEL_FORMAT_BLOB have a height of 1, and width
|
||||
* equal to their size in bytes.
|
||||
*/
|
||||
case PixelFormat::BLOB:
|
||||
*outDrmFormat = DRM_FORMAT_R8;
|
||||
return 0;
|
||||
case PixelFormat::DEPTH_16:
|
||||
return -EINVAL;
|
||||
case PixelFormat::DEPTH_24:
|
||||
return -EINVAL;
|
||||
case PixelFormat::DEPTH_24_STENCIL_8:
|
||||
return -EINVAL;
|
||||
case PixelFormat::DEPTH_32F:
|
||||
return -EINVAL;
|
||||
case PixelFormat::DEPTH_32F_STENCIL_8:
|
||||
return -EINVAL;
|
||||
case PixelFormat::HSV_888:
|
||||
return -EINVAL;
|
||||
case PixelFormat::IMPLEMENTATION_DEFINED:
|
||||
*outDrmFormat = DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED;
|
||||
return 0;
|
||||
case PixelFormat::RAW10:
|
||||
return -EINVAL;
|
||||
case PixelFormat::RAW12:
|
||||
return -EINVAL;
|
||||
case PixelFormat::RAW16:
|
||||
*outDrmFormat = DRM_FORMAT_R16;
|
||||
return 0;
|
||||
/* TODO use blob */
|
||||
case PixelFormat::RAW_OPAQUE:
|
||||
return -EINVAL;
|
||||
case PixelFormat::RGBA_1010102:
|
||||
*outDrmFormat = DRM_FORMAT_ABGR2101010;
|
||||
return 0;
|
||||
case PixelFormat::RGBA_8888:
|
||||
*outDrmFormat = DRM_FORMAT_ABGR8888;
|
||||
return 0;
|
||||
case PixelFormat::RGBA_FP16:
|
||||
*outDrmFormat = DRM_FORMAT_ABGR16161616F;
|
||||
return 0;
|
||||
case PixelFormat::RGBX_8888:
|
||||
*outDrmFormat = DRM_FORMAT_XBGR8888;
|
||||
return 0;
|
||||
case PixelFormat::RGB_565:
|
||||
*outDrmFormat = DRM_FORMAT_RGB565;
|
||||
return 0;
|
||||
case PixelFormat::RGB_888:
|
||||
*outDrmFormat = DRM_FORMAT_RGB888;
|
||||
return 0;
|
||||
case PixelFormat::STENCIL_8:
|
||||
return -EINVAL;
|
||||
case PixelFormat::Y16:
|
||||
*outDrmFormat = DRM_FORMAT_R16;
|
||||
return 0;
|
||||
case PixelFormat::Y8:
|
||||
*outDrmFormat = DRM_FORMAT_R8;
|
||||
return 0;
|
||||
case PixelFormat::YCBCR_420_888:
|
||||
*outDrmFormat = DRM_FORMAT_FLEX_YCbCr_420_888;
|
||||
return 0;
|
||||
case PixelFormat::YCBCR_422_SP:
|
||||
return -EINVAL;
|
||||
case PixelFormat::YCBCR_422_I:
|
||||
return -EINVAL;
|
||||
case PixelFormat::YCBCR_P010:
|
||||
*outDrmFormat = DRM_FORMAT_P010;
|
||||
return 0;
|
||||
case PixelFormat::YCRCB_420_SP:
|
||||
*outDrmFormat = DRM_FORMAT_NV21;
|
||||
return 0;
|
||||
case PixelFormat::YV12:
|
||||
*outDrmFormat = DRM_FORMAT_YVU420_ANDROID;
|
||||
return 0;
|
||||
};
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
int convertToBufferUsage(uint64_t grallocUsage, uint64_t* outBufferUsage) {
|
||||
uint64_t bufferUsage = BO_USE_NONE;
|
||||
|
||||
if ((grallocUsage & BufferUsage::CPU_READ_MASK) ==
|
||||
static_cast<uint64_t>(BufferUsage::CPU_READ_RARELY)) {
|
||||
bufferUsage |= BO_USE_SW_READ_RARELY;
|
||||
}
|
||||
if ((grallocUsage & BufferUsage::CPU_READ_MASK) ==
|
||||
static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN)) {
|
||||
bufferUsage |= BO_USE_SW_READ_OFTEN;
|
||||
}
|
||||
if ((grallocUsage & BufferUsage::CPU_WRITE_MASK) ==
|
||||
static_cast<uint64_t>(BufferUsage::CPU_WRITE_RARELY)) {
|
||||
bufferUsage |= BO_USE_SW_WRITE_RARELY;
|
||||
}
|
||||
if ((grallocUsage & BufferUsage::CPU_WRITE_MASK) ==
|
||||
static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN)) {
|
||||
bufferUsage |= BO_USE_SW_WRITE_OFTEN;
|
||||
}
|
||||
if (grallocUsage & BufferUsage::GPU_TEXTURE) {
|
||||
bufferUsage |= BO_USE_TEXTURE;
|
||||
}
|
||||
if (grallocUsage & BufferUsage::GPU_RENDER_TARGET) {
|
||||
bufferUsage |= BO_USE_RENDERING;
|
||||
}
|
||||
if (grallocUsage & BufferUsage::COMPOSER_OVERLAY) {
|
||||
/* HWC wants to use display hardware, but can defer to OpenGL. */
|
||||
bufferUsage |= BO_USE_SCANOUT | BO_USE_TEXTURE;
|
||||
}
|
||||
if (grallocUsage & BufferUsage::PROTECTED) {
|
||||
bufferUsage |= BO_USE_PROTECTED;
|
||||
}
|
||||
if (grallocUsage & BufferUsage::COMPOSER_CURSOR) {
|
||||
bufferUsage |= BO_USE_NONE;
|
||||
}
|
||||
if (grallocUsage & BufferUsage::VIDEO_ENCODER) {
|
||||
/*HACK: See b/30054495 */
|
||||
bufferUsage |= BO_USE_SW_READ_OFTEN;
|
||||
}
|
||||
if (grallocUsage & BufferUsage::CAMERA_OUTPUT) {
|
||||
bufferUsage |= BO_USE_CAMERA_WRITE;
|
||||
}
|
||||
if (grallocUsage & BufferUsage::CAMERA_INPUT) {
|
||||
bufferUsage |= BO_USE_CAMERA_READ;
|
||||
}
|
||||
if (grallocUsage & BufferUsage::RENDERSCRIPT) {
|
||||
bufferUsage |= BO_USE_RENDERSCRIPT;
|
||||
}
|
||||
if (grallocUsage & BufferUsage::VIDEO_DECODER) {
|
||||
bufferUsage |= BO_USE_HW_VIDEO_DECODER;
|
||||
}
|
||||
|
||||
*outBufferUsage = bufferUsage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int convertToCrosDescriptor(const BufferDescriptorInfo& descriptor,
|
||||
struct cros_gralloc_buffer_descriptor* outCrosDescriptor) {
|
||||
outCrosDescriptor->name = descriptor.name;
|
||||
outCrosDescriptor->width = descriptor.width;
|
||||
outCrosDescriptor->height = descriptor.height;
|
||||
outCrosDescriptor->droid_format = static_cast<int32_t>(descriptor.format);
|
||||
outCrosDescriptor->droid_usage = descriptor.usage;
|
||||
outCrosDescriptor->reserved_region_size = descriptor.reservedSize;
|
||||
|
||||
if (convertToDrmFormat(descriptor.format, &outCrosDescriptor->drm_format)) {
|
||||
std::string pixelFormatString = getPixelFormatString(descriptor.format);
|
||||
drv_log("Failed to convert descriptor. Unsupported fomat %s\n", pixelFormatString.c_str());
|
||||
return -1;
|
||||
}
|
||||
if (convertToBufferUsage(descriptor.usage, &outCrosDescriptor->use_flags)) {
|
||||
std::string usageString = getUsageString(descriptor.usage);
|
||||
drv_log("Failed to convert descriptor. Unsupported usage flags %s\n", usageString.c_str());
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int convertToMapUsage(uint64_t grallocUsage, uint32_t* outMapUsage) {
|
||||
uint32_t mapUsage = BO_MAP_NONE;
|
||||
|
||||
if (grallocUsage & BufferUsage::CPU_READ_MASK) {
|
||||
mapUsage |= BO_MAP_READ;
|
||||
}
|
||||
if (grallocUsage & BufferUsage::CPU_WRITE_MASK) {
|
||||
mapUsage |= BO_MAP_WRITE;
|
||||
}
|
||||
|
||||
*outMapUsage = mapUsage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int convertToFenceFd(const hidl_handle& fenceHandle, int* outFenceFd) {
|
||||
if (!outFenceFd) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
const native_handle_t* nativeHandle = fenceHandle.getNativeHandle();
|
||||
if (nativeHandle && nativeHandle->numFds > 1) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
*outFenceFd = (nativeHandle && nativeHandle->numFds == 1) ? nativeHandle->data[0] : -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int convertToFenceHandle(int fenceFd, hidl_handle* outFenceHandle) {
|
||||
if (!outFenceHandle) {
|
||||
return -EINVAL;
|
||||
}
|
||||
if (fenceFd < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
NATIVE_HANDLE_DECLARE_STORAGE(handleStorage, 1, 0);
|
||||
auto fenceHandle = native_handle_init(handleStorage, 1, 0);
|
||||
fenceHandle->data[0] = fenceFd;
|
||||
|
||||
*outFenceHandle = fenceHandle;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const std::unordered_map<uint32_t, std::vector<PlaneLayout>>& GetPlaneLayoutsMap() {
|
||||
static const auto* kPlaneLayoutsMap =
|
||||
new std::unordered_map<uint32_t, std::vector<PlaneLayout>>({
|
||||
{DRM_FORMAT_ABGR8888,
|
||||
{{
|
||||
.components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 8},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_G,
|
||||
.offsetInBits = 8,
|
||||
.sizeInBits = 8},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_B,
|
||||
.offsetInBits = 16,
|
||||
.sizeInBits = 8},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_A,
|
||||
.offsetInBits = 24,
|
||||
.sizeInBits = 8}},
|
||||
.sampleIncrementInBits = 32,
|
||||
.horizontalSubsampling = 1,
|
||||
.verticalSubsampling = 1,
|
||||
}}},
|
||||
|
||||
{DRM_FORMAT_ABGR2101010,
|
||||
{{
|
||||
.components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 10},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_G,
|
||||
.offsetInBits = 10,
|
||||
.sizeInBits = 10},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_B,
|
||||
.offsetInBits = 20,
|
||||
.sizeInBits = 10},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_A,
|
||||
.offsetInBits = 30,
|
||||
.sizeInBits = 2}},
|
||||
.sampleIncrementInBits = 32,
|
||||
.horizontalSubsampling = 1,
|
||||
.verticalSubsampling = 1,
|
||||
}}},
|
||||
|
||||
{DRM_FORMAT_ABGR16161616F,
|
||||
{{
|
||||
.components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 16},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_G,
|
||||
.offsetInBits = 16,
|
||||
.sizeInBits = 16},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_B,
|
||||
.offsetInBits = 32,
|
||||
.sizeInBits = 16},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_A,
|
||||
.offsetInBits = 48,
|
||||
.sizeInBits = 16}},
|
||||
.sampleIncrementInBits = 64,
|
||||
.horizontalSubsampling = 1,
|
||||
.verticalSubsampling = 1,
|
||||
}}},
|
||||
|
||||
{DRM_FORMAT_ARGB8888,
|
||||
{{
|
||||
.components = {{.type = android::gralloc4::PlaneLayoutComponentType_B,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 8},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_G,
|
||||
.offsetInBits = 8,
|
||||
.sizeInBits = 8},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_R,
|
||||
.offsetInBits = 16,
|
||||
.sizeInBits = 8},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_A,
|
||||
.offsetInBits = 24,
|
||||
.sizeInBits = 8}},
|
||||
.sampleIncrementInBits = 32,
|
||||
.horizontalSubsampling = 1,
|
||||
.verticalSubsampling = 1,
|
||||
}}},
|
||||
|
||||
{DRM_FORMAT_NV12,
|
||||
{{
|
||||
.components = {{.type = android::gralloc4::PlaneLayoutComponentType_Y,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 8}},
|
||||
.sampleIncrementInBits = 8,
|
||||
.horizontalSubsampling = 1,
|
||||
.verticalSubsampling = 1,
|
||||
},
|
||||
{
|
||||
.components =
|
||||
{{.type = android::gralloc4::PlaneLayoutComponentType_CB,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 8},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_CR,
|
||||
.offsetInBits = 8,
|
||||
.sizeInBits = 8}},
|
||||
.sampleIncrementInBits = 16,
|
||||
.horizontalSubsampling = 2,
|
||||
.verticalSubsampling = 2,
|
||||
}}},
|
||||
|
||||
{DRM_FORMAT_NV21,
|
||||
{{
|
||||
.components = {{.type = android::gralloc4::PlaneLayoutComponentType_Y,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 8}},
|
||||
.sampleIncrementInBits = 8,
|
||||
.horizontalSubsampling = 1,
|
||||
.verticalSubsampling = 1,
|
||||
},
|
||||
{
|
||||
.components =
|
||||
{{.type = android::gralloc4::PlaneLayoutComponentType_CR,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 8},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_CB,
|
||||
.offsetInBits = 8,
|
||||
.sizeInBits = 8}},
|
||||
.sampleIncrementInBits = 16,
|
||||
.horizontalSubsampling = 2,
|
||||
.verticalSubsampling = 2,
|
||||
}}},
|
||||
|
||||
{DRM_FORMAT_P010,
|
||||
{{
|
||||
.components = {{.type = android::gralloc4::PlaneLayoutComponentType_Y,
|
||||
.offsetInBits = 6,
|
||||
.sizeInBits = 10}},
|
||||
.sampleIncrementInBits = 16,
|
||||
.horizontalSubsampling = 1,
|
||||
.verticalSubsampling = 1,
|
||||
},
|
||||
{
|
||||
.components =
|
||||
{{.type = android::gralloc4::PlaneLayoutComponentType_CB,
|
||||
.offsetInBits = 6,
|
||||
.sizeInBits = 10},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_CR,
|
||||
.offsetInBits = 22,
|
||||
.sizeInBits = 10}},
|
||||
.sampleIncrementInBits = 32,
|
||||
.horizontalSubsampling = 2,
|
||||
.verticalSubsampling = 2,
|
||||
}}},
|
||||
|
||||
{DRM_FORMAT_R8,
|
||||
{{
|
||||
.components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 8}},
|
||||
.sampleIncrementInBits = 8,
|
||||
.horizontalSubsampling = 1,
|
||||
.verticalSubsampling = 1,
|
||||
}}},
|
||||
|
||||
{DRM_FORMAT_R16,
|
||||
{{
|
||||
.components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 16}},
|
||||
.sampleIncrementInBits = 16,
|
||||
.horizontalSubsampling = 1,
|
||||
.verticalSubsampling = 1,
|
||||
}}},
|
||||
|
||||
{DRM_FORMAT_RGB565,
|
||||
{{
|
||||
.components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 5},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_G,
|
||||
.offsetInBits = 5,
|
||||
.sizeInBits = 6},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_B,
|
||||
.offsetInBits = 11,
|
||||
.sizeInBits = 5}},
|
||||
.sampleIncrementInBits = 16,
|
||||
.horizontalSubsampling = 1,
|
||||
.verticalSubsampling = 1,
|
||||
}}},
|
||||
|
||||
{DRM_FORMAT_RGB888,
|
||||
{{
|
||||
.components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 8},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_G,
|
||||
.offsetInBits = 8,
|
||||
.sizeInBits = 8},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_B,
|
||||
.offsetInBits = 16,
|
||||
.sizeInBits = 8}},
|
||||
.sampleIncrementInBits = 24,
|
||||
.horizontalSubsampling = 1,
|
||||
.verticalSubsampling = 1,
|
||||
}}},
|
||||
|
||||
{DRM_FORMAT_XBGR8888,
|
||||
{{
|
||||
.components = {{.type = android::gralloc4::PlaneLayoutComponentType_B,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 8},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_G,
|
||||
.offsetInBits = 8,
|
||||
.sizeInBits = 8},
|
||||
{.type = android::gralloc4::PlaneLayoutComponentType_R,
|
||||
.offsetInBits = 16,
|
||||
.sizeInBits = 8}},
|
||||
.sampleIncrementInBits = 32,
|
||||
.horizontalSubsampling = 1,
|
||||
.verticalSubsampling = 1,
|
||||
}}},
|
||||
|
||||
{DRM_FORMAT_YVU420,
|
||||
{
|
||||
{
|
||||
.components = {{.type = android::gralloc4::
|
||||
PlaneLayoutComponentType_Y,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 8}},
|
||||
.sampleIncrementInBits = 8,
|
||||
.horizontalSubsampling = 1,
|
||||
.verticalSubsampling = 1,
|
||||
},
|
||||
{
|
||||
.components = {{.type = android::gralloc4::
|
||||
PlaneLayoutComponentType_CB,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 8}},
|
||||
.sampleIncrementInBits = 8,
|
||||
.horizontalSubsampling = 2,
|
||||
.verticalSubsampling = 2,
|
||||
},
|
||||
{
|
||||
.components = {{.type = android::gralloc4::
|
||||
PlaneLayoutComponentType_CR,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 8}},
|
||||
.sampleIncrementInBits = 8,
|
||||
.horizontalSubsampling = 2,
|
||||
.verticalSubsampling = 2,
|
||||
},
|
||||
}},
|
||||
|
||||
{DRM_FORMAT_YVU420_ANDROID,
|
||||
{
|
||||
{
|
||||
.components = {{.type = android::gralloc4::
|
||||
PlaneLayoutComponentType_Y,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 8}},
|
||||
.sampleIncrementInBits = 8,
|
||||
.horizontalSubsampling = 1,
|
||||
.verticalSubsampling = 1,
|
||||
},
|
||||
{
|
||||
.components = {{.type = android::gralloc4::
|
||||
PlaneLayoutComponentType_CR,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 8}},
|
||||
.sampleIncrementInBits = 8,
|
||||
.horizontalSubsampling = 2,
|
||||
.verticalSubsampling = 2,
|
||||
},
|
||||
{
|
||||
.components = {{.type = android::gralloc4::
|
||||
PlaneLayoutComponentType_CB,
|
||||
.offsetInBits = 0,
|
||||
.sizeInBits = 8}},
|
||||
.sampleIncrementInBits = 8,
|
||||
.horizontalSubsampling = 2,
|
||||
.verticalSubsampling = 2,
|
||||
},
|
||||
}},
|
||||
});
|
||||
return *kPlaneLayoutsMap;
|
||||
}
|
||||
|
||||
int getPlaneLayouts(uint32_t drmFormat, std::vector<PlaneLayout>* outPlaneLayouts) {
|
||||
const auto& planeLayoutsMap = GetPlaneLayoutsMap();
|
||||
const auto it = planeLayoutsMap.find(drmFormat);
|
||||
if (it == planeLayoutsMap.end()) {
|
||||
drv_log("Unknown plane layout for format %d\n", drmFormat);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*outPlaneLayouts = it->second;
|
||||
return 0;
|
||||
}
|
||||
41
cros_gralloc/gralloc4/CrosGralloc4Utils.h
Normal file
41
cros_gralloc/gralloc4/CrosGralloc4Utils.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright 2020 The Chromium OS Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <aidl/android/hardware/graphics/common/PlaneLayout.h>
|
||||
#include <android/hardware/graphics/common/1.2/types.h>
|
||||
#include <android/hardware/graphics/mapper/4.0/IMapper.h>
|
||||
|
||||
#include "cros_gralloc/cros_gralloc_types.h"
|
||||
|
||||
std::string getDrmFormatString(uint32_t drmFormat);
|
||||
|
||||
std::string getPixelFormatString(android::hardware::graphics::common::V1_2::PixelFormat format);
|
||||
|
||||
std::string getUsageString(
|
||||
android::hardware::hidl_bitfield<android::hardware::graphics::common::V1_2::BufferUsage>
|
||||
usage);
|
||||
|
||||
int convertToDrmFormat(android::hardware::graphics::common::V1_2::PixelFormat format,
|
||||
uint32_t* outDrmFormat);
|
||||
|
||||
int convertToBufferUsage(uint64_t grallocUsage, uint64_t* outBufferUsage);
|
||||
|
||||
int convertToCrosDescriptor(
|
||||
const android::hardware::graphics::mapper::V4_0::IMapper::BufferDescriptorInfo& descriptor,
|
||||
struct cros_gralloc_buffer_descriptor* outCrosDescriptor);
|
||||
|
||||
int convertToMapUsage(uint64_t grallocUsage, uint32_t* outMapUsage);
|
||||
|
||||
int convertToFenceFd(const android::hardware::hidl_handle& fence_handle, int* out_fence_fd);
|
||||
|
||||
int convertToFenceHandle(int fence_fd, android::hardware::hidl_handle* out_fence_handle);
|
||||
|
||||
int getPlaneLayouts(
|
||||
uint32_t drm_format,
|
||||
std::vector<aidl::android::hardware::graphics::common::PlaneLayout>* out_layouts);
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# Copyright 2020 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
|
||||
interface android.hardware.graphics.allocator@4.0::IAllocator default
|
||||
class hal animation
|
||||
user system
|
||||
group graphics drmrpc
|
||||
capabilities SYS_NICE
|
||||
onrestart restart surfaceflinger
|
||||
writepid /dev/cpuset/system-background/tasks
|
||||
Loading…
Add table
Add a link
Reference in a new issue