diff options
-rw-r--r-- | configure.ac | 37 | ||||
-rw-r--r-- | packaging/hal-backend-tdm-drm.manifest (renamed from packaging/libhal-backend-tdm-drm.manifest) | 0 | ||||
-rw-r--r-- | packaging/hal-backend-tdm-drm.spec (renamed from packaging/libtdm-drm.spec) | 38 | ||||
-rw-r--r-- | packaging/libtdm-drm.manifest | 5 | ||||
-rw-r--r-- | src/Makefile.am | 19 | ||||
-rw-r--r-- | src/libhal-backend-tdm-drm/Makefile.am | 18 | ||||
-rw-r--r-- | src/libtdm-drm/Makefile.am | 16 | ||||
-rw-r--r-- | src/libtdm-drm/tdm_drm.c | 492 | ||||
-rw-r--r-- | src/libtdm-drm/tdm_drm.h | 133 | ||||
-rw-r--r-- | src/libtdm-drm/tdm_drm_display.c | 1869 | ||||
-rw-r--r-- | src/libtdm-drm/tdm_drm_format.c | 134 | ||||
-rw-r--r-- | src/libtdm-drm/tdm_drm_hwc.c | 801 | ||||
-rw-r--r-- | src/libtdm-drm/tdm_drm_hwc.h | 39 | ||||
-rw-r--r-- | src/libtdm-drm/tdm_drm_hwc_window.c | 184 | ||||
-rw-r--r-- | src/libtdm-drm/tdm_drm_hwc_window.h | 36 | ||||
-rw-r--r-- | src/libtdm-drm/tdm_drm_pp.c | 440 | ||||
-rw-r--r-- | src/libtdm-drm/tdm_drm_pp.h | 43 | ||||
-rw-r--r-- | src/libtdm-drm/tdm_drm_types.h | 268 | ||||
-rw-r--r-- | src/tdm_backend_drm.c (renamed from src/libhal-backend-tdm-drm/tdm_backend_drm.c) | 0 | ||||
-rw-r--r-- | src/tdm_backend_drm.h (renamed from src/libhal-backend-tdm-drm/tdm_backend_drm.h) | 0 | ||||
-rw-r--r-- | src/tdm_backend_drm_types.h (renamed from src/libhal-backend-tdm-drm/tdm_backend_drm_types.h) | 0 | ||||
-rw-r--r-- | src/tdm_backend_list.h (renamed from src/libhal-backend-tdm-drm/tdm_backend_list.h) | 0 | ||||
-rw-r--r-- | src/tdm_backend_log.c (renamed from src/libhal-backend-tdm-drm/tdm_backend_log.c) | 0 | ||||
-rw-r--r-- | src/tdm_backend_log.h (renamed from src/libhal-backend-tdm-drm/tdm_backend_log.h) | 0 | ||||
-rw-r--r-- | src/tdm_drm_display.c (renamed from src/libhal-backend-tdm-drm/tdm_drm_display.c) | 0 | ||||
-rw-r--r-- | src/tdm_drm_format.c (renamed from src/libhal-backend-tdm-drm/tdm_drm_format.c) | 0 | ||||
-rw-r--r-- | src/tdm_drm_hwc.c (renamed from src/libhal-backend-tdm-drm/tdm_drm_hwc.c) | 0 | ||||
-rw-r--r-- | src/tdm_drm_hwc_window.c (renamed from src/libhal-backend-tdm-drm/tdm_drm_hwc_window.c) | 0 | ||||
-rw-r--r-- | src/tdm_drm_pp.c (renamed from src/libhal-backend-tdm-drm/tdm_drm_pp.c) | 0 |
29 files changed, 27 insertions, 4545 deletions
diff --git a/configure.ac b/configure.ac index 8885a6b..5842ed7 100644 --- a/configure.ac +++ b/configure.ac @@ -1,8 +1,8 @@ AC_PREREQ([2.60]) -AC_INIT([libtdm-drm], +AC_INIT([hal-backend-tdm-drm], [1.0.0], [https://www.tizen.org], - [libtdm-drm]) + [hal-backend-tdm-drm]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_SRCDIR([Makefile.am]) @@ -25,30 +25,15 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) PKG_CHECK_MODULES(UDEV, libudev, [udev=yes], [udev=no]) -# for libtdm-drm -PKG_CHECK_MODULES(TDM_DRM, libtdm libtbm libdrm pixman-1) - -# for libhal-backend-tdm-drm -PKG_CHECK_MODULES(LIBHAL_BACKEND_TDM_DRM, hal-api-common hal-api-tdm hal-api-tbm libdrm dlog pixman-1) +PKG_CHECK_MODULES(LIBHAL_BACKEND_TDM_DRM, hal-api-common hal-api-tdm hal-api-tbm libtbm libdrm dlog pixman-1) if test x"$udev" = xyes; then - # for libtdm-drm AC_DEFINE(HAVE_UDEV,1,[Enable udev-based monitor hotplug detection]) - TDM_DRM_CFLAGS="$TDM_DRM_CFLAGS $UDEV_CFLAGS" - TDM_DRM_LIBS="$TDM_DRM_LIBS $UDEV_LIBS" - # for libhal-backend-tdm-drm LIBHAL_BACKEND_TDM_DRM_CFLAGS="$LIBHAL_BACKEND_TDM_DRM_CFLAGS $UDEV_CFLAGS" LIBHAL_BACKEND_TDM_DRM_LIBS="$LIBHAL_BACKEND_TDM_DRM_LIBS $UDEV_LIBS" - AC_SUBST(LIBHAL_BACKEND_TDM_DRM_CFLAGS) - AC_SUBST(LIBHAL_BACKEND_TDM_DRM_LIBS) fi -# for libtdm-drm -AC_SUBST(TDM_DRM_CFLAGS) -AC_SUBST(TDM_DRM_LIBS) - -# for libhal-backend-tdm-drm AC_SUBST(LIBHAL_BACKEND_TDM_DRM_CFLAGS) AC_SUBST(LIBHAL_BACKEND_TDM_DRM_LIBS) @@ -59,13 +44,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 tbm 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]), @@ -77,8 +55,6 @@ AC_SUBST(HAL_LIBDIR) # For enumerating devices in test case AC_OUTPUT([ Makefile - src/libhal-backend-tdm-drm/Makefile - src/libtdm-drm/Makefile src/Makefile]) echo "" @@ -88,10 +64,3 @@ echo "LIBHAL_BACKEND_TDM_DRM_CFLAGS : $LIBHAL_BACKEND_TDM_DRM_CFLAGS" echo "LIBHAL_BACKEND_TDM_DRM_LIBS : $LIBHAL_BACKEND_TDM_DRM_LIBS" echo "TDM_MODULE_DIR : $HAL_LIBDIR" echo "" -echo "" -echo "$PACKAGE_STRING will be compiled with:" -echo "" -echo "TDM_DRM_CFLAGS : $TDM_DRM_CFLAGS" -echo "TDM_DRM_LIBS : $TDM_DRM_LIBS" -echo "TDM_MODULE_DIR : $TDM_MODULE_PATH" -echo "" diff --git a/packaging/libhal-backend-tdm-drm.manifest b/packaging/hal-backend-tdm-drm.manifest index 75b0fa5..75b0fa5 100644 --- a/packaging/libhal-backend-tdm-drm.manifest +++ b/packaging/hal-backend-tdm-drm.manifest diff --git a/packaging/libtdm-drm.spec b/packaging/hal-backend-tdm-drm.spec index 88470fb..978468b 100644 --- a/packaging/libtdm-drm.spec +++ b/packaging/hal-backend-tdm-drm.spec @@ -1,17 +1,15 @@ -Name: libtdm-drm +Name: hal-backend-tdm-drm Version: 2.0.5 Release: 0 -Summary: Tizen Display Manager DRM Back-End Library -Group: Development/Libraries +Summary: hal-backend-tdm module for drm +Group: System/Libraries License: MIT Source0: %{name}-%{version}.tar.gz -Source1001: %{name}.manifest -Source1002: libhal-backend-tdm-drm.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) @@ -19,23 +17,13 @@ BuildRequires: pkgconfig(hal-api-tbm) BuildRequires: pkgconfig(pixman-1) %description -Back-End library of Tizen Display Manager DRM : libtdm-mgr DRM library - -%package -n hal-backend-tdm-drm -Summary: hal-backend-tdm module for drm -Group: System/Libraries -Requires: hal-api-tdm -Requires: hal-api-common - -%description -n hal-backend-tdm-drm -descriptionion: hal tdm backend module for drm +description: hal tdm backend module for drm %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 \ @@ -53,28 +41,14 @@ mkdir -p %{buildroot}%{_hal_licensedir}/libhal-backend-tdm-drm cp -af COPYING %{buildroot}%{_hal_licensedir}/libhal-backend-tdm-drm %post -if [ -f %{_libdir}/tdm/libtdm-default.so ]; then - rm -rf %{_libdir}/tdm/libtdm-default.so -fi -ln -s libtdm-drm.so %{_libdir}/tdm/libtdm-default.so - -%postun -p /sbin/ldconfig - -%post -n hal-backend-tdm-drm if [ -f %{_hal_libdir}/libhal-backend-tdm.so ]; then rm -rf %{_hal_libdir}/libhal-backend-tdm.so fi ln -s libhal-backend-tdm-drm.so %{_hal_libdir}/libhal-backend-tdm.so -%postun -n hal-backend-tdm-drm -p /sbin/ldconfig +%postun -p /sbin/ldconfig %files -%defattr(-,root,root,-) %manifest %{name}.manifest -%license COPYING -%{_libdir}/tdm/libtdm-drm.so - -%files -n hal-backend-tdm-drm -%manifest libhal-backend-tdm-drm.manifest %{_hal_licensedir}/libhal-backend-tdm-drm/COPYING %{_hal_libdir}/libhal-backend-*.so* diff --git a/packaging/libtdm-drm.manifest b/packaging/libtdm-drm.manifest deleted file mode 100644 index 75b0fa5..0000000 --- a/packaging/libtdm-drm.manifest +++ /dev/null @@ -1,5 +0,0 @@ -<manifest> - <request> - <domain name="_"/> - </request> -</manifest> diff --git a/src/Makefile.am b/src/Makefile.am index 8cc98b1..d42bca9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1 +1,18 @@ -SUBDIRS = libtdm-drm libhal-backend-tdm-drm +AM_CFLAGS = \ + $(LIBHAL_BACKEND_TDM_DRM_CFLAGS) \ + -I$(top_srcdir)/src/libhal-backend-tdm-drm + +libhal_backend_tdm_drm_la_LTLIBRARIES = libhal-backend-tdm-drm.la +libhal_backend_tdm_drm_ladir = @HAL_LIBDIR@ +libhal_backend_tdm_drm_la_LDFLAGS = -module -avoid-version +libhal_backend_tdm_drm_la_LIBADD = $(LIBHAL_BACKEND_TDM_DRM_LIBS) -ldl + +libhal_backend_tdm_drm_la_SOURCES = \ + tdm_backend_log.c \ + tdm_backend_drm.c \ + tdm_drm_display.c \ + tdm_drm_format.c \ + tdm_drm_hwc_window.c \ + tdm_drm_hwc.c \ + tdm_drm_pp.c + diff --git a/src/libhal-backend-tdm-drm/Makefile.am b/src/libhal-backend-tdm-drm/Makefile.am deleted file mode 100644 index d42bca9..0000000 --- a/src/libhal-backend-tdm-drm/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -AM_CFLAGS = \ - $(LIBHAL_BACKEND_TDM_DRM_CFLAGS) \ - -I$(top_srcdir)/src/libhal-backend-tdm-drm - -libhal_backend_tdm_drm_la_LTLIBRARIES = libhal-backend-tdm-drm.la -libhal_backend_tdm_drm_ladir = @HAL_LIBDIR@ -libhal_backend_tdm_drm_la_LDFLAGS = -module -avoid-version -libhal_backend_tdm_drm_la_LIBADD = $(LIBHAL_BACKEND_TDM_DRM_LIBS) -ldl - -libhal_backend_tdm_drm_la_SOURCES = \ - tdm_backend_log.c \ - tdm_backend_drm.c \ - tdm_drm_display.c \ - tdm_drm_format.c \ - tdm_drm_hwc_window.c \ - tdm_drm_hwc.c \ - tdm_drm_pp.c - diff --git a/src/libtdm-drm/Makefile.am b/src/libtdm-drm/Makefile.am deleted file mode 100644 index 16c3a35..0000000 --- a/src/libtdm-drm/Makefile.am +++ /dev/null @@ -1,16 +0,0 @@ -AM_CFLAGS = \ - $(TDM_DRM_CFLAGS) \ - -I$(top_srcdir)/src - -libtdm_drm_la_LTLIBRARIES = libtdm-drm.la -libtdm_drm_ladir = $(TDM_MODULE_PATH) -libtdm_drm_la_LDFLAGS = -module -avoid-version -libtdm_drm_la_LIBADD = $(TDM_DRM_LIBS) -ldl - -libtdm_drm_la_SOURCES = \ - tdm_drm_hwc_window.c \ - tdm_drm_hwc.c \ - tdm_drm_format.c \ - tdm_drm_pp.c \ - tdm_drm_display.c \ - tdm_drm.c diff --git a/src/libtdm-drm/tdm_drm.c b/src/libtdm-drm/tdm_drm.c deleted file mode 100644 index 2d4bf3a..0000000 --- a/src/libtdm-drm/tdm_drm.c +++ /dev/null @@ -1,492 +0,0 @@ -/************************************************************************** - -libtdm_drm - -Copyright 2015 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_drm.h" -#include <tdm_helper.h> -#include <tbm_drm_helper.h> - -#define ENABLE_PP - -#define TDM_DRM_NAME "vigs" - -#define TDM_HWC 1 - -static tdm_drm_data *drm_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_drm_udev_fd_handler(int fd, tdm_event_loop_mask mask, void *user_data) -{ - tdm_drm_data *edata = (tdm_drm_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_drm_display_update_output_status(edata); - } - - udev_device_unref(dev); - - return TDM_ERROR_NONE; -} - -static void -_tdm_drm_udev_init(tdm_drm_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_drm_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_drm_udev_deinit(tdm_drm_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_drm_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_drm_deinit(tdm_backend_data *bdata) -{ - if (drm_data != bdata) - return; - - TDM_INFO("deinit"); - -#ifdef HAVE_UDEV - _tdm_drm_udev_deinit(drm_data); -#endif - - tdm_drm_display_destroy_output_list(drm_data); - - if (drm_data->plane_res) - drmModeFreePlaneResources(drm_data->plane_res); - if (drm_data->mode_res) - drmModeFreeResources(drm_data->mode_res); - if (drm_data->drm_fd >= 0) - close(drm_data->drm_fd); - - free(drm_data); - drm_data = NULL; -} - -tdm_backend_data * -tdm_drm_init(tdm_display *dpy, tdm_error *error) -{ - tdm_func_display drm_func_display; - tdm_func_output drm_func_output; - tdm_func_layer drm_func_layer; - tdm_func_hwc drm_func_hwc; - tdm_func_hwc_window drm_func_hwc_window; -#ifdef ENABLE_PP - tdm_func_pp drm_func_pp; -#endif - tdm_error ret; - - if (!dpy) { - TDM_ERR("display is null"); - if (error) - *error = TDM_ERROR_INVALID_PARAMETER; - return NULL; - } - - if (drm_data) { - TDM_ERR("failed: init twice"); - if (error) - *error = TDM_ERROR_BAD_REQUEST; - return NULL; - } - - drm_data = calloc(1, sizeof(tdm_drm_data)); - if (!drm_data) { - TDM_ERR("alloc failed"); - if (error) - *error = TDM_ERROR_OUT_OF_MEMORY; - return NULL; - } - -#if TDM_HWC - /* enable the tdm_hwc */ - drm_data->hwc_mode = 1; -#endif - - LIST_INITHEAD(&drm_data->output_list); - LIST_INITHEAD(&drm_data->buffer_list); - - memset(&drm_func_display, 0, sizeof(drm_func_display)); - drm_func_display.display_get_capability = drm_display_get_capability; - drm_func_display.display_get_pp_capability = drm_display_get_pp_capability; - drm_func_display.display_get_outputs = drm_display_get_outputs; - drm_func_display.display_get_fd = drm_display_get_fd; - drm_func_display.display_handle_events = drm_display_handle_events; - drm_func_display.display_create_pp = drm_display_create_pp; - - memset(&drm_func_output, 0, sizeof(drm_func_output)); - drm_func_output.output_get_capability = drm_output_get_capability; - drm_func_output.output_get_layers = drm_output_get_layers; - drm_func_output.output_set_property = drm_output_set_property; - drm_func_output.output_get_property = drm_output_get_property; - drm_func_output.output_wait_vblank = drm_output_wait_vblank; - drm_func_output.output_set_vblank_handler = drm_output_set_vblank_handler; - drm_func_output.output_commit = drm_output_commit; - drm_func_output.output_set_commit_handler = drm_output_set_commit_handler; - drm_func_output.output_set_dpms = drm_output_set_dpms; - drm_func_output.output_get_dpms = drm_output_get_dpms; - drm_func_output.output_set_mode = drm_output_set_mode; - drm_func_output.output_get_mode = drm_output_get_mode; -#ifdef HAVE_UDEV - drm_func_output.output_set_status_handler = drm_output_set_status_handler; -#endif - - if (drm_data->hwc_mode) { - drm_func_output.output_get_hwc = drm_output_get_hwc; - - memset(&drm_func_hwc, 0, sizeof(drm_func_hwc)); - drm_func_hwc.hwc_create_window = drm_hwc_create_window; - drm_func_hwc.hwc_get_video_supported_formats = drm_hwc_get_video_supported_formats; - drm_func_hwc.hwc_get_video_available_properties = NULL; - drm_func_hwc.hwc_get_capabilities = drm_hwc_get_capabilities; - drm_func_hwc.hwc_get_available_properties = drm_hwc_get_available_properties; - drm_func_hwc.hwc_get_client_target_buffer_queue = drm_hwc_get_client_target_buffer_queue; - drm_func_hwc.hwc_set_client_target_buffer = drm_hwc_set_client_target_buffer; - drm_func_hwc.hwc_validate = drm_hwc_validate; - drm_func_hwc.hwc_get_changed_composition_types = drm_hwc_get_changed_composition_types; - drm_func_hwc.hwc_accept_validation = drm_hwc_accept_validation; - drm_func_hwc.hwc_commit = drm_hwc_commit; - drm_func_hwc.hwc_set_commit_handler = drm_hwc_set_commit_handler; - - memset(&drm_func_hwc_window, 0, sizeof(drm_func_hwc_window)); - drm_func_hwc_window.hwc_window_destroy = drm_hwc_window_destroy; - drm_func_hwc_window.hwc_window_acquire_buffer_queue = NULL; // no need - drm_func_hwc_window.hwc_window_release_buffer_queue = NULL; // no need - drm_func_hwc_window.hwc_window_set_composition_type = drm_hwc_window_set_composition_type; - drm_func_hwc_window.hwc_window_set_buffer_damage = drm_hwc_window_set_buffer_damage; - drm_func_hwc_window.hwc_window_set_info = drm_hwc_window_set_info; - drm_func_hwc_window.hwc_window_set_buffer = drm_hwc_window_set_buffer; - drm_func_hwc_window.hwc_window_set_property = drm_hwc_window_set_property; - drm_func_hwc_window.hwc_window_get_property = drm_hwc_window_get_property; - drm_func_hwc_window.hwc_window_get_constraints = drm_hwc_window_get_constraints; - drm_func_hwc_window.hwc_window_set_name = drm_hwc_window_set_name; - drm_func_hwc_window.hwc_window_set_cursor_image = drm_hwc_window_set_cursor_image; - } - - memset(&drm_func_layer, 0, sizeof(drm_func_layer)); - drm_func_layer.layer_get_capability = drm_layer_get_capability; - drm_func_layer.layer_set_property = drm_layer_set_property; - drm_func_layer.layer_get_property = drm_layer_get_property; - drm_func_layer.layer_set_info = drm_layer_set_info; - drm_func_layer.layer_get_info = drm_layer_get_info; - drm_func_layer.layer_set_buffer = drm_layer_set_buffer; - drm_func_layer.layer_unset_buffer = drm_layer_unset_buffer; - -#ifdef ENABLE_PP - memset(&drm_func_pp, 0, sizeof(drm_func_pp)); - drm_func_pp.pp_destroy = drm_pp_destroy; - drm_func_pp.pp_set_info = drm_pp_set_info; - drm_func_pp.pp_attach = drm_pp_attach; - drm_func_pp.pp_commit = drm_pp_commit; - drm_func_pp.pp_set_done_handler = drm_pp_set_done_handler; -#endif - - ret = tdm_backend_register_func_display(dpy, &drm_func_display); - if (ret != TDM_ERROR_NONE) - goto failed; - - ret = tdm_backend_register_func_output(dpy, &drm_func_output); - if (ret != TDM_ERROR_NONE) - goto failed; - - ret = tdm_backend_register_func_layer(dpy, &drm_func_layer); - if (ret != TDM_ERROR_NONE) - goto failed; - - if (drm_data->hwc_mode) { - ret = tdm_backend_register_func_hwc(dpy, &drm_func_hwc); - if (ret != TDM_ERROR_NONE) - goto failed; - - ret = tdm_backend_register_func_hwc_window(dpy, &drm_func_hwc_window); - if (ret != TDM_ERROR_NONE) - goto failed; - } - -#ifdef ENABLE_PP - ret = tdm_backend_register_func_pp(dpy, &drm_func_pp); - if (ret != TDM_ERROR_NONE) - goto failed; -#endif - - drm_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. - */ - drm_data->drm_fd = tbm_drm_helper_get_master_fd(); - if (drm_data->drm_fd < 0) { - drm_data->drm_fd = _tdm_drm_open_drm(); - - if (drm_data->drm_fd < 0) { - ret = TDM_ERROR_OPERATION_FAILED; - goto failed; - } - - tbm_drm_helper_set_tbm_master_fd(drm_data->drm_fd); - } - - TDM_INFO("master fd: %d", drm_data->drm_fd); - -#ifdef HAVE_UDEV - _tdm_drm_udev_init(drm_data); -#endif - -#if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4 && LIBDRM_MICRO_VERSION >= 47 - if (drmSetClientCap(drm_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"); - drm_data->has_universal_plane = 1; - } -#endif - - drm_data->mode_res = drmModeGetResources(drm_data->drm_fd); - if (!drm_data->mode_res) { - TDM_ERR("no drm resource: %m"); - ret = TDM_ERROR_OPERATION_FAILED; - goto failed; - } - - drm_data->plane_res = drmModeGetPlaneResources(drm_data->drm_fd); - if (!drm_data->plane_res) { - TDM_ERR("no drm plane resource: %m"); - ret = TDM_ERROR_OPERATION_FAILED; - goto failed; - } - - if (drm_data->plane_res->count_planes <= 0) { - TDM_ERR("no drm plane resource"); - ret = TDM_ERROR_OPERATION_FAILED; - goto failed; - } - - ret = tdm_drm_display_create_output_list(drm_data); - if (ret != TDM_ERROR_NONE) - goto failed; - - ret = tdm_drm_display_create_layer_list(drm_data); - if (ret != TDM_ERROR_NONE) - goto failed; - - if (error) - *error = TDM_ERROR_NONE; - - TDM_INFO("init success!"); - - return (tdm_backend_data *)drm_data; -failed: - if (error) - *error = ret; - - tdm_drm_deinit(drm_data); - - TDM_ERR("init failed!"); - return NULL; -} - -tdm_backend_module tdm_backend_module_data = { - "drm", - "Samsung", - TDM_BACKEND_SET_ABI_VERSION(1, 1), - tdm_drm_init, - tdm_drm_deinit -}; diff --git a/src/libtdm-drm/tdm_drm.h b/src/libtdm-drm/tdm_drm.h deleted file mode 100644 index 5a0aec9..0000000 --- a/src/libtdm-drm/tdm_drm.h +++ /dev/null @@ -1,133 +0,0 @@ -/************************************************************************** - -libtdm_drm - -Copyright 2015 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_DRM_H_ -#define _TDM_DRM_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 <tdm_backend.h> -#include <tdm_log.h> -#include <tdm_list.h> -#include "tdm_drm_types.h" -#include "tdm_drm_hwc.h" -#include "tdm_drm_hwc_window.h" - -#if HAVE_UDEV -#include <libudev.h> -#endif - -/* drm backend functions (display) */ -tdm_error drm_display_get_capability(tdm_backend_data *bdata, tdm_caps_display *caps); -tdm_error drm_display_get_pp_capability(tdm_backend_data *bdata, tdm_caps_pp *caps); -tdm_output** drm_display_get_outputs(tdm_backend_data *bdata, int *count, tdm_error *error); -tdm_error drm_display_get_fd(tdm_backend_data *bdata, int *fd); -tdm_error drm_display_handle_events(tdm_backend_data *bdata); -tdm_pp* drm_display_create_pp(tdm_backend_data *bdata, tdm_error *error); -tdm_error drm_output_get_capability(tdm_output *output, tdm_caps_output *caps); -tdm_layer** drm_output_get_layers(tdm_output *output, int *count, tdm_error *error); -tdm_error drm_output_set_property(tdm_output *output, unsigned int id, tdm_value value); -tdm_error drm_output_get_property(tdm_output *output, unsigned int id, tdm_value *value); -tdm_error drm_output_wait_vblank(tdm_output *output, int interval, int sync, void *user_data); -tdm_error drm_output_set_vblank_handler(tdm_output *output, tdm_output_vblank_handler func); -tdm_error drm_output_commit(tdm_output *output, int sync, void *user_data); -tdm_error drm_output_set_commit_handler(tdm_output *output, tdm_output_commit_handler func); -tdm_error drm_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value); -tdm_error drm_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value); -tdm_error drm_output_set_mode(tdm_output *output, const tdm_output_mode *mode); -tdm_error drm_output_get_mode(tdm_output *output, const tdm_output_mode **mode); -tdm_error drm_output_set_status_handler(tdm_output *output, tdm_output_status_handler func, void *user_data); -tdm_hwc *drm_output_get_hwc(tdm_output *output, tdm_error *error); - -tdm_hwc_window *drm_hwc_create_window(tdm_hwc *hwc, tdm_error *error); -tdm_error drm_hwc_get_video_supported_formats(tdm_hwc *hwc, const tbm_format **formats, int *count); -tdm_error drm_hwc_get_capabilities(tdm_hwc *hwc, tdm_hwc_capability *capabilities); -tdm_error drm_hwc_get_available_properties(tdm_hwc *hwc, const tdm_prop **props, int *count); -tbm_surface_queue_h drm_hwc_get_client_target_buffer_queue(tdm_hwc *hwc, tdm_error *error); -tdm_error drm_hwc_set_client_target_buffer(tdm_hwc *hwc, tbm_surface_h buffer, tdm_region damage); -tdm_error drm_hwc_validate(tdm_hwc *hwc, tdm_hwc_window **composited_wnds, uint32_t num_wnds, uint32_t *num_types); -tdm_error drm_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 drm_hwc_accept_validation(tdm_hwc *hwc); -tdm_error drm_hwc_commit(tdm_hwc *hwc, int sync, void *user_data); -tdm_error drm_hwc_set_commit_handler(tdm_hwc *hwc, tdm_hwc_commit_handler func); - -void drm_hwc_window_destroy(tdm_hwc_window *hwc_window); -tdm_error drm_hwc_window_set_composition_type(tdm_hwc_window *hwc_window, tdm_hwc_window_composition composition_type); -tdm_error drm_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_region damage); -tdm_error drm_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info); -tdm_error drm_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h surface); -tdm_error drm_hwc_window_set_property(tdm_hwc_window *hwc_window, unsigned int id, tdm_value value); -tdm_error drm_hwc_window_get_property(tdm_hwc_window *hwc_window, unsigned int id, tdm_value *value); -tdm_error drm_hwc_window_get_constraints(tdm_hwc_window *hwc_window, int *constraints); -tdm_error drm_hwc_window_set_name(tdm_hwc_window *hwc_window, const char *name); -tdm_error drm_hwc_window_set_cursor_image(tdm_hwc_window *hwc_window, int width, int height, int stride, void *ptr); - -tdm_error drm_layer_get_capability(tdm_layer *layer, tdm_caps_layer *caps); -tdm_error drm_layer_set_property(tdm_layer *layer, unsigned int id, tdm_value value); -tdm_error drm_layer_get_property(tdm_layer *layer, unsigned int id, tdm_value *value); -tdm_error drm_layer_set_info(tdm_layer *layer, tdm_info_layer *info); -tdm_error drm_layer_get_info(tdm_layer *layer, tdm_info_layer *info); -tdm_error drm_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer); -tdm_error drm_layer_unset_buffer(tdm_layer *layer); -void drm_pp_destroy(tdm_pp *pp); -tdm_error drm_pp_set_info(tdm_pp *pp, tdm_info_pp *info); -tdm_error drm_pp_attach(tdm_pp *pp, tbm_surface_h src, tbm_surface_h dst); -tdm_error drm_pp_commit(tdm_pp *pp); -tdm_error drm_pp_set_done_handler(tdm_pp *pp, tdm_pp_done_handler func, void *user_data); - -uint32_t tdm_drm_format_to_drm_format(tbm_format format); -tbm_format tdm_drm_format_to_tbm_format(uint32_t format); - -void tdm_drm_display_update_output_status(tdm_drm_data *drm_data); -tdm_error tdm_drm_display_create_output_list(tdm_drm_data *drm_data); -void tdm_drm_display_destroy_output_list(tdm_drm_data *drm_data); -tdm_error tdm_drm_display_create_layer_list(tdm_drm_data *drm_data); - -tdm_drm_layer_data * drm_output_data_get_layer_data(tdm_drm_output_data *output_data, int layer_zops); - -#endif /* _TDM_DRM_H_ */ diff --git a/src/libtdm-drm/tdm_drm_display.c b/src/libtdm-drm/tdm_drm_display.c deleted file mode 100644 index ea9a3cc..0000000 --- a/src/libtdm-drm/tdm_drm_display.c +++ /dev/null @@ -1,1869 +0,0 @@ -/************************************************************************** - -libtdm_drm - -Copyright 2015 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 <tdm_helper.h> - -#include "tdm_drm.h" -#include "tdm_drm_pp.h" - -static drmModeModeInfoPtr -_tdm_drm_display_get_mode(tdm_drm_output_data *output_data) -{ - int i; - - if (!output_data->current_mode) { - TDM_ERR("no output_data->current_mode"); - return NULL; - } - - for (i = 0; i < output_data->count_modes; i++) { - drmModeModeInfoPtr drm_mode = &output_data->drm_modes[i]; - if ((drm_mode->hdisplay == output_data->current_mode->hdisplay) && - (drm_mode->vdisplay == output_data->current_mode->vdisplay) && - (drm_mode->vrefresh == output_data->current_mode->vrefresh) && - (drm_mode->flags == output_data->current_mode->flags) && - (drm_mode->type == output_data->current_mode->type) && - !(strncmp(drm_mode->name, output_data->current_mode->name, TDM_NAME_LEN))) - return drm_mode; - } - - return NULL; -} - -static void -_tdm_drm_display_to_tdm_mode(drmModeModeInfoPtr drm_mode, - tdm_output_mode *tdm_mode) -{ - tdm_mode->clock = drm_mode->clock; - tdm_mode->hdisplay = drm_mode->hdisplay; - tdm_mode->hsync_start = drm_mode->hsync_start; - tdm_mode->hsync_end = drm_mode->hsync_end; - tdm_mode->htotal = drm_mode->htotal; - tdm_mode->hskew = drm_mode->hskew; - tdm_mode->vdisplay = drm_mode->vdisplay; - tdm_mode->vsync_start = drm_mode->vsync_start; - tdm_mode->vsync_end = drm_mode->vsync_end; - tdm_mode->vtotal = drm_mode->vtotal; - tdm_mode->vscan = drm_mode->vscan; - tdm_mode->vrefresh = drm_mode->vrefresh; - tdm_mode->flags = drm_mode->flags; - tdm_mode->type = drm_mode->type; - snprintf(tdm_mode->name, TDM_NAME_LEN, "%s", drm_mode->name); -} - -static tdm_error -_tdm_drm_display_get_cur_msc(int fd, int pipe, uint *msc) -{ - drmVBlank vbl; - - vbl.request.type = DRM_VBLANK_RELATIVE; - if (pipe > 0) - vbl.request.type |= DRM_VBLANK_SECONDARY; - - 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_drm_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 > 0) - vbl.request.type |= DRM_VBLANK_SECONDARY; - - vbl.request.sequence = *target_msc; - vbl.request.signal = (unsigned long)(uintptr_t)data; - - if (drmWaitVBlank(fd, &vbl)) { - *target_msc = 0; - TDM_ERR("wait vblank failed: %m"); - return TDM_ERROR_OPERATION_FAILED; - } - - *target_msc = vbl.reply.sequence; - - return TDM_ERROR_NONE; -} - -static tdm_error -_tdm_drm_output_update_status(tdm_drm_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_drm_display_commit_primary_layer(tdm_drm_layer_data *layer_data, - void *user_data, int *do_waitvblank) -{ - tdm_drm_data *drm_data = layer_data->drm_data; - tdm_drm_output_data *output_data = layer_data->output_data; - - if (output_data->mode_changed && layer_data->display_buffer_changed) { - drmModeModeInfoPtr mode; - - if (!layer_data->display_buffer) { - TDM_ERR("primary layer should have a buffer for modestting"); - return TDM_ERROR_BAD_REQUEST; - } - - output_data->mode_changed = 0; - layer_data->display_buffer_changed = 0; - layer_data->info_changed = 0; - - mode = _tdm_drm_display_get_mode(output_data); - if (!mode) { - TDM_ERR("couldn't find proper mode"); - return TDM_ERROR_BAD_REQUEST; - } - - if (drmModeSetCrtc(drm_data->drm_fd, output_data->crtc_id, - layer_data->display_buffer->fb_id, 0, 0, - &output_data->connector_id, 1, mode)) { - TDM_ERR("set crtc failed: %m"); - return TDM_ERROR_OPERATION_FAILED; - } - - _tdm_drm_output_update_status(output_data, TDM_OUTPUT_CONN_STATUS_MODE_SETTED); - - *do_waitvblank = 1; - return TDM_ERROR_NONE; - } else if (layer_data->display_buffer_changed) { - layer_data->display_buffer_changed = 0; - - if (!layer_data->display_buffer) { - if (drmModeSetCrtc(drm_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->status == TDM_OUTPUT_CONN_STATUS_MODE_SETTED) - _tdm_drm_output_update_status(output_data, TDM_OUTPUT_CONN_STATUS_CONNECTED); - - *do_waitvblank = 1; - } else { - tdm_drm_event_data *event_data = calloc(1, sizeof(tdm_drm_event_data)); - - if (!event_data) { - TDM_ERR("alloc failed"); - return TDM_ERROR_OUT_OF_MEMORY; - } - - event_data->type = TDM_DRM_EVENT_TYPE_PAGEFLIP; - event_data->output_data = output_data; - event_data->user_data = user_data; - if (drmModePageFlip(drm_data->drm_fd, output_data->crtc_id, - layer_data->display_buffer->fb_id, DRM_MODE_PAGE_FLIP_EVENT, event_data)) { - TDM_ERR("pageflip failed: %m"); - free(event_data); - return TDM_ERROR_OPERATION_FAILED; - } - *do_waitvblank = 0; - } - } - - return TDM_ERROR_NONE; -} - -static tdm_error -_tdm_drm_display_commit_layer(tdm_drm_layer_data *layer_data) -{ - tdm_drm_data *drm_data = layer_data->drm_data; - tdm_drm_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->current_mode) - crtc_w = output_data->current_mode->hdisplay; - else { - drmModeCrtcPtr crtc = drmModeGetCrtc(drm_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(drm_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(drm_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_INFO("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_drm_display_cb_event(int fd, unsigned int sequence, - unsigned int tv_sec, unsigned int tv_usec, - void *user_data) -{ - tdm_drm_event_data *event_data = user_data; - tdm_drm_output_data *output_data; - tdm_drm_hwc_data *hwc_data; - - if (!event_data) { - TDM_ERR("no event data"); - return; - } - - output_data = event_data->output_data; - - switch (event_data->type) { - case TDM_DRM_EVENT_TYPE_PAGEFLIP: - 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; - 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 -_tdm_drm_display_create_layer_list(tdm_drm_data *drm_data) -{ - tdm_drm_output_data *output_data = NULL; - int i; - - if (LIST_IS_EMPTY(&drm_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, &drm_data->output_list, link) { - break; - } - - if (drm_data->plane_res->count_planes == 0) { - TDM_ERR("no layer error"); - return TDM_ERROR_OPERATION_FAILED; - } - - for (i = 0; i < drm_data->plane_res->count_planes; i++) { - tdm_drm_layer_data *layer_data; - drmModePlanePtr plane; - - plane = drmModeGetPlane(drm_data->drm_fd, drm_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_drm_layer_data)); - if (!layer_data) { - TDM_ERR("alloc failed"); - drmModeFreePlane(plane); - continue; - } - - layer_data->drm_data = drm_data; - layer_data->output_data = output_data; - layer_data->plane_id = drm_data->plane_res->planes[i]; - - 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_drm_display_get_property(tdm_drm_data *drm_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(drm_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(drm_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_drm_display_create_layer_list_type(tdm_drm_data *drm_data) -{ - tdm_drm_output_data *output_data = NULL; - drmModePlanePtr *planes = NULL; - unsigned int *types = NULL; - unsigned int type = 0; - int plane_cnt, primary_cnt, ovl_cnt, cursor_cnt; - int opos_next, cpos_next; - tdm_error ret; - int i; - - if (LIST_IS_EMPTY(&drm_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, &drm_data->output_list, link) { - break; - } - - ret = _tdm_drm_display_get_property(drm_data, - drm_data->plane_res->planes[0], - DRM_MODE_OBJECT_PLANE, "type", &type, - NULL); - if (ret != TDM_ERROR_NONE) { - TDM_ERR("plane doesn't have 'type' property. Call a fallback function"); - - /* if a plane doesn't have "type" property, we call a fallback function - * as default - */ - return _tdm_drm_display_create_layer_list(drm_data); - } - - planes = calloc(drm_data->plane_res->count_planes, sizeof(drmModePlanePtr)); - if (!planes) { - TDM_ERR("alloc failed"); - goto failed; - } - - types = calloc(drm_data->plane_res->count_planes, sizeof(unsigned int)); - if (!types) { - TDM_ERR("alloc failed"); - goto failed; - } - - plane_cnt = 0; - for (i = 0; i < drm_data->plane_res->count_planes; i++) { - drmModePlanePtr plane; - - plane = drmModeGetPlane(drm_data->drm_fd, drm_data->plane_res->planes[i]); - if (!plane) { - TDM_ERR("no plane(%d)", drm_data->plane_res->planes[i]); - goto failed; - } - - if ((plane->possible_crtcs & (1 << output_data->pipe)) == 0) { - drmModeFreePlane(plane); - continue; - } - - ret = _tdm_drm_display_get_property(drm_data, - drm_data->plane_res->planes[i], - DRM_MODE_OBJECT_PLANE, "type", &type, - NULL); - if (ret != TDM_ERROR_NONE) { - drmModeFreePlane(plane); - TDM_ERR("plane(%d) doesn't have 'type' info", - drm_data->plane_res->planes[i]); - goto failed; - } - - /* The TDM drm backend only support a primary layer. */ - if (type != DRM_PLANE_TYPE_PRIMARY) { - TDM_INFO("The TDM drm backend only support a primary layer. plane(%d) type(%d)", - plane->plane_id, type); - drmModeFreePlane(plane); - continue; - } - - planes[plane_cnt] = plane; - types[plane_cnt] = type; - plane_cnt++; - } - - primary_cnt = ovl_cnt = cursor_cnt = 0; - for (i = 0; i < plane_cnt; i++) { - if (types[i] == DRM_PLANE_TYPE_CURSOR) - cursor_cnt++; - else if (types[i] == DRM_PLANE_TYPE_OVERLAY) - ovl_cnt++; - else if (types[i] == DRM_PLANE_TYPE_PRIMARY) - primary_cnt++; - else - TDM_ERR("invalid type(%d)", types[i]); - } - - if (primary_cnt != 1) { - TDM_ERR("primary layer count(%d) should be one", primary_cnt); - goto failed; - } - - opos_next = 1; - cpos_next = ovl_cnt; - for (i = 0; i < plane_cnt; i++) { - tdm_drm_layer_data *layer_data; - - layer_data = calloc(1, sizeof(tdm_drm_layer_data)); - if (!layer_data) { - TDM_ERR("alloc failed"); - goto failed; - } - - layer_data->drm_data = drm_data; - layer_data->output_data = output_data; - layer_data->plane_id = planes[i]->plane_id; - - if (types[i] == DRM_PLANE_TYPE_CURSOR) { - layer_data->capabilities = TDM_LAYER_CAPABILITY_CURSOR | - TDM_LAYER_CAPABILITY_GRAPHIC; - layer_data->zpos = cpos_next++; - } else if (types[i] == DRM_PLANE_TYPE_OVERLAY) { - layer_data->capabilities = TDM_LAYER_CAPABILITY_OVERLAY | - TDM_LAYER_CAPABILITY_GRAPHIC; - layer_data->zpos = opos_next++; - } else if (types[i] == 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 { - 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); - } - - for (i = 0; i < plane_cnt; i++) - if (planes[i]) - drmModeFreePlane(planes[i]); - - free(planes); - free(types); - - return TDM_ERROR_NONE; - -failed: - if (planes) { - for (i = 0; i < drm_data->plane_res->count_planes; i++) - if (planes[i]) - drmModeFreePlane(planes[i]); - free(planes); - } - - free(types); - - return TDM_ERROR_OPERATION_FAILED; -} -#endif - -tdm_error -tdm_drm_display_create_layer_list(tdm_drm_data *drm_data) -{ - tdm_drm_output_data *output_data = NULL; - tdm_error ret; - -#if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4 && LIBDRM_MICRO_VERSION >= 47 - if (drm_data->has_universal_plane) - ret = _tdm_drm_display_create_layer_list_type(drm_data); - else -#endif - ret = _tdm_drm_display_create_layer_list(drm_data); - - if (ret != TDM_ERROR_NONE) - return ret; - - LIST_FOR_EACH_ENTRY(output_data, &drm_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_drm_display_destroy_output_list(tdm_drm_data *drm_data) -{ - tdm_drm_output_data *o = NULL, *oo = NULL; - tdm_drm_hwc_data *hwc_data = NULL; - - if (LIST_IS_EMPTY(&drm_data->output_list)) - return; - - LIST_FOR_EACH_ENTRY_SAFE(o, oo, &drm_data->output_list, link) { - hwc_data = o->hwc_data; - if (hwc_data && hwc_data->target_hwc_window) - drm_hwc_window_destroy(hwc_data->target_hwc_window); - - LIST_DEL(&o->link); - if (!LIST_IS_EMPTY(&o->layer_list)) { - tdm_drm_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->drm_modes); - free(o->output_modes); - free(o); - } -} - -void -tdm_drm_display_update_output_status(tdm_drm_data *drm_data) -{ - tdm_drm_output_data *output_data = NULL; - - if (LIST_IS_EMPTY(&drm_data->output_list)) - return; - - LIST_FOR_EACH_ENTRY(output_data, &drm_data->output_list, link) { - drmModeConnectorPtr connector; - tdm_output_conn_status new_status; - - connector = drmModeGetConnector(drm_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_drm_output_update_status(output_data, new_status); - - drmModeFreeConnector(connector); - } -} - -tdm_error -tdm_drm_display_create_output_list(tdm_drm_data *drm_data) -{ - tdm_drm_output_data *output_data; - int i; - tdm_error ret; - int allocated = 0; - drmModeConnectorPtr connector; - drmModeEncoderPtr encoder; - int conn_idx = -1; - int crtc_id = 0, c, j; - - RETURN_VAL_IF_FAIL(LIST_IS_EMPTY(&drm_data->output_list), - TDM_ERROR_OPERATION_FAILED); - - /* check if there is a connected output */ - for (i = 0; i < drm_data->mode_res->count_connectors; i++) { - connector = drmModeGetConnector(drm_data->drm_fd, - drm_data->mode_res->connectors[i]); - if (!connector) { - TDM_ERR("no connector"); - return TDM_ERROR_OPERATION_FAILED; - } - - /* The TDM drm backend considers only 1 connector because it is the TDM - * reference backend and can't take care of all hardware devices. - * To support various connectors, planes and crtcs, the new TDM backend - * should be implemented. - */ - if (connector->connection == DRM_MODE_CONNECTED) { - conn_idx = i; - drmModeFreeConnector(connector); - break; - } - drmModeFreeConnector(connector); - } - - /* use the first connecoct_id if there is not connector which is connected */ - if (conn_idx == -1) - conn_idx = 0; - - /* The TDM drm backend considers only 1 connector because it is the TDM - * reference backend and can't take care of all hardware devices. - * To support various connectors, planes and crtcs, the new TDM backend - * should be implemented. - */ - connector = drmModeGetConnector(drm_data->drm_fd, - drm_data->mode_res->connectors[conn_idx]); - 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(drm_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 < drm_data->mode_res->count_crtcs; c++) { - if (allocated & (1 << c)) - continue; - - if ((encoder->possible_crtcs & (1 << c)) == 0) - continue; - - crtc_id = drm_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_drm_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->drm_data = drm_data; - output_data->connector_id = drm_data->mode_res->connectors[conn_idx]; - 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; - - 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(drm_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); - } - - if (output_data->dpms_prop_id == 0) - TDM_WRN("not support DPMS"); - - output_data->count_modes = connector->count_modes; - output_data->drm_modes = calloc(connector->count_modes, - sizeof(drmModeModeInfo)); - if (!output_data->drm_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->drm_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->drm_modes[j] = connector->modes[j]; - _tdm_drm_display_to_tdm_mode(&output_data->drm_modes[j], - &output_data->output_modes[j]); - } - - if (drm_data->hwc_mode) - output_data->hwc_enable = 1; - - LIST_ADDTAIL(&output_data->link, &drm_data->output_list); - - TDM_DBG("output_data(%p) connector_id(%d:%d:%d-%d) encoder_id(%d) crtc_id(%d) pipe(%d) dpms_id(%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); - - drmModeFreeEncoder(encoder); - drmModeFreeConnector(connector); - - TDM_DBG("output count: %d", drm_data->mode_res->count_connectors); - - return TDM_ERROR_NONE; -failed_create: - tdm_drm_display_destroy_output_list(drm_data); - return ret; -} - -tdm_error -drm_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_error -drm_display_get_pp_capability(tdm_backend_data *bdata, tdm_caps_pp *caps) -{ - return tdm_drm_pp_get_capability(bdata, caps); -} - -tdm_output ** -drm_display_get_outputs(tdm_backend_data *bdata, int *count, tdm_error *error) -{ - tdm_drm_data *drm_data = bdata; - tdm_drm_output_data *output_data = NULL; - tdm_output **outputs; - tdm_error ret; - int i; - - RETURN_VAL_IF_FAIL(drm_data, NULL); - RETURN_VAL_IF_FAIL(count, NULL); - - *count = 0; - LIST_FOR_EACH_ENTRY(output_data, &drm_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_drm_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, &drm_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 -drm_display_get_fd(tdm_backend_data *bdata, int *fd) -{ - tdm_drm_data *drm_data = bdata; - - RETURN_VAL_IF_FAIL(drm_data, TDM_ERROR_INVALID_PARAMETER); - RETURN_VAL_IF_FAIL(fd, TDM_ERROR_INVALID_PARAMETER); - - *fd = drm_data->drm_fd; - - return TDM_ERROR_NONE; -} - -tdm_error -drm_display_handle_events(tdm_backend_data *bdata) -{ - tdm_drm_data *drm_data = bdata; - drmEventContext ctx; - - RETURN_VAL_IF_FAIL(drm_data, TDM_ERROR_INVALID_PARAMETER); - - memset(&ctx, 0, sizeof(drmEventContext)); - - ctx.version = DRM_EVENT_CONTEXT_VERSION; - ctx.page_flip_handler = _tdm_drm_display_cb_event; - ctx.vblank_handler = _tdm_drm_display_cb_event; - - drmHandleEvent(drm_data->drm_fd, &ctx); - - return TDM_ERROR_NONE; -} - -tdm_pp * -drm_display_create_pp(tdm_backend_data *bdata, tdm_error *error) -{ - tdm_drm_data *drm_data = bdata; - - RETURN_VAL_IF_FAIL(drm_data, NULL); - - return tdm_drm_pp_create(drm_data, error); -} - -tdm_error -drm_output_get_capability(tdm_output *output, tdm_caps_output *caps) -{ - tdm_drm_output_data *output_data = output; - tdm_drm_data *drm_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)); - - drm_data = output_data->drm_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(drm_data->drm_fd, output_data->connector_id); - RETURN_VAL_IF_FAIL(connector, TDM_ERROR_OPERATION_FAILED); - - caps->mode_count = connector->count_modes; - 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; - } - for (i = 0; i < caps->mode_count; i++) - caps->modes[i] = output_data->output_modes[i]; - - caps->mmWidth = connector->mmWidth; - caps->mmHeight = connector->mmHeight; - caps->subpixel = connector->subpixel; - - caps->min_w = drm_data->mode_res->min_width; - caps->min_h = drm_data->mode_res->min_height; - caps->max_w = drm_data->mode_res->max_width; - caps->max_h = drm_data->mode_res->max_height; - caps->preferred_align = -1; - - crtc = drmModeGetCrtc(drm_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(drm_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(drm_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; - - 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 ** -drm_output_get_layers(tdm_output *output, int *count, tdm_error *error) -{ - tdm_drm_output_data *output_data = output; - tdm_drm_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_drm_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 -drm_output_set_property(tdm_output *output, unsigned int id, tdm_value value) -{ - tdm_drm_output_data *output_data = output; - tdm_drm_data *drm_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); - - drm_data = output_data->drm_data; - ret = drmModeObjectSetProperty(drm_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 -drm_output_get_property(tdm_output *output, unsigned int id, tdm_value *value) -{ - tdm_drm_output_data *output_data = output; - tdm_drm_data *drm_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); - - drm_data = output_data->drm_data; - props = drmModeObjectGetProperties(drm_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 -drm_output_wait_vblank(tdm_output *output, int interval, int sync, - void *user_data) -{ - tdm_drm_output_data *output_data = output; - tdm_drm_data *drm_data; - tdm_drm_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_drm_event_data)); - if (!event_data) { - TDM_ERR("alloc failed"); - return TDM_ERROR_OUT_OF_MEMORY; - } - - drm_data = output_data->drm_data; - - ret = _tdm_drm_display_get_cur_msc(drm_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_drm_display_wait_vblank(drm_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 -drm_output_set_vblank_handler(tdm_output *output, - tdm_output_vblank_handler func) -{ - tdm_drm_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; -} - -tdm_error -drm_output_commit(tdm_output *output, int sync, void *user_data) -{ - tdm_drm_output_data *output_data = output; - tdm_drm_data *drm_data; - tdm_drm_layer_data *layer_data = NULL; - tdm_error ret; - int do_waitvblank = 1; - - RETURN_VAL_IF_FAIL(output_data, TDM_ERROR_INVALID_PARAMETER); - - drm_data = output_data->drm_data; - - LIST_FOR_EACH_ENTRY(layer_data, &output_data->layer_list, link) { - if (layer_data == output_data->primary_layer) { - ret = _tdm_drm_display_commit_primary_layer(layer_data, user_data, - &do_waitvblank); - if (ret != TDM_ERROR_NONE) - return ret; - } else { - ret = _tdm_drm_display_commit_layer(layer_data); - if (ret != TDM_ERROR_NONE) - return ret; - } - } - - if (do_waitvblank == 1) { - tdm_drm_event_data *event_data = calloc(1, sizeof(tdm_drm_event_data)); - uint target_msc; - - if (!event_data) { - TDM_ERR("alloc failed"); - return TDM_ERROR_OUT_OF_MEMORY; - } - - ret = _tdm_drm_display_get_cur_msc(drm_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_drm_display_wait_vblank(drm_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 -drm_output_set_commit_handler(tdm_output *output, - tdm_output_commit_handler func) -{ - tdm_drm_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 -drm_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value) -{ - tdm_drm_output_data *output_data = output; - tdm_drm_data *drm_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; - } - - drm_data = output_data->drm_data; - ret = drmModeObjectSetProperty(drm_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; - } - - output_data->current_dpms = dpms_value; - - return TDM_ERROR_NONE; -} - -tdm_error -drm_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value) -{ - tdm_drm_output_data *output_data = output; - tdm_drm_data *drm_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); - - drm_data = output_data->drm_data; - props = drmModeObjectGetProperties(drm_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 -drm_output_set_mode(tdm_output *output, const tdm_output_mode *mode) -{ - tdm_drm_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 = drm_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; - - return TDM_ERROR_NONE; -} - -tdm_error -drm_output_get_mode(tdm_output *output, const tdm_output_mode **mode) -{ - tdm_drm_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_hwc * -drm_output_get_hwc(tdm_output *output, tdm_error *error) -{ - tdm_drm_hwc_data *hwc_data = NULL; - tdm_drm_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_drm_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 = drm_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 -drm_output_set_status_handler(tdm_output *output, - tdm_output_status_handler func, - void *user_data) -{ - tdm_drm_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 -drm_layer_get_capability(tdm_layer *layer, tdm_caps_layer *caps) -{ - tdm_drm_layer_data *layer_data = layer; - tdm_drm_data *drm_data; - drmModePlanePtr plane = NULL; - drmModeObjectPropertiesPtr props = NULL; - int i, format_count = 0; - 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)); - - drm_data = layer_data->drm_data; - plane = drmModeGetPlane(drm_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; /* if VIDEO layer, zpos is -1 */ - - 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++) { - /* TODO: kernel reports wrong formats */ - if (plane->formats[i] != DRM_FORMAT_XRGB8888 && - plane->formats[i] != DRM_FORMAT_ARGB8888) { - TDM_WRN("plane(%d) zpos(%d) %c%c%c%c skipped", - layer_data->plane_id, layer_data->zpos, FOURCC_STR(plane->formats[i])); - continue; - } - caps->formats[format_count] = tdm_drm_format_to_tbm_format(plane->formats[i]); - format_count++; - } - - caps->format_count = format_count; - - props = drmModeObjectGetProperties(drm_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(drm_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 -drm_layer_set_property(tdm_layer *layer, unsigned int id, tdm_value value) -{ - tdm_drm_layer_data *layer_data = layer; - tdm_drm_data *drm_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); - - drm_data = layer_data->drm_data; - ret = drmModeObjectSetProperty(drm_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 -drm_layer_get_property(tdm_layer *layer, unsigned int id, tdm_value *value) -{ - tdm_drm_layer_data *layer_data = layer; - tdm_drm_data *drm_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); - - drm_data = layer_data->drm_data; - props = drmModeObjectGetProperties(drm_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 -drm_layer_set_info(tdm_layer *layer, tdm_info_layer *info) -{ - tdm_drm_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 -drm_layer_get_info(tdm_layer *layer, tdm_info_layer *info) -{ - tdm_drm_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_drm_display_buffer * -_tdm_drm_display_find_buffer(tdm_drm_data *drm_data, tbm_surface_h buffer) -{ - tdm_drm_display_buffer *display_buffer = NULL; - - LIST_FOR_EACH_ENTRY(display_buffer, &drm_data->buffer_list, link) { - if (display_buffer->buffer == buffer) - return display_buffer; - } - - return NULL; -} - -static void -_tdm_drm_display_cb_destroy_buffer(tbm_surface_h buffer, void *user_data) -{ - tdm_drm_data *drm_data; - tdm_drm_display_buffer *display_buffer; - tdm_drm_layer_data *layer_data = NULL; - tdm_drm_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; - } - - drm_data = (tdm_drm_data *) user_data; - - display_buffer = _tdm_drm_display_find_buffer(drm_data, buffer); - if (!display_buffer) { - TDM_ERR("no display_buffer"); - return; - } - - LIST_FOR_EACH_ENTRY(output_data, &drm_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(drm_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_drm_display_buffer * -_tdm_drm_display_create_buffer(tdm_drm_data *drm_data, tbm_surface_h buffer, tdm_error *err) -{ - tdm_drm_display_buffer *display_buffer = NULL; - tdm_error res = TDM_ERROR_NONE; - int count, i, ret; - - display_buffer = calloc(1, sizeof(tdm_drm_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_drm_display_cb_destroy_buffer, drm_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(drm_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("drm_data->drm_fd : %d, display_buffer->fb_id:%u", drm_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, &drm_data->buffer_list); - - if (err) - *err = TDM_ERROR_NONE; - - return display_buffer; -} - -void -tdm_drm_data_destroy_buffer_list(tdm_drm_data *drm_data) -{ - tdm_drm_display_buffer *b = NULL, *bb = NULL; - - LIST_FOR_EACH_ENTRY_SAFE(b, bb, &drm_data->buffer_list, link) { - tdm_buffer_remove_destroy_handler(b->buffer, _tdm_drm_display_cb_destroy_buffer, drm_data); - _tdm_drm_display_cb_destroy_buffer(b->buffer, drm_data); - } -} - -tdm_error -drm_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer) -{ - tdm_drm_layer_data *layer_data = layer; - tdm_drm_data *drm_data; - tdm_drm_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); - - drm_data = layer_data->drm_data; - display_buffer = _tdm_drm_display_find_buffer(drm_data, buffer); - if (!display_buffer) { - display_buffer = _tdm_drm_display_create_buffer(drm_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 -drm_layer_unset_buffer(tdm_layer *layer) -{ - tdm_drm_layer_data *layer_data = layer; - - RETURN_VAL_IF_FAIL(layer_data, TDM_ERROR_INVALID_PARAMETER); - - if (!(layer_data->capabilities & TDM_LAYER_CAPABILITY_PRIMARY) && 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_drm_layer_data * -drm_output_data_get_layer_data(tdm_drm_output_data *output_data, int layer_zpos) -{ - tdm_drm_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; -} diff --git a/src/libtdm-drm/tdm_drm_format.c b/src/libtdm-drm/tdm_drm_format.c deleted file mode 100644 index 2f009d8..0000000 --- a/src/libtdm-drm/tdm_drm_format.c +++ /dev/null @@ -1,134 +0,0 @@ -/************************************************************************** - -libtdm_drm - -Copyright 2015 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_drm.h" - -typedef struct { - tbm_format tbm_format; - uint32_t drm_format; -} tbm_drm_format_data; - -static const tbm_drm_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_drm_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_drm_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-drm/tdm_drm_hwc.c b/src/libtdm-drm/tdm_drm_hwc.c deleted file mode 100644 index 07f7d9d..0000000 --- a/src/libtdm-drm/tdm_drm_hwc.c +++ /dev/null @@ -1,801 +0,0 @@ -/************************************************************************** - -libtdm_drm - -Copyright 2015 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 "tdm_drm.h" - -#define MIN_WIDTH 32 - -#define NUM_LAYERS 4 -#define NUM_BUFFERS 3 - -#define NUM_UI_LAYERS 1 - -#define ZPOS_MAX 1 -#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 int -_drm_hwc_cursor_buffer_unset(tdm_drm_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 -_drm_hwc_cursor_adjust_pos(tdm_drm_hwc_window_data *hwc_window_data) -{ - int x, y; - - /* 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 -_drm_hwc_cursor_buffer_set(tdm_drm_hwc_data *hwc_data, tdm_drm_hwc_window_data *hwc_window_data) -{ - tbm_surface_h cursor_tsurface = NULL; - tbm_surface_info_s tsurface_info; - tbm_surface_error_e ret = TBM_SURFACE_ERROR_NONE; - int img_w, img_h, new_w, new_h; - tbm_format new_format; - unsigned int flags = TBM_BO_SCANOUT; - void *src_ptr = NULL, *dst_ptr = NULL; - int src_stride; - int i; - - _drm_hwc_cursor_adjust_pos(hwc_window_data); - - if (!hwc_window_data->cursor_img_refresh && hwc_window_data->surface) - return 1; - - img_w = hwc_window_data->cursor_img.width; - img_h = hwc_window_data->cursor_img.height; - new_format = hwc_window_data->info.src_config.format; - - /* cursor restriction to set the cursor layer */ - new_w = (CURSOR_MIN_W > img_w) ? CURSOR_MIN_W : img_w; - new_h = (CURSOR_MIN_H > img_h) ? CURSOR_MIN_H : img_h; - - if (hwc_data->cursor_tsurface) { - tbm_surface_internal_unref(hwc_data->cursor_tsurface); - hwc_data->cursor_tsurface = NULL; - } - - cursor_tsurface = tbm_surface_internal_create_with_flags(new_w, new_h, new_format, flags); - RETURN_VAL_IF_FAIL(cursor_tsurface, 0); - - hwc_data->cursor_tsurface = cursor_tsurface; - 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"); - tbm_surface_internal_unref(hwc_data->cursor_tsurface); - hwc_data->cursor_tsurface = NULL; - return 0; - } - - src_ptr = hwc_window_data->cursor_img.ptr; - dst_ptr = tsurface_info.planes[0].ptr; - src_stride = hwc_window_data->cursor_img.stride; - - memset(dst_ptr, 0, tsurface_info.planes[0].stride * tsurface_info.height); - - 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); - - hwc_window_data->surface = hwc_data->cursor_tsurface; - hwc_window_data->cursor_img_surface = 1; - - /* fix the dst_pos info of the cursor window */ - hwc_window_data->info.src_config.pos.w = new_w; - hwc_window_data->info.src_config.pos.h = new_h; - hwc_window_data->info.dst_pos.w = new_w; - hwc_window_data->info.dst_pos.h = new_h; - - hwc_window_data->cursor_img_refresh = 0; - - return 1; -} - -static void -_print_validate_result(tdm_drm_hwc_data *hwc_data, tdm_hwc_window **composited_wnds, uint32_t num_wnds) -{ - tdm_drm_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_INFO(" 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_INFO(" 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 -_drm_hwc_window_can_set_on_hw_layer(tdm_drm_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; - - if (hwc_window_data->info.src_config.pos.w < MIN_WIDTH || hwc_window_data->info.src_config.pos.w % 2) - return 0; - - return 1; -} - -static tbm_surface_queue_h -_drm_hwc_window_get_tbm_buffer_queue(tdm_hwc_window *hwc_window, tdm_error *error) -{ - tdm_drm_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 tdm_error -_drm_hwc_layer_attach_window(tdm_drm_layer_data *layer_data, tdm_drm_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 = drm_layer_unset_buffer(layer_data); - RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret); - } else { - ret = drm_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 = drm_layer_set_buffer(layer_data, hwc_window_data->surface); - RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret); - } - - return ret; -} - -static tdm_error -_drm_hwc_prepare_commit(tdm_drm_hwc_data *hwc_data) -{ - tdm_drm_hwc_window_data *hwc_window_data = NULL; - tdm_drm_layer_data *layer_data = NULL; - int use_layers_zpos[NUM_LAYERS] = {0,}; - int lzpos = 0; - - /* set target hwc window to the layer */ - if (hwc_data->need_target_window) { - layer_data = drm_output_data_get_layer_data(hwc_data->output_data, hwc_data->target_hwc_window->lzpos); - _drm_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) - _drm_hwc_cursor_buffer_unset(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) - _drm_hwc_cursor_buffer_set(hwc_data, hwc_window_data); - - layer_data = drm_output_data_get_layer_data(hwc_data->output_data, hwc_window_data->lzpos); - _drm_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 = drm_output_data_get_layer_data(hwc_data->output_data, lzpos); - if (!layer_data) - continue; - - _drm_hwc_layer_attach_window(layer_data, NULL); - } - - /* for debug */ - for (lzpos = NUM_LAYERS -1 ; lzpos >= 0; lzpos--) { - if (use_layers_zpos[lzpos]) - TDM_INFO(" 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 -_drm_hwc_apply_policy(tdm_drm_hwc_data *hwc_data , tdm_hwc_window **composited_wnds, uint32_t num_wnds) -{ - tdm_drm_hwc_window_data *hwc_window_data = NULL; - tdm_drm_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_0; - int ui_lzpos_bottom = ZPOS_0; - int num_ui_layers = NUM_UI_LAYERS; - int set_clients_below = 0; - int i = 0; - - composited_list = (tdm_drm_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++; - 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 (!_drm_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) { - 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 -_drm_hwc_get_changed_number(tdm_drm_hwc_data *hwc_data) -{ - int num = 0; - tdm_drm_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 * -_drm_hwc_create_window(tdm_hwc *hwc, tdm_hwc_window_info *info, tdm_error *error) -{ - tdm_drm_hwc_data *hwc_data = hwc; - tdm_drm_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_drm_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; - - 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 * -drm_hwc_create_window(tdm_hwc *hwc, tdm_error *error) -{ - tdm_drm_hwc_data *hwc_data = hwc; - tdm_drm_hwc_window_data *hwc_window_data = NULL; - - RETURN_VAL_IF_FAIL(hwc_data, NULL); - - hwc_window_data = _drm_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_INFO("hwc_window(%p) create", hwc_window_data); - if (error) - *error = TDM_ERROR_NONE; - - return hwc_window_data; -} - -tdm_error -drm_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 -drm_hwc_get_capabilities(tdm_hwc *hwc, tdm_hwc_capability *capabilities) -{ - RETURN_VAL_IF_FAIL(hwc != NULL, TDM_ERROR_INVALID_PARAMETER); - RETURN_VAL_IF_FAIL(capabilities != NULL, TDM_ERROR_INVALID_PARAMETER); - - *capabilities |= TDM_HWC_CAPABILITY_VIDEO_SCALE; - - return TDM_ERROR_NONE; -} - -tdm_error -drm_hwc_get_available_properties(tdm_hwc *hwc, const tdm_prop **props, int *count) -{ - tdm_drm_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 -drm_hwc_get_client_target_buffer_queue(tdm_hwc *hwc, tdm_error *error) -{ - tdm_drm_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 = _drm_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 -drm_hwc_set_client_target_buffer(tdm_hwc *hwc, tbm_surface_h buffer, tdm_region damage) -{ - tdm_drm_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 = drm_hwc_window_set_buffer(hwc_data->target_hwc_window, buffer); - RETURN_VAL_IF_FAIL(err == TDM_ERROR_NONE, err); - - err = drm_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 -drm_hwc_validate(tdm_hwc *hwc, tdm_hwc_window **composited_wnds, uint32_t num_wnds, uint32_t *num_types) -{ - tdm_drm_hwc_data *hwc_data = hwc; - tdm_drm_output_data *output_data; - - 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_INFO(" ==============Validate================================="); - - _drm_hwc_apply_policy(hwc_data, composited_wnds, num_wnds); - - *num_types = _drm_hwc_get_changed_number(hwc_data); - - _print_validate_result(hwc_data, composited_wnds, num_wnds); - - return TDM_ERROR_NONE; -} - -tdm_error -drm_hwc_get_changed_composition_types(tdm_hwc *hwc, uint32_t *num_elements, - tdm_hwc_window **hwc_wnds, tdm_hwc_window_composition *composition_types) -{ - tdm_drm_hwc_data *hwc_data = hwc; - tdm_drm_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 = _drm_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 -drm_hwc_accept_validation(tdm_hwc *hwc) -{ - tdm_drm_hwc_data *hwc_data = hwc; - 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); - - TDM_INFO(" ==============Accept Changes Done================================="); - - if (hwc_data->output_data->current_dpms != TDM_OUTPUT_DPMS_ON) { - TDM_ERR("dpms is not on. do not set buffer"); - return TDM_ERROR_BAD_REQUEST; - } - - ret = _drm_hwc_prepare_commit(hwc_data); - RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret); - - return TDM_ERROR_NONE; -} - -tdm_error -drm_hwc_commit(tdm_hwc *hwc, int sync, void *user_data) -{ - tdm_drm_hwc_data *hwc_data = hwc; - tdm_drm_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_INFO(" ==============COMMIT================================="); - - if (hwc_data->output_data->current_dpms != TDM_OUTPUT_DPMS_ON) { - TDM_ERR("dpms is not on. do not commit"); - return TDM_ERROR_BAD_REQUEST; - } - - ret = drm_output_commit(output_data, sync, user_data); - RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret); - - return TDM_ERROR_NONE; -} - -tdm_error -drm_hwc_set_commit_handler(tdm_hwc *hwc, tdm_hwc_commit_handler func) -{ - tdm_drm_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 -drm_hwc_target_window_set_info(tdm_drm_hwc_data *hwc_data, int width, int height) -{ - tdm_hwc_window_info info = {0}; - tdm_drm_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 = drm_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 -drm_hwc_initailize_target_window(tdm_drm_hwc_data *hwc_data) -{ - tdm_hwc_window_info info = {0}; - tdm_error ret = TDM_ERROR_NONE; - tdm_drm_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 = _drm_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) - drm_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-drm/tdm_drm_hwc.h b/src/libtdm-drm/tdm_drm_hwc.h deleted file mode 100644 index f8808f1..0000000 --- a/src/libtdm-drm/tdm_drm_hwc.h +++ /dev/null @@ -1,39 +0,0 @@ -/************************************************************************** - -libtdm_drm - -Copyright 2015 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_DRM_HWC_H_ -#define _TDM_DRM_HWC_H_ - -#include "tdm_drm.h" - -tdm_error drm_hwc_initailize_target_window(tdm_drm_hwc_data *hwc_data); -tdm_error drm_hwc_target_window_set_info(tdm_drm_hwc_data *hwc_data, int width, int height); - -#endif /* _TDM_DRM_HWC_H_ */ diff --git a/src/libtdm-drm/tdm_drm_hwc_window.c b/src/libtdm-drm/tdm_drm_hwc_window.c deleted file mode 100644 index 017fa59..0000000 --- a/src/libtdm-drm/tdm_drm_hwc_window.c +++ /dev/null @@ -1,184 +0,0 @@ -/************************************************************************** - -libtdm_drm - -Copyright 2015 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_drm.h" - -void -drm_hwc_window_destroy(tdm_hwc_window *hwc_window) -{ - tdm_drm_hwc_window_data *hwc_window_data = hwc_window; - - RETURN_IF_FAIL(hwc_window_data != NULL); - - LIST_DEL(&hwc_window_data->link); - - free(hwc_window_data); -} - -tdm_error -drm_hwc_window_set_composition_type(tdm_hwc_window *hwc_window, - tdm_hwc_window_composition comp_type) -{ - tdm_drm_hwc_window_data *hwc_window_data = hwc_window; - tdm_drm_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 -drm_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_region damage) -{ - tdm_drm_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 -drm_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info) -{ - tdm_drm_hwc_window_data *hwc_window_data = hwc_window; - tdm_drm_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 -drm_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h surface) -{ - tdm_drm_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 -drm_hwc_window_set_property(tdm_hwc_window *hwc_window, unsigned int id, tdm_value value) -{ - tdm_drm_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 -drm_hwc_window_get_property(tdm_hwc_window *hwc_window, unsigned int id, tdm_value *value) -{ - tdm_drm_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 -drm_hwc_window_get_constraints(tdm_hwc_window *hwc_window, int *constraints) -{ - tdm_drm_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 -drm_hwc_window_set_name(tdm_hwc_window *hwc_window, const char *name) -{ - tdm_drm_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 -drm_hwc_window_set_cursor_image(tdm_hwc_window *hwc_window, int width, int height, int stride, void *ptr) -{ - tdm_drm_hwc_window_data *hwc_window_data = hwc_window; - - RETURN_VAL_IF_FAIL(hwc_window_data != NULL, TDM_ERROR_INVALID_PARAMETER); - RETURN_VAL_IF_FAIL(hwc_window_data->client_type == TDM_HWC_WIN_COMPOSITION_CURSOR, 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; -} diff --git a/src/libtdm-drm/tdm_drm_hwc_window.h b/src/libtdm-drm/tdm_drm_hwc_window.h deleted file mode 100644 index a5df8f2..0000000 --- a/src/libtdm-drm/tdm_drm_hwc_window.h +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************************************** - -libtdm_drm - -Copyright 2015 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_DRM_HWC_WINDOW_H_ -#define _TDM_DRM_HWC_WINDOW_H_ - -#include "tdm_drm.h" - -#endif /* _TDM_DRM_HWC_WINDOW_H_ */
\ No newline at end of file diff --git a/src/libtdm-drm/tdm_drm_pp.c b/src/libtdm-drm/tdm_drm_pp.c deleted file mode 100644 index c4e5589..0000000 --- a/src/libtdm-drm/tdm_drm_pp.c +++ /dev/null @@ -1,440 +0,0 @@ -/************************************************************************** - -libtdm_drm - -Copyright 2015 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 <pixman.h> - -#include "tdm_drm.h" -#include "tdm_helper.h" - -typedef struct _tdm_drm_pp_buffer { - tbm_surface_h src; - tbm_surface_h dst; - - struct list_head link; -} tdm_drm_pp_buffer; - -typedef struct _tdm_drm_pp_data { - tdm_drm_data *drm_data; - - tdm_info_pp info; - - struct list_head pending_buffer_list; - - tdm_pp_done_handler done_func; - void *done_user_data; - - struct list_head link; -} tdm_drm_pp_data; - - -static tbm_format pp_formats[] = { - TBM_FORMAT_ARGB8888, - TBM_FORMAT_XRGB8888, - TBM_FORMAT_YUV420, -}; - -#define NUM_PP_FORMAT (sizeof(pp_formats) / sizeof(pp_formats[0])) - -static int pp_list_init; -static struct list_head pp_list; - -static pixman_format_code_t -_tdm_drm_pp_pixman_get_format(tbm_format tbmfmt) -{ - switch (tbmfmt) { - case TBM_FORMAT_ARGB8888: - return PIXMAN_a8r8g8b8; - case TBM_FORMAT_XRGB8888: - return PIXMAN_x8r8g8b8; - case TBM_FORMAT_YUV420: - case TBM_FORMAT_YVU420: - return PIXMAN_yv12; - default: - return 0; - } -} - -int -_tdm_drm_pp_pixman_convert(pixman_op_t op, - unsigned char *srcbuf, unsigned char *dstbuf, - pixman_format_code_t src_format, pixman_format_code_t dst_format, - int sbw, int sbh, int sx, int sy, int sw, int sh, - int dbw, int dbh, int dx, int dy, int dw, int dh, - int rotate, int hflip, int vflip) -{ - pixman_image_t *src_img; - pixman_image_t *dst_img; - struct pixman_f_transform ft; - pixman_transform_t transform; - int src_stride, dst_stride; - int src_bpp; - int dst_bpp; - double scale_x, scale_y; - int rotate_step; - int ret = 0; - - RETURN_VAL_IF_FAIL(srcbuf != NULL, 0); - RETURN_VAL_IF_FAIL(dstbuf != NULL, 0); - - TDM_DBG("src(%dx%d: %d,%d %dx%d) dst(%dx%d: %d,%d %dx%d) flip(%d,%d), rot(%d)", - sbw, sbh, sx, sy, sw, sh, dbw, dbh, dx, dy, dw, dh, hflip, vflip, rotate); - - src_bpp = PIXMAN_FORMAT_BPP(src_format) / 8; - RETURN_VAL_IF_FAIL(src_bpp > 0, 0); - - dst_bpp = PIXMAN_FORMAT_BPP(dst_format) / 8; - RETURN_VAL_IF_FAIL(dst_bpp > 0, 0); - - rotate_step = (rotate + 360) / 90 % 4; - - src_stride = sbw * src_bpp; - dst_stride = dbw * dst_bpp; - - src_img = pixman_image_create_bits(src_format, sbw, sbh, (uint32_t *)srcbuf, - src_stride); - dst_img = pixman_image_create_bits(dst_format, dbw, dbh, (uint32_t *)dstbuf, - dst_stride); - - GOTO_IF_FAIL(src_img != NULL, CANT_CONVERT); - GOTO_IF_FAIL(dst_img != NULL, CANT_CONVERT); - - pixman_f_transform_init_identity(&ft); - - if (hflip) { - pixman_f_transform_scale(&ft, NULL, -1, 1); - pixman_f_transform_translate(&ft, NULL, dw, 0); - } - - if (vflip) { - pixman_f_transform_scale(&ft, NULL, 1, -1); - pixman_f_transform_translate(&ft, NULL, 0, dh); - } - - if (rotate_step > 0) { - int c = 0, s = 0, tx = 0, ty = 0; - switch (rotate_step) { - case 1: /* 90 degrees */ - s = -1, tx = -dw; - break; - case 2: /* 180 degrees */ - c = -1, tx = -dw, ty = -dh; - break; - case 3: /* 270 degrees */ - s = 1, ty = -dh; - break; - } - - pixman_f_transform_translate(&ft, NULL, tx, ty); - pixman_f_transform_rotate(&ft, NULL, c, s); - } - - if (rotate_step % 2 == 0) { - scale_x = (double)sw / dw; - scale_y = (double)sh / dh; - } else { - scale_x = (double)sw / dh; - scale_y = (double)sh / dw; - } - - pixman_f_transform_scale(&ft, NULL, scale_x, scale_y); - pixman_f_transform_translate(&ft, NULL, sx, sy); - - pixman_transform_from_pixman_f_transform(&transform, &ft); - pixman_image_set_transform(src_img, &transform); - - pixman_image_composite(op, src_img, NULL, dst_img, 0, 0, 0, 0, dx, dy, dw, dh); - - ret = 1; - -CANT_CONVERT: - if (src_img) - pixman_image_unref(src_img); - if (dst_img) - pixman_image_unref(dst_img); - - return ret; -} - -static tdm_error -_tdm_drm_pp_convert(tdm_drm_pp_buffer *buffer, tdm_info_pp *info) -{ - tbm_surface_info_s src_info, dst_info; - pixman_format_code_t src_format, dst_format; - int sbw, dbw; - int rotate = 0, hflip = 0; - tbm_bo bo = NULL; - int bo_cnt = 0; - int bo_size = 0; - - RETURN_VAL_IF_FAIL(buffer != NULL, TDM_ERROR_INVALID_PARAMETER); - RETURN_VAL_IF_FAIL(buffer->src != NULL, TDM_ERROR_INVALID_PARAMETER); - RETURN_VAL_IF_FAIL(buffer->dst != NULL, TDM_ERROR_INVALID_PARAMETER); - RETURN_VAL_IF_FAIL(info != NULL, TDM_ERROR_INVALID_PARAMETER); - - bo_cnt = tbm_surface_internal_get_num_bos(buffer->src); - RETURN_VAL_IF_FAIL(bo_cnt == 1, TDM_ERROR_INVALID_PARAMETER); - - bo_cnt = tbm_surface_internal_get_num_bos(buffer->dst); - RETURN_VAL_IF_FAIL(bo_cnt == 1, TDM_ERROR_INVALID_PARAMETER); - - bo = tbm_surface_internal_get_bo(buffer->src, 0); - RETURN_VAL_IF_FAIL(bo != NULL, TDM_ERROR_INVALID_PARAMETER); - - bo_size = tbm_bo_size(bo); - - /* not handle buffers which have 2 more gem handles */ - - memset(&src_info, 0, sizeof(tbm_surface_info_s)); - tbm_surface_map(buffer->src, TBM_OPTION_READ, &src_info); - GOTO_IF_FAIL(src_info.planes[0].ptr != NULL, fail_convert); - - memset(&dst_info, 0, sizeof(tbm_surface_info_s)); - tbm_surface_map(buffer->dst, TBM_OPTION_WRITE, &dst_info); - GOTO_IF_FAIL(dst_info.planes[0].ptr != NULL, fail_convert); - - src_format = _tdm_drm_pp_pixman_get_format(src_info.format); - GOTO_IF_FAIL(src_format > 0, fail_convert); - dst_format = _tdm_drm_pp_pixman_get_format(dst_info.format); - GOTO_IF_FAIL(dst_format > 0, fail_convert); - - GOTO_IF_FAIL(pixman_format_supported_destination(dst_format), fail_convert); - - if (src_info.format == TBM_FORMAT_YUV420) { - if (dst_info.format == TBM_FORMAT_XRGB8888) - dst_format = PIXMAN_x8b8g8r8; - else if (dst_info.format == TBM_FORMAT_ARGB8888) - dst_format = PIXMAN_a8b8g8r8; - else if (dst_info.format == TBM_FORMAT_YVU420) { - TDM_ERR("can't convert %c%c%c%c to %c%c%c%c", - FOURCC_STR(src_info.format), FOURCC_STR(dst_info.format)); - goto fail_convert; - } - } - /* need checking for other formats also? */ - - if (IS_RGB(src_info.format)) - sbw = src_info.planes[0].stride >> 2; - else - sbw = src_info.planes[0].stride; - - if (IS_RGB(dst_info.format)) - dbw = dst_info.planes[0].stride >> 2; - else - dbw = dst_info.planes[0].stride; - - rotate = (info->transform % 4) * 90; - if (info->transform >= TDM_TRANSFORM_FLIPPED) - hflip = 1; - - if (bo_size < src_info.planes[0].stride * src_info.height) { - TDM_WRN("bo size(%d) is smaller than the expected size(%d)", - bo_size, src_info.planes[0].stride * src_info.height); - goto fail_convert; - } - - _tdm_drm_pp_pixman_convert(PIXMAN_OP_SRC, - src_info.planes[0].ptr, dst_info.planes[0].ptr, - src_format, dst_format, - sbw, src_info.height, - info->src_config.pos.x, info->src_config.pos.y, - info->src_config.pos.w, info->src_config.pos.h, - dbw, dst_info.height, - info->dst_config.pos.x, info->dst_config.pos.y, - info->dst_config.pos.w, info->dst_config.pos.h, - rotate, hflip, 0); - tbm_surface_unmap(buffer->src); - tbm_surface_unmap(buffer->dst); - - return TDM_ERROR_NONE; -fail_convert: - tbm_surface_unmap(buffer->src); - tbm_surface_unmap(buffer->dst); - return TDM_ERROR_OPERATION_FAILED; -} - -tdm_error -tdm_drm_pp_get_capability(tdm_drm_data *drm_data, tdm_caps_pp *caps) -{ - int i; - - if (!caps) { - TDM_ERR("invalid params"); - return TDM_ERROR_INVALID_PARAMETER; - } - - caps->capabilities = TDM_PP_CAPABILITY_SYNC; - - caps->format_count = NUM_PP_FORMAT; - - /* will be freed in frontend */ - caps->formats = calloc(1, sizeof pp_formats); - if (!caps->formats) { - TDM_ERR("alloc failed"); - return TDM_ERROR_OUT_OF_MEMORY; - } - for (i = 0; i < caps->format_count; i++) - caps->formats[i] = pp_formats[i]; - - caps->min_w = 16; - caps->min_h = 8; - caps->max_w = -1; /* not defined */ - caps->max_h = -1; - caps->preferred_align = 16; - - return TDM_ERROR_NONE; -} - -tdm_pp * -tdm_drm_pp_create(tdm_drm_data *drm_data, tdm_error *error) -{ - tdm_drm_pp_data *pp_data = calloc(1, sizeof(tdm_drm_pp_data)); - if (!pp_data) { - TDM_ERR("alloc failed"); - if (error) - *error = TDM_ERROR_OUT_OF_MEMORY; - return NULL; - } - - pp_data->drm_data = drm_data; - - LIST_INITHEAD(&pp_data->pending_buffer_list); - - if (!pp_list_init) { - pp_list_init = 1; - LIST_INITHEAD(&pp_list); - } - LIST_ADDTAIL(&pp_data->link, &pp_list); - - return pp_data; -} - -void -drm_pp_destroy(tdm_pp *pp) -{ - tdm_drm_pp_data *pp_data = pp; - tdm_drm_pp_buffer *b = NULL, *bb = NULL; - - if (!pp_data) - return; - - LIST_FOR_EACH_ENTRY_SAFE(b, bb, &pp_data->pending_buffer_list, link) { - LIST_DEL(&b->link); - free(b); - } - - LIST_DEL(&pp_data->link); - - free(pp_data); -} - -tdm_error -drm_pp_set_info(tdm_pp *pp, tdm_info_pp *info) -{ - tdm_drm_pp_data *pp_data = pp; - - RETURN_VAL_IF_FAIL(pp_data, TDM_ERROR_INVALID_PARAMETER); - RETURN_VAL_IF_FAIL(info, TDM_ERROR_INVALID_PARAMETER); - - pp_data->info = *info; - - return TDM_ERROR_NONE; -} - -tdm_error -drm_pp_attach(tdm_pp *pp, tbm_surface_h src, tbm_surface_h dst) -{ - tdm_drm_pp_data *pp_data = pp; - tdm_drm_pp_buffer *buffer; - - RETURN_VAL_IF_FAIL(pp_data, TDM_ERROR_INVALID_PARAMETER); - RETURN_VAL_IF_FAIL(src, TDM_ERROR_INVALID_PARAMETER); - RETURN_VAL_IF_FAIL(dst, TDM_ERROR_INVALID_PARAMETER); - - if (tbm_surface_internal_get_num_bos(src) > 1 || - tbm_surface_internal_get_num_bos(dst) > 1) { - TDM_ERR("can't handle multiple tbm bos"); - return TDM_ERROR_OPERATION_FAILED; - } - - buffer = calloc(1, sizeof(tdm_drm_pp_buffer)); - if (!buffer) { - TDM_ERR("alloc failed"); - return TDM_ERROR_NONE; - } - - LIST_ADDTAIL(&buffer->link, &pp_data->pending_buffer_list); - - buffer->src = src; - buffer->dst = dst; - - return TDM_ERROR_NONE; -} - -tdm_error -drm_pp_commit(tdm_pp *pp) -{ - tdm_drm_pp_data *pp_data = pp; - tdm_drm_pp_buffer *b = NULL, *bb = NULL; - - RETURN_VAL_IF_FAIL(pp_data, TDM_ERROR_INVALID_PARAMETER); - - LIST_FOR_EACH_ENTRY_SAFE(b, bb, &pp_data->pending_buffer_list, link) { - LIST_DEL(&b->link); - - _tdm_drm_pp_convert(b, &pp_data->info); - - if (pp_data->done_func) - pp_data->done_func(pp_data, - b->src, - b->dst, - pp_data->done_user_data); - free(b); - } - - return TDM_ERROR_NONE; -} - -tdm_error -drm_pp_set_done_handler(tdm_pp *pp, tdm_pp_done_handler func, void *user_data) -{ - tdm_drm_pp_data *pp_data = pp; - - RETURN_VAL_IF_FAIL(pp_data, TDM_ERROR_INVALID_PARAMETER); - RETURN_VAL_IF_FAIL(func, TDM_ERROR_INVALID_PARAMETER); - - pp_data->done_func = func; - pp_data->done_user_data = user_data; - - return TDM_ERROR_NONE; -} diff --git a/src/libtdm-drm/tdm_drm_pp.h b/src/libtdm-drm/tdm_drm_pp.h deleted file mode 100644 index 3c62d7b..0000000 --- a/src/libtdm-drm/tdm_drm_pp.h +++ /dev/null @@ -1,43 +0,0 @@ -/************************************************************************** - -libtdm_drm - -Copyright 2015 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_DRM_PP_H_ -#define _TDM_DRM_PP_H_ - -#include "tdm_drm.h" - -tdm_error tdm_drm_pp_get_capability(tdm_drm_data *drm_data, tdm_caps_pp *caps); -tdm_pp* tdm_drm_pp_create(tdm_drm_data *drm_data, tdm_error *error); -void tdm_drm_pp_handler(unsigned int prop_id, unsigned int *buf_idx, - unsigned int tv_sec, unsigned int tv_usec, void *data); -void tdm_drm_pp_cb(int fd, unsigned int prop_id, unsigned int *buf_idx, - unsigned int tv_sec, unsigned int tv_usec, - void *user_data); -#endif /* _TDM_DRM_PP_H_ */ diff --git a/src/libtdm-drm/tdm_drm_types.h b/src/libtdm-drm/tdm_drm_types.h deleted file mode 100644 index 5063781..0000000 --- a/src/libtdm-drm/tdm_drm_types.h +++ /dev/null @@ -1,268 +0,0 @@ -/************************************************************************** - -libtdm_drm - -Copyright 2015 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_DRM_TYPES_H_ -#define _TDM_DRM_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 MIN_WIDTH 32 - -/* drm module internal macros, structures, functions */ -#define NEVER_GET_HERE() TDM_ERR("** NEVER GET HERE **") - -#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 CURSOR_MIN_W 192 -#define CURSOR_MIN_H 192 -#define CURSOR_MAX_W 192 -#define CURSOR_MAX_H 192 - -#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_drm_data tdm_drm_data; -typedef struct _tdm_drm_output_data tdm_drm_output_data; -typedef struct _tdm_drm_layer_data tdm_drm_layer_data; -typedef struct _tdm_drm_hwc_data tdm_drm_hwc_data; -typedef struct _tdm_drm_hwc_window_data tdm_drm_hwc_window_data; -typedef struct _tdm_drm_event_data tdm_drm_event_data; -typedef struct _tdm_drm_display_buffer tdm_drm_display_buffer; - -typedef enum { - TDM_DRM_EVENT_TYPE_WAIT, - TDM_DRM_EVENT_TYPE_COMMIT, - TDM_DRM_EVENT_TYPE_PAGEFLIP, -} tdm_drm_event_type; - -struct _tdm_drm_data { - tdm_display *dpy; - - int drm_fd; - -#if LIBDRM_MAJOR_VERSION >= 2 && LIBDRM_MINOR_VERSION >= 4 && LIBDRM_MICRO_VERSION >= 47 - int has_universal_plane; -#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_drm_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_drm_event_data { - tdm_drm_event_type type; - tdm_drm_output_data *output_data; - void *user_data; -}; - -struct _tdm_drm_output_data { - struct list_head link; - - /* data which are fixed at initializing */ - tdm_drm_data *drm_data; - uint32_t connector_id; - uint32_t encoder_id; - uint32_t crtc_id; - uint32_t pipe; - uint32_t dpms_prop_id; - int count_modes; - drmModeModeInfoPtr drm_modes; - tdm_output_mode *output_modes; - tdm_output_type connector_type; - unsigned int connector_type_id; - struct list_head layer_list; - tdm_drm_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; - - /* hwc */ - int hwc_enable; - tdm_drm_hwc_data *hwc_data; - - /* dpms */ - tdm_output_dpms current_dpms; -}; - -struct _tdm_drm_layer_data { - struct list_head link; - - /* data which are fixed at initializing */ - tdm_drm_data *drm_data; - tdm_drm_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_drm_display_buffer *display_buffer; - int display_buffer_changed; -}; - -struct _tdm_drm_hwc_data { - tdm_drm_hwc_window_data *target_hwc_window; - - int need_validate; - int need_target_window; - int need_set_crtc; - - int target_window_zpos; - - tdm_drm_output_data *output_data; - struct list_head hwc_window_list; - - tbm_surface_h cursor_tsurface; - - tdm_hwc_commit_handler commit_func; -}; - -struct _tdm_drm_hwc_window_data { - struct list_head link; - - tdm_drm_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; -}; - -#endif /* _TDM_DRM_TYPES_H_ */ diff --git a/src/libhal-backend-tdm-drm/tdm_backend_drm.c b/src/tdm_backend_drm.c index d6e420e..d6e420e 100644 --- a/src/libhal-backend-tdm-drm/tdm_backend_drm.c +++ b/src/tdm_backend_drm.c diff --git a/src/libhal-backend-tdm-drm/tdm_backend_drm.h b/src/tdm_backend_drm.h index 4cc8fc2..4cc8fc2 100644 --- a/src/libhal-backend-tdm-drm/tdm_backend_drm.h +++ b/src/tdm_backend_drm.h diff --git a/src/libhal-backend-tdm-drm/tdm_backend_drm_types.h b/src/tdm_backend_drm_types.h index 2d13c13..2d13c13 100644 --- a/src/libhal-backend-tdm-drm/tdm_backend_drm_types.h +++ b/src/tdm_backend_drm_types.h diff --git a/src/libhal-backend-tdm-drm/tdm_backend_list.h b/src/tdm_backend_list.h index 3873817..3873817 100644 --- a/src/libhal-backend-tdm-drm/tdm_backend_list.h +++ b/src/tdm_backend_list.h diff --git a/src/libhal-backend-tdm-drm/tdm_backend_log.c b/src/tdm_backend_log.c index e4d17c0..e4d17c0 100644 --- a/src/libhal-backend-tdm-drm/tdm_backend_log.c +++ b/src/tdm_backend_log.c diff --git a/src/libhal-backend-tdm-drm/tdm_backend_log.h b/src/tdm_backend_log.h index c0b9a05..c0b9a05 100644 --- a/src/libhal-backend-tdm-drm/tdm_backend_log.h +++ b/src/tdm_backend_log.h diff --git a/src/libhal-backend-tdm-drm/tdm_drm_display.c b/src/tdm_drm_display.c index 10c820c..10c820c 100644 --- a/src/libhal-backend-tdm-drm/tdm_drm_display.c +++ b/src/tdm_drm_display.c diff --git a/src/libhal-backend-tdm-drm/tdm_drm_format.c b/src/tdm_drm_format.c index 143bf41..143bf41 100644 --- a/src/libhal-backend-tdm-drm/tdm_drm_format.c +++ b/src/tdm_drm_format.c diff --git a/src/libhal-backend-tdm-drm/tdm_drm_hwc.c b/src/tdm_drm_hwc.c index 5f7bc6a..5f7bc6a 100644 --- a/src/libhal-backend-tdm-drm/tdm_drm_hwc.c +++ b/src/tdm_drm_hwc.c diff --git a/src/libhal-backend-tdm-drm/tdm_drm_hwc_window.c b/src/tdm_drm_hwc_window.c index 206f06a..206f06a 100644 --- a/src/libhal-backend-tdm-drm/tdm_drm_hwc_window.c +++ b/src/tdm_drm_hwc_window.c diff --git a/src/libhal-backend-tdm-drm/tdm_drm_pp.c b/src/tdm_drm_pp.c index dc684dd..dc684dd 100644 --- a/src/libhal-backend-tdm-drm/tdm_drm_pp.c +++ b/src/tdm_drm_pp.c |