aboutsummaryrefslogtreecommitdiff
path: root/bufferinfo/legacy/BufferInfoMinigbm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'bufferinfo/legacy/BufferInfoMinigbm.cpp')
-rw-r--r--bufferinfo/legacy/BufferInfoMinigbm.cpp101
1 files changed, 89 insertions, 12 deletions
diff --git a/bufferinfo/legacy/BufferInfoMinigbm.cpp b/bufferinfo/legacy/BufferInfoMinigbm.cpp
index 860de08..777c2b7 100644
--- a/bufferinfo/legacy/BufferInfoMinigbm.cpp
+++ b/bufferinfo/legacy/BufferInfoMinigbm.cpp
@@ -18,29 +18,106 @@
#include "BufferInfoMinigbm.h"
-#include <log/log.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
-#include "cros_gralloc_handle.h"
+#include <cerrno>
+#include <cstring>
+#include "utils/log.h"
namespace android {
LEGACY_BUFFER_INFO_GETTER(BufferInfoMinigbm);
+constexpr int CROS_GRALLOC_DRM_GET_FORMAT = 1;
+constexpr int CROS_GRALLOC_DRM_GET_DIMENSIONS = 2;
+constexpr int CROS_GRALLOC_DRM_GET_BUFFER_INFO = 4;
+constexpr int CROS_GRALLOC_DRM_GET_USAGE = 5;
+
+struct cros_gralloc0_buffer_info {
+ uint32_t drm_fourcc;
+ int num_fds;
+ int fds[4];
+ uint64_t modifier;
+ int offset[4];
+ int stride[4];
+};
+
int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
- cros_gralloc_handle *gr_handle = (cros_gralloc_handle *)handle;
- if (!gr_handle)
+ if (handle == nullptr) {
+ return -EINVAL;
+ }
+
+ uint32_t width{};
+ uint32_t height{};
+ if (gralloc_->perform(gralloc_, CROS_GRALLOC_DRM_GET_DIMENSIONS, handle,
+ &width, &height) != 0) {
+ ALOGE(
+ "CROS_GRALLOC_DRM_GET_DIMENSIONS operation has failed. "
+ "Please ensure you are using the latest minigbm.");
+ return -EINVAL;
+ }
+
+ int32_t droid_format{};
+ if (gralloc_->perform(gralloc_, CROS_GRALLOC_DRM_GET_FORMAT, handle,
+ &droid_format) != 0) {
+ ALOGE(
+ "CROS_GRALLOC_DRM_GET_FORMAT operation has failed. "
+ "Please ensure you are using the latest minigbm.");
return -EINVAL;
+ }
+
+ uint32_t usage{};
+ if (gralloc_->perform(gralloc_, CROS_GRALLOC_DRM_GET_USAGE, handle, &usage) !=
+ 0) {
+ ALOGE(
+ "CROS_GRALLOC_DRM_GET_USAGE operation has failed. "
+ "Please ensure you are using the latest minigbm.");
+ return -EINVAL;
+ }
+
+ struct cros_gralloc0_buffer_info info {};
+ if (gralloc_->perform(gralloc_, CROS_GRALLOC_DRM_GET_BUFFER_INFO, handle,
+ &info) != 0) {
+ ALOGE(
+ "CROS_GRALLOC_DRM_GET_BUFFER_INFO operation has failed. "
+ "Please ensure you are using the latest minigbm.");
+ return -EINVAL;
+ }
+
+ bo->width = width;
+ bo->height = height;
- 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->prime_fds[0] = gr_handle->fds[0];
- bo->pitches[0] = gr_handle->strides[0];
- bo->offsets[0] = gr_handle->offsets[0];
+ bo->hal_format = droid_format;
+
+ bo->format = info.drm_fourcc;
+ bo->usage = usage;
+
+ for (int i = 0; i < info.num_fds; i++) {
+ bo->modifiers[i] = info.modifier;
+ bo->prime_fds[i] = info.fds[i];
+ bo->pitches[i] = info.stride[i];
+ bo->offsets[i] = info.offset[i];
+ }
+
+ return 0;
+}
+
+constexpr char cros_gralloc_module_name[] = "CrOS Gralloc";
+
+int BufferInfoMinigbm::ValidateGralloc() {
+ if (strcmp(gralloc_->common.name, cros_gralloc_module_name) != 0) {
+ ALOGE("Gralloc name isn't valid: Expected: \"%s\", Actual: \"%s\"",
+ cros_gralloc_module_name, gralloc_->common.name);
+ return -EINVAL;
+ }
+
+ if (gralloc_->perform == nullptr) {
+ ALOGE(
+ "CrOS gralloc has no perform call implemented. Please upgrade your "
+ "minigbm.");
+ return -EINVAL;
+ }
return 0;
}