[PATCH weston v2 1/4] simple-dmabuf-drm: allow multiple backends
Guido Günther
agx at sigxcpu.org
Thu Mar 15 16:33:18 UTC 2018
This allows to enable freedreno and intel backends at the same time
building the prerequisites for adding further ones.
---
Makefile.am | 5 ++++-
clients/simple-dmabuf-drm.c | 53 +++++++++++++++++++++++++--------------------
configure.ac | 24 +++++++++++---------
3 files changed, 47 insertions(+), 35 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index e028a2a1..c2d448e7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -624,7 +624,10 @@ nodist_weston_simple_dmabuf_drm_SOURCES = \
protocol/linux-dmabuf-unstable-v1-protocol.c \
protocol/linux-dmabuf-unstable-v1-client-protocol.h
weston_simple_dmabuf_drm_CFLAGS = $(AM_CFLAGS) $(SIMPLE_DMABUF_DRM_CLIENT_CFLAGS)
-weston_simple_dmabuf_drm_LDADD = $(SIMPLE_DMABUF_DRM_CLIENT_LIBS) $(LIBDRM_PLATFORM_LIBS) libshared.la
+weston_simple_dmabuf_drm_LDADD = $(SIMPLE_DMABUF_DRM_CLIENT_LIBS) \
+ $(LIBDRM_PLATFORM_FREEDRENO_LIBS) \
+ $(LIBDRM_PLATFORM_INTEL_LIBS) \
+ libshared.la
endif
if BUILD_SIMPLE_DMABUF_V4L_CLIENT
diff --git a/clients/simple-dmabuf-drm.c b/clients/simple-dmabuf-drm.c
index 14d716de..51ad51f8 100644
--- a/clients/simple-dmabuf-drm.c
+++ b/clients/simple-dmabuf-drm.c
@@ -44,7 +44,8 @@
#ifdef HAVE_LIBDRM_INTEL
#include <i915_drm.h>
#include <intel_bufmgr.h>
-#elif HAVE_LIBDRM_FREEDRENO
+#endif
+#ifdef HAVE_LIBDRM_FREEDRENO
#include <freedreno/freedreno_drmif.h>
#endif
#include <drm_fourcc.h>
@@ -93,10 +94,11 @@ struct buffer {
#ifdef HAVE_LIBDRM_INTEL
drm_intel_bufmgr *bufmgr;
- drm_intel_bo *bo;
-#elif HAVE_LIBDRM_FREEDRENO
+ drm_intel_bo *intel_bo;
+#endif /* HAVE_LIBDRM_INTEL */
+#if HAVE_LIBDRM_FREEDRENO
struct fd_device *fd_dev;
- struct fd_bo *bo;
+ struct fd_bo *fd_bo;
#endif /* HAVE_LIBDRM_FREEDRENO */
uint32_t gem_handle;
@@ -152,15 +154,15 @@ intel_alloc_bo(struct buffer *my_buf)
assert(my_buf->bufmgr);
- my_buf->bo = drm_intel_bo_alloc_tiled(my_buf->bufmgr, "test",
- my_buf->width, my_buf->height,
- (my_buf->bpp / 8), &tiling,
- &my_buf->stride, 0);
+ my_buf->intel_bo = drm_intel_bo_alloc_tiled(my_buf->bufmgr, "test",
+ my_buf->width, my_buf->height,
+ (my_buf->bpp / 8), &tiling,
+ &my_buf->stride, 0);
printf("buffer allocated w %d, h %d, stride %lu, size %lu\n",
- my_buf->width, my_buf->height, my_buf->stride, my_buf->bo->size);
+ my_buf->width, my_buf->height, my_buf->stride, my_buf->intel_bo->size);
- if (!my_buf->bo)
+ if (!my_buf->intel_bo)
return 0;
if (tiling != I915_TILING_NONE)
@@ -172,16 +174,16 @@ intel_alloc_bo(struct buffer *my_buf)
static void
intel_free_bo(struct buffer *my_buf)
{
- drm_intel_bo_unreference(my_buf->bo);
+ drm_intel_bo_unreference(my_buf->intel_bo);
}
static int
intel_map_bo(struct buffer *my_buf)
{
- if (drm_intel_gem_bo_map_gtt(my_buf->bo) != 0)
+ if (drm_intel_gem_bo_map_gtt(my_buf->intel_bo) != 0)
return 0;
- my_buf->mmap = my_buf->bo->virtual;
+ my_buf->mmap = my_buf->intel_bo->virtual;
return 1;
}
@@ -189,15 +191,16 @@ intel_map_bo(struct buffer *my_buf)
static int
intel_bo_export_to_prime(struct buffer *buffer)
{
- return drm_intel_bo_gem_export_to_prime(buffer->bo, &buffer->dmabuf_fd);
+ return drm_intel_bo_gem_export_to_prime(buffer->intel_bo, &buffer->dmabuf_fd);
}
static void
intel_unmap_bo(struct buffer *my_buf)
{
- drm_intel_gem_bo_unmap_gtt(my_buf->bo);
+ drm_intel_gem_bo_unmap_gtt(my_buf->intel_bo);
}
-#elif HAVE_LIBDRM_FREEDRENO
+#endif /* HAVE_LIBDRM_INTEL */
+#ifdef HAVE_LIBDRM_FREEDRENO
#define ALIGN(v, a) ((v + a - 1) & ~(a - 1))
static
@@ -207,9 +210,9 @@ int fd_alloc_bo(struct buffer *buf)
int size = buf->width * buf->height * buf->bpp / 8;
buf->fd_dev = fd_device_new(buf->drm_fd);
- buf->bo = fd_bo_new(buf->fd_dev, size, flags);
+ buf->fd_bo = fd_bo_new(buf->fd_dev, size, flags);
- if (!buf->bo)
+ if (!buf->fd_bo)
return 0;
buf->stride = ALIGN(buf->width, 32) * buf->bpp / 8;
return 1;
@@ -218,13 +221,13 @@ int fd_alloc_bo(struct buffer *buf)
static
void fd_free_bo(struct buffer *buf)
{
- fd_bo_del(buf->bo);
+ fd_bo_del(buf->fd_bo);
}
static
int fd_bo_export_to_prime(struct buffer *buf)
{
- buf->dmabuf_fd = fd_bo_dmabuf(buf->bo);
+ buf->dmabuf_fd = fd_bo_dmabuf(buf->fd_bo);
if (buf->dmabuf_fd > 0)
return 0;
@@ -234,7 +237,7 @@ int fd_bo_export_to_prime(struct buffer *buf)
static
int fd_map_bo(struct buffer *buf)
{
- buf->mmap = fd_bo_map(buf->bo);
+ buf->mmap = fd_bo_map(buf->fd_bo);
if (buf->mmap != NULL)
return 1;
@@ -246,7 +249,7 @@ static
void fd_unmap_bo(struct buffer *buf)
{
}
-#endif
+#endif /* HAVE_LIBDRM_FREEDRENO */
static void
fill_content(struct buffer *my_buf)
@@ -278,7 +281,8 @@ drm_device_destroy(struct buffer *buf)
{
#ifdef HAVE_LIBDRM_INTEL
drm_intel_bufmgr_destroy(buf->bufmgr);
-#elif HAVE_LIBDRM_FREEDRENO
+#endif
+#ifdef HAVE_LIBDRM_FREEDRENO
fd_device_del(buf->fd_dev);
#endif
@@ -308,7 +312,8 @@ drm_device_init(struct buffer *buf)
dev->map_bo = intel_map_bo;
dev->unmap_bo = intel_unmap_bo;
}
-#elif HAVE_LIBDRM_FREEDRENO
+#endif
+#ifdef HAVE_LIBDRM_FREEDRENO
else if (!strcmp(dev->name, "msm")) {
dev->alloc_bo = fd_alloc_bo;
dev->free_bo = fd_free_bo;
diff --git a/configure.ac b/configure.ac
index 0b326ccc..dc2fbe93 100644
--- a/configure.ac
+++ b/configure.ac
@@ -384,19 +384,23 @@ AC_ARG_ENABLE(simple-dmabuf-drm-client,
[do not build the simple dmabuf drm client]),,
enable_simple_dmabuf_drm_client="auto")
if ! test "x$enable_simple_dmabuf_drm_client" = "xno"; then
- PKG_CHECK_MODULES(SIMPLE_DMABUF_DRM_CLIENT, [wayland-client libdrm egl],
- [PKG_CHECK_MODULES(LIBDRM_PLATFORM, [libdrm_freedreno],
- AC_DEFINE([HAVE_LIBDRM_FREEDRENO], [1], [Build freedreno dmabuf client]) have_simple_dmabuf_drm_client=freedreno,
- [PKG_CHECK_MODULES(LIBDRM_PLATFORM, [libdrm_intel],
- AC_DEFINE([HAVE_LIBDRM_INTEL], [1], [Build intel dmabuf client]) have_simple_dmabuf_drm_client=intel,
- have_simple_dmabuf_drm_client=unsupported)])],
- have_simple_dmabuf_drm_client=unsupported)
-
- if test "x$have_simple_dmabuf_drm_client" = "xunsupported" -a "x$enable_simple_dmabuf_drm_client" = "xyes"; then
+ PKG_CHECK_MODULES(SIMPLE_DMABUF_DRM_CLIENT, [wayland-client libdrm egl], [have_simple_dmabuf_libs=yes],
+ [have_simple_dmabuf_libs=no])
+
+ PKG_CHECK_MODULES(LIBDRM_PLATFORM_FREEDRENO, [libdrm_freedreno],
+ AC_DEFINE([HAVE_LIBDRM_FREEDRENO], [1], [Build freedreno dmabuf client]) have_simple_dmabuf_drm_client=yes,
+ [true])
+ PKG_CHECK_MODULES(LIBDRM_PLATFORM_INTEL, [libdrm_intel],
+ AC_DEFINE([HAVE_LIBDRM_INTEL], [1], [Build intel dmabuf client]) have_simple_dmabuf_drm_client=yes,
+ [true])
+
+ if test "x$have_simple_dmabuf_drm_client" != "xyes" -o \
+ "x$have_simple_dmabuf_libs" = "xno" && \
+ "x$enable_simple_dmabuf_drm_client" = "xyes"; then
AC_MSG_ERROR([DRM dmabuf client explicitly enabled, but libdrm_intel or libdrm_freedreno not found])
fi
- if test "x$have_simple_dmabuf_drm_client" = "xfreedreno" -o "x$have_simple_dmabuf_drm_client" = "xintel"; then
+ if test "x$have_simple_dmabuf_drm_client" = "xyes" -a "x$have_simple_dmabuf_libs"; then
enable_simple_dmabuf_drm_client="yes"
fi
fi
--
2.16.1
More information about the wayland-devel
mailing list