Adding drm format in allocate3.cpp
Bug: b/323896722
Test: atest android.graphics.cts.MediaVulkanGpuTest#testMediaImportAndRendering
Change-Id: If74526b2bf54718a54c2a54d4c19189916c9f743
diff --git a/system/hals/allocator3.cpp b/system/hals/allocator3.cpp
index 8a05abd..3c15b63 100644
--- a/system/hals/allocator3.cpp
+++ b/system/hals/allocator3.cpp
@@ -19,6 +19,7 @@
#include <android/hardware/graphics/mapper/3.0/IMapper.h>
#include <hidl/LegacySupport.h>
#include <qemu_pipe_bp.h>
+#include <drm_fourcc.h>
#include "glUtils.h"
#include "cb_handle_30.h"
@@ -364,7 +365,7 @@
RETURN_ERROR(Error3::NO_RESOURCES);
}
}
-
+ uint32_t drmFormat = resolve_drm_format(format);
std::unique_ptr<cb_handle_30_t> handle =
std::make_unique<cb_handle_30_t>(
cpuAlocatorFd.release(),
@@ -374,6 +375,7 @@
width,
height,
static_cast<int>(format),
+ drmFormat,
glFormat,
glType,
bufferSize,
@@ -388,6 +390,25 @@
RETURN(Error3::NONE);
}
+ uint32_t resolve_drm_format(const PixelFormat format) {
+ /**
+ * This aims to replicate the virtgpu format handling for YUV
+ * Moving to minigbm + virtgpu should offer the same behaviour
+ * https://cs.android.com/android/platform/superproject/main/+/main:external/minigbm/virtgpu_virgl.c;l=1206?q=virtgpu&ss=android%2Fplatform%2Fsuperproject%2Fmain
+ */
+ ALOGV("Resolving drm format from PixelFormat %d", static_cast<int>(format));
+ switch (format) {
+ case PixelFormat::YCBCR_420_888:
+ return DRM_FORMAT_YUV420;
+ default:
+ //TODO handle new formats if needed
+ ALOGV("Unknown DRM Format resolution. Proceeding with an "
+ "invalid drm format. Later stages of the application "
+ "should handle this.");
+ return DRM_FORMAT_INVALID;
+ }
+ }
+
void freeCb(std::unique_ptr<cb_handle_30_t> cb) {
if (cb->hostHandleRefcountFdIndex >= 0) {
::close(cb->fds[cb->hostHandleRefcountFdIndex]);
diff --git a/system/hals/cb_handle_30.h b/system/hals/cb_handle_30.h
index ca305c9..11c8d0f 100644
--- a/system/hals/cb_handle_30.h
+++ b/system/hals/cb_handle_30.h
@@ -30,6 +30,7 @@
uint32_t p_width,
uint32_t p_height,
uint32_t p_format,
+ uint32_t p_drmformat,
uint32_t p_glFormat,
uint32_t p_glType,
uint32_t p_bufSize,
@@ -41,6 +42,7 @@
: cb_handle_t(CB_HANDLE_MAGIC_30,
p_hostHandle,
p_format,
+ p_drmformat,
p_stride,
p_bufSize,
p_mmapedOffset),