summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChangyeon Lee <cyeon.lee@samsung.com>2022-06-22 17:35:38 +0900
committerChangyeon Lee <cyeon.lee@samsung.com>2022-06-22 17:35:38 +0900
commita3e1d70f263d794a0a35b4c463677dc3db673d6f (patch)
tree1508ea80db25f84658de43483da94377be53e27e
parent47d7b27a682308755ca253e31f33608e0aa009a3 (diff)
downloadlibtdm-vc4-a3e1d70f263d794a0a35b4c463677dc3db673d6f.tar.gz
libtdm-vc4-a3e1d70f263d794a0a35b4c463677dc3db673d6f.tar.bz2
libtdm-vc4-a3e1d70f263d794a0a35b4c463677dc3db673d6f.zip
Change-Id: Iac872b98d96b2f3edca98149accfc9d4db58cd3c
-rw-r--r--configure.ac40
-rw-r--r--packaging/hal-backend-tdm-vc4.manifest (renamed from packaging/libhal-backend-tdm-vc4.manifest)0
-rw-r--r--packaging/hal-backend-tdm-vc4.spec (renamed from packaging/libtdm-vc4.spec)38
-rw-r--r--packaging/libtdm-vc4.manifest5
-rw-r--r--src/Makefile.am17
-rw-r--r--src/libhal-backend-tdm-vc4/Makefile.am16
-rw-r--r--src/libtdm-vc4/Makefile.am15
-rw-r--r--src/libtdm-vc4/tdm_vc4.c477
-rw-r--r--src/libtdm-vc4/tdm_vc4.h137
-rw-r--r--src/libtdm-vc4/tdm_vc4_display.c2472
-rw-r--r--src/libtdm-vc4/tdm_vc4_format.c134
-rw-r--r--src/libtdm-vc4/tdm_vc4_hwc.c1053
-rw-r--r--src/libtdm-vc4/tdm_vc4_hwc.h39
-rw-r--r--src/libtdm-vc4/tdm_vc4_hwc_window.c204
-rw-r--r--src/libtdm-vc4/tdm_vc4_hwc_window.h36
-rw-r--r--src/libtdm-vc4/tdm_vc4_types.h318
-rw-r--r--src/tdm_backend_list.h (renamed from src/libhal-backend-tdm-vc4/tdm_backend_list.h)0
-rw-r--r--src/tdm_backend_log.c (renamed from src/libhal-backend-tdm-vc4/tdm_backend_log.c)0
-rw-r--r--src/tdm_backend_log.h (renamed from src/libhal-backend-tdm-vc4/tdm_backend_log.h)0
-rw-r--r--src/tdm_backend_vc4.c (renamed from src/libhal-backend-tdm-vc4/tdm_backend_vc4.c)0
-rw-r--r--src/tdm_backend_vc4.h (renamed from src/libhal-backend-tdm-vc4/tdm_backend_vc4.h)0
-rw-r--r--src/tdm_backend_vc4_types.h (renamed from src/libhal-backend-tdm-vc4/tdm_backend_vc4_types.h)0
-rw-r--r--src/tdm_vc4_display.c (renamed from src/libhal-backend-tdm-vc4/tdm_vc4_display.c)0
-rw-r--r--src/tdm_vc4_format.c (renamed from src/libhal-backend-tdm-vc4/tdm_vc4_format.c)0
-rw-r--r--src/tdm_vc4_hwc.c (renamed from src/libhal-backend-tdm-vc4/tdm_vc4_hwc.c)0
-rw-r--r--src/tdm_vc4_hwc_window.c (renamed from src/libhal-backend-tdm-vc4/tdm_vc4_hwc_window.c)0
26 files changed, 27 insertions, 4974 deletions
diff --git a/configure.ac b/configure.ac
index 1f5541d..9f38f12 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,8 +1,8 @@
AC_PREREQ([2.60])
-AC_INIT([libtdm-vc4],
+AC_INIT([hal-backend-tdm-vc4],
[0.1.0],
[https://www.tizen.org],
- [libtdm-vc4])
+ [hal-backend-tdm-vc4])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_SRCDIR([Makefile.am])
@@ -23,30 +23,16 @@ LT_INIT([disable-static])
# Enable quiet compiles on automake 1.11.
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
-# for libtdm-vc4
-PKG_CHECK_MODULES(TDM_VC4, libtdm libtbm [libdrm >= 2.4.47] pixman-1)
-
-# for libhal-backend-tdm-vc4
PKG_CHECK_MODULES(LIBHAL_BACKEND_TDM_VC4, hal-api-common hal-api-tdm hal-api-tbm libdrm dlog pixman-1 libtbm)
PKG_CHECK_MODULES(UDEV, libudev, [udev=yes], [udev=no])
if test x"$udev" = xyes; then
AC_DEFINE(HAVE_UDEV,1,[Enable udev-based monitor hotplug detection])
- # for libtdm-vc4
- TDM_VC4_CFLAGS="$TDM_VC4_CFLAGS $UDEV_CFLAGS"
- TDM_VC4_LIBS="$TDM_VC4_LIBS $UDEV_LIBS"
-
- # for libhal-backend-tdm-vc4
LIBHAL_BACKEND_TDM_VC4_CFLAGS="$LIBHAL_BACKEND_TDM_VC4_CFLAGS $UDEV_CFLAGS"
LIBHAL_BACKEND_TDM_VC4_LIBS="$LIBHAL_BACKEND_TDM_VC4_LIBS $UDEV_LIBS"
fi
-# for libtdm-vc4
-AC_SUBST(TDM_VC4_CFLAGS)
-AC_SUBST(TDM_VC4_LIBS)
-
-# for libhal-backend-tdm-vc4
AC_SUBST(LIBHAL_BACKEND_TDM_VC4_CFLAGS)
AC_SUBST(LIBHAL_BACKEND_TDM_VC4_LIBS)
@@ -57,13 +43,6 @@ AC_DEFINE_UNQUOTED(LIBDRM_MINOR_VERSION, [`pkg-config --modversion libdrm | cut
AC_DEFINE_UNQUOTED(LIBDRM_MICRO_VERSION, [`pkg-config --modversion libdrm | cut -d '.' -f 3`], dnl
[libdrm major version])
-# set the dir for the tdm module
-DEFAULT_TDM_MODULE_PATH="${libdir}/tdm"
-AC_ARG_WITH(tdm-module-path, AS_HELP_STRING([--with-tdm-module-path=PATH], [tdm module dir]),
- [ TDM_MODULE_PATH="$withval" ],
- [ TDM_MODULE_PATH="${DEFAULT_TDM_MODULE_PATH}" ])
-AC_SUBST(TDM_MODULE_PATH)
-
# set the library dir for the tdm hal backend
DEFAULT_HAL_LIBDIR="/hal/lib"
AC_ARG_WITH(hal-libdir, AS_HELP_STRING([--with-hal-libdir=PATH], [hal backend library path]),
@@ -75,21 +54,12 @@ AC_SUBST(HAL_LIBDIR)
# For enumerating devices in test case
AC_OUTPUT([
Makefile
- src/libhal-backend-tdm-vc4/Makefile
- src/libtdm-vc4/Makefile
src/Makefile])
echo ""
echo "$PACKAGE_STRING will be compiled with:"
echo ""
-echo "TDM_VC4_CFLAGS : $LIBHAL_BACKEND_TDM_VC4_CFLAGS"
-echo "TDM_VC4_LIBS : $LIBHAL_BACKEND_TDM_VC4_LIBS"
-echo "TDM_MODULE_DIR : $HAL_LIBDIR"
-echo ""
-echo ""
-echo "$PACKAGE_STRING will be compiled with:"
-echo ""
-echo "TDM_VC4_CFLAGS : $TDM_VC4_CFLAGS"
-echo "TDM_VC4_LIBS : $TDM_VC4_LIBS"
-echo "TDM_MODULE_DIR : $TDM_MODULE_PATH"
+echo "LIBHAL_BACKEND_TDM_VC4_CFLAGS : $LIBHAL_BACKEND_TDM_VC4_CFLAGS"
+echo "LIBHAL_BACKEND_TDM_VC4_LIBS : $LIBHAL_BACKEND_TDM_VC4_LIBS"
+echo "HAL_LIBDIR : $HAL_LIBDIR"
echo ""
diff --git a/packaging/libhal-backend-tdm-vc4.manifest b/packaging/hal-backend-tdm-vc4.manifest
index 75b0fa5..75b0fa5 100644
--- a/packaging/libhal-backend-tdm-vc4.manifest
+++ b/packaging/hal-backend-tdm-vc4.manifest
diff --git a/packaging/libtdm-vc4.spec b/packaging/hal-backend-tdm-vc4.spec
index d9b06b7..6c6ff08 100644
--- a/packaging/libtdm-vc4.spec
+++ b/packaging/hal-backend-tdm-vc4.spec
@@ -1,17 +1,15 @@
-Name: libtdm-vc4
+Name: hal-backend-tdm-vc4
Version: 2.1.1
Release: 0
-Summary: Tizen Display Manager VC4 Back-End Library
-Group: Development/Libraries
+Summary: hal-backend-tdm module for vc4
+Group: System/Libraries
License: MIT
Source0: %{name}-%{version}.tar.gz
-Source1001: %{name}.manifest
-Source1002: libhal-backend-tdm-vc4.manifest
+Source1001: %{name}.manifest
BuildRequires: pkgconfig(libdrm)
BuildRequires: pkgconfig(libudev)
BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(libtdm)
BuildRequires: pkgconfig(libtbm)
BuildRequires: pkgconfig(hal-api-common)
BuildRequires: pkgconfig(hal-api-tdm)
@@ -20,23 +18,13 @@ BuildRequires: pkgconfig(pixman-1)
ExclusiveArch: %{arm} aarch64
%description
-Back-End library of Tizen Display Manager VC4 : libtdm-mgr VC4 library
-
-%package -n hal-backend-tdm-vc4
-Summary: hal-backend-tdm module for vc4
-Group: System/Libraries
-Requires: hal-api-tdm
-Requires: hal-api-common
-
-%description -n hal-backend-tdm-vc4
-descriptionion: hal tdm backend module for vc4
+description: hal tdm backend module for vc4
%global TZ_SYS_RO_SHARE %{?TZ_SYS_RO_SHARE:%TZ_SYS_RO_SHARE}%{!?TZ_SYS_RO_SHARE:/usr/share}
%prep
%setup -q
cp %{SOURCE1001} .
-cp %{SOURCE1002} .
%build
%reconfigure --prefix=%{_prefix} --libdir=%{_libdir} --disable-static \
@@ -54,28 +42,14 @@ mkdir -p %{buildroot}%{_hal_licensedir}/libhal-backend-tdm-vc4
cp -af COPYING %{buildroot}%{_hal_licensedir}/libhal-backend-tdm-vc4
%post
-if [ -f %{_libdir}/tdm/libtdm-default.so ]; then
- rm -rf %{_libdir}/tdm/libtdm-default.so
-fi
-ln -s libtdm-vc4.so %{_libdir}/tdm/libtdm-default.so
-
-%postun -p /sbin/ldconfig
-
-%post -n hal-backend-tdm-vc4
if [ -f %{_hal_libdir}/libhal-backend-tdm.so ]; then
rm -rf %{_hal_libdir}/libhal-backend-tdm.so
fi
ln -s libhal-backend-tdm-vc4.so %{_hal_libdir}/libhal-backend-tdm.so
-%postun -n hal-backend-tdm-vc4 -p /sbin/ldconfig
+%postun -p /sbin/ldconfig
%files
-%defattr(-,root,root,-)
%manifest %{name}.manifest
-%license COPYING
-%{_libdir}/tdm/libtdm-vc4.so
-
-%files -n hal-backend-tdm-vc4
-%manifest libhal-backend-tdm-vc4.manifest
%{_hal_licensedir}/libhal-backend-tdm-vc4/COPYING
%{_hal_libdir}/libhal-backend-*.so*
diff --git a/packaging/libtdm-vc4.manifest b/packaging/libtdm-vc4.manifest
deleted file mode 100644
index 75b0fa5..0000000
--- a/packaging/libtdm-vc4.manifest
+++ /dev/null
@@ -1,5 +0,0 @@
-<manifest>
- <request>
- <domain name="_"/>
- </request>
-</manifest>
diff --git a/src/Makefile.am b/src/Makefile.am
index dea3f73..67be190 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1 +1,16 @@
-SUBDIRS = libtdm-vc4 libhal-backend-tdm-vc4
+AM_CFLAGS = \
+ $(LIBHAL_BACKEND_TDM_VC4_CFLAGS) \
+ -I$(top_srcdir)/src
+
+libhal_backend_tdm_vc4_la_LTLIBRARIES = libhal-backend-tdm-vc4.la
+libhal_backend_tdm_vc4_ladir = @HAL_LIBDIR@
+libhal_backend_tdm_vc4_la_LDFLAGS = -module -avoid-version
+libhal_backend_tdm_vc4_la_LIBADD = $(LIBHAL_BACKEND_TDM_VC4_LIBS) -ldl
+
+libhal_backend_tdm_vc4_la_SOURCES = \
+ tdm_backend_log.c \
+ tdm_backend_vc4.c \
+ tdm_vc4_display.c \
+ tdm_vc4_format.c \
+ tdm_vc4_hwc_window.c \
+ tdm_vc4_hwc.c
diff --git a/src/libhal-backend-tdm-vc4/Makefile.am b/src/libhal-backend-tdm-vc4/Makefile.am
deleted file mode 100644
index 12c0def..0000000
--- a/src/libhal-backend-tdm-vc4/Makefile.am
+++ /dev/null
@@ -1,16 +0,0 @@
-AM_CFLAGS = \
- $(LIBHAL_BACKEND_TDM_VC4_CFLAGS) \
- -I$(top_srcdir)/src/libhal-backend-tdm-vc4
-
-libhal_backend_tdm_vc4_la_LTLIBRARIES = libhal-backend-tdm-vc4.la
-libhal_backend_tdm_vc4_ladir = @HAL_LIBDIR@
-libhal_backend_tdm_vc4_la_LDFLAGS = -module -avoid-version
-libhal_backend_tdm_vc4_la_LIBADD = $(LIBHAL_BACKEND_TDM_VC4_LIBS) -ldl
-
-libhal_backend_tdm_vc4_la_SOURCES = \
- tdm_backend_log.c \
- tdm_backend_vc4.c \
- tdm_vc4_display.c \
- tdm_vc4_format.c \
- tdm_vc4_hwc_window.c \
- tdm_vc4_hwc.c
diff --git a/src/libtdm-vc4/Makefile.am b/src/libtdm-vc4/Makefile.am
deleted file mode 100644
index 592ade3..0000000
--- a/src/libtdm-vc4/Makefile.am
+++ /dev/null
@@ -1,15 +0,0 @@
-AM_CFLAGS = \
- $(TDM_VC4_CFLAGS) \
- -I$(top_srcdir)/src
-
-libtdm_vc4_la_LTLIBRARIES = libtdm-vc4.la
-libtdm_vc4_ladir = $(TDM_MODULE_PATH)
-libtdm_vc4_la_LDFLAGS = -module -avoid-version
-libtdm_vc4_la_LIBADD = $(TDM_VC4_LIBS) -ldl
-
-libtdm_vc4_la_SOURCES = \
- tdm_vc4_hwc_window.c \
- tdm_vc4_hwc.c \
- tdm_vc4_format.c \
- tdm_vc4_display.c \
- tdm_vc4.c
diff --git a/src/libtdm-vc4/tdm_vc4.c b/src/libtdm-vc4/tdm_vc4.c
deleted file mode 100644
index 74ccc10..0000000
--- a/src/libtdm-vc4/tdm_vc4.c
+++ /dev/null
@@ -1,477 +0,0 @@
-/**************************************************************************
-
-libtdm_vc4
-
-Copyright 2017 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: SooChan Lim <sc1.lim@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#if HAVE_UDEV
-#include <libudev.h>
-#endif
-
-#include "tdm_vc4.h"
-#include <tdm_helper.h>
-#include <tbm_drm_helper.h>
-
-#define TDM_DRM_NAME "vc4-drm"
-
-static tdm_vc4_data *vc4_data;
-
-#ifdef HAVE_UDEV
-static struct udev_device *
-_tdm_find_primary_gpu(void)
-{
- struct udev *udev;
- struct udev_enumerate *e;
- struct udev_list_entry *entry;
- const char *path, *id;
- struct udev_device *device, *drm_device, *pci;
-
- udev = udev_new();
- if (!udev) {
- TDM_ERR("fail to initialize udev context\n");
- return NULL;
- }
-
- e = udev_enumerate_new(udev);
- udev_enumerate_add_match_subsystem(e, "drm");
- udev_enumerate_add_match_sysname(e, "card[0-9]*");
-
- udev_enumerate_scan_devices(e);
- drm_device = NULL;
- udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
- path = udev_list_entry_get_name(entry);
- device = udev_device_new_from_syspath(udev, path);
- if (!device)
- continue;
-
- pci = udev_device_get_parent_with_subsystem_devtype(device, "pci", NULL);
- if (pci) {
- id = udev_device_get_sysattr_value(pci, "boot_vga");
- if (id && !strcmp(id, "1")) {
- if (drm_device)
- udev_device_unref(drm_device);
- drm_device = device;
- break;
- }
- }
-
- if (!drm_device)
- drm_device = device;
- else
- udev_device_unref(device);
- }
-
- udev_enumerate_unref(e);
- return drm_device;
-}
-
-static tdm_error
-_tdm_vc4_udev_fd_handler(int fd, tdm_event_loop_mask mask, void *user_data)
-{
- tdm_vc4_data *edata = (tdm_vc4_data*)user_data;
- struct udev_device *dev;
- const char *hotplug;
- struct stat s;
- dev_t udev_devnum;
- int ret;
-
- dev = udev_monitor_receive_device(edata->uevent_monitor);
- if (!dev) {
- TDM_ERR("couldn't receive device");
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- udev_devnum = udev_device_get_devnum(dev);
-
- ret = fstat(edata->drm_fd, &s);
- if (ret == -1) {
- TDM_ERR("fstat failed");
- udev_device_unref(dev);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- hotplug = udev_device_get_property_value(dev, "HOTPLUG");
-
- if (memcmp(&s.st_rdev, &udev_devnum, sizeof(dev_t)) == 0 &&
- hotplug && atoi(hotplug) == 1) {
- TDM_INFO("HotPlug");
- tdm_vc4_display_update_output_status(edata);
- }
-
- udev_device_unref(dev);
-
- return TDM_ERROR_NONE;
-}
-
-static void
-_tdm_vc4_udev_init(tdm_vc4_data *edata)
-{
- struct udev *u = NULL;
- struct udev_monitor *mon = NULL;
-
- u = udev_new();
- if (!u) {
- TDM_ERR("couldn't create udev");
- goto failed;
- }
-
- mon = udev_monitor_new_from_netlink(u, "udev");
- if (!mon) {
- TDM_ERR("couldn't create udev monitor");
- goto failed;
- }
-
- if (udev_monitor_filter_add_match_subsystem_devtype(mon, "drm", "drm_minor") > 0 ||
- udev_monitor_enable_receiving(mon) < 0) {
- TDM_ERR("add match subsystem failed");
- goto failed;
- }
-
- edata->uevent_source =
- tdm_event_loop_add_fd_handler(edata->dpy, udev_monitor_get_fd(mon),
- TDM_EVENT_LOOP_READABLE,
- _tdm_vc4_udev_fd_handler,
- edata, NULL);
- if (!edata->uevent_source) {
- TDM_ERR("couldn't create udev event source");
- goto failed;
- }
-
- edata->uevent_monitor = mon;
-
- TDM_INFO("hotplug monitor created");
-
- return;
-failed:
- if (mon)
- udev_monitor_unref(mon);
- if (u)
- udev_unref(u);
-}
-
-static void
-_tdm_vc4_udev_deinit(tdm_vc4_data *edata)
-{
- if (edata->uevent_source) {
- tdm_event_loop_source_remove(edata->uevent_source);
- edata->uevent_source = NULL;
- }
-
- if (edata->uevent_monitor) {
- struct udev *u = udev_monitor_get_udev(edata->uevent_monitor);
- udev_monitor_unref(edata->uevent_monitor);
- udev_unref(u);
- edata->uevent_monitor = NULL;
- TDM_INFO("hotplug monitor destroyed");
- }
-}
-#endif
-
-static int
-_tdm_vc4_open_drm(void)
-{
- int fd = -1;
-
- fd = drmOpen(TDM_DRM_NAME, NULL);
- if (fd < 0)
- TDM_WRN("Cannot open '%s' drm", TDM_DRM_NAME);
-
-#ifdef HAVE_UDEV
- if (fd < 0) {
- struct udev_device *drm_device = NULL;
- const char *filename;
- TDM_WRN("Cannot open drm device.. search by udev");
-
- drm_device = _tdm_find_primary_gpu();
- if (drm_device == NULL) {
- TDM_ERR("fail to find drm device\n");
- goto close_l;
- }
-
- filename = udev_device_get_devnode(drm_device);
-
- fd = open(filename, O_RDWR | O_CLOEXEC);
- if (fd < 0)
- TDM_ERR("Cannot open drm device(%s)\n", filename);
-
- TDM_DBG("open drm device (name:%s, fd:%d)", filename, fd);
-
- udev_device_unref(drm_device);
- }
-close_l:
-#endif
- return fd;
-}
-
-void
-tdm_vc4_deinit(tdm_backend_data *bdata)
-{
- if (vc4_data != bdata)
- return;
-
- TDM_INFO("deinit");
-
-#ifdef HAVE_UDEV
- _tdm_vc4_udev_deinit(vc4_data);
-#endif
-
- tdm_vc4_display_destroy_output_list(vc4_data);
- tdm_vc4_data_destroy_buffer_list(vc4_data);
-
- if (vc4_data->plane_res)
- drmModeFreePlaneResources(vc4_data->plane_res);
- if (vc4_data->mode_res)
- drmModeFreeResources(vc4_data->mode_res);
- if (vc4_data->drm_fd >= 0)
- close(vc4_data->drm_fd);
-
- free(vc4_data);
- vc4_data = NULL;
-}
-
-tdm_backend_data *
-tdm_vc4_init(tdm_display *dpy, tdm_error *error)
-{
- tdm_func_display vc4_func_display;
- tdm_func_output vc4_func_output;
- tdm_func_layer vc4_func_layer;
- tdm_func_hwc vc4_func_hwc;
- tdm_func_hwc_window vc4_func_hwc_window;
- tdm_error ret;
-
- if (!dpy) {
- TDM_ERR("display is null");
- if (error)
- *error = TDM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- if (vc4_data) {
- TDM_ERR("failed: init twice");
- if (error)
- *error = TDM_ERROR_BAD_REQUEST;
- return NULL;
- }
-
- vc4_data = calloc(1, sizeof(tdm_vc4_data));
- if (!vc4_data) {
- TDM_ERR("alloc failed");
- if (error)
- *error = TDM_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
-
- /* enable the tdm_hwc */
- vc4_data->hwc_mode = 1;
-
- LIST_INITHEAD(&vc4_data->output_list);
- LIST_INITHEAD(&vc4_data->buffer_list);
-
- memset(&vc4_func_display, 0, sizeof(vc4_func_display));
- vc4_func_display.display_get_capability = vc4_display_get_capability;
- vc4_func_display.display_get_outputs = vc4_display_get_outputs;
- vc4_func_display.display_get_fd = vc4_display_get_fd;
- vc4_func_display.display_handle_events = vc4_display_handle_events;
-
- memset(&vc4_func_output, 0, sizeof(vc4_func_output));
- vc4_func_output.output_get_capability = vc4_output_get_capability;
- vc4_func_output.output_get_layers = vc4_output_get_layers;
- vc4_func_output.output_set_property = vc4_output_set_property;
- vc4_func_output.output_get_property = vc4_output_get_property;
- vc4_func_output.output_wait_vblank = vc4_output_wait_vblank;
- vc4_func_output.output_set_vblank_handler = vc4_output_set_vblank_handler;
- vc4_func_output.output_commit = vc4_output_commit;
- vc4_func_output.output_set_commit_handler = vc4_output_set_commit_handler;
- vc4_func_output.output_set_dpms = vc4_output_set_dpms;
- vc4_func_output.output_get_dpms = vc4_output_get_dpms;
- vc4_func_output.output_set_mode = vc4_output_set_mode;
- vc4_func_output.output_get_mode = vc4_output_get_mode;
- vc4_func_output.output_set_mirror = vc4_output_set_mirror;
- vc4_func_output.output_unset_mirror = vc4_output_unset_mirror;
-#ifdef HAVE_UDEV
- vc4_func_output.output_set_status_handler = vc4_output_set_status_handler;
-#endif
- if (vc4_data->hwc_mode) {
- vc4_func_output.output_get_hwc = vc4_output_get_hwc;
-
- memset(&vc4_func_hwc, 0, sizeof(vc4_func_hwc));
- vc4_func_hwc.hwc_create_window = vc4_hwc_create_window;
- vc4_func_hwc.hwc_get_video_supported_formats = vc4_hwc_get_video_supported_formats;
- vc4_func_hwc.hwc_get_video_available_properties = NULL;
- vc4_func_hwc.hwc_get_capabilities = vc4_hwc_get_capabilities;
- vc4_func_hwc.hwc_get_available_properties = vc4_hwc_get_available_properties;
- vc4_func_hwc.hwc_get_client_target_buffer_queue = vc4_hwc_get_client_target_buffer_queue;
- vc4_func_hwc.hwc_set_client_target_buffer = vc4_hwc_set_client_target_buffer;
- vc4_func_hwc.hwc_set_client_target_acquire_fence = vc4_hwc_set_client_target_acquire_fence;
- vc4_func_hwc.hwc_validate = vc4_hwc_validate;
- vc4_func_hwc.hwc_get_changed_composition_types = vc4_hwc_get_changed_composition_types;
- vc4_func_hwc.hwc_accept_validation = vc4_hwc_accept_validation;
- vc4_func_hwc.hwc_commit = vc4_hwc_commit;
- vc4_func_hwc.hwc_set_commit_handler = vc4_hwc_set_commit_handler;
- vc4_func_hwc.hwc_get_commit_fence = vc4_hwc_get_commit_fence;
- vc4_func_hwc.hwc_get_release_fences = vc4_hwc_get_release_fences;
-
- memset(&vc4_func_hwc_window, 0, sizeof(vc4_func_hwc_window));
- vc4_func_hwc_window.hwc_window_destroy = vc4_hwc_window_destroy;
- vc4_func_hwc_window.hwc_window_acquire_buffer_queue = NULL; // no need
- vc4_func_hwc_window.hwc_window_release_buffer_queue = NULL; // no need
- vc4_func_hwc_window.hwc_window_set_composition_type = vc4_hwc_window_set_composition_type;
- vc4_func_hwc_window.hwc_window_set_buffer_damage = vc4_hwc_window_set_buffer_damage;
- vc4_func_hwc_window.hwc_window_set_info = vc4_hwc_window_set_info;
- vc4_func_hwc_window.hwc_window_set_buffer = vc4_hwc_window_set_buffer;
- vc4_func_hwc_window.hwc_window_set_property = vc4_hwc_window_set_property;
- vc4_func_hwc_window.hwc_window_get_property = vc4_hwc_window_get_property;
- vc4_func_hwc_window.hwc_window_get_constraints = vc4_hwc_window_get_constraints;
- vc4_func_hwc_window.hwc_window_set_name = vc4_hwc_window_set_name;
- vc4_func_hwc_window.hwc_window_set_cursor_image = vc4_hwc_window_set_cursor_image;
- vc4_func_hwc_window.hwc_window_set_acquire_fence = vc4_hwc_window_set_acquire_fence;
- }
-
- memset(&vc4_func_layer, 0, sizeof(vc4_func_layer));
- vc4_func_layer.layer_get_capability = vc4_layer_data_get_capability;
- vc4_func_layer.layer_set_property = vc4_layer_set_property;
- vc4_func_layer.layer_get_property = vc4_layer_data_get_property;
- vc4_func_layer.layer_set_info = vc4_layer_set_info;
- vc4_func_layer.layer_get_info = vc4_layer_data_get_info;
- vc4_func_layer.layer_set_buffer = vc4_layer_set_buffer;
- vc4_func_layer.layer_unset_buffer = vc4_layer_unset_buffer;
-
- ret = tdm_backend_register_func_display(dpy, &vc4_func_display);
- if (ret != TDM_ERROR_NONE)
- goto failed;
-
- ret = tdm_backend_register_func_output(dpy, &vc4_func_output);
- if (ret != TDM_ERROR_NONE)
- goto failed;
-
- ret = tdm_backend_register_func_layer(dpy, &vc4_func_layer);
- if (ret != TDM_ERROR_NONE)
- goto failed;
-
- if (vc4_data->hwc_mode) {
- ret = tdm_backend_register_func_hwc(dpy, &vc4_func_hwc);
- if (ret != TDM_ERROR_NONE)
- goto failed;
-
- ret = tdm_backend_register_func_hwc_window(dpy, &vc4_func_hwc_window);
- if (ret != TDM_ERROR_NONE)
- goto failed;
- }
-
- vc4_data->dpy = dpy;
-
- /* The drm master fd can be opened by a tbm backend module in
- * tbm_bufmgr_init() time. In this case, we just get it from tbm.
- */
- vc4_data->drm_fd = tbm_drm_helper_get_master_fd();
- if (vc4_data->drm_fd < 0) {
- vc4_data->drm_fd = _tdm_vc4_open_drm();
-
- if (vc4_data->drm_fd < 0) {
- ret = TDM_ERROR_OPERATION_FAILED;
- goto failed;
- }
-
- tbm_drm_helper_set_tbm_master_fd(vc4_data->drm_fd);
- }
-
- TDM_INFO("master fd(%d)", vc4_data->drm_fd);
-
-#ifdef HAVE_UDEV
- _tdm_vc4_udev_init(vc4_data);
-#endif
-
-#if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4 && LIBDRM_MICRO_VERSION >= 47
- if (drmSetClientCap(vc4_data->drm_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1) < 0) {
- TDM_WRN("Set DRM_CLIENT_CAP_UNIVERSAL_PLANES failed");
- } else {
- TDM_INFO("has universal planes");
- vc4_data->has_universal_plane = 1;
- }
- if (drmSetClientCap(vc4_data->drm_fd, DRM_CLIENT_CAP_ATOMIC, 1) < 0) {
- TDM_WRN("Set DRM_CLIENT_CAP_ATOMIC failed");
- } else {
- TDM_INFO("has atomic");
- vc4_data->has_atomic = 1;
- }
-#endif
-
- vc4_data->mode_res = drmModeGetResources(vc4_data->drm_fd);
- if (!vc4_data->mode_res) {
- TDM_ERR("no drm resource: %m");
- ret = TDM_ERROR_OPERATION_FAILED;
- goto failed;
- }
-
- vc4_data->plane_res = drmModeGetPlaneResources(vc4_data->drm_fd);
- if (!vc4_data->plane_res) {
- TDM_ERR("no drm plane resource: %m");
- ret = TDM_ERROR_OPERATION_FAILED;
- goto failed;
- }
-
- if (vc4_data->plane_res->count_planes <= 0) {
- TDM_ERR("no drm plane resource");
- ret = TDM_ERROR_OPERATION_FAILED;
- goto failed;
- }
-
- ret = tdm_vc4_display_create_output_list(vc4_data);
- if (ret != TDM_ERROR_NONE)
- goto failed;
-
- ret = tdm_vc4_display_create_layer_list(vc4_data);
- if (ret != TDM_ERROR_NONE)
- goto failed;
-
- if (error)
- *error = TDM_ERROR_NONE;
-
- TDM_INFO("init success!");
-
- return (tdm_backend_data *)vc4_data;
-failed:
- if (error)
- *error = ret;
-
- tdm_vc4_deinit(vc4_data);
-
- TDM_ERR("init failed!");
- return NULL;
-}
-
-tdm_backend_module tdm_backend_module_data = {
- "vc4",
- "Samsung",
- TDM_BACKEND_SET_ABI_VERSION(2, 0),
- tdm_vc4_init,
- tdm_vc4_deinit
-};
diff --git a/src/libtdm-vc4/tdm_vc4.h b/src/libtdm-vc4/tdm_vc4.h
deleted file mode 100644
index 1787a55..0000000
--- a/src/libtdm-vc4/tdm_vc4.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/**************************************************************************
-
-libtdm_vc4
-
-Copyright 2017 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: SooChan Lim <sc1.lim@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#ifndef _TDM_VC4_H_
-#define _TDM_VC4_H_
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include <errno.h>
-#include <unistd.h>
-#include <limits.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-
-#include <xf86drm.h>
-#include <xf86drmMode.h>
-#include <tbm_surface.h>
-#include <tbm_surface_internal.h>
-#include <tbm_surface_queue.h>
-#include <tdm_backend.h>
-#include <tdm_log.h>
-#include <tdm_list.h>
-#include "tdm_vc4_types.h"
-#include "tdm_vc4_hwc.h"
-#include "tdm_vc4_hwc_window.h"
-
-#if HAVE_UDEV
-#include <libudev.h>
-#endif
-
-/* drm backend functions (display) */
-tdm_error vc4_display_get_capability(tdm_backend_data *bdata, tdm_caps_display *caps);
-tdm_output** vc4_display_get_outputs(tdm_backend_data *bdata, int *count, tdm_error *error);
-tdm_error vc4_display_get_fd(tdm_backend_data *bdata, int *fd);
-tdm_error vc4_display_handle_events(tdm_backend_data *bdata);
-tdm_error vc4_output_get_capability(tdm_output *output, tdm_caps_output *caps);
-tdm_layer** vc4_output_get_layers(tdm_output *output, int *count, tdm_error *error);
-tdm_error vc4_output_set_property(tdm_output *output, unsigned int id, tdm_value value);
-tdm_error vc4_output_get_property(tdm_output *output, unsigned int id, tdm_value *value);
-tdm_error vc4_output_wait_vblank(tdm_output *output, int interval, int sync, void *user_data);
-tdm_error vc4_output_set_vblank_handler(tdm_output *output, tdm_output_vblank_handler func);
-tdm_error vc4_output_commit(tdm_output *output, int sync, void *user_data);
-tdm_error vc4_output_set_commit_handler(tdm_output *output, tdm_output_commit_handler func);
-tdm_error vc4_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value);
-tdm_error vc4_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value);
-tdm_error vc4_output_set_mode(tdm_output *output, const tdm_output_mode *mode);
-tdm_error vc4_output_get_mode(tdm_output *output, const tdm_output_mode **mode);
-tdm_error vc4_output_set_mirror(tdm_output *output, tdm_output *src_output, tdm_transform transform);
-tdm_error vc4_output_unset_mirror(tdm_output *output);
-tdm_error vc4_output_set_status_handler(tdm_output *output, tdm_output_status_handler func, void *user_data);
-tdm_hwc *vc4_output_get_hwc(tdm_output *output, tdm_error *error);
-
-tdm_hwc_window *vc4_hwc_create_window(tdm_hwc *hwc, tdm_error *error);
-tdm_error vc4_hwc_get_video_supported_formats(tdm_hwc *hwc, const tbm_format **formats, int *count);
-tdm_error vc4_hwc_get_capabilities(tdm_hwc *hwc, tdm_hwc_capability *capabilities);
-tdm_error vc4_hwc_get_available_properties(tdm_hwc *hwc, const tdm_prop **props, int *count);
-tbm_surface_queue_h vc4_hwc_get_client_target_buffer_queue(tdm_hwc *hwc, tdm_error *error);
-tdm_error vc4_hwc_set_client_target_buffer(tdm_hwc *hwc, tbm_surface_h buffer, tdm_region damage);
-tdm_error vc4_hwc_set_client_target_acquire_fence(tdm_hwc *hwc, int acquire_fence);
-tdm_error vc4_hwc_validate(tdm_hwc *hwc, tdm_hwc_window **composited_wnds, uint32_t num_wnds, uint32_t *num_types);
-tdm_error vc4_hwc_get_changed_composition_types(tdm_hwc *hwc, uint32_t *num_elements, tdm_hwc_window **hwc_wnds, tdm_hwc_window_composition *composition_types);
-tdm_error vc4_hwc_accept_validation(tdm_hwc *hwc);
-tdm_error vc4_hwc_commit(tdm_hwc *hwc, int sync, void *user_data);
-tdm_error vc4_hwc_set_commit_handler(tdm_hwc *hwc, tdm_hwc_commit_handler func);
-tdm_error vc4_hwc_get_commit_fence(tdm_hwc *hwc, int *fence);
-tdm_error vc4_hwc_get_release_fences(tdm_hwc *hwc, uint32_t *num_elements, tdm_hwc_window **hwc_window, int *fences);
-
-void vc4_hwc_window_destroy(tdm_hwc_window *hwc_window);
-tdm_error vc4_hwc_window_set_composition_type(tdm_hwc_window *hwc_window, tdm_hwc_window_composition composition_type);
-tdm_error vc4_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_region damage);
-tdm_error vc4_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info);
-tdm_error vc4_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h surface);
-tdm_error vc4_hwc_window_set_property(tdm_hwc_window *hwc_window, unsigned int id, tdm_value value);
-tdm_error vc4_hwc_window_get_property(tdm_hwc_window *hwc_window, unsigned int id, tdm_value *value);
-tdm_error vc4_hwc_window_get_constraints(tdm_hwc_window *hwc_window, int *constraints);
-tdm_error vc4_hwc_window_set_name(tdm_hwc_window *hwc_window, const char *name);
-tdm_error vc4_hwc_window_set_cursor_image(tdm_hwc_window *hwc_window, int width, int height, int stride, void *ptr);
-tdm_error vc4_hwc_window_set_acquire_fence(tdm_hwc_window *hwc_window, int acquire_fence);
-
-tdm_error vc4_layer_data_get_capability(tdm_layer *layer, tdm_caps_layer *caps);
-tdm_error vc4_layer_set_property(tdm_layer *layer, unsigned int id, tdm_value value);
-tdm_error vc4_layer_data_get_property(tdm_layer *layer, unsigned int id, tdm_value *value);
-tdm_error vc4_layer_set_info(tdm_layer *layer, tdm_info_layer *info);
-tdm_error vc4_layer_data_get_info(tdm_layer *layer, tdm_info_layer *info);
-tdm_error vc4_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer);
-tdm_error vc4_layer_unset_buffer(tdm_layer *layer);
-tdm_error vc4_layer_data_get_buffer_flags(tdm_layer *layer, unsigned int *flags);
-tdm_error vc4_layer_set_acquire_fence(tdm_layer *layer, int acquire_fence);
-
-uint32_t tdm_vc4_format_to_drm_format(tbm_format format);
-tbm_format tdm_vc4_format_to_tbm_format(uint32_t format);
-
-void tdm_vc4_display_update_output_status(tdm_vc4_data *vc4_data);
-tdm_error tdm_vc4_display_create_output_list(tdm_vc4_data *vc4_data);
-void tdm_vc4_display_destroy_output_list(tdm_vc4_data *vc4_data);
-tdm_error tdm_vc4_display_create_layer_list(tdm_vc4_data *vc4_data);
-
-tdm_vc4_layer_data * vc4_output_data_get_layer_data(tdm_vc4_output_data *output_data, int layer_zops);
-tdm_error vc4_output_data_prepare_mirror_commit(tdm_vc4_output_data *output_data, tbm_surface_h surface);
-
-void tdm_vc4_data_destroy_buffer_list(tdm_vc4_data *vc4_data);
-#endif /* _TDM_VC4_H_ */
diff --git a/src/libtdm-vc4/tdm_vc4_display.c b/src/libtdm-vc4/tdm_vc4_display.c
deleted file mode 100644
index 4fbad9d..0000000
--- a/src/libtdm-vc4/tdm_vc4_display.c
+++ /dev/null
@@ -1,2472 +0,0 @@
-/**************************************************************************
-
-libtdm_vc4
-
-Copyright 2017 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: SooChan Lim <sc1.lim@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "tdm_vc4.h"
-
-#define LIST_INSERT_AFTER(__after, __item) \
- (__item)->prev = (__after); \
- (__item)->next = (__after)->next; \
- (__after)->next->prev = (__item); \
- (__after)->next = (__item);
-
-static drmModeModeInfoPtr
-_tdm_vc4_display_get_mode(tdm_vc4_output_data *output_data)
-{
- int i;
-
- if (!output_data->current_mode) {
- TDM_ERR("no output_data->current_mode");
- return NULL;
- }
-
- const tdm_output_mode *mode;
-
- mode = output_data->current_mode;
- TDM_INFO("Current mode: %s, %d, %d, %d, %d, %d",
- mode->name, mode->hdisplay, mode->vdisplay, mode->vrefresh, mode->flags, mode->type);
-
-
- TDM_INFO(" Count modes: %d %d", output_data->count_drm_modes, output_data->count_modes);
-
- for (i = 0; i < output_data->count_drm_modes; i++) {
- drmModeModeInfoPtr vc4_mode = &output_data->vc4_modes[i];
-
- TDM_INFO(" DRM mode: %s, %d, %d, %d, %d, %d",
- vc4_mode->name, vc4_mode->hdisplay, vc4_mode->vdisplay, vc4_mode->vrefresh, vc4_mode->flags, vc4_mode->type);
-
- if ((vc4_mode->hdisplay == output_data->current_mode->hdisplay) &&
- (vc4_mode->hsync_start == output_data->current_mode->hsync_start) &&
- (vc4_mode->hsync_end == output_data->current_mode->hsync_end) &&
- (vc4_mode->htotal == output_data->current_mode->htotal) &&
- (vc4_mode->hskew == output_data->current_mode->hskew) &&
- (vc4_mode->vdisplay == output_data->current_mode->vdisplay) &&
- (vc4_mode->vsync_start == output_data->current_mode->vsync_start) &&
- (vc4_mode->vsync_end == output_data->current_mode->vsync_end) &&
- (vc4_mode->vtotal == output_data->current_mode->vtotal) &&
- (vc4_mode->vscan == output_data->current_mode->vscan) &&
- (vc4_mode->clock == output_data->current_mode->clock) &&
- (vc4_mode->vrefresh == output_data->current_mode->vrefresh) &&
- (vc4_mode->flags == output_data->current_mode->flags) &&
- (vc4_mode->type == output_data->current_mode->type) &&
- !(strncmp(vc4_mode->name, output_data->current_mode->name, TDM_NAME_LEN)))
- return vc4_mode;
- }
-
- return NULL;
-}
-
-static tdm_error
-_tdm_vc4_display_set_fb(tdm_vc4_data *vc4_data, tbm_surface_h buffer, unsigned int *id)
-{
- unsigned int width;
- unsigned int height;
- unsigned int format;
- unsigned int handles[4] = {0,};
- unsigned int pitches[4] = {0,};
- unsigned int offsets[4] = {0,};
- unsigned int size;
- unsigned int fb_id;
- int ret, count, i;
-
- width = tbm_surface_get_width(buffer);
- height = tbm_surface_get_height(buffer);
- format = tbm_surface_get_format(buffer);
- count = tbm_surface_internal_get_num_bos(buffer);
- for (i = 0; i < count; i++) {
- tbm_bo bo = tbm_surface_internal_get_bo(buffer, i);
- handles[i] = tbm_bo_get_handle(bo, TBM_DEVICE_DEFAULT).u32;
- }
- count = tbm_surface_internal_get_num_planes(format);
- for (i = 0; i < count; i++)
- tbm_surface_internal_get_plane_data(buffer, i, &size, &offsets[i], &pitches[i]);
-
- TDM_DBG("AddFB2: drm_fd(%d) size(%dx%d) format(%c%c%c%c) handles(%d,%d,%d) pitches(%d,%d,%d) offsets(%d,%d,%d) buffer(%p)",
- vc4_data->drm_fd, width, height, FOURCC_STR(format),
- handles[0], handles[1], handles[2], pitches[0], pitches[1], pitches[2],
- offsets[0], offsets[1], offsets[2], buffer);
-
- ret = drmModeAddFB2(vc4_data->drm_fd, width, height, format,
- handles, pitches, offsets, &fb_id, 0);
- if (ret < 0) {
- TDM_ERR("add fb failed: %m");
- return TDM_ERROR_OPERATION_FAILED;
- }
- TDM_DBG("AddFB2 success: drm_fd(%d) fb_id(%u)", vc4_data->drm_fd, fb_id);
-
- *id = fb_id;
- return TDM_ERROR_NONE;
-}
-
-static tdm_error
-_tdm_vc4_output_update_status(tdm_vc4_output_data *output_data,
- tdm_output_conn_status status)
-{
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
-
- if (output_data->status == status)
- return TDM_ERROR_NONE;
-
- output_data->status = status;
-
- if (output_data->status_func)
- output_data->status_func(output_data, status,
- output_data->status_user_data);
-
- return TDM_ERROR_NONE;
-}
-
-static tdm_error
-_tdm_vc4_display_set_crtc(tdm_vc4_data *vc4_data, tdm_vc4_output_data *output_data, int set)
-{
- int ret;
-
- output_data->mode_changed = 0;
-
- if (set) {
- tbm_surface_h buffer = NULL;
- tbm_surface_info_s info;
- drmModeModeInfoPtr mode;
- unsigned int fb_id = 0;
-
- if (!output_data->current_mode)
- return TDM_ERROR_OPERATION_FAILED;
-
- mode = _tdm_vc4_display_get_mode(output_data);
- if (!mode) {
- TDM_ERR("couldn't find proper mode");
- return TDM_ERROR_BAD_REQUEST;
- }
-
- buffer = tbm_surface_create(output_data->current_mode->hdisplay,
- output_data->current_mode->vdisplay,
- TBM_FORMAT_XRGB8888);
- RETURN_VAL_IF_FAIL(buffer, TDM_ERROR_OPERATION_FAILED);
-
- if (tbm_surface_map(buffer, TBM_SURF_OPTION_WRITE, &info) != TBM_ERROR_NONE) {
- tbm_surface_destroy(buffer);
- return TDM_ERROR_OPERATION_FAILED;
- }
- memset(info.planes[0].ptr, 0x0, info.size);
-
- tbm_surface_unmap(buffer);
-
- if (_tdm_vc4_display_set_fb(vc4_data, buffer, &fb_id) != TDM_ERROR_NONE) {
- tbm_surface_destroy(buffer);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- TDM_DBG("drmModeSetCrtc drm_fd(%d) crtc_id(%u) fb_id(%u) mode(%u,%u)",
- vc4_data->drm_fd, output_data->crtc_id, fb_id,
- mode->hdisplay, mode->vdisplay);
-
- if (drmModeSetCrtc(vc4_data->drm_fd, output_data->crtc_id,
- fb_id, 0, 0,
- &output_data->connector_id, 1, mode)) {
- TDM_ERR("set crtc failed: %m");
- ret = drmModeRmFB(vc4_data->drm_fd, fb_id);
- if (ret < 0)
- TDM_ERR("rm fb failed fb_id(%u)", fb_id);
- tbm_surface_destroy(buffer);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- _tdm_vc4_output_update_status(output_data, TDM_OUTPUT_CONN_STATUS_MODE_SETTED);
- output_data->status = TDM_OUTPUT_CONN_STATUS_MODE_SETTED;
-
- if (output_data->crtc_buffer) {
- ret = drmModeRmFB(vc4_data->drm_fd, output_data->crtc_fb_id);
- if (ret < 0)
- TDM_ERR("rm fb failed fb_id(%u)", output_data->crtc_fb_id);
- tbm_surface_destroy(output_data->crtc_buffer);
- }
- output_data->crtc_buffer = buffer;
- output_data->crtc_fb_id = fb_id;
- } else {
- TDM_DBG("drmModeSetCrtc unset drm_fd(%d) crtc_id(%u)",
- vc4_data->drm_fd, output_data->crtc_id);
-
- if (drmModeSetCrtc(vc4_data->drm_fd, output_data->crtc_id,
- 0, 0, 0, NULL, 0, NULL)) {
- TDM_ERR("unset crtc failed: %m");
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- if (output_data->crtc_buffer) {
- ret = drmModeRmFB(vc4_data->drm_fd, output_data->crtc_fb_id);
- if (ret < 0)
- TDM_ERR("rm fb failed fb_id(%u)", output_data->crtc_fb_id);
- tbm_surface_destroy(output_data->crtc_buffer);
- }
- output_data->crtc_buffer = NULL;
- output_data->crtc_fb_id = 0;
- }
-
- return TDM_ERROR_NONE;
-}
-
-static void
-_tdm_vc4_display_to_tdm_mode(drmModeModeInfoPtr vc4_mode,
- tdm_output_mode *tdm_mode)
-{
- tdm_mode->clock = vc4_mode->clock;
- tdm_mode->hdisplay = vc4_mode->hdisplay;
- tdm_mode->hsync_start = vc4_mode->hsync_start;
- tdm_mode->hsync_end = vc4_mode->hsync_end;
- tdm_mode->htotal = vc4_mode->htotal;
- tdm_mode->hskew = vc4_mode->hskew;
- tdm_mode->vdisplay = vc4_mode->vdisplay;
- tdm_mode->vsync_start = vc4_mode->vsync_start;
- tdm_mode->vsync_end = vc4_mode->vsync_end;
- tdm_mode->vtotal = vc4_mode->vtotal;
- tdm_mode->vscan = vc4_mode->vscan;
- tdm_mode->vrefresh = vc4_mode->vrefresh;
- tdm_mode->flags = vc4_mode->flags;
- tdm_mode->type = vc4_mode->type;
- snprintf(tdm_mode->name, TDM_NAME_LEN, "%s", vc4_mode->name);
-}
-
-static tdm_error
-_tdm_vc4_display_get_cur_msc(int fd, int pipe, uint *msc)
-{
- drmVBlank vbl;
-
- vbl.request.type = DRM_VBLANK_RELATIVE;
- if (pipe == 1)
- vbl.request.type |= DRM_VBLANK_SECONDARY;
- else if (pipe > 1)
- vbl.request.type |= pipe << DRM_VBLANK_HIGH_CRTC_SHIFT;
-
- vbl.request.sequence = 0;
- if (drmWaitVBlank(fd, &vbl)) {
- TDM_ERR("get vblank counter failed: %m");
- *msc = 0;
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- *msc = vbl.reply.sequence;
-
- return TDM_ERROR_NONE;
-}
-
-static tdm_error
-_tdm_vc4_display_wait_vblank(int fd, int pipe, uint *target_msc, void *data)
-{
- drmVBlank vbl;
-
- vbl.request.type = DRM_VBLANK_ABSOLUTE | DRM_VBLANK_EVENT;
- if (pipe == 1)
- vbl.request.type |= DRM_VBLANK_SECONDARY;
- else if (pipe > 1)
- vbl.request.type |= pipe << DRM_VBLANK_HIGH_CRTC_SHIFT;
-
- vbl.request.sequence = *target_msc;
- vbl.request.signal = (unsigned long)(uintptr_t)data;
-
- if (drmWaitVBlank(fd, &vbl)) {
- TDM_ERR("wait vblank failed: %m");
- *target_msc = 0;
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- *target_msc = vbl.reply.sequence;
-
- return TDM_ERROR_NONE;
-}
-
-static tdm_error
-_tdm_vc4_display_commit_layer(tdm_vc4_layer_data *layer_data)
-{
- tdm_vc4_data *vc4_data = layer_data->vc4_data;
- tdm_vc4_output_data *output_data = layer_data->output_data;
- uint32_t fx, fy, fw, fh;
- int crtc_w;
-
- if (!layer_data->display_buffer_changed && !layer_data->info_changed)
- return TDM_ERROR_NONE;
-
- if (!output_data->crtc_enabled || output_data->mode_changed) {
- if (_tdm_vc4_display_set_crtc(vc4_data, output_data, 1) != TDM_ERROR_NONE)
- return TDM_ERROR_OPERATION_FAILED;
-
- output_data->crtc_enabled = 1;
- }
-
- if (output_data->current_mode)
- crtc_w = output_data->current_mode->hdisplay;
- else {
- drmModeCrtcPtr crtc = drmModeGetCrtc(vc4_data->drm_fd, output_data->crtc_id);
- if (!crtc) {
- TDM_ERR("getting crtc failed");
- return TDM_ERROR_OPERATION_FAILED;
- }
- crtc_w = crtc->width;
- if (crtc_w == 0) {
- TDM_ERR("getting crtc width failed");
- drmModeFreeCrtc(crtc);
- return TDM_ERROR_OPERATION_FAILED;
- }
- drmModeFreeCrtc(crtc);
- }
-
- layer_data->display_buffer_changed = 0;
- layer_data->info_changed = 0;
-
- if (!layer_data->display_buffer) {
- if (drmModeSetPlane(vc4_data->drm_fd, layer_data->plane_id,
- output_data->crtc_id, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
- TDM_ERR("unset plane(%d) filed: %m", layer_data->plane_id);
-
- return TDM_ERROR_NONE;
- }
-
- /* Source values are 16.16 fixed point */
- fx = ((unsigned int)layer_data->info.src_config.pos.x) << 16;
- fy = ((unsigned int)layer_data->info.src_config.pos.y) << 16;
- fw = ((unsigned int)layer_data->info.src_config.pos.w) << 16;
- fh = ((unsigned int)layer_data->info.src_config.pos.h) << 16;
-
- if (drmModeSetPlane(vc4_data->drm_fd, layer_data->plane_id,
- output_data->crtc_id, layer_data->display_buffer->fb_id, 0,
- layer_data->info.dst_pos.x, layer_data->info.dst_pos.y,
- layer_data->info.dst_pos.w, layer_data->info.dst_pos.h,
- fx, fy, fw, fh) < 0) {
- TDM_ERR("set plane(%d) failed: %m", layer_data->plane_id);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- TDM_DBG("plane(%d) crtc(%d) pos(%d) on: fb(%d,[%d,%d %dx%d]=>[%d,%d %dx%d])\n",
- layer_data->plane_id, output_data->crtc_id, layer_data->zpos,
- layer_data->display_buffer->fb_id,
- layer_data->info.src_config.pos.x, layer_data->info.src_config.pos.y,
- layer_data->info.src_config.pos.w, layer_data->info.src_config.pos.h,
- layer_data->info.dst_pos.x, layer_data->info.dst_pos.y,
- layer_data->info.dst_pos.w, layer_data->info.dst_pos.h);
-
- return TDM_ERROR_NONE;
-}
-
-static void
-_tdm_vc4_display_cb_event(int fd, unsigned int sequence,
- unsigned int tv_sec, unsigned int tv_usec,
- void *user_data)
-{
- tdm_vc4_event_data *event_data = user_data;
- tdm_vc4_output_data *output_data;
- tdm_vc4_hwc_data *hwc_data;
-
-
- if (!event_data) {
- TDM_ERR("no event data");
- return;
- }
-
- output_data = event_data->output_data;
-
-
- TDM_DBG("==== Atomic Commit Handler pipe, %u, crtc_id, %u connector_id, %u",
- output_data->pipe, output_data->crtc_id, output_data->connector_id);
-
- switch (event_data->type) {
- case TDM_DRM_EVENT_TYPE_PAGEFLIP:
- if (output_data->commit_func)
- output_data->commit_func(output_data, sequence, tv_sec, tv_usec,
- event_data->user_data);
- break;
- case TDM_DRM_EVENT_TYPE_WAIT:
- if (output_data->vblank_func)
- output_data->vblank_func(output_data, sequence, tv_sec, tv_usec,
- event_data->user_data);
- break;
- case TDM_DRM_EVENT_TYPE_COMMIT:
- if (output_data->hwc_enable) {
- hwc_data = output_data->hwc_data;
- if (!hwc_data) {
- TDM_ERR("no hwc_data");
- break;
- }
-
- if (hwc_data->commit_func)
- hwc_data->commit_func(hwc_data, sequence,
- tv_sec, tv_usec,
- event_data->user_data);
- } else {
- if (output_data->commit_func)
- output_data->commit_func(output_data, sequence,
- tv_sec, tv_usec,
- event_data->user_data);
- }
- break;
- default:
- break;
- }
-
- free(event_data);
-}
-
-static tdm_error
-_vc4_output_get_atomic_prop_id(int drm_fd, uint32_t object_id, uint32_t object_type, const char *name, uint32_t *id)
-{
- drmModeObjectPropertiesPtr properties = NULL;
- drmModePropertyPtr property = NULL;
- int i;
-
- properties = drmModeObjectGetProperties(drm_fd, object_id, object_type);
- if (properties == NULL) {
- TDM_ERR("drmModeObjectGetProperties failed");
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- for (i = 0; i < properties->count_props; i++) {
- property = drmModeGetProperty(drm_fd, properties->props[i]);
- if (property == NULL) {
- continue;
- }
-
- if (strcmp(property->name, name) == 0) {
- *id = property->prop_id;
- drmModeFreeProperty(property);
- break;
- }
- drmModeFreeProperty(property);
- }
-
- drmModeFreeObjectProperties(properties);
-
- return TDM_ERROR_NONE;
-}
-
-static tdm_error
-_tdm_vc4_display_create_layer_list(tdm_vc4_data *vc4_data)
-{
- tdm_vc4_output_data *output_data = NULL;
- int i;
-
- if (LIST_IS_EMPTY(&vc4_data->output_list)) {
- TDM_ERR("no output");
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- /* The TDM drm backend only support one output. */
- LIST_FOR_EACH_ENTRY(output_data, &vc4_data->output_list, link) {
- break;
- }
-
- if (vc4_data->plane_res->count_planes == 0) {
- TDM_ERR("no layer error");
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- for (i = 0; i < vc4_data->plane_res->count_planes; i++) {
- tdm_vc4_layer_data *layer_data;
- drmModePlanePtr plane;
-
- plane = drmModeGetPlane(vc4_data->drm_fd, vc4_data->plane_res->planes[i]);
- if (!plane) {
- TDM_ERR("no plane");
- continue;
- }
-
- if ((plane->possible_crtcs & (1 << output_data->pipe)) == 0) {
- drmModeFreePlane(plane);
- continue;
- }
-
- layer_data = calloc(1, sizeof(tdm_vc4_layer_data));
- if (!layer_data) {
- TDM_ERR("alloc failed");
- drmModeFreePlane(plane);
- continue;
- }
-
- layer_data->vc4_data = vc4_data;
- layer_data->output_data = output_data;
- layer_data->plane_id = vc4_data->plane_res->planes[i];
- layer_data->acquire_fence = -1;
-
- layer_data->capabilities = TDM_LAYER_CAPABILITY_PRIMARY |
- TDM_LAYER_CAPABILITY_GRAPHIC;
- output_data->primary_layer = layer_data;
-
- TDM_INFO("layer_data(%p) plane_id(%d) crtc_id(%d) capabilities(%x)",
- layer_data, layer_data->plane_id, layer_data->output_data->crtc_id,
- layer_data->capabilities);
-
- LIST_ADDTAIL(&layer_data->link, &output_data->layer_list);
-
- drmModeFreePlane(plane);
-
- /* can't take care of other planes for various hardware devices */
- break;
- }
-
- return TDM_ERROR_NONE;
-}
-
-#if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4 && LIBDRM_MICRO_VERSION >= 47
-
-static tdm_error
-_tdm_vc4_display_get_property(tdm_vc4_data *vc4_data,
- unsigned int obj_id, unsigned int obj_type,
- const char *name, unsigned int *value,
- int *is_immutable)
-{
- drmModeObjectPropertiesPtr props = NULL;
- int i;
-
- props = drmModeObjectGetProperties(vc4_data->drm_fd, obj_id, obj_type);
- if (!props)
- return TDM_ERROR_OPERATION_FAILED;
-
- for (i = 0; i < props->count_props; i++) {
- drmModePropertyPtr prop = drmModeGetProperty(vc4_data->drm_fd,
- props->props[i]);
-
- if (!prop)
- continue;
-
- if (!strcmp(prop->name, name)) {
- if (is_immutable)
- *is_immutable = prop->flags & DRM_MODE_PROP_IMMUTABLE;
- if (value)
- *value = (unsigned int)props->prop_values[i];
- drmModeFreeProperty(prop);
- drmModeFreeObjectProperties(props);
- return TDM_ERROR_NONE;
- }
-
- drmModeFreeProperty(prop);
- }
- drmModeFreeObjectProperties(props);
- TDM_DBG("coundn't find '%s' property", name);
- return TDM_ERROR_OPERATION_FAILED;
-}
-
-static tdm_error
-_tdm_vc4_display_create_layer_list_type(tdm_vc4_data *vc4_data)
-{
- drmModePlanePtr plane;
- tdm_error ret;
- int i;
-
- for (i = 0; i < vc4_data->plane_res->count_planes; i++) {
- tdm_vc4_output_data *output_data = NULL;
- tdm_vc4_layer_data *layer_data;
- unsigned int type = 0;
- int output_find = 0;
-
- plane = drmModeGetPlane(vc4_data->drm_fd, vc4_data->plane_res->planes[i]);
- if (!plane) {
- TDM_ERR("no plane");
- continue;
- }
-
- ret = _tdm_vc4_display_get_property(vc4_data,
- vc4_data->plane_res->planes[i],
- DRM_MODE_OBJECT_PLANE, "type", &type, NULL);
- if (ret != TDM_ERROR_NONE) {
- TDM_ERR("plane(%d) doesn't have 'type' info",
- vc4_data->plane_res->planes[i]);
- drmModeFreePlane(plane);
- continue;
- }
-
- layer_data = calloc(1, sizeof(tdm_vc4_layer_data));
- if (!layer_data) {
- TDM_ERR("alloc failed");
- drmModeFreePlane(plane);
- continue;
- }
-
- LIST_FOR_EACH_ENTRY(output_data, &vc4_data->output_list, link) {
- if (plane->possible_crtcs & (1 << output_data->pipe)) {
- output_find = 1;
- break;
- }
- }
-
- if (!output_find) {
- TDM_ERR("plane(%d) couldn't found proper output", plane->plane_id);
- drmModeFreePlane(plane);
- free(layer_data);
- continue;
- }
-
- layer_data->vc4_data = vc4_data;
- layer_data->output_data = output_data;
- layer_data->plane_id = vc4_data->plane_res->planes[i];
- layer_data->acquire_fence = -1;
-
- if (type == DRM_PLANE_TYPE_CURSOR) {
- layer_data->capabilities = TDM_LAYER_CAPABILITY_CURSOR |
- TDM_LAYER_CAPABILITY_GRAPHIC;
- layer_data->zpos = 2;
- } else if (type == DRM_PLANE_TYPE_OVERLAY) {
- layer_data->capabilities = TDM_LAYER_CAPABILITY_OVERLAY |
- TDM_LAYER_CAPABILITY_GRAPHIC;
- layer_data->zpos = 1;
- } else if (type == DRM_PLANE_TYPE_PRIMARY) {
- layer_data->capabilities = TDM_LAYER_CAPABILITY_PRIMARY |
- TDM_LAYER_CAPABILITY_GRAPHIC;
- layer_data->zpos = 0;
- output_data->primary_layer = layer_data;
- } else {
- drmModeFreePlane(plane);
- free(layer_data);
- continue;
- }
-
- TDM_INFO("layer_data(%p) plane_id(%d) crtc_id(%d) zpos(%d) capabilities(%x)",
- layer_data, layer_data->plane_id, layer_data->output_data->crtc_id,
- layer_data->zpos, layer_data->capabilities);
-
- LIST_ADDTAIL(&layer_data->link, &output_data->layer_list);
-
- /* get the atomic prop ids*/
- if (vc4_data->has_atomic) {
- ret = _vc4_output_get_atomic_prop_id(vc4_data->drm_fd, layer_data->plane_id,
- DRM_MODE_OBJECT_PLANE, "FB_ID", &layer_data->atomic_props_ids.fb_id);
- if (ret != TDM_ERROR_NONE) {
- free(layer_data);
- goto failed_atomic_prop_id;
- }
-
- ret = _vc4_output_get_atomic_prop_id(vc4_data->drm_fd, layer_data->plane_id,
- DRM_MODE_OBJECT_PLANE, "CRTC_ID", &layer_data->atomic_props_ids.crtc_id);
- if (ret != TDM_ERROR_NONE) {
- free(layer_data);
- goto failed_atomic_prop_id;
- }
-
- ret = _vc4_output_get_atomic_prop_id(vc4_data->drm_fd, layer_data->plane_id,
- DRM_MODE_OBJECT_PLANE, "SRC_X", &layer_data->atomic_props_ids.src_x);
- if (ret != TDM_ERROR_NONE) {
- free(layer_data);
- goto failed_atomic_prop_id;
- }
-
- ret = _vc4_output_get_atomic_prop_id(vc4_data->drm_fd, layer_data->plane_id,
- DRM_MODE_OBJECT_PLANE, "SRC_Y", &layer_data->atomic_props_ids.src_y);
- if (ret != TDM_ERROR_NONE) {
- free(layer_data);
- goto failed_atomic_prop_id;
- }
-
- ret = _vc4_output_get_atomic_prop_id(vc4_data->drm_fd, layer_data->plane_id,
- DRM_MODE_OBJECT_PLANE, "SRC_W", &layer_data->atomic_props_ids.src_w);
- if (ret != TDM_ERROR_NONE) {
- free(layer_data);
- goto failed_atomic_prop_id;
- }
-
- ret = _vc4_output_get_atomic_prop_id(vc4_data->drm_fd, layer_data->plane_id,
- DRM_MODE_OBJECT_PLANE, "SRC_H", &layer_data->atomic_props_ids.src_h);
- if (ret != TDM_ERROR_NONE) {
- free(layer_data);
- goto failed_atomic_prop_id;
- }
-
- ret = _vc4_output_get_atomic_prop_id(vc4_data->drm_fd, layer_data->plane_id,
- DRM_MODE_OBJECT_PLANE, "CRTC_X", &layer_data->atomic_props_ids.crtc_x);
- if (ret != TDM_ERROR_NONE) {
- free(layer_data);
- goto failed_atomic_prop_id;
- }
-
- ret = _vc4_output_get_atomic_prop_id(vc4_data->drm_fd, layer_data->plane_id,
- DRM_MODE_OBJECT_PLANE, "CRTC_Y", &layer_data->atomic_props_ids.crtc_y);
- if (ret != TDM_ERROR_NONE) {
- free(layer_data);
- goto failed_atomic_prop_id;
- }
-
- ret = _vc4_output_get_atomic_prop_id(vc4_data->drm_fd, layer_data->plane_id,
- DRM_MODE_OBJECT_PLANE, "CRTC_W", &layer_data->atomic_props_ids.crtc_w);
- if (ret != TDM_ERROR_NONE) {
- free(layer_data);
- goto failed_atomic_prop_id;
- }
-
- ret = _vc4_output_get_atomic_prop_id(vc4_data->drm_fd, layer_data->plane_id,
- DRM_MODE_OBJECT_PLANE, "CRTC_H", &layer_data->atomic_props_ids.crtc_h);
- if (ret != TDM_ERROR_NONE) {
- free(layer_data);
- goto failed_atomic_prop_id;
- }
-
- ret = _vc4_output_get_atomic_prop_id(vc4_data->drm_fd, layer_data->plane_id,
- DRM_MODE_OBJECT_PLANE, "IN_FENCE_FD", &layer_data->atomic_props_ids.in_fence_fd);
- if (ret != TDM_ERROR_NONE) {
- free(layer_data);
- goto failed_atomic_prop_id;
- }
- }
-
- drmModeFreePlane(plane);
- }
-
- return TDM_ERROR_NONE;
-
-failed_atomic_prop_id:
- if (plane)
- drmModeFreePlane(plane);
-
- return TDM_ERROR_OPERATION_FAILED;
-}
-#endif
-
-static int
-_get_primary_layer_zpos(tdm_vc4_output_data *output_data)
-{
- tdm_vc4_layer_data *layer_data = NULL;
-
- LIST_FOR_EACH_ENTRY(layer_data, &output_data->layer_list, link) {
- if (layer_data->capabilities & TDM_LAYER_CAPABILITY_PRIMARY)
- return layer_data->zpos;
- }
-
- return -1;
-}
-
-tdm_error
-tdm_vc4_display_create_layer_list(tdm_vc4_data *vc4_data)
-{
- tdm_vc4_output_data *output_data = NULL;
- tdm_error ret;
-
-#if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4 && LIBDRM_MICRO_VERSION >= 47
- if (vc4_data->has_universal_plane)
- ret = _tdm_vc4_display_create_layer_list_type(vc4_data);
- else
-#endif
- ret = _tdm_vc4_display_create_layer_list(vc4_data);
-
- if (ret != TDM_ERROR_NONE)
- return ret;
-
- LIST_FOR_EACH_ENTRY(output_data, &vc4_data->output_list, link) {
- if (!output_data->primary_layer) {
- TDM_ERR("output(%d) no primary layer", output_data->pipe);
- return TDM_ERROR_OPERATION_FAILED;
- }
- }
-
- return TDM_ERROR_NONE;
-}
-
-void
-tdm_vc4_display_destroy_output_list(tdm_vc4_data *vc4_data)
-{
- tdm_vc4_output_data *o = NULL, *oo = NULL;
- tdm_vc4_hwc_data *hwc_data = NULL;
-
- if (LIST_IS_EMPTY(&vc4_data->output_list))
- return;
-
- LIST_FOR_EACH_ENTRY_SAFE(o, oo, &vc4_data->output_list, link) {
- hwc_data = o->hwc_data;
- if (hwc_data && hwc_data->target_hwc_window)
- vc4_hwc_window_destroy(hwc_data->target_hwc_window);
-
- if (o->crtc_enabled) {
- _tdm_vc4_display_set_crtc(vc4_data, o, 0);
- o->crtc_enabled = 0;
- }
-
- LIST_DEL(&o->link);
- if (!LIST_IS_EMPTY(&o->layer_list)) {
- tdm_vc4_layer_data *l = NULL, *ll = NULL;
- LIST_FOR_EACH_ENTRY_SAFE(l, ll, &o->layer_list, link) {
- LIST_DEL(&l->link);
- if (l->display_buffer)
- tbm_surface_internal_unref(l->display_buffer->buffer);
- free(l);
- }
- }
- free(o->vc4_modes);
- free(o->output_modes);
- free(o);
- }
-}
-
-void
-tdm_vc4_display_update_output_status(tdm_vc4_data *vc4_data)
-{
- tdm_vc4_output_data *output_data = NULL;
-
- if (LIST_IS_EMPTY(&vc4_data->output_list))
- return;
-
- LIST_FOR_EACH_ENTRY(output_data, &vc4_data->output_list, link) {
- drmModeConnectorPtr connector;
- tdm_output_conn_status new_status;
-
- connector = drmModeGetConnector(vc4_data->drm_fd,
- output_data->connector_id);
- if (!connector) {
- TDM_ERR("no connector: %d", output_data->connector_id);
- continue;
- }
-
- if (connector->connection == DRM_MODE_CONNECTED)
- new_status = TDM_OUTPUT_CONN_STATUS_CONNECTED;
- else
- new_status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
-
- _tdm_vc4_output_update_status(output_data, new_status);
-
- drmModeFreeConnector(connector);
- }
-}
-
-tdm_error
-tdm_vc4_display_create_output_list(tdm_vc4_data *vc4_data)
-{
- tdm_vc4_output_data *output_data;
- int i;
- tdm_error ret;
- int allocated = 0;
-
- RETURN_VAL_IF_FAIL(LIST_IS_EMPTY(&vc4_data->output_list),
- TDM_ERROR_OPERATION_FAILED);
-
- for (i = 0; i < vc4_data->mode_res->count_connectors; i++) {
- drmModeConnectorPtr connector;
- drmModeEncoderPtr encoder;
- int crtc_id = 0, c, j;
-
- connector = drmModeGetConnector(vc4_data->drm_fd,
- vc4_data->mode_res->connectors[i]);
- if (!connector) {
- TDM_ERR("no connector");
- ret = TDM_ERROR_OPERATION_FAILED;
- goto failed_create;
- }
-
- if (connector->count_encoders != 1) {
- TDM_ERR("too many encoders: %d", connector->count_encoders);
- drmModeFreeConnector(connector);
- ret = TDM_ERROR_OPERATION_FAILED;
- goto failed_create;
- }
-
- encoder = drmModeGetEncoder(vc4_data->drm_fd, connector->encoders[0]);
- if (!encoder) {
- TDM_ERR("no encoder");
- drmModeFreeConnector(connector);
- ret = TDM_ERROR_OPERATION_FAILED;
- goto failed_create;
- }
-
- for (c = 0; c < vc4_data->mode_res->count_crtcs; c++) {
- if (allocated & (1 << c))
- continue;
-
- if ((encoder->possible_crtcs & (1 << c)) == 0)
- continue;
-
- crtc_id = vc4_data->mode_res->crtcs[c];
- allocated |= (1 << c);
- break;
- }
-
- if (crtc_id == 0) {
- TDM_ERR("no possible crtc");
- drmModeFreeConnector(connector);
- drmModeFreeEncoder(encoder);
- ret = TDM_ERROR_OPERATION_FAILED;
- goto failed_create;
- }
-
- output_data = calloc(1, sizeof(tdm_vc4_output_data));
- if (!output_data) {
- TDM_ERR("alloc failed");
- drmModeFreeConnector(connector);
- drmModeFreeEncoder(encoder);
- ret = TDM_ERROR_OUT_OF_MEMORY;
- goto failed_create;
- }
-
- LIST_INITHEAD(&output_data->layer_list);
-
- output_data->vc4_data = vc4_data;
- output_data->connector_id = vc4_data->mode_res->connectors[i];
- output_data->encoder_id = encoder->encoder_id;
- output_data->crtc_id = crtc_id;
- output_data->pipe = c;
- output_data->connector_type = connector->connector_type;
- output_data->connector_type_id = connector->connector_type_id;
- output_data->commit_fence = -1;
-
- if (connector->connection == DRM_MODE_CONNECTED)
- output_data->status = TDM_OUTPUT_CONN_STATUS_CONNECTED;
- else
- output_data->status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
-
- for (j = 0; j < connector->count_props; j++) {
- drmModePropertyPtr prop = drmModeGetProperty(vc4_data->drm_fd,
- connector->props[j]);
- if (!prop)
- continue;
- if (!strcmp(prop->name, "DPMS")) {
- output_data->dpms_prop_id = connector->props[j];
- drmModeFreeProperty(prop);
- break;
- }
- drmModeFreeProperty(prop);
- }
-
- output_data->count_modes = connector->count_modes;
- output_data->vc4_modes = calloc(connector->count_modes, sizeof(drmModeModeInfo));
- if (!output_data->vc4_modes) {
- TDM_ERR("alloc failed");
- free(output_data);
- drmModeFreeConnector(connector);
- drmModeFreeEncoder(encoder);
- ret = TDM_ERROR_OUT_OF_MEMORY;
- goto failed_create;
- }
-
- output_data->output_modes = calloc(connector->count_modes, sizeof(tdm_output_mode));
- if (!output_data->output_modes) {
- TDM_ERR("alloc failed");
- free(output_data->vc4_modes);
- free(output_data);
- drmModeFreeConnector(connector);
- drmModeFreeEncoder(encoder);
- ret = TDM_ERROR_OUT_OF_MEMORY;
- goto failed_create;
- }
-
- for (j = 0; j < connector->count_modes; j++) {
- output_data->vc4_modes[j] = connector->modes[j];
- _tdm_vc4_display_to_tdm_mode(&output_data->vc4_modes[j],
- &output_data->output_modes[j]);
- }
-
- if (vc4_data->hwc_mode)
- output_data->hwc_enable = 1;
-
- LIST_ADDTAIL(&output_data->link, &vc4_data->output_list);
-
- TDM_INFO("output_data(%p) connector_id(%d:%d:%d-%d) encoder_id(%d) crtc_id(%d) pipe(%d) dpms_id(%d) count_modes(%d)",
- output_data, output_data->connector_id, output_data->status,
- output_data->connector_type,
- output_data->connector_type_id, output_data->encoder_id, output_data->crtc_id,
- output_data->pipe, output_data->dpms_prop_id, output_data->count_modes);
-
- drmModeFreeEncoder(encoder);
- drmModeFreeConnector(connector);
-
- /* get the atomic prop ids*/
- if (vc4_data->has_atomic) {
- ret = _vc4_output_get_atomic_prop_id(vc4_data->drm_fd, output_data->connector_id,
- DRM_MODE_OBJECT_CONNECTOR, "CRTC_ID", &output_data->atomic_props_ids.crtc_id);
- if (ret != TDM_ERROR_NONE)
- goto failed_atomic_prop_id;
-
- ret = _vc4_output_get_atomic_prop_id(vc4_data->drm_fd, output_data->crtc_id,
- DRM_MODE_OBJECT_CRTC, "MODE_ID", &output_data->atomic_props_ids.crtc_mode_id);
- if (ret != TDM_ERROR_NONE)
- goto failed_atomic_prop_id;
-
- ret = _vc4_output_get_atomic_prop_id(vc4_data->drm_fd, output_data->crtc_id,
- DRM_MODE_OBJECT_CRTC, "ACTIVE", &output_data->atomic_props_ids.crtc_active);
- if (ret != TDM_ERROR_NONE)
- goto failed_atomic_prop_id;
-
- ret = _vc4_output_get_atomic_prop_id(vc4_data->drm_fd, output_data->crtc_id,
- DRM_MODE_OBJECT_CRTC, "OUT_FENCE_PTR", &output_data->atomic_props_ids.out_fence_ptr);
- if (ret != TDM_ERROR_NONE)
- goto failed_atomic_prop_id;
- }
- }
-
- TDM_INFO("output count: %d", vc4_data->mode_res->count_connectors);
-
- return TDM_ERROR_NONE;
-failed_atomic_prop_id:
-failed_create:
- tdm_vc4_display_destroy_output_list(vc4_data);
- return ret;
-}
-
-tdm_error
-vc4_display_get_capability(tdm_backend_data *bdata, tdm_caps_display *caps)
-{
- RETURN_VAL_IF_FAIL(caps, TDM_ERROR_INVALID_PARAMETER);
-
- caps->max_layer_count = -1; /* not defined */
-
- return TDM_ERROR_NONE;
-}
-
-tdm_output **
-vc4_display_get_outputs(tdm_backend_data *bdata, int *count, tdm_error *error)
-{
- tdm_vc4_data *vc4_data = bdata;
- tdm_vc4_output_data *output_data = NULL;
- tdm_output **outputs;
- tdm_error ret;
- int i;
-
- RETURN_VAL_IF_FAIL(vc4_data, NULL);
- RETURN_VAL_IF_FAIL(count, NULL);
-
- *count = 0;
- LIST_FOR_EACH_ENTRY(output_data, &vc4_data->output_list, link)
- (*count)++;
-
- if (*count == 0) {
- ret = TDM_ERROR_NONE;
- goto failed_get;
- }
-
- /* will be freed in frontend */
- outputs = calloc(*count, sizeof(tdm_vc4_output_data *));
- if (!outputs) {
- TDM_ERR("failed: alloc memory");
- *count = 0;
- ret = TDM_ERROR_OUT_OF_MEMORY;
- goto failed_get;
- }
-
- i = 0;
- LIST_FOR_EACH_ENTRY(output_data, &vc4_data->output_list, link)
- outputs[i++] = output_data;
-
- if (error)
- *error = TDM_ERROR_NONE;
-
- return outputs;
-failed_get:
- if (error)
- *error = ret;
- return NULL;
-}
-
-tdm_error
-vc4_display_get_fd(tdm_backend_data *bdata, int *fd)
-{
- tdm_vc4_data *vc4_data = bdata;
-
- RETURN_VAL_IF_FAIL(vc4_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(fd, TDM_ERROR_INVALID_PARAMETER);
-
- *fd = vc4_data->drm_fd;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_display_handle_events(tdm_backend_data *bdata)
-{
- tdm_vc4_data *vc4_data = bdata;
- drmEventContext ctx;
-
- RETURN_VAL_IF_FAIL(vc4_data, TDM_ERROR_INVALID_PARAMETER);
-
- memset(&ctx, 0, sizeof(drmEventContext));
-
- ctx.version = DRM_EVENT_CONTEXT_VERSION;
- ctx.page_flip_handler = _tdm_vc4_display_cb_event;
- ctx.vblank_handler = _tdm_vc4_display_cb_event;
-
- drmHandleEvent(vc4_data->drm_fd, &ctx);
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_output_get_capability(tdm_output *output, tdm_caps_output *caps)
-{
- tdm_vc4_output_data *output_data = output;
- tdm_vc4_data *vc4_data;
- drmModeConnectorPtr connector = NULL;
- drmModeCrtcPtr crtc = NULL;
- drmModeObjectPropertiesPtr props = NULL;
- int i;
- tdm_error ret;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(caps, TDM_ERROR_INVALID_PARAMETER);
-
- memset(caps, 0, sizeof(tdm_caps_output));
-
- vc4_data = output_data->vc4_data;
-
- snprintf(caps->maker, TDM_NAME_LEN, "unknown");
- snprintf(caps->model, TDM_NAME_LEN, "unknown");
- snprintf(caps->name, TDM_NAME_LEN, "unknown");
-
- caps->status = output_data->status;
- caps->type = output_data->connector_type;
- caps->type_id = output_data->connector_type_id;
-
- connector = drmModeGetConnector(vc4_data->drm_fd, output_data->connector_id);
- RETURN_VAL_IF_FAIL(connector, TDM_ERROR_OPERATION_FAILED);
-
- caps->mode_count = connector->count_modes;
- if (caps->mode_count != 0) {
- caps->modes = calloc(1, sizeof(tdm_output_mode) * caps->mode_count);
- if (!caps->modes) {
- ret = TDM_ERROR_OUT_OF_MEMORY;
- TDM_ERR("alloc failed\n");
- goto failed_get;
- }
-
- output_data->count_drm_modes = connector->count_modes;
- output_data->count_modes = caps->mode_count;
-
- drmModeModeInfoPtr new_drm_modes;
- tdm_output_mode *new_output_modes;
-
- new_drm_modes = calloc(connector->count_modes,
- sizeof(drmModeModeInfo));
- if (!new_drm_modes) {
- ret = TDM_ERROR_OUT_OF_MEMORY;
- TDM_ERR("alloc failed drm_modes\n");
- goto failed_get;
- }
- new_output_modes = calloc(caps->mode_count,
- sizeof(tdm_output_mode));
- if (!new_output_modes) {
- ret = TDM_ERROR_OUT_OF_MEMORY;
- TDM_ERR("alloc failed output_modes\n");
- free(new_drm_modes);
- goto failed_get;
- }
- if (output_data->vc4_modes)
- free(output_data->vc4_modes);
- if (output_data->output_modes)
- free(output_data->output_modes);
-
- output_data->vc4_modes = new_drm_modes;
- output_data->output_modes = new_output_modes;
-
- for (i = 0; i < connector->count_modes; i++) {
- output_data->vc4_modes[i] = connector->modes[i];
- _tdm_vc4_display_to_tdm_mode(&output_data->vc4_modes[i],
- &output_data->output_modes[i]);
- caps->modes[i] = output_data->output_modes[i];
- }
- } else {
- caps->modes = NULL;
- output_data->count_drm_modes = connector->count_modes;
- output_data->count_modes = caps->mode_count;
-
- if (output_data->vc4_modes)
- free(output_data->vc4_modes);
- if (output_data->output_modes)
- free(output_data->output_modes);
-
- output_data->vc4_modes = NULL;
- output_data->output_modes = NULL;
- }
-
- caps->mmWidth = connector->mmWidth;
- caps->mmHeight = connector->mmHeight;
- caps->subpixel = connector->subpixel;
-
- caps->min_w = vc4_data->mode_res->min_width;
- caps->min_h = vc4_data->mode_res->min_height;
- caps->max_w = vc4_data->mode_res->max_width;
- caps->max_h = vc4_data->mode_res->max_height;
- caps->preferred_align = -1;
-
- crtc = drmModeGetCrtc(vc4_data->drm_fd, output_data->crtc_id);
- if (!crtc) {
- ret = TDM_ERROR_OPERATION_FAILED;
- TDM_ERR("get crtc failed: %m\n");
- goto failed_get;
- }
-
- props = drmModeObjectGetProperties(vc4_data->drm_fd, output_data->crtc_id,
- DRM_MODE_OBJECT_CRTC);
- if (!props) {
- ret = TDM_ERROR_OPERATION_FAILED;
- TDM_ERR("get crtc properties failed: %m\n");
- goto failed_get;
- }
-
- caps->props = calloc(1, sizeof(tdm_prop) * props->count_props);
- if (!caps->props) {
- ret = TDM_ERROR_OUT_OF_MEMORY;
- TDM_ERR("alloc failed\n");
- goto failed_get;
- }
-
- caps->prop_count = 0;
- for (i = 0; i < props->count_props; i++) {
- drmModePropertyPtr prop = drmModeGetProperty(vc4_data->drm_fd, props->props[i]);
- if (!prop)
- continue;
- snprintf(caps->props[caps->prop_count].name, TDM_NAME_LEN, "%s", prop->name);
- caps->props[caps->prop_count].id = props->props[i];
- caps->prop_count++;
- drmModeFreeProperty(prop);
- }
-
- if (output_data->hwc_enable) {
- caps->capabilities |= TDM_OUTPUT_CAPABILITY_HWC;
- caps->capabilities |= TDM_OUTPUT_CAPABILITY_MIRROR;
- }
-
- drmModeFreeObjectProperties(props);
- drmModeFreeCrtc(crtc);
- drmModeFreeConnector(connector);
-
- return TDM_ERROR_NONE;
-failed_get:
- drmModeFreeCrtc(crtc);
- drmModeFreeObjectProperties(props);
- drmModeFreeConnector(connector);
- free(caps->modes);
- free(caps->props);
- memset(caps, 0, sizeof(tdm_caps_output));
- return ret;
-}
-
-tdm_layer **
-vc4_output_get_layers(tdm_output *output, int *count, tdm_error *error)
-{
- tdm_vc4_output_data *output_data = output;
- tdm_vc4_layer_data *layer_data = NULL;
- tdm_layer **layers;
- tdm_error ret;
- int i;
-
- RETURN_VAL_IF_FAIL(output_data, NULL);
- RETURN_VAL_IF_FAIL(count, NULL);
-
- *count = 0;
- LIST_FOR_EACH_ENTRY(layer_data, &output_data->layer_list, link)
- (*count)++;
-
- if (output_data->hwc_enable) {
- *count = 0;
- ret = TDM_ERROR_NONE;
- goto failed_get;
- }
-
- if (*count == 0) {
- ret = TDM_ERROR_NONE;
- goto failed_get;
- }
-
- /* will be freed in frontend */
- layers = calloc(*count, sizeof(tdm_vc4_layer_data *));
- if (!layers) {
- TDM_ERR("failed: alloc memory");
- *count = 0;
- ret = TDM_ERROR_OUT_OF_MEMORY;
- goto failed_get;
- }
-
- i = 0;
- LIST_FOR_EACH_ENTRY(layer_data, &output_data->layer_list, link)
- layers[i++] = layer_data;
-
- if (error)
- *error = TDM_ERROR_NONE;
-
- return layers;
-failed_get:
- if (error)
- *error = ret;
- return NULL;
-}
-
-tdm_error
-vc4_output_set_property(tdm_output *output, unsigned int id, tdm_value value)
-{
- tdm_vc4_output_data *output_data = output;
- tdm_vc4_data *vc4_data;
- int ret;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(output_data->crtc_id > 0, TDM_ERROR_INVALID_PARAMETER);
-
- vc4_data = output_data->vc4_data;
- ret = drmModeObjectSetProperty(vc4_data->drm_fd,
- output_data->crtc_id, DRM_MODE_OBJECT_CRTC,
- id, value.u32);
- if (ret < 0) {
- TDM_ERR("set property failed: %m");
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_output_get_property(tdm_output *output, unsigned int id, tdm_value *value)
-{
- tdm_vc4_output_data *output_data = output;
- tdm_vc4_data *vc4_data;
- drmModeObjectPropertiesPtr props;
- int i;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(output_data->crtc_id > 0, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(value, TDM_ERROR_INVALID_PARAMETER);
-
- vc4_data = output_data->vc4_data;
- props = drmModeObjectGetProperties(vc4_data->drm_fd, output_data->crtc_id,
- DRM_MODE_OBJECT_CRTC);
- if (props == NULL) {
- TDM_ERR("get property failed: %m");
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- for (i = 0; i < props->count_props; i++)
- if (props->props[i] == id) {
- (*value).u32 = (uint)props->prop_values[i];
- break;
- }
-
- drmModeFreeObjectProperties(props);
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_output_wait_vblank(tdm_output *output, int interval, int sync,
- void *user_data)
-{
- tdm_vc4_output_data *output_data = output;
- tdm_vc4_data *vc4_data;
- tdm_vc4_event_data *event_data;
- uint target_msc;
- tdm_error ret;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
-
- event_data = calloc(1, sizeof(tdm_vc4_event_data));
- if (!event_data) {
- TDM_ERR("alloc failed");
- return TDM_ERROR_OUT_OF_MEMORY;
- }
-
- vc4_data = output_data->vc4_data;
-
- ret = _tdm_vc4_display_get_cur_msc(vc4_data->drm_fd, output_data->pipe,
- &target_msc);
- if (ret != TDM_ERROR_NONE)
- goto failed_vblank;
-
- target_msc += interval;
-
- event_data->type = TDM_DRM_EVENT_TYPE_WAIT;
- event_data->output_data = output_data;
- event_data->user_data = user_data;
-
- ret = _tdm_vc4_display_wait_vblank(vc4_data->drm_fd, output_data->pipe,
- &target_msc, event_data);
- if (ret != TDM_ERROR_NONE)
- goto failed_vblank;
-
- return TDM_ERROR_NONE;
-failed_vblank:
- free(event_data);
- return ret;
-}
-
-tdm_error
-vc4_output_set_vblank_handler(tdm_output *output,
- tdm_output_vblank_handler func)
-{
- tdm_vc4_output_data *output_data = output;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(func, TDM_ERROR_INVALID_PARAMETER);
-
- output_data->vblank_func = func;
-
- return TDM_ERROR_NONE;
-}
-
-static tdm_error
-_vc4_layer_add_atomic_properties(tdm_vc4_layer_data *layer_data, drmModeAtomicReqPtr request,
- uint32_t fb_id, uint32_t crtc_id, uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h,
- uint32_t crtc_x, uint32_t crtc_y, uint32_t crtc_w, uint32_t crtc_h, int acquire_fence)
-{
- tdm_error ret = TDM_ERROR_NONE;
-
- ret = drmModeAtomicAddProperty(request, layer_data->plane_id, layer_data->atomic_props_ids.fb_id, fb_id);
- if (ret < 0) {
- TDM_ERR("fail to add the atomic prop. fb_id(%u)", fb_id);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- ret = drmModeAtomicAddProperty(request, layer_data->plane_id, layer_data->atomic_props_ids.crtc_id, crtc_id);
- if (ret < 0) {
- TDM_ERR("fail to add the atomic prop. crtc_id(%u)", crtc_id);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- ret = drmModeAtomicAddProperty(request, layer_data->plane_id, layer_data->atomic_props_ids.src_x, src_x);
- if (ret < 0) {
- TDM_ERR("fail to add the atomic prop. src_x(%u)", src_x);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- ret = drmModeAtomicAddProperty(request, layer_data->plane_id, layer_data->atomic_props_ids.src_y, src_y);
- if (ret < 0) {
- TDM_ERR("fail to add the atomic prop. src_y(%u)", src_y);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- ret = drmModeAtomicAddProperty(request, layer_data->plane_id, layer_data->atomic_props_ids.src_w, src_w);
- if (ret < 0) {
- TDM_ERR("fail to add the atomic prop. src_w(%u)", src_w);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- ret = drmModeAtomicAddProperty(request, layer_data->plane_id, layer_data->atomic_props_ids.src_h, src_h);
- if (ret < 0) {
- TDM_ERR("fail to add the atomic prop. src_h(%u)", src_h);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- ret = drmModeAtomicAddProperty(request, layer_data->plane_id, layer_data->atomic_props_ids.crtc_x, crtc_x);
- if (ret < 0) {
- TDM_ERR("fail to add the atomic prop. crtc_x(%u)", crtc_x);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- ret = drmModeAtomicAddProperty(request, layer_data->plane_id, layer_data->atomic_props_ids.crtc_y, crtc_y);
- if (ret < 0) {
- TDM_ERR("fail to add the atomic prop. crtc_y(%u)", crtc_y);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- ret = drmModeAtomicAddProperty(request, layer_data->plane_id, layer_data->atomic_props_ids.crtc_w, crtc_w);
- if (ret < 0) {
- TDM_ERR("fail to add the atomic prop. crtc_w(%u)", crtc_w);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- ret = drmModeAtomicAddProperty(request, layer_data->plane_id, layer_data->atomic_props_ids.crtc_h, crtc_h);
- if (ret < 0) {
- TDM_ERR("fail to add the atomic prop. crtc_h(%u)", crtc_h);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- ret = drmModeAtomicAddProperty(request, layer_data->plane_id, layer_data->atomic_props_ids.in_fence_fd, acquire_fence);
- if (ret < 0) {
- TDM_ERR("fail to add the atomic prop. acquire_fence(%d)", acquire_fence);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- return TDM_ERROR_NONE;
-}
-
-static tdm_error
-_vc4_layer_make_atomic_request(tdm_vc4_layer_data *layer_data, drmModeAtomicReqPtr request)
-{
- tdm_vc4_data *vc4_data = layer_data->vc4_data;
- tdm_vc4_output_data *output_data = layer_data->output_data;
- uint32_t fx, fy, fw, fh;
- tdm_info_layer layer_info = layer_data->info;
- tdm_error ret = TDM_ERROR_NONE;
-
- if (!layer_data->display_buffer_changed && !layer_data->info_changed)
- return TDM_ERROR_NONE;
-
- layer_data->display_buffer_changed = 0;
- layer_data->info_changed = 0;
-
- if (!layer_data->display_buffer) {
- TDM_DBG("MakeAtomicRequest: drm_fd(%d) plane_id(%u) crtc_id(%u) off",
- vc4_data->drm_fd, layer_data->plane_id, output_data->crtc_id);
-
- ret = _vc4_layer_add_atomic_properties(layer_data, request, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1);
- if (ret != TDM_ERROR_NONE) {
- TDM_ERR("_vc4_layer_add_atomic_properties failed.");
- return ret;
- }
-
- return TDM_ERROR_NONE;
- }
-
- /* Source values are 16.16 fixed point */
- fx = ((unsigned int)layer_info.src_config.pos.x) << 16;
- fy = ((unsigned int)layer_info.src_config.pos.y) << 16;
- fw = ((unsigned int)layer_info.src_config.pos.w) << 16;
- fh = ((unsigned int)layer_info.src_config.pos.h) << 16;
-
- TDM_DBG("MakeAtomicRequest: drm_fd(%d) plane_id(%u) zpos(%d) crtc_id(%u) fb_id(%u) src(%u,%u %ux%u) dst(%u,%u %ux%u)",
- vc4_data->drm_fd, layer_data->plane_id, layer_data->zpos,
- output_data->crtc_id, layer_data->display_buffer->fb_id,
- layer_info.src_config.pos.x, layer_info.src_config.pos.y,
- layer_info.src_config.pos.w, layer_info.src_config.pos.h,
- layer_info.dst_pos.x, layer_info.dst_pos.y,
- layer_info.dst_pos.w, layer_info.dst_pos.h);
-
- ret = _vc4_layer_add_atomic_properties(layer_data, request,
- layer_data->display_buffer->fb_id, output_data->crtc_id,
- fx, fy, fw, fh,
- layer_info.dst_pos.x, layer_info.dst_pos.y,
- layer_info.dst_pos.w, layer_info.dst_pos.h, layer_data->acquire_fence);
- if (ret != TDM_ERROR_NONE) {
- TDM_ERR("MakeAtomicRequest failed");
- return ret;
- }
-
- return TDM_ERROR_NONE;
-}
-
-static tdm_error
-_vc4_output_make_atomic_request(tdm_vc4_output_data *output_data, drmModeAtomicReqPtr request,
- int *out_fence_fd, uint32_t *flags)
-{
- drmModeModeInfoPtr current_mode;
- int ret;
-
- if (!output_data->crtc_enabled || output_data->mode_changed) {
- current_mode = _tdm_vc4_display_get_mode(output_data);
- if (!current_mode) {
- TDM_ERR("couldn't find proper mode");
- return TDM_ERROR_BAD_REQUEST;
- }
-
- if (output_data->current_mode_blob_id > 0)
- drmModeDestroyPropertyBlob(output_data->vc4_data->drm_fd, output_data->current_mode_blob_id);
-
- if (drmModeCreatePropertyBlob(output_data->vc4_data->drm_fd, current_mode,
- sizeof(drmModeModeInfo), &output_data->current_mode_blob_id)) {
- TDM_ERR("fail to drmModeCreatePropertyBlob mode");
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- ret = drmModeAtomicAddProperty(request, output_data->connector_id,
- output_data->atomic_props_ids.crtc_id, output_data->crtc_id);
- if (ret < 0) {
- TDM_ERR("fail to set crtc error:%d", errno);
- return ret;
- }
-
- ret = drmModeAtomicAddProperty(request, output_data->crtc_id,
- output_data->atomic_props_ids.crtc_mode_id, output_data->current_mode_blob_id);
- if (ret < 0) {
- TDM_ERR("fail to set mode error:%d", errno);
- return ret;
- }
-
- ret = drmModeAtomicAddProperty(request, output_data->crtc_id,
- output_data->atomic_props_ids.crtc_active, 1);
- if (ret < 0) {
- TDM_ERR("fail to set active error:%d", errno);
- return ret;
- }
-
- output_data->crtc_enabled = 1;
- output_data->mode_changed = 0;
-
- _tdm_vc4_output_update_status(output_data, TDM_OUTPUT_CONN_STATUS_MODE_SETTED);
-
- *flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
- }
-
- ret = drmModeAtomicAddProperty(request, output_data->crtc_id,
- output_data->atomic_props_ids.out_fence_ptr, (uintptr_t)out_fence_fd);
- if (ret < 0) {
- TDM_ERR("fail to out fence ptr error:%d", errno);
- return ret;
- }
-
- return TDM_ERROR_NONE;
-}
-
-static tdm_error
-_vc4_output_atomic_commit(tdm_output *output, int sync, void *user_data)
-{
- tdm_vc4_output_data *output_data = output;
- tdm_vc4_layer_data *layer_data = NULL;
- tdm_vc4_event_data *event_data;
- drmModeAtomicReqPtr request;
- uint32_t flags = 0;
- tdm_error ret;
- int out_fence_fd = -1;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
-
- request = drmModeAtomicAlloc();
- if (!request) {
- TDM_ERR("drmModeAtomicAlloc failed.");
- return TDM_ERROR_OUT_OF_MEMORY;
- }
-
- flags |= DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_NONBLOCK;
-
- ret = _vc4_output_make_atomic_request(output_data, request, &out_fence_fd, &flags);
- if (ret != TDM_ERROR_NONE) {
- TDM_ERR("_vc4_output_make_atomic_request failed.");
- drmModeAtomicFree(request);
- return ret;
- }
-
- LIST_FOR_EACH_ENTRY(layer_data, &output_data->layer_list, link) {
- ret = _vc4_layer_make_atomic_request(layer_data, request);
- if (ret != TDM_ERROR_NONE) {
- TDM_ERR("_vc4_layer_make_atomic_request failed.");
- drmModeAtomicFree(request);
- return ret;
- }
- }
-
- event_data = calloc(1, sizeof(tdm_vc4_event_data));
- if (!event_data) {
- TDM_ERR("fail to alloc event_data.");
- drmModeAtomicFree(request);
- return TDM_ERROR_OUT_OF_MEMORY;
- }
-
- event_data->type = TDM_DRM_EVENT_TYPE_COMMIT;
- event_data->output_data = output_data;
- event_data->user_data = user_data;
-
- TDM_DBG("==== Atomic Commit pipe, %u, crtc_id, %u connector_id, %u",
- output_data->pipe, output_data->crtc_id, output_data->connector_id);
-
- if (drmModeAtomicCommit(output_data->vc4_data->drm_fd, request, flags, event_data) < 0) {
- TDM_ERR("drmModeAtomicCommit failed.");
- drmModeAtomicFree(request);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- if (output_data->commit_fence >= 0)
- close(output_data->commit_fence);
-
- output_data->commit_fence = out_fence_fd;
-
- drmModeAtomicFree(request);
-
- return TDM_ERROR_NONE;
-}
-
-static tdm_error
-_vc4_output_layers_commit(tdm_output *output, int sync, void *user_data)
-{
- tdm_vc4_output_data *output_data = output;
- tdm_vc4_data *vc4_data;
- tdm_vc4_layer_data *layer_data = NULL;
- tdm_error ret;
- int do_waitvblank = 1;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
-
- vc4_data = output_data->vc4_data;
-
- LIST_FOR_EACH_ENTRY(layer_data, &output_data->layer_list, link) {
- ret = _tdm_vc4_display_commit_layer(layer_data);
- if (ret != TDM_ERROR_NONE)
- return ret;
- }
-
- if (do_waitvblank == 1) {
- tdm_vc4_event_data *event_data = calloc(1, sizeof(tdm_vc4_event_data));
- uint target_msc;
-
- if (!event_data) {
- TDM_ERR("alloc failed");
- return TDM_ERROR_OUT_OF_MEMORY;
- }
-
- ret = _tdm_vc4_display_get_cur_msc(vc4_data->drm_fd, output_data->pipe,
- &target_msc);
- if (ret != TDM_ERROR_NONE) {
- free(event_data);
- return ret;
- }
-
- target_msc++;
-
- event_data->type = TDM_DRM_EVENT_TYPE_COMMIT;
- event_data->output_data = output_data;
- event_data->user_data = user_data;
-
- ret = _tdm_vc4_display_wait_vblank(vc4_data->drm_fd, output_data->pipe,
- &target_msc, event_data);
- if (ret != TDM_ERROR_NONE) {
- free(event_data);
- return ret;
- }
- }
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_output_commit(tdm_output *output, int sync, void *user_data)
-{
- tdm_vc4_output_data *output_data = output;
- tdm_vc4_data *vc4_data;
- tdm_error ret = TDM_ERROR_NONE;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
-
- vc4_data = output_data->vc4_data;
-
- /* check the atomic pageflip */
- if (vc4_data->has_atomic) {
- ret = _vc4_output_atomic_commit(output, sync, user_data);
- if (ret != TDM_ERROR_NONE) {
- TDM_ERR("_vc4_output_atomic_commit failed.");
- return ret;
- }
- } else {
- ret = _vc4_output_layers_commit(output, sync, user_data);
- if (ret != TDM_ERROR_NONE) {
- TDM_ERR("_vc4_output_layers_commit failed.");
- return ret;
- }
- }
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_output_set_commit_handler(tdm_output *output,
- tdm_output_commit_handler func)
-{
- tdm_vc4_output_data *output_data = output;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(func, TDM_ERROR_INVALID_PARAMETER);
-
- output_data->commit_func = func;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value)
-{
- tdm_vc4_output_data *output_data = output;
- tdm_output_dpms cur_dpms_value;
- tdm_vc4_data *vc4_data;
- int ret;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
-
- if (output_data->dpms_prop_id == 0) {
- TDM_WRN("not support DPMS");
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- /*
- * Workaround for the RPi4 firmware bug, call drmModeObjectSetProperty
- * only if there is a real DPMS mode change to avoid vblank timeout.
- */
- if (vc4_output_get_dpms(output, &cur_dpms_value) == TDM_ERROR_NONE &&
- cur_dpms_value == dpms_value)
- return TDM_ERROR_NONE;
-
- vc4_data = output_data->vc4_data;
- ret = drmModeObjectSetProperty(vc4_data->drm_fd,
- output_data->connector_id, DRM_MODE_OBJECT_CONNECTOR,
- output_data->dpms_prop_id, dpms_value);
- if (ret < 0) {
- TDM_ERR("set dpms failed: %m");
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value)
-{
- tdm_vc4_output_data *output_data = output;
- tdm_vc4_data *vc4_data;
- drmModeObjectPropertiesPtr props;
- int i;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(dpms_value, TDM_ERROR_INVALID_PARAMETER);
-
- vc4_data = output_data->vc4_data;
- props = drmModeObjectGetProperties(vc4_data->drm_fd, output_data->connector_id,
- DRM_MODE_OBJECT_CONNECTOR);
- if (props == NULL) {
- TDM_ERR("get property failed: %m");
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- for (i = 0; i < props->count_props; i++)
- if (props->props[i] == output_data->dpms_prop_id) {
- *dpms_value = (uint)props->prop_values[i];
- break;
- }
-
- drmModeFreeObjectProperties(props);
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_output_set_mode(tdm_output *output, const tdm_output_mode *mode)
-{
- tdm_vc4_output_data *output_data = output;
- tdm_error ret = TDM_ERROR_NONE;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(mode, TDM_ERROR_INVALID_PARAMETER);
-
- /* create or replace the target_window when the output mode is set */
- if (output_data->hwc_enable) {
- ret = vc4_hwc_target_window_set_info(output_data->hwc_data, mode->hdisplay, mode->vdisplay);
- if (ret != TDM_ERROR_NONE) {
- TDM_ERR("set info target hwc window failed (%d)", ret);
- return ret;
- }
- }
-
- output_data->current_mode = mode;
- output_data->mode_changed = 1;
-
- TDM_INFO("Set the output mode: %s, %d, %d, %d, %d, %d",
- mode->name, mode->hdisplay, mode->vdisplay, mode->vrefresh, mode->flags, mode->type);
-
- ret = _tdm_vc4_display_set_crtc(output_data->vc4_data, output_data, 1);
- if (ret != TDM_ERROR_NONE) {
- TDM_ERR("fail to set crtc.");
- return TDM_ERROR_OPERATION_FAILED;
- }
- output_data->crtc_enabled = 1;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_output_get_mode(tdm_output *output, const tdm_output_mode **mode)
-{
- tdm_vc4_output_data *output_data = output;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(mode, TDM_ERROR_INVALID_PARAMETER);
-
- *mode = output_data->current_mode;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_output_set_mirror(tdm_output *output, tdm_output *src_output, tdm_transform transform)
-{
- tdm_vc4_output_data *output_data = (tdm_vc4_output_data *)output;
- tdm_vc4_output_data *src_output_data = (tdm_vc4_output_data *)src_output;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(src_output_data, TDM_ERROR_INVALID_PARAMETER);
-
- if (!output_data->hwc_enable) {
- TDM_ERR("Output Mirroring is not Implemented.");
- return TDM_ERROR_NOT_IMPLEMENTED;
- }
-
- output_data->mirror_src_output_data = src_output_data;
- src_output_data->mirror_dst_output_data = output_data;
- src_output_data->mirror_dst_transform = transform;
-
- TDM_INFO("Set the mirror. transform(%d)", transform);
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_output_unset_mirror(tdm_output *output)
-{
- tdm_vc4_output_data *output_data = (tdm_vc4_output_data *)output;
- tdm_vc4_output_data *src_output_data;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
-
- if (!output_data->hwc_enable) {
- TDM_ERR("Output Mirroring is not Implemented.");
- return TDM_ERROR_NOT_IMPLEMENTED;
- }
-
- src_output_data = output_data->mirror_src_output_data;
-
- src_output_data->mirror_dst_transform = TDM_TRANSFORM_NORMAL;
- src_output_data->mirror_dst_output_data = NULL;
- output_data->mirror_src_output_data = NULL;
-
- TDM_INFO("Unet the mirror.");
-
- return TDM_ERROR_NONE;
-}
-
-tdm_hwc *
-vc4_output_get_hwc(tdm_output *output, tdm_error *error)
-{
- tdm_vc4_hwc_data *hwc_data = NULL;
- tdm_vc4_output_data *output_data = output;
- tdm_error ret = TDM_ERROR_NONE;
-
- if (!output_data) {
- TDM_ERR("invalid params");
- if (error)
- *error = TDM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- if (output_data->hwc_data) {
- TDM_INFO("hwc_data already exists");
- if (error)
- *error = TDM_ERROR_NONE;
- return output_data->hwc_data;
- }
-
- hwc_data = calloc(1, sizeof(tdm_vc4_hwc_data));
- if (!hwc_data) {
- TDM_ERR("alloc failed");
- if (error)
- *error = TDM_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
- hwc_data->output_data = output_data;
-
- LIST_INITHEAD(&hwc_data->hwc_window_list);
-
- output_data->hwc_data = hwc_data;
-
- ret = vc4_hwc_initailize_target_window(output_data->hwc_data);
- if (ret != TDM_ERROR_NONE) {
- TDM_ERR("create target hwc window failed (%d)", ret);
- free(hwc_data);
- if (error)
- *error = ret;
- return NULL;
- }
-
- if (error)
- *error = TDM_ERROR_NONE;
-
- return hwc_data;
-}
-
-
-tdm_error
-vc4_output_set_status_handler(tdm_output *output,
- tdm_output_status_handler func,
- void *user_data)
-{
- tdm_vc4_output_data *output_data = output;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(func, TDM_ERROR_INVALID_PARAMETER);
-
- output_data->status_func = func;
- output_data->status_user_data = user_data;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_layer_data_get_capability(tdm_layer *layer, tdm_caps_layer *caps)
-{
- tdm_vc4_layer_data *layer_data = layer;
- tdm_vc4_data *vc4_data;
- drmModePlanePtr plane = NULL;
- drmModeObjectPropertiesPtr props = NULL;
- int i, format_count = 0;
- int primary_zpos = _get_primary_layer_zpos(layer_data->output_data);
- tdm_error ret;
-
- RETURN_VAL_IF_FAIL(layer_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(caps, TDM_ERROR_INVALID_PARAMETER);
-
- memset(caps, 0, sizeof(tdm_caps_layer));
-
- vc4_data = layer_data->vc4_data;
- plane = drmModeGetPlane(vc4_data->drm_fd, layer_data->plane_id);
- if (!plane) {
- TDM_ERR("get plane failed: %m");
- ret = TDM_ERROR_OPERATION_FAILED;
- goto failed_get;
- }
-
- caps->capabilities = layer_data->capabilities;
- caps->zpos = layer_data->zpos;
-
- caps->format_count = plane->count_formats;
- caps->formats = calloc(1, sizeof(tbm_format) * caps->format_count);
- if (!caps->formats) {
- ret = TDM_ERROR_OUT_OF_MEMORY;
- TDM_ERR("alloc failed\n");
- goto failed_get;
- }
-
- for (i = 0; i < caps->format_count; i++) {
- /* Changing between RGB and YUV format for a plane doesn't work properly
- * only support AR24, XR24 for primary, overlay
- */
- if (layer_data->zpos >= primary_zpos) {
- if (plane->formats[i] != DRM_FORMAT_XRGB8888 && plane->formats[i] != DRM_FORMAT_ARGB8888)
- continue;
- } else {
- /* only support NV12 for underlay */
- if (plane->formats[i] != DRM_FORMAT_NV12)
- continue;
- }
-
- caps->formats[format_count] = tdm_vc4_format_to_tbm_format(plane->formats[i]);
- format_count++;
- }
-
- caps->format_count = format_count;
-
- props = drmModeObjectGetProperties(vc4_data->drm_fd, layer_data->plane_id,
- DRM_MODE_OBJECT_PLANE);
- if (!props) {
- ret = TDM_ERROR_OPERATION_FAILED;
- TDM_ERR("get plane properties failed: %m\n");
- goto failed_get;
- }
-
- caps->props = calloc(1, sizeof(tdm_prop) * props->count_props);
- if (!caps->props) {
- ret = TDM_ERROR_OUT_OF_MEMORY;
- TDM_ERR("alloc failed\n");
- goto failed_get;
- }
-
- caps->prop_count = 0;
- for (i = 0; i < props->count_props; i++) {
- drmModePropertyPtr prop = drmModeGetProperty(vc4_data->drm_fd, props->props[i]);
- if (!prop)
- continue;
- if (!strncmp(prop->name, "type", TDM_NAME_LEN)) {
- drmModeFreeProperty(prop);
- continue;
- }
- if (!strncmp(prop->name, "zpos", TDM_NAME_LEN)) {
- drmModeFreeProperty(prop);
- continue;
- }
- snprintf(caps->props[caps->prop_count].name, TDM_NAME_LEN, "%s", prop->name);
- caps->props[caps->prop_count].id = props->props[i];
- caps->prop_count++;
- drmModeFreeProperty(prop);
- }
-
- drmModeFreeObjectProperties(props);
- drmModeFreePlane(plane);
-
- return TDM_ERROR_NONE;
-failed_get:
- drmModeFreeObjectProperties(props);
- drmModeFreePlane(plane);
- free(caps->formats);
- free(caps->props);
- memset(caps, 0, sizeof(tdm_caps_layer));
- return ret;
-}
-
-tdm_error
-vc4_layer_set_property(tdm_layer *layer, unsigned int id, tdm_value value)
-{
- tdm_vc4_layer_data *layer_data = layer;
- tdm_vc4_data *vc4_data;
- int ret;
-
- RETURN_VAL_IF_FAIL(layer_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(layer_data->plane_id > 0, TDM_ERROR_INVALID_PARAMETER);
-
- vc4_data = layer_data->vc4_data;
- ret = drmModeObjectSetProperty(vc4_data->drm_fd,
- layer_data->plane_id, DRM_MODE_OBJECT_PLANE,
- id, value.u32);
- if (ret < 0) {
- TDM_ERR("set property failed: %m");
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_layer_data_get_property(tdm_layer *layer, unsigned int id, tdm_value *value)
-{
- tdm_vc4_layer_data *layer_data = layer;
- tdm_vc4_data *vc4_data;
- drmModeObjectPropertiesPtr props;
- int i;
-
- RETURN_VAL_IF_FAIL(layer_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(layer_data->plane_id > 0, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(value, TDM_ERROR_INVALID_PARAMETER);
-
- vc4_data = layer_data->vc4_data;
- props = drmModeObjectGetProperties(vc4_data->drm_fd, layer_data->plane_id,
- DRM_MODE_OBJECT_PLANE);
- if (props == NULL) {
- TDM_ERR("get property failed: %m");
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- for (i = 0; i < props->count_props; i++)
- if (props->props[i] == id) {
- (*value).u32 = (uint)props->prop_values[i];
- break;
- }
-
- drmModeFreeObjectProperties(props);
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_layer_set_info(tdm_layer *layer, tdm_info_layer *info)
-{
- tdm_vc4_layer_data *layer_data = layer;
-
- RETURN_VAL_IF_FAIL(layer_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(info, TDM_ERROR_INVALID_PARAMETER);
-
- layer_data->info = *info;
- layer_data->info_changed = 1;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_layer_data_get_info(tdm_layer *layer, tdm_info_layer *info)
-{
- tdm_vc4_layer_data *layer_data = layer;
-
- RETURN_VAL_IF_FAIL(layer_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(info, TDM_ERROR_INVALID_PARAMETER);
-
- *info = layer_data->info;
-
- return TDM_ERROR_NONE;
-}
-
-static tdm_vc4_display_buffer *
-_tdm_vc4_display_find_buffer(tdm_vc4_data *vc4_data, tbm_surface_h buffer)
-{
- tdm_vc4_display_buffer *display_buffer = NULL;
-
- LIST_FOR_EACH_ENTRY(display_buffer, &vc4_data->buffer_list, link) {
- if (display_buffer->buffer == buffer)
- return display_buffer;
- }
-
- return NULL;
-}
-
-static void
-_tdm_vc4_display_cb_destroy_buffer(tbm_surface_h buffer, void *user_data)
-{
- tdm_vc4_data *vc4_data;
- tdm_vc4_display_buffer *display_buffer;
- tdm_vc4_layer_data *layer_data = NULL;
- tdm_vc4_output_data *output_data = NULL;
- char buf[256] = {0,};
- char *ret_tmp;
-
- if (!user_data) {
- TDM_ERR("no user_data");
- return;
- }
- if (!buffer) {
- TDM_ERR("no buffer");
- return;
- }
-
- vc4_data = (tdm_vc4_data *) user_data;
-
- display_buffer = _tdm_vc4_display_find_buffer(vc4_data, buffer);
- if (!display_buffer) {
- TDM_ERR("no display_buffer");
- return;
- }
-
- LIST_FOR_EACH_ENTRY(output_data, &vc4_data->output_list, link) {
- LIST_FOR_EACH_ENTRY(layer_data, &output_data->layer_list, link) {
- if (display_buffer == layer_data->display_buffer)
- layer_data->display_buffer = NULL;
- }
- }
-
- if (display_buffer->fb_id > 0) {
- if (drmModeRmFB(vc4_data->drm_fd, display_buffer->fb_id) < 0) {
- ret_tmp = strerror_r(errno, buf, sizeof(buf));
- TDM_ERR("rm fb failed: %d(%s,%s)\n", errno, buf, ret_tmp);
- }
- }
-
- TDM_DBG("destroy buffer:%p", display_buffer->buffer);
-
- LIST_DEL(&display_buffer->link);
- free(display_buffer);
-}
-
-static tdm_vc4_display_buffer *
-_tdm_vc4_display_create_buffer(tdm_vc4_data *vc4_data, tbm_surface_h buffer, tdm_error *err)
-{
- tdm_vc4_display_buffer *display_buffer = NULL;
- tdm_error res = TDM_ERROR_NONE;
- int count, i, ret;
-
- display_buffer = calloc(1, sizeof(tdm_vc4_display_buffer));
- if (!display_buffer) {
- TDM_ERR("alloc failed");
- if (err)
- *err = TDM_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
-
- display_buffer->buffer = buffer;
-
- res = tdm_buffer_add_destroy_handler(buffer, _tdm_vc4_display_cb_destroy_buffer, vc4_data);
- if (res != TDM_ERROR_NONE) {
- TDM_ERR("add destroy handler fail");
- free(display_buffer);
- if (err)
- *err = res;
- return NULL;
- }
-
- display_buffer->width = tbm_surface_get_width(buffer);
- display_buffer->height = tbm_surface_get_height(buffer);
- display_buffer->format = tbm_surface_get_format(buffer);
- display_buffer->count = tbm_surface_internal_get_num_bos(buffer);
- count = tbm_surface_internal_get_num_planes(display_buffer->format);
- TDM_DBG("create buffer:%p %dx%d %c%c%c%c bo_num:%d plane_num:%d",
- buffer, display_buffer->width, display_buffer->height,
- FOURCC_STR(display_buffer->format), display_buffer->count, count);
-
- for (i = 0; i < count; i++) {
- int bo_idx = 0;
- tbm_bo bo = NULL;
-
- bo_idx = tbm_surface_internal_get_plane_bo_idx(buffer, i);
- bo = tbm_surface_internal_get_bo(buffer, bo_idx);
- display_buffer->handles[i] = tbm_bo_get_handle(bo, TBM_DEVICE_DEFAULT).u32;
-
- tbm_surface_internal_get_plane_data(buffer, i, &display_buffer->size,
- &display_buffer->offsets[i],
- &display_buffer->pitches[i]);
- TDM_DBG(" create buffer:%p plane%d(size:%d offset:%d pitch:%d) bo%d(handle:%d)",
- buffer, i, display_buffer->size, display_buffer->offsets[i],
- display_buffer->pitches[i], bo_idx, display_buffer->handles[i]);
- }
-
- ret = drmModeAddFB2(vc4_data->drm_fd, display_buffer->width, display_buffer->height,
- display_buffer->format, display_buffer->handles, display_buffer->pitches,
- display_buffer->offsets, &display_buffer->fb_id, 0);
- if (ret < 0) {
- TDM_ERR("add fb failed: %m");
- free(display_buffer);
- if (err)
- *err = TDM_ERROR_OPERATION_FAILED;
- return NULL;
- }
-
- TDM_DBG("vc4_data->drm_fd : %d, display_buffer->fb_id:%u", vc4_data->drm_fd,
- display_buffer->fb_id);
-
- if (IS_RGB(display_buffer->format))
- display_buffer->width = display_buffer->pitches[0] >> 2;
- else
- display_buffer->width = display_buffer->pitches[0];
-
- LIST_ADDTAIL(&display_buffer->link, &vc4_data->buffer_list);
-
- if (err)
- *err = TDM_ERROR_NONE;
-
- return display_buffer;
-}
-
-void
-tdm_vc4_data_destroy_buffer_list(tdm_vc4_data *vc4_data)
-{
- tdm_vc4_display_buffer *b = NULL, *bb = NULL;
-
- LIST_FOR_EACH_ENTRY_SAFE(b, bb, &vc4_data->buffer_list, link) {
- tdm_buffer_remove_destroy_handler(b->buffer, _tdm_vc4_display_cb_destroy_buffer, vc4_data);
- _tdm_vc4_display_cb_destroy_buffer(b->buffer, vc4_data);
- }
-}
-
-tdm_error
-vc4_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer)
-{
- tdm_vc4_layer_data *layer_data = layer;
- tdm_vc4_data *vc4_data;
- tdm_vc4_display_buffer *display_buffer;
- tdm_error err = TDM_ERROR_NONE;
-
- RETURN_VAL_IF_FAIL(layer_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(buffer, TDM_ERROR_INVALID_PARAMETER);
-
- TDM_DBG("layer[%p]zpos[%d] buffer:%p", layer, layer_data->zpos, buffer);
-
- vc4_data = layer_data->vc4_data;
- display_buffer = _tdm_vc4_display_find_buffer(vc4_data, buffer);
- if (!display_buffer) {
- display_buffer = _tdm_vc4_display_create_buffer(vc4_data, buffer, &err);
- RETURN_VAL_IF_FAIL(display_buffer != NULL, err);
- }
-
- if (layer_data->display_buffer != display_buffer) {
- if (layer_data->display_buffer)
- tbm_surface_internal_unref(layer_data->display_buffer->buffer);
-
- layer_data->display_buffer = display_buffer;
- tbm_surface_internal_ref(layer_data->display_buffer->buffer);
- layer_data->display_buffer_changed = 1;
- }
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_layer_unset_buffer(tdm_layer *layer)
-{
- tdm_vc4_layer_data *layer_data = layer;
-
- RETURN_VAL_IF_FAIL(layer_data, TDM_ERROR_INVALID_PARAMETER);
-
- TDM_DBG("layer[%p]zpos[%d]", layer, layer_data->zpos);
-
- if (layer_data->display_buffer)
- tbm_surface_internal_unref(layer_data->display_buffer->buffer);
-
- layer_data->display_buffer = NULL;
- layer_data->display_buffer_changed = 1;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_vc4_layer_data *
-vc4_output_data_get_layer_data(tdm_vc4_output_data *output_data, int layer_zpos)
-{
- tdm_vc4_layer_data *l = NULL;
-
- RETURN_VAL_IF_FAIL(output_data, NULL);
-
- LIST_FOR_EACH_ENTRY(l, &output_data->layer_list, link) {
- if (l->zpos == layer_zpos)
- return l;
- }
-
- return NULL;
-}
-
-static void
-_vc4_output_data_center_rect_get(int src_w, int src_h, int dst_w, int dst_h, tdm_pos *fit)
-{
- float rh;
-
- if (src_w <= 0 || src_h <= 0 || dst_w <= 0 || dst_h <= 0 || !fit)
- return;
-
- rh = (float) src_h / src_w;
-
- fit->x = 0;
- fit->y = 0;
- fit->w = dst_w;
- fit->h = dst_w * rh;
-
- //TDM_ERR("=###### (%d, %d, %d, %d) (%f)", fit->x, fit->y, fit->w, fit->h, rh);
-}
-
-tdm_error
-vc4_output_data_prepare_mirror_commit(tdm_vc4_output_data *output_data, tbm_surface_h surface)
-{
- tdm_vc4_layer_data *layer_data = NULL;
- tdm_info_layer info;
- tbm_surface_info_s surf_info;
- tdm_error ret;
- tdm_pos dst_pos;
-
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(surface, TDM_ERROR_INVALID_PARAMETER);
-
- RETURN_VAL_IF_FAIL(output_data->current_mode, TDM_ERROR_OPERATION_FAILED);
-
- layer_data = vc4_output_data_get_layer_data(output_data, 0);
- RETURN_VAL_IF_FAIL(layer_data, TDM_ERROR_OPERATION_FAILED);
-
- memset(&dst_pos, 0, sizeof(tdm_pos));
-
- tbm_surface_get_info(surface, &surf_info);
- // TODO: NEED to fix the calculation of the dst_pos
- _vc4_output_data_center_rect_get(surf_info.width, surf_info.height,
- output_data->current_mode->hdisplay, output_data->current_mode->hdisplay,
- &dst_pos);
-
- info.src_config.size.h = surf_info.width;
- info.src_config.size.v = surf_info.height;
- info.src_config.format = TBM_FORMAT_ARGB8888;
- info.src_config.pos.x = 0;
- info.src_config.pos.y = 0;
- info.src_config.pos.w = surf_info.width;
- info.src_config.pos.h = surf_info.height;
- info.dst_pos.x = dst_pos.x;
- info.dst_pos.y = dst_pos.y;
- info.dst_pos.w = output_data->current_mode->hdisplay;
- info.dst_pos.h = output_data->current_mode->vdisplay;
- info.transform = TDM_TRANSFORM_NORMAL;
-
- ret = vc4_layer_set_info((tdm_layer *)layer_data, &info);
- RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
-
- ret = vc4_layer_set_buffer(layer_data, surface);
- RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_layer_set_acquire_fence(tdm_layer *layer, int acquire_fence)
-{
- tdm_vc4_layer_data *layer_data = layer;
-
- RETURN_VAL_IF_FAIL(layer_data, TDM_ERROR_INVALID_PARAMETER);
-
- TDM_DBG("layer[%p]zpos[%d] acquire_fence:%d", layer, layer_data->zpos, acquire_fence);
-
- if (layer_data->acquire_fence != acquire_fence)
- layer_data->acquire_fence = acquire_fence;
-
- return TDM_ERROR_NONE;
-}
diff --git a/src/libtdm-vc4/tdm_vc4_format.c b/src/libtdm-vc4/tdm_vc4_format.c
deleted file mode 100644
index 241b7b7..0000000
--- a/src/libtdm-vc4/tdm_vc4_format.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/**************************************************************************
-
-libtdm_vc4
-
-Copyright 2017 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: SooChan Lim <sc1.lim@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <drm_fourcc.h>
-#include <tbm_surface.h>
-
-#include "tdm_vc4.h"
-
-typedef struct {
- tbm_format tbm_format;
- uint32_t drm_format;
-} tbm_vc4_format_data;
-
-static const tbm_vc4_format_data formats[] = {
- {TBM_FORMAT_C8, DRM_FORMAT_C8},
- {TBM_FORMAT_RGB332, DRM_FORMAT_RGB332},
- {TBM_FORMAT_BGR233, DRM_FORMAT_BGR233},
- {TBM_FORMAT_XRGB4444, DRM_FORMAT_XRGB4444},
- {TBM_FORMAT_XBGR4444, DRM_FORMAT_XBGR4444},
- {TBM_FORMAT_RGBX4444, DRM_FORMAT_RGBX4444},
- {TBM_FORMAT_BGRX4444, DRM_FORMAT_BGRX4444},
- {TBM_FORMAT_ARGB4444, DRM_FORMAT_ARGB4444},
- {TBM_FORMAT_ABGR4444, DRM_FORMAT_ABGR4444},
- {TBM_FORMAT_RGBA4444, DRM_FORMAT_RGBA4444},
- {TBM_FORMAT_BGRA4444, DRM_FORMAT_BGRA4444},
- {TBM_FORMAT_XRGB1555, DRM_FORMAT_XRGB1555},
- {TBM_FORMAT_XBGR1555, DRM_FORMAT_XBGR1555},
- {TBM_FORMAT_RGBX5551, DRM_FORMAT_RGBX5551},
- {TBM_FORMAT_BGRX5551, DRM_FORMAT_BGRX5551},
- {TBM_FORMAT_ARGB1555, DRM_FORMAT_ARGB1555},
- {TBM_FORMAT_ABGR1555, DRM_FORMAT_ABGR1555},
- {TBM_FORMAT_RGBA5551, DRM_FORMAT_RGBA5551},
- {TBM_FORMAT_BGRA5551, DRM_FORMAT_BGRA5551},
- {TBM_FORMAT_RGB565, DRM_FORMAT_RGB565},
- {TBM_FORMAT_BGR565, DRM_FORMAT_BGR565},
- {TBM_FORMAT_RGB888, DRM_FORMAT_RGB888},
- {TBM_FORMAT_BGR888, DRM_FORMAT_BGR888},
- {TBM_FORMAT_XRGB8888, DRM_FORMAT_XRGB8888},
- {TBM_FORMAT_XBGR8888, DRM_FORMAT_XBGR8888},
- {TBM_FORMAT_RGBX8888, DRM_FORMAT_RGBX8888},
- {TBM_FORMAT_BGRX8888, DRM_FORMAT_BGRX8888},
- {TBM_FORMAT_ARGB8888, DRM_FORMAT_ARGB8888},
- {TBM_FORMAT_ABGR8888, DRM_FORMAT_ABGR8888},
- {TBM_FORMAT_RGBA8888, DRM_FORMAT_RGBA8888},
- {TBM_FORMAT_BGRA8888, DRM_FORMAT_BGRA8888},
- {TBM_FORMAT_XRGB2101010, DRM_FORMAT_XRGB2101010},
- {TBM_FORMAT_XBGR2101010, DRM_FORMAT_XBGR2101010},
- {TBM_FORMAT_RGBX1010102, DRM_FORMAT_RGBX1010102},
- {TBM_FORMAT_BGRX1010102, DRM_FORMAT_BGRX1010102},
- {TBM_FORMAT_ARGB2101010, DRM_FORMAT_ARGB2101010},
- {TBM_FORMAT_ABGR2101010, DRM_FORMAT_ABGR2101010},
- {TBM_FORMAT_RGBA1010102, DRM_FORMAT_RGBA1010102},
- {TBM_FORMAT_BGRA1010102, DRM_FORMAT_BGRA1010102},
- {TBM_FORMAT_YUYV, DRM_FORMAT_YUYV},
- {TBM_FORMAT_YVYU, DRM_FORMAT_YVYU},
- {TBM_FORMAT_UYVY, DRM_FORMAT_UYVY},
- {TBM_FORMAT_VYUY, DRM_FORMAT_VYUY},
- {TBM_FORMAT_AYUV, DRM_FORMAT_AYUV},
- {TBM_FORMAT_NV12, DRM_FORMAT_NV12},
- {TBM_FORMAT_NV21, DRM_FORMAT_NV21},
- {TBM_FORMAT_NV16, DRM_FORMAT_NV16},
- {TBM_FORMAT_NV61, DRM_FORMAT_NV61},
- {TBM_FORMAT_YUV410, DRM_FORMAT_YUV410},
- {TBM_FORMAT_YVU410, DRM_FORMAT_YVU410},
- {TBM_FORMAT_YUV411, DRM_FORMAT_YUV411},
- {TBM_FORMAT_YVU411, DRM_FORMAT_YVU411},
- {TBM_FORMAT_YUV420, DRM_FORMAT_YUV420},
- {TBM_FORMAT_YVU420, DRM_FORMAT_YVU420},
- {TBM_FORMAT_YUV422, DRM_FORMAT_YUV422},
- {TBM_FORMAT_YVU422, DRM_FORMAT_YVU422},
- {TBM_FORMAT_YUV444, DRM_FORMAT_YUV444},
- {TBM_FORMAT_YVU444, DRM_FORMAT_YVU444},
-};
-
-#define NUM_FORMATS (sizeof(formats) / sizeof(formats[0]))
-
-uint32_t
-tdm_vc4_format_to_drm_format(tbm_format format)
-{
- int i;
-
- for (i = 0; i < NUM_FORMATS; i++)
- if (formats[i].tbm_format == format)
- return formats[i].drm_format;
-
- TDM_ERR("tbm format '%c%c%c%c' not found", FOURCC_STR(format));
-
- return 0;
-}
-
-tbm_format
-tdm_vc4_format_to_tbm_format(uint32_t format)
-{
- int i;
-
- for (i = 0; i < NUM_FORMATS; i++)
- if (formats[i].drm_format == format)
- return formats[i].tbm_format;
-
- TDM_ERR("drm format '%c%c%c%c' not found", FOURCC_STR(format));
-
- return 0;
-}
diff --git a/src/libtdm-vc4/tdm_vc4_hwc.c b/src/libtdm-vc4/tdm_vc4_hwc.c
deleted file mode 100644
index 0325052..0000000
--- a/src/libtdm-vc4/tdm_vc4_hwc.c
+++ /dev/null
@@ -1,1053 +0,0 @@
-/**************************************************************************
-
-libtdm_vc4
-
-Copyright 2017 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: SooChan Lim <sc1.lim@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <tdm_helper.h>
-#include <pixman.h>
-#include "tdm_vc4.h"
-
-#define NUM_LAYERS 4
-#define NUM_BUFFERS 3
-
-#define NUM_UI_LAYERS 2
-
-#define ZPOS_MAX 3
-#define ZPOS_CURSOR 2
-#define ZPOS_1 1
-#define ZPOS_0 0
-#define ZPOS_VIDEO1 0
-#define ZPOS_NONE -999
-
-tbm_format hwc_window_video_formats[] = {
- TBM_FORMAT_NV12,
- TBM_FORMAT_YUV420
-};
-
-const char *
-_comp_to_str(tdm_hwc_window_composition composition_type)
-{
- if (composition_type == TDM_HWC_WIN_COMPOSITION_CLIENT)
- return "CLIENT";
- else if (composition_type == TDM_HWC_WIN_COMPOSITION_DEVICE)
- return "DEVICE";
- else if (composition_type == TDM_HWC_WIN_COMPOSITION_CURSOR)
- return "CURSOR";
- else if (composition_type == TDM_HWC_WIN_COMPOSITION_VIDEO)
- return "VIDEO";
- else if (composition_type == TDM_HWC_WIN_COMPOSITION_NONE)
- return "SKIP";
-
- return "unknown";
-}
-
-static tbm_surface_queue_h
-_vc4_hwc_window_get_tbm_buffer_queue(tdm_hwc_window *hwc_window, tdm_error *error)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = NULL;
- tbm_surface_queue_h tqueue = NULL;
- int width, height;
- tbm_format format;
-
- if (error)
- *error = TDM_ERROR_INVALID_PARAMETER;
-
- RETURN_VAL_IF_FAIL(hwc_window != NULL, NULL);
-
- hwc_window_data = hwc_window;
-
- width = hwc_window_data->info.src_config.size.h;
- height = hwc_window_data->info.src_config.size.v;
- format = hwc_window_data->info.src_config.format;
-
- tqueue = tbm_surface_queue_create(NUM_BUFFERS, width, height, format, TBM_BO_SCANOUT);
- if (error)
- *error = TDM_ERROR_OPERATION_FAILED;
- RETURN_VAL_IF_FAIL(tqueue != NULL, NULL);
-
- if (error)
- *error = TDM_ERROR_NONE;
-
- return tqueue;
-}
-
-static tbm_surface_queue_h
-_vc4_hwc_window_get_cursor_tbm_buffer_queue(tdm_hwc_window *hwc_window, tdm_error *error)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = NULL;
- tbm_surface_queue_h tqueue = NULL;
- int width, height;
-
- if (error)
- *error = TDM_ERROR_INVALID_PARAMETER;
-
- RETURN_VAL_IF_FAIL(hwc_window != NULL, NULL);
-
- hwc_window_data = hwc_window;
-
- switch (hwc_window_data->info.transform) {
- case TDM_TRANSFORM_90:
- case TDM_TRANSFORM_FLIPPED_90:
- case TDM_TRANSFORM_270:
- case TDM_TRANSFORM_FLIPPED_270:
- width = hwc_window_data->cursor_img.height;
- height = hwc_window_data->cursor_img.width;
- break;
- default:
- width = hwc_window_data->cursor_img.width;
- height = hwc_window_data->cursor_img.height;
- break;
- }
-
- tqueue = tbm_surface_queue_create(NUM_BUFFERS, width, height, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
- if (error)
- *error = TDM_ERROR_OPERATION_FAILED;
- RETURN_VAL_IF_FAIL(tqueue != NULL, NULL);
-
- tbm_surface_queue_set_modes(tqueue, TBM_SURFACE_QUEUE_MODE_GUARANTEE_CYCLE);
-
- if (error)
- *error = TDM_ERROR_NONE;
-
- return tqueue;
-}
-
-static int
-_vc4_hwc_cursor_buffer_image_render(tdm_vc4_hwc_data *hwc_data, tdm_vc4_hwc_window_data *hwc_window_data)
-{
- tbm_surface_info_s tsurface_info;
- tbm_surface_error_e ret = TBM_SURFACE_ERROR_NONE;
- void *src_ptr = NULL, *dst_ptr = NULL;
- int src_stride, transform, img_w, img_h;
- pixman_image_t *src_img = NULL, *dst_img = NULL;
- pixman_transform_t t;
- struct pixman_f_transform ft;
- int c = 0, s = 0, tx = 0, ty = 0;
- int i;
-
- ret = tbm_surface_map(hwc_data->cursor_tsurface, TBM_SURF_OPTION_WRITE, &tsurface_info);
- if (ret != TBM_SURFACE_ERROR_NONE) {
- TDM_ERR("Failed to map tsurface\n");
- return 0;
- }
-
- src_ptr = hwc_window_data->cursor_img.ptr;
- src_stride = hwc_window_data->cursor_img.stride;
- img_w = hwc_window_data->cursor_img.width;
- img_h = hwc_window_data->cursor_img.height;
- transform = hwc_window_data->info.transform;
-
- dst_ptr = tsurface_info.planes[0].ptr;
-
- memset(dst_ptr, 0, tsurface_info.planes[0].stride * tsurface_info.height);
-
- if (transform) {
- src_img = pixman_image_create_bits(PIXMAN_a8r8g8b8, img_w, img_h, (uint32_t*)src_ptr, src_stride);
- if (!src_img) {
- TDM_ERR("Failed to create src pixman\n");
- return 0;
- }
-
- dst_img = pixman_image_create_bits(PIXMAN_a8r8g8b8, tsurface_info.width, tsurface_info.height,
- (uint32_t*)dst_ptr, tsurface_info.planes[0].stride);
- if (!dst_img) {
- TDM_ERR("Failed to create dst pixman\n");
- pixman_image_unref(src_img);
- return 0;
- }
-
- pixman_f_transform_init_identity(&ft);
-
- if (transform >= TDM_TRANSFORM_FLIPPED) {
- pixman_f_transform_scale(&ft, NULL, -1, 1);
- pixman_f_transform_translate(&ft, NULL, tsurface_info.width, 0);
- }
-
- switch (transform) {
- case TDM_TRANSFORM_90:
- case TDM_TRANSFORM_FLIPPED_90:
- c = 0, s = 1, ty = -tsurface_info.height;
- break;
- case TDM_TRANSFORM_180:
- case TDM_TRANSFORM_FLIPPED_180:
- c = -1, s = 0, tx = -tsurface_info.width, ty = -tsurface_info.height;
- break;
- case TDM_TRANSFORM_270:
- case TDM_TRANSFORM_FLIPPED_270:
- c = 0, s = -1, tx = -tsurface_info.width;
- break;
- default:
- break;
- }
-
- pixman_f_transform_translate(&ft, NULL, tx, ty);
- pixman_f_transform_rotate(&ft, NULL, c, s);
- pixman_transform_from_pixman_f_transform(&t, &ft);
- pixman_image_set_transform(src_img, &t);
- pixman_image_composite(PIXMAN_OP_SRC, src_img, NULL, dst_img, 0, 0, 0, 0, 0, 0,
- tsurface_info.width, tsurface_info.height);
- pixman_image_unref(src_img);
- pixman_image_unref(dst_img);
- }
- else {
- for (i = 0 ; i < img_h ; i++) {
- memcpy(dst_ptr, src_ptr, src_stride);
- dst_ptr += tsurface_info.planes[0].stride;
- src_ptr += src_stride;
- }
- }
-
- tbm_surface_unmap(hwc_data->cursor_tsurface);
-
- return 1;
-}
-
-static int
-_vc4_hwc_cursor_window_surface_clear(tdm_vc4_hwc_window_data *hwc_window_data)
-{
- hwc_window_data->surface = NULL;
- hwc_window_data->cursor_img_surface = 0;
-
- hwc_window_data->info.src_config.pos.w = hwc_window_data->cursor_img.width;
- hwc_window_data->info.src_config.pos.h = hwc_window_data->cursor_img.height;
- hwc_window_data->info.dst_pos.w = hwc_window_data->cursor_img.width;
- hwc_window_data->info.dst_pos.h = hwc_window_data->cursor_img.height;
-
- return 1;
-}
-
-static void
-_vc4_hwc_cursor_buffer_unset(tdm_vc4_hwc_data *hwc_data)
-{
- if (hwc_data->cursor_tsurface) {
- tbm_surface_queue_release(hwc_data->cursor_tqueue, hwc_data->cursor_tsurface);
- hwc_data->cursor_tsurface = NULL;
- }
-
- if (hwc_data->cursor_tqueue) {
- tbm_surface_queue_destroy(hwc_data->cursor_tqueue);
- hwc_data->cursor_tqueue = NULL;
- }
-}
-
-static void
-_vc4_hwc_cursor_adjust_pos(tdm_vc4_hwc_data *hwc_data, tdm_vc4_hwc_window_data *hwc_window_data)
-{
- int x, y, width, height;
-
- width = tbm_surface_get_width(hwc_data->cursor_tsurface);
- height = tbm_surface_get_height(hwc_data->cursor_tsurface);
-
- hwc_window_data->info.src_config.pos.w = width;
- hwc_window_data->info.src_config.pos.h = height;
- hwc_window_data->info.dst_pos.w = width;
- hwc_window_data->info.dst_pos.h = height;
-
- /* dst pos of cursor is possible set by negative value
- * this is temporary code.
- */
- x = hwc_window_data->info.dst_pos.x;
- y = hwc_window_data->info.dst_pos.y;
-
- if (x < 0) hwc_window_data->info.dst_pos.x = 0;
- if (y < 0) hwc_window_data->info.dst_pos.y = 0;
-}
-
-static int
-_vc4_hwc_cursor_buffer_set(tdm_vc4_hwc_data *hwc_data, tdm_vc4_hwc_window_data *hwc_window_data)
-{
- tbm_surface_h cursor_tsurface = NULL;
- tbm_surface_queue_error_e tsq_error = TBM_SURFACE_QUEUE_ERROR_NONE;
- int img_w, img_h;
- int tqueue_w, tqueue_h;
- tdm_error error;
-
- if (hwc_window_data->cursor_img_refresh || !hwc_window_data->surface) {
- switch (hwc_window_data->info.transform) {
- case TDM_TRANSFORM_90:
- case TDM_TRANSFORM_FLIPPED_90:
- case TDM_TRANSFORM_270:
- case TDM_TRANSFORM_FLIPPED_270:
- img_w = hwc_window_data->cursor_img.height;
- img_h = hwc_window_data->cursor_img.width;
- break;
- default:
- img_w = hwc_window_data->cursor_img.width;
- img_h = hwc_window_data->cursor_img.height;
- break;
- }
-
- if (!hwc_data->cursor_tqueue) {
- hwc_data->cursor_tqueue = _vc4_hwc_window_get_cursor_tbm_buffer_queue(hwc_window_data, &error);
- if (error != TDM_ERROR_NONE) {
- TDM_ERR("Failed to create cursor buffer queue error:%d", error);
- return 0;
- }
- } else {
- tqueue_w = tbm_surface_queue_get_width(hwc_data->cursor_tqueue);
- tqueue_h = tbm_surface_queue_get_height(hwc_data->cursor_tqueue);
- if ((img_w != tqueue_w) || (img_h != tqueue_h))
- tbm_surface_queue_reset(hwc_data->cursor_tqueue, img_w, img_h, TBM_FORMAT_ARGB8888);
- }
-
- if (hwc_data->cursor_tsurface) {
- tbm_surface_queue_release(hwc_data->cursor_tqueue, hwc_data->cursor_tsurface);
- hwc_data->cursor_tsurface = NULL;
- }
-
- if (!tbm_surface_queue_can_dequeue(hwc_data->cursor_tqueue, 0)) {
- TDM_ERR("Can't dequeue cursor tqueue");
- return 0;
- }
-
- tsq_error = tbm_surface_queue_dequeue(hwc_data->cursor_tqueue, &cursor_tsurface);
- if (tsq_error != TBM_SURFACE_QUEUE_ERROR_NONE) {
- TDM_ERR("Failed to dequeue cursor tqueue error:%d", tsq_error);
- return 0;
- }
-
- hwc_data->cursor_tsurface = cursor_tsurface;
-
- _vc4_hwc_cursor_buffer_image_render(hwc_data, hwc_window_data);
-
- hwc_window_data->surface = cursor_tsurface;
- hwc_window_data->cursor_img_surface = 1;
- hwc_window_data->cursor_img_refresh = 0;
- }
-
- _vc4_hwc_cursor_adjust_pos(hwc_data, hwc_window_data);
-
- return 1;
-}
-
-static void
-_print_validate_result(tdm_vc4_hwc_data *hwc_data, tdm_hwc_window **composited_wnds, uint32_t num_wnds)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = NULL;
- int i;
-
- for (i = 0; i < num_wnds; i++) {
- hwc_window_data = composited_wnds[i];
- switch (hwc_window_data->validated_type) {
- case TDM_HWC_WIN_COMPOSITION_CLIENT:
- TDM_DBG(" window(%p) %s -> %s : lzpos(%d) -- {%s} on TARGET WINDOW", hwc_window_data,
- _comp_to_str(hwc_window_data->client_type),
- _comp_to_str(hwc_window_data->validated_type),
- hwc_data->target_hwc_window->lzpos,
- hwc_window_data->name ? hwc_window_data->name : "NONE");
- break;
- case TDM_HWC_WIN_COMPOSITION_DEVICE:
- case TDM_HWC_WIN_COMPOSITION_VIDEO:
- case TDM_HWC_WIN_COMPOSITION_CURSOR:
- case TDM_HWC_WIN_COMPOSITION_NONE:
- TDM_DBG(" window(%p) %s -> %s : lzpos(%d) -- {%s}", hwc_window_data,
- _comp_to_str(hwc_window_data->client_type),
- _comp_to_str(hwc_window_data->validated_type),
- hwc_window_data->lzpos,
- hwc_window_data->name ? hwc_window_data->name : "NONE");
- break;
- default:
- break;
- }
- }
-}
-
-static int
-_vc4_hwc_window_can_set_on_hw_layer(tdm_vc4_hwc_window_data *hwc_window_data)
-{
- if (!hwc_window_data->surface)
- return 0;
-
- if (hwc_window_data->info.transform != TDM_TRANSFORM_NORMAL)
- return 0;
-
- if (hwc_window_data->info.src_config.pos.w != hwc_window_data->info.dst_pos.w)
- return 0;
-
- if (hwc_window_data->info.src_config.pos.h != hwc_window_data->info.dst_pos.h)
- return 0;
-
- if (!IS_RGB(hwc_window_data->info.src_config.format))
- return 0;
-
- if (hwc_window_data->info.dst_pos.x > hwc_window_data->hwc_data->output_data->current_mode->hdisplay ||
- hwc_window_data->info.dst_pos.y > hwc_window_data->hwc_data->output_data->current_mode->vdisplay)
- return 0;
-
- return 1;
-}
-
-static tdm_error
-_vc4_hwc_layer_attach_window(tdm_vc4_layer_data *layer_data, tdm_vc4_hwc_window_data *hwc_window_data)
-{
- tdm_error ret = TDM_ERROR_NONE;
-
- RETURN_VAL_IF_FAIL(layer_data, TDM_ERROR_OPERATION_FAILED);
-
- if (hwc_window_data == NULL || hwc_window_data->surface == NULL) {
- if (layer_data->display_buffer)
- ret = vc4_layer_unset_buffer(layer_data);
- RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
-
- if (layer_data->acquire_fence >= 0)
- ret = vc4_layer_set_acquire_fence(layer_data, -1);
- RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
- } else {
- ret = vc4_layer_set_info((tdm_layer *)layer_data, (tdm_info_layer *)&(hwc_window_data->info));
- RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
- RETURN_VAL_IF_FAIL(hwc_window_data->surface != NULL, TDM_ERROR_INVALID_PARAMETER);
- ret = vc4_layer_set_buffer(layer_data, hwc_window_data->surface);
- RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
- ret = vc4_layer_set_acquire_fence(layer_data, hwc_window_data->acquire_fence);
- RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
- }
-
- return ret;
-}
-
-static tdm_error
-_vc4_hwc_prepare_commit(tdm_vc4_hwc_data *hwc_data)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = NULL;
- tdm_vc4_layer_data *layer_data = NULL;
- int use_layers_zpos[NUM_LAYERS] = {0,};
- int lzpos = 0;
- int cursor_enabled = 0;
-
- /* set target hwc window to the layer */
- if (hwc_data->need_target_window) {
- layer_data = vc4_output_data_get_layer_data(hwc_data->output_data, hwc_data->target_hwc_window->lzpos);
- _vc4_hwc_layer_attach_window(layer_data, hwc_data->target_hwc_window);
- use_layers_zpos[hwc_data->target_hwc_window->lzpos] = 1;
- }
-
- /* set the hwc_windows to the layers */
- LIST_FOR_EACH_ENTRY_REV(hwc_window_data, &hwc_data->hwc_window_list, link) {
- if (hwc_window_data->validated_type == TDM_HWC_WIN_COMPOSITION_NONE ||
- hwc_window_data->validated_type == TDM_HWC_WIN_COMPOSITION_CLIENT) {
- if (hwc_window_data->cursor_img_surface)
- _vc4_hwc_cursor_window_surface_clear(hwc_window_data);
-
- continue;
- }
-
- if (hwc_window_data == hwc_data->target_hwc_window)
- continue;
-
- /* set the cursor buffer HERE if it needs */
- if (hwc_window_data->validated_type == TDM_HWC_WIN_COMPOSITION_CURSOR) {
- _vc4_hwc_cursor_buffer_set(hwc_data, hwc_window_data);
- cursor_enabled = 1;
- }
-
- layer_data = vc4_output_data_get_layer_data(hwc_data->output_data, hwc_window_data->lzpos);
- _vc4_hwc_layer_attach_window(layer_data, hwc_window_data);
- use_layers_zpos[hwc_window_data->lzpos] = 1;
- }
-
- /* unset the unused layers */
- for (lzpos = 0; lzpos < NUM_LAYERS; lzpos++) {
- if (use_layers_zpos[lzpos])
- continue;
-
- layer_data = vc4_output_data_get_layer_data(hwc_data->output_data, lzpos);
- if (!layer_data)
- continue;
-
- _vc4_hwc_layer_attach_window(layer_data, NULL);
- }
-
- if (!cursor_enabled)
- _vc4_hwc_cursor_buffer_unset(hwc_data);
-
- /* for debug */
- for (lzpos = NUM_LAYERS -1 ; lzpos >= 0; lzpos--) {
- if (use_layers_zpos[lzpos])
- TDM_DBG(" lzpos(%d) : %s", lzpos, use_layers_zpos[lzpos] ? "SET" : "UNSET");
- }
-
- return TDM_ERROR_NONE;
-}
-
-/* assign the validated_type to the composited_wnds
- * assign the layer_zpos to the composited_wnds
- */
-static void
-_vc4_hwc_apply_policy(tdm_vc4_hwc_data *hwc_data , tdm_hwc_window **composited_wnds, uint32_t num_wnds)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = NULL;
- tdm_vc4_hwc_window_data **composited_list = NULL;
- int client_count = 0;
- int device_count = 0;
- int video_count = 0;
- int cursor_count = 0;
- int ui_lzpos_top = ZPOS_1;
- int ui_lzpos_bottom = ZPOS_0;
- int num_ui_layers = NUM_UI_LAYERS;
- int set_clients_below = 0;
- int i = 0;
-
- composited_list = (tdm_vc4_hwc_window_data **)composited_wnds;
-
- /* initialize the need_target_window */
- hwc_data->need_target_window = 0;
-
- /* initialize the validated_types */
- LIST_FOR_EACH_ENTRY_REV(hwc_window_data, &hwc_data->hwc_window_list, link) {
- if (hwc_window_data->validated_type != TDM_HWC_WIN_COMPOSITION_NONE)
- hwc_window_data->validated_type = TDM_HWC_WIN_COMPOSITION_NONE;
- }
-
- /* use the target_window to commit when there is no window. */
- if (num_wnds == 0) {
- hwc_data->need_target_window = 1;
- hwc_data->target_hwc_window->lzpos = ui_lzpos_bottom;
- return;
- }
-
- /* 1. first check validate_type without target_window */
- for (i = 0; i < num_wnds; i++) {
- switch (composited_list[i]->client_type) {
- case TDM_HWC_WIN_COMPOSITION_VIDEO:
- composited_list[i]->validated_type = TDM_HWC_WIN_COMPOSITION_VIDEO;
- video_count++;
- num_ui_layers--;
- continue;
- case TDM_HWC_WIN_COMPOSITION_CURSOR:
- if (set_clients_below) break;
- if (cursor_count > 0) break;
-
- composited_list[i]->validated_type = TDM_HWC_WIN_COMPOSITION_CURSOR;
- cursor_count++;
- continue;
- case TDM_HWC_WIN_COMPOSITION_DEVICE:
- if (set_clients_below) break;
- if (num_ui_layers <= 0) break;
- if (!_vc4_hwc_window_can_set_on_hw_layer(composited_list[i])) break;
-
- composited_list[i]->validated_type = TDM_HWC_WIN_COMPOSITION_DEVICE;
- device_count++;
- num_ui_layers--;
- continue;
- default:
- break;
- }
-
- composited_list[i]->validated_type = TDM_HWC_WIN_COMPOSITION_CLIENT;
- client_count++;
- set_clients_below = 1;
- }
-
- /* 2. check need target window and set ui_lzpos top and bottom */
- num_ui_layers = NUM_UI_LAYERS;
-
- if (video_count > 0) {
- ui_lzpos_bottom++;
- num_ui_layers--;
- }
-
- if ((client_count > 0) ||
- ((video_count > 0) && (device_count == NUM_UI_LAYERS))) {
- ui_lzpos_bottom++;
- num_ui_layers--;
- hwc_data->need_target_window = 1;
- hwc_data->target_hwc_window->lzpos = ui_lzpos_bottom - 1;
- }
-
- if (num_ui_layers > device_count)
- ui_lzpos_top = ui_lzpos_bottom + device_count - 1;
-
- /* 3. set lzpos and modify validate_type with target_window */
- for (i = 0; i < num_wnds; i++) {
- switch (composited_list[i]->validated_type) {
- case TDM_HWC_WIN_COMPOSITION_VIDEO:
- composited_list[i]->lzpos = ZPOS_VIDEO1;
- continue;
- case TDM_HWC_WIN_COMPOSITION_CURSOR:
- composited_list[i]->lzpos = ZPOS_CURSOR;
- continue;
- case TDM_HWC_WIN_COMPOSITION_DEVICE:
- if (num_ui_layers <= 0) break;
- composited_list[i]->lzpos = ui_lzpos_top;
- ui_lzpos_top--;
- num_ui_layers--;
- continue;
- default:
- break;
- }
-
- composited_list[i]->validated_type = TDM_HWC_WIN_COMPOSITION_CLIENT;
- composited_list[i]->lzpos = ZPOS_NONE;
- }
-}
-
-static int
-_vc4_hwc_get_changed_number(tdm_vc4_hwc_data *hwc_data)
-{
- int num = 0;
- tdm_vc4_hwc_window_data *hwc_window_data = NULL;
-
- LIST_FOR_EACH_ENTRY(hwc_window_data, &hwc_data->hwc_window_list, link) {
- if (hwc_window_data->client_type == TDM_HWC_WIN_COMPOSITION_NONE)
- continue;
-
- if (hwc_window_data->client_type != hwc_window_data->validated_type)
- num++;
- }
-
- return num;
-}
-
-tdm_hwc_window *
-_vc4_hwc_create_window(tdm_hwc *hwc, tdm_hwc_window_info *info, tdm_error *error)
-{
- tdm_vc4_hwc_data *hwc_data = hwc;
- tdm_vc4_hwc_window_data *hwc_window_data = NULL;
-
- if (error)
- *error = TDM_ERROR_NONE;
-
- if (!hwc_data) {
- TDM_ERR("invalid params");
- if (error)
- *error = TDM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- hwc_window_data = calloc(1, sizeof(tdm_vc4_hwc_window_data));
- if (!hwc_window_data) {
- TDM_ERR("alloc failed");
- if (error)
- *error = TDM_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
-
- hwc_window_data->hwc_data = hwc_data;
- hwc_window_data->acquire_fence = -1;
-
- if (info)
- memcpy(&hwc_window_data->info, info, sizeof(tdm_hwc_window_info));
-
- LIST_INITHEAD(&hwc_window_data->link);
-
- return hwc_window_data;
-}
-
-tdm_hwc_window *
-vc4_hwc_create_window(tdm_hwc *hwc, tdm_error *error)
-{
- tdm_vc4_hwc_data *hwc_data = hwc;
- tdm_vc4_hwc_window_data *hwc_window_data = NULL;
-
- RETURN_VAL_IF_FAIL(hwc_data, NULL);
-
- hwc_window_data = _vc4_hwc_create_window(hwc_data, NULL, error);
- RETURN_VAL_IF_FAIL(hwc_window_data, NULL);
-
- LIST_ADDTAIL(&hwc_window_data->link, &hwc_data->hwc_window_list);
-
- TDM_DBG("hwc_window(%p) create", hwc_window_data);
- if (error)
- *error = TDM_ERROR_NONE;
-
- return hwc_window_data;
-}
-
-tdm_error
-vc4_hwc_get_video_supported_formats(tdm_hwc *hwc, const tbm_format **formats, int *count)
-{
- RETURN_VAL_IF_FAIL(hwc != NULL, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(formats != NULL, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- // TODO: fix these formats.
- *formats = hwc_window_video_formats;
- *count = sizeof(hwc_window_video_formats) / sizeof(tbm_format);
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_get_capabilities(tdm_hwc *hwc, tdm_hwc_capability *capabilities)
-{
- tdm_vc4_hwc_data *hwc_data = hwc;
- tdm_vc4_data *vc4_data;
-
- RETURN_VAL_IF_FAIL(hwc != NULL, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(capabilities != NULL, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(hwc_data->output_data != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- vc4_data = hwc_data->output_data->vc4_data;
- RETURN_VAL_IF_FAIL(vc4_data != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- *capabilities |= TDM_HWC_CAPABILITY_VIDEO_SCALE;
-
- if (vc4_data->has_atomic)
- *capabilities |= TDM_HWC_CAPABILITY_FENCE;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_get_available_properties(tdm_hwc *hwc, const tdm_prop **props, int *count)
-{
- tdm_vc4_hwc_data *hwc_data = hwc;
-
- RETURN_VAL_IF_FAIL(hwc_data != NULL, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(props != NULL, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- *props = NULL;
- *count = 0;
-
- return TDM_ERROR_NONE;
-}
-
-tbm_surface_queue_h
-vc4_hwc_get_client_target_buffer_queue(tdm_hwc *hwc, tdm_error *error)
-{
- tdm_vc4_hwc_data *hwc_data = hwc;
- tbm_surface_queue_h tqueue = NULL;
-
- if (error)
- *error = TDM_ERROR_INVALID_PARAMETER;
-
- RETURN_VAL_IF_FAIL(hwc_data != NULL, NULL);
-
- if (hwc_data->target_hwc_window == NULL) {
- if (error)
- *error = TDM_ERROR_OPERATION_FAILED;
- return NULL;
- }
-
- tqueue = _vc4_hwc_window_get_tbm_buffer_queue(hwc_data->target_hwc_window, error);
- RETURN_VAL_IF_FAIL(tqueue, NULL);
-
- if (error)
- *error = TDM_ERROR_NONE;
-
- return tqueue;
-}
-
-tdm_error
-vc4_hwc_set_client_target_buffer(tdm_hwc *hwc, tbm_surface_h buffer, tdm_region damage)
-{
- tdm_vc4_hwc_data *hwc_data = hwc;
- tdm_error err;
-
- RETURN_VAL_IF_FAIL(hwc_data != NULL, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(hwc_data->target_hwc_window != NULL, TDM_ERROR_OPERATION_FAILED);
-
- err = vc4_hwc_window_set_buffer(hwc_data->target_hwc_window, buffer);
- RETURN_VAL_IF_FAIL(err == TDM_ERROR_NONE, err);
-
- err = vc4_hwc_window_set_buffer_damage(hwc_data->target_hwc_window, damage);
- RETURN_VAL_IF_FAIL(err == TDM_ERROR_NONE, err);
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_set_client_target_acquire_fence(tdm_hwc *hwc, int acquire_fence)
-{
- tdm_vc4_hwc_data *hwc_data = hwc;
- tdm_error err;
-
- RETURN_VAL_IF_FAIL(hwc_data != NULL, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(hwc_data->target_hwc_window != NULL, TDM_ERROR_OPERATION_FAILED);
-
- err = vc4_hwc_window_set_acquire_fence(hwc_data->target_hwc_window, acquire_fence);
- RETURN_VAL_IF_FAIL(err == TDM_ERROR_NONE, err);
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_validate(tdm_hwc *hwc, tdm_hwc_window **composited_wnds, uint32_t num_wnds, uint32_t *num_types)
-{
- tdm_vc4_hwc_data *hwc_data = hwc;
- tdm_vc4_output_data *output_data;
- tdm_vc4_hwc_window_data **composited_list = NULL;
- int i;
-
- RETURN_VAL_IF_FAIL(hwc_data != NULL, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(num_types != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- output_data = hwc_data->output_data;
- RETURN_VAL_IF_FAIL(output_data != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- TDM_DBG(" ==============Validate=================================");
-
- /* mirror is set. all clients should be the client type. */
- if (output_data->mirror_dst_output_data) {
- composited_list = (tdm_vc4_hwc_window_data **)composited_wnds;
- for (i = 0; i < num_wnds; i++) {
- composited_list[i]->validated_type = TDM_HWC_WIN_COMPOSITION_CLIENT;
- }
- hwc_data->need_target_window = 1;
- hwc_data->target_hwc_window->lzpos = ZPOS_0;
- } else {
- _vc4_hwc_apply_policy(hwc_data, composited_wnds, num_wnds);
- }
-
- *num_types = _vc4_hwc_get_changed_number(hwc_data);
-
- _print_validate_result(hwc_data, composited_wnds, num_wnds);
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_get_changed_composition_types(tdm_hwc *hwc, uint32_t *num_elements,
- tdm_hwc_window **hwc_wnds, tdm_hwc_window_composition *composition_types)
-{
- tdm_vc4_hwc_data *hwc_data = hwc;
- tdm_vc4_hwc_window_data *hwc_window_data = NULL;
- int num = 0;
-
- RETURN_VAL_IF_FAIL(hwc_data != NULL, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(num_elements != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- if ((hwc_wnds == NULL) || (composition_types == NULL)) {
- *num_elements = _vc4_hwc_get_changed_number(hwc_data);
- return TDM_ERROR_NONE;
- }
-
- LIST_FOR_EACH_ENTRY_REV(hwc_window_data, &hwc_data->hwc_window_list, link) {
- if (hwc_window_data->client_type == TDM_HWC_WIN_COMPOSITION_NONE)
- continue;
-
- if (num >= *num_elements)
- break;
-
- if (hwc_window_data->client_type != hwc_window_data->validated_type) {
- composition_types[num] = hwc_window_data->validated_type;
- hwc_wnds[num] = hwc_window_data;
- num++;
- }
- }
-
- /* set real num of changed composition types */
- *num_elements = num;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_accept_validation(tdm_hwc *hwc)
-{
- tdm_vc4_hwc_data *hwc_data = hwc;
- tdm_vc4_output_data *output_data;
- tdm_error ret = TDM_ERROR_NONE;
-
- RETURN_VAL_IF_FAIL(hwc_data != NULL, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(hwc_data->output_data != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- output_data = hwc_data->output_data;
-
- TDM_DBG(" ==============Accept Changes Done=================================");
-
- ret = _vc4_hwc_prepare_commit(hwc_data);
- RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
-
- /* prepare_mirror_commit for mirroring */
- if (output_data->mirror_dst_output_data) {
- ret = vc4_output_data_prepare_mirror_commit(output_data->mirror_dst_output_data,
- hwc_data->target_hwc_window->surface);
- if (ret != TDM_ERROR_NONE)
- TDM_ERR("fail to prepare mirror_commit.");
- }
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_commit(tdm_hwc *hwc, int sync, void *user_data)
-{
- tdm_vc4_hwc_data *hwc_data = hwc;
- tdm_vc4_output_data *output_data = NULL;
- tdm_error ret;
-
- RETURN_VAL_IF_FAIL(hwc_data, TDM_ERROR_INVALID_PARAMETER);
-
- output_data = hwc_data->output_data;
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
-
- TDM_DBG(" ==============COMMIT=================================");
-
- ret = vc4_output_commit(output_data, sync, user_data);
- RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
-
- /* commit for mirroring */
- if (output_data->mirror_dst_output_data) {
- ret = vc4_output_commit(output_data->mirror_dst_output_data, sync, NULL);
- RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret);
- }
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_set_commit_handler(tdm_hwc *hwc, tdm_hwc_commit_handler func)
-{
- tdm_vc4_hwc_data *hwc_data = hwc;
-
- RETURN_VAL_IF_FAIL(hwc_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(func, TDM_ERROR_INVALID_PARAMETER);
-
- hwc_data->commit_func = func;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_get_commit_fence(tdm_hwc *hwc, int *commit_fence)
-{
- tdm_vc4_hwc_data *hwc_data = hwc;
- tdm_vc4_output_data *output_data;
-
- RETURN_VAL_IF_FAIL(hwc_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(commit_fence, TDM_ERROR_INVALID_PARAMETER);
-
- output_data = hwc_data->output_data;
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
-
- *commit_fence = dup(output_data->commit_fence);
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_get_release_fences(tdm_hwc *hwc, uint32_t *num_elements,
- tdm_hwc_window **hwc_wnds, int *fences)
-{
- tdm_vc4_hwc_data *hwc_data = hwc;
- tdm_vc4_output_data *output_data;
- tdm_vc4_hwc_window_data *hwc_window_data = NULL;
- int num = 0;
-
- RETURN_VAL_IF_FAIL(hwc_data != NULL, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(num_elements != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- output_data = hwc_data->output_data;
- RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER);
-
- LIST_FOR_EACH_ENTRY_REV(hwc_window_data, &hwc_data->hwc_window_list, link) {
- if ((hwc_window_data->validated_type != TDM_HWC_WIN_COMPOSITION_DEVICE) &&
- (hwc_window_data->validated_type != TDM_HWC_WIN_COMPOSITION_VIDEO))
- continue;
-
- if (hwc_wnds && fences) {
- fences[num] = dup(output_data->commit_fence);
- hwc_wnds[num] = hwc_window_data;
- }
-
- num++;
- }
-
- *num_elements = num;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_target_window_set_info(tdm_vc4_hwc_data *hwc_data, int width, int height)
-{
- tdm_hwc_window_info info = {0};
- tdm_vc4_hwc_window_data *target_hwc_window;
- tdm_error ret = TDM_ERROR_NONE;
-
- RETURN_VAL_IF_FAIL(hwc_data, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(hwc_data->target_hwc_window, TDM_ERROR_INVALID_PARAMETER);
-
- target_hwc_window = hwc_data->target_hwc_window;
-
- info.dst_pos.x = 0;
- info.dst_pos.y = 0;
- info.dst_pos.w = width;
- info.dst_pos.h = height;
-
- info.src_config.pos.x = 0;
- info.src_config.pos.y = 0;
- info.src_config.pos.w = width;
- info.src_config.pos.h = height;
-
- info.src_config.size.h = width;
- info.src_config.size.v = height;
- info.src_config.format = TBM_FORMAT_ARGB8888;
-
- ret = vc4_hwc_window_set_info(target_hwc_window, &info);
- if (ret != TDM_ERROR_NONE) {
- TDM_ERR("set info target hwc window failed (%d)", ret);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_initailize_target_window(tdm_vc4_hwc_data *hwc_data)
-{
- tdm_hwc_window_info info = {0};
- tdm_error ret = TDM_ERROR_NONE;
- tdm_vc4_hwc_window_data *target_hwc_window;
-
- RETURN_VAL_IF_FAIL(hwc_data, TDM_ERROR_INVALID_PARAMETER);
-
- info.dst_pos.x = 0;
- info.dst_pos.y = 0;
- info.dst_pos.w = 2;
- info.dst_pos.h = 1;
-
- info.src_config.pos.x = 0;
- info.src_config.pos.y = 0;
- info.src_config.pos.w = 2;
- info.src_config.pos.h = 1;
-
- info.src_config.size.h = 2;
- info.src_config.size.v = 1;
- info.src_config.format = TBM_FORMAT_ARGB8888;
-
- target_hwc_window = _vc4_hwc_create_window(hwc_data, &info, &ret);
- if (ret != TDM_ERROR_NONE) {
- TDM_ERR("create target hwc window failed (%d)", ret);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- if (hwc_data->target_hwc_window)
- vc4_hwc_window_destroy(hwc_data->target_hwc_window);
-
- hwc_data->target_hwc_window = target_hwc_window;
- hwc_data->need_set_crtc = 1;
-
- return TDM_ERROR_NONE;
-}
diff --git a/src/libtdm-vc4/tdm_vc4_hwc.h b/src/libtdm-vc4/tdm_vc4_hwc.h
deleted file mode 100644
index aaf8f3d..0000000
--- a/src/libtdm-vc4/tdm_vc4_hwc.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/**************************************************************************
-
-libtdm_vc4
-
-Copyright 2017 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: SooChan Lim <sc1.lim@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#ifndef _TDM_VC4_HWC_H_
-#define _TDM_VC4_HWC_H_
-
-#include "tdm_vc4.h"
-
-tdm_error vc4_hwc_initailize_target_window(tdm_vc4_hwc_data *hwc_data);
-tdm_error vc4_hwc_target_window_set_info(tdm_vc4_hwc_data *hwc_data, int width, int height);
-
-#endif /* _TDM_VC4_HWC_H_ */
diff --git a/src/libtdm-vc4/tdm_vc4_hwc_window.c b/src/libtdm-vc4/tdm_vc4_hwc_window.c
deleted file mode 100644
index 6cfc80c..0000000
--- a/src/libtdm-vc4/tdm_vc4_hwc_window.c
+++ /dev/null
@@ -1,204 +0,0 @@
-/**************************************************************************
-
-libtdm_vc4
-
-Copyright 2017 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: SooChan Lim <sc1.lim@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "tdm_vc4.h"
-
-void
-vc4_hwc_window_destroy(tdm_hwc_window *hwc_window)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = hwc_window;
-
- RETURN_IF_FAIL(hwc_window_data != NULL);
-
- if (hwc_window_data->acquire_fence >= 0)
- close(hwc_window_data->acquire_fence);
-
- LIST_DEL(&hwc_window_data->link);
-
- free(hwc_window_data);
-}
-
-tdm_error
-vc4_hwc_window_set_composition_type(tdm_hwc_window *hwc_window,
- tdm_hwc_window_composition comp_type)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = hwc_window;
- tdm_vc4_hwc_data *hwc_data = hwc_window_data->hwc_data;
-
- RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(hwc_data != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- /* change the client_type when it is different from one which has before */
- if (hwc_window_data->client_type == comp_type)
- return TDM_ERROR_NONE;
-
- hwc_window_data->client_type = comp_type;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_region damage)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = hwc_window;
-
- RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- //TODO::
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = hwc_window;
- tdm_vc4_hwc_data *hwc_data;
-
- RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
- hwc_data = hwc_window_data->hwc_data;
- RETURN_VAL_IF_FAIL(hwc_data != NULL, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(info != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- if (!memcmp(&hwc_window_data->info, info, sizeof(tdm_hwc_window_info)))
- return TDM_ERROR_NONE;
-
- hwc_window_data->info = *info;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h surface)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = hwc_window;
- tdm_error err = TDM_ERROR_OPERATION_FAILED;
-
- RETURN_VAL_IF_FAIL(hwc_window_data != NULL, err);
-
- if (hwc_window_data->surface == surface)
- return TDM_ERROR_NONE;
-
- hwc_window_data->surface = surface;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_window_set_property(tdm_hwc_window *hwc_window, unsigned int id, tdm_value value)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = hwc_window;
-
- RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- //TODO:
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_window_get_property(tdm_hwc_window *hwc_window, unsigned int id, tdm_value *value)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = hwc_window;
-
- RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- //TODO:
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_window_get_constraints(tdm_hwc_window *hwc_window, int *constraints)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = hwc_window;
-
- RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
- RETURN_VAL_IF_FAIL(constraints != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- // no constraints
- *constraints = 0;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_window_set_name(tdm_hwc_window *hwc_window, const char *name)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = hwc_window;
-
- RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- if (!name)
- return TDM_ERROR_NONE;
-
- snprintf(hwc_window_data->name, TDM_NAME_LEN, "%s", name);
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_window_set_cursor_image(tdm_hwc_window *hwc_window, int width, int height, int stride, void *ptr)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = hwc_window;
-
- RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- hwc_window_data->cursor_img.width = width;
- hwc_window_data->cursor_img.height = height;
- hwc_window_data->cursor_img.stride = stride;
- hwc_window_data->cursor_img.ptr = ptr;
-
- hwc_window_data->cursor_img_refresh = 1;
-
- return TDM_ERROR_NONE;
-}
-
-tdm_error
-vc4_hwc_window_set_acquire_fence(tdm_hwc_window *hwc_window, int acquire_fence)
-{
- tdm_vc4_hwc_window_data *hwc_window_data = hwc_window;
-
- RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER);
-
- if (hwc_window_data->acquire_fence >= 0) {
- close(hwc_window_data->acquire_fence);
- hwc_window_data->acquire_fence = -1;
- }
-
- if (acquire_fence >= 0)
- hwc_window_data->acquire_fence = dup(acquire_fence);
-
- return TDM_ERROR_NONE;
-}
diff --git a/src/libtdm-vc4/tdm_vc4_hwc_window.h b/src/libtdm-vc4/tdm_vc4_hwc_window.h
deleted file mode 100644
index 1de390a..0000000
--- a/src/libtdm-vc4/tdm_vc4_hwc_window.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/**************************************************************************
-
-libtdm_vc4
-
-Copyright 2017 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: SooChan Lim <sc1.lim@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#ifndef _TDM_VC4_HWC_WINDOW_H_
-#define _TDM_VC4_HWC_WINDOW_H_
-
-#include "tdm_vc4.h"
-
-#endif /* _TDM_VC4_HWC_WINDOW_H_ */ \ No newline at end of file
diff --git a/src/libtdm-vc4/tdm_vc4_types.h b/src/libtdm-vc4/tdm_vc4_types.h
deleted file mode 100644
index 537ba23..0000000
--- a/src/libtdm-vc4/tdm_vc4_types.h
+++ /dev/null
@@ -1,318 +0,0 @@
-/**************************************************************************
-
-libtdm_vc4
-
-Copyright 2017 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: SooChan Lim <sc1.lim@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#ifndef _TDM_VC4_TYPES_H_
-#define _TDM_VC4_TYPES_H_
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include <errno.h>
-#include <unistd.h>
-#include <limits.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-
-#include <linux/fb.h>
-#include <xf86drm.h>
-#include <xf86drmMode.h>
-#include <tbm_surface.h>
-#include <tbm_surface_internal.h>
-#include <tdm_backend.h>
-#include <tdm_log.h>
-#include <tdm_list.h>
-#include <drm_fourcc.h>
-#include <tdm_helper.h>
-
-#if HAVE_UDEV
-#include <libudev.h>
-#endif
-
-#define C(b, m) (((b) >> (m)) & 0xFF)
-#define B(c, s) ((((unsigned int)(c)) & 0xff) << (s))
-#define FOURCC(a, b, c, d) (B(d, 24) | B(c, 16) | B(b, 8) | B(a, 0))
-#define FOURCC_STR(id) C(id, 0), C(id, 8), C(id, 16), C(id, 24)
-
-#define IS_RGB(format) (format == TBM_FORMAT_XRGB8888 || format == TBM_FORMAT_ARGB8888 || \
- format == TBM_FORMAT_XBGR8888 || format == TBM_FORMAT_ABGR8888)
-
-#define CLEAR(x) memset(&(x), 0, sizeof(x))
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-#define SWAP(a, b) ({int t; t = a; a = b; b = t; })
-#define ROUNDUP(x) (ceil(floor((float)(height) / 4)))
-
-#define ALIGN_TO_16B(x) ((((x) + (1 << 4) - 1) >> 4) << 4)
-#define ALIGN_TO_32B(x) ((((x) + (1 << 5) - 1) >> 5) << 5)
-#define ALIGN_TO_128B(x) ((((x) + (1 << 7) - 1) >> 7) << 7)
-#define ALIGN_TO_2KB(x) ((((x) + (1 << 11) - 1) >> 11) << 11)
-#define ALIGN_TO_8KB(x) ((((x) + (1 << 13) - 1) >> 13) << 13)
-#define ALIGN_TO_64KB(x) ((((x) + (1 << 16) - 1) >> 16) << 16)
-
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-
-#define RETURN_VAL_IF_FAIL(cond, val) {\
- if (!(cond)) {\
- TDM_ERR("'%s' failed", #cond);\
- return val;\
- } \
-}
-
-#define RETURN_IF_FAIL(cond) {\
- if (!(cond)) {\
- TDM_ERR("'%s' failed", #cond);\
- return;\
- } \
-}
-
-#define GOTO_IF_FAIL(cond, val) {\
- if (!(cond)) {\
- TDM_ERR("'%s' failed", #cond);\
- goto val;\
- } \
-}
-
-typedef struct _tdm_vc4_data tdm_vc4_data;
-typedef struct _tdm_vc4_output_data tdm_vc4_output_data;
-typedef struct _tdm_vc4_layer_data tdm_vc4_layer_data;
-typedef struct _tdm_vc4_hwc_data tdm_vc4_hwc_data;
-typedef struct _tdm_vc4_hwc_window_data tdm_vc4_hwc_window_data;
-typedef struct _tdm_vc4_event_data tdm_vc4_event_data;
-typedef struct _tdm_vc4_display_buffer tdm_vc4_display_buffer;
-
-typedef enum {
- TDM_DRM_EVENT_TYPE_WAIT,
- TDM_DRM_EVENT_TYPE_COMMIT,
- TDM_DRM_EVENT_TYPE_PAGEFLIP,
-} tdm_vc4_event_type;
-
-struct _tdm_vc4_data {
- tdm_display *dpy;
-
- int drm_fd;
-
-#if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4 && LIBDRM_MICRO_VERSION >= 47
- int has_universal_plane;
- int has_atomic;
-#endif
-
-#if HAVE_UDEV
- struct udev_monitor *uevent_monitor;
- tdm_event_loop_source *uevent_source;
-#endif
-
- drmModeResPtr mode_res;
- drmModePlaneResPtr plane_res;
-
- int hwc_mode;
-
- struct list_head output_list;
- struct list_head buffer_list;
-};
-
-struct _tdm_vc4_display_buffer {
- struct list_head link;
-
- unsigned int fb_id;
- tbm_surface_h buffer;
- int width;
- unsigned int height;
- unsigned int format;
- unsigned int handles[4];
- unsigned int fds[4];
- unsigned int pitches[4];
- unsigned int offsets[4];
- unsigned int size;
- unsigned int count;
-};
-
-struct _tdm_vc4_event_data {
- tdm_vc4_event_type type;
- tdm_vc4_output_data *output_data;
- void *user_data;
-};
-
-struct display_properties_ids {
- uint32_t connector_crtc_id;
- uint32_t crtc_mode_id;
- uint32_t crtc_active;
- uint32_t plane_fb_id;
- uint32_t plane_crtc_id;
- uint32_t plane_src_x;
- uint32_t plane_src_y;
- uint32_t plane_src_w;
- uint32_t plane_src_h;
- uint32_t plane_crtc_x;
- uint32_t plane_crtc_y;
- uint32_t plane_crtc_w;
- uint32_t plane_crtc_h;
- uint32_t plane_zpos;
-};
-
-struct _tdm_vc4_output_data {
- struct list_head link;
-
- /* data which are fixed at initializing */
- tdm_vc4_data *vc4_data;
- uint32_t connector_id;
- uint32_t encoder_id;
- uint32_t crtc_id;
- uint32_t pipe;
- uint32_t dpms_prop_id;
- int count_modes;
- int count_drm_modes;
- drmModeModeInfoPtr vc4_modes;
- tdm_output_mode *output_modes;
- tdm_output_type connector_type;
- unsigned int connector_type_id;
- struct list_head layer_list;
- tdm_vc4_layer_data *primary_layer;
-
- /* not fixed data below */
- tdm_output_vblank_handler vblank_func;
- tdm_output_commit_handler commit_func;
-
- tdm_output_conn_status status;
- tdm_output_status_handler status_func;
- void *status_user_data;
-
- int mode_changed;
- const tdm_output_mode *current_mode;
- unsigned int current_mode_blob_id;
-
- tbm_surface_h crtc_buffer;
- int crtc_enabled;
- unsigned int crtc_fb_id;
-
- uint32_t output_plane;
- struct display_properties_ids props;
-
- /* hwc */
- int hwc_enable;
- tdm_vc4_hwc_data *hwc_data;
-
- /* atomic prop ids*/
- struct {
- uint32_t crtc_id;
- uint32_t crtc_mode_id;
- uint32_t crtc_active;
- uint32_t out_fence_ptr;
- } atomic_props_ids;
-
- /* mirroring output_data, only one support */
- tdm_vc4_output_data *mirror_dst_output_data;
- tdm_transform mirror_dst_transform;
- tdm_vc4_output_data *mirror_src_output_data;
-
- int commit_fence;
-};
-
-struct _tdm_vc4_layer_data {
- struct list_head link;
-
- /* data which are fixed at initializing */
- tdm_vc4_data *vc4_data;
- tdm_vc4_output_data *output_data;
- uint32_t plane_id;
- tdm_layer_capability capabilities;
- int zpos;
-
- /* not fixed data below */
- tdm_info_layer info;
- int info_changed;
-
- tdm_vc4_display_buffer *display_buffer;
- int display_buffer_changed;
-
- /* atomic prop ids*/
- struct {
- uint32_t fb_id;
- uint32_t crtc_id;
- uint32_t src_x;
- uint32_t src_y;
- uint32_t src_w;
- uint32_t src_h;
- uint32_t crtc_x;
- uint32_t crtc_y;
- uint32_t crtc_w;
- uint32_t crtc_h;
- uint32_t zpos;
- uint32_t in_fence_fd;
- } atomic_props_ids;
-
- int acquire_fence;
-};
-
-struct _tdm_vc4_hwc_data {
- tdm_vc4_hwc_window_data *target_hwc_window;
-
- int need_validate;
- int need_target_window;
- int need_set_crtc;
-
- int target_window_zpos;
-
- tdm_vc4_output_data *output_data;
- struct list_head hwc_window_list;
-
- tbm_surface_queue_h cursor_tqueue;
- tbm_surface_h cursor_tsurface;
-
- tdm_hwc_commit_handler commit_func;
-};
-
-struct _tdm_vc4_hwc_window_data {
- struct list_head link;
-
- tdm_vc4_hwc_data *hwc_data;
-
- tdm_hwc_window_info info;
- tbm_surface_h surface;
- tdm_hwc_window_composition client_type;
- tdm_hwc_window_composition validated_type;
- int lzpos;
-
- char name[TDM_NAME_LEN];
- struct {
- int width;
- int height;
- int stride;
- void *ptr;
- } cursor_img;
- int cursor_img_surface;
- int cursor_img_refresh;
-
- int acquire_fence;
-};
-
-#endif /* _TDM_VC4_TYPES_H_ */
diff --git a/src/libhal-backend-tdm-vc4/tdm_backend_list.h b/src/tdm_backend_list.h
index 3873817..3873817 100644
--- a/src/libhal-backend-tdm-vc4/tdm_backend_list.h
+++ b/src/tdm_backend_list.h
diff --git a/src/libhal-backend-tdm-vc4/tdm_backend_log.c b/src/tdm_backend_log.c
index 808ceb1..808ceb1 100644
--- a/src/libhal-backend-tdm-vc4/tdm_backend_log.c
+++ b/src/tdm_backend_log.c
diff --git a/src/libhal-backend-tdm-vc4/tdm_backend_log.h b/src/tdm_backend_log.h
index a62ec86..a62ec86 100644
--- a/src/libhal-backend-tdm-vc4/tdm_backend_log.h
+++ b/src/tdm_backend_log.h
diff --git a/src/libhal-backend-tdm-vc4/tdm_backend_vc4.c b/src/tdm_backend_vc4.c
index b69c999..b69c999 100644
--- a/src/libhal-backend-tdm-vc4/tdm_backend_vc4.c
+++ b/src/tdm_backend_vc4.c
diff --git a/src/libhal-backend-tdm-vc4/tdm_backend_vc4.h b/src/tdm_backend_vc4.h
index 5c17786..5c17786 100644
--- a/src/libhal-backend-tdm-vc4/tdm_backend_vc4.h
+++ b/src/tdm_backend_vc4.h
diff --git a/src/libhal-backend-tdm-vc4/tdm_backend_vc4_types.h b/src/tdm_backend_vc4_types.h
index 46e6b08..46e6b08 100644
--- a/src/libhal-backend-tdm-vc4/tdm_backend_vc4_types.h
+++ b/src/tdm_backend_vc4_types.h
diff --git a/src/libhal-backend-tdm-vc4/tdm_vc4_display.c b/src/tdm_vc4_display.c
index 3db50bb..3db50bb 100644
--- a/src/libhal-backend-tdm-vc4/tdm_vc4_display.c
+++ b/src/tdm_vc4_display.c
diff --git a/src/libhal-backend-tdm-vc4/tdm_vc4_format.c b/src/tdm_vc4_format.c
index 043a4af..043a4af 100644
--- a/src/libhal-backend-tdm-vc4/tdm_vc4_format.c
+++ b/src/tdm_vc4_format.c
diff --git a/src/libhal-backend-tdm-vc4/tdm_vc4_hwc.c b/src/tdm_vc4_hwc.c
index 5924d82..5924d82 100644
--- a/src/libhal-backend-tdm-vc4/tdm_vc4_hwc.c
+++ b/src/tdm_vc4_hwc.c
diff --git a/src/libhal-backend-tdm-vc4/tdm_vc4_hwc_window.c b/src/tdm_vc4_hwc_window.c
index 84100d6..84100d6 100644
--- a/src/libhal-backend-tdm-vc4/tdm_vc4_hwc_window.c
+++ b/src/tdm_vc4_hwc_window.c