replace common qcom sources with samsung ones

This commit is contained in:
SaschaNes
2025-08-12 22:13:00 +02:00
parent ba24dcded9
commit 6f7753de11
5682 changed files with 2450203 additions and 103634 deletions

View File

@@ -0,0 +1,52 @@
AM_CFLAGS = -Wundef -Wstrict-prototypes -Wno-trigraphs -std=c++11
AM_CFLAGS+= -I./inc -I$(WORKSPACE)/vendor/qcom/opensource/commonsys-intf/display/include
AM_CFLAGS+= -DGBM_DEBUG -DALLOCATE_SURFACE_BO_AT_CREATION -DBUILD_HAS_WAYLAND_SUPPORT -DVENUS_COLOR_FORMAT
AM_CPPFLAGS = -Wundef -Wstrict-prototypes -Wno-trigraphs -std=c++11
AM_CPPFLAGS+= -I./inc -I$(WORKSPACE)/vendor/qcom/opensource/commonsys-intf/display/include
AM_CPPFLAGS+= -DGBM_DEBUG -DALLOCATE_SURFACE_BO_AT_CREATION -DBUILD_HAS_WAYLAND_SUPPORT -DVENUS_COLOR_FORMAT
if IS_QRBX210
AM_CFLAGS += -DENABLE_CAM_MIMAS
AM_CPPFLAGS += -DENABLE_CAM_MIMAS
endif
if IS_QCS610
AM_CFLAGS += -DENABLE_CAM_NV12_128
AM_CPPFLAGS += -DENABLE_CAM_NV12_128
endif
if ENABLE_COMPILEWITHDRM
AM_CFLAGS += -DENABLE_DRM
AM_CPPFLAGS += -DENABLE_DRM
else
AM_CFLAGS += -DENABLE_FB
AM_CPPFLAGS += -DENABLE_FB
endif
lib_LTLIBRARIES = libgbm.la
libgbm_la_CFLAGS = $(AM_CFLAGS)
libgbm_la_CPPFLAGS = $(AM_CFLAGS)
libgbm_la_LDFLAGS = -shared -avoid-version -lm -ldl -lwayland-server -lwayland-client
libgbm_la_SOURCES = src/gbm.c \
src/msmgbm_camera.c \
src/msmgbm_video.c \
src/msmgbm_common.c \
src/msmgbm_platform_wrapper.cpp \
src/msmgbm_adreno_utils.cpp \
src/msmgbm_mapper.cpp
if ENABLE_COMPILEWITHDRM
libgbm_la_SOURCES += src/msmgbm.c
else
libgbm_la_SOURCES += src/msmgbm_fb.c
endif
bin_PROGRAMS = gbmtest
gbmtest_SOURCES = test/gbmtest.c
gbmtest_LDADD = libgbm.la
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = gbm.pc
EXTRA_DIST = $(pkgconfig_DATA)

View File

@@ -0,0 +1,78 @@
Copyright (c) 2021 The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
________________________________________
/*
* Copyright © 2011 Intel Corporation
*
* 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, sublicense,
* 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
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS 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.
*
* Authors:
* Benjamin Franzke <benjaminfranzke@googlemail.com>
*/
________________________________________
/*
* Copyright 2014 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
________________________________________
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
________________________________________

View File

@@ -0,0 +1,147 @@
# Copyright (c) 2021 The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of The Linux Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AC_PREREQ(2.61)
AC_INIT([libgbm],
20.1.0,
[],
libgbm)
AM_INIT_AUTOMAKE([-Wall -Wno-error foreign subdir-objects])
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
LT_INIT
AM_MAINTAINER_MODE
AC_CONFIG_HEADER([config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_ARG_WITH([glib],
AC_HELP_STRING([--with-glib],
[enable glib, building HLOS systems which use glib]))
if (test "x${with_glib}" = "xyes"); then
AC_DEFINE(ENABLE_USEGLIB, 1, [Define if HLOS systems uses glib])
PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= 2.16, dummy=yes,
AC_MSG_ERROR(GThread >= 2.16 is required))
PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16, dummy=yes,
AC_MSG_ERROR(GLib >= 2.16 is required))
GLIB_CFLAGS="$GLIB_CFLAGS $GTHREAD_CFLAGS"
GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS"
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
fi
if test "x${with_glib}" = "xyes"; then
CFLAGS="$CFLAGS -I$GLIB_CFLAGS -DUSE_GLIB"
LDFLAGS="$LDFLAGS -lglib-2.0"
fi
AC_ARG_WITH([core_includes],
AC_HELP_STRING([--with-core-includes=@<:@dir@:>@],
[Specify the location of the core headers]),
[core_incdir=$withval],
with_core_includes=no)
if test "x$with_core_includes" != "xno"; then
CFLAGS="${CFLAGS} -I${core_incdir}"
fi
#pkgconfigdir=${libdir}/pkgconfig
#AC_SUBST(pkgconfigdir)
AC_ARG_WITH(sanitized-headers,
AS_HELP_STRING([--with-sanitized-headers=DIR],
[Specify the location of the sanitized Linux headers]),
[CPPFLAGS="$CPPFLAGS -I$withval"])
AC_ARG_ENABLE([compilewithdrm],
AC_HELP_STRING([--enable-compilewithdrm],
[enable compilewithdrm, build gbm with compilewithdrm]),
[enable_compilewithdrm="${enableval}"],
enable_compilewithdrm=no)
AM_CONDITIONAL([ENABLE_COMPILEWITHDRM], [test "x${enable_compilewithdrm}" = "xyes"])
AC_ARG_ENABLE([wayland-support],
AC_HELP_STRING([--enable-wayland-support],
[with wayland support, build gbm with wayland-support]),
[enable_waylandsupport="${enableval}"],
enable_waylandsupport=no)
AM_CONDITIONAL(BUILD_HAS_WAYLAND_SUPPORT, test "x${enable_waylandsupport}" = "xyes")
if test "x${enable_waylandsupport}" = "xyes"; then
AC_DEFINE(BUILD_HAS_WAYLAND_SUPPORT, 1, [Enable when build has wayland support])
fi
AC_ARG_ENABLE([target-qrbx210],
AC_HELP_STRING([--enable-target-qrbx210],
[Enable conditional compile for target qrbx210]),
[target_qrbx210="${enableval}"],
target_qrbx210=no)
AM_CONDITIONAL([IS_QRBX210], [test "x$target_qrbx210" = xyes])
AC_ARG_ENABLE([target-qcs610],
AC_HELP_STRING([--enable-target-qcs610],
[Enable conditional compile for target qcs610]),
[target_qcs610="${enableval}"],
target_qcs610=no)
AM_CONDITIONAL([IS_QCS610], [test "x$target_qcs610" = xyes])
# Checks for programs.
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CXX
AC_PROG_LIBTOOL
AC_PROG_AWK
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
#PKG_CHECK_MODULES(LIBDRM, [libdrm])
ALLOCATE_SURFACE_BO_AT_CREATION=yes
AM_CONDITIONAL(ALLOCATE_SURFACE_BO_AT_CREATION, test $ALLOCATE_SURFACE_BO_AT_CREATION = yes)
if test $ALLOCATE_SURFACE_BO_AT_CREATION = yes; then
AC_DEFINE(ALLOCATE_SURFACE_BO_AT_CREATION, 1, [Enable surface's BO creation at surface creation time])
fi
AC_CONFIG_FILES([ \
Makefile \
gbm.pc
])
AC_SUBST([CFLAGS])
AC_SUBST([CPPFLAGS])
AC_SUBST([LIBS])
AC_OUTPUT
#AC_OUTPUT([Makefile src/Makefile])

View File

@@ -0,0 +1,10 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libgbm
Description: Userspace interface to kernel ION Memory services
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lgbm
Cflags: -I${includedir}

View File

@@ -0,0 +1,450 @@
/*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
* Not a Contribution.
*
* Copyright (c) 2017, 2021 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright © 2011 Intel Corporation
*
* 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, sublicense,
* 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
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS 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.
*
* Authors:
* Benjamin Franzke <benjaminfranzke@googlemail.com>
*/
#ifndef _GBM_H_
#define _GBM_H_
#ifdef __cplusplus
extern "C" {
#endif
#define __GBM__ 1
#include <stddef.h>
#include <stdint.h>
/**
* \file gbm.h
* \brief Generic Buffer Manager
*/
struct gbm_device;
struct gbm_bo;
struct gbm_surface;
/**
* \mainpage The Generic Buffer Manager
*
* This module provides an abstraction that the caller can use to request a
* buffer from the underlying memory management system for the platform.
*
* This allows the creation of portable code whilst still allowing access to
* the underlying memory manager.
*/
/**
* Abstraction representing the handle to a buffer allocated by the
* manager
*/
union gbm_bo_handle {
void *ptr;
int32_t s32;
uint32_t u32;
int64_t s64;
uint64_t u64;
};
/** Format of the allocated buffer */
enum gbm_bo_format {
/** RGB with 8 bits per channel in a 32 bit value */
GBM_BO_FORMAT_XRGB8888,
/** ARGB with 8 bits per channel in a 32 bit value */
GBM_BO_FORMAT_ARGB8888
};
#define __gbm_fourcc_code(a,b,c,d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \
((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
#define GBM_FORMAT_BIG_ENDIAN (1<<31) /* format is big endian instead of little endian */
/* color index */
#define GBM_FORMAT_C8 __gbm_fourcc_code('C', '8', ' ', ' ') /* [7:0] C */
/* 8 bpp Red */
#define GBM_FORMAT_R8 __gbm_fourcc_code('R', '8', ' ', ' ') /* [7:0] R */
/* 16 bpp Red */
#define GBM_FORMAT_R16 __gbm_fourcc_code('R', '1', '6', ' ') /* [15:0] R little endian */
/* 16 bpp RG */
#define GBM_FORMAT_RG88 __gbm_fourcc_code('R', 'G', '8', '8') /* [15:0] R:G 8:8 little endian */
/* 32 bpp RG */
#define GBM_FORMAT_RG1616 __gbm_fourcc_code('R', 'G', '3', '2') /* [31:0] R:G 16:16 little endian */
/* 8 bpp RGB */
#define GBM_FORMAT_RGB332 __gbm_fourcc_code('R', 'G', 'B', '8') /* [7:0] R:G:B 3:3:2 */
#define GBM_FORMAT_BGR233 __gbm_fourcc_code('B', 'G', 'R', '8') /* [7:0] B:G:R 2:3:3 */
/* 16 bpp RGB */
#define GBM_FORMAT_XRGB4444 __gbm_fourcc_code('X', 'R', '1', '2') /* [15:0] x:R:G:B 4:4:4:4 little endian */
#define GBM_FORMAT_XBGR4444 __gbm_fourcc_code('X', 'B', '1', '2') /* [15:0] x:B:G:R 4:4:4:4 little endian */
#define GBM_FORMAT_RGBX4444 __gbm_fourcc_code('R', 'X', '1', '2') /* [15:0] R:G:B:x 4:4:4:4 little endian */
#define GBM_FORMAT_BGRX4444 __gbm_fourcc_code('B', 'X', '1', '2') /* [15:0] B:G:R:x 4:4:4:4 little endian */
#define GBM_FORMAT_ARGB4444 __gbm_fourcc_code('A', 'R', '1', '2') /* [15:0] A:R:G:B 4:4:4:4 little endian */
#define GBM_FORMAT_ABGR4444 __gbm_fourcc_code('A', 'B', '1', '2') /* [15:0] A:B:G:R 4:4:4:4 little endian */
#define GBM_FORMAT_RGBA4444 __gbm_fourcc_code('R', 'A', '1', '2') /* [15:0] R:G:B:A 4:4:4:4 little endian */
#define GBM_FORMAT_BGRA4444 __gbm_fourcc_code('B', 'A', '1', '2') /* [15:0] B:G:R:A 4:4:4:4 little endian */
#define GBM_FORMAT_XRGB1555 __gbm_fourcc_code('X', 'R', '1', '5') /* [15:0] x:R:G:B 1:5:5:5 little endian */
#define GBM_FORMAT_XBGR1555 __gbm_fourcc_code('X', 'B', '1', '5') /* [15:0] x:B:G:R 1:5:5:5 little endian */
#define GBM_FORMAT_RGBX5551 __gbm_fourcc_code('R', 'X', '1', '5') /* [15:0] R:G:B:x 5:5:5:1 little endian */
#define GBM_FORMAT_BGRX5551 __gbm_fourcc_code('B', 'X', '1', '5') /* [15:0] B:G:R:x 5:5:5:1 little endian */
#define GBM_FORMAT_ARGB1555 __gbm_fourcc_code('A', 'R', '1', '5') /* [15:0] A:R:G:B 1:5:5:5 little endian */
#define GBM_FORMAT_ABGR1555 __gbm_fourcc_code('A', 'B', '1', '5') /* [15:0] A:B:G:R 1:5:5:5 little endian */
#define GBM_FORMAT_RGBA5551 __gbm_fourcc_code('R', 'A', '1', '5') /* [15:0] R:G:B:A 5:5:5:1 little endian */
#define GBM_FORMAT_BGRA5551 __gbm_fourcc_code('B', 'A', '1', '5') /* [15:0] B:G:R:A 5:5:5:1 little endian */
#define GBM_FORMAT_RGB565 __gbm_fourcc_code('R', 'G', '1', '6') /* [15:0] R:G:B 5:6:5 little endian */
#define GBM_FORMAT_BGR565 __gbm_fourcc_code('B', 'G', '1', '6') /* [15:0] B:G:R 5:6:5 little endian */
/* 24 bpp RGB */
#define GBM_FORMAT_RGB888 __gbm_fourcc_code('R', 'G', '2', '4') /* [23:0] R:G:B little endian */
#define GBM_FORMAT_BGR888 __gbm_fourcc_code('B', 'G', '2', '4') /* [23:0] B:G:R little endian */
/* 32 bpp RGB */
#define GBM_FORMAT_XRGB8888 __gbm_fourcc_code('X', 'R', '2', '4') /* [31:0] x:R:G:B 8:8:8:8 little endian */
#define GBM_FORMAT_XBGR8888 __gbm_fourcc_code('X', 'B', '2', '4') /* [31:0] x:B:G:R 8:8:8:8 little endian */
#define GBM_FORMAT_RGBX8888 __gbm_fourcc_code('R', 'X', '2', '4') /* [31:0] R:G:B:x 8:8:8:8 little endian */
#define GBM_FORMAT_BGRX8888 __gbm_fourcc_code('B', 'X', '2', '4') /* [31:0] B:G:R:x 8:8:8:8 little endian */
#define GBM_FORMAT_ARGB8888 __gbm_fourcc_code('A', 'R', '2', '4') /* [31:0] A:R:G:B 8:8:8:8 little endian */
#define GBM_FORMAT_ABGR8888 __gbm_fourcc_code('A', 'B', '2', '4') /* [31:0] A:B:G:R 8:8:8:8 little endian */
#define GBM_FORMAT_RGBA8888 __gbm_fourcc_code('R', 'A', '2', '4') /* [31:0] R:G:B:A 8:8:8:8 little endian */
#define GBM_FORMAT_BGRA8888 __gbm_fourcc_code('B', 'A', '2', '4') /* [31:0] B:G:R:A 8:8:8:8 little endian */
#define GBM_FORMAT_XRGB2101010 __gbm_fourcc_code('X', 'R', '3', '0') /* [31:0] x:R:G:B 2:10:10:10 little endian */
#define GBM_FORMAT_XBGR2101010 __gbm_fourcc_code('X', 'B', '3', '0') /* [31:0] x:B:G:R 2:10:10:10 little endian */
#define GBM_FORMAT_RGBX1010102 __gbm_fourcc_code('R', 'X', '3', '0') /* [31:0] R:G:B:x 10:10:10:2 little endian */
#define GBM_FORMAT_BGRX1010102 __gbm_fourcc_code('B', 'X', '3', '0') /* [31:0] B:G:R:x 10:10:10:2 little endian */
#define GBM_FORMAT_ARGB2101010 __gbm_fourcc_code('A', 'R', '3', '0') /* [31:0] A:R:G:B 2:10:10:10 little endian */
#define GBM_FORMAT_ABGR2101010 __gbm_fourcc_code('A', 'B', '3', '0') /* [31:0] A:B:G:R 2:10:10:10 little endian */
#define GBM_FORMAT_RGBA1010102 __gbm_fourcc_code('R', 'A', '3', '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */
#define GBM_FORMAT_BGRA1010102 __gbm_fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */
/* packed YCbCr */
#define GBM_FORMAT_YUYV __gbm_fourcc_code('Y', 'U', 'Y', 'V') /* [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian */
#define GBM_FORMAT_YVYU __gbm_fourcc_code('Y', 'V', 'Y', 'U') /* [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian */
#define GBM_FORMAT_UYVY __gbm_fourcc_code('U', 'Y', 'V', 'Y') /* [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian */
#define GBM_FORMAT_VYUY __gbm_fourcc_code('V', 'Y', 'U', 'Y') /* [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian */
#define GBM_FORMAT_AYUV __gbm_fourcc_code('A', 'Y', 'U', 'V') /* [31:0] A:Y:Cb:Cr 8:8:8:8 little endian */
/*
* 2 plane YCbCr
* index 0 = Y plane, [7:0] Y
* index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
* or
* index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
*/
#define GBM_FORMAT_NV12 __gbm_fourcc_code('N', 'V', '1', '2') /* 2x2 subsampled Cr:Cb plane */
#define GBM_FORMAT_NV21 __gbm_fourcc_code('N', 'V', '2', '1') /* 2x2 subsampled Cb:Cr plane */
#define GBM_FORMAT_NV16 __gbm_fourcc_code('N', 'V', '1', '6') /* 2x1 subsampled Cr:Cb plane */
#define GBM_FORMAT_NV61 __gbm_fourcc_code('N', 'V', '6', '1') /* 2x1 subsampled Cb:Cr plane */
/*
* 3 plane YCbCr
* index 0: Y plane, [7:0] Y
* index 1: Cb plane, [7:0] Cb
* index 2: Cr plane, [7:0] Cr
* or
* index 1: Cr plane, [7:0] Cr
* index 2: Cb plane, [7:0] Cb
*/
#define GBM_FORMAT_YUV410 __gbm_fourcc_code('Y', 'U', 'V', '9') /* 4x4 subsampled Cb (1) and Cr (2) planes */
#define GBM_FORMAT_YVU410 __gbm_fourcc_code('Y', 'V', 'U', '9') /* 4x4 subsampled Cr (1) and Cb (2) planes */
#define GBM_FORMAT_YUV411 __gbm_fourcc_code('Y', 'U', '1', '1') /* 4x1 subsampled Cb (1) and Cr (2) planes */
#define GBM_FORMAT_YVU411 __gbm_fourcc_code('Y', 'V', '1', '1') /* 4x1 subsampled Cr (1) and Cb (2) planes */
#define GBM_FORMAT_YUV420 __gbm_fourcc_code('Y', 'U', '1', '2') /* 2x2 subsampled Cb (1) and Cr (2) planes */
#define GBM_FORMAT_YVU420 __gbm_fourcc_code('Y', 'V', '1', '2') /* 2x2 subsampled Cr (1) and Cb (2) planes */
#define GBM_FORMAT_YUV422 __gbm_fourcc_code('Y', 'U', '1', '6') /* 2x1 subsampled Cb (1) and Cr (2) planes */
#define GBM_FORMAT_YVU422 __gbm_fourcc_code('Y', 'V', '1', '6') /* 2x1 subsampled Cr (1) and Cb (2) planes */
#define GBM_FORMAT_YUV444 __gbm_fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */
#define GBM_FORMAT_YVU444 __gbm_fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */
struct gbm_format_name_desc {
char name[5];
};
/**
* Flags to indicate the intended use for the buffer - these are passed into
* gbm_bo_create(). The caller must set the union of all the flags that are
* appropriate
*
* \sa Use gbm_device_is_format_supported() to check if the combination of format
* and use flags are supported
*/
enum gbm_bo_flags {
/**
* Buffer is going to be presented to the screen using an API such as KMS
*/
GBM_BO_USE_SCANOUT = (1 << 0),
/**
* Buffer is going to be used as cursor
*/
GBM_BO_USE_CURSOR = (1 << 1),
/**
* Deprecated
*/
GBM_BO_USE_CURSOR_64X64 = GBM_BO_USE_CURSOR,
/**
* Buffer is to be used for rendering - for example it is going to be used
* as the storage for a color buffer
*/
GBM_BO_USE_RENDERING = (1 << 2),
/**
* Buffer can be used for gbm_bo_write. This is guaranteed to work
* with GBM_BO_USE_CURSOR. but may not work for other combinations.
*/
GBM_BO_USE_WRITE = (1 << 3),
/**
* Buffer is linear, i.e. not tiled.
*/
GBM_BO_USE_LINEAR = (1 << 4),
};
int
gbm_device_get_fd(struct gbm_device *gbm);
const char *
gbm_device_get_backend_name(struct gbm_device *gbm);
int
gbm_device_is_format_supported(struct gbm_device *gbm,
uint32_t format, uint32_t usage);
int
gbm_device_get_format_modifier_plane_count(struct gbm_device *gbm,
uint32_t format,
uint64_t modifier);
void
gbm_device_destroy(struct gbm_device *gbm);
struct gbm_device *
gbm_create_device(int fd);
struct gbm_bo *
gbm_bo_create(struct gbm_device *gbm,
uint32_t width, uint32_t height,
uint32_t format, uint32_t flags);
struct gbm_bo *
gbm_bo_create_with_modifiers(struct gbm_device *gbm,
uint32_t width, uint32_t height,
uint32_t format,
const uint64_t *modifiers,
const unsigned int count);
#define GBM_BO_IMPORT_WL_BUFFER 0x5501
#define GBM_BO_IMPORT_EGL_IMAGE 0x5502
#define GBM_BO_IMPORT_FD 0x5503
#define GBM_BO_IMPORT_FD_MODIFIER 0x5504
struct gbm_import_fd_data {
int fd;
uint32_t width;
uint32_t height;
uint32_t stride;
uint32_t format;
};
#define GBM_MAX_PLANES 4
struct gbm_import_fd_modifier_data {
uint32_t width;
uint32_t height;
uint32_t format;
uint32_t num_fds;
int fds[GBM_MAX_PLANES];
int strides[GBM_MAX_PLANES];
int offsets[GBM_MAX_PLANES];
uint64_t modifier;
};
struct gbm_bo *
gbm_bo_import(struct gbm_device *gbm, uint32_t type,
void *buffer, uint32_t usage);
/**
* Flags to indicate the type of mapping for the buffer - these are
* passed into gbm_bo_map(). The caller must set the union of all the
* flags that are appropriate.
*
* These flags are independent of the GBM_BO_USE_* creation flags. However,
* mapping the buffer may require copying to/from a staging buffer.
*
* See also: pipe_transfer_usage
*/
enum gbm_bo_transfer_flags {
/**
* Buffer contents read back (or accessed directly) at transfer
* create time.
*/
GBM_BO_TRANSFER_READ = (1 << 0),
/**
* Buffer contents will be written back at unmap time
* (or modified as a result of being accessed directly).
*/
GBM_BO_TRANSFER_WRITE = (1 << 1),
/**
* Read/modify/write
*/
GBM_BO_TRANSFER_READ_WRITE = (GBM_BO_TRANSFER_READ | GBM_BO_TRANSFER_WRITE),
};
void *
gbm_bo_map(struct gbm_bo *bo,
uint32_t x, uint32_t y, uint32_t width, uint32_t height,
uint32_t flags, uint32_t *stride, void **map_data);
void
gbm_bo_unmap(struct gbm_bo *bo, void *map_data);
uint32_t
gbm_bo_get_width(struct gbm_bo *bo);
uint32_t
gbm_bo_get_height(struct gbm_bo *bo);
uint32_t
gbm_bo_get_stride(struct gbm_bo *bo);
uint32_t
gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane);
uint32_t
gbm_bo_get_format(struct gbm_bo *bo);
uint32_t
gbm_bo_get_bpp(struct gbm_bo *bo);
uint32_t
gbm_bo_get_offset(struct gbm_bo *bo, int plane);
struct gbm_device *
gbm_bo_get_device(struct gbm_bo *bo);
union gbm_bo_handle
gbm_bo_get_handle(struct gbm_bo *bo);
int
gbm_bo_get_fd(struct gbm_bo *bo);
uint64_t
gbm_bo_get_modifier(struct gbm_bo *bo);
int
gbm_bo_get_plane_count(struct gbm_bo *bo);
union gbm_bo_handle
gbm_bo_get_handle_for_plane(struct gbm_bo *bo, int plane);
int
gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count);
void
gbm_bo_set_user_data(struct gbm_bo *bo, void *data,
void (*destroy_user_data)(struct gbm_bo *, void *));
void *
gbm_bo_get_user_data(struct gbm_bo *bo);
void
gbm_bo_destroy(struct gbm_bo *bo);
struct gbm_surface *
gbm_surface_create(struct gbm_device *gbm,
uint32_t width, uint32_t height,
uint32_t format, uint32_t flags);
struct gbm_surface *
gbm_surface_create_with_modifiers(struct gbm_device *gbm,
uint32_t width, uint32_t height,
uint32_t format,
const uint64_t *modifiers,
const unsigned int count);
int
gbm_surface_needs_lock_front_buffer(struct gbm_surface *surface);
struct gbm_bo *
gbm_surface_lock_front_buffer(struct gbm_surface *surface);
void
gbm_surface_release_buffer(struct gbm_surface *surface, struct gbm_bo *bo);
int
gbm_surface_has_free_buffers(struct gbm_surface *surface);
void
gbm_surface_destroy(struct gbm_surface *surface);
char *
gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc *desc);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,812 @@
/*
* Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
* Not a Contribution.
*
* Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*Not a contribution
*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Copyright © 2011 Intel Corporation
*
* 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, sublicense,
* 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
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS 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.
*
* Authors:
* Benjamin Franzke <benjaminfranzke@googlemail.com>
*/
#ifndef GBM_PRIV_H_
#define GBM_PRIV_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* \file gbm_priv.h
* \brief: This header file would be an interface for Graphics and video clients
*
*/
#include <stdint.h>
#include <stddef.h>
#include <stdarg.h>
#include <gbm.h>
#include <color_metadata.h>
/**
* These are the flags used by the clients during allocation to
* indicate the purpose of allocation to the gbm backend.
* Gbm backend can use them to decide on the ION heap id and ION flags to be
* used as part of ION allocation.
* NOTE:
* These usage flags are extension to the open source gbm.h defined
* flags, so the initial integer value of these flags has spacing to avoid
* conflicts
*/
/** These allocation heap are used to select the corresponding ION heap id. */
#define GBM_BO_ALLOC_SYSTEM_HEAP_QTI 0x00000100 /*BO allocation from system heap*/
#define GBM_BO_ALLOC_SECURE_HEAP_QTI 0x00000200 /*BO allocation from secure heap*/
#define GBM_BO_ALLOC_SECURE_DISPLAY_HEAP_QTI 0x00000400 /*BO allocation from secure-display heap*/
#define GBM_BO_ALLOC_ADSP_HEAP_QTI 0x00000800 /*BO allocation from ADSP heap*/
#define GBM_BO_ALLOC_CAMERA_HEAP_QTI 0x00001000 /*BO allocation from camera heap*/
#define GBM_BO_ALLOC_IOMMU_HEAP_QTI 0x00002000 /*BO allocation from IOMMU heap*/
#define GBM_BO_ALLOC_MM_HEAP_QTI 0x00004000 /*BO allocation from MM heap*/
/** These usage flags are used to inform GBM backend about the usage of the allcated BO.*/
#define GBM_BO_USAGE_PROTECTED_QTI 0x00008000 /*BO allocation flag to get protected BO*/
#define GBM_BO_USAGE_UNCACHED_QTI 0x00010000 /*BO allocation flag to get uncached BO*/
#define GBM_BO_USAGE_CPU_READ_QTI 0x00020000 /*BO has CPU read access */
#define GBM_BO_USAGE_CPU_WRITE_QTI 0x00040000 /*BO has CPU write access */
#define GBM_BO_USAGE_NON_CPU_WRITER_QTI 0x00080000 /*BO has non-CPU writer access */
#define GBM_BO_USAGE_UBWC_ALIGNED_QTI 0x00100000 /*BO allocation for UBWC enabled client request*/
#define GBM_BO_USAGE_CAMERA_READ_QTI 0x00200000 /*BO used for camera consumer */
#define GBM_BO_USAGE_CAMERA_WRITE_QTI 0x00400000 /*BO used for camera producer */
#define GBM_BO_USAGE_VIDEO_ENCODER_QTI 0x00800000 /*BO used for video encoder */
#define GBM_BO_USAGE_HW_COMPOSER_QTI 0x01000000 /*BO used for video encoder */
#define GBM_BO_USAGE_HW_RENDERING_QTI 0x02000000 /*BO allocation for GPU based rendering operation */
#define GBM_BO_USAGE_10BIT_QTI 0x04000000 /*BO allocation for 10 bit */
#define GBM_BO_USAGE_10BIT_TP_QTI 0x08000000 /*BO allocation for 10 bit TP */
#define GBM_BO_USAGE_EGL_IMAGE_QTI 0x10000000 /*BO allocation for EGL image operation */
/**
* These are the parameter types to be used by the clients to query metadata info from gbm backend
*
*/
#define GBM_METADATA_GET_INTERLACED 0x00000001 /*Param type to query Interlaced field*/
#define GBM_METADATA_GET_REFRESH_RATE 0x00000002 /*Param type to query Refresh rate field*/
#define GBM_METADATA_GET_MAP_SECURE_BUFFER 0x00000004 /*Param type to query map secure buffer field*/
#define GBM_METADATA_GET_LINEAR_FORMAT 0x00000008 /*Param type to query linear format field*/
#define GBM_METADATA_GET_COLOR_SPACE 0x00000010 /*Param type to query Color space field*/
#define GBM_METADATA_GET_IGC 0x00000020 /*Param type to query IGC field*/
#define GBM_METADATA_GET_S3DFORMAT 0x00000040 /*Param type to query S3D format field*/
#define GBM_METADATA_GET_SECURE_BUF_STAT 0x00000080 /*Param type to query secure buffer status*/
#define GBM_METADATA_GET_COLOR_METADATA 0x00000100 /*Param type to query Color Metadata*/
#define GBM_METADATA_GET_UBWC_BUF_STAT 0x00000200 /*Param type to query UBWC buffer status*/
#define GBM_METADATA_GET_VT_TIMESTAMP 0x00000400 /*Param type to query VT timestamp*/
#define GBM_METADATA_GET_VIDEO_PERF_MODE 0x00000800 /*Param type to query Video Perf mode*/
#define GBM_METADATA_GET_CVP_METADATA 0x00001000 /*Param type to query CVPMetadata*/
#define GBM_METADATA_GET_VIDEO_HIST_STAT 0x00002000 /*Param type to query Video Histogram Stat*/
/**
* These are the parameter types to be used by the clients to set metadata info from gbm backend
*
*/
#define GBM_METADATA_SET_INTERLACED 0x00000001 /*Param type to set Interlaced field*/
#define GBM_METADATA_SET_REFRESH_RATE 0x00000002 /*Param type to set Refresh rate field*/
#define GBM_METADATA_SET_MAP_SECURE_BUFFER 0x00000004 /*Param type to set map secure buffer field*/
#define GBM_METADATA_SET_LINEAR_FORMAT 0x00000008 /*Param type to set linear format field*/
#define GBM_METADATA_SET_COLOR_SPACE 0x00000010 /*Param type to set Color space field*/
#define GBM_METADATA_SET_IGC 0x00000020 /*Param type to set IGC field*/
#define GBM_METADATA_SET_S3DFORMAT 0x00000040 /*Param type to set S3D format field*/
#define GBM_METADATA_SET_COLOR_METADATA 0x00000080 /*Param type to set Color Metadata*/
#define GBM_METADATA_SET_VT_TIMESTAMP 0x00000100 /*Param type to set VT timestamp*/
#define GBM_METADATA_SET_VIDEO_PERF_MODE 0x00000200 /*Param type to set Video Perf mode*/
#define GBM_METADATA_SET_CVP_METADATA 0x00000400 /*Param type to set CVPMetadata*/
#define GBM_METADATA_SET_VIDEO_HIST_STAT 0x00000800 /*Param type to set Video Histogram Stat*/
/**
* These define the color space value for the Metadata Color space entry
*
*/
#define GBM_METADATA_COLOR_SPACE_ITU_R_601 0x1
#define GBM_METADATA_COLOR_SPACE_ITU_R_601_FR 0x2
#define GBM_METADATA_COLOR_SPACE_ITU_R_709 0x3
#define GBM_METADATA_COLOR_SPACE_ITU_R_2020 0x4
#define GBM_METADATA_COLOR_SPACE_ITU_R_2020_FR 0x5
/**
* These define the IGC value for the Metadata IGC entry
*
*/
#define GBM_METADATA_IGC_NONE 0x1
#define GBM_METADATA_IGC_sRGB 0x2
/**
* Supported Perform API Operation Opcodes
*
*/
#define GBM_PERFORM_GET_SURFACE_FORMAT 0x0 /*Query user provided format from the
gbm surface*/
#define GBM_PERFORM_GET_SURFACE_WIDTH 0x1 /*Query user provided width from the
gbm surface */
#define GBM_PERFORM_GET_SURFACE_HEIGHT 0x2 /*Query user provided height from the
gbm surface*/
#define GBM_PERFORM_SET_SURFACE_FRONT_BO 0x3 /*Update the current state to
NEW_FRONT_BUFFER of the BO associated
with the gbm surface*/
#define GBM_PERFORM_GET_SURFACE_FREE_BO 0x4 /*Return the BO which is marked free
associated with the gbm surface */
#define GBM_PERFORM_VALIDATE_SURFACE 0x5 /*Validate the GBM Surface*/
#define GBM_PERFORM_CPU_MAP_FOR_BO 0x6 /*Return the mapped address to the
BO buffer*/
#define GBM_PERFORM_CPU_UNMAP_FOR_BO 0x7 /*Unmap the already mapped BO buffer*/
#define GBM_PERFORM_GET_BO_SIZE 0x8 /*Query BO buffer size*/
#define GBM_PERFORM_GET_BO_NAME 0x9 /*Query BO buffer name*/
#define GBM_PERFORM_IMPORT_BO_FROM_NAME 0x11 /*Import BO from specified name*/
#define GBM_PERFORM_GET_DRM_DEVICE_MAGIC 0x12 /*Query DRM Device magic id */
#define GBM_PERFORM_AUTH_DRM_DEVICE_MAGIC 0x13 /*Authenticate DRM Device magic id */
#define GBM_PERFORM_GET_DRM_DEVICE_NAME 0x14 /*Query DRM Device name */
#define GBM_PERFORM_VALIDATE_DEVICE 0x15 /*Validate the GBM Device*/
#define GBM_PERFORM_GET_METADATA 0x16 /*Query Metadata info */
#define GBM_PERFORM_SET_METADATA 0x17 /*Set Metadata info */
#define GBM_PERFORM_GET_YUV_PLANE_INFO 0x18 /*Query YUV plane info */
#define GBM_PERFORM_GET_UBWC_STATUS 0x19 /*Query if the BO Allocation was
with UBWC enabled hardware*/
#define GBM_PERFORM_GET_RGB_DATA_ADDRESS 0x20 /*Query for RGB data base address*/
#define GBM_PERFORM_SET_GPU_ADDR_FOR_BO 0x21 /*Set GPU addr */
#define GBM_PERFORM_GET_GPU_ADDR_FOR_BO 0x22 /* Query GPU Addr */
#define GBM_PERFORM_GET_SECURE_BUFFER_STATUS 0x23 /* Query Buffer is secured */
#define GBM_PERFORM_GET_METADATA_ION_FD 0x24 /* Get Metadata ion fd from BO*/
#define GBM_PERFORM_DUMP_HASH_MAP 0x25 /* Dump the existing hash map
table contents*/
#define GBM_PERFORM_DUMP_BO_CONTENT 0x26 /* Dump the BO buffer contents
on to a file*/
#define GBM_PERFORM_GET_BO_ALIGNED_WIDTH 0x27 /* Get Aligned width from BO*/
#define GBM_PERFORM_GET_BO_ALIGNED_HEIGHT 0x28 /* Get Aligned height from BO*/
#define GBM_PERFORM_GET_PLANE_INFO 0x29 /* Get Plane Info from BO*/
#define GBM_PERFORM_DEFAULT_INIT_COLOR_META 0x30 /* Initialize Color Meta structure with
default values to validate */
#define GBM_PERFORM_DUMP_COLOR_META 0x31 /* Dump Color Meta structure */
#define GBM_PERFORM_GET_BUFFER_SIZE_DIMENSIONS 0x32 /* Query Buffer size and dimenstions
(aligned width, aligned height and size)*/
#define GBM_PERFORM_GET_SURFACE_UBWC_STATUS 0x33 /* Query if the Surface BO Allocation was
with UBWC enabled hardware */
#define GBM_PERFORM_GET_WL_RESOURCE_FROM_GBM_BUF_INFO 0x34 /* Get wl_resource from gbm_buf_info*/
#define GBM_PERFORM_GET_GBM_BUF_INFO_FROM_WL_RESOURCE 0x35 /* Retrieve gbm_buf_info from
wl_resource */
#define GBM_PERFORM_GET_RENDER_DEVICE_NAME 0x36 /* Get render node for user */
#define GBM_PERFORM_GET_BUFFER_STRIDE_SCANLINE_SIZE 0x37 /* Query Buffer stride, scanline and size
(stride, scanline and size)*/
#define GBM_PERFORM_GET_FD_WITH_NEW 0x38 /* Query whether get fd with new */
/**
* Error representation for GBM API's
*
*/
#define GBM_ERROR_NONE 0x0
#define GBM_ERROR_BAD_DESCRIPTOR 0x1
#define GBM_ERROR_BAD_HANDLE 0x2
#define GBM_ERROR_BAD_VALUE 0x3
#define GBM_ERROR_NOT_SHARED 0x4
#define GBM_ERROR_NO_RESOURCES 0x5
#define GBM_ERROR_UNDEFINED 0x6
#define GBM_ERROR_UNSUPPORTED 0x7
/**
* Custom import type define
* In case there are more enums added to GBM import,
* they'd be in sequential order.To avoid conflicts it's
* best to have an unused range ... 0x4FFF and decremented
* if we have any more imports added
*/
#define GBM_BO_IMPORT_GBM_BUF_TYPE 0x4FFF
/**
* Custom 4CC Modifiers
*
* Format Modifiers info extracted from open source drm_fourcc.h:
*
* Format modifiers describe, typically, a re-ordering or modification
* of the data in a plane of an FB. This can be used to express tiled/
* swizzled formats, or compression, or a combination of the two.
*
* The upper 4 bits of the format modifier are a vendor-id as assigned
* below. The lower 28 bits are assigned as vendor sees fit.
*/
/* Vendor Ids: */
#define GBM_FORMAT_MOD_VENDOR_QTI 0x05
/* add more to the end as needed */
#define fourcc_mod_code_qti(vendor, val) \
((((uint32_t)GBM_FORMAT_MOD_VENDOR_## vendor) << 28) | (val & 0x0fffffffULL))
/**
* Below is the list of Custom 4CC modes supported by libgbm
*
*/
#define GBM_FORMAT_RAW16 fourcc_mod_code_qti(QTI, 1)
#define GBM_FORMAT_RAW10 fourcc_mod_code_qti(QTI, 2)
#define GBM_FORMAT_RAW12 fourcc_mod_code_qti(QTI, 3)
#define GBM_FORMAT_RAW8 fourcc_mod_code_qti(QTI, 4)
#define GBM_FORMAT_YV12 fourcc_mod_code_qti(QTI, 5)
#define GBM_FORMAT_YCbCr_420_SP fourcc_mod_code_qti(QTI, 6)
#define GBM_FORMAT_YCrCb_420_SP fourcc_mod_code_qti(QTI, 7)
#define GBM_FORMAT_YCbCr_422_SP fourcc_mod_code_qti(QTI, 8)
#define GBM_FORMAT_YCrCb_422_SP fourcc_mod_code_qti(QTI, 9)
#define GBM_FORMAT_YCbCr_422_I fourcc_mod_code_qti(QTI, 10)
#define GBM_FORMAT_YCrCb_422_I fourcc_mod_code_qti(QTI, 11)
#define GBM_FORMAT_YCbCr_420_SP_VENUS fourcc_mod_code_qti(QTI, 12)
#define GBM_FORMAT_NV12_ENCODEABLE fourcc_mod_code_qti(QTI, 13)
#define GBM_FORMAT_YCrCb_420_SP_VENUS fourcc_mod_code_qti(QTI, 14)
#define GBM_FORMAT_NV21_ZSL fourcc_mod_code_qti(QTI, 15)
#define GBM_FORMAT_BLOB fourcc_mod_code_qti(QTI, 16)
#define GBM_FORMAT_RAW_OPAQUE fourcc_mod_code_qti(QTI, 17)
#define GBM_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR fourcc_mod_code_qti(QTI, 18)
#define GBM_FORMAT_COMPRESSED_RGBA_ASTC_5x4_KHR fourcc_mod_code_qti(QTI, 19)
#define GBM_FORMAT_COMPRESSED_RGBA_ASTC_5x5_KHR fourcc_mod_code_qti(QTI, 20)
#define GBM_FORMAT_COMPRESSED_RGBA_ASTC_6x5_KHR fourcc_mod_code_qti(QTI, 21)
#define GBM_FORMAT_COMPRESSED_RGBA_ASTC_6x6_KHR fourcc_mod_code_qti(QTI, 22)
#define GBM_FORMAT_COMPRESSED_RGBA_ASTC_8x5_KHR fourcc_mod_code_qti(QTI, 23)
#define GBM_FORMAT_COMPRESSED_RGBA_ASTC_8x6_KHR fourcc_mod_code_qti(QTI, 24)
#define GBM_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR fourcc_mod_code_qti(QTI, 25)
#define GBM_FORMAT_COMPRESSED_RGBA_ASTC_10x5_KHR fourcc_mod_code_qti(QTI, 26)
#define GBM_FORMAT_COMPRESSED_RGBA_ASTC_10x6_KHR fourcc_mod_code_qti(QTI, 27)
#define GBM_FORMAT_COMPRESSED_RGBA_ASTC_10x8_KHR fourcc_mod_code_qti(QTI, 28)
#define GBM_FORMAT_COMPRESSED_RGBA_ASTC_10x10_KHR fourcc_mod_code_qti(QTI, 29)
#define GBM_FORMAT_COMPRESSED_RGBA_ASTC_12x10_KHR fourcc_mod_code_qti(QTI, 30)
#define GBM_FORMAT_COMPRESSED_RGBA_ASTC_12x12_KHR fourcc_mod_code_qti(QTI, 31)
#define GBM_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR fourcc_mod_code_qti(QTI, 32)
#define GBM_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR fourcc_mod_code_qti(QTI, 33)
#define GBM_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR fourcc_mod_code_qti(QTI, 34)
#define GBM_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR fourcc_mod_code_qti(QTI, 35)
#define GBM_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR fourcc_mod_code_qti(QTI, 36)
#define GBM_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR fourcc_mod_code_qti(QTI, 37)
#define GBM_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR fourcc_mod_code_qti(QTI, 38)
#define GBM_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR fourcc_mod_code_qti(QTI, 39)
#define GBM_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR fourcc_mod_code_qti(QTI, 40)
#define GBM_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR fourcc_mod_code_qti(QTI, 41)
#define GBM_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR fourcc_mod_code_qti(QTI, 42)
#define GBM_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR fourcc_mod_code_qti(QTI, 43)
#define GBM_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR fourcc_mod_code_qti(QTI, 44)
#define GBM_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR fourcc_mod_code_qti(QTI, 45)
#define GBM_FORMAT_YCbCr_420_SP_VENUS_UBWC fourcc_mod_code_qti(QTI, 46)
#define GBM_FORMAT_YCbCr_420_888 fourcc_mod_code_qti(QTI, 47)
#define GBM_FORMAT_IMPLEMENTATION_DEFINED fourcc_mod_code_qti(QTI, 48)
#define GBM_FORMAT_NV12_HEIF fourcc_mod_code_qti(QTI, 49)
#define GBM_FORMAT_YCbCr_420_P010_VENUS fourcc_mod_code_qti(QTI, 50)
#define GBM_FORMAT_NV12_LINEAR_FLEX fourcc_mod_code_qti(QTI, 51)
#define GBM_FORMAT_NV12_UBWC_FLEX fourcc_mod_code_qti(QTI, 52)
#define GBM_FORMAT_MULTIPLANAR_FLEX fourcc_mod_code_qti(QTI, 53)
#define GBM_FORMAT_RGBA16161616F fourcc_mod_code_qti(QTI, 54)
#define GBM_FORMAT_RGB161616F fourcc_mod_code_qti(QTI, 55)
#define GBM_FORMAT_RGBA32323232F fourcc_mod_code_qti(QTI, 56)
#define GBM_FORMAT_RGB323232F fourcc_mod_code_qti(QTI, 57)
#define GBM_FORMAT_YCbCr_420_TP10_UBWC __gbm_fourcc_code('Q', '1', '2', 'A')
#define GBM_FORMAT_YCbCr_420_P010_UBWC __gbm_fourcc_code('Q', '1', '2', 'B')
/* Y/CbCr 4:2:0 P10 format*/
#define GBM_FORMAT_P010 __gbm_fourcc_code('P', '0', '1', '0')
/**
* Pixel component ID defines
* to be used at the generic plane object
*
*/
/* luma */
#define PIXEL_COMPONENT_Y 0x00000001
/* chroma blue */
#define PIXEL_COMPONENT_Cb 0x00000002
/* chroma red */
#define PIXEL_COMPONENT_Cr 0x00000004
/* red */
#define PIXEL_COMPONENT_R 0x00000100
/* green */
#define PIXEL_COMPONENT_G 0x00000200
/* blue */
#define PIXEL_COMPONENT_B 0x00000400
/*RAW 10 */
#define PIXEL_COMPONENT_RAW10 0x00010000
/*RAW 16 */
#define PIXEL_COMPONENT_RAW16 0x00020000
/* alpha */
#define PIXEL_COMPONENT_A 0x00100000
/* Maximum count of planes for given frame buffer
Different from GBM_MAX_PLANES
*/
#define MAX_NUM_OF_PLANES 5
#define MAX_NUM_MODIFIERS 4
/* possible formats for 3D content*/
enum {
HAL_NO_3D = 0x0,
HAL_3D_SIDE_BY_SIDE_L_R = 0x1,
HAL_3D_SIDE_BY_SIDE_R_L = 0x2,
HAL_3D_TOP_BOTTOM = 0x4,
HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000, // unused legacy format
};
enum UBWC_Version {
UBWC_UNUSED = 0,
UBWC_1_0 = 0x1,
UBWC_2_0 = 0x2,
UBWC_3_0 = 0x3,
UBWC_4_0 = 0x4,
UBWC_MAX_VERSION = 0xFF,
};
#define MAX_UBWC_STATS_LENGTH 32
struct UBWC_2_0_Stats {
uint32_t nCRStatsTile32; /**< UBWC Stats info for 32 Byte Tile */
uint32_t nCRStatsTile64; /**< UBWC Stats info for 64 Byte Tile */
uint32_t nCRStatsTile96; /**< UBWC Stats info for 96 Byte Tile */
uint32_t nCRStatsTile128; /**< UBWC Stats info for 128 Byte Tile */
uint32_t nCRStatsTile160; /**< UBWC Stats info for 160 Byte Tile */
uint32_t nCRStatsTile192; /**< UBWC Stats info for 192 Byte Tile */
uint32_t nCRStatsTile256; /**< UBWC Stats info for 256 Byte Tile */
};
struct UBWCStats {
enum UBWC_Version version; /* Union depends on this version. */
uint8_t bDataValid; /* If [non-zero], CR Stats data is valid.
90 * Consumers may use stats data.
91 * If [zero], CR Stats data is invalid.
92 * Consumers *Shall* not use stats data */
union {
struct UBWC_2_0_Stats ubwc_stats;
uint32_t reserved[MAX_UBWC_STATS_LENGTH]; /* This is for future */
};
};
#define VIDEO_HISTOGRAM_STATS_SIZE (4 * 1024)
/* Frame type bit mask */
#define QD_SYNC_FRAME (0x1 << 0)
struct VideoHistogramMetadata {
uint32_t stats_info[1024]; /* video stats payload */
uint32_t stat_len; /* Payload size in bytes */
uint32_t frame_type; /* bit mask to indicate frame type */
uint32_t display_width;
uint32_t display_height;
uint32_t decode_width;
uint32_t decode_height;
uint32_t reserved[12];
};
#define CVP_METADATA_SIZE 1024
enum CVPMetadataFlags {
/* bit wise flags */
CVP_METADATA_FLAG_NONE = 0x00000000,
CVP_METADATA_FLAG_REPEAT = 0x00000001,
};
typedef struct CVPMetadata {
uint32_t size; /* payload size in bytes */
uint8_t payload[CVP_METADATA_SIZE];
uint32_t capture_frame_rate;
/* Frame rate in Q16 format.
Eg: fps = 7.5, then
capture_frame_rate = 7 << 16 --> Upper 16 bits to represent 7
capture_frame_rate |= 5 -------> Lower 16 bits to represent 5
If size > 0, framerate is valid
If size = 0, invalid data, so ignore all parameters */
uint32_t cvp_frame_rate;
enum CVPMetadataFlags flags;
uint32_t reserved[8];
} CVPMetadata;
/**
* The generic_buf_layout structure is used with any pixel format that can be
* represented by it, such as:
* - GBM_FORMAT_YCbCr_*_888
* - GBM_FORMAT_FLEX_RGB*_888
* - GBM_FORMAT_RGB[AX]_888[8],BGRA_8888,RGB_888
* - GBM_FORMAT_YV12,Y8,Y16,YCbCr_422_SP/I,YCrCb_420_SP
* - even implementation defined formats that can be represented by
* the structures
*
* Vertical increment (aka. row increment or stride) describes the distance in
* bytes from the first pixel of one row to the first pixel of the next row
* (below) for the component plane. This can be negative.
*
* Horizontal increment (aka. column or pixel increment) describes the distance
* in bytes from one pixel to the next pixel (to the right) on the same row for
* the component plane. This can be negative.
*
* Each plane can be subsampled either vertically or horizontally by
* a power-of-two factor.
*
* The bit-depth of each component can be arbitrary, as long as the pixels are
* laid out on whole bytes, in native byte-order, using the most significant
* bits of each unit.
*
*
* generic planar layout object definition
*
*/
typedef struct generic_plane {
uint32_t *top_left; /* pointer to the first byte of the top-left
pixel of the plane. */
/* NOTE: For secured buffers this pointer is
NULL */
uint32_t offset; /* offset to the first byte of the top-left
pixel of the plane */
int32_t component_id; /* ID to represent */
uint32_t aligned_width; /* Aligned width in pixels */
uint32_t aligned_height; /* Aligned height in pixels*/
uint32_t size; /* size in bytes*/
int32_t bits_per_component; /* bits allocated for the component in each
pixel. Must be a positive multiple of 8. */
int32_t bits_used; /* number of the most significant bits used
in the format for this component.
Must be between 1 and bits_per_component */
int32_t h_increment; /* horizontal increment */
int32_t v_increment; /* vertical increment */
int32_t h_subsampling; /* horizontal subsampling. Must be a positive
power of 2. */
int32_t v_subsampling; /* vertical subsampling. Must be a positive
power of 2. */
uint32_t stride; /* stride for plane */
} generic_plane_t;
typedef struct generic_buf_layout {
int pixel_format; /* the kind of pixel format */
uint32_t num_planes; /* number of planes
0 for FLEX_FORMAT_INVALID */
generic_plane_t planes[MAX_NUM_OF_PLANES]; /* a plane for each component,
ordered in increasing
component value order.
E.g. FLEX_FORMAT_RGBA
maps 0 -> R, 1 -> G, etc.
Can be NULL for FLEX_FORMAT_INVALID */
} generic_buf_layout_t;
/**
* gbm device object definition
*
*/
struct gbm_device {
int fd; /*gbm device fd */
const char *name; /* gbm device name*/
unsigned refcount; /* used to track the gbm device open call
reference*/
void (*destroy)(struct gbm_device *gbm);
int (*is_format_supported)(struct gbm_device *gbm,
uint32_t format,
uint32_t usage);
struct gbm_bo *(*bo_create)(struct gbm_device *gbm,
uint32_t width, uint32_t height,
uint32_t format,
uint32_t usage,
const uint64_t *modifiers,
const unsigned int count);
struct gbm_bo *(*bo_import)(struct gbm_device *gbm, uint32_t type,
void *buffer, uint32_t usage);
int (*get_format_modifier_plane_count)(uint32_t format,
uint64_t modifier);
struct gbm_surface *(*surface_create)(struct gbm_device *gbm,
uint32_t width, uint32_t height,
uint32_t format, uint32_t flags,
uint64_t *modifiers, unsigned int count);
};
/**
* The Metadata structure whose buffer handle is associated with
* gbm buffer object
*
* The members of this structure are accessed by gbm perform API only
*/
struct meta_data_t {
uint32_t operation; /* specific operation or state*/
uint32_t interlaced; /* video buffer scan */
uint32_t s3d_format; /* 3D video format supported */
uint32_t linear_format; /* Producer output buffer is linear for UBWC Interlaced video */
uint32_t color_space; /* color space specfics */
uint32_t map_secure_buffer; /* Flag to represent SecureBuffer being used for GPU*/
int is_buffer_secure; /* Flag to query if buffer is secure*/
int is_buffer_ubwc; /* Flag to query if buffer is UBWC allocated */
int igc; /* IGC value*/
float refresh_rate; /* video referesh rate*/
ColorMetaData color_info; /* Color Aspects + HDR info */
uint64_t vt_timestamp; /* timestamp set by camera, intended for VT*/
uint32_t isVideoPerfMode; /* set by camera indicates buffer will be used for
High performace video use case */
struct VideoHistogramMetadata histMetadata; /*histogram metadata*/
CVPMetadata cvpMetadata; /* Metadata from cvp */
};
/**
* The allocated gbm buffer object.
*
* The members in this structure should not be accessed directly.
*/
struct gbm_bo {
int ion_fd; /* ION buffer fd */
int ion_metadata_fd; /* ION metadata fd */
union gbm_bo_handle handle; /* GEM handle */
union gbm_bo_handle metadata_handle; /* GEM metadata handle */
uint32_t format; /* buffer format */
uint32_t width; /* unaligned width of the buffer in pixels */
uint32_t height; /* unaligned height of the buffer in pixels */
uint32_t aligned_width; /* aligned width of the buffer in pixels */
uint32_t aligned_height; /* aligned height of the buffer in pixels */
uint32_t size; /* size of the buffer in bytes */
uint32_t stride; /* stride of the buffer in bytes */
uint32_t usage_flags; /* usage flags */
uint32_t fbid; /* framebuffer id */
uint32_t bpp; /* bytes per pixel*/
uint32_t plane_count; /* plane count*/
generic_buf_layout_t buf_lyt;
uint64_t modifier;
int (*bo_write)(struct gbm_bo *bo, const void *buf, size_t data);
int (*bo_get_fd)(struct gbm_bo *bo);
struct gbm_device* (*bo_get_device)(struct gbm_bo *bo);
void (*bo_destroy)(struct gbm_bo *bo);
void *user_data;
void (*destroy_user_data)(struct gbm_bo *, void *);
void * (*bo_map)(uint32_t x, uint32_t y, uint32_t width, uint32_t height,
uint32_t flags, uint32_t *stride, void **map_data);
void (*bo_unmap)(void *map_data);
uint32_t (*stride_for_plane)(int plane, struct gbm_bo *);
};
/**
* The allocated gbm surface object.
*
* The members in this structure should not be accessed directly.
*/
struct gbm_surface {
uint32_t format; /* pixel format */
uint32_t width; /* width of surface in pixels */
uint32_t height; /* height of surface in pixels */
uint32_t flags; /* usage flags */
void (*surface_release_buffer)(struct gbm_surface *surface,
struct gbm_bo *bo);
int (*surface_has_free_buffers)(struct gbm_surface *surface);
void (*surface_destroy)(struct gbm_surface *surface);
struct gbm_bo* (*surface_lock_front_buffer)(struct gbm_surface *surface);
};
/**
* The gbm buffer data object used by the import fd API.
*
*/
struct gbm_buf_info {
int fd; /* ion fd */
int metadata_fd; /* ion metadata fd*/
uint32_t width; /* width of surface in pixels */
uint32_t height; /* height of surface in pixels */
uint32_t format; /* pixel format*/
};
/**
* gbm backend interface object.
*
*/
struct gbm_backendpriv{
const char *backend_name;
struct gbm_device *(*create_device)(int fd);
};
/**
* gbm backend interface .
*
*/
struct gbm_backendpriv *gbm_get_priv(void);
/**
* Perform supported queries
* Input : operation opcodes
* : Arguments depending on the operation
* Return = gbm_error value
*
*/
int gbm_perform(int operation,...);
#ifdef __cplusplus
}
#endif
#endif //GBM_PRIV_H_

View File

@@ -0,0 +1,521 @@
/*
* Copyright (c) 2017, 2021 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Changes from Qualcomm Innovation Center are provided under the following license:
*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the
* disclaimer below) provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _MSM_GBM_H_
#define _MSM_GBM_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <display/drm/sde_drm.h>
//Enables debug log
#ifdef GBM_DEBUG
#define GBM_DBG_LOG fprintf
#else
#define GBM_DBG_LOG(...) {}
#endif
#define LOG_FATAL (1)
#define LOG_ERR (2)
#define LOG_WARN (3)
#define LOG_INFO (4)
#define LOG_DBG (5)
extern int g_debug_level;
#define LOG(level, ...) do { \
if (level <= g_debug_level) { \
if(level==LOG_FATAL) \
fprintf(stderr,"%s","GBM_FATAL::"); \
if(level==LOG_ERR) \
fprintf(stderr,"%s", "GBM_ERR::"); \
if(level==LOG_WARN) \
fprintf(stderr,"%s", "GBM_WARN::"); \
if(level==LOG_INFO) \
fprintf(stderr,"%s", "GBM_INFO::"); \
if(level==LOG_DBG) \
fprintf(stderr,"%s", "GBM_DBG::"); \
fprintf(stderr,"%s(%d)::",__func__,__LINE__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
fflush(stderr); \
} \
} while (0)
/*Currently three buffer mechanism is used for GPU rendering and Hardware Composition sync*/
#ifdef ALLOCATE_SURFACE_BO_AT_CREATION
#define NUM_BACK_BUFFERS 3
#else
#define NUM_BACK_BUFFERS 2
#endif
#define MAX_NUM_PLANES 3
#define QCMAGIC 0XDFDFECBA // need to compe up with something unique
/**
* State representation of the gbm buffer object
*
*/
#define GBM_BO_STATE_FREE (0x0) /* Unused/Free state of the Buffer Object */
#define GBM_BO_STATE_INUSE_BY_COMPOSITOR (0x1) /* Buffer Object locked for composition */
#define GBM_BO_STATE_INUSE_BY_GPU (0x2) /* Buffer Object locked for GPU rendering */
#define GBM_BO_STATE_NEW_FRONT_BUFFER (0x3) /* Buffer Object currently available for
* grab by GPU or Compositor */
/**
* State representation of the gbm buffer object during
* gbm surface creation if enabled
*
*/
#ifndef ALLOCATE_SURFACE_BO_AT_CREATION
#define SURFACE_BOSLOT_STATE_FREE (0x0) /* Unused/Free state of the Buffer Object */
#define SURFACE_BOSLOT_STATE_INUSE_BY_COMPOSITOR (0x1) /* BO locked for composition */
#define SURFACE_BOSLOT_STATE_HAS_NEW_FRONT_BUFFER (0x2) /* BO currently available for
* grab by GPU or Compositor */
#endif
/**
* msm gbm device object corresponding to the gbm device object instance
*
* The members in this structure should not be accessed directly.
*/
struct msmgbm_device {
struct gbm_device base;
uint32_t magic;
int fd; /* device fd */
int iondev_fd; /* ION device fd */
};
struct msmgbm_surface {
struct gbm_surface base;
uint32_t magic;
struct msmgbm_device* device;
struct msmgbm_bo *bo[NUM_BACK_BUFFERS];
int inuse_index;
#ifndef ALLOCATE_SURFACE_BO_AT_CREATION
int bo_slot[NUM_BACK_BUFFERS];
#endif
};
/**
* The allocated local msm buffer object for the corresponding gbm buffer object.
*
* The members in this structure should not be accessed directly.
*/
struct msmgbm_bo {
struct gbm_bo base;
uint32_t magic;
struct msmgbm_device* device;
uint32_t name;
uint64_t gpuaddr;
void* cpuaddr;
void* mt_cpuaddr;
size_t size;
size_t mt_size;
uint32_t current_state;
uint32_t fbid;
int ion_handle;
int ion_mt_handle;
int import_flg;
};
/**
* Buffer Descriptor used for param passing between API's
*
*/
struct gbm_bufdesc {
uint32_t Width;
uint32_t Height;
uint32_t Format;
uint32_t Usage;
};
struct gbm_buf_resource {
struct gbm_buf_info *buffer_info;
uint32_t magic;
};
/**
* The gbm buffer data object related
* information stored in hashmap
*/
struct msmgbm_private_info {
void* cpuaddr; /* gbm bo cpu address */
void* mt_cpuaddr; /* gbm bo meta data address */
};
/*
* Function prototypes of all supported API's by backend
*
*/
/** create the gbm bo
*
* \param handle to gbm device
* \param width
* \param height
* \param format
* \param usage flag
* \return gbm bo handle
*
*/
static struct gbm_bo *msmgbm_bo_create(struct gbm_device *gbm,uint32_t width,
uint32_t height,uint32_t format,
uint32_t usage, const uint64_t *modifiers,
const unsigned int count);
/** Destroy the gbm bo
*
* \param bo The buffer object
* \return None
*
*/
static void msmgbm_bo_destroy(struct gbm_bo *bo);
/** To query gbm device pointer
*
* \param bo The buffer object
* \return gbm device handle
*
*/
static struct gbm_device* msmgbm_bo_get_device(struct gbm_bo *bo);
/** query gbm bo name
*
* \param gbm bo handle
* \return id
*
*/
int msmgbm_bo_get_name(struct gbm_bo* bo);
/** Perform write operation onto the gbm bo
*
* \param bo The buffer object
* \param user buffer handle
* \param byte count
* \return =0 for success
* >0 for fail
*
*/
static int msmgbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count);
/** create the gbm bo
*
* \param import gbm bo handle depending on type
* \param gbm device
* \param type
* \param void pointer
* \param usage flag
* \return gbm bo handle
*
*/
struct gbm_bo * msmgbm_bo_import(struct gbm_device *gbm,uint32_t type,
void *buffer, uint32_t usage);
/** Import gbm bo handle from fd
*
* \param handle to msmgbm_device
* \param fd via void *
* \param usage flags
* \return gbm bo handle
*
*/
struct gbm_bo * msmgbm_bo_import_fd(struct msmgbm_device *msm_dev,
void *buffer, uint32_t usage);
/** Import gbm bo handle from name element of the wl buffer resource
*
* \param msmgbm_device handle
* \param wl buffer handle
* \param usage flag
* \return gbm bo handle
*
*/
struct gbm_bo * msmgbm_bo_import_wl_buffer(struct msmgbm_device *msm_dev,
void *buffer, uint32_t usage);
/** create the gbm bo
*
* \param msmgbm_device handle
* \param egl buffer handle
* \param usage flag
* \return gbm bo handle
*
*/
struct gbm_bo * msmgbm_bo_import_egl_image(struct msmgbm_device *msm_dev,
void *buffer, uint32_t usage);
/** create requested gbm surface with the dimensions
*
* \param gbm device handle
* \param width
* \param height
* \param format
* \param usage flag
* \return gbm surface
*
*/
static struct gbm_surface *
msmgbm_surface_create(struct gbm_device *gbm, uint32_t width,
uint32_t height, uint32_t format, uint32_t flags,
uint64_t *modifiers, unsigned int count);
/** destroy gbm surface
*
* \param handle to gbm surface
* \return None
*
*/
static void msmgbm_surface_destroy(struct gbm_surface *surf);
/** Verifies if surface is allocated by MSM GBM backend
*
* \Returns GBM_ERROR values
*
*/
static inline
int msmgbm_validate_surface(struct gbm_surface *surf);
/** update the state of the current bo associated with the surface to used by compositor
*
* \param surface handle
* \return gbm bo handle
*
*/
static struct gbm_bo * msmgbm_surface_lock_front_buffer(struct gbm_surface *surf);
/** update the state of the current bo associated with the surface to free
*
* \param surface handle
* \return gbm bo handle
*
*/
static void msmgbm_surface_release_buffer(struct gbm_surface *surf,
struct gbm_bo *bo);
/* Returns bo which can be used as front buffer on success
* \Returns GBM_ERROR values
*
*/
struct gbm_bo* msmgbm_surface_get_free_bo(struct gbm_surface *surf);
/** update the state machine of a bo to be used as the surface front buffer
* \Returns GBM_ERROR values
*
*/
int msmgbm_surface_set_front_bo(struct gbm_surface *surf, struct gbm_bo *gbo);
/** Returns the CPU address of metadata
* if fails returns NULL
*/
void* msmgbm_cpu_map_metafd(int meta_ion_fd, unsigned int metadata_size);
/** Returns the cpu address of non secure bo
* if mmap fails or buffer is secure, returns NULL
*/
void* msmgbm_cpu_map_ionfd(int ion_fd, unsigned int size, struct meta_data_t *meta_data);
/** Returns the CPU access address for the BO buffer
* \Returns CPU address on Success / Null on fail
*
*/
void * msmgbm_bo_cpu_map(struct gbm_bo *gbo);
/* Unmap the BO buffer from CPU access
* \Returns GBM_ERROR values
*
*/
int msmgbm_bo_cpu_unmap(struct gbm_bo *gbo);
/* Returns BO size on success
* \Returns size on Success/ GBM_ERROR Values on Failure
*
*/
static inline
size_t msmgbm_bo_get_size(struct gbm_bo *bo);
/** create gbm device
*
* \param display driver device fd
* \return gbm device handle
*
*/
static struct gbm_device * msmgbm_device_create(int fd);
/** destroy the gbm device handle
*
* \param gbm device handle
* \return none
*
*/
static void msmgbm_device_destroy(struct gbm_device *gbm);
/** To query gbm device fd
*
* \param bo The buffer object
* \return fd
*
*/
static int msmgbm_device_get_fd(struct gbm_bo *bo);
/** query device unique id
*
* \param handle to gbm device
* \return ID
*
*/
unsigned int msmgbm_device_get_magic(struct gbm_device *dev);
/** query drm device file name
*
* \return gbm bo handle
*
*/
static inline
const char* msmgbm_drm_device_get_name(void);
/** Authenticate the DRM magic ID
*
* \Returns 0 on success
* \Returns -1 on failure
*
*/
int msmgbm_device_authenticate_magic(struct gbm_device *dev,
uint32_t magic);
/** Import a BO handle from a unique ID/name
*
* \Returns imported BO pointer on success
* \Returns NULL on failure
*
*/
struct gbm_bo* msmgbm_bo_import_from_name(struct gbm_device *dev,
unsigned int name);
/** Returns global name on success
*
* \Returns GBM_ERROR values on failure
*
*/
int msmgbm_bo_get_name(struct gbm_bo* bo);
/** Verifies if device is allocated by MSM GBM backend
*
* \Returns GBM_ERROR values
*
*/
static inline
int msmgbm_validate_device(struct gbm_device *dev);
/** Query metadata info depending on the operation/paramtype
*
* \Returns GBM_ERROR values
*
*/
int msmgbm_get_metadata(struct gbm_bo *gbo, int paramType,void *param);
/** Set metadata info depending on the operation/paramtype
*
* \Returns GBM_ERROR values
*
*/
int msmgbm_set_metadata(struct gbm_bo *gbo, int paramType,void *param);
/** Get RGB Data Address for a given gbm buffer object
*
* \Returns GBM_ERROR values
*
*/
int msmgbm_get_rgb_data_address(struct gbm_bo *gbo, void **rgb_data);
/**
* C wrapper function to increment the reference count for the valid gem_handle
* @input param: device fd
* @input param: gem handle
* @return : none
*
*/
void incr_handle_refcnt(int device_fd, uint32_t handle);
/**
* C wrapper function to decrement the reference count for the valid map gem_handle
* @input param: device fd
* @input param: gem handle
* @return : 1 for delete key from map /0 for decremented ref count
*
*/
int decr_handle_refcnt(int device_fd, uint32_t handle);
#ifdef __cplusplus
}
#endif
#endif //_MSM_GBM_H_

View File

@@ -0,0 +1,151 @@
/*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
* Not a Contribution.
*
* Copyright (c) 2017-2018, 2021 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __MSMGBM_ADRENO_UTILS_H__
#define __MSMGBM_ADRENO_UTILS_H__
namespace msm_gbm {
// Adreno Pixel Formats
typedef enum {
ADRENO_PIXELFORMAT_UNKNOWN = 0,
ADRENO_PIXELFORMAT_R32G32B32A32_FLOAT = 2,
ADRENO_PIXELFORMAT_R32G32B32_FLOAT = 6,
ADRENO_PIXELFORMAT_R16G16B16A16_FLOAT = 10,
ADRENO_PIXELFORMAT_R10G10B10A2_UNORM = 24, // Vertex, Normalized GL_UNSIGNED_INT_10_10_10_2_OES
ADRENO_PIXELFORMAT_R8G8B8A8 = 28,
ADRENO_PIXELFORMAT_R8G8B8A8_SRGB = 29,
ADRENO_PIXELFORMAT_R16G16_UNORM = 35,
ADRENO_PIXELFORMAT_R8G8_UNORM = 49,
ADRENO_PIXELFORMAT_R16_UNORM = 56,
ADRENO_PIXELFORMAT_R8_UNORM = 61,
ADRENO_PIXELFORMAT_B5G6R5 = 85,
ADRENO_PIXELFORMAT_B5G5R5A1 = 86,
ADRENO_PIXELFORMAT_B8G8R8A8 = 90,
ADRENO_PIXELFORMAT_B8G8R8A8_SRGB = 91,
ADRENO_PIXELFORMAT_B8G8R8X8_SRGB = 93,
ADRENO_PIXELFORMAT_NV12 = 103,
ADRENO_PIXELFORMAT_P010 = 104,
ADRENO_PIXELFORMAT_YUY2 = 107,
ADRENO_PIXELFORMAT_B4G4R4A4 = 115,
ADRENO_PIXELFORMAT_NV12_EXT = 506, // NV12 with non-std alignment and offsets
ADRENO_PIXELFORMAT_R8G8B8X8 = 507, // GL_RGB8 (Internal)
ADRENO_PIXELFORMAT_R8G8B8 = 508, // GL_RGB8
ADRENO_PIXELFORMAT_A1B5G5R5 = 519, // GL_RGB5_A1
ADRENO_PIXELFORMAT_R8G8B8X8_SRGB = 520, // GL_SRGB8
ADRENO_PIXELFORMAT_R8G8B8_SRGB = 521, // GL_SRGB8
ADRENO_PIXELFORMAT_R16G16B16_FLOAT = 523,
ADRENO_PIXELFORMAT_R5G6B5 = 610, // RGBA version of B5G6R5
ADRENO_PIXELFORMAT_R5G5B5A1 = 611, // RGBA version of B5G5R5A1
ADRENO_PIXELFORMAT_R4G4B4A4 = 612, // RGBA version of B4G4R4A4
ADRENO_PIXELFORMAT_UYVY = 614, // YUV 4:2:2 packed progressive (1 plane)
ADRENO_PIXELFORMAT_NV21 = 619,
ADRENO_PIXELFORMAT_Y8U8V8A8 = 620, // YUV 4:4:4 packed (1 plane)
ADRENO_PIXELFORMAT_Y8 = 625, // Single 8-bit luma only channel YUV format
ADRENO_PIXELFORMAT_TP10 = 654, // YUV 4:2:0 planar 10 bits/comp (2 planes)
} ADRENOPIXELFORMAT;
class adreno_mem_info {
public:
bool init();
adreno_mem_info();
~adreno_mem_info();
/**
* Function to compute the adreno aligned width and aligned height
* based on the width and format.
*
* @return aligned width, aligned height
*/
void get_aligned_wdth_hght_uncmprsd_rgb_fmt(int width, int height, int format, int tileEnabled,
unsigned int *aligned_w, unsigned int *aligned_h);
/**
* Function to compute the adreno aligned width and aligned height
* based on the width and format.
*
* @return aligned width, aligned height
*/
void get_aligned_wdth_hght_cmprsd_rgb_fmt(int width, int height, int format, unsigned int *aligned_w,
unsigned int *aligned_h);
/**
* Function to compute the pixel alignment requirement.
*
* @return alignment
*/
unsigned int get_gpu_pxl_align();
/**
* Function to return whether GPU support MacroTile feature
*
* @return >0 : supported
* 0 : not supported
*/
bool is_mcro_tiling_supported();
/**
* Function to query whether GPU supports UBWC for given GBM format
* @return > 0 : supported
* 0 : not supported
*/
bool is_ubwc_supported_gpu(unsigned int gbm_format);
/**
* Function to get the corresponding Adreno format for given GBM format
*/
ADRENOPIXELFORMAT get_gpu_pxl_fmt(unsigned int gbm_format);
private:
// link(s)to adreno surface padding library.
int (*LINK_adreno_compute_padding)(int width, int bpp, int surface_tile_height,
int screen_tile_height, int padding_threshold) = NULL;
void (*LINK_adreno_compute_fmt_aligned_width_and_height)(int width, int height, int plane_id,
ADRENOPIXELFORMAT format, int num_samples,
int tile_mode, int raster_mode,
int padding_threshold, int *aligned_w,
int *aligned_h) = NULL;
int (*LINK_adreno_is_mcro_tile_supportd_gpu)(void) = NULL;
void (*LINK_adreno_compute_compressedfmt_aligned_width_and_height)(
int width, int height, int format, int tile_mode, int raster_mode, int padding_threshold,
int *aligned_w, int *aligned_h, int *bpp) = NULL;
int (*LINK_adreno_is_ubwc_supportd_gpu)(ADRENOPIXELFORMAT format) = NULL;
unsigned int (*LINK_adreno_get_gpu_pixel_alignment)() = NULL;
bool gfx_ubwc_disable_ = false;
bool map_fb_ = false;
void *libadreno_utils_ = NULL;
};
} // namespace msm_gbm
#endif // __MSMGBM_ADRENO_UTILS_H__

View File

@@ -0,0 +1,59 @@
/*
* Copyright (c) 2018, 2021 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MSMGBM_COMMON_H_
#define MSMGBM_COMMON_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
bool IsImplDefinedFormat(uint32_t format);
uint32_t GetImplDefinedFormat(uint32_t usage_flags, uint32_t format);
uint32_t GetIonAllocFlags(uint32_t alloc_flags);
uint32_t GetIonHeapId(uint32_t alloc_flags);
/*camera specific functions*/
uint32_t GetCameraImplDefinedFormat(uint32_t usage_flags, uint32_t format);
uint32_t GetCameraIonAllocFlags(uint32_t alloc_flags);
uint32_t GetCameraIonHeapId(uint32_t alloc_flags);
/*video specific functions*/
uint32_t GetVideoImplDefinedFormat(uint32_t usage_flags, uint32_t format);
uint32_t GetVideoIonAllocFlags(uint32_t alloc_flags);
uint32_t GetVideoIonHeapId(uint32_t alloc_flags);
#ifdef __cplusplus
}
#endif
#endif //MSMGBM_COMMON_H_

View File

@@ -0,0 +1,119 @@
/*
* Copyright (c) 2017, 2021 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __MSMGBM_MAPPER_H__
#define __MSMGBM_MAPPER_H__
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <memory>
#include <cstdio>
#include <pthread.h>
#include "gbm_priv.h"
#include "msmgbm.h"
namespace msm_gbm {
class msmgbm_mapper {
public:
msmgbm_mapper();
~msmgbm_mapper();
bool init();
//Structure definition to maintain hash table on a per process basis
//to manage metadata.
struct msmgbm_buffer {
int ion_fd;
int ion_metadata_fd;
uint32_t width;
uint32_t height;
uint32_t format;
int ref_count=0;
void *cpuaddr = NULL;
void *mt_cpuaddr = NULL;
explicit msmgbm_buffer(int fd, int mtadta_fd, uint32_t wdth, uint32_t hght, uint32_t fmt,
void *cpu_addr, void *mt_cpu_addr):
ion_fd(fd),
ion_metadata_fd(mtadta_fd),
width(wdth),
height(hght),
format(fmt),
cpuaddr(cpu_addr),
mt_cpuaddr(mt_cpu_addr) {
}
void IncRef() {++ref_count;}
int DecRef() {return --ref_count == 0;}
};
std::unordered_map<int, std::shared_ptr<msmgbm_buffer>>gbm_buf_map_;
struct gem_handle_key {
int device_fd;
uint32_t handle;
gem_handle_key(int device_fd, uint32_t handle) : device_fd(device_fd), handle(handle){}
};
struct HashFunc {
std::size_t operator()(const gem_handle_key &key) const
{
using std::size_t;
using std::hash;
return ((hash<int>()(key.device_fd)
^ (hash<uint32_t>()(key.handle) << 1)) >> 1);
}
};
struct EqualKey {
bool operator () (const gem_handle_key &key1, const gem_handle_key &key2) const
{
return key1.device_fd == key2.device_fd && key1.handle == key2.handle;
}
};
std::unordered_map<gem_handle_key, int, HashFunc, EqualKey>gem_object_map_;
void register_to_map(int ion_fd, struct gbm_buf_info * gbm_buf,
struct msmgbm_private_info * gbo_private_info);
int search_map(int ion_fd, struct gbm_buf_info * gbm_buf,
struct msmgbm_private_info * gbo_private_info);
int update_map(int ion_fd, struct gbm_buf_info * gbm_buf,
struct msmgbm_private_info * gbo_private_info);
void map_dump(void);
void add_map_entry(int ion_fd);
int del_map_entry(int ion_fd);
void incr_handle_refcnt(int device_fd, uint32_t handle);
int decr_handle_refcnt(int device_fd, uint32_t handle);
};
} // namespace msm_gbm
#endif // __MSMGBM_MAPPER_H__

View File

@@ -0,0 +1,360 @@
/*
* Copyright (c) 2017, 2021 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Changes from Qualcomm Innovation Center are provided under the following license:
*
* Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the
* disclaimer below) provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __MSMGBM_PFM_WRP_H__
#define __MSMGBM_PFM_WRP_H__
#include "msmgbm_adreno_utils.h"
#include "gbm_priv.h"
#include "msmgbm.h"
#include <linux/version.h>
#ifdef VENUS_COLOR_FORMAT
#include <display/media/mmm_color_fmt.h>
#else
#define VENUS_Y_STRIDE(args...) 0
#define VENUS_Y_SCANLINES(args...) 0
#define VENUS_BUFFER_SIZE(args...) 0
#endif
namespace msm_gbm {
/**
* Function to query if CPU access usage flags are set
* @return : true/false
*
*/
bool cpu_can_accss(int prod_usage, int cons_usage);
/**
* Helper function to query if CPU access usage flags are set
* @return : true/false
*
*/
bool cpu_can_rd(int prod_usage, int cons_usage);
/**
* Helper function to query if CPU access usage flags are set
* @return : true/false
*
*/
bool cpu_can_wr(int prod_usage);
/**
* Function to query bpp depending on format
* @return : bpp value
*
*/
uint32_t get_bpp_for_uncmprsd_rgb_fmt(int format) ;
class platform_wrap {
public:
platform_wrap();
~platform_wrap();
/**
* Function to Initialize the platform wrapper object
* @return true/
* false
*/
bool init(void);
/**
* Function to query UBWC support
* @return true/
* false
*/
bool is_ubwc_enbld(int format, int prod_usage, int cons_usage);
/**
* Function to query MacroTile support
* @return true/
* false
*/
bool is_mcro_tile_enbld(int format, int prod_usage, int cons_usage);
/**
* Function to query the UBWC Enabled Buffer Size
* @return size on success
* 0 on fail
*/
unsigned int get_ubwc_size(int width, int height, int format, unsigned int alignedw, unsigned int alignedh);
/**
* Helper Function to query the UBWC Enabled Buffer Size
* @return size on success
* 0 : fail
*/
unsigned int get_rgb_ubwc_mb_size(int width, int height, uint32_t bpp);
/**
* Helper Function to query the UBWC Enabled Buffer Size
* @return block width and height
*/
void get_rgb_ubwc_blk_size(uint32_t bpp, int *block_width, int *block_height);
/**
* Function to query the RGB format support
* @return true : success
* false : fail
*/
int is_valid_rgb_fmt(int gbm_format);
/**
* Function to check whether the format is RAW
* @params gbm format
* @return true : success
* false : fail
*
*/
bool is_valid_raw_fmt(int format);
uint32_t get_bpp_for_uncmprsd_rgb_fmt(int format);
/**
* Function to check whether the format is uncompressed RGB
* @params gbm format
* @return boolean 0 (compressed RGB format)
* 1 (uncompressed RGB format)
*
*/
bool is_valid_uncmprsd_rgb_fmt(int format);
/**
* Function to check whether the format is uncompressed RGB
* @params gbm format
* @return boolean 0 (uncompressed RGB format)
* 1 (compressed RGB format)
*
*/
bool is_valid_cmprsd_rgb_fmt(int format);
/**
* Function to check whether the format is yuv format
* @params gbm format
* @return true : success
* false : fail
*
*/
bool is_valid_yuv_fmt(int format);
/**
* Function to query UBWC feature support
* @return true : success
* false : fail
*/
bool is_ubwc_support_enbld(int format);
/**
* Function to query UBWC enabled format support
* @return true : success
* false : fail
*/
bool is_valid_ubwc_fmt(int format);
/**
* Function to get aligned width and height depending on the underlying GPU/Video platform
* @return aligned_w
* aligned_h
*/
void get_aligned_wdth_hght(gbm_bufdesc *descriptor, unsigned int *aligned_w,
unsigned int *aligned_h);
/**
* Function to get stride, scanline and size depending on the underlying GPU/Video platform
* @return stride
* scanline
* size
*/
void get_stride_scanline_size(gbm_bufdesc *descriptor, unsigned int *stride,
unsigned int *scanline, unsigned int *size);
/**
* Function to get size aligned width and height depending on the underlying GPU/Video platform
* @params gbm format
* width of the buffer
* height of the buffer
* usage flags
* aligned height
* aligned weight
* @return size of the buffer
*/
unsigned int get_size(int format, int width, int height, int usage,
int alignedw, int alignedh);
/**
* Function to get aligned width and height for YUV format
* @params gbm format
* width of the buffer
* height of the buffer
* @return aligned height
* aligned weight
*
*/
void get_yuv_ubwc_wdth_hght(int width, int height, int format,
unsigned int *aligned_w, unsigned int *aligned_h);
private:
bool gpu_support_macrotile = false;
bool display_support_macrotile = false;
adreno_mem_info *adreno_helper_ = NULL;
};
extern "C" {
/**
* C wrapper Function to get aligned width and height depending on the underlying GPU/Video platform
* @return aligned_w
* aligned_h
*/
void qry_aligned_wdth_hght(gbm_bufdesc *descriptor, unsigned int *alignedw, unsigned int *alignedh);
/**
* C wrapper Function to get stride, scanline and size depending on the underlying GPU/Video platform
* @return stride
* scanline
* size
*/
void qry_stride_scanline_size(gbm_bufdesc *descriptor, unsigned int *stride,
unsigned int *scanline, unsigned int *size);
/**
* C wrapper Function to query size based on format from the platform wrapper
* @return : size
*
*/
unsigned int qry_size(gbm_bufdesc *desc, unsigned int alignedw, unsigned int alignedh);
/**
* C wrapper Function to check whether the format is UBWC or not.
* @params gbm format
* @return boolean 0 (non UBWC format)
* 1 (UBWC format)
*/
bool is_valid_ubwc_format(int format);
/**
* Function to return bytes per pixel for a given uncompressed RGB format
* @params uncompressed RGB gbm format
* @return bytes per pixel
*
*/
uint32_t get_bpp_for_uncmprsd_rgb_format(int format);
/**
* Function to return bytes needed to represent UBWC RGB Metabuffer
* @params RGB gbm format
* @return size of UBWC RGB meta buffer
*
*/
uint32_t get_rgb_ubwc_metabuffer_size(int width, int height, int bpp);
/**
* C wrapper Function to check whether the format is uncompressed RGB format or not.
* @params gbm format
* @return boolean 0 (compressed RGB format)
* 1 (uncompressed RGB format)
*/
bool is_valid_uncmprsd_rgb_format(int format);
/**
* C wrapper Function to check whether the format is uncompressed RGB format or not.
* @params gbm format
* @return boolean 0 (uncompressed RGB format)
* 1 (compressed RGB format)
*/
bool is_valid_cmprsd_rgb_format(int format);
/**
* C wrapper Function to check whether the format is yuv format or not.
* @params gbm format
* @return boolean 0 (non yuv format)
* 1 (yuv format)
*/
bool is_valid_yuv_format(int format);
/**
* C wrapper function to know if the format is UBWC
*/
bool is_ubwc_enbld(int format, int prod_usage,
int cons_usage);
/**
* C wrapper Function to check whether the format is RAW format or not.
* @params gbm format
* @return boolean 0 (non RAW format)
* 1 (RAW format)
*/
bool is_valid_raw_format(int format);
/**
* C wrapper function to know if the format is RGB
*/
bool is_valid_rgb_fmt(int format);
/**
* C wrapper Function to delete platform wrapper object
* @return : None
*
*/
void platform_wrap_deinstnce(void);
/**
* C wrapper Function to create a cpp object of platform wrapper class
* @return 0 : success
* 1 : failure
*/
bool platform_wrap_instnce(void);
}
} // namespace msm_gbm
#endif // __MSMGBM_PFM_WRP_H__

View File

@@ -0,0 +1,791 @@
/*
* Copyright (c) 2017, 2021 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright © 2011 Intel Corporation
*
* 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, sublicense,
* 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
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS 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.
*
* Authors:
* Benjamin Franzke <benjaminfranzke@googlemail.com>
*
* Changes from Qualcomm Innovation Center are provided under the following license:
*
* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#include <stdio.h>
#include <stdint.h>
#include <gbm.h>
#include <gbm_priv.h>
#include <errno.h>
/** Returns the file description for the gbm device
*
* \return The fd that the struct gbm_device was created with
*/
int
gbm_device_get_fd(struct gbm_device *gbm_dev)
{
if(gbm_dev!=NULL){
return gbm_dev->fd;
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid device pointer\n",__func__,__LINE__);
return -1;
}
}
/** Get the backend name for the given gbm device
*
* \return The backend name string - this belongs to the device and must not
* be freed
*/
const char *
gbm_device_get_backend_name(struct gbm_device *gbm_dev)
{
if(gbm_dev!=NULL){
return gbm_dev->name;
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid device pointer\n",__func__,__LINE__);
return NULL;
}
}
/** Test if a format is supported for a given set of usage flags.
*
* \param gbm The created buffer manager
* \param format The format to test
* \param usage A bitmask of the usages to test the format against
* \return 1 if the format is supported otherwise 0
*
* \sa enum gbm_bo_flags for the list of flags that the format can be
* tested against
*
* \sa enum gbm_bo_format for the list of formats
*/
int
gbm_device_is_format_supported(struct gbm_device *gbm_dev,
unsigned int format, unsigned int usage)
{
if(gbm_dev!=NULL){
return gbm_dev->is_format_supported(gbm_dev, format,usage);
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid device pointer\n",__func__,__LINE__);
return -1;
}
}
int
gbm_device_get_format_modifier_plane_count(struct gbm_device *gbm,
uint32_t format,
uint64_t modifier)
{
return gbm->get_format_modifier_plane_count(format, modifier);
}
/** Destroy the gbm device and free all resources associated with it.
*
* \param gbm The device created using gbm_create_device()
*/
void
gbm_device_destroy(struct gbm_device *gbm_dev)
{
if(gbm_dev!=NULL)
{
gbm_dev->refcount--;
if (gbm_dev->refcount == 0) {
return gbm_dev->destroy(gbm_dev);
}
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid device pointer\n",__func__,__LINE__);
return ;
}
}
/** Create a gbm device for allocating buffers
*
* The file descriptor passed in is used by the backend to communicate with
* platform for allocating the memory. For allocations using DRI this would be
* the file descriptor returned when opening a device such as \c
* /dev/dri/card0
*
* \param fd The file descriptor for an backend specific device
* \return The newly created struct gbm_device. The resources associated with
* the device should be freed with gbm_device_destroy() when it is no longer
* needed. If the creation of the device failed NULL will be returned.
*/
struct gbm_device *
gbm_create_device(int fd)
{
struct gbm_backendpriv *backend =NULL;
struct gbm_device *gbm_dev =NULL;
backend = gbm_get_priv();
if(backend == NULL) {
fprintf(stderr,"%s(%d): No backend found, Device creation failed\n",__func__,__LINE__);
return NULL;
}
if(fd <= 0){
fprintf(stderr,"%s(%d): Inavid file descriptor (%d)\n",__func__,__LINE__,fd);
}
gbm_dev = backend->create_device(fd);
if(gbm_dev == NULL)
{
fprintf(stderr,"%s(%d): Device creation failed\n",__func__,__LINE__);
return NULL;
}
gbm_dev->refcount = 1;
gbm_dev->fd = fd;
if(backend->backend_name != NULL){
gbm_dev->name = backend->backend_name;
fprintf(stderr,"%s(%d): Info: backend name is: %s\n",__func__,__LINE__,gbm_dev->name);
}
else
{
gbm_dev->name = NULL;
fprintf(stderr,"%s(%d): Info: backend name is null\n",__func__,__LINE__);
}
return gbm_dev;
}
/** Get the width of the buffer object
*
* \param bo The buffer object
* \return The width of the allocated buffer object
*
*/
unsigned int
gbm_bo_get_width(struct gbm_bo *bo)
{
if(bo!=NULL){
return bo->width;
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
return 0;
}
}
/** Get the height of the buffer object
*
* \param bo The buffer object
* \return The height of the allocated buffer object
*/
unsigned int
gbm_bo_get_height(struct gbm_bo *bo)
{
if(bo!=NULL){
return bo->height;
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
return 0;
}
}
/** Get the stride of the buffer object
*
* This is calculated by the backend when it does the allocation in
* gbm_bo_create()
*
* \param bo The buffer object
* \return The stride of the allocated buffer object in bytes
*/
unsigned int
gbm_bo_get_stride(struct gbm_bo *bo)
{
if(bo!=NULL){
if(bo->usage_flags & GBM_BO_USAGE_UBWC_ALIGNED_QTI){
return bo->stride_for_plane(1, bo);
} else {
return bo->stride_for_plane(0, bo);
}
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
return 0;
}
}
/** Get the stride for the given plane
*
* \param bo The buffer object
* \param plane for which you want the stride
*
* \sa gbm_bo_get_stride()
*/
uint32_t
gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane)
{
if (!bo){
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
return 0;
}
if (plane >= MAX_NUM_OF_PLANES) {
fprintf(stderr,"%s(%d): invalid plane \n",__func__,__LINE__);
return 0;
}
return bo->stride_for_plane(plane, bo);
}
/** Get the format of the buffer object
*
* The format of the pixels in the buffer.
*
* \param bo The buffer object
* \return The format of buffer object, on of the GBM_FORMAT_* codes
*/
unsigned int
gbm_bo_get_format(struct gbm_bo *bo)
{
if(bo!=NULL){
return bo->format;
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
return 0;
}
}
uint32_t
gbm_bo_get_bpp(struct gbm_bo *bo)
{
if(bo!=NULL){
return bo->bpp;
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
return 0;
}
}
uint32_t
gbm_bo_get_offset(struct gbm_bo *bo, int plane)
{
if(bo!=NULL){
if (plane <= MAX_NUM_OF_PLANES-1) {
return bo->buf_lyt.planes[plane].offset;
} else {
fprintf(stderr,"%s(%d): invalid plane \n",__func__,__LINE__);
return 0;
}
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
return 0;
}
}
/** Get the handle of the buffer object
*
* This is stored in the platform generic union gbm_bo_handle type. However
* the format of this handle is platform specific.
*
* \param bo The buffer object
* \return Returns the handle of the allocated buffer object
*/
union gbm_bo_handle
gbm_bo_get_handle(struct gbm_bo *bo)
{
return bo->handle;
}
/** Returns the file description of the buffer object
*
* \param bo The buffer object
* \return Returns a file descriptor referring to the underlying buffer
*/
int
gbm_bo_get_fd(struct gbm_bo *bo)
{
if(bo!=NULL){
return bo->bo_get_fd(bo);
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
return 0;
}
}
uint64_t
gbm_bo_get_modifier(struct gbm_bo *bo)
{
if(bo!=NULL){
return bo->modifier;
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
return 0;
}
}
int
gbm_bo_get_plane_count(struct gbm_bo *bo)
{
if(bo!=NULL){
return (int)(bo->plane_count);
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
return 0;
}
}
union gbm_bo_handle
gbm_bo_get_handle_for_plane(struct gbm_bo *bo, int plane)
{
union gbm_bo_handle handle;
if(bo!=NULL){
if (plane <= MAX_NUM_OF_PLANES) {
return handle;
} else {
return (handle);
}
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
return handle;
}
}
/** Write data into the buffer object
*
* If the buffer object was created with the GBM_BO_USE_WRITE flag,
* this function can used to write data into the buffer object. The
* data is copied directly into the object and it's the responsiblity
* of the caller to make sure the data represents valid pixel data,
* according to the width, height, stride and format of the buffer object.
*
* \param bo The buffer object
* \param buf The data to write
* \param count The number of bytes to write
* \return Returns -1 on error, 0 otherwise
*/
int
gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count)
{
if(bo!=NULL){
return bo->bo_write(bo,buf,count);
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
return 0;
}
}
/** Get the gbm device used to create the buffer object
*
* \param bo The buffer object
* \return Returns the gbm device with which the buffer object was created
*/
struct gbm_device *
gbm_bo_get_device(struct gbm_bo *bo)
{
if(bo!=NULL){
return bo->bo_get_device(bo);
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
return 0;
}
}
/** Set the user data associated with a buffer object
*
* \param bo The buffer object
* \param data The data to associate to the buffer object
* \param destroy_user_data A callback (which may be %NULL) that will be
* called prior to the buffer destruction
*/
void
gbm_bo_set_user_data(struct gbm_bo *bo, void *data,
void (*destroy_user_data)(struct gbm_bo *, void *))
{
if(bo!=NULL) {
bo->user_data = data;
bo->destroy_user_data = destroy_user_data;
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
}
return;
}
/** Get the user data associated with a buffer object
*
* \param bo The buffer object
* \return Returns the user data associated with the buffer object or %NULL
* if no data was associated with it
*
* \sa gbm_bo_set_user_data()
*/
void *
gbm_bo_get_user_data(struct gbm_bo *bo)
{
if(bo!=NULL){
return bo->user_data;
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
return NULL;
}
}
/**
* Destroys the given buffer object and frees all resources associated with
* it.
*
* \param bo The buffer object
*/
void
gbm_bo_destroy(struct gbm_bo *bo)
{
if(bo!=NULL){
if (bo->destroy_user_data) {
bo->destroy_user_data(bo, bo->user_data);
}
bo->bo_destroy(bo);
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid bo pointer\n",__func__,__LINE__);
}
return;
}
/**
* Allocate a buffer object for the given dimensions
*
* \param gbm The gbm device returned from gbm_create_device()
* \param width The width for the buffer
* \param height The height for the buffer
* \param format The format to use for the buffer
* \param usage The union of the usage flags for this buffer
*
* \return A newly allocated buffer that should be freed with gbm_bo_destroy()
* when no longer needed. If an error occurs during allocation %NULL will be
* returned.
*
* \sa enum gbm_bo_format for the list of formats
* \sa enum gbm_bo_flags for the list of usage flags
*/
struct gbm_bo *
gbm_bo_create(struct gbm_device *gbm_dev,
uint32_t width, uint32_t height,
uint32_t format, uint32_t usage)
{
if (width == 0 || height == 0){
errno = EINVAL;
fprintf(stderr,"%s(%d): width(%d) or height(%d) value\n",__func__,__LINE__,width,height);
return NULL;
}
if(gbm_dev!=NULL){
return gbm_dev->bo_create(gbm_dev,width,height,format,usage, NULL, 0);
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid device pointer\n",__func__,__LINE__);
return NULL;
}
}
struct gbm_bo *
gbm_bo_create_with_modifiers(struct gbm_device *gbm,
uint32_t width, uint32_t height,
uint32_t format,
const uint64_t *modifiers,
const unsigned int count)
{
if (width == 0 || height == 0) {
errno = EINVAL;
return NULL;
}
if ((count && !modifiers) || (modifiers && !count)) {
errno = EINVAL;
return NULL;
}
if(gbm!=NULL){
return gbm->bo_create(gbm,width,height,format, 0, modifiers, count);
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid device pointer\n",__func__,__LINE__);
return NULL;
}
}
/**
* Create a gbm buffer object from an foreign object
*
* This function imports a foreign object and creates a new gbm bo for it.
* This enabled using the foreign object with a display API such as KMS.
* Currently two types of foreign objects are supported, indicated by the type
* argument:
*
* GBM_BO_IMPORT_WL_BUFFER
* GBM_BO_IMPORT_EGL_IMAGE
*
* The the gbm bo shares the underlying pixels but its life-time is
* independent of the foreign object.
*
* \param gbm The gbm device returned from gbm_create_device()
* \param gbm The type of object we're importing
* \param gbm Pointer to the external object
* \param usage The union of the usage flags for this buffer
*
* \return A newly allocated buffer object that should be freed with
* gbm_bo_destroy() when no longer needed.
*
* \sa enum gbm_bo_flags for the list of usage flags
*/
struct gbm_bo *
gbm_bo_import(struct gbm_device *gbm_dev,
uint32_t type, void *buffer, uint32_t usage)
{
if(gbm_dev!=NULL){
return gbm_dev->bo_import(gbm_dev,type,buffer,usage);
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid device pointer\n",__func__,__LINE__);
return NULL;
}
}
void *
gbm_bo_map(struct gbm_bo *bo,
uint32_t x, uint32_t y, uint32_t width, uint32_t height,
uint32_t flags, uint32_t *stride, void **map_data){
bo->bo_map(x, y, width, height, flags, stride, map_data);
}
void
gbm_bo_unmap(struct gbm_bo *bo, void *map_data)
{
if(bo)
{
bo->bo_unmap(map_data);
}
}
/**
* Allocate a surface object
*
* \param gbm The gbm device returned from gbm_create_device()
* \param width The width for the surface
* \param height The height for the surface
* \param format The format to use for the surface
*
* \return A newly allocated surface that should be freed with
* gbm_surface_destroy() when no longer needed. If an error occurs
* during allocation %NULL will be returned.
*
* \sa enum gbm_bo_format for the list of formats
*/
struct gbm_surface *
gbm_surface_create(struct gbm_device *gbm_dev,
uint32_t width, uint32_t height,
uint32_t format, uint32_t flags)
{
if(gbm_dev!=NULL){
return gbm_dev->surface_create(gbm_dev,width,height,format,flags, NULL, 0);
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid device pointer\n",__func__,__LINE__);
return NULL;
}
}
struct gbm_surface *
gbm_surface_create_with_modifiers(struct gbm_device *gbm,
uint32_t width, uint32_t height,
uint32_t format,
const uint64_t *modifiers,
const unsigned int count)
{
if ((count && !modifiers) || (modifiers && !count)) {
errno = EINVAL;
return NULL;
}
return gbm->surface_create(gbm, width, height, format, 0,modifiers,count);
}
/**
* Destroys the given surface and frees all resources associated with
* it.
*
* All buffers locked with gbm_surface_lock_front_buffer() should be
* released prior to calling this function.
*
* \param surf The surface
*/
void
gbm_surface_destroy(struct gbm_surface *gbm_surf)
{
if(gbm_surf!=NULL){
gbm_surf->surface_destroy(gbm_surf);
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid surface pointer\n",__func__,__LINE__);
}
return;
}
/**
* Lock the surface's current front buffer
*
* Lock rendering to the surface's current front buffer until it is
* released with gbm_surface_release_buffer().
*
* This function must be called exactly once after calling
* eglSwapBuffers. Calling it before any eglSwapBuffer has happened
* on the surface or two or more times after eglSwapBuffers is an
* error. A new bo representing the new front buffer is returned. On
* multiple invocations, all the returned bos must be released in
* order to release the actual surface buffer.
*
* \param surf The surface
*
* \return A buffer object that should be released with
* gbm_surface_release_buffer() when no longer needed. The implementation
* is free to reuse buffers released with gbm_surface_release_buffer() so
* this bo should not be destroyed using gbm_bo_destroy(). If an error
* occurs this function returns %NULL.
*/
struct gbm_bo *
gbm_surface_lock_front_buffer(struct gbm_surface *gbm_surf)
{
if(gbm_surf!=NULL){
return gbm_surf->surface_lock_front_buffer(gbm_surf);
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid surface pointer\n",__func__,__LINE__);
return NULL;
}
}
/**
* Release a locked buffer obtained with gbm_surface_lock_front_buffer()
*
* Returns the underlying buffer to the gbm surface. Releasing a bo
* will typically make gbm_surface_has_free_buffer() return 1 and thus
* allow rendering the next frame, but not always. The implementation
* may choose to destroy the bo immediately or reuse it, in which case
* the user data associated with it is unchanged.
*
* \param surf The surface
* \param bo The buffer object
*/
void
gbm_surface_release_buffer(struct gbm_surface *gbm_surf, struct gbm_bo *bo)
{
if(gbm_surf != NULL && bo != NULL){
gbm_surf->surface_release_buffer(gbm_surf, bo);
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid surface pointer\n",__func__,__LINE__);
}
return;
}
/**
* Return whether or not a surface has free (non-locked) buffers
*
* Before starting a new frame, the surface must have a buffer
* available for rendering. Initially, a gbm surface will have a free
* buffer, but after one of more buffers have been locked (\sa
* gbm_surface_lock_front_buffer()), the application must check for a
* free buffer before rendering.
*
* If a surface doesn't have a free buffer, the application must
* return a buffer to the surface using gbm_surface_release_buffer()
* and after that, the application can query for free buffers again.
*
* \param surf The surface
* \return 1 if the surface has free buffers, 0 otherwise
*/
int
gbm_surface_has_free_buffers(struct gbm_surface *gbm_surf)
{
if(gbm_surf != NULL){
return gbm_surf->surface_has_free_buffers(gbm_surf);
}
else {
fprintf(stderr,"%s(%d): NULL or Invalid surface pointer\n",__func__,__LINE__);
return 0;
}
}
/**
* Returns a string representing the fourcc format name.
*
* \param desc Caller-provided storage for the format name string.
* \return String containing the fourcc of the format.
*/
char *
gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc *desc)
{
desc->name[0] = gbm_format;
desc->name[1] = gbm_format >> 8;
desc->name[2] = gbm_format >> 16;
desc->name[3] = gbm_format >> 24;
desc->name[4] = 0;
return desc->name;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,269 @@
/*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
* Not a Contribution.
*
* Copyright (c) 2017-2018, 2021 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <cstdio>
#include <cstddef>
#include <dlfcn.h>
#include "msmgbm_adreno_utils.h"
#include "gbm_priv.h"
#include "msmgbm.h"
#define INT(exp) static_cast<int>(exp)
#define UINT(exp) static_cast<unsigned int>(exp)
#define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))
#ifdef GBM_DEBUG
#define GBM_DBG_LOG fprintf
#else
#define GBM_DBG_LOG(...) {}
#endif
namespace msm_gbm {
adreno_mem_info::adreno_mem_info() {
}
bool adreno_mem_info::init() {
dlerror(); //Clear any errors
libadreno_utils_ = ::dlopen("libadreno_utils.so", RTLD_NOW);
if (libadreno_utils_) {
*reinterpret_cast<void **>(&LINK_adreno_compute_fmt_aligned_width_and_height) =
::dlsym(libadreno_utils_, "compute_fmt_aligned_width_and_height");
*reinterpret_cast<void **>(&LINK_adreno_compute_padding) =
::dlsym(libadreno_utils_, "compute_surface_padding");
*reinterpret_cast<void **>(&LINK_adreno_is_mcro_tile_supportd_gpu) =
::dlsym(libadreno_utils_, "isMacroTilingSupportedByGpu");
*reinterpret_cast<void **>(&LINK_adreno_compute_compressedfmt_aligned_width_and_height) =
::dlsym(libadreno_utils_, "compute_compressedfmt_aligned_width_and_height");
*reinterpret_cast<void **>(&LINK_adreno_is_ubwc_supportd_gpu) =
::dlsym(libadreno_utils_, "isUBWCSupportedByGpu");
*reinterpret_cast<void **>(&LINK_adreno_get_gpu_pixel_alignment) =
::dlsym(libadreno_utils_, "get_gpu_pixel_alignment");
} else {
char *error=NULL;
if ((error= dlerror()) != NULL)
LOG(LOG_ERR, "%s\n", error);
LOG(LOG_ERR," Failed to load libadreno_utils.so\n");
return false;
}
LOG(LOG_DBG,"adreno_mem_info Success\n");
return true;
}
adreno_mem_info::~adreno_mem_info() {
if (libadreno_utils_) {
LOG(LOG_DBG,"Destroyer\n");
::dlclose(libadreno_utils_);
}
}
bool adreno_mem_info::is_mcro_tiling_supported() {
if (LINK_adreno_is_mcro_tile_supportd_gpu) {
LOG(LOG_DBG," func access %p\n",LINK_adreno_is_mcro_tile_supportd_gpu);
return LINK_adreno_is_mcro_tile_supportd_gpu();
}
return false;
}
void adreno_mem_info::get_aligned_wdth_hght_uncmprsd_rgb_fmt(int width,
int height, int format, int tile_enabled,unsigned int *aligned_w,
unsigned int *aligned_h) {
*aligned_w = (unsigned int)ALIGN(width, 32);
*aligned_h = (unsigned int)ALIGN(height, 32);
// Don't add any additional padding if debug.gralloc.map_fb_memory
// is enabled
if (map_fb_) {
return;
}
int bpp = 4;
switch (format) {
case GBM_FORMAT_RGBA32323232F:
bpp = 16;
break;
case GBM_FORMAT_RGB323232F:
bpp = 12;
break;
case GBM_FORMAT_RGBA16161616F:
bpp = 8;
break;
case GBM_FORMAT_RGB161616F:
bpp = 6;
break;
case GBM_FORMAT_RGB888:
case GBM_FORMAT_BGR888:
bpp = 3;
break;
case GBM_FORMAT_RG88:
case GBM_FORMAT_R16:
case GBM_FORMAT_RGB565:
case GBM_FORMAT_BGR565:
case GBM_FORMAT_RGBA5551:
case GBM_FORMAT_RGBA4444:
bpp = 2;
break;
case GBM_FORMAT_R8:
bpp = 1;
break;
default:
break;
}
int raster_mode = 0; // Adreno unknown raster mode.
int padding_threshold = 512; // Threshold for padding surfaces.
// the function below computes aligned width and aligned height
// based on linear or macro tile mode selected.
if (LINK_adreno_compute_fmt_aligned_width_and_height) {
LOG(LOG_DBG,"Using LINK_adreno_compute_fmt_aligned_width_and_height func:= %p\n",
LINK_adreno_compute_fmt_aligned_width_and_height);
ADRENOPIXELFORMAT gpu_pixel_format = get_gpu_pxl_fmt(format);
if (gpu_pixel_format != ADRENO_PIXELFORMAT_UNKNOWN) {
LINK_adreno_compute_fmt_aligned_width_and_height(
width, height, 0 /*plane_id*/, gpu_pixel_format, 1 /*num_samples */,
tile_enabled, raster_mode, padding_threshold, reinterpret_cast<int *>(aligned_w),
reinterpret_cast<int *>(aligned_h));
}
} else if (LINK_adreno_compute_padding) {
int surface_tile_height = 1; // Linear surface
LOG(LOG_DBG,"Using LINK_adreno_compute_padding func:= %p\n",LINK_adreno_compute_padding);
*aligned_w = UINT(LINK_adreno_compute_padding(width, bpp, surface_tile_height,
raster_mode,padding_threshold));
LOG(LOG_DBG,"Old GFX API is used to calculate stride\n");
} else {
LOG(LOG_ERR,"Symbols compute_surface_padding and "
"compute_aligned_width_and_height not found\n");
}
}
void adreno_mem_info::get_aligned_wdth_hght_cmprsd_rgb_fmt(
int width, int height, int format, unsigned int *aligned_w,
unsigned int *aligned_h) {
if (LINK_adreno_compute_compressedfmt_aligned_width_and_height) {
int bytesPerPixel = 0;
int raster_mode = 0; // Adreno unknown raster mode.
int padding_threshold = 512; // Threshold for padding
// surfaces.
LINK_adreno_compute_compressedfmt_aligned_width_and_height(
width, height, format, 0, raster_mode, padding_threshold,
reinterpret_cast<int *>(aligned_w), reinterpret_cast<int *>(aligned_h), &bytesPerPixel);
} else {
LOG(LOG_ERR,"compute_compressedfmt_aligned_width_and_height not found");
}
}
bool adreno_mem_info::is_ubwc_supported_gpu(unsigned int format) {
if (!gfx_ubwc_disable_ && LINK_adreno_is_ubwc_supportd_gpu) {
ADRENOPIXELFORMAT gpu_format = get_gpu_pxl_fmt(format);
return LINK_adreno_is_ubwc_supportd_gpu(gpu_format);
}
return false;
}
unsigned int adreno_mem_info::get_gpu_pxl_align() {
if (LINK_adreno_get_gpu_pixel_alignment) {
return LINK_adreno_get_gpu_pixel_alignment();
}
return 1;
}
ADRENOPIXELFORMAT adreno_mem_info::get_gpu_pxl_fmt(unsigned int gbm_format) {
switch (gbm_format) {
case GBM_FORMAT_R8:
return ADRENO_PIXELFORMAT_R8_UNORM;
case GBM_FORMAT_RG88:
return ADRENO_PIXELFORMAT_R8G8_UNORM;
case GBM_FORMAT_R16:
return ADRENO_PIXELFORMAT_R16_UNORM;
case GBM_FORMAT_RG1616:
return ADRENO_PIXELFORMAT_R16G16_UNORM;
case GBM_FORMAT_BGR888:
return ADRENO_PIXELFORMAT_R8G8B8;
case GBM_FORMAT_RGBA8888:
return ADRENO_PIXELFORMAT_R8G8B8A8;
case GBM_FORMAT_XBGR8888:
return ADRENO_PIXELFORMAT_R8G8B8X8;
case GBM_FORMAT_ABGR8888:
return ADRENO_PIXELFORMAT_R8G8B8A8;
case GBM_FORMAT_ABGR2101010:
return ADRENO_PIXELFORMAT_R10G10B10A2_UNORM;
case GBM_FORMAT_RGB565:
return ADRENO_PIXELFORMAT_B5G6R5;
case GBM_FORMAT_BGR565:
return ADRENO_PIXELFORMAT_R5G6B5;
case GBM_FORMAT_RGB888:
return ADRENO_PIXELFORMAT_R8G8B8;
case GBM_FORMAT_NV12_ENCODEABLE:
return ADRENO_PIXELFORMAT_NV12;
case GBM_FORMAT_UYVY:
return ADRENO_PIXELFORMAT_UYVY;
case GBM_FORMAT_YCbCr_420_SP_VENUS:
case GBM_FORMAT_YCbCr_420_SP_VENUS_UBWC:
case GBM_FORMAT_NV12:
return ADRENO_PIXELFORMAT_NV12;
case GBM_FORMAT_YCbCr_420_TP10_UBWC:
return ADRENO_PIXELFORMAT_TP10;
case GBM_FORMAT_YCbCr_420_P010_UBWC:
return ADRENO_PIXELFORMAT_P010;
case GBM_FORMAT_RGB161616F:
return ADRENO_PIXELFORMAT_R16G16B16_FLOAT;
case GBM_FORMAT_RGB323232F:
return ADRENO_PIXELFORMAT_R32G32B32_FLOAT;
case GBM_FORMAT_RGBA16161616F:
return ADRENO_PIXELFORMAT_R16G16B16A16_FLOAT;
case GBM_FORMAT_RGBA32323232F:
return ADRENO_PIXELFORMAT_R32G32B32A32_FLOAT;
default:
LOG(LOG_ERR,":No map for format: 0x%x",gbm_format);
break;
}
return ADRENO_PIXELFORMAT_UNKNOWN;
}
} // namespace msm_gbm

View File

@@ -0,0 +1,106 @@
/*
* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
* Not a Contribution.
*
* Copyright (c) 2018, 2021 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include <stddef.h>
#include <linux/msm_ion.h>
#include <linux/ion.h>
#include <gbm_priv.h>
#include <msmgbm.h>
#include <msmgbm_common.h>
/**
* Get the implementaion defined format based on usage flags.
* @return - pixel_format to be used for BO
* returns input format if none of the combination matches.
*/
uint32_t GetCameraImplDefinedFormat(uint32_t usage_flags, uint32_t format)
{
uint32_t pixel_format = format;
if((usage_flags & GBM_BO_USAGE_CAMERA_READ_QTI) &&
(usage_flags & GBM_BO_USAGE_CAMERA_WRITE_QTI)){
pixel_format = GBM_FORMAT_NV21_ZSL;
}else if(usage_flags & GBM_BO_USAGE_CAMERA_READ_QTI){
pixel_format = GBM_FORMAT_YCrCb_420_SP;
}else if(usage_flags & GBM_BO_USAGE_CAMERA_WRITE_QTI){
if(format == GBM_FORMAT_YCbCr_420_888){
pixel_format = GBM_FORMAT_NV21_ZSL;
}else{
pixel_format = GBM_FORMAT_YCbCr_420_SP_VENUS;
}
}else if(usage_flags & GBM_BO_USAGE_HW_COMPOSER_QTI){
if (GBM_FORMAT_IMPLEMENTATION_DEFINED == format) {
pixel_format = GBM_FORMAT_NV12_ENCODEABLE;
} else {
pixel_format = GBM_FORMAT_RGBA8888;
}
}
return pixel_format;
}
/**
* Get the ion allocation flags based on allocation flags.
* @return - ion flags for BO allocation
*/
uint32_t GetCameraIonAllocFlags(uint32_t alloc_flags)
{
uint32_t ion_flags = 0;
if((alloc_flags & GBM_BO_USAGE_PROTECTED_QTI)
&& (alloc_flags & GBM_BO_USAGE_CAMERA_WRITE_QTI)){
if(alloc_flags & GBM_BO_USAGE_HW_COMPOSER_QTI)
ion_flags |= ION_FLAG_CP_CAMERA_PREVIEW;
else
ion_flags |= ION_FLAG_CP_CAMERA;
}
return ion_flags;
}
/**
* Get the ion heap id based on allocation flags.
* @return - ion heap id for BO allocation
*/
uint32_t GetCameraIonHeapId(uint32_t alloc_flags)
{
uint32_t ion_heap_id = 0;
if((alloc_flags & GBM_BO_USAGE_PROTECTED_QTI) &&
alloc_flags & GBM_BO_USAGE_CAMERA_WRITE_QTI){
ion_heap_id = ION_HEAP(ION_SECURE_DISPLAY_HEAP_ID);
}
return ion_heap_id;
}

View File

@@ -0,0 +1,158 @@
/*
* Copyright (c) 2018, 2021 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <linux/msm_ion.h>
#include <linux/ion.h>
#include <gbm_priv.h>
#include <msmgbm.h>
#include <msmgbm_common.h>
bool IsImplDefinedFormat(uint32_t format)
{
if((format == GBM_FORMAT_YCbCr_420_888) ||
(format == GBM_FORMAT_IMPLEMENTATION_DEFINED))
return true;
else
return false;
}
uint32_t GetDefaultImplDefinedFormat(uint32_t usage_flags, uint32_t format)
{
uint32_t pixel_format = format;
if(usage_flags & GBM_BO_USAGE_UBWC_ALIGNED_QTI){
pixel_format = GBM_FORMAT_YCbCr_420_SP_VENUS_UBWC;
if (usage_flags & GBM_BO_USAGE_10BIT_QTI) {
pixel_format = GBM_FORMAT_YCbCr_420_P010_UBWC;
} else if (usage_flags & GBM_BO_USAGE_10BIT_TP_QTI) {
pixel_format = GBM_FORMAT_YCbCr_420_TP10_UBWC;
}
} else if (usage_flags & GBM_BO_USAGE_10BIT_QTI) {
pixel_format = GBM_FORMAT_YCbCr_420_P010_VENUS;
}
return pixel_format;
}
uint32_t GetImplDefinedFormat(uint32_t usage_flags, uint32_t format)
{
uint32_t pixel_format = format;
pixel_format = GetDefaultImplDefinedFormat(usage_flags, pixel_format);
pixel_format = GetCameraImplDefinedFormat(usage_flags, pixel_format);
pixel_format = GetVideoImplDefinedFormat(usage_flags, pixel_format);
/*default if no valid format is set by camera/video*/
if(IsImplDefinedFormat(pixel_format))
pixel_format = GBM_FORMAT_NV21_ZSL;
LOG(LOG_DBG,"%s: format 0x%x\n", __func__, pixel_format);
return pixel_format;
}
static uint32_t GetDefaultIonAllocFlags(uint32_t alloc_flags)
{
uint32_t ion_flags = 0;
/*set heap specific flags*/
if(alloc_flags & GBM_BO_ALLOC_SECURE_HEAP_QTI){
ion_flags |= ION_FLAG_CP_PIXEL;
}else if((alloc_flags & GBM_BO_ALLOC_SECURE_DISPLAY_HEAP_QTI) &&
!(alloc_flags & GBM_BO_USAGE_CAMERA_WRITE_QTI)){
/*check for secure display*/
ion_flags |= ION_FLAG_CP_SEC_DISPLAY;
}
/*check if it is secure allocation*/
if(alloc_flags & GBM_BO_USAGE_PROTECTED_QTI){
ion_flags |= ION_FLAG_SECURE;
}
/*check if uncached buffer is requested*/
if(!(alloc_flags & GBM_BO_USAGE_UNCACHED_QTI)){
ion_flags |= ION_FLAG_CACHED;
}
return ion_flags;
}
uint32_t GetIonAllocFlags(uint32_t alloc_flags)
{
uint32_t ion_flags = 0;
ion_flags |= GetDefaultIonAllocFlags(alloc_flags);
ion_flags |= GetCameraIonAllocFlags(alloc_flags);
ion_flags |= GetVideoIonAllocFlags(alloc_flags);
LOG(LOG_DBG,"%s: ion_flags 0x%x\n", __func__, ion_flags);
return ion_flags;
}
static uint32_t GetDefaultIonHeapId(uint32_t alloc_flags)
{
uint32_t ion_heap_id = 0;
if(alloc_flags & GBM_BO_ALLOC_SECURE_HEAP_QTI){
ion_heap_id = ION_HEAP(ION_SECURE_HEAP_ID);
}else if(alloc_flags & GBM_BO_ALLOC_SECURE_DISPLAY_HEAP_QTI){
ion_heap_id = ION_HEAP(ION_SECURE_DISPLAY_HEAP_ID);
}else if(alloc_flags & GBM_BO_ALLOC_ADSP_HEAP_QTI){
ion_heap_id = ION_HEAP(ION_ADSP_HEAP_ID);
}else if(alloc_flags & GBM_BO_ALLOC_CAMERA_HEAP_QTI){
ion_heap_id = ION_HEAP(ION_CAMERA_HEAP_ID);
}else if(alloc_flags & GBM_BO_ALLOC_IOMMU_HEAP_QTI){
/*IOMMU_HEAP is deprecated, use ION_SYSTEM_HEAP_ID*/
ion_heap_id = ION_HEAP(ION_SYSTEM_HEAP_ID);
}else if(alloc_flags & GBM_BO_ALLOC_MM_HEAP_QTI){
ion_heap_id = ION_HEAP(ION_CP_MM_HEAP_ID);
}else{
ion_heap_id = ION_HEAP(ION_SYSTEM_HEAP_ID);
}
return ion_heap_id;
}
uint32_t GetIonHeapId(uint32_t alloc_flags)
{
uint32_t ion_heap_id = 0;
ion_heap_id |= GetDefaultIonHeapId(alloc_flags);
ion_heap_id |= GetCameraIonHeapId(alloc_flags);
ion_heap_id |= GetVideoIonHeapId(alloc_flags);
LOG(LOG_DBG,"%s: ion_heap_id 0x%x\n", __func__, ion_heap_id);
return ion_heap_id;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,332 @@
/*
* Copyright (c) 2017, 2021 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "msmgbm_mapper.h"
namespace msm_gbm {
extern "C" {
static msmgbm_mapper *msmgbm_mapper_ = NULL;
static unsigned int msmgbm_inst_count_ = 0;
static pthread_mutex_t msmgbm_mutex = PTHREAD_MUTEX_INITIALIZER;
/**
* C wrapper function to create a cpp object of msmgbm mapper class
* @input param: None
* @return 0 : success
* 1 : failure
*/
bool msmgbm_mapper_instnce(void) {
pthread_mutex_lock(&msmgbm_mutex);
if (msmgbm_mapper_ == NULL) {
msmgbm_mapper_ = new msmgbm_mapper();
if (!msmgbm_mapper_->init()) {
pthread_mutex_unlock(&msmgbm_mutex);
return 1;
}
}
msmgbm_inst_count_ ++;
pthread_mutex_unlock(&msmgbm_mutex);
return 0;
}
/**
* C wrapper function to register to the hash map a gbm_buf_info indexed by an ion_fd
* @input param: ion_fd , gbm_buf_info object handle
* @return : none
*/
void register_to_hashmap(int fd, struct gbm_buf_info * gbm_buf,
struct msmgbm_private_info * gbo_private_info) {
msmgbm_mapper_->register_to_map(fd, gbm_buf, gbo_private_info);
}
/**
* C wrapper function to search hash map using ion_fd and retrieve the gbm_buf_info
* @input param: ion_fd , gbm_buf_info object handle
* @return : GBM error status
*
*/
int search_hashmap(int fd, struct gbm_buf_info *buf_info,
struct msmgbm_private_info * gbo_private_info) {
if(msmgbm_mapper_->search_map(fd,buf_info, gbo_private_info))
return GBM_ERROR_NONE;
else
return GBM_ERROR_BAD_HANDLE;
}
/**
* C wrapper function to update hash map using ion_fd and retrieve the gbm_buf_info
* @input param: ion_fd , gbm_buf_info object handle
* @return : GBM error status
*
*/
int update_hashmap(int fd, struct gbm_buf_info *buf_info,
struct msmgbm_private_info * gbo_private_info) {
if(msmgbm_mapper_->update_map(fd,buf_info, gbo_private_info))
return GBM_ERROR_NONE;
else
return GBM_ERROR_BAD_HANDLE;
}
/**
* C wrapper function to dump hash map
* @input param: void
* @return : none
*
*/
void dump_hashmap(void) {
msmgbm_mapper_->map_dump();
}
/**
* C wrapper function to increment the reference count for the valid map entry
* @input param: ion_fd
* @return : none
*
*/
void incr_refcnt(int fd) {
msmgbm_mapper_->add_map_entry(fd);
}
/**
* C wrapper function to decrement the reference count for the valid map entry
* @input param: ion_fd
* @return : 1 for delete map entry /0 for decremented ref count
*
*/
int decr_refcnt(int fd){
if (msmgbm_mapper_)
return msmgbm_mapper_->del_map_entry(fd);
else {
LOG(LOG_INFO,"gbm mapper had been de-instantiated\n");
return 1;
}
}
void incr_handle_refcnt(int device_fd, uint32_t handle) {
msmgbm_mapper_->incr_handle_refcnt(device_fd, handle);
}
int decr_handle_refcnt(int device_fd, uint32_t handle){
if (msmgbm_mapper_)
return msmgbm_mapper_->decr_handle_refcnt(device_fd, handle);
else {
LOG(LOG_INFO,"gbm mapper had been de-instantiated\n");
return 1;
}
}
void msmgbm_mapper::incr_handle_refcnt(int device_fd, uint32_t gem_handle) {
struct gem_handle_key key(device_fd, gem_handle);
auto it = gem_object_map_.find(key);
if (it != gem_object_map_.end()) {
it->second++;
} else {
gem_object_map_.emplace(std::make_pair(key, 1));
}
}
int msmgbm_mapper::decr_handle_refcnt(int device_fd, uint32_t gem_handle) {
struct gem_handle_key key(device_fd, gem_handle);
auto it = gem_object_map_.find(key);
if (it != gem_object_map_.end()) {
it->second--;
if (it->second == 0) {
gem_object_map_.erase(key);
return 1;
} else
return 0;
} else {
return 0;
}
}
/**
* C wrapper function to delete msmsgbm mapper object
* @input param: None
* @return : None
*
*/
void msmgbm_mapper_deinstnce(void) {
pthread_mutex_lock(&msmgbm_mutex);
if (--msmgbm_inst_count_ != 0) {
pthread_mutex_unlock(&msmgbm_mutex);
return;
}
if (msmgbm_mapper_) {
delete msmgbm_mapper_;
msmgbm_mapper_ = NULL;
}
pthread_mutex_unlock(&msmgbm_mutex);
}
}
/**
* Constructor
*/
msmgbm_mapper::msmgbm_mapper() {
LOG(LOG_INFO,"gbm mapper instantiated\n");
}
/**
* Destructor
*/
msmgbm_mapper::~msmgbm_mapper() {
LOG(LOG_INFO,"gbm mapper de-instantiated\n");
}
bool msmgbm_mapper::init() {
gbm_buf_map_.clear();
gem_object_map_.clear();
return true;
}
/**
* Function to register to the hash map a gbm_buf_info indexed by an ion_fd
* @input param: ion_fd , gbm_buf_info object handle
* @return : none
*/
void msmgbm_mapper::register_to_map(int fd, struct gbm_buf_info * gbm_buf,
struct msmgbm_private_info *gbo_private_info) {
auto buffer = std::make_shared<msmgbm_buffer>(fd,gbm_buf->metadata_fd,
gbm_buf->width,gbm_buf->height,gbm_buf->format,
gbo_private_info->cpuaddr, gbo_private_info->mt_cpuaddr);
gbm_buf_map_.emplace(std::make_pair(fd, buffer));
}
/**
* Function to search hash map using ion_fd and retrieve the gbm_buf_info
* @input param: ion_fd , gbm_buf_info object handle, msmgbm_private_info object handle
* @return : 1 or O
*
*/
int msmgbm_mapper::search_map(int fd, struct gbm_buf_info *buf_info,
struct msmgbm_private_info *gbo_private_info){
auto it = gbm_buf_map_.find(fd);
if (it != gbm_buf_map_.end()) {
buf_info->fd=it->second->ion_fd;
buf_info->metadata_fd=it->second->ion_metadata_fd;
buf_info->width=it->second->width;
buf_info->height=it->second->height;
buf_info->format=it->second->format;
gbo_private_info->cpuaddr = it->second->cpuaddr;
gbo_private_info->mt_cpuaddr = it->second->mt_cpuaddr;
return 1;
} else {
return 0;
}
}
/**
* Function to update hash map entry using ion_fd as hash key
* @input param: ion_fd , gbm_buf_info object handle
* @return : 1 or O
*
*/
int msmgbm_mapper::update_map(int fd, struct gbm_buf_info *buf_info,
struct msmgbm_private_info *gbo_private_info){
auto it = gbm_buf_map_.find(fd);
if (it != gbm_buf_map_.end()) {
it->second->ion_fd=buf_info->fd;
it->second->ion_metadata_fd=buf_info->metadata_fd;
it->second->width=buf_info->width;
it->second->height=buf_info->height;
it->second->format=buf_info->format;
it->second->cpuaddr=gbo_private_info->cpuaddr;
it->second->mt_cpuaddr=gbo_private_info->mt_cpuaddr;
return 1;
} else {
return 0;
}
}
/**
* Function to dump the hash map table
* @input void
* @return void
*
*/
void msmgbm_mapper::map_dump(void) {
int count=1;
printf("Hash Table dump\n");
printf("***********************************************\n");
for (auto it : gbm_buf_map_) {
auto buf = it.second;
printf("ENTRY %d\n",count++);
printf("---------------------------------\n");
printf("----ion_fd = %d\n",buf->ion_fd);
printf("----ion_metadata_fd = %d\n",buf->ion_metadata_fd);
printf("----width = %u\n",buf->width);
printf("----height = %u\n",buf->height);
printf("----format = %u\n",buf->format);
printf("----cpuaddr = %p\n",buf->cpuaddr);
printf("----mt_cpuaddr = %p\n",buf->mt_cpuaddr);
printf("---------------------------------\n");
}
printf("Total no.of entries=%d\n",count-1);
printf("***********************************************\n");
}
/**
* Function to increment the reference count for the valid map entry
* @input param: ion_fd
* @return : none
*
*/
void msmgbm_mapper::add_map_entry(int fd) {
auto it = gbm_buf_map_.find(fd);
if (it != gbm_buf_map_.end()){
it->second->IncRef();
}
}
/**
* Function to decrement the reference count for the valid map entry
* @input param: ion_fd
* @return : none
*
*/
int msmgbm_mapper::del_map_entry(int fd) {
auto it = gbm_buf_map_.find(fd);
if (it!= gbm_buf_map_.end())
if(it->second->DecRef()){
gbm_buf_map_.erase(fd);
return 1;
}else
return 0;
return 1;
}
} // namespace msm_gbm

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 2018, 2021 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include <gbm_priv.h>
#include <msmgbm.h>
#include <msmgbm_common.h>
/**
* Get the implementaion defined format based on usage flags.
* @return - pixel_format to be used for BO
* returns input format if none of the combination matches.
*/
uint32_t GetVideoImplDefinedFormat(uint32_t usage_flags, uint32_t format)
{
uint32_t pixel_format = format;
if(!IsImplDefinedFormat(format))
return pixel_format;
if(usage_flags & GBM_BO_USAGE_VIDEO_ENCODER_QTI){
pixel_format = GBM_FORMAT_NV12_ENCODEABLE;
}
return pixel_format;
}
/**
* Get the ion allocation flags based on allocation flags.
* @return - ion flags for BO allocation
*/
uint32_t GetVideoIonAllocFlags(uint32_t alloc_flags)
{
uint32_t ion_flags = 0;
return ion_flags;
}
/**
* Get the ion heap id based on allocation flags.
* @return - ion heap id for BO allocation
*/
uint32_t GetVideoIonHeapId(uint32_t alloc_flags)
{
uint32_t ion_heap_id = 0;
return ion_heap_id;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,75 @@
#!/bin/sh
#Copyright (c) 2020, 2021 The Linux Foundation. All rights reserved.
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
#
#1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
#2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
#3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#MPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
#LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
#CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
#INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
#CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
#ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
#THE POSSIBILITY OF SUCH DAMAGE.
#
#SPDX-License-Identifier: BSD-3-Clause
number=1
res=1
if [ ! "$1" ]
then
echo "usage: gbmtest_all <Max Test cases to execute>"
echo "Default Max Tests are 25"
MAX_TEST_CASE=25
else
MAX_TEST_CASE=$1
fi
CHECK_TEST_CASE=`expr $MAX_TEST_CASE + 1`
killall weston
while [ "$number" -lt "$CHECK_TEST_CASE" ]
do
/usr/bin/gbmtest "$number" > /dev/null 2>&1
res=$?
echo "TEST " | tr -d '\n';
if [ "$res" == 0 ] #success if 0 fail if 1
then
test_pass="$test_pass $number"
echo $number | tr -d '\n'; echo " - PASSED"
else
test_fail="$test_fail $number"
echo $number | tr -d '\n'; echo " - FAILED"
fi
number=`expr $number + 1`
done
echo ""; echo "RESULTS:"
echo "Passing Test Cases:"; echo ""
#print passing test case numbers
echo ${test_pass} ; echo ""
echo "Failing Test Cases:"
echo ""
#print failing test case numbers
echo "${test_fail}"; echo ""

View File

@@ -0,0 +1,5 @@
# Makefile.am - Automake script for sdm
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = libformatutils/src liballocator/src libsdmcomposer/src

View File

@@ -0,0 +1,3 @@
vendor.display.enable_demura=0
vendor.display.enable_spr=0
vendor.display.enable_rounded_corner=1

View File

@@ -0,0 +1,49 @@
# -*- Autoconf -*-
# configure.ac -- Autoconf script for sdm
#
# Process this file with autoconf to produce a configure script
# Requires autoconf tool later than 2.61
AC_PREREQ(2.61)
# Initialize the display package version 1.0.0
AC_INIT([display],1.0.0)
# Does not strictly follow GNU Coding standards
AM_INIT_AUTOMAKE([foreign])
# Disables auto rebuilding of configure, Makefile.ins
AM_MAINTAINER_MODE
# defines some macros variable to be included by source
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
#AC_SUBST([COMMON_CFLAGS], [-Wall -Werror -Wno-sign-conversion -Wconversion ])
AC_SUBST([AM_CPPFLAGS], [--std=c++14])
AC_ARG_WITH(sanitized-headers,
AS_HELP_STRING([--with-sanitized-headers=DIR],
[Specify the location of the sanitized Linux headers]),
[CPPFLAGS="$CPPFLAGS -I$withval"])
PKG_CHECK_MODULES([LIBDMABUFHEAP], [libdmabufheap])
AC_SUBST([LIBDMABUFHEAP_CFLAGS])
AC_SUBST([LIBDMABUFHEAP_LIBS])
# Checks for programs.
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CXX
AC_PROG_LIBTOOL
AC_PROG_AWK
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_SUBST([CFLAGS])
AC_SUBST([CC])
AC_CONFIG_FILES([ \
Makefile \
libformatutils/src/Makefile \
liballocator/src/Makefile \
libsdmcomposer/src/Makefile
])
AC_OUTPUT

View File

@@ -0,0 +1,155 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef __ALLOC_INTERFACE_H__
#define __ALLOC_INTERFACE_H__
#include "buffer_interface.h"
namespace sdm {
enum CacheOp {
kCacheReadStart = 0x1, //!< Invalidate the cache before the buffer read
kCacheReadDone, //!< Flush the cache after the buffer read
kCacheWriteStart, //!< Invalidate the cache before the buffer write
kCacheWriteDone, //!< Flush the cache after the buffer write
kCacheInvalidate, //!< Invalidate the cache before the buffer read/write
kCacheClean, //!< Flush the cache after the buffer read/write
};
struct AllocData {
bool uncached = false; //!< Specifies the buffer to be cached or uncached
uint32_t width; //!< Width of the buffer to be allocated.
uint32_t height; //!< Height of the buffer to be allocated.
BufferFormat format; //!< Format of the buffer to be allocated.
uint32_t size; //!< Size of the buffer to be allocated. Allocator allocates the
//!< buffer of this size, if size is non zero otherwise allocator
//!< allocates the buffer based on width, height and format.
struct UsageHints {
union {
struct {
uint32_t trusted_ui : 1; //!< Denotes buffer to be allocated from trusted ui heap.
uint32_t tui_demura : 2; //!< Denotes buffer to be allocated from trusted ui demura heap.
};
uint64_t hints;
};
};
UsageHints usage_hints; //!< Hints to know about the producer of the buffer
};
struct CloneData {
int fd = -1; //!< Buffer fd to be cloned.
uint32_t width; //!< Width of the buffer to be cloned.
uint32_t height; //!< Height of the buffer to be cloned.
BufferFormat format; //!< Format of the buffer to be cloned.
};
class AllocInterface {
public:
/*! @brief Method to get the instance of allocator interface.
@details This function opens the ion device and provides the ion allocator interface
@return Returns AllocInterface pointer on sucess otherwise NULL
*/
static AllocInterface *GetInstance();
/*! @brief Method to to allocate buffer for a given buffer attributes
@param[in] data - \link AllocData \endlink
@param[out] buffer_handle - \link BufferHandle \endlink
@return Returns 0 on sucess otherwise errno
*/
virtual int AllocBuffer(AllocData *data, BufferHandle *buffer_handle) = 0;
/*! @brief Method to deallocate buffer
@param[in] buffer_handle - \link BufferHandle \endlink
@return Returns 0 on sucess otherwise errno
*/
virtual int FreeBuffer(BufferHandle *buffer_handle) = 0;
/*! @brief This creates a new mapping in the virtual address space of the calling process and
provides the pointer.
@param[in] fd - fd of the buffer to be mapped
@param[in] size - size of the buffer to be mapped
@param[out] base - virtual base address after mapping
@return Returns 0 on sucess otherwise errno
*/
virtual int MapBuffer(int fd, unsigned int size, void **base) = 0;
/*! @brief This function unmaps the buffer for the given pointer.
@param[in] base - virtual base address to be unmapped
@param[in] size - size of the buffer to be unmapped
@return Returns 0 on sucess otherwise errno
*/
virtual int UnmapBuffer(void *base, unsigned int size) = 0;
/*! @brief This function helps to invalidate and flush the cache for the read write operation.
@param[in] CacheOp - \link CacheOp \endlink
@param[in] fd - fd of the buffer to be mapped
@return Returns 0 on sucess otherwise errno
*/
virtual int SyncBuffer(CacheOp op, int fd) = 0;
/*! @brief This function helps to clone the buffer handle for the given buffer parameters
@param[in] clone_data - \link CloneData \endlink
@param[out] buffer_handle - \link BufferHandle \endlink
@return Returns 0 on sucess otherwise errno
*/
virtual int CloneBuffer(const CloneData &clone_data, BufferHandle *buffer_handle) = 0;
protected:
virtual ~AllocInterface() { }
};
} // namespace sdm
#endif // __ALLOC_INTERFACE_H__

View File

@@ -0,0 +1,122 @@
/*
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Changes from Qualcomm Innovation Center are provided under the following license:
* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef __BUFFER_INTERFACE_H__
#define __BUFFER_INTERFACE_H__
namespace sdm {
typedef void * Handle;
enum BufferFormat {
/* All RGB formats, Any new format will be added towards end of this group to maintain backward
compatibility.
*/
kBufferFormatInvalid = -1, //!< Invalid buffer format
kBufferFormatARGB8888, //!< 8-bits Alpha, Red, Green, Blue interleaved in ARGB order.
kBufferFormatRGBA8888, //!< 8-bits Red, Green, Blue, Alpha interleaved in RGBA order.
kBufferFormatBGRA8888, //!< 8-bits Blue, Green, Red, Alpha interleaved in BGRA order.
kBufferFormatXRGB8888, //!< 8-bits Padding, Red, Green, Blue interleaved in XRGB order.
//!< NoAlpha.
kBufferFormatRGBX8888, //!< 8-bits Red, Green, Blue, Padding interleaved in RGBX order.
//!< NoAlpha.
kBufferFormatBGRX8888, //!< 8-bits Blue, Green, Red, Padding interleaved in BGRX order.
//!< NoAlpha.
kBufferFormatRGBA5551, //!< 5-bits Red, Green, Blue, and 1 bit Alpha interleaved in
//!< RGBA order.
kBufferFormatRGBA4444, //!< 4-bits Red, Green, Blue, Alpha interleaved in RGBA order.
kBufferFormatRGB888, //!< 8-bits Red, Green, Blue interleaved in RGB order. No Alpha.
kBufferFormatBGR888, //!< 8-bits Blue, Green, Red interleaved in BGR order. No Alpha.
kBufferFormatRGB565, //!< 5-bit Red, 6-bit Green, 5-bit Blue interleaved in RGB order.
//!< NoAlpha.
kBufferFormatBGR565, //!< 5-bit Blue, 6-bit Green, 5-bit Red interleaved in BGR order.
//!< NoAlpha.
kBufferFormatRGBA1010102, //!< 10-bits Red, Green, Blue, Alpha interleaved in RGBA order.
kBufferFormatARGB2101010, //!< 10-bits Alpha, Red, Green, Blue interleaved in ARGB order.
kBufferFormatRGBX1010102, //!< 10-bits Red, Green, Blue, Padding interleaved in RGBX order.
//!< NoAlpha.
kBufferFormatXRGB2101010, //!< 10-bits Padding, Red, Green, Blue interleaved in XRGB order.
//!< NoAlpha.
kBufferFormatBGRA1010102, //!< 10-bits Blue, Green, Red, Alpha interleaved in BGRA order.
kBufferFormatABGR2101010, //!< 10-bits Alpha, Blue, Green, Red interleaved in ABGR order.
kBufferFormatBGRX1010102, //!< 10-bits Blue, Green, Red, Padding interleaved in BGRX order.
//!< NoAlpha.
kBufferFormatXBGR2101010, //!< 10-bits Padding, Blue, Green, Red interleaved in XBGR order.
//!< NoAlpha.
kBufferFormatRGB101010, //!< 10-bits Red, Green, Blue, interleaved in RGB order. No Alpha.
kBufferFormatRGBA8888Ubwc, //!< UBWC aligned RGBA8888 format
kBufferFormatRGBX8888Ubwc, //!< UBWC aligned RGBX8888 format
kBufferFormatBGR565Ubwc, //!< UBWC aligned BGR565 format
kBufferFormatRGBA1010102Ubwc, //!< UBWC aligned RGBA1010102 format
kBufferFormatRGBX1010102Ubwc, //!< UBWC aligned RGBX1010102 format
};
struct Rect {
float left = 0.0f; //!< Specifies the left coordinates of the pixel buffer
float top = 0.0f; //!< Specifies the top coordinates of the pixel buffer
float right = 0.0f; //!< Specifies the right coordinates of the pixel buffer
float bottom = 0.0f; //!< Specifies the bottom coordinates of the pixel buffer
bool operator==(const Rect& rect) const {
return left == rect.left && right == rect.right && top == rect.top && bottom == rect.bottom;
}
bool operator!=(const Rect& rect) const {
return !operator==(rect);
}
};
struct BufferHandle {
int32_t fd = -1; //!< fd of the allocated buffer to be displayed.
int32_t producer_fence_fd = -1; //!< Created and signaled by the producer. Consumer
//!< needs to wait on this before the buffer
//!< is being accessed
int32_t consumer_fence_fd = -1; //!< Created and signaled by the consumer. Producer
//!< needs to wait on this before the buffer
//!< is being modified
uint32_t width = 0; //!< Actual width of the buffer in pixels
uint32_t height = 0; //!< Actual height of the buffer in pixels.
uint32_t aligned_width = 0; //!< Aligned width of the buffer in pixels
uint32_t aligned_height = 0; //!< Aligned height of the buffer in pixels
BufferFormat format = kBufferFormatInvalid; //!< Format of the buffer refer BufferFormat
uint32_t stride_in_bytes = 0; //!< Stride of the buffer in bytes
uint32_t size = 0; //!< Allocated buffer size
bool uncached = false; //!< Enable or disable buffer caching during R/W
int64_t buffer_id = -1; //!< Unique Id of the allocated buffer for the
//!< internal use only
Rect src_crop = {}; //!< Crop rectangle of src buffer, if client doesn't
//!< specify, its default to {0, 0, width, height}
};
} // namespace sdm
#endif // __BUFFER_INTERFACE_H__

View File

@@ -0,0 +1,86 @@
/*
Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the
disclaimer below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __PROPERTY_PARSER_INTERFACE__
#define __PROPERTY_PARSER_INTERFACE__
class PropertyParserInterface {
public:
/*! @brief Method to create property parser interface.
@details This function to be called once per the device life cycle. This function creates
property parser interface which parses the property and its value from
vendor_build.prop property file. Property and value should be stored in following
format "property_name=value" to parse the file appropriately.
@param[out] intf - Populates property parser interface pointer.
@return Returns 0 on sucess otherwise errno
*/
static int Create(PropertyParserInterface **intf);
/*! @brief Method to destroy property parser interface.
@details This function to be called once per the device life cycle.
@param[in] intf - Property parser interface pointer which was populated by Create() function.
@return Returns 0 on sucess otherwise errno
*/
static int Destroy(PropertyParserInterface *intf);
/*! @brief Method to get the value of the property as integer.
@param[in] property_name - property name for which you want to retrieve the value.
@param[out] value - Integer pointer stores the value of the property.
@return Returns 0 on sucess otherwise errno
*/
virtual int GetProperty(const char *property_name, int *value) = 0;
/*! @brief Method to get the value of the property as char string.
@param[in] property_name - property name for which you want to retrieve the value.
@param[out] value - char pointer stores the value of the property.
@return Returns 0 on sucess otherwise errno
*/
virtual int GetProperty(const char *property_name, char *value) = 0;
protected:
virtual ~PropertyParserInterface() { }
};
#endif // __PROPERTY_PARSER_INTERFACE__

View File

@@ -0,0 +1,284 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __SDM_COMP_INTERFACE_H__
#define __SDM_COMP_INTERFACE_H__
#include "buffer_interface.h"
namespace sdm {
typedef void * Handle;
enum SDMCompDisplayType {
kSDMCompDisplayTypePrimary, // Defines the display type for primary display
kSDMCompDisplayTypeSecondary1, // Defines the display type for secondary builtin display
kSDMCompDisplayTypeMax,
};
// The following values matches the HEVC spec
typedef enum ColorPrimaries {
// Unused = 0;
ColorPrimaries_BT709_5 = 1, // ITU-R BT.709-5 or equivalent
/* Unspecified = 2, Reserved = 3*/
ColorPrimaries_BT470_6M = 4, // ITU-R BT.470-6 System M or equivalent
ColorPrimaries_BT601_6_625 = 5, // ITU-R BT.601-6 625 or equivalent
ColorPrimaries_BT601_6_525 = 6, // ITU-R BT.601-6 525 or equivalent
ColorPrimaries_SMPTE_240M = 7, // SMPTE_240M
ColorPrimaries_GenericFilm = 8, // Generic Film
ColorPrimaries_BT2020 = 9, // ITU-R BT.2020 or equivalent
ColorPrimaries_SMPTE_ST428 = 10, // SMPTE_240M
ColorPrimaries_AdobeRGB = 11,
ColorPrimaries_DCIP3 = 12,
ColorPrimaries_EBU3213 = 22,
ColorPrimaries_Max = 0xff,
} ColorPrimaries;
typedef enum GammaTransfer {
// Unused = 0;
Transfer_sRGB = 1, // ITR-BT.709-5
/* Unspecified = 2, Reserved = 3 */
Transfer_Gamma2_2 = 4,
Transfer_Gamma2_8 = 5,
Transfer_SMPTE_170M = 6, // BT.601-6 525 or 625
Transfer_SMPTE_240M = 7, // SMPTE_240M
Transfer_Linear = 8,
Transfer_Log = 9,
Transfer_Log_Sqrt = 10,
Transfer_XvYCC = 11, // IEC 61966-2-4
Transfer_BT1361 = 12, // Rec.ITU-R BT.1361 extended gamut
Transfer_sYCC = 13, // IEC 61966-2-1 sRGB or sYCC
Transfer_BT2020_2_1 = 14, // Rec. ITU-R BT.2020-2 (same as the values 1, 6, and 15)
Transfer_BT2020_2_2 = 15, // Rec. ITU-R BT.2020-2 (same as the values 1, 6, and 14)
Transfer_SMPTE_ST2084 = 16, // 2084
Transfer_ST_428 = 17, // SMPTE ST 428-1
Transfer_HLG = 18, // ARIB STD-B67
Transfer_Max = 0xff,
} GammaTransfer;
enum RenderIntent {
//<! Colors with vendor defined gamut
kRenderIntentNative,
//<! Colors with in gamut are left untouched, out side the gamut are hard clipped
kRenderIntentColorimetric,
//<! Colors with in gamut are ehanced, out side the gamuat are hard clipped
kRenderIntentEnhance,
//<! Tone map hdr colors to display's dynamic range, mapping to display gamut is
//<! defined in colormertic.
kRenderIntentToneMapColorimetric,
//<! Tone map hdr colors to display's dynamic range, mapping to display gamut is
//<! defined in enhance.
kRenderIntentToneMapEnhance,
//<! Custom render intents range
kRenderIntentOemCustomStart = 0x100,
kRenderIntentOemCustomEnd = 0x1ff,
//<! If STC implementation returns kOemModulateHw render intent, STC manager will
//<! call the implementation for all the render intent/blend space combination.
//<! STC implementation can modify/modulate the HW assets.
kRenderIntentOemModulateHw = 0xffff - 1,
kRenderIntentMaxRenderIntent = 0xffff
};
struct SDMCompDisplayAttributes {
uint32_t vsync_period = 0; //!< VSync period in nanoseconds.
uint32_t x_res = 0; //!< Total number of pixels in X-direction on the display panel.
uint32_t y_res = 0; //!< Total number of pixels in Y-direction on the display panel.
float x_dpi = 0.0f; //!< Dots per inch in X-direction.
float y_dpi = 0.0f; //!< Dots per inch in Y-direction.
bool is_yuv = false; //!< If the display output is in YUV format.
uint32_t fps = 0; //!< fps of the display.
bool smart_panel = false; //!< Speficies the panel is video mode or command mode
};
struct SDMCompMixerConfig {
uint32_t width = 0;
uint32_t height = 0;
};
struct ColorMode {
//<! Blend-Space gamut
ColorPrimaries gamut = ColorPrimaries_Max;
//<! Blend-space Gamma
GammaTransfer gamma = Transfer_Max;
//<! Intent of the mode
RenderIntent intent = kRenderIntentMaxRenderIntent ;
};
class CallbackInterface {
public:
/*! @brief Callback method to handle any asyn error.
@details This function need to be implemented by the client which will be called
by the sdm composer on any hardware hang etc.
*/
virtual void OnError() = 0;
protected:
virtual ~CallbackInterface() { }
// callbackdata where client can store the context information about display type
// for which this callback corresponds to.
Handle callback_data_ = nullptr;
};
class SDMCompInterface {
public:
/*! @brief Method to create display composer interface for TUI service.
@details This function to be called once per the device life cycle. This function creates
sdm core and opens up the display driver drm interface.
@param[out] intf - Populates composer interface pointer.
@return Returns 0 on sucess otherwise errno
*/
static int Create(SDMCompInterface **intf);
/*! @brief Method to destroy display composer interface for TUI service.
@details This function to be called once per the device life cycle. This function destroys
sdm core and closes the display driver drm interface.
@param[in] intf - Composer interface pointer which was populated by Create() function.
@return Returns 0 on sucess otherwise errno
*/
static int Destroy(SDMCompInterface *intf);
/*! @brief Method to create display for composer where the TUI to be rendered.
@details This function to be called on start of TUI session. This function creates primary or
secondary display based on the display type passed by the client and intialize the
display.to its appropriate state This function to be called once per display. This is
also responsible to create single layer to the created display
@param[in] display_type - Specifies the type of a display. \link SDMCompDisplayType \endlink
@param[in] callback - Pointer to callback interface which handles the async error.
\link CallbackInterface \endlink
@param[out] disp_hnd - pointer to display handle which stores the context of the client.
@return Returns 0 on sucess otherwise errno
*/
virtual int CreateDisplay(SDMCompDisplayType display_type, CallbackInterface *callback,
Handle *disp_hnd) = 0;
/*! @brief Method to destroy display for composer where the TUI to be rendered.
@details This function to be called on end of TUI session. This function destroys primary or
secondary display based on the display type passed by the client and relinquish all the
MDP hw resources. This function to be called once per display.
@param[in] disp_hnd - pointer to display handle which was created during CreateDisplay()
@return Returns 0 on sucess otherwise errno
*/
virtual int DestroyDisplay(Handle disp_hnd) = 0;
/*! @brief Method to get display attributes for a given display handle.
@param[in] disp_hnd - pointer to display handle which was created during CreateDisplay()
@param[out] display_attributes - pointer to display attributes to b populated for a given
display handle. \link SDMCompDisplayAttributes \endlink.
@return Returns 0 on sucess otherwise errno
*/
virtual int GetDisplayAttributes(Handle disp_hnd,
SDMCompDisplayAttributes *display_attributes) = 0;
/*! @brief Method to prepare and render buffer to display
@param[in] disp_hnd - pointer to display handle which was created during CreateDisplay()
@param[in] buf_handle - pointer to buffer handle which specifies the attributes of a buffer
@param[out] retire_fence - pointer to retire fence which will be signaled once display hw
picks up the buf_handle for rendering.
@return Returns 0 on sucess otherwise errno
*/
virtual int ShowBuffer(Handle disp_hnd, BufferHandle *buf_handle, int32_t *retire_fence) = 0;
/*! @brief Method to set color mode with render intent
@param[in] disp_hnd - pointer to display handle which was created during CreateDisplay()
@param[in] mode - ColorMode struct which contains blend space and render intent info
@return Returns 0 on sucess otherwise errno
*/
virtual int SetColorModeWithRenderIntent(Handle disp_hnd, struct ColorMode mode) = 0;
/*! @brief Method to get all the supported color modesDprepare and render buffer to display
* ut
@param[in] disp_hnd - pointer to display handle which was created during CreateDisplay()
@param[out] out_num_modes - pointer to uint32_t which specifies the number of color modes
@param[out] out_modes - pointer to ColorMode struct which contains all color modes that
are parsed from xml files
@return Returns 0 on sucess otherwise errno
*/
virtual int GetColorModes(Handle disp_hnd, uint32_t *out_num_modes,
struct ColorMode *out_modes) = 0;
/*! @brief Method to set panel brightness
@detail This api enables client to set the panel brightness of a given display, If the set
brightness level is below the minimum panel brightness values set by the API
SetMinPanelBrightness(), then it ignores the request.
@param[in] disp_hnd - pointer to display handle which was created during CreateDisplay()
@param[in] brightness_level - brightness_level of the panel varies from 0.0f to 1.0f
@return Returns 0 on sucess otherwise errno
*/
virtual int SetPanelBrightness(Handle disp_hnd, float brightness_level) = 0;
/*! @brief Method to set minimum panel brightness level
@detail This api enables client to set minimum panel brightness threshold of a given display,
If the set brightness level is below the minimum panel brightness threshold, Reset the
panel brightness level to minimum panel brightness value
@param[in] disp_hnd - pointer to display handle which was created during CreateDisplay()
@param[in] min_brightness_level - min_brightness_level of the panel varies from 0.0f to 1.0f
@return Returns 0 on sucess otherwise errno
*/
virtual int SetMinPanelBrightness(Handle disp_hnd, float min_brightness_level) = 0;
protected:
virtual ~SDMCompInterface() { }
};
} // namespace sdm
#endif // __SDM_COMP_INTERFACE_H__

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __SDMCOMP_SERVICE_EXTN_INTF_H__
#define __SDMCOMP_SERVICE_EXTN_INTF_H__
#include "libqrtr.h"
#define EXTN_LIB_NAME "libsdmcompserviceextn.so"
#define CREATE_SDMCOMP_SERVICE_EXTN "CreateSDMCompServiceExtn"
#define DESTROY_SDMCOMP_SERVICE_EXTN "DestroySDMCompServiceExtn"
class SDMCompServiceExtnIntf;
typedef int (*CreateSDMCompExtnIntf)(int qrtr_fd, SDMCompServiceExtnIntf **intf);
typedef int (*DestroySDMCompExtnIntf)(SDMCompServiceExtnIntf *intf);
class SDMCompServiceExtnIntf {
public:
virtual void CommandHandler(const struct qrtr_packet &qrtr_pkt) = 0;
protected:
virtual ~SDMCompServiceExtnIntf() { }
};
#endif // __SDMCOMP_SERVICE_EXTN_INTF_H__

View File

@@ -0,0 +1,114 @@
/*
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
Changes from Qualcomm Innovation Center are provided under the following license:
Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the
disclaimer below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __SDMCOMP_SERVICE_INTF_H__
#define __SDMCOMP_SERVICE_INTF_H__
#include <stdarg.h>
#include "libqrtr.h"
namespace sdm {
class SDMCompServiceIntf;
enum SDMCompServiceEvents {
kEventSetPanelBrightness,
kEventSetDisplayConfig,
kEventImportDemuraBuffers,
kEventMax,
};
struct SDMCompServiceDispConfigs {
uint32_t h_total = 0;
uint32_t v_total = 0;
uint32_t fps = 0;
bool smart_panel = false;
uint32_t mixer_width = 0;
uint32_t mixer_height = 0;
};
struct SDMCompServiceDemuraBufInfo {
int hfc_buf_fd = -1;
uint32_t hfc_buf_size = 0;
uint64_t panel_id = 0;
};
class SDMCompServiceCbIntf {
public:
virtual int OnEvent(SDMCompServiceEvents event_type, ...) = 0;
protected:
virtual ~SDMCompServiceCbIntf() { }
};
class SDMCompServiceIntf {
public:
static int Create(SDMCompServiceCbIntf *callback, SDMCompServiceIntf **intf);
static int Destroy(SDMCompServiceIntf *intf);
protected:
virtual ~SDMCompServiceIntf() { }
};
}
#endif // __SDMCOMP_SERVICE_INTF_H__

View File

@@ -0,0 +1,18 @@
SDM_PATH := ${WORKSPACE}/display/vendor/qcom/opensource/display-core/sdm
AM_CPPFLAGS += "-I$(SDM_PATH)/include"
AM_CPPFLAGS += "-I$(SDM_PATH)/../libdebug"
AM_CPPFLAGS += "-I$(SDM_PATH)/../include"
AM_CPPFLAGS += "-I${WORKSPACE}/display/vendor/qcom/opensource/commonsys-intf/display/include/"
c_sources = alloc_interface.cpp \
ion_alloc_impl.cpp \
dma_buf_alloc_impl.cpp
lib_LTLIBRARIES = liballocator.la
liballocator_la_CC = @CC@
liballocator_la_SOURCES = $(c_sources)
liballocator_la_CFLAGS = $(COMMON_CFLAGS)
liballocator_la_CPPFLAGS = $(AM_CPPFLAGS) -DLOG_TAG=\"ION_ALLOCATOR\" @LIBDMABUFHEAP_CFLAGS@ -std=c++17
liballocator_la_LIBADD = ../../libformatutils/src/libformatutils.la
liballocator_la_LDFLAGS = -shared -avoid-version @LIBDMABUFHEAP_LIBS@

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <utils/debug.h>
#include <utils/utils.h>
#include "alloc_interface.h"
#include "ion_alloc_impl.h"
#include "dma_buf_alloc_impl.h"
#define __CLASS__ "AllocInterface"
namespace sdm {
AllocInterface *AllocInterface::GetInstance() {
AllocInterface *alloc_intf = sdm::DmaBufAllocator::GetInstance();
if (alloc_intf == NULL) {
alloc_intf = IonAllocator::GetInstance();
}
return alloc_intf;
}
} // namespace sdm

View File

@@ -0,0 +1,263 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <string.h>
#include <linux/dma-buf.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <utils/constants.h>
#include <string>
#include "debug_handler.h"
#include "dma_buf_alloc_impl.h"
#include "formats.h"
#define SZ_4K 0x1000
#define DEBUG 0
#define __CLASS__ "DmaBufAllocator"
namespace sdm {
template <class Type>
inline Type ALIGN(Type x, Type align) {
return (x + align - 1) & ~(align - 1);
}
DmaBufAllocator* DmaBufAllocator::dma_buf_allocator_ = NULL;
BufferAllocator DmaBufAllocator::buffer_allocator_ = {};
int64_t DmaBufAllocator::id_ = -1;
DmaBufAllocator *DmaBufAllocator::GetInstance() {
if (!dma_buf_allocator_) {
dma_buf_allocator_ = new DmaBufAllocator();
}
return dma_buf_allocator_;
}
int DmaBufAllocator::AllocBuffer(AllocData *data, BufferHandle *buffer_handle) {
if (!data || !buffer_handle) {
DLOGE("Invalid parameter data %p buffer_handle %p", data, buffer_handle);
return -EINVAL;
}
DLOGD_IF(DEBUG, "AllocData WxHxF %dx%dx%d uncached %d usage_hints %x size %d", data->width,
data->height, data->format, data->uncached, data->usage_hints, data->size);
int fd = -1;
uint32_t flags = 0;
std::string heap_name = {};
uint32_t align = SZ_4K;
uint32_t aligned_w = 0;
uint32_t aligned_h = 0;
GetAlignedWidthAndHeight(data->width, data->height, &aligned_w, &aligned_h);
uint32_t size = data->size;
if (!size) {
size = GetBufferSize(data->width, data->height, data->format);
}
GetHeapInfo(data, &heap_name);
fd = buffer_allocator_.Alloc(heap_name, size, flags, align);
if (fd < 0) {
DLOGE("Dmabuf alloc failed buf_fd %d size %d align %d heap_name %x flags %x",
fd, size, align, heap_name.c_str(), flags);
return -ENOMEM;
}
buffer_handle->fd = fd;
buffer_handle->width = data->width;
buffer_handle->height = data->height;
buffer_handle->format = data->format;
buffer_handle->aligned_width = aligned_w;
buffer_handle->aligned_height = aligned_h;
buffer_handle->size = size;
buffer_handle->stride_in_bytes = aligned_w * GetBpp(data->format);
buffer_handle->uncached = data->uncached;
buffer_handle->buffer_id = id_++;
DLOGD_IF(DEBUG, "Allocated buffer Aligned WxHxF %dx%dx%d stride_in_bytes %d size:%u fd:%d",
buffer_handle->aligned_width, buffer_handle->aligned_height, buffer_handle->format,
buffer_handle->stride_in_bytes, buffer_handle->size, buffer_handle->fd);
return 0;
}
int DmaBufAllocator::FreeBuffer(BufferHandle *buffer_handle) {
if (!buffer_handle) {
return -EINVAL;
}
close(buffer_handle->fd);
return 0;
}
int DmaBufAllocator::SyncBuffer(CacheOp op, int dma_buf_fd) {
struct dma_buf_sync sync;
int err = 0;
switch (op) {
case kCacheReadStart:
sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ;
break;
case kCacheReadDone:
sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_READ;
break;
case kCacheWriteStart:
sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_WRITE;
break;
case kCacheWriteDone:
sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_WRITE;
break;
case kCacheInvalidate:
sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_RW;
break;
case kCacheClean:
sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_RW;
break;
default:
DLOGE("%s: Invalid operation %d", __FUNCTION__, op);
return -1;
}
if (ioctl(dma_buf_fd, INT(DMA_BUF_IOCTL_SYNC), &sync)) {
err = -errno;
DLOGE("%s: DMA_BUF_IOCTL_SYNC failed with error - %s", __FUNCTION__, strerror(errno));
return err;
}
return 0;
}
int DmaBufAllocator::MapBuffer(int fd, unsigned int size, void **base) {
if (!base || fd < 0 || !size) {
DLOGE("Invalid parameters base %p, fd %d, size %d", base, fd, size);
return -EINVAL;
}
int err = 0;
void *addr = 0;
addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
*base = addr;
if (addr == MAP_FAILED) {
err = -errno;
DLOGE("Failed to map memory in the client: %s", strerror(errno));
} else {
DLOGD_IF(DEBUG, "Mapped buffer base:%p size:%u fd:%d", addr, size, fd);
}
return err;
}
int DmaBufAllocator::UnmapBuffer(void *base, unsigned int size) {
if (!base || !size) {
DLOGE("Invalid parameters base %p, size %d", base, size);
return -EINVAL;
}
DLOGD_IF(DEBUG, "Unmapping buffer base:%p size:%u", base, size);
int err = 0;
if (munmap(base, size)) {
err = -errno;
DLOGE("Failed to unmap memory at %p : %s", base, strerror(errno));
}
return err;
}
int DmaBufAllocator::CloneBuffer(const CloneData &data, BufferHandle *buffer_handle) {
if (!buffer_handle) {
DLOGE("Invalid parameter data %p buffer_handle %p", buffer_handle);
return -EINVAL;
}
DLOGD_IF(DEBUG, "CloneData WxHxF %dx%dx%d fd %d", data.width, data.height, data.format, data.fd);
int err = 0;
uint32_t aligned_w = 0;
uint32_t aligned_h = 0;
GetAlignedWidthAndHeight(data.width, data.height, &aligned_w, &aligned_h);
uint32_t size = GetBufferSize(data.width, data.height, data.format);
buffer_handle->fd = dup(data.fd);
buffer_handle->width = data.width;
buffer_handle->height = data.height;
buffer_handle->format = data.format;
buffer_handle->aligned_width = aligned_w;
buffer_handle->aligned_height = aligned_h;
buffer_handle->size = size;
buffer_handle->stride_in_bytes = aligned_w * GetBpp(data.format);
buffer_handle->buffer_id = id_++;
DLOGD_IF(DEBUG, "Cloned buffer Aligned WxHxF %dx%dx%d stride_in_bytes %d size:%u fd:%d",
buffer_handle->aligned_width, buffer_handle->aligned_height, buffer_handle->format,
buffer_handle->stride_in_bytes, buffer_handle->size, buffer_handle->fd);
return 0;
}
void DmaBufAllocator::GetHeapInfo(AllocData *data, std::string *heap_name) {
if (data->usage_hints.trusted_ui) {
*heap_name = "qcom,tui";
} else if (data->usage_hints.tui_demura) {
*heap_name = "qcom,tui_demura";
}
}
void DmaBufAllocator::GetAlignedWidthAndHeight(int width, int height, uint32_t *aligned_width,
uint32_t *aligned_height) {
if (!aligned_width || !aligned_height) {
return;
}
*aligned_width = ALIGN(width, 32);
*aligned_height = ALIGN(height, 32);
}
uint32_t DmaBufAllocator::GetBufferSize(int width, int height, BufferFormat format) {
uint32_t aligned_w = 0;
uint32_t aligned_h = 0;
GetAlignedWidthAndHeight(width, height, &aligned_w, &aligned_h);
return (aligned_w * aligned_h * GetBpp(format));
}
} // namespace sdm

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __DMA_BUF_ALLOC_IMPL_H__
#define __DMA_BUF_ALLOC_IMPL_H__
#include <BufferAllocator/BufferAllocator.h>
#include "alloc_interface.h"
namespace sdm {
class DmaBufAllocator : public AllocInterface {
public:
~DmaBufAllocator() { }
virtual int AllocBuffer(AllocData *data, BufferHandle *buffer_handle);
virtual int FreeBuffer(BufferHandle *buffer_handle);
virtual int MapBuffer(int fd, unsigned int size, void **base);
virtual int UnmapBuffer(void *base, unsigned int size);
virtual int SyncBuffer(CacheOp op, int fd);
virtual int CloneBuffer (const CloneData &data, BufferHandle *buffer_handle);
static DmaBufAllocator *GetInstance();
private:
DmaBufAllocator() {}
void GetHeapInfo(AllocData *data, std::string *heap_name);
void GetAlignedWidthAndHeight(int width, int height, uint32_t *aligned_width,
uint32_t *aligned_height);
uint32_t GetBufferSize(int width, int height, BufferFormat format);
static DmaBufAllocator* dma_buf_allocator_;
static BufferAllocator buffer_allocator_;
static int64_t id_;
};
} // namespace sdm
#endif // __DMA_BUF_ALLOC_IMPL_H__

View File

@@ -0,0 +1,293 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <string.h>
#include <linux/dma-buf.h>
#include <linux/msm_ion.h>
#include <linux/msm_ion_ids.h>
#include <ion/ion.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <utils/constants.h>
#include "debug_handler.h"
#include "ion_alloc_impl.h"
#include "formats.h"
#define SZ_2M 0x200000
#define SZ_4K 0x1000
#define DEBUG 0
#define __CLASS__ "IonAllocator"
namespace sdm {
template <class Type>
inline Type ALIGN(Type x, Type align) {
return (x + align - 1) & ~(align - 1);
}
IonAllocator* IonAllocator::ion_allocator_ = NULL;
int64_t IonAllocator::id_ = -1;
IonAllocator *IonAllocator::GetInstance() {
if (!ion_allocator_) {
ion_allocator_ = new IonAllocator();
int error = ion_allocator_->Init();
if (error != 0) {
DLOGE("Ion initialization failed");
return NULL;
}
}
return ion_allocator_;
}
int IonAllocator::Init() {
if (ion_dev_fd_ == -1) {
ion_dev_fd_ = ion_open();
}
if (ion_dev_fd_ < 0) {
DLOGE("%s: Failed to open ion device - %s", __FUNCTION__, strerror(errno));
ion_dev_fd_ = -1;
return -EINVAL;
}
return 0;
}
void IonAllocator::Deinit() {
if (ion_dev_fd_ > -1) {
ion_close(ion_dev_fd_);
}
ion_dev_fd_ = -1;
}
int IonAllocator::AllocBuffer(AllocData *data, BufferHandle *buffer_handle) {
if (!data || !buffer_handle) {
DLOGE("Invalid parameter data %p buffer_handle %p", data, buffer_handle);
return -EINVAL;
}
DLOGD_IF(DEBUG, "AllocData WxHxF %dx%dx%d uncached %d usage_hints %x size %d", data->width,
data->height, data->format, data->uncached, data->usage_hints, data->size);
int err = 0;
int fd = -1;
uint32_t flags = 0;
uint32_t heap_id = 0;
// TODO(user): Revisit here
uint32_t align = SZ_4K;
uint32_t aligned_w = 0;
uint32_t aligned_h = 0;
GetAlignedWidthAndHeight(data->width, data->height, &aligned_w, &aligned_h);
uint32_t size = data->size;
if (!size) {
size = GetBufferSize(data->width, data->height, data->format);
}
GetIonHeapInfo(data, &heap_id, &flags);
err = ion_alloc_fd(ion_dev_fd_, size, align, heap_id, flags, &fd);
if (err) {
DLOGE("Ion alloc failed ion_fd %d size %d align %d heap_id %x flags %x err %d",
ion_dev_fd_, size, align, heap_id, flags, err);
return err;
}
buffer_handle->fd = fd;
buffer_handle->width = data->width;
buffer_handle->height = data->height;
buffer_handle->format = data->format;
buffer_handle->aligned_width = aligned_w;
buffer_handle->aligned_height = aligned_h;
buffer_handle->size = size;
buffer_handle->stride_in_bytes = aligned_w * GetBpp(data->format);
buffer_handle->uncached = data->uncached;
buffer_handle->buffer_id = id_++;
DLOGD_IF(DEBUG, "Allocated buffer Aligned WxHxF %dx%dx%d stride_in_bytes %d size:%u fd:%d",
buffer_handle->aligned_width, buffer_handle->aligned_height, buffer_handle->format,
buffer_handle->stride_in_bytes, buffer_handle->size, buffer_handle->fd);
return 0;
}
int IonAllocator::FreeBuffer(BufferHandle *buffer_handle) {
if (!buffer_handle) {
return -EINVAL;
}
close(buffer_handle->fd);
return 0;
}
int IonAllocator::SyncBuffer(CacheOp op, int dma_buf_fd) {
struct dma_buf_sync sync;
int err = 0;
switch (op) {
case kCacheReadStart:
sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ;
break;
case kCacheReadDone:
sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_READ;
break;
case kCacheWriteStart:
sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_WRITE;
break;
case kCacheWriteDone:
sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_WRITE;
break;
case kCacheInvalidate:
sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_RW;
break;
case kCacheClean:
sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_RW;
break;
default:
DLOGE("%s: Invalid operation %d", __FUNCTION__, op);
return -1;
}
if (ioctl(dma_buf_fd, INT(DMA_BUF_IOCTL_SYNC), &sync)) {
err = -errno;
DLOGE("%s: DMA_BUF_IOCTL_SYNC failed with error - %s", __FUNCTION__, strerror(errno));
return err;
}
return 0;
}
int IonAllocator::MapBuffer(int fd, unsigned int size, void **base) {
if (!base || fd < 0 || !size) {
DLOGE("Invalid parameters base %p, fd %d, size %d", base, fd, size);
return -EINVAL;
}
int err = 0;
void *addr = 0;
addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
*base = addr;
if (addr == MAP_FAILED) {
err = -errno;
DLOGE("ion: Failed to map memory in the client: %s", strerror(errno));
} else {
DLOGD_IF(DEBUG, "ion: Mapped buffer base:%p size:%u fd:%d", addr, size, fd);
}
return err;
}
int IonAllocator::UnmapBuffer(void *base, unsigned int size) {
if (!base || !size) {
DLOGE("Invalid parameters base %p, size %d", base, size);
return -EINVAL;
}
DLOGD_IF(DEBUG, "ion: Unmapping buffer base:%p size:%u", base, size);
int err = 0;
if (munmap(base, size)) {
err = -errno;
DLOGE("ion: Failed to unmap memory at %p : %s", base, strerror(errno));
}
return err;
}
int IonAllocator::CloneBuffer(const CloneData &data, BufferHandle *buffer_handle) {
if (!buffer_handle) {
DLOGE("Invalid parameter data %p buffer_handle %p", buffer_handle);
return -EINVAL;
}
DLOGD_IF(DEBUG, "CloneData WxHxF %dx%dx%d fd %d", data.width, data.height, data.format, data.fd);
int err = 0;
uint32_t aligned_w = 0;
uint32_t aligned_h = 0;
GetAlignedWidthAndHeight(data.width, data.height, &aligned_w, &aligned_h);
uint32_t size = GetBufferSize(data.width, data.height, data.format);
buffer_handle->fd = dup(data.fd);
buffer_handle->width = data.width;
buffer_handle->height = data.height;
buffer_handle->format = data.format;
buffer_handle->aligned_width = aligned_w;
buffer_handle->aligned_height = aligned_h;
buffer_handle->size = size;
buffer_handle->stride_in_bytes = aligned_w * GetBpp(data.format);
buffer_handle->buffer_id = id_++;
DLOGD_IF(DEBUG, "Cloned buffer Aligned WxHxF %dx%dx%d stride_in_bytes %d size:%u fd:%d",
buffer_handle->aligned_width, buffer_handle->aligned_height, buffer_handle->format,
buffer_handle->stride_in_bytes, buffer_handle->size, buffer_handle->fd);
return 0;
}
void IonAllocator::GetIonHeapInfo(AllocData *data, uint32_t *ion_heap_id,
uint32_t *ion_flags) {
uint32_t heap_id = ION_HEAP(ION_SYSTEM_HEAP_ID);
uint32_t flags = 0;
if (data->usage_hints.trusted_ui) {
heap_id = ION_HEAP(ION_TUI_CARVEOUT_HEAP_ID);
}
flags |= data->uncached ? 0 : ION_FLAG_CACHED;
*ion_flags = flags;
*ion_heap_id = heap_id;
}
void IonAllocator::GetAlignedWidthAndHeight(int width, int height, uint32_t *aligned_width,
uint32_t *aligned_height) {
if (!aligned_width || !aligned_height) {
return;
}
*aligned_width = ALIGN(width, 32);
*aligned_height = ALIGN(height, 32);
}
uint32_t IonAllocator::GetBufferSize(int width, int height, BufferFormat format) {
uint32_t aligned_w = 0;
uint32_t aligned_h = 0;
GetAlignedWidthAndHeight(width, height, &aligned_w, &aligned_h);
return (aligned_w * aligned_h * GetBpp(format));
}
} // namespace sdm

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __ION_ALLOC_IMPL_H__
#define __ION_ALLOC_IMPL_H__
#include "alloc_interface.h"
namespace sdm {
class IonAllocator : public AllocInterface {
public:
~IonAllocator() { Deinit(); }
virtual int AllocBuffer(AllocData *data, BufferHandle *buffer_handle);
virtual int FreeBuffer(BufferHandle *buffer_handle);
virtual int MapBuffer(int fd, unsigned int size, void **base);
virtual int UnmapBuffer(void *base, unsigned int size);
virtual int SyncBuffer(CacheOp op, int fd);
virtual int CloneBuffer (const CloneData &data, BufferHandle *buffer_handle);
static IonAllocator *GetInstance();
private:
IonAllocator() {}
int Init();
void Deinit();
void GetIonHeapInfo(AllocData *data, uint32_t *ion_heap_id, uint32_t *ion_flags);
void GetAlignedWidthAndHeight(int width, int height, uint32_t *aligned_width,
uint32_t *aligned_height);
uint32_t GetBufferSize(int width, int height, BufferFormat format);
int ion_dev_fd_ = -1;
static IonAllocator* ion_allocator_;
static int64_t id_;
};
} // namespace sdm
#endif // __ION_ALLOC_IMPL_H__

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __FORMATS_H__
#define __FORMATS_H__
#include <core/layer_buffer.h>
#include "sdm_comp_interface.h"
namespace sdm {
float GetBpp(BufferFormat format);
LayerBufferFormat GetSDMFormat(BufferFormat buf_format);
BufferFormat GetSDMCompFormat(LayerBufferFormat sdm_format);
} // namespace sdm
#endif // __FORMATS_H__

View File

@@ -0,0 +1,14 @@
DISPLAY_CORE_PATH := ${WORKSPACE}/display/vendor/qcom/opensource/display-core
AM_CPPFLAGS += "-I$(DISPLAY_CORE_PATH)/sdm/include"
AM_CPPFLAGS += "-I$(DISPLAY_CORE_PATH)/include"
AM_CPPFLAGS += "-I${WORKSPACE}/display/vendor/qcom/opensource/commonsys-intf/display/include/"
c_sources = formats.cpp
lib_LTLIBRARIES = libformatutils.la
libformatutils_la_CC = @CC@
libformatutils_la_SOURCES = $(c_sources)
libformatutils_la_CFLAGS = $(COMMON_CFLAGS)
libformatutils_la_CPPFLAGS = $(AM_CPPFLAGS) -DLOG_TAG=\"FORMATUTILS\"
libformatutils_la_LDFLAGS = -shared -avoid-version

View File

@@ -0,0 +1,187 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "formats.h"
namespace sdm {
float GetBpp(BufferFormat format) {
float bpp = 0.0f;
switch (format) {
case kBufferFormatARGB8888:
case kBufferFormatRGBA8888:
case kBufferFormatBGRA8888:
case kBufferFormatXRGB8888:
case kBufferFormatRGBX8888:
case kBufferFormatBGRX8888:
case kBufferFormatRGBA1010102:
case kBufferFormatARGB2101010:
case kBufferFormatRGBX1010102:
case kBufferFormatXRGB2101010:
case kBufferFormatBGRA1010102:
case kBufferFormatABGR2101010:
case kBufferFormatBGRX1010102:
case kBufferFormatXBGR2101010:
case kBufferFormatRGBA8888Ubwc:
case kBufferFormatRGBX8888Ubwc:
case kBufferFormatRGBA1010102Ubwc:
case kBufferFormatRGBX1010102Ubwc:
return 4.0f;
case kBufferFormatRGB888:
case kBufferFormatBGR888:
return 3.0f;
case kBufferFormatRGB565:
case kBufferFormatBGR565:
case kBufferFormatRGBA5551:
case kBufferFormatRGBA4444:
case kBufferFormatBGR565Ubwc:
return 2.0f;
default:
return 0.0f;
}
return bpp;
}
LayerBufferFormat GetSDMFormat(BufferFormat buf_format) {
switch (buf_format) {
case kBufferFormatARGB8888:
return kFormatARGB8888;
case kBufferFormatRGBA8888:
return kFormatRGBA8888;
case kBufferFormatBGRA8888:
return kFormatBGRA8888;
case kBufferFormatXRGB8888:
return kFormatXRGB8888;
case kBufferFormatRGBX8888:
return kFormatRGBX8888;
case kBufferFormatBGRX8888:
return kFormatBGRX8888;
case kBufferFormatRGBA1010102:
return kFormatRGBA1010102;
case kBufferFormatARGB2101010:
return kFormatARGB2101010;
case kBufferFormatRGBX1010102:
return kFormatRGBX1010102;
case kBufferFormatXRGB2101010:
return kFormatXRGB2101010;
case kBufferFormatBGRA1010102:
return kFormatBGRA1010102;
case kBufferFormatABGR2101010:
return kFormatABGR2101010;
case kBufferFormatBGRX1010102:
return kFormatBGRX1010102;
case kBufferFormatXBGR2101010:
return kFormatXBGR2101010;
case kBufferFormatRGB888:
return kFormatRGB888;
case kBufferFormatBGR888:
return kFormatBGR888;
case kBufferFormatRGB565:
return kFormatRGB565;
case kBufferFormatBGR565:
return kFormatBGR565;
case kBufferFormatRGBA5551:
return kFormatRGBA5551;
case kBufferFormatRGBA4444:
return kFormatRGBA4444;
case kBufferFormatRGBA8888Ubwc:
return kFormatRGBA8888Ubwc;
case kBufferFormatRGBX8888Ubwc:
return kFormatRGBX8888Ubwc;
case kBufferFormatBGR565Ubwc:
return kFormatBGR565Ubwc;
case kBufferFormatRGBA1010102Ubwc:
return kFormatRGBA1010102Ubwc;
case kBufferFormatRGBX1010102Ubwc:
return kFormatRGBX1010102Ubwc;
default:
return kFormatInvalid;
}
}
BufferFormat GetSDMCompFormat(LayerBufferFormat sdm_format) {
switch (sdm_format) {
case kFormatARGB8888:
return kBufferFormatARGB8888;
case kFormatRGBA8888:
return kBufferFormatRGBA8888;
case kFormatBGRA8888:
return kBufferFormatBGRA8888;
case kFormatXRGB8888:
return kBufferFormatXRGB8888;
case kFormatRGBX8888:
return kBufferFormatRGBX8888;
case kFormatBGRX8888:
return kBufferFormatBGRX8888;
case kFormatRGBA1010102:
return kBufferFormatRGBA1010102;
case kFormatARGB2101010:
return kBufferFormatARGB2101010;
case kFormatRGBX1010102:
return kBufferFormatRGBX1010102;
case kFormatXRGB2101010:
return kBufferFormatXRGB2101010;
case kFormatBGRA1010102:
return kBufferFormatBGRA1010102;
case kFormatABGR2101010:
return kBufferFormatABGR2101010;
case kFormatBGRX1010102:
return kBufferFormatBGRX1010102;
case kFormatXBGR2101010:
return kBufferFormatXBGR2101010;
case kFormatRGB888:
return kBufferFormatRGB888;
case kFormatBGR888:
return kBufferFormatBGR888;
case kFormatRGB565:
return kBufferFormatRGB565;
case kFormatBGR565:
return kBufferFormatBGR565;
case kFormatRGBA5551:
return kBufferFormatRGBA5551;
case kFormatRGBA4444:
return kBufferFormatRGBA4444;
case kFormatRGBA8888Ubwc:
return kBufferFormatRGBA8888Ubwc;
case kFormatRGBX8888Ubwc:
return kBufferFormatRGBX8888Ubwc;
case kFormatBGR565Ubwc:
return kBufferFormatBGR565Ubwc;
case kFormatRGBA1010102Ubwc:
return kBufferFormatRGBA1010102Ubwc;
case kFormatRGBX1010102Ubwc:
return kBufferFormatRGBX1010102Ubwc;
default:
return kBufferFormatInvalid;
}
}
} // namespace sdm

View File

@@ -0,0 +1,33 @@
SDM_PATH := ${WORKSPACE}/display/vendor/qcom/opensource/display-core/sdm
SDM_COMP_PATH := ${WORKSPACE}/display/vendor/qcom/opensource/display/sdm-composer
AM_CPPFLAGS += "-I$(SDM_PATH)/include"
AM_CPPFLAGS += "-I$(SDM_PATH)/../libdebug"
AM_CPPFLAGS += "-I$(SDM_PATH)/../include"
AM_CPPFLAGS += "-I${WORKSPACE}/display/vendor/qcom/opensource/commonsys-intf/display/include/"
AM_CPPFLAGS += "-I$(SDM_PATH)/../libmemutils"
AM_CPPFLAGS += "-I${PKG_CONFIG_SYSROOT_DIR}/${includedir}/qmi-framework"
AM_CPPFLAGS += "-I$(SDM_COMP_PATH)/include"
c_sources = sdm_comp_buffer_allocator.cpp \
sdm_comp_buffer_sync_handler.cpp \
sdm_comp_debugger.cpp \
sdm_comp_display_builtin.cpp \
sdm_comp_impl.cpp \
sdm_comp_interface.cpp \
sdm_comp_service.cpp \
sdm_comp_service_intf.cpp \
sdm_comp_service_client.cpp \
property_parser_interface.cpp \
property_parser_impl.cpp
lib_LTLIBRARIES = libsdmcomposer.la
libsdmcomposer_la_CC = @CC@
libsdmcomposer_la_SOURCES = $(c_sources)
libsdmcomposer_la_CFLAGS = $(COMMON_CFLAGS)
libsdmcomposer_la_CPPFLAGS = $(AM_CPPFLAGS) -DLOG_TAG=\"SDM\"
libsdmcomposer_la_LIBADD := ../../libformatutils/src/libformatutils.la \
../../liballocator/src/liballocator.la
libsdmcomposer_la_LDFLAGS := -shared -avoid-version -lsdmcore -lsdmutils -lsdmdal -ldl \
-lpthread -lmemutils -lsystemdq

View File

@@ -0,0 +1,134 @@
/*
Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the
disclaimer below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include <fstream>
#include "property_parser_impl.h"
#include "debug_handler.h"
#define __CLASS__ "PropertyParserImpl"
#define PERSIST_PROPERTY_FILE_PATH "/persist/display/vendor_display_build.prop"
#define PROPERTY_FILE_PATH "/usr/data/display/vendor_display_build.prop"
PropertyParserImpl *PropertyParserImpl::property_parser_impl_ = nullptr;
uint32_t PropertyParserImpl::ref_count_ = 0;
recursive_mutex PropertyParserImpl::recursive_mutex_;
PropertyParserImpl *PropertyParserImpl::GetInstance() {
if (!property_parser_impl_) {
property_parser_impl_= new PropertyParserImpl();
}
return property_parser_impl_;
}
int PropertyParserImpl::Init() {
lock_guard<recursive_mutex> obj(recursive_mutex_);
if (ref_count_) {
ref_count_++;
return 0;
}
bool prop_file_found = false;
std::fstream prop_file;
prop_file.open(PERSIST_PROPERTY_FILE_PATH, std::fstream::in);
if (prop_file.is_open()) {
prop_file_found = true;
DLOGI("found prop file %s", PERSIST_PROPERTY_FILE_PATH);
} else {
prop_file.open(PROPERTY_FILE_PATH, std::fstream::in);
if (prop_file.is_open()) {
DLOGI("found prop file %s", PROPERTY_FILE_PATH);
prop_file_found = true;
}
}
if (prop_file_found) {
std::string line = {};
while (std::getline(prop_file, line)) {
auto pos = line.find('=');
if (pos != std::string::npos) {
std::string prop_name = line.substr(0, pos);
std::string value = line.substr(pos + 1, std::string::npos);
DLOGI("%s=%s", prop_name.c_str(), value.c_str());
properties_map_.emplace(std::make_pair(prop_name, value));
}
}
}
ref_count_++;
return 0;
}
int PropertyParserImpl::Deinit() {
lock_guard<recursive_mutex> obj(recursive_mutex_);
if (ref_count_) {
ref_count_--;
if (!ref_count_) {
delete property_parser_impl_;
property_parser_impl_ = nullptr;
}
}
return 0;
}
int PropertyParserImpl::GetProperty(const char *property_name, int *value) {
lock_guard<recursive_mutex> obj(recursive_mutex_);
if (!property_name || !value)
return -EINVAL;
*value = 0;
auto it = properties_map_.find(property_name);
if (it != properties_map_.end())
*value = std::stoi(it->second);
else
return -ENOKEY;
return 0;
}
int PropertyParserImpl::GetProperty(const char *property_name, char *value) {
lock_guard<recursive_mutex> obj(recursive_mutex_);
if (!property_name || !value)
return -EINVAL;
auto it = properties_map_.find(property_name);
if (it != properties_map_.end())
std::snprintf(value, it->second.size(), "%s", it->second.c_str());
else
return -ENOKEY;
return 0;
}

View File

@@ -0,0 +1,70 @@
/*
Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the
disclaimer below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __PROPERTY_PARSER_IMPL_H__
#define __PROPERTY_PARSER_IMPL_H__
#include <errno.h>
#include <map>
#include <string>
#include <mutex>
#include "property_parser_interface.h"
using std::recursive_mutex;
using std::lock_guard;
class PropertyParserImpl : public PropertyParserInterface {
public:
static PropertyParserImpl *GetInstance();
virtual ~PropertyParserImpl() { }
int Init();
int Deinit();
virtual int GetProperty(const char *property_name, int *value);
virtual int GetProperty(const char *property_name, char *value);
private:
static PropertyParserImpl *property_parser_impl_;
static uint32_t ref_count_;
static recursive_mutex recursive_mutex_;
std::map<std::string, std::string> properties_map_ = {};
};
#endif // __PROPERTY_PARSER_IMPL_H__

View File

@@ -0,0 +1,77 @@
/*
Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the
disclaimer below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <utils/debug.h>
#include <utils/utils.h>
#include "property_parser_interface.h"
#include "property_parser_impl.h"
#define __CLASS__ "PropertyParserInterface"
int PropertyParserInterface::Create(PropertyParserInterface **intf) {
if (!intf) {
DLOGE("intf pointer is NULL");
return -EINVAL;
}
PropertyParserImpl *property_parser_impl = PropertyParserImpl::GetInstance();
if (!property_parser_impl) {
return -EINVAL;
}
int error = property_parser_impl->Init();
if (error != 0) {
DLOGE("Init failed with %d", error);
return error;
}
*intf = property_parser_impl;
return error;
}
int PropertyParserInterface::Destroy(PropertyParserInterface *intf) {
if (!intf) {
DLOGE("intf pointer is NULL");
return -EINVAL;
}
PropertyParserImpl *property_parser_impl = static_cast<PropertyParserImpl *>(intf);
int error = property_parser_impl->Deinit();
if (error != 0) {
DLOGE("Deinit failed with %d", error);
return error;
}
return 0;
}

View File

@@ -0,0 +1,184 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#include <core/buffer_allocator.h>
#include <utils/constants.h>
#include <utils/debug.h>
#include "sdm_comp_buffer_allocator.h"
#include "sdm_comp_debugger.h"
#include "formats.h"
#include "alloc_interface.h"
#define __CLASS__ "SDMCompBufferAllocator"
namespace sdm {
int SDMCompBufferAllocator::AllocateBuffer(BufferInfo *buffer_info) {
AllocInterface *alloc_intf = AllocInterface::GetInstance();
if (!alloc_intf) {
return -ENOMEM;
}
const BufferConfig &buffer_config = buffer_info->buffer_config;
AllocatedBufferInfo *alloc_buffer_info = &buffer_info->alloc_buffer_info;
BufferHandle *buffer_handle = new BufferHandle();
AllocData data = {};
data.width = buffer_config.width;
data.height = buffer_config.height;
data.format = GetSDMCompFormat(buffer_config.format);
data.uncached = true;
data.usage_hints.trusted_ui = true;
if (buffer_config.tui_demura) {
data.usage_hints.trusted_ui = false;
data.usage_hints.tui_demura = true;
}
int error = alloc_intf->AllocBuffer(&data, buffer_handle);
if (error != 0) {
DLOGE("Allocation failed WxHxF %dx%dx%d, uncached %d", data.width, data.height, data.format,
data.uncached);
delete buffer_handle;
return -ENOMEM;
}
alloc_buffer_info->fd = buffer_handle->fd;
alloc_buffer_info->stride = buffer_handle->stride_in_bytes;
alloc_buffer_info->aligned_width = buffer_handle->aligned_width;
alloc_buffer_info->aligned_height = buffer_handle->aligned_height;
alloc_buffer_info->format = buffer_config.format;
alloc_buffer_info->size = buffer_handle->size;
alloc_buffer_info->id = buffer_handle->buffer_id;
buffer_info->private_data = buffer_handle;
return 0;
}
int SDMCompBufferAllocator::FreeBuffer(BufferInfo *buffer_info) {
AllocInterface *alloc_intf = AllocInterface::GetInstance();
if (!alloc_intf) {
return -ENOMEM;
}
AllocatedBufferInfo &alloc_buffer_info = buffer_info->alloc_buffer_info;
BufferHandle *buffer_handle = reinterpret_cast<BufferHandle *>(buffer_info->private_data);
alloc_intf->FreeBuffer(buffer_handle);
delete buffer_handle;
alloc_buffer_info.fd = -1;
alloc_buffer_info.stride = 0;
alloc_buffer_info.size = 0;
buffer_info->private_data = NULL;
return 0;
}
uint32_t SDMCompBufferAllocator::GetBufferSize(BufferInfo *buffer_info) {
const BufferConfig &buffer_config = buffer_info->buffer_config;
uint32_t aligned_w = 0;
uint32_t aligned_h = 0;
BufferFormat buf_format = GetSDMCompFormat(buffer_config.format);
GetAlignedWidthAndHeight(buffer_config.width, buffer_config.height, &aligned_w, &aligned_h);
return (aligned_w * aligned_h * GetBpp(buf_format));
}
int SDMCompBufferAllocator::GetAllocatedBufferInfo(
const BufferConfig &buffer_config, AllocatedBufferInfo *allocated_buffer_info) {
uint32_t aligned_w = 0;
uint32_t aligned_h = 0;
BufferFormat buf_format = GetSDMCompFormat(buffer_config.format);
GetAlignedWidthAndHeight(buffer_config.width, buffer_config.height, &aligned_w, &aligned_h);
allocated_buffer_info->stride = aligned_w * GetBpp(buf_format);
allocated_buffer_info->aligned_width = aligned_w;
allocated_buffer_info->aligned_height = aligned_h;
allocated_buffer_info->size = (aligned_w * aligned_h * GetBpp(buf_format));
return 0;
}
int SDMCompBufferAllocator::GetBufferLayout(const AllocatedBufferInfo &buf_info, uint32_t stride[4],
uint32_t offset[4], uint32_t *num_planes) {
if (!num_planes) {
return -EINVAL;
}
BufferFormat buf_format = GetSDMCompFormat(buf_info.format);
*num_planes = 1;
stride[0] = static_cast<uint32_t>(buf_info.aligned_width * GetBpp(buf_format));
offset[0] = 0;
return 0;
}
void SDMCompBufferAllocator::GetAlignedWidthAndHeight(int width, int height,
uint32_t *aligned_width,
uint32_t *aligned_height) {
if (!aligned_width || !aligned_height) {
return;
}
*aligned_width = ALIGN(width, 32);
*aligned_height = ALIGN(height, 32);
}
int SDMCompBufferAllocator::SetBufferInfo(LayerBufferFormat format, int *target,
uint64_t *flags) {
return 0;
}
int SDMCompBufferAllocator::GetAlignedWidthAndHeight(int width, int height,
int format,
uint32_t alloc_type,
int *aligned_width,
int *aligned_height) {
return 0;
}
bool SDMCompBufferAllocator::GetSDMColorSpace(const int int_dataspace,
QtiDataspace *dataspace) {
return false;
}
LayerBufferFormat
SDMCompBufferAllocator::GetSDMFormat(const int32_t &source, const int32_t flags,
const int64_t compression_type) {
return kFormatInvalid;
}
DisplayError
SDMCompBufferAllocator::ColorMetadataToDataspace(Dataspace ds,
uint32_t *int_dataspace) {
return kErrorNone;
}
int32_t
SDMCompBufferAllocator::TranslateFromLegacyDataspace(const int32_t &legacy_ds) {
return 0;
}
} // namespace sdm

View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef __SDM_COMP_BUFFER_ALLOCATOR_H__
#define __SDM_COMP_BUFFER_ALLOCATOR_H__
#include <fcntl.h>
#include <sys/mman.h>
#include <core/sdm_types.h>
#include <core/buffer_allocator.h>
namespace sdm {
template <class Type>
inline Type ALIGN(Type x, Type align) {
return (x + align - 1) & ~(align - 1);
}
class SDMCompBufferAllocator : public BufferAllocator {
public:
virtual int AllocateBuffer(BufferInfo *buffer_info);
virtual int FreeBuffer(BufferInfo *buffer_info);
virtual uint32_t GetBufferSize(BufferInfo *buffer_info);
virtual int GetAllocatedBufferInfo(const BufferConfig &buffer_config,
AllocatedBufferInfo *allocated_buffer_info);
virtual int GetBufferLayout(const AllocatedBufferInfo &buf_info, uint32_t stride[4],
uint32_t offset[4], uint32_t *num_planes);
virtual int SetBufferInfo(LayerBufferFormat format, int *target,
uint64_t *flags);
virtual int GetAlignedWidthAndHeight(int width, int height, int format,
uint32_t alloc_type, int *aligned_width,
int *aligned_height);
virtual bool GetSDMColorSpace(const int int_dataspace,
QtiDataspace *dataspace);
virtual LayerBufferFormat GetSDMFormat(const int32_t &source,
const int32_t flags,
const int64_t compression_type);
virtual DisplayError ColorMetadataToDataspace(Dataspace ds,
uint32_t *int_dataspace);
virtual int32_t TranslateFromLegacyDataspace(const int32_t &legacy_ds);
private:
void GetAlignedWidthAndHeight(int width, int height, uint32_t *aligned_width,
uint32_t *aligned_height);
};
} // namespace sdm
#endif // __SDM_COMP_BUFFER_ALLOCATOR_H__

View File

@@ -0,0 +1,131 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
Changes from Qualcomm Innovation Center are provided under the following license:
Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the
disclaimer below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <errno.h>
#include <string.h>
#include <sync/sync.h>
#include <utils/constants.h>
#include <utils/debug.h>
#include "sdm_comp_debugger.h"
#include "sdm_comp_buffer_sync_handler.h"
#define __CLASS__ "SDMCompBufferSyncHandler"
namespace sdm {
int SDMCompBufferSyncHandler::SyncWait(int fd) {
return SyncWait(fd, 1000);
}
int SDMCompBufferSyncHandler::SyncWait(int fd, int timeout) {
int error = 0;
if (fd >= 0) {
error = sync_wait(fd, timeout);
if (error < 0) {
DLOGW("sync_wait() error on fd = %d, timeout = %dms. (errno = %d \"%s\")", fd, timeout, errno,
strerror(errno));
return error;
}
}
return 0;
}
int SDMCompBufferSyncHandler::SyncMerge(int fd1, int fd2, int *merged_fd) {
// Merge the two fences. In the case where one of the fences is not a
// valid fence (e.g. NO_FENCE) merge the one valid fence with itself so
// that a new fence with the given name is created.
// TODO(user): "SyncMerge"string should be replaced with user-defined string to represent
// why it is merged.
if (fd1 >= 0 && fd2 >= 0) {
*merged_fd = sync_merge("SyncMerge", fd1, fd2);
} else if (fd1 >= 0) {
*merged_fd = sync_merge("SyncMerge", fd1, fd1);
} else if (fd2 >= 0) {
*merged_fd = sync_merge("SyncMerge", fd2, fd2);
} else {
*merged_fd = -1;
return 0;
}
if (*merged_fd == -1) {
DLOGE("Sync merge error! fd1 %d fd2 %d", fd1, fd2);
return -EINVAL;
}
return 0;
}
bool SDMCompBufferSyncHandler::IsSyncSignaled(int fd) {
if (sync_wait(fd, 0) < 0) {
return false;
} else {
return true;
}
}
} // namespace sdm

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __SDM_COMP_BUFFER_SYNC_HANDLER_H__
#define __SDM_COMP_BUFFER_SYNC_HANDLER_H__
#include <sys/mman.h>
#include <fcntl.h>
#include <core/sdm_types.h>
#include <core/buffer_sync_handler.h>
#include <utils/fence.h>
namespace sdm {
class SDMCompBufferSyncHandler : public BufferSyncHandler {
public:
SDMCompBufferSyncHandler() { Fence::Set(this); }
virtual int SyncWait(int fd);
virtual int SyncWait(int fd, int timeout);
virtual int SyncMerge(int fd1, int fd2, int *merged_fd);
virtual bool IsSyncSignaled(int fd);
virtual void GetSyncInfo(int fd, std::ostringstream *os) { };
};
} // namespace sdm
#endif // __SDM_COMP_BUFFER_SYNC_HANDLER_H__

View File

@@ -0,0 +1,315 @@
/*
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
*
* Changes from Qualcomm Innovation Center are provided under the following license:
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdarg.h>
#ifdef ANDROID
#include <log/log.h>
#endif
#include <utils/constants.h>
#include "sdm_comp_debugger.h"
#include <string>
#include <cstring>
using std::string;
namespace sdm {
SDMCompDebugHandler SDMCompDebugHandler::debug_handler_;
SDMCompDebugHandler::SDMCompDebugHandler() {
DebugHandler::Set(SDMCompDebugHandler::Get());
PropertyParserInterface::Create(&prop_parser_intf_);
}
void SDMCompDebugHandler::DebugAll(bool enable, int verbose_level) {
if (enable) {
debug_handler_.log_mask_ = 0x7FFFFFFF;
if (verbose_level) {
// Enable verbose scalar logs only when explicitly enabled
debug_handler_.log_mask_[kTagScalar] = 0;
}
debug_handler_.verbose_level_ = verbose_level;
} else {
debug_handler_.log_mask_ = 0x1; // kTagNone should always be printed.
debug_handler_.verbose_level_ = 0;
}
DebugHandler::SetLogMask(debug_handler_.log_mask_);
}
void SDMCompDebugHandler::DebugResources(bool enable, int verbose_level) {
if (enable) {
debug_handler_.log_mask_[kTagResources] = 1;
debug_handler_.verbose_level_ = verbose_level;
} else {
debug_handler_.log_mask_[kTagResources] = 0;
debug_handler_.verbose_level_ = 0;
}
DebugHandler::SetLogMask(debug_handler_.log_mask_);
}
void SDMCompDebugHandler::DebugStrategy(bool enable, int verbose_level) {
if (enable) {
debug_handler_.log_mask_[kTagStrategy] = 1;
debug_handler_.verbose_level_ = verbose_level;
} else {
debug_handler_.log_mask_[kTagStrategy] = 0;
debug_handler_.verbose_level_ = 0;
}
DebugHandler::SetLogMask(debug_handler_.log_mask_);
}
void SDMCompDebugHandler::DebugCompManager(bool enable, int verbose_level) {
if (enable) {
debug_handler_.log_mask_[kTagCompManager] = 1;
debug_handler_.verbose_level_ = verbose_level;
} else {
debug_handler_.log_mask_[kTagCompManager] = 0;
debug_handler_.verbose_level_ = 0;
}
DebugHandler::SetLogMask(debug_handler_.log_mask_);
}
void SDMCompDebugHandler::DebugDriverConfig(bool enable, int verbose_level) {
if (enable) {
debug_handler_.log_mask_[kTagDriverConfig] = 1;
debug_handler_.verbose_level_ = verbose_level;
} else {
debug_handler_.log_mask_[kTagDriverConfig] = 0;
debug_handler_.verbose_level_ = 0;
}
DebugHandler::SetLogMask(debug_handler_.log_mask_);
}
void SDMCompDebugHandler::DebugRotator(bool enable, int verbose_level) {
if (enable) {
debug_handler_.log_mask_[kTagRotator] = 1;
debug_handler_.verbose_level_ = verbose_level;
} else {
debug_handler_.log_mask_[kTagRotator] = 0;
debug_handler_.verbose_level_ = 0;
}
DebugHandler::SetLogMask(debug_handler_.log_mask_);
}
void SDMCompDebugHandler::DebugScalar(bool enable, int verbose_level) {
if (enable) {
debug_handler_.log_mask_[kTagScalar] = 1;
debug_handler_.verbose_level_ = verbose_level;
} else {
debug_handler_.log_mask_[kTagScalar] = 0;
debug_handler_.verbose_level_ = 0;
}
DebugHandler::SetLogMask(debug_handler_.log_mask_);
}
void SDMCompDebugHandler::DebugQdcm(bool enable, int verbose_level) {
if (enable) {
debug_handler_.log_mask_[kTagQDCM] = 1;
debug_handler_.verbose_level_ = verbose_level;
} else {
debug_handler_.log_mask_[kTagQDCM] = 0;
debug_handler_.verbose_level_ = 0;
}
DebugHandler::SetLogMask(debug_handler_.log_mask_);
}
void SDMCompDebugHandler::DebugClient(bool enable, int verbose_level) {
if (enable) {
debug_handler_.log_mask_[kTagClient] = 1;
debug_handler_.verbose_level_ = verbose_level;
} else {
debug_handler_.log_mask_[kTagClient] = 0;
debug_handler_.verbose_level_ = 0;
}
DebugHandler::SetLogMask(debug_handler_.log_mask_);
}
void SDMCompDebugHandler::DebugDisplay(bool enable, int verbose_level) {
if (enable) {
debug_handler_.log_mask_[kTagDisplay] = 1;
debug_handler_.verbose_level_ = verbose_level;
} else {
debug_handler_.log_mask_[kTagDisplay] = 0;
debug_handler_.verbose_level_ = 0;
}
DebugHandler::SetLogMask(debug_handler_.log_mask_);
}
void SDMCompDebugHandler::DebugQos(bool enable, int verbose_level) {
if (enable) {
debug_handler_.log_mask_[kTagQOSClient] = 1;
debug_handler_.log_mask_[kTagQOSImpl] = 1;
debug_handler_.verbose_level_ = verbose_level;
} else {
debug_handler_.log_mask_[kTagQOSClient] = 0;
debug_handler_.log_mask_[kTagQOSImpl] = 0;
debug_handler_.verbose_level_ = 0;
}
DebugHandler::SetLogMask(debug_handler_.log_mask_);
}
void SDMCompDebugHandler::Error(const char *format, ...) {
va_list list;
va_start(list, format);
#ifdef ANDROID
__android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, list);
#else
char buffer[1024];
vsnprintf (buffer, 1024, format, list);
// TODO(user): print timestamp, process id and thread id
printf("E %s %s \n", LOG_TAG, buffer);
#endif
va_end(list);
}
void SDMCompDebugHandler::Warning(const char *format, ...) {
va_list list;
va_start(list, format);
#ifdef ANDROID
__android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, format, list);
#else
char buffer[1024];
vsnprintf (buffer, 1024, format, list);
printf("W %s %s \n", LOG_TAG, buffer);
#endif
va_end(list);
}
void SDMCompDebugHandler::Info(const char *format, ...) {
va_list list;
va_start(list, format);
#ifdef ANDROID
__android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, list);
#else
char buffer[1024];
vsnprintf (buffer, 1024, format, list);
printf("I %s %s \n", LOG_TAG, buffer);
#endif
va_end(list);
}
void SDMCompDebugHandler::Debug(const char *format, ...) {
va_list list;
va_start(list, format);
#ifdef ANDROID
__android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, format, list);
#else
char buffer[1024];
vsnprintf (buffer, 1024, format, list);
printf("D %s %s \n", LOG_TAG, buffer);
#endif
va_end(list);
}
void SDMCompDebugHandler::Verbose(const char *format, ...) {
if (debug_handler_.verbose_level_) {
va_list list;
va_start(list, format);
#ifdef ANDROID
__android_log_vprint(ANDROID_LOG_VERBOSE, LOG_TAG, format, list);
#else
char buffer[1024];
vsnprintf (buffer, 1024, format, list);
printf("V %s %s \n", LOG_TAG, buffer);
#endif
va_end(list);
}
}
void SDMCompDebugHandler::BeginTrace(const char *class_name, const char *function_name,
const char *custom_string) {
}
void SDMCompDebugHandler::EndTrace() {
}
int SDMCompDebugHandler::GetIdleTimeoutMs() {
return IDLE_TIMEOUT_DEFAULT_MS;
}
int SDMCompDebugHandler::GetProperty(const char *property_name, int *value) {
if (!property_name || !value)
return kErrorNotSupported;
if (prop_parser_intf_) {
return prop_parser_intf_->GetProperty(property_name, value);
}
auto it = properties_map_.find(property_name);
if (it != properties_map_.end())
*value = std::stoi(it->second);
else
return kErrorUndefined;
return kErrorNone;
}
int SDMCompDebugHandler::GetProperty(const char *property_name, char *value) {
if (!property_name || !value)
return kErrorNotSupported;
if (prop_parser_intf_) {
return prop_parser_intf_->GetProperty(property_name, value);
}
auto it = properties_map_.find(property_name);
if (it != properties_map_.end())
std::snprintf(value, it->second.size(), "%s", it->second.c_str());
else
return kErrorUndefined;
return kErrorNone;
}
int SDMCompDebugHandler::SetProperty(const char *property_name, const char *value) {
if (!property_name || !value) {
Error("SetProperty: failed to set property_name :%s :: %s\n", property_name, value);
return kErrorNotSupported;
}
properties_map_.emplace(std::string(property_name), std::string(value));
return kErrorNone;
}
} // namespace sdm

View File

@@ -0,0 +1,90 @@
/*
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
*
* Changes from Qualcomm Innovation Center are provided under the following license:
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __SDM_COMP_DEBUGGER_H__
#define __SDM_COMP_DEBUGGER_H__
#include <core/sdm_types.h>
#include <debug_handler.h>
#include "property_parser_interface.h"
#include <bitset>
#include <map>
namespace sdm {
using display::DebugHandler;
class SDMCompDebugHandler : public DebugHandler {
public:
SDMCompDebugHandler();
static inline DebugHandler* Get() { return &debug_handler_; }
static void DebugAll(bool enable, int verbose_level);
static void DebugResources(bool enable, int verbose_level);
static void DebugStrategy(bool enable, int verbose_level);
static void DebugCompManager(bool enable, int verbose_level);
static void DebugDriverConfig(bool enable, int verbose_level);
static void DebugRotator(bool enable, int verbose_level);
static void DebugScalar(bool enable, int verbose_level);
static void DebugQdcm(bool enable, int verbose_level);
static void DebugClient(bool enable, int verbose_level);
static void DebugQos(bool enable, int verbose_level);
static void DebugDisplay(bool enable, int verbose_level);
static void DebugAllocator(bool enable, int verbose_level);
static int GetIdleTimeoutMs();
virtual void Error(const char *format, ...);
virtual void Warning(const char *format, ...);
virtual void Info(const char *format, ...);
virtual void Debug(const char *format, ...);
virtual void Verbose(const char *format, ...);
virtual void BeginTrace(const char *class_name, const char *function_name,
const char *custom_string);
virtual void EndTrace();
virtual int GetProperty(const char *property_name, int *value);
virtual int GetProperty(const char *property_name, char *value);
int SetProperty(const char *property_name, const char *value);
private:
static SDMCompDebugHandler debug_handler_;
std::bitset<32> log_mask_;
int32_t verbose_level_;
std::map<std::string, std::string> properties_map_;
PropertyParserInterface *prop_parser_intf_ = nullptr;
};
} // namespace sdm
#endif // __SDM_COMP_DEBUGGER_H__

View File

@@ -0,0 +1,499 @@
/*
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Changes from Qualcomm Innovation Center are provided under the following license:
* Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#include <utils/constants.h>
#include <utils/debug.h>
#include <errno.h>
#include <unistd.h>
#include "sdm_comp_display_builtin.h"
#include "sdm_comp_debugger.h"
#include "formats.h"
#include "utils/fence.h"
#include "utils/rect.h"
#define __CLASS__ "SDMCompDisplayBuiltIn"
namespace sdm {
SDMCompDisplayBuiltIn::SDMCompDisplayBuiltIn(CoreInterface *core_intf,
CallbackInterface *callback, SDMCompDisplayType disp_type, int32_t disp_id)
: core_intf_(core_intf), callback_(callback), display_type_(disp_type),
display_id_(disp_id) {
}
int SDMCompDisplayBuiltIn::Init() {
int status = 0;
DisplayError error = core_intf_->CreateDisplay(display_id_, this, &display_intf_);
if (error != kErrorNone) {
if (kErrorDeviceRemoved == error) {
DLOGW("Display creation cancelled. Display %d-%d removed.", display_id_, display_type_);
return -ENODEV;
} else {
DLOGE("Display create failed. Error = %d display_id = %d event_handler = %p disp_intf = %p",
error, display_id_, this, &display_intf_);
return -EINVAL;
}
}
error = display_intf_->SetDisplayState(kStateOn, false /* tear_down */, NULL /* release_fence */);
if (error != kErrorNone) {
status = -EINVAL;
goto cleanup;
}
display_intf_->GetActiveConfig(&active_config_);
display_intf_->GetConfig(active_config_, &variable_info_);
display_intf_->SetCompositionState(kCompositionGPU, false);
CreateLayerSet();
error = display_intf_->GetStcColorModes(&stc_mode_list_);
if (error != kErrorNone) {
DLOGW("Failed to get Stc color modes, error %d", error);
stc_mode_list_.list.clear();
} else {
DLOGI("Stc mode count %d", stc_mode_list_.list.size());
}
PopulateColorModes();
return status;
cleanup:
DestroyLayerSet();
core_intf_->DestroyDisplay(display_intf_);
return status;
}
int SDMCompDisplayBuiltIn::Deinit() {
DisplayConfigFixedInfo fixed_info = {};
display_intf_->GetConfig(&fixed_info);
DisplayError error = kErrorNone;
if (!fixed_info.is_cmdmode) {
error = display_intf_->Flush(&layer_stack_);
if (error != kErrorNone && error != kErrorPermission) {
DLOGE("Flush failed. Error = %d", error);
return -EINVAL;
}
}
DestroyLayerSet();
error = core_intf_->DestroyDisplay(display_intf_);
if (error != kErrorNone) {
DLOGE("Display destroy failed. Error = %d", error);
return -EINVAL;
}
first_commit_ = true;
return 0;
}
int SDMCompDisplayBuiltIn::GetNumVariableInfoConfigs(uint32_t *count) {
if (!count) {
return -EINVAL;
}
DisplayError error = display_intf_->GetNumVariableInfoConfigs(count);
if (error != kErrorNone) {
return -EINVAL;
}
return 0;
}
int SDMCompDisplayBuiltIn::GetDisplayConfig(int config_idx,
DisplayConfigVariableInfo *variable_info) {
if (!variable_info) {
return -EINVAL;
}
DisplayError error = display_intf_->GetConfig(config_idx, variable_info);
if (error != kErrorNone) {
return -EINVAL;
}
return 0;
}
int SDMCompDisplayBuiltIn::SetDisplayConfig(int config_idx) {
DisplayError error = display_intf_->SetActiveConfig(config_idx);
if (error != kErrorNone) {
return -EINVAL;
}
active_config_ = config_idx;
error = display_intf_->GetConfig(config_idx, &variable_info_);
if (error != kErrorNone) {
return -EINVAL;
}
return 0;
}
void SDMCompDisplayBuiltIn::SetFrameBufferConfig() {
DisplayConfigVariableInfo fb_config;
display_intf_->GetFrameBufferConfig(&fb_config);
fb_config.x_pixels = mixer_config_.width;
fb_config.y_pixels = mixer_config_.height;
display_intf_->SetFrameBufferConfig(fb_config);
}
void SDMCompDisplayBuiltIn::SetMixerConfig(uint32_t width, uint32_t height) {
mixer_config_.width = width;
mixer_config_.height = height;
SetFrameBufferConfig();
}
int SDMCompDisplayBuiltIn::GetDisplayAttributes(SDMCompDisplayAttributes *display_attributes) {
if (!display_attributes) {
return -EINVAL;
}
// 1. When DS is not enabled, Layers are to be rendered at display resolution, which is same as
// LM config.
// 2. When DS is enabled (for AI scaler), layers are to be rendered at resolution less than
// display resolution. In this scenario, LM is reconfigured to new resolution.
// So in both scenarios, mixer attributes can be considered as Display attributes.
display_attributes->x_res = mixer_config_.width;
display_attributes->y_res = mixer_config_.height;
display_attributes->x_dpi = variable_info_.x_dpi;
display_attributes->y_dpi = variable_info_.y_dpi;
display_attributes->vsync_period = variable_info_.vsync_period_ns;
display_attributes->is_yuv = variable_info_.is_yuv;
display_attributes->fps = variable_info_.fps;
display_attributes->smart_panel = variable_info_.smart_panel;
return 0;
}
int SDMCompDisplayBuiltIn::ShowBuffer(BufferHandle *buf_handle, int32_t *retire_fence) {
int status = PrepareLayerStack(buf_handle);
if (status != 0) {
DLOGE("PrepareLayerStack failed %d", status);
return status;
}
status = ApplyCurrentColorModeWithRenderIntent();
if (status != 0) {
DLOGW("Failed to ApplyCurrentColorModeWithRenderIntent. Error = %d", status);
}
if (!validated_) {
DisplayError error = display_intf_->Prepare(&layer_stack_);
if (error != kErrorNone) {
DLOGW("Prepare failed. Error = %d", error);
return -EINVAL;
}
// Cache layer, if demura is configured, demura layer will be created in Prepare() function
demura_layer_ = nullptr;
for (auto &layer : layer_stack_.layers) {
if (layer->flags.is_demura) {
DLOGI("Demura layer is present");
demura_layer_ = layer;
}
}
// RC resources available after first cycle so enable skip_validate from 2nd cycle
if (!first_commit_) {
validated_ = true;
}
} else {
if (demura_layer_ != nullptr) {
layer_stack_.layers.push_back(demura_layer_);
}
}
DisplayError error = display_intf_->Commit(&layer_stack_);
if (error != kErrorNone) {
DLOGW("Commit failed. Error = %d", error);
return -EINVAL;
}
Layer *layer = layer_stack_.layers.at(0);
*retire_fence = Fence::Dup(layer_stack_.retire_fence);
buf_handle->consumer_fence_fd = Fence::Dup(layer->input_buffer.release_fence);
first_commit_ = false;
return 0;
}
void SDMCompDisplayBuiltIn::PopulateColorModes() {
for (uint32_t i = 0; i < stc_mode_list_.list.size(); i++) {
snapdragoncolor::ColorMode stc_mode = stc_mode_list_.list[i];
ColorPrimaries gamut = static_cast<ColorPrimaries>(stc_mode.gamut);
GammaTransfer gamma = static_cast<GammaTransfer>(stc_mode.gamma);
RenderIntent intent = static_cast<RenderIntent>(stc_mode.intent);
color_mode_map_[gamut][gamma][intent] = stc_mode;
}
}
int SDMCompDisplayBuiltIn::SetColorModeWithRenderIntent(struct ColorMode mode) {
if (mode.gamut < ColorPrimaries_BT709_5 || mode.gamut >= ColorPrimaries_Max) {
DLOGE("Invalid color primaries %d", mode.gamut);
return -EINVAL;
}
if (mode.gamma < Transfer_sRGB || mode.gamma >= Transfer_Max) {
DLOGE("Invalid gamma transfer %d", mode.gamma);
return -EINVAL;
}
if (mode.intent >= kRenderIntentMaxRenderIntent ) {
DLOGE("Invalid intent %d", mode.intent);
return -EINVAL;
}
if (current_mode_.gamut == mode.gamut && current_mode_.gamma == mode.gamma &&
current_mode_.intent == mode.intent) {
return 0;
}
current_mode_ = mode;
apply_mode_ = true;
Refresh();
return 0;
}
int SDMCompDisplayBuiltIn::GetStcColorModeFromMap(const ColorMode &mode,
snapdragoncolor::ColorMode *out_mode) {
if (!out_mode) {
DLOGE("Invalid parameter, out_mode is NULL");
return -EINVAL;
}
if (color_mode_map_.find(mode.gamut) == color_mode_map_.end()) {
DLOGE("Color Primary %d is not supported", mode.gamut);
return -ENOTSUP;
}
if (color_mode_map_[mode.gamut].find(mode.gamma) == color_mode_map_[mode.gamut].end()) {
DLOGE("Gamma Transfer %d is not supported", mode.gamma);
return -ENOTSUP;
}
auto iter = color_mode_map_[mode.gamut][mode.gamma].find(mode.intent);
if (iter != color_mode_map_[mode.gamut][mode.gamma].end()) {
// Found the mode
*out_mode = iter->second;
return 0;
}
DLOGW("Can't find color mode gamut %d gamma %d intent %d", mode.gamut, mode.gamma, mode.intent);
return -ENOTSUP;
}
int SDMCompDisplayBuiltIn::ApplyCurrentColorModeWithRenderIntent() {
if (stc_mode_list_.list.size() < 1) {
return 0;
}
if (!apply_mode_) {
return 0;
}
snapdragoncolor::ColorMode mode;
int ret = GetStcColorModeFromMap(current_mode_, &mode);
if (ret) {
DLOGW("Cannot find mode for current_color_mode_ gamut %d gamma %d intent %d ",
current_mode_.gamut, current_mode_.gamma, current_mode_.intent);
return 0;
}
DLOGI("Applying Stc mode (gamut %d gamma %d intent %d hw_assets.size %d)",
mode.gamut, mode.gamma, mode.intent, mode.hw_assets.size());
DisplayError error = display_intf_->SetStcColorMode(mode);
if (error != kErrorNone) {
DLOGE("Failed to apply Stc color mode: gamut %d gamma %d intent %d err %d",
mode.gamut, mode.gamma, mode.intent, error);
return 0;
}
apply_mode_ = false;
validated_ = false;
DLOGV_IF(kTagQDCM, "Successfully applied mode gamut = %d, gamma = %d, intent = %d",
current_mode_.gamut, current_mode_.gamma, current_mode_.intent);
return 0;
}
int SDMCompDisplayBuiltIn::GetColorModes(uint32_t *out_num_modes, struct ColorMode *out_modes) {
if (!out_num_modes || !out_modes) {
DLOGE("Invalid parameters");
return -EINVAL;
}
auto it = stc_mode_list_.list.begin();
*out_num_modes = std::min(*out_num_modes, UINT32(stc_mode_list_.list.size()));
ColorMode mode = {};
for (uint32_t i = 0; i < *out_num_modes; it++, i++) {
mode.gamut = static_cast<ColorPrimaries>(it->gamut);
mode.gamma = static_cast<GammaTransfer>(it->gamma);
mode.intent = static_cast<RenderIntent>(it->intent);
out_modes[i] = mode;
}
return 0;
}
void SDMCompDisplayBuiltIn::CreateLayerSet() {
Layer *layer = new Layer();
layer->flags.updating = 1;
layer->src_rect = LayerRect(0, 0, variable_info_.x_pixels, variable_info_.y_pixels);
layer->dst_rect = layer->src_rect;
layer->input_buffer = {};
layer->input_buffer.width = variable_info_.x_pixels;
layer->input_buffer.height = variable_info_.y_pixels;
layer->input_buffer.unaligned_width = variable_info_.x_pixels;
layer->input_buffer.unaligned_height = variable_info_.y_pixels;
layer->input_buffer.format = kFormatInvalid;
layer->input_buffer.planes[0].fd = -1;
layer->input_buffer.handle_id = -1;
layer->frame_rate = variable_info_.fps;
layer->blending = kBlendingPremultiplied;
layer_set_.push_back(layer);
}
void SDMCompDisplayBuiltIn::DestroyLayerSet() {
// Remove any layer if any and clear layer stack
for (Layer *layer : layer_set_)
delete layer;
layer_set_.clear();
}
int SDMCompDisplayBuiltIn::PrepareLayerStack(BufferHandle *buf_handle) {
if (!buf_handle) {
DLOGE("buf_handle pointer is null");
return -EINVAL;
}
Layer *layer = layer_set_.at(0);
layer->input_buffer.planes[0].fd = buf_handle->fd;
layer->input_buffer.planes[0].stride = buf_handle->stride_in_bytes;
layer->input_buffer.handle_id = buf_handle->buffer_id;
layer->input_buffer.buffer_id = buf_handle->buffer_id;
if (cached_buf_handle_.width == buf_handle->width &&
cached_buf_handle_.height == buf_handle->height &&
cached_buf_handle_.aligned_width == buf_handle->aligned_width &&
cached_buf_handle_.aligned_height == buf_handle->aligned_height &&
cached_buf_handle_.format == buf_handle->format &&
cached_buf_handle_.src_crop == buf_handle->src_crop) {
layer_stack_.layers.clear();
for (auto &it : layer_set_)
layer_stack_.layers.push_back(it);
return 0;
}
BufferFormat buf_format = GetSDMCompFormat(layer->input_buffer.format);
LayerRect src_crop = LayerRect(buf_handle->src_crop.left, buf_handle->src_crop.top,
buf_handle->src_crop.right, buf_handle->src_crop.bottom);
layer->input_buffer.width = buf_handle->width;
layer->input_buffer.height = buf_handle->height;
layer->input_buffer.unaligned_width = buf_handle->width;
layer->input_buffer.unaligned_height = buf_handle->height;
layer->input_buffer.format = GetSDMFormat(buf_handle->format);
layer->frame_rate = variable_info_.fps;
layer->blending = kBlendingPremultiplied;
layer->src_rect = LayerRect(0, 0, buf_handle->width, buf_handle->height);
if (IsValid(src_crop)) {
layer->src_rect = Intersection(src_crop, layer->src_rect);
}
layer->dst_rect.right = (float)mixer_config_.width;
layer->dst_rect.bottom = (float)mixer_config_.height;
DLOGI("WxHxF %dx%dx%d Crop[LTRB] [%.0f %.0f %.0f %.0f]", layer->input_buffer.width,
layer->input_buffer.height, layer->input_buffer.format, layer->src_rect.left,
layer->src_rect.top, layer->src_rect.right, layer->src_rect.bottom);
layer_stack_.layers.clear();
validated_ = false;
for (auto &it : layer_set_)
layer_stack_.layers.push_back(it);
cached_buf_handle_.width = buf_handle->width;
cached_buf_handle_.height = buf_handle->height;
cached_buf_handle_.aligned_width = buf_handle->aligned_width;
cached_buf_handle_.aligned_height = buf_handle->aligned_height;
cached_buf_handle_.format = buf_handle->format;
cached_buf_handle_.src_crop = buf_handle->src_crop;
return 0;
}
DisplayError SDMCompDisplayBuiltIn::HandleEvent(DisplayEvent event) {
DLOGI("Received display event %d", event);
switch (event) {
case kDisplayPowerResetEvent:
case kPanelDeadEvent:
if (callback_) {
callback_->OnError();
}
break;
default:
break;
}
return kErrorNone;
}
int SDMCompDisplayBuiltIn::SetPanelBrightness(float brightness_level) {
if (brightness_level < min_panel_brightness_) {
DLOGE("brightness level is invalid!! brightness_level %f, min_panel_brightness %f",
brightness_level, min_panel_brightness_);
return -EINVAL;
}
// if min_panel_brightness is not set, then set panel_brightness value as min_panel_brightness
if (min_panel_brightness_ == 0.0f) {
min_panel_brightness_ = brightness_level;
}
DisplayError err = display_intf_->SetPanelBrightness(brightness_level);
if (err != kErrorNone) {
return -EINVAL;
}
return 0;
}
int SDMCompDisplayBuiltIn::SetMinPanelBrightness(float min_brightness) {
if (min_brightness < 0.0f || min_brightness > 1.0) {
DLOGE("Invalid min brightness settings %f", min_brightness);
return -EINVAL;
}
min_panel_brightness_ = min_brightness;
return 0;
}
} // namespace sdm

View File

@@ -0,0 +1,113 @@
/*
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Changes from Qualcomm Innovation Center are provided under the following license:
* Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef __SDM_COMP_DISPLAY_BUILTIN_H__
#define __SDM_COMP_DISPLAY_BUILTIN_H__
#include <string>
#include <vector>
#include "utils/constants.h"
#include "core/display_interface.h"
#include "core/core_interface.h"
#include "core/sdm_types.h"
#include "sdm_comp_interface.h"
#include "private/color_params.h"
namespace sdm {
class SDMCompDisplayBuiltIn : public DisplayEventHandler {
public:
explicit SDMCompDisplayBuiltIn(CoreInterface *core_intf, CallbackInterface *callback,
SDMCompDisplayType disp_type, int32_t disp_id);
virtual ~SDMCompDisplayBuiltIn() { }
virtual DisplayError VSync(const DisplayEventVSync &vsync) { return kErrorNone; }
virtual DisplayError Refresh() { return kErrorNone; }
virtual DisplayError CECMessage(char *message) { return kErrorNone; }
virtual DisplayError HistogramEvent(int source_fd, uint32_t blob_id) { return kErrorNone; }
virtual DisplayError HandleEvent(DisplayEvent event);
virtual void MMRMEvent(bool restricted) { }
int Init();
int Deinit();
int GetDisplayAttributes(SDMCompDisplayAttributes *display_attributes);
int ShowBuffer(BufferHandle *buf_handle, int32_t *out_release_fence);
int SetColorModeWithRenderIntent(struct ColorMode mode);
int GetColorModes(uint32_t *out_num_modes, struct ColorMode *out_modes);
SDMCompDisplayType GetDisplayType() { return display_type_; }
int SetPanelBrightness(float brightness_level);
int SetMinPanelBrightness(float min_brightness);
int GetNumVariableInfoConfigs(uint32_t *count);
int GetDisplayConfig(int config_idx, DisplayConfigVariableInfo *variable_info);
int SetDisplayConfig(int config_idx);
void SetFrameBufferConfig();
void SetMixerConfig(uint32_t width, uint32_t height);
private:
void CreateLayerSet();
void DestroyLayerSet();
int PrepareLayerStack(BufferHandle *buf_handle);
void PopulateColorModes();
int GetStcColorModeFromMap(const ColorMode &mode, snapdragoncolor::ColorMode *out_mode);
int ApplyCurrentColorModeWithRenderIntent();
CoreInterface *core_intf_ = NULL;
DisplayInterface *display_intf_ = NULL;
DisplayConfigVariableInfo variable_info_ = {};
SDMCompMixerConfig mixer_config_ = {};
CallbackInterface *callback_ = NULL;
SDMCompDisplayType display_type_;
int display_id_ = -1;
LayerStack layer_stack_ = {};
uint32_t active_config_ = 0xFFFFFFFF;
bool apply_mode_ = false;
ColorMode current_mode_ = {};
snapdragoncolor::ColorModeList stc_mode_list_ = {};
typedef std::map<RenderIntent, snapdragoncolor::ColorMode> RenderIntentMap;
typedef std::map<GammaTransfer, RenderIntentMap> TransferMap;
std::map<ColorPrimaries, TransferMap> color_mode_map_ = {};
float min_panel_brightness_ = 0.0f;
bool validated_ = false;
bool first_commit_ = true;
std::vector<Layer *> layer_set_ = {};
BufferHandle cached_buf_handle_;
Layer *demura_layer_ = nullptr;
};
} // namespace sdm
#endif // __SDM_COMP_DISPLAY_BUILTIN_H__

View File

@@ -0,0 +1,511 @@
/*
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
Changes from Qualcomm Innovation Center are provided under the following license:
Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the
disclaimer below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include <thread>
#include "sdm_comp_impl.h"
#include "core/sdm_types.h"
#include "debug_handler.h"
#include "core/ipc_interface.h"
#include "vm_interface.h"
#include "private/generic_payload.h"
#include "sdm_comp_debugger.h"
#define __CLASS__ "SDMCompImpl"
namespace sdm {
SDMCompImpl *SDMCompImpl::sdm_comp_impl_ = nullptr;
SDMCompDisplayBuiltIn *SDMCompImpl::display_builtin_[kSDMCompDisplayTypeMax] = { nullptr };
uint32_t SDMCompImpl::ref_count_ = 0;
uint32_t SDMCompImpl::disp_ref_count_[kSDMCompDisplayTypeMax] = { 0 };
recursive_mutex recursive_mutex_;
SDMCompImpl *SDMCompImpl::GetInstance() {
if (!sdm_comp_impl_) {
sdm_comp_impl_= new SDMCompImpl();
}
return sdm_comp_impl_;
}
int SDMCompImpl::Init() {
lock_guard<recursive_mutex> obj(recursive_mutex_);
if (ref_count_) {
ref_count_++;
return 0;
}
int ret = SDMCompServiceIntf::Create(this, &sdm_comp_service_intf_);
if (ret != 0) {
DLOGW("SDMCompServiceIntf create failed!! %d\n", ret);
return ret;
}
ipc_intf_ = std::make_shared<SDMCompIPCImpl>();
DisplayError error = CoreInterface::CreateCore(&buffer_allocator_, &buffer_sync_handler_, NULL,
ipc_intf_, &core_intf_);
if (error != kErrorNone) {
DLOGE("Failed to create CoreInterface");
SDMCompServiceIntf::Destroy(sdm_comp_service_intf_);
return -EINVAL;
}
ref_count_++;
SDMCompDebugHandler *sdm_comp_dbg_handler =
static_cast<SDMCompDebugHandler *>(SDMCompDebugHandler::Get());
sdm_comp_dbg_handler->GetProperty(ENABLE_ROUNDED_CORNER, &rc_enabled_);
DLOGI("RC status: %d", rc_enabled_);
return 0;
}
int SDMCompImpl::Deinit() {
lock_guard<recursive_mutex> obj(recursive_mutex_);
if (ref_count_) {
ref_count_--;
if (!ref_count_) {
if (sdm_comp_service_intf_) {
SDMCompServiceIntf::Destroy(sdm_comp_service_intf_);
}
DisplayError error = CoreInterface::DestroyCore();
if (error != kErrorNone) {
DLOGE("Display core de-initialization failed. Error = %d", error);
return -EINVAL;
}
if (ipc_intf_) {
ipc_intf_->Deinit();
}
delete sdm_comp_impl_;
sdm_comp_impl_ = nullptr;
}
}
return 0;
}
int SDMCompImpl::CreateDisplay(SDMCompDisplayType display_type, CallbackInterface *callback,
Handle *disp_hnd) {
lock_guard<recursive_mutex> obj(recursive_mutex_);
if (!disp_hnd || display_type >= kSDMCompDisplayTypeMax) {
return -EINVAL;
}
if (display_builtin_[display_type]) {
*disp_hnd = display_builtin_[display_type];
disp_ref_count_[display_type]++;
return 0;
}
int status = 0;
HWDisplaysInfo hw_displays_info = {};
DisplayError error = core_intf_->GetDisplaysStatus(&hw_displays_info);
if (error != kErrorNone) {
DLOGE("Failed to get connected display list. Error = %d", error);
return -EINVAL;
}
for (auto &iter : hw_displays_info) {
auto &info = iter.second;
if (info.display_type != kBuiltIn) {
continue;
}
if ((display_type == kSDMCompDisplayTypePrimary && !info.is_primary) ||
(display_type != kSDMCompDisplayTypePrimary && info.is_primary)) {
continue;
}
if (!info.is_connected) {
continue;
}
DLOGI("Create builtin display, id = %d, type = %d", info.display_id, display_type);
SDMCompDisplayBuiltIn *display_builtin = new SDMCompDisplayBuiltIn(core_intf_, callback,
display_type, info.display_id);
status = display_builtin->Init();
if (status) {
delete display_builtin;
display_builtin = nullptr;
return status;
}
*disp_hnd = display_builtin;
display_builtin_[display_type] = display_builtin;
disp_ref_count_[display_type]++;
HandlePendingEvents();
break;
}
return status;
}
int SDMCompImpl::DestroyDisplay(Handle disp_hnd) {
lock_guard<recursive_mutex> obj(recursive_mutex_);
if (!disp_hnd) {
DLOGE("Display handle is NULL");
return -EINVAL;
}
SDMCompDisplayBuiltIn *sdm_comp_display = reinterpret_cast<SDMCompDisplayBuiltIn *>(disp_hnd);
SDMCompDisplayType disp_type = sdm_comp_display->GetDisplayType();
if (disp_ref_count_[disp_type]) {
disp_ref_count_[disp_type]--;
if (!disp_ref_count_[disp_type]) {
int status = sdm_comp_display->Deinit();
if (status != 0) {
return status;
}
DLOGI("Destroying builtin display %d", disp_type);
delete display_builtin_[disp_type];
display_builtin_[disp_type] = nullptr;
}
}
first_commit_ = true;
return 0;
}
int SDMCompImpl::GetDisplayAttributes(Handle disp_hnd,
SDMCompDisplayAttributes *display_attributes) {
lock_guard<recursive_mutex> obj(recursive_mutex_);
if (!disp_hnd || !display_attributes) {
DLOGE("Invalid input param disp_hnd %d, display_attributes %d", disp_hnd, display_attributes);
return -EINVAL;
}
SDMCompDisplayBuiltIn *sdm_comp_display = reinterpret_cast<SDMCompDisplayBuiltIn *>(disp_hnd);
return sdm_comp_display->GetDisplayAttributes(display_attributes);
}
int SDMCompImpl::ShowBuffer(Handle disp_hnd, BufferHandle *buf_handle, int32_t *retire_fence) {
lock_guard<recursive_mutex> obj(recursive_mutex_);
if (!disp_hnd || !buf_handle || !retire_fence) {
DLOGE("Invalid input param disp_hnd %d, buf_handle %d, retire_fence %d", disp_hnd, buf_handle,
retire_fence);
return -EINVAL;
}
SDMCompDisplayBuiltIn *sdm_comp_display = reinterpret_cast<SDMCompDisplayBuiltIn *>(disp_hnd);
// RC resources available after first cycle so enable RC need two commits.
if(rc_enabled_ && first_commit_) {
sdm_comp_display->ShowBuffer(buf_handle, retire_fence);
int ret = buffer_sync_handler_.SyncWait(*retire_fence);
if (ret) {
DLOGW("syncwait failed err:%d", ret);
}
close(*retire_fence);
close(buf_handle->consumer_fence_fd);
first_commit_ = false;
}
return sdm_comp_display->ShowBuffer(buf_handle, retire_fence);
}
int SDMCompImpl::SetColorModeWithRenderIntent(Handle disp_hnd, struct ColorMode mode) {
lock_guard<recursive_mutex> obj(recursive_mutex_);
if (!disp_hnd) {
DLOGE("Invalid input param disp_hnd %d", disp_hnd);
return -EINVAL;
}
SDMCompDisplayBuiltIn *sdm_comp_display = reinterpret_cast<SDMCompDisplayBuiltIn *>(disp_hnd);
return sdm_comp_display->SetColorModeWithRenderIntent(mode);
}
int SDMCompImpl::GetColorModes(Handle disp_hnd, uint32_t *out_num_modes,
struct ColorMode *out_modes) {
lock_guard<recursive_mutex> obj(recursive_mutex_);
if (!disp_hnd || !out_num_modes || !out_modes) {
DLOGE("Invalid input param disp_hnd %d, out_num_modes %d, out_modes %d", disp_hnd, out_num_modes,
out_modes);
return -EINVAL;
}
SDMCompDisplayBuiltIn *sdm_comp_display = reinterpret_cast<SDMCompDisplayBuiltIn *>(disp_hnd);
return sdm_comp_display->GetColorModes(out_num_modes, out_modes);
}
int SDMCompImpl::SetPanelBrightness(Handle disp_hnd, float brightness_level) {
if (!disp_hnd) {
DLOGE("Invalid input param disp_hnd %d", disp_hnd);
return -EINVAL;
}
SDMCompDisplayBuiltIn *sdm_comp_display = reinterpret_cast<SDMCompDisplayBuiltIn *>(disp_hnd);
return sdm_comp_display->SetPanelBrightness(brightness_level);
}
int SDMCompImpl::SetMinPanelBrightness(Handle disp_hnd, float min_brightness_level) {
if (!disp_hnd) {
DLOGE("Invalid input param disp_hnd %d", disp_hnd);
return -EINVAL;
}
SDMCompDisplayBuiltIn *sdm_comp_display = reinterpret_cast<SDMCompDisplayBuiltIn *>(disp_hnd);
int err = sdm_comp_display->SetMinPanelBrightness(min_brightness_level);
if (err == 0) {
SDMCompDisplayType disp_type = sdm_comp_display->GetDisplayType();
if (panel_brightness_[disp_type] < min_brightness_level) {
return SetPanelBrightness(disp_hnd, min_brightness_level);
}
}
return err;
}
int SDMCompImpl::OnEvent(SDMCompServiceEvents event, ...) {
int err = 0;
va_list arguments;
va_start(arguments, event);
switch (event) {
case kEventSetPanelBrightness: {
lock_guard<recursive_mutex> obj(recursive_mutex_);
SDMCompDisplayType disp_type = (SDMCompDisplayType)(va_arg(arguments, int));
float panel_brightness = FLOAT(va_arg(arguments, double));
if (display_builtin_[disp_type]) {
int err = display_builtin_[disp_type]->SetPanelBrightness(panel_brightness);
DLOGI("Setting panel brightness value %f on display type %d is %s", panel_brightness,
disp_type, err ? "failed" : "successful");
} else {
pending_events_.emplace(std::make_pair(kEventSetPanelBrightness, disp_type));
panel_brightness_[disp_type] = panel_brightness;
DLOGI("Cache panel brightness value %f on display type %d", panel_brightness, disp_type);
}
} break;
case kEventSetDisplayConfig: {
lock_guard<recursive_mutex> obj(recursive_mutex_);
SDMCompDisplayType disp_type = (SDMCompDisplayType)(va_arg(arguments, int));
SDMCompServiceDispConfigs *disp_configs =
reinterpret_cast<SDMCompServiceDispConfigs*>(va_arg(arguments, Handle));
if (display_builtin_[disp_type]) {
DLOGW("Setting display config is not supported in the middle of TUI session");
err = -ENOTSUP;
} else {
pending_events_.emplace(std::make_pair(kEventSetDisplayConfig, disp_type));
disp_configs_[disp_type] = *disp_configs;
DLOGI("Cache display h_total %d, vtotal %d, fps %d, %s panel for display type %d",
disp_configs->h_total, disp_configs->v_total, disp_configs->fps,
disp_configs->smart_panel ? "cmdmode" : "videomode", disp_type);
}
} break;
case kEventImportDemuraBuffers: {
lock_guard<recursive_mutex> obj(recursive_mutex_);
SDMCompServiceDemuraBufInfo *demura_buf_info =
reinterpret_cast<SDMCompServiceDemuraBufInfo*>(va_arg(arguments, Handle));
if (demura_buf_info && ipc_intf_) {
GenericPayload pl;
SDMCompServiceDemuraBufInfo* buffer = nullptr;
if ((err = pl.CreatePayload<SDMCompServiceDemuraBufInfo>(buffer))) {
DLOGE("Failed to create payload for BufferInfo, error = %d", err);
break;
}
buffer->hfc_buf_fd = demura_buf_info->hfc_buf_fd;
buffer->hfc_buf_size = demura_buf_info->hfc_buf_size;
buffer->panel_id = demura_buf_info->panel_id;
if ((err = ipc_intf_->SetParameter(kIpcParamSetDemuraBuffer, pl))) {
DLOGE("Failed to Cache the demura Buffers err %d", err);
break;
}
}
} break;
default:
err = -EINVAL;
break;
}
va_end(arguments);
return err;
}
void SDMCompImpl::HandlePendingEvents() {
for (auto pending_event : pending_events_) {
SDMCompDisplayType display_type = pending_event.second;
switch (pending_event.first) {
case kEventSetDisplayConfig: {
uint32_t num_configs = 0;
bool foundConfig = false;
int err = display_builtin_[display_type]->GetNumVariableInfoConfigs(&num_configs);
for (uint32_t config_idx = 0; config_idx < num_configs; config_idx++) {
DisplayConfigVariableInfo variable_info = {};
int err = display_builtin_[display_type]->GetDisplayConfig(config_idx, &variable_info);
if (err == 0) {
if (variable_info.h_total != disp_configs_[display_type].h_total ||
variable_info.v_total != disp_configs_[display_type].v_total ||
variable_info.fps != disp_configs_[display_type].fps ||
variable_info.smart_panel != disp_configs_[display_type].smart_panel) {
continue;
}
err = display_builtin_[display_type]->SetDisplayConfig(config_idx);
if (err != 0) {
continue;
}
foundConfig = true;
DLOGI("Setting display config idx %d, WxH %dx%d, fps %d, %s panel for display type %d",
config_idx, variable_info.x_pixels, variable_info.y_pixels, variable_info.fps,
disp_configs_[display_type].smart_panel ? "cmdmode" : "videomode", display_type);
display_builtin_[display_type]->SetMixerConfig(disp_configs_[display_type].mixer_width,
disp_configs_[display_type].mixer_height);
break;
}
}
// TODO(user): Need to fix why config not coming properly
if (!foundConfig) {
DLOGW("Failed to find the current config, set the default config as 0");
err = display_builtin_[display_type]->SetDisplayConfig(0);
if (err != 0) {
DLOGW("Failed to set config to secondary vm");
}
}
} break;
case kEventSetPanelBrightness: {
int err = display_builtin_[display_type]->SetPanelBrightness(panel_brightness_[display_type]);
DLOGI("SetPanelBrightness value %f on display type %d is %s", panel_brightness_[display_type],
display_type, err ? "failed" : "successful");
} break;
default:
break;
}
}
pending_events_.clear();
}
int SDMCompIPCImpl::SetParameter(IPCParams param, const GenericPayload &in) {
int ret = 0;
switch(param) {
case kIpcParamSetDemuraBuffer: {
SDMCompServiceDemuraBufInfo *buf_info = nullptr;
uint32_t sz = 0;
if ((ret = in.GetPayload(buf_info, &sz))) {
DLOGE("Failed to get input payload error = %d", ret);
return ret;
}
if (buf_info->hfc_buf_fd > 0) {
hfc_buf_info_.hfc_buf_fd = buf_info->hfc_buf_fd;
hfc_buf_info_.hfc_buf_size = buf_info->hfc_buf_size;
hfc_buf_info_.panel_id = buf_info->panel_id;
} else {
DLOGW("Failed to import HFC buffer");
}
} break;
default:
break;
}
return 0;
}
int SDMCompIPCImpl::GetParameter(IPCParams param, GenericPayload *out) {
(void)param;
(void)out;
DLOGE("GetParameter on param %d is not supported", param);
return -ENOTSUP;
}
int SDMCompIPCImpl::ProcessOps(IPCOps op, const GenericPayload &in, GenericPayload *out) {
lock_guard<recursive_mutex> obj(recursive_mutex_);
if (!out) {
return -EINVAL;
}
int ret = 0;
switch(op) {
case kIpcOpsImportBuffers: {
IPCImportBufInParams *buf_in_params = nullptr;
IPCImportBufOutParams *buf_out_params = nullptr;
uint32_t sz = 0;
if ((ret = in.GetPayload(buf_in_params, &sz))) {
DLOGE("Failed to get input payload error = %d", ret);
return ret;
}
if ((ret = out->GetPayload(buf_out_params, &sz))) {
DLOGE("Failed to get output payload error = %d", ret);
return ret;
}
if (buf_in_params->req_buf_type == kIpcBufferTypeDemuraHFC) {
IPCBufferInfo buf;
buf.fd = hfc_buf_info_.hfc_buf_fd;
buf.size = hfc_buf_info_.hfc_buf_size;
buf.panel_id = hfc_buf_info_.panel_id;
buf.mem_handle = -1;
buf_out_params->buffers.push_back(buf);
DLOGI("ProcessOps: hfc fd:%d and size :%u", hfc_buf_info_.hfc_buf_fd,
hfc_buf_info_.hfc_buf_size);
} else {
DLOGE("Invalid buffer type : %d", buf_in_params->req_buf_type);
}
} break;
default:
break;
}
return 0;
}
int SDMCompIPCImpl::Deinit() {
hfc_buf_info_ = {};
return 0;
}
} // namespace sdm

View File

@@ -0,0 +1,139 @@
/*
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
Changes from Qualcomm Innovation Center are provided under the following license:
Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the
disclaimer below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __SDM_COMP_IMPL_H__
#define __SDM_COMP_IMPL_H__
#include <core/core_interface.h>
#include <errno.h>
#include <mutex>
#include <condition_variable>
#include "sdm_comp_buffer_sync_handler.h"
#include "sdm_comp_buffer_allocator.h"
#include "sdm_comp_interface.h"
#include "core/display_interface.h"
#include "sdm_comp_service_intf.h"
#include "sdm_comp_display_builtin.h"
namespace sdm {
using std::recursive_mutex;
using std::lock_guard;
class SDMCompIPCImpl : public IPCIntf {
public:
int Init() { return 0; }
int Deinit();
int SetParameter(IPCParams param, const GenericPayload &in);
int GetParameter(IPCParams param, GenericPayload *out);
int ProcessOps(IPCOps op, const GenericPayload &in, GenericPayload *out);
private:
SDMCompServiceDemuraBufInfo hfc_buf_info_ {};
};
class SDMCompImpl : public SDMCompInterface, SDMCompServiceCbIntf {
public:
static SDMCompImpl *GetInstance();
virtual ~SDMCompImpl() { }
int Init();
int Deinit();
int SetParameter(IPCParams param, const GenericPayload &in);
int GetParameter(IPCParams param, GenericPayload *out);
int ProcessOps(IPCOps op, const GenericPayload &in, GenericPayload *out);
protected:
virtual int CreateDisplay(SDMCompDisplayType display_type, CallbackInterface *callback,
Handle *disp_hnd);
virtual int DestroyDisplay(Handle disp_hnd);
virtual int GetDisplayAttributes(Handle disp_hnd, SDMCompDisplayAttributes *display_attributes);
virtual int ShowBuffer(Handle disp_hnd, BufferHandle *buf_handle, int32_t *retire_fence);
virtual int SetColorModeWithRenderIntent(Handle disp_hnd, struct ColorMode mode);
virtual int GetColorModes(Handle disp_hnd, uint32_t *out_num_modes,
struct ColorMode *out_modes);
virtual int SetPanelBrightness(Handle disp_hnd, float brightness_level);
virtual int SetMinPanelBrightness(Handle disp_hnd, float min_brightness_level);
virtual int OnEvent(SDMCompServiceEvents event, ...);
void HandlePendingEvents();
static SDMCompImpl *sdm_comp_impl_;
static SDMCompDisplayBuiltIn *display_builtin_[kSDMCompDisplayTypeMax];
static uint32_t ref_count_;
static uint32_t disp_ref_count_[kSDMCompDisplayTypeMax];
CoreInterface *core_intf_ = nullptr;
SDMCompBufferAllocator buffer_allocator_;
SDMCompBufferSyncHandler buffer_sync_handler_;
SDMCompServiceIntf *sdm_comp_service_intf_ = nullptr;
float panel_brightness_[kSDMCompDisplayTypeMax] = {0.0f};
SDMCompServiceDispConfigs disp_configs_[kSDMCompDisplayTypeMax] = {};
std::map<SDMCompServiceEvents, SDMCompDisplayType> pending_events_ = {};
std::shared_ptr<SDMCompIPCImpl> ipc_intf_;
bool first_commit_ = true;
int rc_enabled_ = 0;
};
} // namespace sdm
#endif // __SDM_COMP_IMPL_H__

View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <utils/debug.h>
#include <utils/utils.h>
#include "sdm_comp_interface.h"
#include "sdm_comp_impl.h"
#define __CLASS__ "SDMCompInterface"
namespace sdm {
int SDMCompInterface::Create(SDMCompInterface **intf) {
if (!intf) {
DLOGE("intf pointer is NULL");
return -EINVAL;
}
SDMCompImpl *sdm_comp_impl = SDMCompImpl::GetInstance();
if (!sdm_comp_impl) {
return -EINVAL;
}
int error = sdm_comp_impl->Init();
if (error != 0) {
DLOGE("Init failed with %d", error);
return error;
}
*intf = sdm_comp_impl;
return error;
}
int SDMCompInterface::Destroy(SDMCompInterface *intf) {
if (!intf) {
DLOGE("intf pointer is NULL");
return -EINVAL;
}
SDMCompImpl *sdm_comp_impl = static_cast<SDMCompImpl *>(intf);
int error = sdm_comp_impl->Deinit();
if (error != 0) {
DLOGE("Deinit failed with %d", error);
return error;
}
return 0;
}
} // namespace sdm

View File

@@ -0,0 +1,656 @@
/*
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
Changes from Qualcomm Innovation Center are provided under the following license:
Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the
disclaimer below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <sys/poll.h>
#include <sys/mman.h>
#include <systemdq/sd-bus.h>
#include <mutex>
#include <algorithm>
#include <cstring>
#include <string>
#include "sdm_comp_service.h"
#include "sdm_comp_debugger.h"
#include "display_properties.h"
#define __CLASS__ "SDMCompService"
#define DISPLAY_SERVICE_FILE_WITH_PARAM "display@.service"
#define DISPLAY_SERVICE_FILE_NO_PARAM "display.service"
#define SYSTEMD_ESCAPE_BIN "/bin/systemd-escape"
namespace sdm {
std::mutex SDMCompService::qrtr_lock_;
std::vector <SDMCompServiceCbIntf *> SDMCompService::callbacks_ = {};
int SDMCompService::qrtr_fd_ = -1;
DynLib SDMCompService::qrtr_lib_ = {};
MemBuf *SDMCompService::mem_buf_ = nullptr;
DynLib SDMCompService::extension_lib_ = {};
CreateSDMCompExtnIntf SDMCompService::create_sdm_comp_extn_intf_ = nullptr;
DestroySDMCompExtnIntf SDMCompService::destroy_sdm_comp_extn_intf_ = nullptr;
SDMCompServiceExtnIntf *SDMCompService::sdm_comp_service_extn_intf_ = nullptr;
int SDMCompService::exit_thread_fd_ = -1;
std::thread SDMCompService::event_thread_ = {};
QrtrOpen SDMCompService::qrtr_open_ = nullptr;
QrtrClose SDMCompService::qrtr_close_ = nullptr;
QrtrSendTo SDMCompService::qrtr_send_to_ = nullptr;
QrtrPublish SDMCompService::qrtr_publish_ = nullptr;
QrtrBye SDMCompService::qrtr_bye_ = nullptr;
QrtrDecode SDMCompService::qrtr_decode_ = nullptr;
std::mutex SDMCompService::pending_cmd_lock_;
std::multimap<int, struct qrtr_packet> SDMCompService::pending_commands_ = {};
static bool IsModuleLoaded() {
FILE *fp = popen("cat /proc/modules | grep msm_drm", "r");
if (fp == NULL) {
return false;
}
char buf[16];
if (fread (buf, 1, sizeof (buf), fp) > 0) {
pclose(fp);
return true;
}
pclose(fp);
return false;
}
static int LoadModule(const std::string &service_file_path, const std::string &argument) {
if (IsModuleLoaded()) {
return 0;
}
sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus_message *msg = NULL;
sd_bus *bus = NULL;
char systemd_escape_cmd[256] = {};
char modified_arg[256] = {};
std::string mod_service_file_path(service_file_path);
if (!argument.empty()) {
FILE *cmd_file;
snprintf(systemd_escape_cmd, sizeof(systemd_escape_cmd), "%s '%s' 2>&1",
SYSTEMD_ESCAPE_BIN, argument.c_str());
DLOGI("systemd_escape_cmd %s", systemd_escape_cmd);
cmd_file = popen(systemd_escape_cmd, "r");
if (!cmd_file) {
DLOGI("cmd file is NULL");
return -EINVAL;
}
if (fgets(modified_arg, sizeof(modified_arg), cmd_file) == NULL) {
DLOGE("fgets returned null");
return -EINVAL;
}
DLOGI("modified_arg %s", modified_arg);
pclose(cmd_file);
std::size_t pos = mod_service_file_path.find_first_of('@');
if (pos == std::string::npos) {
DLOGE("Invalid service file path!!");
return -EINVAL;
}
mod_service_file_path.insert(pos + 1, modified_arg);
pos = mod_service_file_path.find_first_of('\n');
if (pos != std::string::npos) {
mod_service_file_path.erase(pos, 1);
}
}
DLOGI("service file path %s", mod_service_file_path.c_str());
int err = sd_bus_open_system(&bus);
if (err < 0) {
DLOGE("Failed to connect to system bus err %d %s", err, strerror(errno));
return err;
}
err = sd_bus_call_method(bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"StartUnit",
&error,
&msg,
"ss",
mod_service_file_path.c_str(),
"replace");
if (err < 0) {
DLOGE("sd_bus_call_method failed with err %d %s", err, strerror(errno));
}
sd_bus_error_free(&error);
sd_bus_message_unref(msg);
sd_bus_unref(bus);
DLOGI("Loading kernel module is %s", (err < 0) ? "failed" : "successful");
return ((err < 0) ? err : 0);
}
int SDMCompService::RegisterCallback(SDMCompServiceCbIntf *callback) {
std::lock_guard<std::mutex> lock(qrtr_lock_);
if (qrtr_fd_ > 0) {
callbacks_.push_back(callback);
if (callback) {
std::thread(HandlePendingCommands).detach();
}
return 0;
}
int err = 0;
// Try to load qrtr library & get handle to its interface.
if (qrtr_lib_.Open("libqrtr.so.1.0.0")) {
if (!qrtr_lib_.Sym("qrtr_open", reinterpret_cast<void **>(&qrtr_open_)) ||
!qrtr_lib_.Sym("qrtr_close", reinterpret_cast<void **>(&qrtr_close_)) ||
!qrtr_lib_.Sym("qrtr_sendto", reinterpret_cast<void **>(&qrtr_send_to_)) ||
!qrtr_lib_.Sym("qrtr_publish", reinterpret_cast<void **>(&qrtr_publish_)) ||
!qrtr_lib_.Sym("qrtr_bye", reinterpret_cast<void **>(&qrtr_bye_)) ||
!qrtr_lib_.Sym("qrtr_decode", reinterpret_cast<void **>(&qrtr_decode_))) {
DLOGE("Unable to load symbols, error = %s", qrtr_lib_.Error());
return-ENOENT;
}
} else {
DLOGE("Unable to load libqrtr.so, error = %s", qrtr_lib_.Error());
return-ENOENT;
}
qrtr_fd_ = qrtr_open_(0);
if (qrtr_fd_ < 0) {
DLOGE("Failed to create qrtr socket");
err = -EINVAL;
goto cleanup;
}
err = qrtr_publish_(qrtr_fd_, SDM_COMP_SERVICE_ID, SDM_COMP_SERVICE_VERSION,
SDM_COMP_SERVICE_INSTANCE);
if (err < 0) {
DLOGE("failed to publish rmtfs service %d", err);
goto cleanup;
}
err = MemBuf::GetInstance(&mem_buf_);
if (err != 0) {
DLOGE("MemBuf::GetInstance failed!! %d\n", err);
goto cleanup;
}
// Try to load extension library & get handle to its interface.
if (extension_lib_.Open(EXTN_LIB_NAME)) {
if (!extension_lib_.Sym(CREATE_SDMCOMP_SERVICE_EXTN,
reinterpret_cast<void **>(&create_sdm_comp_extn_intf_)) ||
!extension_lib_.Sym(DESTROY_SDMCOMP_SERVICE_EXTN,
reinterpret_cast<void **>(&destroy_sdm_comp_extn_intf_))) {
DLOGE("Unable to load symbols, error = %s", extension_lib_.Error());
err = -ENOENT;
goto cleanup;
}
err = create_sdm_comp_extn_intf_(qrtr_fd_, &sdm_comp_service_extn_intf_);
if (err != 0) {
DLOGE("Unable to create sdm comp service extenstion interface");
goto cleanup;
}
} else {
DLOGW("Unable to load = %s, error = %s", EXTN_LIB_NAME, extension_lib_.Error());
}
// Create an eventfd to be used to unblock the poll system call when
// a thread is exiting.
exit_thread_fd_ = Sys::eventfd_(0, 0);
event_thread_ = std::thread(&SDMCompService::QRTREventHandler);
event_thread_.detach();
callbacks_.push_back(callback);
if (callback) {
HandlePendingCommands();
}
return 0;
cleanup:
UnRegisterCallback(callback);
return err;
}
int SDMCompService::UnRegisterCallback(SDMCompServiceCbIntf *callback) {
std::lock_guard<std::mutex> lock(qrtr_lock_);
auto it = std::find(callbacks_.begin(), callbacks_.end(), callback);
if (it != callbacks_.end()) {
callbacks_.erase(it);
}
if (!callbacks_.empty()) {
return 0;
}
uint64_t exit_value = 1;
if (exit_thread_fd_ > 0) {
ssize_t write_size = Sys::write_(exit_thread_fd_, &exit_value, sizeof(uint64_t));
if (write_size != sizeof(uint64_t)) {
DLOGW("Error triggering exit fd (%d). write size = %d, error = %s", exit_thread_fd_,
write_size, strerror(errno));
}
if (event_thread_.joinable()) {
event_thread_.join();
}
Sys::close_(exit_thread_fd_);
}
if (destroy_sdm_comp_extn_intf_) {
destroy_sdm_comp_extn_intf_(sdm_comp_service_extn_intf_);
}
if (mem_buf_) {
MemBuf::PutInstance();
}
if (qrtr_fd_ > 0) {
qrtr_bye_(qrtr_fd_, SDM_COMP_SERVICE_ID, SDM_COMP_SERVICE_VERSION,
SDM_COMP_SERVICE_INSTANCE);
qrtr_close_(qrtr_fd_);
}
return 0;
}
void SDMCompService::SendResponse(int node, int port, const Response &rsp) {
int ret = qrtr_send_to_(qrtr_fd_, node, port, &rsp, sizeof(rsp));
if (ret < 0) {
DLOGE("Failed to send response for command %d ret %d", rsp.id, ret);
}
DLOGI("Sent response for the command id %d size %d", rsp.id, sizeof(rsp));
}
void SDMCompService::HandleImportDemuraBuffers(const struct qrtr_packet &qrtr_pkt, Response *rsp) {
Command *cmd = reinterpret_cast<Command *>(qrtr_pkt.data);
rsp->id = cmd->id;
DemuraMemInfo *demura_mem_info = &cmd->cmd_export_demura_buf.demura_mem_info;
SDMCompServiceDemuraBufInfo demura_buf_info = {};
int demura_enabled = 0;
SDMCompDebugHandler *sdm_comp_dbg_handler =
static_cast<SDMCompDebugHandler *>(SDMCompDebugHandler::Get());
sdm_comp_dbg_handler->GetProperty(ENABLE_DEMURA, &demura_enabled);
if (!demura_enabled) {
DLOGI("demura is not enabled on TVM");
return;
}
DLOGI("hfc mem handle :%d", demura_mem_info->hfc_mem_hdl);
if (demura_mem_info->hfc_mem_hdl != -1) {
VmParams vm_params;
std::bitset<kVmPermissionMax> buf_perm = { 0 };
buf_perm.set(kVmPermissionRead);
buf_perm.set(kVmPermissionWrite);
vm_params.emplace(kVmTypeTrusted, buf_perm);
vm_params.emplace(kVmTypePrimary, buf_perm);
int error = mem_buf_->Import(demura_mem_info->hfc_mem_hdl, vm_params,
&demura_buf_info.hfc_buf_fd);
if (error != 0) {
DLOGW("Import failed with %d", error);
rsp->status = error;
return;
}
demura_buf_info.hfc_buf_size = demura_mem_info->hfc_mem_size;
demura_buf_info.panel_id = demura_mem_info->panel_id;
DLOGI("hfc fd:%d and size :%u", demura_buf_info.hfc_buf_fd, demura_buf_info.hfc_buf_size);
}
for (auto callback : callbacks_) {
if (callback) {
int err = callback->OnEvent(kEventImportDemuraBuffers, &demura_buf_info);
DLOGI("ImportDemuraBuffers on panel_id %lu is %s", demura_mem_info->panel_id,
err ? "failed" : "successful");
rsp->status = err;
}
}
}
void SDMCompService::HandleSetBacklight(const struct qrtr_packet &qrtr_pkt, Response *rsp) {
Command *cmd = reinterpret_cast<Command *>(qrtr_pkt.data);
rsp->id = cmd->id;
CmdSetBacklight *cmd_backlight = reinterpret_cast<CmdSetBacklight*>(&cmd->cmd_set_backlight);
SDMCompDisplayType sdm_comp_disp_type = GetSDMCompDisplayType(cmd_backlight->disp_type);
if (sdm_comp_disp_type == kSDMCompDisplayTypeMax) {
DLOGE("Invalid display_type %d", sdm_comp_disp_type);
rsp->status = -EINVAL;
return;
}
for (auto callback : callbacks_) {
if (callback) {
int err = callback->OnEvent(kEventSetPanelBrightness, sdm_comp_disp_type,
cmd_backlight->brightness);
rsp->status = err;
}
}
}
void SDMCompService::HandleSetDisplayConfigs(const struct qrtr_packet &qrtr_pkt, Response *rsp) {
Command *cmd = reinterpret_cast<Command *>(qrtr_pkt.data);
rsp->id = cmd->id;
CmdSetDisplayConfigs *cmd_disp_configs =
reinterpret_cast<CmdSetDisplayConfigs*>(&cmd->cmd_set_disp_configs);
SDMCompDisplayType sdm_comp_disp_type = GetSDMCompDisplayType(cmd_disp_configs->disp_type);
if (sdm_comp_disp_type == kSDMCompDisplayTypeMax) {
DLOGE("Invalid display_type %d", sdm_comp_disp_type);
rsp->status = -EINVAL;
return;
}
for (auto callback : callbacks_) {
if (callback) {
SDMCompServiceDispConfigs disp_configs = {};
disp_configs.h_total = cmd_disp_configs->h_total;
disp_configs.v_total = cmd_disp_configs->v_total;
disp_configs.fps = cmd_disp_configs->fps;
disp_configs.smart_panel = cmd_disp_configs->smart_panel;
disp_configs.mixer_width = cmd_disp_configs->mixer_width;
disp_configs.mixer_height = cmd_disp_configs->mixer_height;
int err = callback->OnEvent(kEventSetDisplayConfig, sdm_comp_disp_type, &disp_configs);
rsp->status = err;
}
}
}
void SDMCompService::HandleSetProperties(const struct qrtr_packet &qrtr_pkt, Response *rsp) {
Command *cmd = reinterpret_cast<Command *>(qrtr_pkt.data);
rsp->id = cmd->id;
CmdSetProperties *cmd_set_props =
reinterpret_cast<CmdSetProperties *>(&cmd->cmd_set_properties);
for (int i = 0; i < cmd_set_props->props.count; i++) {
SDMCompDebugHandler *sdm_comp_dbg_handler =
static_cast<SDMCompDebugHandler *>(SDMCompDebugHandler::Get());
sdm_comp_dbg_handler->SetProperty(cmd_set_props->props.property_list[i].prop_name,
cmd_set_props->props.property_list[i].value);
DLOGI("prop idx : %d, name: %s, value :%s", i, cmd_set_props->props.property_list[i].prop_name,
cmd_set_props->props.property_list[i].value);
}
}
void SDMCompService::HandleSetPanelBootParams(const struct qrtr_packet &qrtr_pkt, Response *rsp) {
Command *cmd = reinterpret_cast<Command *>(qrtr_pkt.data);
rsp->id = cmd->id;
CmdSetPanelBootParam *cmd_set_panel_boot_param =
reinterpret_cast<CmdSetPanelBootParam *>(&cmd->cmd_set_panel_boot_param);
DLOGI("panel_boot_param_string %s", cmd_set_panel_boot_param->panel_boot_string);
int ret = 0;
std::string panel_boot_str(cmd_set_panel_boot_param->panel_boot_string);
if (!panel_boot_str.empty())
ret = LoadModule(DISPLAY_SERVICE_FILE_WITH_PARAM, panel_boot_str);
else
ret = LoadModule(DISPLAY_SERVICE_FILE_NO_PARAM, panel_boot_str);
if (ret != 0) {
DLOGE("Failed loading kernel module %d", ret);
rsp->status = -EINVAL;
return;
}
}
void SDMCompService::CommandHandler(const struct qrtr_packet &qrtr_pkt) {
Response rsp = {};
rsp.status = -EINVAL;
if (qrtr_pkt.data_len < sizeof(Command)) {
DLOGW("Invalid packet!! length %zu command buffer size %d", qrtr_pkt.data_len, sizeof(Command));
SendResponse(qrtr_pkt.node, qrtr_pkt.port, rsp);
return;
}
Command *cmd = reinterpret_cast<Command *>(qrtr_pkt.data);
if (!cmd) {
DLOGE("cmd is null!!\n");
SendResponse(qrtr_pkt.node, qrtr_pkt.port, rsp);
return;
}
rsp.id = cmd->id;
if (cmd->id < kCmdMax) {
if (cmd->version > VM_INTF_VERSION) {
DLOGE("Invalid vm interface client version %x, supported version %x", cmd->version,
VM_INTF_VERSION);
SendResponse(qrtr_pkt.node, qrtr_pkt.port, rsp);
return;
}
// Command kCmdSetPanelBootParams is handled in sdm comp service. So valid client
// is not needed to handle it.
if ((cmd->id != kCmdSetPanelBootParams) && (cmd->id != kCmdSetProperties) &&
!IsRegisteredClientValid()) {
std::lock_guard<std::mutex> lock(pending_cmd_lock_);
struct qrtr_packet qrtr_pkt_temp = qrtr_pkt;
qrtr_pkt_temp.data = (void *)new uint8_t[sizeof(Command)];
qrtr_pkt_temp.data_len = sizeof(Command);
memcpy(qrtr_pkt_temp.data, qrtr_pkt.data, qrtr_pkt_temp.data_len);
pending_commands_.emplace(std::make_pair(cmd->id, qrtr_pkt_temp));
DLOGI("Registered client invalid handle the command %d later", cmd->id);
rsp.status = 0;
SendResponse(qrtr_pkt.node, qrtr_pkt.port, rsp);
return;
}
}
DLOGI("Received command %d from client fd %d node %d port %d", cmd->id, qrtr_fd_, qrtr_pkt.node,
qrtr_pkt.port);
switch (cmd->id) {
case kCmdExportDemuraBuffers:
HandleImportDemuraBuffers(qrtr_pkt, &rsp);
break;
case kCmdSetBacklight: {
HandleSetBacklight(qrtr_pkt, &rsp);
} break;
case kCmdSetDisplayConfig: {
HandleSetDisplayConfigs(qrtr_pkt, &rsp);
} break;
case kCmdSetProperties: {
HandleSetProperties(qrtr_pkt, &rsp);
} break;
case kCmdSetPanelBootParams: {
HandleSetPanelBootParams(qrtr_pkt, &rsp);
} break;
default:
if (sdm_comp_service_extn_intf_) {
sdm_comp_service_extn_intf_->CommandHandler(qrtr_pkt);
}
break;
}
if (cmd->id < kCmdMax) {
SendResponse(qrtr_pkt.node, qrtr_pkt.port, rsp);
}
}
void SDMCompService::QRTREventHandler() {
struct sockaddr_qrtr soc_qrtr = {};
struct qrtr_packet qrtr_pkt = {};
socklen_t soc_len;
char buf[4096] = {};
struct pollfd poll_fd[2] = {-1};
qrtr_lock_.lock();
// Add qrtr socket fd
poll_fd[0].fd = qrtr_fd_;
poll_fd[0].revents = 0;
poll_fd[0].events = POLLIN | POLLERR;
qrtr_lock_.unlock();
// Add event fd to exit the thread
poll_fd[1].fd = exit_thread_fd_;
poll_fd[1].revents = 0;
poll_fd[1].events = POLLIN;
// Clear any existing data
Sys::pread_(exit_thread_fd_, buf, 4096, 0);
DLOGI("Start listening to the client request %d", SDM_COMP_SERVICE_ID);
while(!callbacks_.empty()) {
int ret = poll(poll_fd, sizeof(poll_fd) / sizeof(struct pollfd), -1);
if (ret < 0) {
continue;
}
if (!(poll_fd[0].revents & POLLIN || poll_fd[0].revents & POLLERR)) {
continue;
}
soc_len = sizeof(soc_qrtr);
ret = recvfrom(qrtr_fd_, buf, sizeof(buf), 0, (sockaddr *)&soc_qrtr,
&soc_len);
if (ret < 0) {
if (errno == EAGAIN) {
continue;
}
return;
}
{
std::lock_guard<std::mutex> lock(qrtr_lock_);
ret = qrtr_decode_(&qrtr_pkt, buf, ret, &soc_qrtr);
if (ret < 0) {
DLOGE("failed to decode incoming message");
continue;
}
switch (qrtr_pkt.type) {
case QRTR_TYPE_DEL_CLIENT:
DLOGI("Client with port %d node %d is disconnected", qrtr_pkt.port, qrtr_pkt.node);
break;
case QRTR_TYPE_BYE:
DLOGI("System server goes down");
break;
case QRTR_TYPE_DATA:
CommandHandler(qrtr_pkt);
break;
}
}
}
DLOGI("Exiting qrtr event thread");
}
SDMCompDisplayType SDMCompService::GetSDMCompDisplayType(DisplayType disp_type) {
switch(disp_type) {
case kDisplayTypePrimary:
return kSDMCompDisplayTypePrimary;
case kDisplayTypeSecondary1:
return kSDMCompDisplayTypeSecondary1;
default:
return kSDMCompDisplayTypeMax;
}
}
void SDMCompService::HandlePendingCommands() {
std::lock_guard<std::mutex> lock(pending_cmd_lock_);
Response rsp = {};
for (auto cmd : pending_commands_) {
int cmd_id = cmd.first;
const struct qrtr_packet &qrtr_pkt = cmd.second;
switch (cmd_id) {
case kCmdExportDemuraBuffers:
HandleImportDemuraBuffers(qrtr_pkt, &rsp);
break;
case kCmdSetBacklight: {
HandleSetBacklight(qrtr_pkt, &rsp);
} break;
case kCmdSetDisplayConfig: {
HandleSetDisplayConfigs(qrtr_pkt, &rsp);
} break;
case kCmdSetProperties: {
HandleSetProperties(qrtr_pkt, &rsp);
} break;
case kCmdSetPanelBootParams: {
HandleSetPanelBootParams(qrtr_pkt, &rsp);
} break;
default:
break;
}
if (qrtr_pkt.data) {
delete [] qrtr_pkt.data;
}
}
pending_commands_.clear();
}
bool SDMCompService::IsRegisteredClientValid() {
for (auto callback : callbacks_) {
if (callback) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,138 @@
/*
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
Changes from Qualcomm Innovation Center are provided under the following license:
Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the
disclaimer below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __SDM_COMP_SERVICE_H__
#define __SDM_COMP_SERVICE_H__
#include <stdint.h>
#include "vm_interface.h"
#include "libqrtr.h"
#include "membuf_wrapper.h"
#include "sdm_comp_service_intf.h"
#include "utils/sys.h"
#include "sdm_comp_service_extn_intf.h"
#include "sdm_comp_interface.h"
#include <mutex>
#include <vector>
#include <thread>
#include <map>
using std::mutex;
namespace sdm {
typedef int (*QrtrOpen)(int rport);
typedef void (*QrtrClose)(int sock);
typedef int (*QrtrSendTo)(int sock, uint32_t node, uint32_t port, const void *data,
unsigned int sz);
typedef int (*QrtrPublish)(int sock, uint32_t service, uint16_t version, uint16_t instance);
typedef int (*QrtrBye)(int sock, uint32_t service, uint16_t version, uint16_t instance);
typedef int (*QrtrDecode)(struct qrtr_packet *dest, void *buf, size_t len,
const struct sockaddr_qrtr *sq);
class SDMCompService {
public:
static int RegisterCallback(SDMCompServiceCbIntf *callback);
static int UnRegisterCallback(SDMCompServiceCbIntf *callback);
private:
static void QRTREventHandler();
static void CommandHandler(const struct qrtr_packet &qrtr_pkt);
static void SendResponse(int node, int port, const Response &rsp);
static void HandleImportDemuraBuffers(const struct qrtr_packet &qrtr_pkt, Response *rsp);
static void HandleSetBacklight(const struct qrtr_packet &qrtr_pkt, Response *rsp);
static void HandleSetDisplayConfigs(const struct qrtr_packet &qrtr_pkt, Response *rsp);
static void HandleSetProperties(const struct qrtr_packet &qrtr_pkt, Response *rsp);
static void HandleSetPanelBootParams(const struct qrtr_packet &qrtr_pkt, Response *rsp);
static SDMCompDisplayType GetSDMCompDisplayType(DisplayType disp_type);
static void HandlePendingCommands();
static bool IsRegisteredClientValid();
static std::mutex qrtr_lock_;
static QrtrOpen qrtr_open_;
static QrtrClose qrtr_close_;
static QrtrSendTo qrtr_send_to_;
static QrtrPublish qrtr_publish_;
static QrtrBye qrtr_bye_;
static QrtrDecode qrtr_decode_;
static std::vector <SDMCompServiceCbIntf *> callbacks_;
static int qrtr_fd_;
static DynLib qrtr_lib_;
static MemBuf *mem_buf_;
static DynLib extension_lib_;
static CreateSDMCompExtnIntf create_sdm_comp_extn_intf_;
static DestroySDMCompExtnIntf destroy_sdm_comp_extn_intf_;
static SDMCompServiceExtnIntf *sdm_comp_service_extn_intf_;
static int exit_thread_fd_;
static std::thread event_thread_;
static std::mutex pending_cmd_lock_;
static std::multimap<int, struct qrtr_packet> pending_commands_;
};
} // namespace sdm
#endif // __SDM_COMP_SERVICE_H__

View File

@@ -0,0 +1,60 @@
/*
Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the
disclaimer below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <errno.h>
#include "sdm_comp_service_client.h"
#include "sdm_comp_service.h"
#include "debug_handler.h"
#define __CLASS__ "SDMCompServiceClient"
namespace sdm {
int SDMCompServiceClient::Init(SDMCompServiceCbIntf *callback) {
int err = SDMCompService::RegisterCallback(callback);
if (err != 0) {
DLOGE("Init failed!! err %d", err);
return err;
}
callback_ = callback;
return 0;
}
int SDMCompServiceClient::Deinit() {
return SDMCompService::UnRegisterCallback(callback_);
}
}

View File

@@ -0,0 +1,59 @@
/*
Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the
disclaimer below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __SDM_COMP_SERVICE_CLIENT_H__
#define __SDM_COMP_SERVICE_CLIENT_H__
#include <stdint.h>
#include "sdm_comp_service_intf.h"
#include "utils/sys.h"
#include "sdm_comp_interface.h"
namespace sdm {
class SDMCompServiceClient : public SDMCompServiceIntf {
public:
int Init(SDMCompServiceCbIntf *callback);
int Deinit();
~SDMCompServiceClient() { }
private:
SDMCompServiceCbIntf *callback_ = nullptr;
};
} // namespace sdm
#endif // __SDM_COMP_SERVICE_CLIENT_H__

View File

@@ -0,0 +1,108 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
Changes from Qualcomm Innovation Center are provided under the following license:
Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the
disclaimer below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <utils/debug.h>
#include <utils/utils.h>
#include "sdm_comp_service_intf.h"
#include "sdm_comp_service_client.h"
#define __CLASS__ "SDMCompServiceIntf"
namespace sdm {
int SDMCompServiceIntf::Create(SDMCompServiceCbIntf *callback, SDMCompServiceIntf **intf) {
if (!intf) {
DLOGE("intf pointer is NULL");
return -EINVAL;
}
SDMCompServiceClient *sdm_comp_service_client = new SDMCompServiceClient();
int error = sdm_comp_service_client->Init(callback);
if (error != 0) {
DLOGE("SDMCompServiceClient Init failed!! %d\n", error);
delete sdm_comp_service_client;
return error;
}
*intf = sdm_comp_service_client;
return 0;
}
int SDMCompServiceIntf::Destroy(SDMCompServiceIntf *intf) {
if (!intf) {
DLOGE("intf pointer is NULL");
return -EINVAL;
}
SDMCompServiceClient *sdm_comp_service_client = static_cast<SDMCompServiceClient *>(intf);
int error = sdm_comp_service_client->Deinit();
if (error != 0) {
DLOGE("Deinit failed with %d", error);
return error;
}
delete intf;
return 0;
}
} // namespace sdm