summaryrefslogtreecommitdiff
path: root/cros_gralloc
diff options
context:
space:
mode:
authorYiwei Zhang <zzyiwei@chromium.org>2021-09-16 22:08:27 +0000
committerCommit Bot <commit-bot@chromium.org>2021-09-17 13:47:55 +0000
commitdfe5ac6b587771996e22c883e9020574d3a64151 (patch)
tree0e47525ea13d52a1370dcb0d9841bbd79671c2b4 /cros_gralloc
parent6032967f7694752f27a36f17c8fd8814af847a4f (diff)
downloadminigbm-dfe5ac6b587771996e22c883e9020574d3a64151.tar.gz
gralloc: resolve format and use_flags at cros_gralloc_driver level
This simplify the separate resolving efforts in different gralloc frontends (including separate logic in gralloc4 mapper and allocator). BUG=b:199524294 TEST=CtsNativeHardwareTestCases Change-Id: I74cd19df9b06c26a124e89c3367dd76b5b57dbd0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3166893 Reviewed-by: Jason Macnak <natsu@google.com> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: Jason Macnak <natsu@google.com> Tested-by: Yiwei Zhang <zzyiwei@chromium.org> Commit-Queue: Yiwei Zhang <zzyiwei@chromium.org>
Diffstat (limited to 'cros_gralloc')
-rw-r--r--cros_gralloc/cros_gralloc_driver.cc19
-rw-r--r--cros_gralloc/gralloc0/gralloc0.cc24
-rw-r--r--cros_gralloc/gralloc4/CrosGralloc4Allocator.cc18
-rw-r--r--cros_gralloc/gralloc4/CrosGralloc4Mapper.cc18
4 files changed, 22 insertions, 57 deletions
diff --git a/cros_gralloc/cros_gralloc_driver.cc b/cros_gralloc/cros_gralloc_driver.cc
index d38ddd4..61f61b1 100644
--- a/cros_gralloc/cros_gralloc_driver.cc
+++ b/cros_gralloc/cros_gralloc_driver.cc
@@ -8,6 +8,7 @@
#include <cstdlib>
#include <fcntl.h>
+#include <hardware/gralloc.h>
#include <sys/mman.h>
#include <syscall.h>
#include <xf86drm.h>
@@ -152,6 +153,24 @@ bool cros_gralloc_driver::get_resolved_format_and_use_flags(
}
combo = drv_get_combination(drv_, resolved_format, resolved_use_flags);
+ if (!combo && (descriptor->droid_usage & GRALLOC_USAGE_HW_COMPOSER)) {
+ resolved_use_flags &= ~BO_USE_SCANOUT;
+ combo = drv_get_combination(drv_, resolved_format, resolved_use_flags);
+ }
+ if (!combo && (descriptor->droid_usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) &&
+ descriptor->droid_format != HAL_PIXEL_FORMAT_YCbCr_420_888) {
+ // Unmask BO_USE_HW_VIDEO_ENCODER for other formats. They are mostly
+ // intermediate formats not passed directly to the encoder (e.g.
+ // camera). YV12 is passed to the encoder component, but it is converted
+ // to YCbCr_420_888 before being passed to the hw encoder.
+ resolved_use_flags &= ~BO_USE_HW_VIDEO_ENCODER;
+ combo = drv_get_combination(drv_, resolved_format, resolved_use_flags);
+ }
+ if (!combo && (descriptor->droid_usage & BUFFER_USAGE_FRONT_RENDERING)) {
+ resolved_use_flags &= ~BO_USE_FRONT_RENDERING;
+ resolved_use_flags |= BO_USE_LINEAR;
+ combo = drv_get_combination(drv_, resolved_format, resolved_use_flags);
+ }
if (!combo)
return false;
diff --git a/cros_gralloc/gralloc0/gralloc0.cc b/cros_gralloc/gralloc0/gralloc0.cc
index cc87f3b..7140966 100644
--- a/cros_gralloc/gralloc0/gralloc0.cc
+++ b/cros_gralloc/gralloc0/gralloc0.cc
@@ -84,7 +84,6 @@ static int gralloc0_alloc(alloc_device_t *dev, int w, int h, int format, int usa
buffer_handle_t *handle, int *stride)
{
int32_t ret;
- bool supported;
struct cros_gralloc_buffer_descriptor descriptor;
auto mod = (struct gralloc0_module const *)dev->common.module;
@@ -96,28 +95,7 @@ static int gralloc0_alloc(alloc_device_t *dev, int w, int h, int format, int usa
descriptor.use_flags = cros_gralloc_convert_usage(usage);
descriptor.reserved_region_size = 0;
- supported = mod->driver->is_supported(&descriptor);
- if (!supported && (usage & GRALLOC_USAGE_HW_COMPOSER)) {
- descriptor.use_flags &= ~BO_USE_SCANOUT;
- supported = mod->driver->is_supported(&descriptor);
- }
- if (!supported && (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) &&
- format != HAL_PIXEL_FORMAT_YCbCr_420_888) {
- // Unmask BO_USE_HW_VIDEO_ENCODER for other formats. They are mostly
- // intermediate formats not passed directly to the encoder (e.g.
- // camera). YV12 is passed to the encoder component, but it is converted
- // to YCbCr_420_888 before being passed to the hw encoder.
- descriptor.use_flags &= ~BO_USE_HW_VIDEO_ENCODER;
- drv_log("Retrying format %u allocation without encoder flag", format);
- supported = mod->driver->is_supported(&descriptor);
- }
- if (!supported && (usage & BUFFER_USAGE_FRONT_RENDERING)) {
- descriptor.use_flags &= ~BO_USE_FRONT_RENDERING;
- descriptor.use_flags |= BO_USE_LINEAR;
- supported = mod->driver->is_supported(&descriptor);
- }
-
- if (!supported) {
+ if (!mod->driver->is_supported(&descriptor)) {
drv_log("Unsupported combination -- HAL format: %u, HAL usage: %u, "
"drv_format: %4.4s, use_flags: %llu\n",
format, usage, reinterpret_cast<char *>(&descriptor.drm_format),
diff --git a/cros_gralloc/gralloc4/CrosGralloc4Allocator.cc b/cros_gralloc/gralloc4/CrosGralloc4Allocator.cc
index ee7199c..0368e1a 100644
--- a/cros_gralloc/gralloc4/CrosGralloc4Allocator.cc
+++ b/cros_gralloc/gralloc4/CrosGralloc4Allocator.cc
@@ -44,23 +44,7 @@ Error CrosGralloc4Allocator::allocate(const BufferDescriptorInfo& descriptor, ui
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 && (descriptor.usage & BufferUsage::VIDEO_ENCODER) &&
- descriptor.format != PixelFormat::YCBCR_420_888) {
- crosDescriptor.use_flags &= ~BO_USE_HW_VIDEO_ENCODER;
- supported = mDriver->is_supported(&crosDescriptor);
- }
- if (!supported && (descriptor.usage & BUFFER_USAGE_FRONT_RENDERING)) {
- crosDescriptor.use_flags &= ~BO_USE_FRONT_RENDERING;
- crosDescriptor.use_flags |= BO_USE_LINEAR;
- supported = mDriver->is_supported(&crosDescriptor);
- }
-
- if (!supported) {
+ if (!mDriver->is_supported(&crosDescriptor)) {
std::string drmFormatString = get_drm_format_string(crosDescriptor.drm_format);
std::string pixelFormatString = getPixelFormatString(descriptor.format);
std::string usageString = getUsageString(descriptor.usage);
diff --git a/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc b/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc
index 0179902..327c8ca 100644
--- a/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc
+++ b/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc
@@ -392,23 +392,7 @@ Return<void> CrosGralloc4Mapper::isSupported(const BufferDescriptorInfo& descrip
return Void();
}
- 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 && (descriptor.usage & BufferUsage::VIDEO_ENCODER) &&
- descriptor.format != PixelFormat::YCBCR_420_888) {
- crosDescriptor.use_flags &= ~BO_USE_HW_VIDEO_ENCODER;
- supported = mDriver->is_supported(&crosDescriptor);
- }
- if (!supported && (descriptor.usage & BUFFER_USAGE_FRONT_RENDERING)) {
- crosDescriptor.use_flags &= ~BO_USE_FRONT_RENDERING;
- crosDescriptor.use_flags |= BO_USE_LINEAR;
- supported = mDriver->is_supported(&crosDescriptor);
- }
-
- hidlCb(Error::NONE, supported);
+ hidlCb(Error::NONE, mDriver->is_supported(&crosDescriptor));
return Void();
}