Skip to content
This repository was archived by the owner on Jan 7, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 9 additions & 47 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,28 @@
// found in the LICENSE file.

cc_defaults {
name: "gralloc.minigbm_intel_defaults",
name: "gralloc.minigbm_intel_defaults_pri",
cflags: ["-DDRV_I915"],
}

cc_defaults {
name: "gralloc.minigbm_meson_defaults",
cflags: ["-DDRV_MESON"],
}

cc_defaults {
name: "gralloc.minigbm_defaults",
name: "gralloc.minigbm_defaults_pri",

srcs: [
"amdgpu.c",
"drv.c",
"evdi.c",
"exynos.c",
"helpers_array.c",
"helpers.c",
"i915.c",
"marvell.c",
"mediatek.c",
"meson.c",
"msm.c",
"nouveau.c",
"radeon.c",
"rockchip.c",
"tegra.c",
"udl.c",
"vc4.c",
"vgem.c",
"virtio_gpu.c",

// for i915 private
"i915_private.c",
"cros_gralloc/i915_private_android.cc",

"cros_gralloc/cros_gralloc_buffer.cc",
"cros_gralloc/cros_gralloc_driver.cc",
"cros_gralloc/cros_gralloc_helpers.cc",
Expand Down Expand Up @@ -76,15 +65,10 @@ cc_defaults {
}

cc_library_shared {
name: "gralloc.minigbm",
defaults: ["gralloc.minigbm_defaults"],
}

cc_library_shared {
name: "gralloc.minigbm_intel",
name: "gralloc.intel",
defaults: [
"gralloc.minigbm_defaults",
"gralloc.minigbm_intel_defaults",
"gralloc.minigbm_defaults_pri",
"gralloc.minigbm_intel_defaults_pri",
],
enabled: false,
arch: {
Expand All @@ -96,25 +80,3 @@ cc_library_shared {
},
},
}

cc_library_shared {
name: "gralloc.minigbm_meson",
defaults: [
"gralloc.minigbm_defaults",
"gralloc.minigbm_meson_defaults",
],
}

cc_library_shared {
name: "libminigbm",
defaults: ["gralloc.minigbm_defaults"],
shared_libs: ["liblog"],
static_libs: ["libdrm"],

srcs: [
"gbm.c",
"gbm_helpers.c",
],

export_include_dirs: ["."],
}
31 changes: 25 additions & 6 deletions cros_gralloc/cros_gralloc_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,27 @@ int32_t cros_gralloc_driver::init()
continue;

version = drmGetVersion(fd);
if (!version)
if (!version) {
close(fd);
continue;
}

if (undesired[i] && !strcmp(version->name, undesired[i])) {
drmFreeVersion(version);
close(fd);
continue;
}

drmFreeVersion(version);
drv_ = drv_create(fd);
if (drv_)

if (drv_) {
return 0;
}
else {
close(fd);
continue;
}
}
}

Expand Down Expand Up @@ -232,12 +241,22 @@ int32_t cros_gralloc_driver::release(buffer_handle_t handle)

auto buffer = get_buffer(hnd);
if (!buffer) {
drv_log("Invalid Reference.\n");
return -EINVAL;
uint32_t id = -1;
if (drmPrimeFDToHandle(drv_get_fd(drv_), hnd->fds[0], &id)) {
drv_log("drmPrimeFDToHandle failed.");
return -errno;
}
if (buffers_.count(id)) {
buffer = buffers_[id];
buffer->increase_refcount();
} else {
drv_log("Could not found reference");
return -EINVAL;
}
}

if (!--handles_[hnd].second)
else if (!--handles_[hnd].second) {
handles_.erase(hnd);
}

if (buffer->decrease_refcount() == 0) {
buffers_.erase(buffer->get_id());
Expand Down
13 changes: 12 additions & 1 deletion cros_gralloc/cros_gralloc_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@
*/

#include "cros_gralloc_helpers.h"
#include "i915_private_android.h"

#include <sync/sync.h>
#include <stdio.h>

const char* drmFormat2Str(int drm_format)
{
static char buf[5];
char *pDrmFormat = (char*) &drm_format;
snprintf(buf, sizeof(buf), "%c%c%c%c", *pDrmFormat, *(pDrmFormat + 1),
*(pDrmFormat + 2), *(pDrmFormat + 3));
return buf;
}

uint32_t cros_gralloc_convert_format(int format)
{
Expand Down Expand Up @@ -41,7 +52,7 @@ uint32_t cros_gralloc_convert_format(int format)
return DRM_FORMAT_R8;
}

return DRM_FORMAT_NONE;
return i915_private_convert_format(format);
}

cros_gralloc_handle_t cros_gralloc_convert_handle(buffer_handle_t handle)
Expand Down
1 change: 1 addition & 0 deletions cros_gralloc/cros_gralloc_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ constexpr uint32_t cros_gralloc_magic = 0xABCDDCBA;
constexpr uint32_t handle_data_size =
((sizeof(struct cros_gralloc_handle) - offsetof(cros_gralloc_handle, fds[0])) / sizeof(int));

const char *drmFormat2Str(int format);
uint32_t cros_gralloc_convert_format(int32_t format);

cros_gralloc_handle_t cros_gralloc_convert_handle(buffer_handle_t handle);
Expand Down
10 changes: 7 additions & 3 deletions cros_gralloc/gralloc0/gralloc0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include "../cros_gralloc_driver.h"
#include "../i915_private_android.h"

#include <cassert>
#include <hardware/gralloc.h>
Expand Down Expand Up @@ -115,7 +116,7 @@ static int gralloc0_alloc(alloc_device_t *dev, int w, int h, int format, int usa
if (!supported) {
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),
format, usage, drmFormat2Str(descriptor.drm_format),
static_cast<unsigned long long>(descriptor.use_flags));
return -EINVAL;
}
Expand Down Expand Up @@ -179,13 +180,15 @@ static int gralloc0_open(const struct hw_module_t *mod, const char *name, struct
return 0;
}

if (strcmp(name, GRALLOC_HARDWARE_GPU0)) {
if (strcmp(name, GRALLOC_HARDWARE_GPU0) != 0 && strcmp(name, GRALLOC_HARDWARE_MODULE_ID) != 0) {
drv_log("Incorrect device name - %s.\n", name);
return -EINVAL;
}

if (gralloc0_init(module, true))
if (gralloc0_init(module, true)) {
drv_log("gralloc0_init failed");
return -ENODEV;
}

*dev = &module->alloc->common;
return 0;
Expand Down Expand Up @@ -372,6 +375,7 @@ static int gralloc0_lock_async_ycbcr(struct gralloc_module_t const *module, buff

switch (hnd->format) {
case DRM_FORMAT_NV12:
case DRM_FORMAT_NV12_Y_TILED_INTEL:
ycbcr->y = addr[0];
ycbcr->cb = addr[1];
ycbcr->cr = addr[1] + 1;
Expand Down
116 changes: 116 additions & 0 deletions cros_gralloc/i915_private_android.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright 2017 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.
*/

#ifdef DRV_I915

#include "i915_private_android.h"
#include "i915_private_android_types.h"

#include "cros_gralloc_helpers.h"

#include <hardware/gralloc.h>

uint32_t i915_private_convert_format(int format)
{
switch (format) {
case HAL_PIXEL_FORMAT_NV12:
return DRM_FORMAT_NV12;
case HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL:
return DRM_FORMAT_NV12_Y_TILED_INTEL;
case HAL_PIXEL_FORMAT_YCbCr_422_I:
return DRM_FORMAT_YUYV;
case HAL_PIXEL_FORMAT_Y16:
return DRM_FORMAT_R16;
case HAL_PIXEL_FORMAT_YCbCr_444_888:
return DRM_FORMAT_YUV444;
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
return DRM_FORMAT_NV21;
case HAL_PIXEL_FORMAT_YCbCr_422_SP:
return DRM_FORMAT_NV16;
case HAL_PIXEL_FORMAT_YCbCr_422_888:
return DRM_FORMAT_YUV422;
case HAL_PIXEL_FORMAT_P010_INTEL:
return DRM_FORMAT_P010;
case HAL_PIXEL_FORMAT_RGBA_1010102:
return DRM_FORMAT_ABGR2101010;
case HAL_PIXEL_FORMAT_RGBA_FP16:
return DRM_FORMAT_ABGR16161616F;
}

return DRM_FORMAT_NONE;
}

#if 0
int32_t i915_private_invert_format(int format)
{
/* Convert the DRM FourCC into the most specific HAL pixel format. */
switch (format) {
case DRM_FORMAT_ARGB8888:
return HAL_PIXEL_FORMAT_BGRA_8888;
case DRM_FORMAT_RGB565:
return HAL_PIXEL_FORMAT_RGB_565;
case DRM_FORMAT_RGB888:
return HAL_PIXEL_FORMAT_RGB_888;
case DRM_FORMAT_ABGR8888:
return HAL_PIXEL_FORMAT_RGBA_8888;
case DRM_FORMAT_XBGR8888:
return HAL_PIXEL_FORMAT_RGBX_8888;
case DRM_FORMAT_FLEX_YCbCr_420_888:
return HAL_PIXEL_FORMAT_YCbCr_420_888;
case DRM_FORMAT_YVU420_ANDROID:
return HAL_PIXEL_FORMAT_YV12;
case DRM_FORMAT_R8:
return HAL_PIXEL_FORMAT_BLOB;
case DRM_FORMAT_NV12:
return HAL_PIXEL_FORMAT_NV12;
case DRM_FORMAT_NV12_Y_TILED_INTEL:
return HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL;
case DRM_FORMAT_YUYV:
return HAL_PIXEL_FORMAT_YCbCr_422_I;
case DRM_FORMAT_R16:
return HAL_PIXEL_FORMAT_Y16;
case DRM_FORMAT_P010:
return HAL_PIXEL_FORMAT_P010_INTEL;
case DRM_FORMAT_YUV444:
return HAL_PIXEL_FORMAT_YCbCr_444_888;
case DRM_FORMAT_NV21:
return HAL_PIXEL_FORMAT_YCrCb_420_SP;
case DRM_FORMAT_NV16:
return HAL_PIXEL_FORMAT_YCbCr_422_SP;
case DRM_FORMAT_YUV422:
return HAL_PIXEL_FORMAT_YCbCr_422_888;
case DRM_FORMAT_ABGR2101010:
return HAL_PIXEL_FORMAT_RGBA_1010102;
case DRM_FORMAT_ABGR16161616F:
return HAL_PIXEL_FORMAT_RGBA_FP16;
default:
cros_gralloc_error("Unhandled DRM format %4.4s", drmFormat2Str(format));
}

return 0;
}

bool i915_private_supported_yuv_format(uint32_t droid_format)
{
switch (droid_format) {
case HAL_PIXEL_FORMAT_NV12:
case HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL:
case HAL_PIXEL_FORMAT_YCbCr_422_I:
case HAL_PIXEL_FORMAT_YCbCr_422_888:
case HAL_PIXEL_FORMAT_YCbCr_444_888:
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
case HAL_PIXEL_FORMAT_Y16:
case HAL_PIXEL_FORMAT_P010_INTEL:
return true;
default:
return false;
}

return false;
}
#endif

#endif
19 changes: 19 additions & 0 deletions cros_gralloc/i915_private_android.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2017 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.
*/

#ifdef DRV_I915

#include <stdint.h>

#include "i915_private.h"

uint32_t i915_private_convert_format(int format);

int32_t i915_private_invert_format(int format);

bool i915_private_supported_yuv_format(uint32_t droid_format);

#endif
Loading