summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Stratiienko <roman.stratiienko@globallogic.com>2019-12-06 12:30:28 +0200
committerRoman Stratiienko <roman.stratiienko@globallogic.com>2019-12-19 08:33:52 +0000
commit4163efcb37b8e7a6bf00acec60ea9f9be2a5969a (patch)
tree69422e9e59f30ef1a3237b15abc20dcc3809b896
parentb7b81cfba252c6dda77356fe5fd9cfd682c63a5d (diff)
drm_hwcomposer: Extract ConvertBoInfo() from ImportBuffer() method
To check either BO could be imported on validation stage, we need to get more information regarding buffer (format, size, etc.) This extraction also allows us to make ImportBuffer() and CanImport() methods generic for all platforms. In case BO can't be imported due to already existant checks in ImportBuffer(), validator only marks single layer to be elaborated by GPU instead of whole composition. Signed-off-by: Roman Stratiienko <roman.stratiienko@globallogic.com>
-rw-r--r--include/drmhwcgralloc.h3
-rw-r--r--include/platform.h3
-rw-r--r--platform/platformdrmgeneric.cpp69
-rw-r--r--platform/platformdrmgeneric.h2
-rw-r--r--platform/platformhisi.cpp48
-rw-r--r--platform/platformhisi.h3
-rw-r--r--platform/platformimagination.cpp27
-rw-r--r--platform/platformimagination.h2
-rw-r--r--platform/platformmeson.cpp40
-rw-r--r--platform/platformmeson.h3
-rw-r--r--platform/platformminigbm.cpp24
-rw-r--r--platform/platformminigbm.h2
12 files changed, 88 insertions, 138 deletions
diff --git a/include/drmhwcgralloc.h b/include/drmhwcgralloc.h
index 65a4007..b959714 100644
--- a/include/drmhwcgralloc.h
+++ b/include/drmhwcgralloc.h
@@ -29,8 +29,11 @@ typedef struct hwc_drm_bo {
uint32_t pixel_stride;
uint32_t pitches[HWC_DRM_BO_MAX_PLANES];
uint32_t offsets[HWC_DRM_BO_MAX_PLANES];
+ uint32_t prime_fds[HWC_DRM_BO_MAX_PLANES];
uint32_t gem_handles[HWC_DRM_BO_MAX_PLANES];
+ uint64_t modifiers[HWC_DRM_BO_MAX_PLANES];
uint32_t fb_id;
+ bool with_modifiers;
int acquire_fence_fd;
void *priv;
} hwc_drm_bo_t;
diff --git a/include/platform.h b/include/platform.h
index 6fdece2..6775e29 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -52,6 +52,9 @@ class Importer {
// Checks if importer can import the buffer.
virtual bool CanImportBuffer(buffer_handle_t handle) = 0;
+
+ // Convert platform-dependent buffer format to drm_hwc internal format.
+ virtual int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) = 0;
};
class Planner {
diff --git a/platform/platformdrmgeneric.cpp b/platform/platformdrmgeneric.cpp
index 668742c..1aa8160 100644
--- a/platform/platformdrmgeneric.cpp
+++ b/platform/platformdrmgeneric.cpp
@@ -110,19 +110,12 @@ uint32_t DrmGenericImporter::DrmFormatToBitsPerPixel(uint32_t drm_format) {
}
}
-int DrmGenericImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
+int DrmGenericImporter::ConvertBoInfo(buffer_handle_t handle,
+ hwc_drm_bo_t *bo) {
gralloc_handle_t *gr_handle = gralloc_handle(handle);
if (!gr_handle)
return -EINVAL;
- uint32_t gem_handle;
- int ret = drmPrimeFDToHandle(drm_->fd(), gr_handle->prime_fd, &gem_handle);
- if (ret) {
- ALOGE("failed to import prime fd %d ret=%d", gr_handle->prime_fd, ret);
- return ret;
- }
-
- memset(bo, 0, sizeof(hwc_drm_bo_t));
bo->width = gr_handle->width;
bo->height = gr_handle->height;
bo->hal_format = gr_handle->format;
@@ -132,18 +125,54 @@ int DrmGenericImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
bo->usage = gr_handle->usage;
bo->pixel_stride = (gr_handle->stride * 8) /
DrmFormatToBitsPerPixel(bo->format);
+ bo->prime_fds[0] = gr_handle->prime_fd;
bo->pitches[0] = gr_handle->stride;
- bo->gem_handles[0] = gem_handle;
bo->offsets[0] = 0;
- ret = drmModeAddFB2(drm_->fd(), bo->width, bo->height, bo->format,
- bo->gem_handles, bo->pitches, bo->offsets, &bo->fb_id, 0);
+ return 0;
+}
+
+int DrmGenericImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
+ memset(bo, 0, sizeof(hwc_drm_bo_t));
+
+ int ret = ConvertBoInfo(handle, bo);
+ if (ret)
+ return ret;
+
+ ret = drmPrimeFDToHandle(drm_->fd(), bo->prime_fds[0], &bo->gem_handles[0]);
+ if (ret) {
+ ALOGE("failed to import prime fd %d ret=%d", bo->prime_fds[0], ret);
+ return ret;
+ }
+
+ for (int i = 1; i < HWC_DRM_BO_MAX_PLANES; i++) {
+ int fd = bo->prime_fds[i];
+ if (fd != 0) {
+ if (fd != bo->prime_fds[0]) {
+ ALOGE("Multiplanar FBs are not supported by this version of composer");
+ return -ENOTSUP;
+ }
+ bo->gem_handles[i] = bo->gem_handles[0];
+ }
+ }
+
+ if (!bo->with_modifiers)
+ ret = drmModeAddFB2(drm_->fd(), bo->width, bo->height, bo->format,
+ bo->gem_handles, bo->pitches, bo->offsets, &bo->fb_id,
+ 0);
+ else
+ ret = drmModeAddFB2WithModifiers(drm_->fd(), bo->width, bo->height,
+ bo->format, bo->gem_handles, bo->pitches,
+ bo->offsets, bo->modifiers, &bo->fb_id,
+ bo->modifiers[0] ? DRM_MODE_FB_MODIFIERS
+ : 0);
+
if (ret) {
ALOGE("could not create drm fb %d", ret);
return ret;
}
- ImportHandle(gem_handle);
+ ImportHandle(bo->gem_handles[0]);
return ret;
}
@@ -170,13 +199,17 @@ int DrmGenericImporter::ReleaseBuffer(hwc_drm_bo_t *bo) {
}
bool DrmGenericImporter::CanImportBuffer(buffer_handle_t handle) {
- if (handle == NULL)
+ hwc_drm_bo_t bo;
+
+ int ret = ConvertBoInfo(handle, &bo);
+ if (ret)
return false;
- if (exclude_non_hwfb_) {
- gralloc_handle_t *hnd = gralloc_handle(handle);
- return hnd->usage & GRALLOC_USAGE_HW_FB;
- }
+ if (bo.prime_fds[0] == 0)
+ return false;
+
+ if (exclude_non_hwfb_ && !(bo.usage & GRALLOC_USAGE_HW_FB))
+ return false;
return true;
}
diff --git a/platform/platformdrmgeneric.h b/platform/platformdrmgeneric.h
index a7cf941..f9d923f 100644
--- a/platform/platformdrmgeneric.h
+++ b/platform/platformdrmgeneric.h
@@ -44,6 +44,8 @@ class DrmGenericImporter : public Importer {
int ImportHandle(uint32_t gem_handle);
int ReleaseHandle(uint32_t gem_handle);
+ int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+
uint32_t ConvertHalFormatToDrm(uint32_t hal_format);
uint32_t DrmFormatToBitsPerPixel(uint32_t drm_format);
diff --git a/platform/platformhisi.cpp b/platform/platformhisi.cpp
index 81d8039..1f1478f 100644
--- a/platform/platformhisi.cpp
+++ b/platform/platformhisi.cpp
@@ -92,41 +92,29 @@ bool HisiImporter::IsDrmFormatRgb(uint32_t drm_format) {
case DRM_FORMAT_YVU420:
return false;
default:
- ALOGE("Unsupported format %u assuming rgb?", drm_format);
+ ALOGV("Unsupported format %u assuming rgb?", drm_format);
return true;
}
}
-int HisiImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
+int HisiImporter::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
bool is_rgb;
- uint64_t modifiers[4] = {0};
-
- memset(bo, 0, sizeof(hwc_drm_bo_t));
private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>(
handle);
if (!hnd)
return -EINVAL;
- // We can't import these types of buffers.
- // These buffers should have been filtered out with CanImportBuffer()
if (!(hnd->usage & GRALLOC_USAGE_HW_FB))
return -EINVAL;
- uint32_t gem_handle;
- int ret = drmPrimeFDToHandle(drm_->fd(), hnd->share_fd, &gem_handle);
- if (ret) {
- ALOGE("failed to import prime fd %d ret=%d", hnd->share_fd, ret);
- return ret;
- }
-
uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
if (fmt == DRM_FORMAT_INVALID)
return -EINVAL;
- is_rgb = IsDrmFormatRgb(fmt);
- modifiers[0] = ConvertGrallocFormatToDrmModifiers(hnd->internal_format,
- is_rgb);
+ is_rgb = HisiImporter::IsDrmFormatRgb(fmt);
+ bo->modifiers[0] = HisiImporter::
+ ConvertGrallocFormatToDrmModifiers(hnd->internal_format, is_rgb);
bo->width = hnd->width;
bo->height = hnd->height;
@@ -135,7 +123,7 @@ int HisiImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
bo->usage = hnd->usage;
bo->pixel_stride = hnd->stride;
bo->pitches[0] = hnd->byte_stride;
- bo->gem_handles[0] = gem_handle;
+ bo->prime_fds[0] = hnd->share_fd;
bo->offsets[0] = 0;
switch (fmt) {
@@ -150,11 +138,11 @@ int HisiImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
int v_size = vu_stride * (adjusted_height / 2);
/* V plane*/
- bo->gem_handles[1] = gem_handle;
+ bo->prime_fds[1] = hnd->share_fd;
bo->pitches[1] = vu_stride;
bo->offsets[1] = y_size;
/* U plane */
- bo->gem_handles[2] = gem_handle;
+ bo->prime_fds[2] = hnd->share_fd;
bo->pitches[2] = vu_stride;
bo->offsets[2] = y_size + v_size;
break;
@@ -163,25 +151,9 @@ int HisiImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
break;
}
- ret = drmModeAddFB2WithModifiers(drm_->fd(), bo->width, bo->height,
- bo->format, bo->gem_handles, bo->pitches,
- bo->offsets, modifiers, &bo->fb_id,
- modifiers[0] ? DRM_MODE_FB_MODIFIERS : 0);
-
- if (ret) {
- ALOGE("could not create drm fb %d", ret);
- return ret;
- }
+ bo->with_modifiers = true;
- ImportHandle(gem_handle);
-
- return ret;
-}
-
-bool HisiImporter::CanImportBuffer(buffer_handle_t handle) {
- private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>(
- handle);
- return hnd && (hnd->usage & GRALLOC_USAGE_HW_FB);
+ return 0;
}
class PlanStageHiSi : public Planner::PlanStage {
diff --git a/platform/platformhisi.h b/platform/platformhisi.h
index 9dfea89..f127bdb 100644
--- a/platform/platformhisi.h
+++ b/platform/platformhisi.h
@@ -31,8 +31,7 @@ class HisiImporter : public DrmGenericImporter {
public:
using DrmGenericImporter::DrmGenericImporter;
- int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
- bool CanImportBuffer(buffer_handle_t handle) override;
+ int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
private:
uint64_t ConvertGrallocFormatToDrmModifiers(uint64_t flags, bool is_rgb);
diff --git a/platform/platformimagination.cpp b/platform/platformimagination.cpp
index 5e0335c..ea34ecc 100644
--- a/platform/platformimagination.cpp
+++ b/platform/platformimagination.cpp
@@ -22,30 +22,22 @@ Importer *Importer::CreateInstance(DrmDevice *drm) {
return importer;
}
-int ImaginationImporter::ImportBuffer(buffer_handle_t handle,
- hwc_drm_bo_t *bo) {
+int ImaginationImporter::ConvertBoInfo(buffer_handle_t handle,
+ hwc_drm_bo_t *bo) {
IMG_native_handle_t *hnd = (IMG_native_handle_t *)handle;
if (!hnd)
return -EINVAL;
- uint32_t gem_handle;
- int ret = drmPrimeFDToHandle(drm_->fd(), hnd->fd[0], &gem_handle);
- if (ret) {
- ALOGE("failed to import prime fd %d ret=%d", hnd->fd[0], ret);
- return ret;
- }
-
/* Extra bits are responsible for buffer compression and memory layout */
if (hnd->iFormat & ~0x10f) {
- ALOGE("Special buffer formats are not supported");
+ ALOGV("Special buffer formats are not supported");
return -EINVAL;
}
- memset(bo, 0, sizeof(hwc_drm_bo_t));
bo->width = hnd->iWidth;
bo->height = hnd->iHeight;
bo->usage = hnd->usage;
- bo->gem_handles[0] = gem_handle;
+ bo->prime_fds[0] = hnd->fd[0];
bo->pitches[0] = ALIGN(hnd->iWidth, HW_ALIGN) * hnd->uiBpp >> 3;
switch (hnd->iFormat) {
@@ -57,20 +49,11 @@ int ImaginationImporter::ImportBuffer(buffer_handle_t handle,
default:
bo->format = ConvertHalFormatToDrm(hnd->iFormat & 0xf);
if (bo->format == DRM_FORMAT_INVALID) {
- ALOGE("Cannot convert hal format to drm format %u", hnd->iFormat);
+ ALOGV("Cannot convert hal format to drm format %u", hnd->iFormat);
return -EINVAL;
}
}
- ret = drmModeAddFB2(drm_->fd(), bo->width, bo->height, bo->format,
- bo->gem_handles, bo->pitches, bo->offsets, &bo->fb_id, 0);
- if (ret) {
- ALOGE("could not create drm fb ret: %d", ret);
- return ret;
- }
-
- ImportHandle(gem_handle);
-
return 0;
}
diff --git a/platform/platformimagination.h b/platform/platformimagination.h
index 85dfc45..f2a7cb7 100644
--- a/platform/platformimagination.h
+++ b/platform/platformimagination.h
@@ -15,7 +15,7 @@ class ImaginationImporter : public DrmGenericImporter {
public:
using DrmGenericImporter::DrmGenericImporter;
- int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+ int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
};
} // namespace android
diff --git a/platform/platformmeson.cpp b/platform/platformmeson.cpp
index 7b7a1f1..ad3aff1 100644
--- a/platform/platformmeson.cpp
+++ b/platform/platformmeson.cpp
@@ -75,33 +75,21 @@ uint64_t MesonImporter::ConvertGrallocFormatToDrmModifiers(
}
#endif
-int MesonImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
- uint64_t modifiers[4] = {0};
-
- memset(bo, 0, sizeof(hwc_drm_bo_t));
-
+int MesonImporter::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>(
handle);
if (!hnd)
return -EINVAL;
- // We can't import these types of buffers.
- // These buffers should have been filtered out with CanImportBuffer()
if (!(hnd->usage & GRALLOC_USAGE_HW_FB))
return -EINVAL;
- uint32_t gem_handle;
- int ret = drmPrimeFDToHandle(drm_->fd(), hnd->share_fd, &gem_handle);
- if (ret) {
- ALOGE("failed to import prime fd %d ret=%d", hnd->share_fd, ret);
- return ret;
- }
-
uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
if (fmt == DRM_FORMAT_INVALID)
return -EINVAL;
- modifiers[0] = ConvertGrallocFormatToDrmModifiers(hnd->internal_format);
+ bo->modifiers[0] = MesonImporter::ConvertGrallocFormatToDrmModifiers(
+ hnd->internal_format);
bo->width = hnd->width;
bo->height = hnd->height;
@@ -109,29 +97,13 @@ int MesonImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
bo->format = fmt;
bo->usage = hnd->usage;
bo->pixel_stride = hnd->stride;
+ bo->prime_fds[0] = hnd->share_fd;
bo->pitches[0] = hnd->byte_stride;
- bo->gem_handles[0] = gem_handle;
bo->offsets[0] = 0;
- ret = drmModeAddFB2WithModifiers(drm_->fd(), bo->width, bo->height,
- bo->format, bo->gem_handles, bo->pitches,
- bo->offsets, modifiers, &bo->fb_id,
- modifiers[0] ? DRM_MODE_FB_MODIFIERS : 0);
-
- if (ret) {
- ALOGE("could not create drm fb %d", ret);
- return ret;
- }
-
- ImportHandle(gem_handle);
-
- return ret;
-}
+ bo->with_modifiers = true;
-bool MesonImporter::CanImportBuffer(buffer_handle_t handle) {
- private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>(
- handle);
- return hnd && (hnd->usage & GRALLOC_USAGE_HW_FB);
+ return 0;
}
std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) {
diff --git a/platform/platformmeson.h b/platform/platformmeson.h
index 7be7702..f29b796 100644
--- a/platform/platformmeson.h
+++ b/platform/platformmeson.h
@@ -31,8 +31,7 @@ class MesonImporter : public DrmGenericImporter {
public:
using DrmGenericImporter::DrmGenericImporter;
- int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
- bool CanImportBuffer(buffer_handle_t handle) override;
+ int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
private:
uint64_t ConvertGrallocFormatToDrmModifiers(uint64_t flags);
diff --git a/platform/platformminigbm.cpp b/platform/platformminigbm.cpp
index cb1e110..df195d3 100644
--- a/platform/platformminigbm.cpp
+++ b/platform/platformminigbm.cpp
@@ -44,39 +44,23 @@ Importer *Importer::CreateInstance(DrmDevice *drm) {
return importer;
}
-int DrmMinigbmImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
+int DrmMinigbmImporter::ConvertBoInfo(buffer_handle_t handle,
+ hwc_drm_bo_t *bo) {
cros_gralloc_handle *gr_handle = (cros_gralloc_handle *)handle;
if (!gr_handle)
return -EINVAL;
- uint32_t gem_handle;
- int ret = drmPrimeFDToHandle(drm_->fd(), gr_handle->fds[0], &gem_handle);
- if (ret) {
- ALOGE("failed to import prime fd %d ret=%d", gr_handle->fds[0], ret);
- return ret;
- }
-
- memset(bo, 0, sizeof(hwc_drm_bo_t));
bo->width = gr_handle->width;
bo->height = gr_handle->height;
bo->hal_format = gr_handle->droid_format;
bo->format = gr_handle->format;
bo->usage = gr_handle->usage;
bo->pixel_stride = gr_handle->pixel_stride;
+ bo->prime_fds[0] = gr_handle->fds[0];
bo->pitches[0] = gr_handle->strides[0];
bo->offsets[0] = gr_handle->offsets[0];
- bo->gem_handles[0] = gem_handle;
-
- ret = drmModeAddFB2(drm_->fd(), bo->width, bo->height, bo->format,
- bo->gem_handles, bo->pitches, bo->offsets, &bo->fb_id, 0);
- if (ret) {
- ALOGE("could not create drm fb %d", ret);
- return ret;
- }
-
- ImportHandle(gem_handle);
- return ret;
+ return 0;
}
std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) {
diff --git a/platform/platformminigbm.h b/platform/platformminigbm.h
index ff69f14..053b2aa 100644
--- a/platform/platformminigbm.h
+++ b/platform/platformminigbm.h
@@ -28,7 +28,7 @@ namespace android {
class DrmMinigbmImporter : public DrmGenericImporter {
public:
using DrmGenericImporter::DrmGenericImporter;
- int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+ int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
};
} // namespace android