Browse Source
[cmake] libadrenotools, boost-headers -> CPM
[cmake] libadrenotools, boost-headers -> CPM
Signed-off-by: crueter <crueter@eden-emu.dev>pull/143/head
No known key found for this signature in database
GPG Key ID: 425ACD2D4830EBC6
56 changed files with 88 additions and 14480 deletions
-
3.gitmodules
-
10.patch/discord-rpc/0001-cmake-version.patch
-
40.patch/discord-rpc/0002-no-clang-format.patch
-
20.patch/libadrenotools/0001-linkerns-cpm.patch
-
22externals/CMakeLists.txt
-
1externals/boost-headers
-
4externals/libadrenotools/.gitmodules
-
37externals/libadrenotools/CMakeLists.txt
-
24externals/libadrenotools/LICENSE
-
30externals/libadrenotools/README.md
-
13externals/libadrenotools/adrenotools.pc.in
-
10externals/libadrenotools/build_asm.sh
-
23externals/libadrenotools/gen/bcenabler_patch.h
-
41externals/libadrenotools/include/adrenotools/bcenabler.h
-
71externals/libadrenotools/include/adrenotools/driver.h
-
27externals/libadrenotools/include/adrenotools/priv.h
-
19externals/libadrenotools/lib/linkernsbypass/CMakeLists.txt
-
24externals/libadrenotools/lib/linkernsbypass/LICENSE
-
9externals/libadrenotools/lib/linkernsbypass/README.md
-
192externals/libadrenotools/lib/linkernsbypass/android_linker_ns.cpp
-
81externals/libadrenotools/lib/linkernsbypass/android_linker_ns.h
-
67externals/libadrenotools/lib/linkernsbypass/elf_soname_patcher.cpp
-
21externals/libadrenotools/lib/linkernsbypass/elf_soname_patcher.h
-
135externals/libadrenotools/src/bcenabler.cpp
-
83externals/libadrenotools/src/bcenabler_patch.s
-
210externals/libadrenotools/src/driver.cpp
-
27externals/libadrenotools/src/hook/CMakeLists.txt
-
5externals/libadrenotools/src/hook/file_redirect_hook.c
-
13externals/libadrenotools/src/hook/gsl_alloc_hook.c
-
229externals/libadrenotools/src/hook/hook_impl.cpp
-
30externals/libadrenotools/src/hook/hook_impl.h
-
31externals/libadrenotools/src/hook/hook_impl_params.h
-
2124externals/libadrenotools/src/hook/kgsl.h
-
9externals/libadrenotools/src/hook/main_hook.c
-
96externals/libadrenotools/tools/ADPKG.md
-
7externals/libadrenotools/tools/README.md
-
12externals/libadrenotools/tools/acc-shim/README.md
-
108externals/libadrenotools/tools/acc-shim/vk_acc_shim.cpp
-
67externals/libadrenotools/tools/blob-patcher.py
-
9externals/libadrenotools/tools/qtimapper-shim/.clang-format
-
37externals/libadrenotools/tools/qtimapper-shim/Android.bp
-
19externals/libadrenotools/tools/qtimapper-shim/README.md
-
173externals/libadrenotools/tools/qtimapper-shim/ext/QtiGrallocDefs.h
-
86externals/libadrenotools/tools/qtimapper-shim/ext/common.h
-
344externals/libadrenotools/tools/qtimapper-shim/ext/gr_adreno_info.cpp
-
234externals/libadrenotools/tools/qtimapper-shim/ext/gr_adreno_info.h
-
190externals/libadrenotools/tools/qtimapper-shim/ext/gr_priv_handle.h
-
662externals/libadrenotools/tools/qtimapper-shim/ext/gr_utils.cpp
-
156externals/libadrenotools/tools/qtimapper-shim/ext/gr_utils.h
-
103externals/libadrenotools/tools/qtimapper-shim/ext/gralloc_priv.h
-
183externals/libadrenotools/tools/qtimapper-shim/ext/mapper.h
-
224externals/libadrenotools/tools/qtimapper-shim/ext/mapperextensions.h
-
6744externals/libadrenotools/tools/qtimapper-shim/ext/types/common.h
-
250externals/libadrenotools/tools/qtimapper-shim/ext/types/mapper.h
-
707externals/libadrenotools/tools/qtimapper-shim/ext/types/mapperextensions.h
-
472externals/libadrenotools/tools/qtimapper-shim/shim.cpp
@ -0,0 +1,10 @@ |
|||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|||
index 5dad9e9..760a1b2 100644
|
|||
--- a/CMakeLists.txt
|
|||
+++ b/CMakeLists.txt
|
|||
@@ -1,4 +1,4 @@
|
|||
-cmake_minimum_required (VERSION 3.2.0)
|
|||
+cmake_minimum_required (VERSION 3.10)
|
|||
project (DiscordRPC) |
|||
|
|||
include(GNUInstallDirs) |
|||
@ -0,0 +1,40 @@ |
|||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|||
index 760a1b2..540d643 100644
|
|||
--- a/CMakeLists.txt
|
|||
+++ b/CMakeLists.txt
|
|||
@@ -12,20 +12,6 @@ file(GLOB_RECURSE ALL_SOURCE_FILES
|
|||
src/*.cpp src/*.h src/*.c |
|||
) |
|||
|
|||
-# Set CLANG_FORMAT_SUFFIX if you are using custom clang-format, e.g. clang-format-5.0
|
|||
-find_program(CLANG_FORMAT_CMD clang-format${CLANG_FORMAT_SUFFIX})
|
|||
-
|
|||
-if (CLANG_FORMAT_CMD)
|
|||
- add_custom_target(
|
|||
- clangformat
|
|||
- COMMAND ${CLANG_FORMAT_CMD}
|
|||
- -i -style=file -fallback-style=none
|
|||
- ${ALL_SOURCE_FILES}
|
|||
- DEPENDS
|
|||
- ${ALL_SOURCE_FILES}
|
|||
- )
|
|||
-endif(CLANG_FORMAT_CMD)
|
|||
-
|
|||
# thirdparty stuff |
|||
execute_process( |
|||
COMMAND mkdir ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty |
|||
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
|
|||
index 290d761..cd2cc92 100644
|
|||
--- a/src/CMakeLists.txt
|
|||
+++ b/src/CMakeLists.txt
|
|||
@@ -120,10 +120,6 @@ if (${BUILD_SHARED_LIBS})
|
|||
target_compile_definitions(discord-rpc PRIVATE -DDISCORD_BUILDING_SDK) |
|||
endif(${BUILD_SHARED_LIBS}) |
|||
|
|||
-if (CLANG_FORMAT_CMD)
|
|||
- add_dependencies(discord-rpc clangformat)
|
|||
-endif(CLANG_FORMAT_CMD)
|
|||
-
|
|||
# install |
|||
|
|||
install( |
|||
@ -0,0 +1,20 @@ |
|||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|||
index 16c6092..9e75548 100644
|
|||
--- a/CMakeLists.txt
|
|||
+++ b/CMakeLists.txt
|
|||
@@ -8,7 +8,14 @@ project(adrenotools LANGUAGES CXX C)
|
|||
|
|||
set(GEN_INSTALL_TARGET OFF CACHE BOOL "") |
|||
|
|||
-add_subdirectory(lib/linkernsbypass)
|
|||
+include(CPM)
|
|||
+set(CPM_USE_LOCAL_PACKAGES OFF)
|
|||
+
|
|||
+CPMAddPackage(
|
|||
+ NAME linkernsbypass
|
|||
+ URL "https://github.com/bylaws/liblinkernsbypass/archive/aa3975893d.zip"
|
|||
+ URL_HASH SHA512=43d3d146facb7ec99d066a9b8990369ab7b9eec0d5f9a67131b0a0744fde0af27d884ca1f2a272cd113718a23356530ed97703c8c0659c4c25948d50c106119e
|
|||
+)
|
|||
|
|||
set(LIB_SOURCES src/bcenabler.cpp |
|||
src/driver.cpp |
|||
@ -1,4 +0,0 @@ |
|||
[submodule "lib/linkernsbypass"] |
|||
path = lib/linkernsbypass |
|||
url = https://github.com/bylaws/liblinkernsbypass/ |
|||
branch = master |
|||
@ -1,37 +0,0 @@ |
|||
cmake_minimum_required(VERSION 3.14) |
|||
|
|||
if(NOT ${CMAKE_ANDROID_ARCH_ABI} STREQUAL arm64-v8a) |
|||
message(FATAL_ERROR "Unsupported target architecture: ${CMAKE_ANDROID_ARCH_ABI}. Please make an issue on the repo!") |
|||
endif() |
|||
|
|||
project(adrenotools LANGUAGES CXX C) |
|||
|
|||
set(GEN_INSTALL_TARGET OFF CACHE BOOL "") |
|||
|
|||
add_subdirectory(lib/linkernsbypass) |
|||
|
|||
set(LIB_SOURCES src/bcenabler.cpp |
|||
src/driver.cpp |
|||
include/adrenotools/bcenabler.h |
|||
include/adrenotools/driver.h |
|||
include/adrenotools/priv.h) |
|||
|
|||
add_library(adrenotools ${LIB_SOURCES}) |
|||
|
|||
target_include_directories(adrenotools PUBLIC include) |
|||
target_include_directories(adrenotools PRIVATE .) |
|||
target_compile_options(adrenotools PRIVATE -Wall -Wextra) |
|||
target_link_libraries(adrenotools android linkernsbypass) |
|||
|
|||
add_subdirectory(src/hook) |
|||
if (${BUILD_SHARED_LIBS}) |
|||
target_link_options(adrenotools PRIVATE "-Wl,-s,--exclude-libs,liblinkernsbypass.a") |
|||
endif() |
|||
if (${GEN_INSTALL_TARGET}) |
|||
configure_file(adrenotools.pc.in adrenotools.pc @ONLY) |
|||
install(FILES ${CMAKE_BINARY_DIR}/adrenotools.pc DESTINATION lib/pkgconfig) |
|||
install(TARGETS adrenotools main_hook file_redirect_hook gsl_alloc_hook hook_impl) |
|||
install(DIRECTORY include/ |
|||
DESTINATION include |
|||
FILES_MATCHING PATTERN "*.h*") |
|||
endif() |
|||
@ -1,24 +0,0 @@ |
|||
BSD 2-Clause License |
|||
|
|||
Copyright (c) 2021, Billy Laws |
|||
|
|||
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. |
|||
|
|||
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. |
|||
@ -1,30 +0,0 @@ |
|||
### Adreno Tools |
|||
A library for applying rootless Adreno GPU driver modifications/replacements. Currently supports loading custom GPU drivers such as [turnip](https://docs.mesa3d.org/android.html#building-using-the-android-ndk), enabling BCn textures and redirecting file operations to allow accessing shader dumps and modification of the [driver config file](https://gist.github.com/bylaws/04130932e2634d1c6a2a9729e3940d60) without root. |
|||
|
|||
#### Documentation |
|||
API is documented in the `include/adrenotools` headers. |
|||
|
|||
#### Support |
|||
Android 9+ |
|||
Arm64 |
|||
|
|||
Please create an issue if support for anything else is desired. |
|||
|
|||
### FAQ |
|||
|
|||
#### Is there an example project? |
|||
|
|||
There is a simple bare-bones project [AdrenoToolsTest](https://github.com/darksylinc/AdrenoToolsTest) demonstrating how to get libadrenotools working. |
|||
|
|||
#### How do I use this to update the drivers on my phone? Where's the apk? |
|||
|
|||
You don't. This library is **not** for installing into Android and is **not** for end users. |
|||
This library is aimed at other developers. |
|||
|
|||
Each individual app must explicitly make use of libadrenotools in order to load custom drivers into an app / game. |
|||
|
|||
#### How do I use this library to make \<favourite game\> use newer drivers? |
|||
|
|||
See previous question. It's up to the game developer to add support & use this library. |
|||
|
|||
You could contact them to so they add support for it; but that's out of our power. |
|||
@ -1,13 +0,0 @@ |
|||
prefix="@CMAKE_INSTALL_PREFIX@" |
|||
exec_prefix=${prefix} |
|||
libdir=${exec_prefix}/lib |
|||
includedir=${prefix}/include |
|||
|
|||
Name: adrenotools |
|||
Description: |
|||
URL: |
|||
Version: 1.0.0 |
|||
Libs: -L${libdir} -ladrenotools |
|||
Libs.private: |
|||
Requires.private: |
|||
Cflags: -I${includedir} |
|||
@ -1,10 +0,0 @@ |
|||
#!/bin/sh |
|||
|
|||
aarch64-linux-gnu-gcc -c src/bcenabler_patch.s -o /tmp/patch.o |
|||
aarch64-linux-gnu-objcopy -O binary -j .text /tmp/patch.o /tmp/patch.bin |
|||
|
|||
# Must be smaller than a single page |
|||
bin2c -o gen/bcenabler_patch.h -n PatchRawData /tmp/patch.bin |
|||
|
|||
rm /tmp/patch.o |
|||
rm /tmp/patch.bin |
|||
@ -1,23 +0,0 @@ |
|||
/* Generated by bin2c, do not edit manually */ |
|||
|
|||
/* Contents of file /tmp/patch.bin */ |
|||
const long int PatchRawData_size = 264; |
|||
const unsigned char PatchRawData[264] = { |
|||
0x1F, 0x0C, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0xE0, 0x08, 0x80, 0x52, 0x3E, 0x00, 0x00, 0x14, |
|||
0x1F, 0x14, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0xE0, 0x08, 0x80, 0x52, 0x3A, 0x00, 0x00, 0x14, |
|||
0x1F, 0x10, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x00, 0x09, 0x80, 0x52, 0x36, 0x00, 0x00, 0x14, |
|||
0x1F, 0x18, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x00, 0x09, 0x80, 0x52, 0x32, 0x00, 0x00, 0x14, |
|||
0x1F, 0x1C, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x40, 0x09, 0x80, 0x52, 0x2E, 0x00, 0x00, 0x14, |
|||
0x1F, 0x20, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x60, 0x09, 0x80, 0x52, 0x2A, 0x00, 0x00, 0x14, |
|||
0x1F, 0x24, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0xA0, 0x09, 0x80, 0x52, 0x26, 0x00, 0x00, 0x14, |
|||
0x1F, 0x28, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0xC0, 0x09, 0x80, 0x52, 0x22, 0x00, 0x00, 0x14, |
|||
0x1F, 0x2C, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x00, 0x0A, 0x80, 0x52, 0x1E, 0x00, 0x00, 0x14, |
|||
0x1F, 0x30, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x20, 0x0A, 0x80, 0x52, 0x1A, 0x00, 0x00, 0x14, |
|||
0x1F, 0x34, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x60, 0x0A, 0x80, 0x52, 0x16, 0x00, 0x00, 0x14, |
|||
0x1F, 0x38, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x80, 0x0A, 0x80, 0x52, 0x12, 0x00, 0x00, 0x14, |
|||
0x1F, 0x3C, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0xE0, 0x0B, 0x80, 0x52, 0x0E, 0x00, 0x00, 0x14, |
|||
0x1F, 0x40, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x00, 0x0C, 0x80, 0x52, 0x0A, 0x00, 0x00, 0x14, |
|||
0x1F, 0x44, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x40, 0x0C, 0x80, 0x52, 0x06, 0x00, 0x00, 0x14, |
|||
0x1F, 0x48, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x60, 0x0C, 0x80, 0x52, 0x02, 0x00, 0x00, 0x14, |
|||
0x00, 0x00, 0x80, 0x52, 0xFF, 0xFF, 0xFF, 0xFF |
|||
}; |
|||
@ -1,41 +0,0 @@ |
|||
// SPDX-License-Identifier: BSD-2-Clause |
|||
// Copyright © 2021 Billy Laws |
|||
|
|||
#pragma once |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#else |
|||
#include <stdbool.h> |
|||
#endif |
|||
|
|||
#include <stdint.h> |
|||
|
|||
/** |
|||
* @brief Describes the level of BCeNabler support for a driver |
|||
*/ |
|||
enum adrenotools_bcn_type { |
|||
ADRENOTOOLS_BCN_INCOMPATIBLE, //!< Driver isn't supported by BCeNabler |
|||
ADRENOTOOLS_BCN_BLOB, //!< Driver already supports BCn textures so BCeNabler isn't necessary |
|||
ADRENOTOOLS_BCN_PATCH //!< Driver can be patched with BCeNabler to support BCn textures |
|||
}; |
|||
|
|||
/** |
|||
* @brief Checks the status of BCn support in the supplied driver |
|||
* @param major The major part of VkPhysicalDeviceProperties::driverVersion |
|||
* @param minor The minor part of VkPhysicalDeviceProperties::driverVersion |
|||
* @param vendorId VkPhysicalDeviceProperties::vendorId |
|||
*/ |
|||
enum adrenotools_bcn_type adrenotools_get_bcn_type(uint32_t major, uint32_t minor, uint32_t vendorId); |
|||
|
|||
/** |
|||
* @brief Patches the Adreno graphics driver to enable support for BCn compressed formats |
|||
* @note adrenotools_get_bcn_type MUST be checked to equal ADRENOTOOLS_BCN_PATCH before calling this |
|||
* @param vkGetPhysicalDeviceFormatPropertiesFn A pointer to vkGetPhysicalDeviceFormatProperties obtained through vkGetInstanceProcAddr. This is used to find the correct function to patch |
|||
* @return If the patching succeeded, if false the driver will be in an undefined state |
|||
*/ |
|||
bool adrenotools_patch_bcn(void *vkGetPhysicalDeviceFormatPropertiesFn); |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
@ -1,71 +0,0 @@ |
|||
// SPDX-License-Identifier: BSD-2-Clause |
|||
// Copyright © 2021 Billy Laws |
|||
|
|||
#pragma once |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
#include <stdbool.h> |
|||
#include "priv.h" |
|||
|
|||
/** |
|||
* @brief Opens a new libvulkan.so instance according to `flags` |
|||
* @remark IMPORTANT: The app MUST be packaged w/ useLegacyPackaging = true. The reason for this is |
|||
* that we install the hook in hookLibDir; but this folder won't be set correctly when useLegacyPackaging == false |
|||
* because Android expects to read the *.so directly from the apk (instead of decompressing them into nativeLibraryDir). |
|||
* @param dlopenMode The dlopen mode to use when opening libvulkan |
|||
* @param featureFlags Which adrenotools driver features to enable |
|||
* @param tmpLibDir A writable directory to hold patched libraries, only used on api < 29 due to the lack of memfd support. If nullptr is passed and the API version is < 29 memfd usage will be attempted and if unsupported nullptr will be returned |
|||
* @param hookLibDir The directory holding the built hooks. |
|||
* IMPORTANT: This path MUST point to whatever `getApplicationInfo().nativeLibraryDir` (Kotlin code) returns. |
|||
* Failing to do so will result in this function returning a valid ptr but then the hook will fail and either the original driver is loaded as fallback, or vkEnumeratePhysicalDevices returns 0 devices. |
|||
* @param customDriverDir The directory to load a custom GPU driver named according to `customDriverName` from. Only used if ADRENOTOOLS_DRIVER_CUSTOM is set in `featureFlags`. |
|||
* IMPORTANT: This path MUST NOT be on sdcard/storage. i.e. use ANativeActivity::internalDataPath and often looks like "/data/user/0/com.example.app/files/". |
|||
* Otherwise you will get permission denied because dlopen() can't be done on *.so libraries that any random user or application can manipulate (which would be a security risk). |
|||
* @param customDriverName The soname of the custom driver to load. Only used if ADRENOTOOLS_DRIVER_CUSTOM is set in `featureFlags` |
|||
* @param fileRedirectDir The directory which to redirect all file accesses performed by the driver to. Only used if ADRENOTOOLS_DRIVER_FILE_REDIRECT is set in `featureFlags` |
|||
* @param userMappingHandle A pointer to a void* which will be set to the mapping handle if ADRENOTOOLS_DRIVER_GPU_MAPPING_IMPORT is set in `featureFlags` |
|||
*/ |
|||
void *adrenotools_open_libvulkan(int dlopenMode, int featureFlags, const char *tmpLibDir, const char *hookLibDir, const char *customDriverDir, const char *customDriverName, const char *fileRedirectDir, void **userMappingHandle); |
|||
|
|||
/** |
|||
* @brief Imports the given CPU mapped memory range into the GSL allocator. This should then be followed by a call to vkAllocateMemory with a matching size which will return a VkDeviceMemory view over the input region |
|||
* @param handle Mapping handle that was returned by adrenotools_open_libvulkan |
|||
* @param hostPtr The host pointer to import |
|||
* @param size The size of the region to import |
|||
* @return True on success |
|||
*/ |
|||
bool adrenotools_import_user_mem(void *handle, void *hostPtr, uint64_t size); |
|||
|
|||
/** |
|||
* @brief Maps GPU memory and imports it into the GSL allocator. This should then be followed by a call to adrenotools_mem_cpu_map to map the memory on the CPU, then finally vkAllocateMemory with a matching size |
|||
* @param handle Mapping handle that was returned by adrenotools_open_libvulkan |
|||
* @param size Pointer to a variable containing the size of the region to import, will be updated to contain the required size of the region to allocate CPU side |
|||
* @return true on success |
|||
*/ |
|||
bool adrenotools_mem_gpu_allocate(void *handle, uint64_t *size); |
|||
|
|||
/** |
|||
* @brief Maps the last mapping allocated using adrenotools_mem_gpu_allocate into the given host memory region, such that vkAllocateMemory can then be called |
|||
* @param handle Mapping handle that was returned by adrenotools_open_libvulkan |
|||
* @param hostPtr A pointer to where the mapping should be mapped |
|||
* @param size The size of the mapping. MUST be equal to the size returned by adrenotools_mem_gpu_allocate |
|||
*/ |
|||
bool adrenotools_mem_cpu_map(void *handle, void *hostPtr, uint64_t size); |
|||
|
|||
/** |
|||
* @note This function should be called after adrenotools_open_libvulkan and Vulkan driver init to check if the mapping import hook loaded successfully |
|||
* @return True if the mapping was successfully imported (or initialization succeeded) |
|||
*/ |
|||
bool adrenotools_validate_gpu_mapping(void *handle); |
|||
|
|||
/** |
|||
* @brief Provides a way to force the GPU to run at the maximum possible clocks (thermal constraints will still be applied) |
|||
*/ |
|||
void adrenotools_set_turbo(bool turbo); |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
@ -1,27 +0,0 @@ |
|||
// SPDX-License-Identifier: BSD-2-Clause |
|||
// Copyright © 2021 Billy Laws |
|||
|
|||
#pragma once |
|||
|
|||
#include <stdint.h> |
|||
|
|||
/** |
|||
* @brief Bitfield enum of additional driver features that can be used with adrenotools_open_libvulkan |
|||
*/ |
|||
enum { |
|||
ADRENOTOOLS_DRIVER_CUSTOM = 1 << 0, |
|||
ADRENOTOOLS_DRIVER_FILE_REDIRECT = 1 << 1, |
|||
ADRENOTOOLS_DRIVER_GPU_MAPPING_IMPORT = 1 << 2, |
|||
}; |
|||
|
|||
#define ADRENOTOOLS_GPU_MAPPING_SUCCEEDED_MAGIC 0xDEADBEEF |
|||
|
|||
/** |
|||
* @brief A replacement GPU memory mapping for use with ADRENOTOOLS_DRIVER_GPU_MAPPING_IMPORT |
|||
*/ |
|||
struct adrenotools_gpu_mapping { |
|||
void *host_ptr; |
|||
uint64_t gpu_addr; //!< The GPU address of the mapping to import, if mapping import/init succeeds this will be set to ADRENOTOOLS_GPU_MAPPING_SUCCEEDED_MAGIC |
|||
uint64_t size; |
|||
uint64_t flags; |
|||
}; |
|||
@ -1,19 +0,0 @@ |
|||
cmake_minimum_required(VERSION 3.14) |
|||
|
|||
if(NOT ${CMAKE_ANDROID_ARCH_ABI} STREQUAL arm64-v8a) |
|||
message(FATAL_ERROR "Unsupported target architecture: ${CMAKE_ANDROID_ARCH_ABI}. Please make an issue on the repo!") |
|||
endif() |
|||
|
|||
project(linkernsbypass LANGUAGES CXX) |
|||
|
|||
set(SOURCES android_linker_ns.cpp |
|||
android_linker_ns.h |
|||
elf_soname_patcher.cpp |
|||
elf_soname_patcher.h) |
|||
|
|||
add_library(linkernsbypass STATIC ${SOURCES}) |
|||
|
|||
|
|||
target_compile_options(linkernsbypass PRIVATE -Wall -Wextra) |
|||
target_link_libraries(linkernsbypass android dl) |
|||
target_include_directories(linkernsbypass PUBLIC .) |
|||
@ -1,24 +0,0 @@ |
|||
BSD 2-Clause License |
|||
|
|||
Copyright (c) 2021, Billy Laws |
|||
|
|||
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. |
|||
|
|||
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. |
|||
@ -1,9 +0,0 @@ |
|||
### Android Linker Namespace Bypass Library |
|||
Provides access to the hidden linker namespace functionality in Android 9+ and exposes an interface for hooking libraries similar to a runtime equivalent of `LD_PRELOAD`. |
|||
See the `android_linker_ns.h` header for an API reference. |
|||
|
|||
#### Support |
|||
Android 9+ |
|||
Arm64 |
|||
|
|||
Android 8 and arm32 could be supported with some trivial changes, feel free to open an issue if you have a use for this library on either of them. |
|||
@ -1,192 +0,0 @@ |
|||
// SPDX-License-Identifier: BSD-2-Clause
|
|||
// Copyright © 2021 Billy Laws
|
|||
|
|||
#include <array>
|
|||
#include <cstdio>
|
|||
#include <cstdlib>
|
|||
#include <errno.h>
|
|||
#include <dlfcn.h>
|
|||
#include <unistd.h>
|
|||
#include <fcntl.h>
|
|||
#include <android/dlext.h>
|
|||
#include <android/log.h>
|
|||
#include <android/api-level.h>
|
|||
#include <sys/mman.h>
|
|||
#include "elf_soname_patcher.h"
|
|||
#include "android_linker_ns.h"
|
|||
|
|||
using loader_android_create_namespace_t = android_namespace_t *(*)(const char *, const char *, const char *, uint64_t, const char *, android_namespace_t *, const void *); |
|||
static loader_android_create_namespace_t loader_android_create_namespace; |
|||
|
|||
static bool lib_loaded; |
|||
|
|||
|
|||
/* Public API */ |
|||
bool linkernsbypass_load_status() { |
|||
return lib_loaded; |
|||
} |
|||
|
|||
struct android_namespace_t *android_create_namespace(const char *name, |
|||
const char *ld_library_path, |
|||
const char *default_library_path, |
|||
uint64_t type, |
|||
const char *permitted_when_isolated_path, |
|||
android_namespace_t *parent_namespace) { |
|||
auto caller{__builtin_return_address(0)}; |
|||
return loader_android_create_namespace(name, ld_library_path, default_library_path, type, |
|||
permitted_when_isolated_path, parent_namespace, caller); |
|||
} |
|||
|
|||
struct android_namespace_t *android_create_namespace_escape(const char *name, |
|||
const char *ld_library_path, |
|||
const char *default_library_path, |
|||
uint64_t type, |
|||
const char *permitted_when_isolated_path, |
|||
android_namespace_t *parent_namespace) { |
|||
auto caller{reinterpret_cast<void *>(&dlopen)}; |
|||
return loader_android_create_namespace(name, ld_library_path, default_library_path, type, |
|||
permitted_when_isolated_path, parent_namespace, caller); |
|||
} |
|||
|
|||
android_get_exported_namespace_t android_get_exported_namespace; |
|||
|
|||
android_link_namespaces_all_libs_t android_link_namespaces_all_libs; |
|||
|
|||
android_link_namespaces_t android_link_namespaces; |
|||
|
|||
bool linkernsbypass_link_namespace_to_default_all_libs(android_namespace_t *to) { |
|||
// Creating a shared namespace with the default parent will give a copy of the default namespace that we can actually access
|
|||
// This is needed since there is no way to access a direct handle to the default namespace as it's not exported
|
|||
static auto defaultNs{android_create_namespace_escape("default_copy", nullptr, nullptr, ANDROID_NAMESPACE_TYPE_SHARED, nullptr, nullptr)}; |
|||
return android_link_namespaces_all_libs(to, defaultNs); |
|||
} |
|||
|
|||
void *linkernsbypass_namespace_dlopen(const char *filename, int flags, android_namespace_t *ns) { |
|||
android_dlextinfo extInfo{ |
|||
.flags = ANDROID_DLEXT_USE_NAMESPACE, |
|||
.library_namespace = ns |
|||
}; |
|||
|
|||
return android_dlopen_ext(filename, flags, &extInfo); |
|||
} |
|||
|
|||
#ifndef __NR_memfd_create
|
|||
#if defined(__aarch64__)
|
|||
#define __NR_memfd_create 279
|
|||
#else
|
|||
#error Unsupported target architecture!
|
|||
#endif
|
|||
#endif
|
|||
|
|||
void *linkernsbypass_namespace_dlopen_unique(const char *libPath, const char *libTargetDir, int flags, android_namespace_t *ns) { |
|||
static std::array<char, PATH_MAX> PathBuf{}; |
|||
|
|||
// Used as a unique ID for overwriting soname and creating target lib files
|
|||
static uint16_t TargetId{}; |
|||
|
|||
int libTargetFd{[&] () { |
|||
if (libTargetDir) { |
|||
snprintf(PathBuf.data(), PathBuf.size(), "%s/%d_patched.so", libTargetDir, TargetId); |
|||
return open(PathBuf.data(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); |
|||
} else { |
|||
// If memfd isn't supported errno will contain ENOSYS after calling
|
|||
errno = 0; |
|||
int fd{static_cast<int>(syscall(__NR_memfd_create, libPath, 0))}; |
|||
if (errno == ENOSYS || fd < 0) |
|||
return -1; |
|||
else |
|||
return fd; |
|||
} |
|||
}()}; |
|||
if (libTargetFd == -1) |
|||
return nullptr; |
|||
|
|||
// Partially overwrite soname with 3 digits (replacing lib...) with to make sure a cached so isn't loaded
|
|||
std::array<char, 3> sonameOverwrite{}; |
|||
snprintf(sonameOverwrite.data(), sonameOverwrite.size(), "%03u", TargetId++); |
|||
|
|||
if (!elf_soname_patch(libPath, libTargetFd, sonameOverwrite.data())) |
|||
return nullptr; |
|||
|
|||
// Load our patched library into the hook namespace
|
|||
android_dlextinfo hookExtInfo{ |
|||
.flags = ANDROID_DLEXT_USE_NAMESPACE | ANDROID_DLEXT_USE_LIBRARY_FD, |
|||
.library_fd = libTargetFd, |
|||
.library_namespace = ns |
|||
}; |
|||
|
|||
// Make a path that looks about right
|
|||
snprintf(PathBuf.data(), PathBuf.size(), "/proc/self/fd/%d", libTargetFd); |
|||
|
|||
return android_dlopen_ext(PathBuf.data(), flags, &hookExtInfo); |
|||
} |
|||
|
|||
static void *align_ptr(void *ptr) { |
|||
return reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(ptr) & ~(getpagesize() - 1)); |
|||
} |
|||
|
|||
/* Private */ |
|||
__attribute__((constructor)) static void resolve_linker_symbols() { |
|||
using loader_dlopen_t = void *(*)(const char *, int, const void *); |
|||
|
|||
if (android_get_device_api_level() < 28) |
|||
return; |
|||
|
|||
// ARM64 specific function walking to locate the internal dlopen handler
|
|||
auto loader_dlopen{[]() { |
|||
union BranchLinked { |
|||
uint32_t raw; |
|||
|
|||
struct { |
|||
int32_t offset : 26; //!< 26-bit branch offset
|
|||
uint8_t sig : 6; //!< 6-bit signature
|
|||
}; |
|||
|
|||
bool Verify() { |
|||
return sig == 0x25; |
|||
} |
|||
}; |
|||
static_assert(sizeof(BranchLinked) == 4, "BranchLinked is wrong size"); |
|||
|
|||
// Some devices ship with --X mapping for exexecutables so work around that
|
|||
mprotect(align_ptr(reinterpret_cast<void *>(&dlopen)), getpagesize(), PROT_WRITE | PROT_READ | PROT_EXEC); |
|||
|
|||
// dlopen is just a wrapper for __loader_dlopen that passes the return address as the third arg hence we can just walk it to find __loader_dlopen
|
|||
auto blInstr{reinterpret_cast<BranchLinked *>(&dlopen)}; |
|||
while (!blInstr->Verify()) |
|||
blInstr++; |
|||
|
|||
return reinterpret_cast<loader_dlopen_t>(blInstr + blInstr->offset); |
|||
}()}; |
|||
|
|||
// Protect the loader_dlopen function to remove the BTI attribute (since this is an internal function that isn't intended to be jumped indirectly to)
|
|||
mprotect(align_ptr(reinterpret_cast<void *>(&loader_dlopen)), getpagesize(), PROT_WRITE | PROT_READ | PROT_EXEC); |
|||
|
|||
// Passing dlopen as a caller address tricks the linker into using the internal unrestricted namespace letting us access libraries that are normally forbidden in the classloader namespace imposed on apps
|
|||
auto ldHandle{loader_dlopen("ld-android.so", RTLD_LAZY, reinterpret_cast<void *>(&dlopen))}; |
|||
if (!ldHandle) |
|||
return; |
|||
|
|||
android_link_namespaces_all_libs = reinterpret_cast<android_link_namespaces_all_libs_t>(dlsym(ldHandle, "__loader_android_link_namespaces_all_libs")); |
|||
if (!android_link_namespaces_all_libs) |
|||
return; |
|||
|
|||
android_link_namespaces = reinterpret_cast<android_link_namespaces_t>(dlsym(ldHandle, "__loader_android_link_namespaces")); |
|||
if (!android_link_namespaces) |
|||
return; |
|||
|
|||
auto libdlAndroidHandle{loader_dlopen("libdl_android.so", RTLD_LAZY, reinterpret_cast<void *>(&dlopen))}; |
|||
if (!libdlAndroidHandle) |
|||
return; |
|||
|
|||
loader_android_create_namespace = reinterpret_cast<loader_android_create_namespace_t>(dlsym(libdlAndroidHandle, "__loader_android_create_namespace")); |
|||
if (!loader_android_create_namespace) |
|||
return; |
|||
|
|||
android_get_exported_namespace = reinterpret_cast<android_get_exported_namespace_t>(dlsym(libdlAndroidHandle, "__loader_android_get_exported_namespace")); |
|||
if (!android_get_exported_namespace) |
|||
return; |
|||
|
|||
// Lib is now safe to use
|
|||
lib_loaded = true; |
|||
} |
|||
@ -1,81 +0,0 @@ |
|||
// SPDX-License-Identifier: BSD-2-Clause |
|||
// Copyright © 2021 Billy Laws |
|||
|
|||
#pragma once |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
#include <stdint.h> |
|||
|
|||
// https://cs.android.com/android/platform/superproject/+/0a492a4685377d41fef2b12e9af4ebfa6feef9c2:art/libnativeloader/include/nativeloader/dlext_namespaces.h;l=25;bpv=1;bpt=1 |
|||
enum { |
|||
ANDROID_NAMESPACE_TYPE_REGULAR = 0, |
|||
ANDROID_NAMESPACE_TYPE_ISOLATED = 1, |
|||
ANDROID_NAMESPACE_TYPE_SHARED = 2, |
|||
ANDROID_NAMESPACE_TYPE_EXEMPT_LIST_ENABLED = 0x08000000, |
|||
ANDROID_NAMESPACE_TYPE_ALSO_USED_AS_ANONYMOUS = 0x10000000, |
|||
ANDROID_NAMESPACE_TYPE_SHARED_ISOLATED = ANDROID_NAMESPACE_TYPE_SHARED | ANDROID_NAMESPACE_TYPE_ISOLATED, |
|||
}; |
|||
|
|||
/** |
|||
* @brief Checks if linkernsbypass loaded successfully and is safe to use |
|||
* @note IMPORTANT: This should be called before any calls to the rest of the library are made |
|||
* @return true if loading succeeded |
|||
*/ |
|||
bool linkernsbypass_load_status(); |
|||
|
|||
// https://cs.android.com/android/platform/superproject/+/0a492a4685377d41fef2b12e9af4ebfa6feef9c2:art/libnativeloader/include/nativeloader/dlext_namespaces.h;l=86;bpv=1;bpt=1 |
|||
struct android_namespace_t *android_create_namespace(const char *name, |
|||
const char *ld_library_path, |
|||
const char *default_library_path, |
|||
uint64_t type, |
|||
const char *permitted_when_isolated_path, |
|||
struct android_namespace_t *parent_namespace); |
|||
|
|||
struct android_namespace_t *android_create_namespace_escape(const char *name, |
|||
const char *ld_library_path, |
|||
const char *default_library_path, |
|||
uint64_t type, |
|||
const char *permitted_when_isolated_path, |
|||
struct android_namespace_t *parent_namespace); |
|||
|
|||
// https://cs.android.com/android/platform/superproject/+/dcb01ef31026b3b8aeb72dada3370af63fe66bbd:bionic/linker/linker.cpp;l=3554 |
|||
typedef struct android_namespace_t *(*android_get_exported_namespace_t)(const char *); |
|||
extern android_get_exported_namespace_t android_get_exported_namespace; |
|||
|
|||
// https://cs.android.com/android/platform/superproject/+/dcb01ef31026b3b8aeb72dada3370af63fe66bbd:bionic/linker/linker.cpp;l=2499 |
|||
typedef bool (*android_link_namespaces_all_libs_t)(struct android_namespace_t *, struct android_namespace_t *); |
|||
extern android_link_namespaces_all_libs_t android_link_namespaces_all_libs; |
|||
|
|||
// https://cs.android.com/android/platform/superproject/+/dcb01ef31026b3b8aeb72dada3370af63fe66bbd:bionic/linker/linker.cpp;l=2473 |
|||
typedef bool (*android_link_namespaces_t)(struct android_namespace_t *, struct android_namespace_t *, const char *); |
|||
extern android_link_namespaces_t android_link_namespaces; |
|||
|
|||
/** |
|||
* @brief Like android_link_namespaces_all_libs but links from the default namespace |
|||
*/ |
|||
bool linkernsbypass_link_namespace_to_default_all_libs(struct android_namespace_t *to); |
|||
|
|||
/** |
|||
* @brief Loads a library into a namespace |
|||
* @note IMPORTANT: If `filename` is compiled with the '-z global' linker flag and RTLD_GLOBAL is supplied in `flags` the library will be added to the namespace's LD_PRELOAD list |
|||
* @param filename The name of the library to load |
|||
* @param flags The rtld flags for `filename` |
|||
* @param ns The namespace to dlopen into |
|||
*/ |
|||
void *linkernsbypass_namespace_dlopen(const char *filename, int flags, struct android_namespace_t *ns); |
|||
|
|||
/** |
|||
* @brief Force loads a unique instance of a library into a namespace |
|||
* @param libPath The path to the library to load with hooks applied |
|||
* @param libTargetDir A temporary directory to hold the soname patched library at `libPath`, will attempt to use memfd if nullptr |
|||
* @param flags The rtld flags for `libName` |
|||
* @param ns The namespace to dlopen into |
|||
*/ |
|||
void *linkernsbypass_namespace_dlopen_unique(const char *libPath, const char *libTargetDir, int flags, struct android_namespace_t *ns); |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
@ -1,67 +0,0 @@ |
|||
// SPDX-License-Identifier: BSD-2-Clause
|
|||
// Copyright © 2021 Billy Laws
|
|||
|
|||
#include <initializer_list>
|
|||
#include <cstdint>
|
|||
#include <errno.h>
|
|||
#include <sys/stat.h>
|
|||
#include <sys/mman.h>
|
|||
#include <fcntl.h>
|
|||
#include <unistd.h>
|
|||
#include <link.h>
|
|||
#include <elf.h>
|
|||
#include "elf_soname_patcher.h"
|
|||
|
|||
bool elf_soname_patch(const char *libPath, int targetFd, const char *sonamePatch) { |
|||
struct stat libStat{}; |
|||
if (stat(libPath, &libStat)) |
|||
return false; |
|||
|
|||
if (ftruncate(targetFd, libStat.st_size) == -1) |
|||
return false; |
|||
|
|||
// Map the memory so we can read our elf into it
|
|||
auto mappedLib{reinterpret_cast<uint8_t *>(mmap(nullptr, libStat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, targetFd, 0))}; |
|||
if (!mappedLib) |
|||
return false; |
|||
|
|||
int libFd{open(libPath, O_RDONLY)}; |
|||
if (libFd == false) |
|||
return false; |
|||
|
|||
// Read lib elf into target file
|
|||
if (read(libFd, mappedLib, libStat.st_size) != libStat.st_size) |
|||
return false; |
|||
|
|||
// No longer needed
|
|||
close(libFd); |
|||
|
|||
auto eHdr{reinterpret_cast<ElfW(Ehdr) *>(mappedLib)}; |
|||
auto sHdrEntries{reinterpret_cast<ElfW(Shdr) *>(mappedLib + eHdr->e_shoff)}; |
|||
|
|||
// Iterate over section headers to find the .dynamic section
|
|||
for (ElfW(Half) i{}; i < eHdr->e_shnum; i++) { |
|||
auto &sHdr{sHdrEntries[i]}; |
|||
if (sHdr.sh_type == SHT_DYNAMIC) { |
|||
auto strTab{reinterpret_cast<char *>(mappedLib + sHdrEntries[sHdr.sh_link].sh_offset)}; |
|||
auto dynHdrEntries{reinterpret_cast<ElfW(Dyn) *>(mappedLib + sHdr.sh_offset)}; |
|||
|
|||
// Iterate over .dynamic entries to find DT_SONAME
|
|||
for (ElfW(Xword) k{}; k < (sHdr.sh_size / sHdr.sh_entsize); k++) { |
|||
auto &dynHdrEntry{dynHdrEntries[k]}; |
|||
if (dynHdrEntry.d_tag == DT_SONAME) { |
|||
char *soname{strTab + dynHdrEntry.d_un.d_val}; |
|||
|
|||
// Partially replace the old soname with the soname patch
|
|||
size_t charIdx{}; |
|||
for (; soname[charIdx] != 0 && sonamePatch[charIdx] != 0; charIdx++) |
|||
soname[charIdx] = sonamePatch[charIdx]; |
|||
|
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
@ -1,21 +0,0 @@ |
|||
// SPDX-License-Identifier: BSD-2-Clause |
|||
// Copyright © 2021 Billy Laws |
|||
|
|||
#pragma once |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
/** |
|||
* @brief Overwrites a portion of the soname in an elf by loading it into shared memory and modifying .dynstr |
|||
* @note IMPORTANT: The supplied soname patch will overwrite the first strlen(sonamePatch) chars of the soname |
|||
* @param elfPath Full path to the elf to patch |
|||
* @param targetFd FD to use for storing the patched library |
|||
* @return True on success |
|||
*/ |
|||
bool elf_soname_patch(const char *elfPath, int targetFd, const char *newSoname); |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
@ -1,135 +0,0 @@ |
|||
// SPDX-License-Identifier: BSD-2-Clause
|
|||
// Copyright © 2021 Billy Laws
|
|||
|
|||
#include <fstream>
|
|||
#include <string>
|
|||
#include <cstring>
|
|||
#include <sys/mman.h>
|
|||
#include <unistd.h>
|
|||
#include <adrenotools/bcenabler.h>
|
|||
#include "gen/bcenabler_patch.h"
|
|||
|
|||
enum adrenotools_bcn_type adrenotools_get_bcn_type(uint32_t major, uint32_t minor, uint32_t vendorId) { |
|||
if (vendorId != 0x5143 || major != 512) |
|||
return ADRENOTOOLS_BCN_INCOMPATIBLE; |
|||
|
|||
if (minor >= 514) |
|||
return ADRENOTOOLS_BCN_BLOB; |
|||
|
|||
return ADRENOTOOLS_BCN_PATCH; |
|||
} |
|||
|
|||
// Searches /proc/self/maps for the first free page after the given address
|
|||
static void *find_free_page(uintptr_t address) { |
|||
std::ifstream procMaps("/proc/self/maps"); |
|||
|
|||
uintptr_t end{}; |
|||
|
|||
for (std::string line; std::getline(procMaps, line); ) { |
|||
std::size_t addressSeparator{line.find('-')}; |
|||
uintptr_t start{std::strtoull(line.substr(0, addressSeparator).c_str(), nullptr, 16)}; |
|||
|
|||
if (end > address && start != end) |
|||
return reinterpret_cast<void *>(end); |
|||
|
|||
end = std::strtoull(line.substr(addressSeparator + 1, line.find( ' ')).c_str(), nullptr, 16); |
|||
} |
|||
|
|||
return nullptr; |
|||
} |
|||
|
|||
static void *align_ptr(void *ptr) { |
|||
return reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(ptr) & ~(getpagesize() - 1)); |
|||
} |
|||
|
|||
bool adrenotools_patch_bcn(void *vkGetPhysicalDeviceFormatPropertiesFn) { |
|||
union Branch { |
|||
struct { |
|||
int32_t offset : 26; //!< 26-bit branch offset
|
|||
uint8_t sig : 6; //!< 6-bit signature (0x25 for linked, 0x5 for jump)
|
|||
}; |
|||
|
|||
uint32_t raw{}; |
|||
}; |
|||
static_assert(sizeof(Branch) == 4, "Branch size is invalid"); |
|||
|
|||
// Find the nearest unmapped page where we can place patch code
|
|||
void *patchPage{find_free_page(reinterpret_cast<uintptr_t>(vkGetPhysicalDeviceFormatPropertiesFn))}; |
|||
if (!patchPage) |
|||
return false; |
|||
|
|||
// Map patch region
|
|||
void *ptr{mmap(patchPage, getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0)}; |
|||
if (ptr != patchPage) |
|||
return false; |
|||
|
|||
// Allow reading from the blob's .text section since some devices enable ---X
|
|||
// Protect two pages just in case we happen to land on a page boundary
|
|||
if (mprotect(align_ptr(vkGetPhysicalDeviceFormatPropertiesFn), getpagesize() * 2, PROT_WRITE | PROT_READ | PROT_EXEC)) |
|||
return false; |
|||
|
|||
// First branch in this function is targeted at the function we want to patch
|
|||
Branch *blInst{reinterpret_cast<Branch *>(vkGetPhysicalDeviceFormatPropertiesFn)}; |
|||
|
|||
constexpr uint8_t BranchLinkSignature{0x25}; |
|||
|
|||
// Search for first instruction with the BL signature
|
|||
while (blInst->sig != BranchLinkSignature) |
|||
blInst++; |
|||
|
|||
// Internal QGL format conversion function that we need to patch
|
|||
uint32_t *convFormatFn{reinterpret_cast<uint32_t *>(blInst) + blInst->offset}; |
|||
|
|||
// See mprotect call above
|
|||
// This time we also set PROT_WRITE so we can write our patch to the page
|
|||
if (mprotect(align_ptr(convFormatFn), getpagesize() * 2, PROT_WRITE | PROT_READ | PROT_EXEC)) |
|||
return false; |
|||
|
|||
// This would normally set the default result to 0 (error) in the format not found case
|
|||
constexpr uint32_t ClearResultSignature{0x2a1f03e0}; |
|||
|
|||
// We replace it with a branch to our own extended if statement which adds in the extra things for BCn
|
|||
uint32_t *clearResultPtr{convFormatFn}; |
|||
while (*clearResultPtr != ClearResultSignature) |
|||
clearResultPtr++; |
|||
|
|||
// Ensure we don't write out of bounds
|
|||
if (PatchRawData_size > getpagesize()) |
|||
return false; |
|||
|
|||
// Copy the patch function to our mapped page
|
|||
memcpy(patchPage, PatchRawData, PatchRawData_size); |
|||
|
|||
// Fixup the patch code so it correctly returns back to the driver after running
|
|||
constexpr uint32_t PatchReturnFixupMagic{0xffffffff}; |
|||
constexpr uint8_t BranchSignature{0x5}; |
|||
|
|||
uint32_t *fixupTargetPtr{clearResultPtr + 1}; |
|||
auto *fixupPtr{reinterpret_cast<uint32_t *>(patchPage)}; |
|||
for (long unsigned int i{}; i < (PatchRawData_size / sizeof(uint32_t)); i++, fixupPtr++) { |
|||
if (*fixupPtr == PatchReturnFixupMagic) { |
|||
Branch branchToDriver{ |
|||
{ |
|||
.offset = static_cast<int32_t>((reinterpret_cast<intptr_t>(fixupTargetPtr) - reinterpret_cast<intptr_t>(fixupPtr)) / sizeof(int32_t)), |
|||
.sig = BranchSignature, |
|||
} |
|||
}; |
|||
|
|||
*fixupPtr = branchToDriver.raw; |
|||
} |
|||
} |
|||
|
|||
Branch branchToPatch{ |
|||
{ |
|||
.offset = static_cast<int32_t>((reinterpret_cast<intptr_t>(patchPage) - reinterpret_cast<intptr_t>(clearResultPtr)) / sizeof(int32_t)), |
|||
.sig = BranchSignature, |
|||
} |
|||
}; |
|||
|
|||
*clearResultPtr = branchToPatch.raw; |
|||
|
|||
asm volatile("ISB"); |
|||
|
|||
// Done!
|
|||
return true; |
|||
} |
|||
@ -1,83 +0,0 @@ |
|||
cmp w0, 131 |
|||
bne .L2 |
|||
mov w0, 71 |
|||
b .L3 |
|||
.L2: |
|||
cmp w0, 133 |
|||
bne .L4 |
|||
mov w0, 71 |
|||
b .L3 |
|||
.L4: |
|||
cmp w0, 132 |
|||
bne .L5 |
|||
mov w0, 72 |
|||
b .L3 |
|||
.L5: |
|||
cmp w0, 134 |
|||
bne .L6 |
|||
mov w0, 72 |
|||
b .L3 |
|||
.L6: |
|||
cmp w0, 135 |
|||
bne .L7 |
|||
mov w0, 74 |
|||
b .L3 |
|||
.L7: |
|||
cmp w0, 136 |
|||
bne .L8 |
|||
mov w0, 75 |
|||
b .L3 |
|||
.L8: |
|||
cmp w0, 137 |
|||
bne .L9 |
|||
mov w0, 77 |
|||
b .L3 |
|||
.L9: |
|||
cmp w0, 138 |
|||
bne .L10 |
|||
mov w0, 78 |
|||
b .L3 |
|||
.L10: |
|||
cmp w0, 139 |
|||
bne .L11 |
|||
mov w0, 80 |
|||
b .L3 |
|||
.L11: |
|||
cmp w0, 140 |
|||
bne .L12 |
|||
mov w0, 81 |
|||
b .L3 |
|||
.L12: |
|||
cmp w0, 141 |
|||
bne .L13 |
|||
mov w0, 83 |
|||
b .L3 |
|||
.L13: |
|||
cmp w0, 142 |
|||
bne .L14 |
|||
mov w0, 84 |
|||
b .L3 |
|||
.L14: |
|||
cmp w0, 143 |
|||
bne .L15 |
|||
mov w0, 95 |
|||
b .L3 |
|||
.L15: |
|||
cmp w0, 144 |
|||
bne .L16 |
|||
mov w0, 96 |
|||
b .L3 |
|||
.L16: |
|||
cmp w0, 145 |
|||
bne .L17 |
|||
mov w0, 98 |
|||
b .L3 |
|||
.L17: |
|||
cmp w0, 146 |
|||
bne .L18 |
|||
mov w0, 99 |
|||
b .L3 |
|||
.L18: |
|||
mov w0, 0 |
|||
.L3: |
|||
.word 0xffffffff // Branch fixup |
|||
@ -1,210 +0,0 @@ |
|||
// SPDX-License-Identifier: BSD-2-Clause
|
|||
// Copyright © 2021 Billy Laws
|
|||
|
|||
#include <string>
|
|||
#include <string_view>
|
|||
#include <sys/stat.h>
|
|||
#include <sys/ioctl.h>
|
|||
#include <sys/mman.h>
|
|||
#include <dlfcn.h>
|
|||
#include <fcntl.h>
|
|||
#include <android/api-level.h>
|
|||
#include <android/log.h>
|
|||
#include <android_linker_ns.h>
|
|||
#include "hook/kgsl.h"
|
|||
#include "hook/hook_impl_params.h"
|
|||
#include <adrenotools/driver.h>
|
|||
#include <unistd.h>
|
|||
|
|||
void *adrenotools_open_libvulkan(int dlopenFlags, int featureFlags, const char *tmpLibDir, const char *hookLibDir, const char *customDriverDir, const char *customDriverName, const char *fileRedirectDir, void **userMappingHandle) { |
|||
// Bail out if linkernsbypass failed to load, this probably means we're on api < 28
|
|||
if (!linkernsbypass_load_status()) |
|||
return nullptr; |
|||
|
|||
// Always use memfd on Q+ since it's guaranteed to work
|
|||
if (android_get_device_api_level() >= 29) |
|||
tmpLibDir = nullptr; |
|||
|
|||
// Verify that params for specific features are only passed if they are enabled
|
|||
if (!(featureFlags & ADRENOTOOLS_DRIVER_FILE_REDIRECT) && fileRedirectDir) |
|||
return nullptr; |
|||
|
|||
if (!(featureFlags & ADRENOTOOLS_DRIVER_CUSTOM) && (customDriverDir || customDriverName)) |
|||
return nullptr; |
|||
|
|||
if (!(featureFlags & ADRENOTOOLS_DRIVER_GPU_MAPPING_IMPORT) && userMappingHandle) |
|||
return nullptr; |
|||
|
|||
// Verify that params for enabled features are correct
|
|||
struct stat buf{}; |
|||
|
|||
if (featureFlags & ADRENOTOOLS_DRIVER_CUSTOM) { |
|||
if (!customDriverName || !customDriverDir) |
|||
return nullptr; |
|||
|
|||
if (stat((std::string(customDriverDir) + customDriverName).c_str(), &buf) != 0) |
|||
return nullptr; |
|||
} |
|||
|
|||
// Verify that params for enabled features are correct
|
|||
if (featureFlags & ADRENOTOOLS_DRIVER_FILE_REDIRECT) { |
|||
if (!fileRedirectDir) |
|||
return nullptr; |
|||
|
|||
if (stat(fileRedirectDir, &buf) != 0) |
|||
return nullptr; |
|||
} |
|||
|
|||
// Create a namespace that can isolate our hook from the classloader namespace
|
|||
auto hookNs{android_create_namespace("adrenotools-libvulkan", hookLibDir, nullptr, ANDROID_NAMESPACE_TYPE_SHARED, nullptr, nullptr)}; |
|||
|
|||
// Link it to the default namespace so the hook can use libandroid etc
|
|||
if (!linkernsbypass_link_namespace_to_default_all_libs(hookNs)) |
|||
return nullptr; |
|||
|
|||
// Preload the hook implementation, otherwise we get a weird issue where despite being in NEEDED of the hook lib the hook's symbols will overwrite ours and cause an infinite loop
|
|||
auto hookImpl{linkernsbypass_namespace_dlopen("libhook_impl.so", RTLD_NOW, hookNs)}; |
|||
if (!hookImpl) |
|||
return nullptr; |
|||
|
|||
// Pass parameters to the hook implementation
|
|||
auto initHookParam{reinterpret_cast<void (*)(const void *)>(dlsym(hookImpl, "init_hook_param"))}; |
|||
if (!initHookParam) |
|||
return nullptr; |
|||
|
|||
|
|||
auto importMapping{[&]() -> adrenotools_gpu_mapping * { |
|||
if (featureFlags & ADRENOTOOLS_DRIVER_GPU_MAPPING_IMPORT) { |
|||
// This will be leaked, but it's not a big deal since it's only a few bytes
|
|||
adrenotools_gpu_mapping *mapping{new adrenotools_gpu_mapping{}}; |
|||
*userMappingHandle = mapping; |
|||
return mapping; |
|||
} else { |
|||
return nullptr; |
|||
} |
|||
}()}; |
|||
|
|||
initHookParam(new HookImplParams(featureFlags, tmpLibDir, hookLibDir, customDriverDir, customDriverName, fileRedirectDir, importMapping)); |
|||
|
|||
// Load the libvulkan hook into the isolated namespace
|
|||
if (!linkernsbypass_namespace_dlopen("libmain_hook.so", RTLD_GLOBAL, hookNs)) |
|||
return nullptr; |
|||
|
|||
return linkernsbypass_namespace_dlopen_unique("/system/lib64/libvulkan.so", tmpLibDir, dlopenFlags, hookNs); |
|||
} |
|||
|
|||
bool adrenotools_import_user_mem(void *handle, void *hostPtr, uint64_t size) { |
|||
auto importMapping{reinterpret_cast<adrenotools_gpu_mapping *>(handle)}; |
|||
|
|||
kgsl_gpuobj_import_useraddr addr{ |
|||
.virtaddr = reinterpret_cast<uint64_t>(hostPtr), |
|||
}; |
|||
|
|||
kgsl_gpuobj_import userMemImport{ |
|||
.priv = reinterpret_cast<uint64_t>(&addr), |
|||
.priv_len = size, |
|||
.flags = KGSL_CACHEMODE_WRITEBACK << KGSL_CACHEMODE_SHIFT | KGSL_MEMFLAGS_IOCOHERENT, |
|||
.type = KGSL_USER_MEM_TYPE_ADDR, |
|||
|
|||
}; |
|||
|
|||
kgsl_gpuobj_info info{}; |
|||
|
|||
int kgslFd{open("/dev/kgsl-3d0", O_RDWR)}; |
|||
if (kgslFd < 0) |
|||
return false; |
|||
|
|||
int ret{ioctl(kgslFd, IOCTL_KGSL_GPUOBJ_IMPORT, &userMemImport)}; |
|||
if (ret) |
|||
goto err; |
|||
|
|||
info.id = userMemImport.id; |
|||
ret = ioctl(kgslFd, IOCTL_KGSL_GPUOBJ_INFO, &info); |
|||
if (ret) |
|||
goto err; |
|||
|
|||
importMapping->host_ptr = hostPtr; |
|||
importMapping->gpu_addr = info.gpuaddr; |
|||
importMapping->size = size; |
|||
importMapping->flags = 0xc2600; //!< Unknown flags, but they are required for the mapping to work
|
|||
|
|||
close(kgslFd); |
|||
return true; |
|||
|
|||
err: |
|||
close(kgslFd); |
|||
return false; |
|||
} |
|||
|
|||
bool adrenotools_mem_gpu_allocate(void *handle, uint64_t *size) { |
|||
auto mapping{reinterpret_cast<adrenotools_gpu_mapping *>(handle)}; |
|||
|
|||
kgsl_gpuobj_alloc gpuobjAlloc{ |
|||
.size = *size, |
|||
.flags = KGSL_CACHEMODE_WRITEBACK << KGSL_CACHEMODE_SHIFT | KGSL_MEMFLAGS_IOCOHERENT, |
|||
}; |
|||
|
|||
kgsl_gpuobj_info info{}; |
|||
|
|||
int kgslFd{open("/dev/kgsl-3d0", O_RDWR)}; |
|||
if (kgslFd < 0) |
|||
return false; |
|||
|
|||
int ret{ioctl(kgslFd, IOCTL_KGSL_GPUOBJ_ALLOC, &gpuobjAlloc)}; |
|||
if (ret) |
|||
goto err; |
|||
|
|||
*size = gpuobjAlloc.mmapsize; |
|||
|
|||
info.id = gpuobjAlloc.id; |
|||
|
|||
ret = ioctl(kgslFd, IOCTL_KGSL_GPUOBJ_INFO, &info); |
|||
if (ret) |
|||
goto err; |
|||
|
|||
mapping->host_ptr = nullptr; |
|||
mapping->gpu_addr = info.gpuaddr; |
|||
mapping->size = *size; |
|||
mapping->flags = 0xc2600; //!< Unknown flags, but they are required for the mapping to work
|
|||
|
|||
close(kgslFd); |
|||
return true; |
|||
|
|||
err: |
|||
close(kgslFd); |
|||
return false; |
|||
} |
|||
|
|||
|
|||
bool adrenotools_mem_cpu_map(void *handle, void *hostPtr, uint64_t size) { |
|||
auto mapping{reinterpret_cast<adrenotools_gpu_mapping *>(handle)}; |
|||
|
|||
int kgslFd{open("/dev/kgsl-3d0", O_RDWR)}; |
|||
if (kgslFd < 0) |
|||
return false; |
|||
|
|||
mapping->host_ptr = mmap(hostPtr, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, kgslFd, mapping->gpu_addr); |
|||
close(kgslFd); |
|||
return mapping->host_ptr != nullptr; |
|||
} |
|||
|
|||
bool adrenotools_validate_gpu_mapping(void *handle) { |
|||
auto importMapping{reinterpret_cast<adrenotools_gpu_mapping *>(handle)}; |
|||
return importMapping->gpu_addr == ADRENOTOOLS_GPU_MAPPING_SUCCEEDED_MAGIC; |
|||
} |
|||
|
|||
void adrenotools_set_turbo(bool turbo) { |
|||
uint32_t enable{turbo ? 0U : 1U}; |
|||
kgsl_device_getproperty prop{ |
|||
.type = KGSL_PROP_PWRCTRL, |
|||
.value = reinterpret_cast<void *>(&enable), |
|||
.sizebytes = sizeof(enable), |
|||
}; |
|||
|
|||
int kgslFd{open("/dev/kgsl-3d0", O_RDWR)}; |
|||
if (kgslFd < 0) |
|||
return; |
|||
|
|||
ioctl(kgslFd, IOCTL_KGSL_SETPROPERTY, &prop); |
|||
close (kgslFd); |
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
add_library(hook_impl SHARED hook_impl.cpp hook_impl.h hook_impl_params.h) |
|||
|
|||
target_compile_options(hook_impl PRIVATE -Wall -Wextra) |
|||
target_link_libraries(hook_impl linkernsbypass log) |
|||
target_include_directories(hook_impl PRIVATE ../../include) |
|||
set_target_properties(hook_impl PROPERTIES CXX_VISIBILITY_PRESET hidden) |
|||
|
|||
add_library(main_hook SHARED main_hook.c) |
|||
|
|||
target_compile_options(main_hook PRIVATE -Wall -Wextra) |
|||
target_link_options(main_hook PRIVATE -z global) |
|||
target_link_libraries(main_hook hook_impl) |
|||
set_target_properties(main_hook PROPERTIES CXX_VISIBILITY_PRESET hidden) |
|||
|
|||
add_library(file_redirect_hook SHARED file_redirect_hook.c) |
|||
|
|||
target_compile_options(file_redirect_hook PRIVATE -Wall -Wextra) |
|||
target_link_options(file_redirect_hook PRIVATE -z global) |
|||
target_link_libraries(file_redirect_hook hook_impl) |
|||
set_target_properties(file_redirect_hook PROPERTIES CXX_VISIBILITY_PRESET hidden) |
|||
|
|||
add_library(gsl_alloc_hook SHARED gsl_alloc_hook.c) |
|||
|
|||
target_compile_options(gsl_alloc_hook PRIVATE -Wall -Wextra) |
|||
target_link_options(gsl_alloc_hook PRIVATE -z global) |
|||
target_link_libraries(gsl_alloc_hook hook_impl) |
|||
set_target_properties(gsl_alloc_hook PROPERTIES CXX_VISIBILITY_PRESET hidden) |
|||
@ -1,5 +0,0 @@ |
|||
#include "hook_impl.h" |
|||
|
|||
__attribute__((visibility("default"))) FILE *fopen(const char *filename, const char *mode) { |
|||
return hook_fopen(filename, mode); |
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
#include "hook_impl.h" |
|||
|
|||
__attribute__((visibility("default"))) int gsl_memory_alloc_pure(uint32_t size, uint32_t flags, void *memDesc) { |
|||
return hook_gsl_memory_alloc_pure_64((uint64_t)size, flags, memDesc); |
|||
} |
|||
|
|||
__attribute__((visibility("default"))) int gsl_memory_alloc_pure_64(uint64_t size, uint32_t flags, void *memDesc) { |
|||
return hook_gsl_memory_alloc_pure_64(size, flags, memDesc); |
|||
} |
|||
|
|||
__attribute__((visibility("default"))) int gsl_memory_free_pure(void *memDesc) { |
|||
return hook_gsl_memory_free_pure(memDesc); |
|||
} |
|||
@ -1,229 +0,0 @@ |
|||
#include <initializer_list>
|
|||
#include <string>
|
|||
#include <cstdio>
|
|||
#include <cstring>
|
|||
#include <dlfcn.h>
|
|||
#include <fcntl.h>
|
|||
#include <sys/ioctl.h>
|
|||
#include <android_linker_ns.h>
|
|||
#include <android/dlext.h>
|
|||
#include <android/log.h>
|
|||
#include "kgsl.h"
|
|||
#include "hook_impl_params.h"
|
|||
#include "hook_impl.h"
|
|||
|
|||
#define TAG "hook_impl"
|
|||
#define LOGI(fmt, ...) __android_log_print(ANDROID_LOG_INFO, TAG, fmt, ##__VA_ARGS__)
|
|||
|
|||
const HookImplParams *hook_params; //!< Bunch of info needed to load/patch the driver
|
|||
int (*gsl_memory_alloc_pure_sym)(uint32_t, uint32_t, void *); |
|||
int (*gsl_memory_alloc_pure_64_sym)(uint64_t, uint32_t, void *); |
|||
int (*gsl_memory_free_pure_sym)(void *); |
|||
int kgsl_fd; |
|||
|
|||
using gsl_memory_alloc_pure_t = decltype(gsl_memory_alloc_pure_sym); |
|||
using gsl_memory_alloc_pure_64_t = decltype(gsl_memory_alloc_pure_64_sym); |
|||
using gsl_memory_free_pure_t = decltype(gsl_memory_free_pure_sym); |
|||
|
|||
__attribute__((visibility("default"))) void init_hook_param(const void *param) { |
|||
hook_params = reinterpret_cast<const HookImplParams *>(param); |
|||
} |
|||
|
|||
__attribute__((visibility("default"))) void init_gsl(void *alloc, void *alloc64, void *free) { |
|||
gsl_memory_alloc_pure_sym = reinterpret_cast<gsl_memory_alloc_pure_t>(alloc); |
|||
gsl_memory_alloc_pure_64_sym = reinterpret_cast<gsl_memory_alloc_pure_64_t>(alloc64); |
|||
gsl_memory_free_pure_sym = reinterpret_cast<gsl_memory_free_pure_t>(free); |
|||
} |
|||
|
|||
__attribute__((visibility("default"))) void *hook_android_dlopen_ext(const char *filename, int flags, const android_dlextinfo *extinfo) { |
|||
auto fallback{[&]() { |
|||
LOGI("hook_android_dlopen_ext: falling back!"); |
|||
return android_dlopen_ext(filename, flags, extinfo); |
|||
}}; |
|||
|
|||
LOGI("hook_android_dlopen_ext: filename: %s", filename); |
|||
|
|||
// Ignore non-vulkan libraries
|
|||
if (!strstr(filename, "vulkan.")) |
|||
return android_dlopen_ext(filename, flags, extinfo); |
|||
|
|||
if (extinfo->library_namespace == nullptr || !(extinfo->flags & ANDROID_DLEXT_USE_NAMESPACE)) { |
|||
LOGI("hook_android_dlopen_ext: hook failed: namespace not supplied!"); |
|||
return fallback(); |
|||
} |
|||
|
|||
// customDriverDir will be empty if ADRENOTOOLS_DRIVER_CUSTOM isn't set therefore it's fine to have either way
|
|||
auto driverNs{android_create_namespace(filename, hook_params->customDriverDir.c_str(), |
|||
hook_params->hookLibDir.c_str(), ANDROID_NAMESPACE_TYPE_SHARED, |
|||
nullptr, extinfo->library_namespace)}; |
|||
if (!driverNs) { |
|||
LOGI("hook_android_dlopen_ext: hook failed: namespace not supplied!"); |
|||
return fallback(); |
|||
} |
|||
|
|||
// We depend on libandroid which is unlikely to be in the supplied driver namespace so we have to link it over
|
|||
android_link_namespaces(driverNs, nullptr, "libandroid.so"); |
|||
|
|||
// Preload ourself, a new instance will be created since we have different linker ancestory
|
|||
// If we don't preload we get a weird issue where despite being in NEEDED of the hook lib the hook's symbols will overwrite ours and cause an infinite loop
|
|||
auto hookImpl{linkernsbypass_namespace_dlopen("libhook_impl.so", RTLD_NOW, driverNs)}; |
|||
if (!hookImpl) |
|||
return nullptr; |
|||
|
|||
// Pass parameters to ourself
|
|||
auto initHookParam{reinterpret_cast<void (*)(const void *)>(dlsym(hookImpl, "init_hook_param"))}; |
|||
if (!initHookParam) |
|||
return nullptr; |
|||
|
|||
initHookParam(hook_params); |
|||
|
|||
if (hook_params->featureFlags & ADRENOTOOLS_DRIVER_FILE_REDIRECT) { |
|||
if (!linkernsbypass_namespace_dlopen("libfile_redirect_hook.so", RTLD_GLOBAL, driverNs)) { |
|||
LOGI("hook_android_dlopen_ext: hook failed: failed to apply libfopen_redirect_hook!"); |
|||
return fallback(); |
|||
} |
|||
|
|||
LOGI("hook_android_dlopen_ext: applied libfile_redirect_hook"); |
|||
} |
|||
|
|||
// Use our new namespace to load the vulkan driver
|
|||
auto newExtinfo{*extinfo}; |
|||
newExtinfo.library_namespace = driverNs; |
|||
|
|||
if (hook_params->featureFlags & ADRENOTOOLS_DRIVER_GPU_MAPPING_IMPORT) { |
|||
if (!linkernsbypass_namespace_dlopen("libgsl_alloc_hook.so", RTLD_GLOBAL, driverNs)) { |
|||
LOGI("hook_android_dlopen_ext: hook failed: failed to apply libgsl_alloc_hook!"); |
|||
return fallback(); |
|||
} |
|||
|
|||
auto libgslHandle{android_dlopen_ext("vkbgsl.so", RTLD_NOW, &newExtinfo)}; |
|||
if (!libgslHandle) { |
|||
libgslHandle = android_dlopen_ext("notgsl.so", RTLD_NOW, &newExtinfo); |
|||
if (!libgslHandle) |
|||
libgslHandle = android_dlopen_ext("libgsl.so", RTLD_NOW, &newExtinfo); |
|||
} |
|||
|
|||
if (libgslHandle) { |
|||
gsl_memory_alloc_pure_sym = reinterpret_cast<decltype(gsl_memory_alloc_pure_sym)>(dlsym(libgslHandle, "gsl_memory_alloc_pure")); |
|||
gsl_memory_alloc_pure_64_sym = reinterpret_cast<decltype(gsl_memory_alloc_pure_64_sym)>(dlsym(libgslHandle, "gsl_memory_alloc_pure_64")); |
|||
gsl_memory_free_pure_sym = reinterpret_cast<decltype(gsl_memory_free_pure_sym)>(dlsym(libgslHandle, "gsl_memory_free_pure")); |
|||
if ((gsl_memory_alloc_pure_sym || gsl_memory_alloc_pure_64_sym) && gsl_memory_free_pure_sym) { |
|||
auto initGsl{reinterpret_cast<void (*)(gsl_memory_alloc_pure_t, gsl_memory_alloc_pure_64_t, gsl_memory_free_pure_t)>(dlsym(hookImpl, "init_gsl"))}; |
|||
if (!initGsl) |
|||
return fallback(); |
|||
|
|||
initGsl(gsl_memory_alloc_pure_sym, gsl_memory_alloc_pure_64_sym, gsl_memory_free_pure_sym); |
|||
LOGI("hook_android_dlopen_ext: applied libgsl_alloc_hook"); |
|||
hook_params->nextGpuMapping->gpu_addr = ADRENOTOOLS_GPU_MAPPING_SUCCEEDED_MAGIC; |
|||
} |
|||
} |
|||
|
|||
if (!((gsl_memory_alloc_pure_sym || gsl_memory_alloc_pure_64_sym) && gsl_memory_free_pure_sym)) |
|||
LOGI("hook_android_dlopen_ext: hook failed: failed to apply libgsl_alloc_hook!"); |
|||
} |
|||
|
|||
// TODO: If there is already an instance of a Vulkan driver loaded hooks won't be applied, this will only be the case for skiavk generally
|
|||
// To fix this we would need to search /proc/self/maps for the file to a loaded instance of the library in order to read it to patch the soname and load it uniquely
|
|||
if (hook_params->featureFlags & ADRENOTOOLS_DRIVER_CUSTOM) { |
|||
LOGI("hook_android_dlopen_ext: loading custom driver: %s%s", hook_params->customDriverDir.c_str(), hook_params->customDriverName.c_str()); |
|||
void *handle{android_dlopen_ext(hook_params->customDriverName.c_str(), flags, &newExtinfo)}; |
|||
if (!handle) { |
|||
LOGI("hook_android_dlopen_ext: hook failed: failed to load custom driver: %s!", dlerror()); |
|||
return fallback(); |
|||
} |
|||
|
|||
return handle; |
|||
} else { |
|||
LOGI("hook_android_dlopen_ext: loading default driver: %s", filename); |
|||
return android_dlopen_ext(filename, flags, &newExtinfo); |
|||
} |
|||
} |
|||
|
|||
__attribute__((visibility("default"))) void *hook_android_load_sphal_library(const char *filename, int flags) { |
|||
LOGI("hook_android_load_sphal_library: filename: %s", filename); |
|||
|
|||
// https://android.googlesource.com/platform/system/core/+/master/libvndksupport/linker.cpp
|
|||
for (const char *name : {"sphal", "vendor", "default"}) { |
|||
if (auto vendorNs{android_get_exported_namespace(name)}) { |
|||
android_dlextinfo dlextinfo{ |
|||
.flags = ANDROID_DLEXT_USE_NAMESPACE, |
|||
.library_namespace = vendorNs, |
|||
}; |
|||
|
|||
return hook_android_dlopen_ext(filename, flags, &dlextinfo); |
|||
} |
|||
} |
|||
|
|||
return nullptr; |
|||
} |
|||
|
|||
__attribute__((visibility("default"))) FILE *hook_fopen(const char *filename, const char *mode) { |
|||
if (!strncmp("/proc", filename, 5) || !strncmp("/sys", filename, 4)) { |
|||
LOGI("hook_fopen: passthrough: %s", filename); |
|||
return fopen(filename, mode); |
|||
} |
|||
|
|||
auto replacement{hook_params->fileRedirectDir + filename}; |
|||
LOGI("hook_fopen: %s -> %s", filename, replacement.c_str()); |
|||
|
|||
return fopen(replacement.c_str(), mode); |
|||
} |
|||
|
|||
static constexpr uintptr_t GslMemDescImportedPrivMagic{0xdeadb33f}; |
|||
struct GslMemDesc { |
|||
void *hostptr; |
|||
uint64_t gpuaddr; |
|||
uint64_t size; |
|||
uint64_t flags; |
|||
uintptr_t priv; |
|||
}; |
|||
|
|||
__attribute__((visibility("default"))) int hook_gsl_memory_alloc_pure_64(uint64_t size, uint32_t flags, void *memDesc) { |
|||
auto gslMemDesc{reinterpret_cast<GslMemDesc *>(memDesc)}; |
|||
if (hook_params->nextGpuMapping && hook_params->nextGpuMapping->size == size && (hook_params->nextGpuMapping->flags & flags) == hook_params->nextGpuMapping->flags) { |
|||
auto &nextMapping{*hook_params->nextGpuMapping}; |
|||
|
|||
gslMemDesc->hostptr = nextMapping.host_ptr; |
|||
gslMemDesc->gpuaddr = nextMapping.gpu_addr; |
|||
gslMemDesc->size = nextMapping.size; |
|||
gslMemDesc->flags = nextMapping.flags; |
|||
gslMemDesc->priv = GslMemDescImportedPrivMagic; |
|||
hook_params->nextGpuMapping->size = 0; |
|||
hook_params->nextGpuMapping->gpu_addr = ADRENOTOOLS_GPU_MAPPING_SUCCEEDED_MAGIC; |
|||
return 0; |
|||
} else { |
|||
if (gsl_memory_alloc_pure_64_sym) |
|||
return gsl_memory_alloc_pure_64_sym(size, flags, gslMemDesc); |
|||
else |
|||
return gsl_memory_alloc_pure_sym((uint32_t)size, flags, gslMemDesc); |
|||
} |
|||
} |
|||
|
|||
__attribute__((visibility("default"))) int hook_gsl_memory_free_pure(void *memDesc) { |
|||
auto gslMemDesc{reinterpret_cast<GslMemDesc *>(memDesc)}; |
|||
|
|||
if (gslMemDesc->priv == GslMemDescImportedPrivMagic) { |
|||
if (!kgsl_fd) |
|||
kgsl_fd = open("/dev/kgsl-3d0", O_RDWR); |
|||
|
|||
kgsl_gpumem_get_info info{ |
|||
.gpuaddr = gslMemDesc->gpuaddr |
|||
}; |
|||
|
|||
if (ioctl(kgsl_fd, IOCTL_KGSL_GPUMEM_GET_INFO, &info) < 0) { |
|||
LOGI("IOCTL_KGSL_GPUMEM_GET_INFO failed"); |
|||
return 0; |
|||
} |
|||
|
|||
kgsl_gpuobj_free args{ |
|||
.id = info.id, |
|||
}; |
|||
|
|||
if (ioctl(kgsl_fd, IOCTL_KGSL_GPUOBJ_FREE, &args) < 0) |
|||
LOGI("IOCTL_KGSL_GPUOBJ_FREE failed"); |
|||
|
|||
return 0; |
|||
} else { |
|||
return gsl_memory_free_pure_sym(memDesc); |
|||
} |
|||
} |
|||
@ -1,30 +0,0 @@ |
|||
// SPDX-License-Identifier: BSD-2-Clause |
|||
// Copyright © 2021 Billy Laws |
|||
|
|||
#pragma once |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
#include <stdio.h> |
|||
#include <android/dlext.h> |
|||
|
|||
void init_hook_param(const void *param); |
|||
|
|||
void init_gsl(void *alloc, void *alloc64, void *free); |
|||
|
|||
void *hook_android_dlopen_ext(const char *filename, int flags, const android_dlextinfo *extinfo); |
|||
|
|||
void *hook_android_load_sphal_library(const char *filename, int flags); |
|||
|
|||
FILE *hook_fopen(const char *filename, const char *mode); |
|||
|
|||
int hook_gsl_memory_alloc_pure_64(uint64_t size, uint32_t flags, void *memDesc); |
|||
|
|||
int hook_gsl_memory_free_pure(void *memDesc); |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
|
|||
@ -1,31 +0,0 @@ |
|||
// SPDX-License-Identifier: BSD-2-Clause |
|||
// Copyright © 2021 Billy Laws |
|||
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <adrenotools/priv.h> |
|||
|
|||
/** |
|||
* @brief Holds the parameters needed for all hooks |
|||
* @note See comments for adrenotools_open_libvulkan as a reference for member variables |
|||
*/ |
|||
struct HookImplParams { |
|||
int featureFlags; |
|||
std::string tmpLibDir; |
|||
std::string hookLibDir; |
|||
std::string customDriverDir; |
|||
std::string customDriverName; |
|||
std::string fileRedirectDir; |
|||
adrenotools_gpu_mapping *nextGpuMapping; |
|||
|
|||
HookImplParams(int featureFlags, const char *tmpLibDir, const char *hookLibDir, const char *customDriverDir, |
|||
const char *customDriverName, const char *fileRedirectDir, adrenotools_gpu_mapping *nextGpuMapping) |
|||
: featureFlags(featureFlags), |
|||
tmpLibDir(tmpLibDir ? tmpLibDir : ""), |
|||
hookLibDir(hookLibDir), |
|||
customDriverDir(customDriverDir ? customDriverDir : ""), |
|||
customDriverName(customDriverName ? customDriverName : ""), |
|||
fileRedirectDir(fileRedirectDir ? fileRedirectDir : ""), |
|||
nextGpuMapping(nextGpuMapping) {} |
|||
}; |
|||
2124
externals/libadrenotools/src/hook/kgsl.h
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1,9 +0,0 @@ |
|||
#include "hook_impl.h" |
|||
|
|||
__attribute__((visibility("default"))) void *android_dlopen_ext(const char *filename, int flags, const android_dlextinfo *extinfo) { |
|||
return hook_android_dlopen_ext(filename, flags, extinfo); |
|||
} |
|||
|
|||
__attribute__((visibility("default"))) void *android_load_sphal_library(const char *filename, int flags) { |
|||
return hook_android_load_sphal_library(filename, flags); |
|||
} |
|||
@ -1,96 +0,0 @@ |
|||
# Android Driver Package Format |
|||
|
|||
## Contents |
|||
- `meta.json` that follows `Schema` |
|||
- `<driver>.so` main driver shared library |
|||
- `*.so` all libraries depended on by the main driver library, these must have their sonames altered if they wish to replace the system version of the library |
|||
|
|||
## Example |
|||
- `meta.json`: |
|||
```json |
|||
{ |
|||
"schemaVersion": 1, |
|||
"name": "Qualcomm v615 Vulkan driver", |
|||
"description": "Proprietary Vulkan driver for Adreno 6xx and Adreno 7xx", |
|||
"author": "ByLaws", |
|||
"packageVersion": "2", |
|||
"vendor": "Qualcomm", |
|||
"driverVersion": "0.615.0", |
|||
"minApi": 27, |
|||
"libraryName": "vulkan.ad0615.so" |
|||
} |
|||
``` |
|||
|
|||
- `vulkan.ad0615.so`: main patched driver |
|||
- `notadreno_utils.so`, `notdmabufheap.so`, `notgsl.so`, `notllvm-glnext.so`, `notllvm-qgl.so`: patched-soname versions of libraries specific to each driver version |
|||
- `android.hardware.graphics.mappershim.so`, `vendor.qti.hardware.display.mapperextensionsshim.so`, `vendor.qti.hardware.display.mappershim.so`: qtimapper-shim libs |
|||
|
|||
## Creation |
|||
I recommend running blob-patcher.py to patch a set of blobs from a device dump with mapper ver as 5, then copying in the qtimapper-shim files from the adrenotools releases page. |
|||
```bash |
|||
$ mkdir outpkg |
|||
$ patch.py <device dump> outpkg vulkan.adreno.so vulkan.ad0615.so 1 |
|||
$ vim outpkg/meta.json |
|||
$ cp qtimapper-shim-rel/* outpkg |
|||
``` |
|||
|
|||
## Schema |
|||
```json |
|||
{ |
|||
"$schema": "https://json-schema.org/draft/2020-12/schema", |
|||
"title": "ADPKG Schema", |
|||
"type": "object", |
|||
"properties": { |
|||
"schemaVersion": { |
|||
"type": "number", |
|||
"example": 1 |
|||
}, |
|||
"name": { |
|||
"type": "string", |
|||
"example": "Qualcomm Adreno Driver" |
|||
}, |
|||
"vendor": { |
|||
"enum": [ |
|||
"Qualcomm", |
|||
"Mesa" |
|||
], |
|||
}, |
|||
"driverVersion": { |
|||
"type": "string", |
|||
"pattern": "^[0-9]+.[0-9]+.[0-9]+(-.+)?$", |
|||
"example": "512.604.0" |
|||
}, |
|||
"author": { |
|||
"type": "string", |
|||
"example": "Billy Laws" |
|||
}, |
|||
"description": { |
|||
"type": "string", |
|||
"description": "Additional description of the driver, this shouldn't contain redundant information that is already covered by the other fields such as the version and only denote details important for the user" |
|||
}, |
|||
"packageVersion": { |
|||
"type": "string", |
|||
"example": "3029-bylaws" |
|||
}, |
|||
"minApi": { |
|||
"type": "number", |
|||
"description": "The minimum Android API version required by the driver to function correctly", |
|||
"example": 27 |
|||
}, |
|||
"libraryName": { |
|||
"type": "string", |
|||
"description": "The name of the main shared library object", |
|||
"example": "vulkan.adreno.so" |
|||
}, |
|||
}, |
|||
"required": [ |
|||
"schemaVersion", |
|||
"name", |
|||
"author", |
|||
"packageVersion", |
|||
"vendor", |
|||
"driverVersion", |
|||
"minApi", |
|||
] |
|||
} |
|||
``` |
|||
@ -1,7 +0,0 @@ |
|||
## Tools for working with the Adreno Vulkan blob |
|||
|
|||
blob-patcher.py is a script for generating adrenotools loadable drivers from an extracted ROM zip |
|||
qtimapper-shim allows newer drivers to work on devices that lack support for the new mapper HAL |
|||
acc-shim allows for suppling arguments to the underlying LLVM-based shader compiler library |
|||
|
|||
|
|||
@ -1,12 +0,0 @@ |
|||
## Adreno Compiler Collection parameter shim |
|||
|
|||
### TODO |
|||
Make some sort of API for this so parameters can be changed through adrenotools in realtime. |
|||
|
|||
### Compilation |
|||
``` |
|||
$ sed -i 's/libllvm-glnext/notreal-glnext/g' libllvm-glnext.so |
|||
$ mv libllvm-glnext.so notreal-glnext.so |
|||
$ aarch64-linux-android28-clang vk_acc_shim.cpp -o notllvm-glnext.so --shared -fpic |
|||
$ sed -i 's/libllvm-glnext/notllvm-glnext/g' vulkan.adreno.so |
|||
``` |
|||
@ -1,108 +0,0 @@ |
|||
#include <stdint.h>
|
|||
#include <dlfcn.h>
|
|||
#include <string.h>
|
|||
#include <android/log.h>
|
|||
|
|||
thread_local int satisfy_driver_emutls; |
|||
|
|||
// Check libllvm-glnext.so in older drivers for a full list of these, newer ones are slightly more awkward due to the split
|
|||
enum class OptionType : uint32_t { |
|||
ArgsStringList = 1, |
|||
QcArgsString = 4, |
|||
OptLevelInt = 0x101, |
|||
NoOptsInt = 0x10D, |
|||
}; |
|||
|
|||
struct StringListVal { |
|||
uint32_t len; |
|||
const char **entry; |
|||
}; |
|||
|
|||
struct Option |
|||
{ |
|||
OptionType type; |
|||
// PAD
|
|||
union { |
|||
bool boolVal; |
|||
int intVal; |
|||
float floatVal; |
|||
StringListVal *strVals; |
|||
const char *strVal; |
|||
}; |
|||
}; |
|||
|
|||
|
|||
struct OptionsSet |
|||
{ |
|||
Option *options; |
|||
uint32_t num; |
|||
}; |
|||
|
|||
|
|||
int CompileHook(void *state, OptionsSet *opts); |
|||
|
|||
decltype(CompileHook) *OrigCompile{}; |
|||
|
|||
int CompileHook(void *state, OptionsSet *opts) { |
|||
constexpr size_t ReplacementOptsNum = 201; |
|||
|
|||
Option replacementOpts[ReplacementOptsNum]; |
|||
uint32_t patchedOptNum{}; |
|||
|
|||
// Insert your desired args here - results will be written to stderr
|
|||
const char *argv[] = {"-help", "-help-hidden", "", NULL }; |
|||
StringListVal listVal{ |
|||
.len = 3, |
|||
.entry = argv, |
|||
}; |
|||
|
|||
replacementOpts[patchedOptNum++] = { |
|||
.type = OptionType::ArgsStringList, |
|||
.strVals = &listVal |
|||
}; |
|||
|
|||
const char *opt ="Verbose=true Quiet=false"; |
|||
replacementOpts[patchedOptNum++] = { |
|||
.type = OptionType::QcArgsString, |
|||
.strVal = opt |
|||
}; |
|||
|
|||
if (opts->num + patchedOptNum > ReplacementOptsNum) |
|||
__builtin_trap(); |
|||
|
|||
memcpy(&replacementOpts[patchedOptNum], opts->options, sizeof(Option) * opts->num); |
|||
|
|||
OptionsSet optList{ |
|||
.options = replacementOpts, |
|||
.num = opts->num + patchedOptNum |
|||
}; |
|||
|
|||
return OrigCompile(state, &optList); |
|||
} |
|||
|
|||
|
|||
struct LlvmInterface { |
|||
uint32_t unk0[3]; |
|||
// PAD
|
|||
void *makeContext; |
|||
void *delContext; |
|||
decltype(CompileHook) *compile; |
|||
void *unk; |
|||
}; |
|||
|
|||
extern "C" int LoadACC(LlvmInterface *impl); |
|||
|
|||
extern "C" __attribute__((visibility("default"))) int LoadACC(LlvmInterface *impl) { |
|||
void *hnd = dlopen("notreal-glnext.so", RTLD_NOW); |
|||
|
|||
auto origLoadACC = reinterpret_cast<decltype(LoadACC) *>(dlsym(hnd, "LoadACC")); |
|||
if (!origLoadACC) |
|||
__builtin_trap(); |
|||
|
|||
int ret = origLoadACC(impl); |
|||
|
|||
OrigCompile = impl->compile; |
|||
impl->compile = &CompileHook; |
|||
|
|||
return ret; |
|||
} |
|||
@ -1,67 +0,0 @@ |
|||
#!/usr/bin/python3 |
|||
import sys, os |
|||
|
|||
def patch_lib_base(in_dir, out_dir, libs, in_name, out_name): |
|||
with open(in_dir + in_name, "rb") as inf: |
|||
with open(out_dir + out_name, "wb") as outf: |
|||
content = inf.read() |
|||
for lib in libs: |
|||
print(out_name + ": repl:", lib[0], "->", lib[1]) |
|||
content = content.replace(lib[0].encode(), lib[1].encode()) |
|||
|
|||
content = content.replace(in_name.encode(), out_name.encode()) |
|||
outf.write(content); |
|||
|
|||
def patch_lib(in_dir, out_dir, libs, name): |
|||
patch_lib_base(in_dir, out_dir, libs, "lib" + name + ".so", "not" + name + ".so") |
|||
|
|||
def patch_references(lib_dir, out_dir, vulkan_libname, vulkan_newname, shim_mapper): |
|||
try: |
|||
os.mkdir(out_dir) |
|||
os.mkdir(out_dir + "/hw") |
|||
except: |
|||
pass |
|||
|
|||
replacement_list = [("libgsl.so", "notgsl.so"), ("libllvm-glnext.so", "notllvm-glnext.so"), ("libdmabufheap.so", "notdmabufheap.so"), ("libadreno_utils.so", "notadreno_utils.so"), ("libllvm-qgl.so", "notllvm-qgl.so")] |
|||
|
|||
if (shim_mapper < 2): |
|||
replacement_list += [("vendor.qti.hardware.display.mapper@2.0.so", "vendor.qti.hardware.display.mappershim.so"), |
|||
("android.hardware.graphics.mapper@2.0.so", "android.hardware.graphics.mappershim.so"), |
|||
("vendor.qti.hardware.display.mapperextensions@1.0.so", "vendor.qti.hardware.display.mapperextensionsshim.so"), |
|||
("vendor.qti.hardware.display.mapperextensions@1.1.so", "vendor.qti.hardware.display.mapperextensionsshim.so")] |
|||
if (shim_mapper < 3): |
|||
replacement_list += [("vendor.qti.hardware.display.mapper@3.0.so", "vendor.qti.hardware.display.mappershim.so"), |
|||
("android.hardware.graphics.mapper@3.0.so", "android.hardware.graphics.mappershim.so")] |
|||
if (shim_mapper < 4): |
|||
replacement_list += [("vendor.qti.hardware.display.mapper@4.0.so", "vendor.qti.hardware.display.mappershim.so"), |
|||
("android.hardware.graphics.mapper@4.0.so", "android.hardware.graphics.mappershim.so")] |
|||
|
|||
for lib in ["gsl", "llvm-glnext", "dmabufheap", "adreno_utils", "llvm-qgl"]: |
|||
try: |
|||
patch_lib(lib_dir, out_dir, replacement_list, lib) |
|||
except: |
|||
pass |
|||
|
|||
patch_lib_base(lib_dir + "/hw/", out_dir + "/hw/", replacement_list, vulkan_libname, vulkan_newname) |
|||
|
|||
if (len(sys.argv)!= 6): |
|||
print("<in> <out> <vk soname> <vk soname new> <device mapper ver>") |
|||
sys.exit() |
|||
|
|||
|
|||
|
|||
root_path = sys.argv[1] |
|||
out_path = sys.argv[2] |
|||
vulkan_libname = sys.argv[3] |
|||
vulkan_newname = sys.argv[4] |
|||
shim_mapper = int(sys.argv[5]) |
|||
vendor_path = root_path + "/vendor/" |
|||
|
|||
if (len(vulkan_newname) != len(vulkan_libname)): |
|||
print("Errror") |
|||
sys.exit() |
|||
|
|||
for libdir in ["/lib64/", "/lib/"]: |
|||
patch_references(vendor_path + libdir, out_path + libdir, vulkan_libname, vulkan_newname, shim_mapper) |
|||
print("done!") |
|||
|
|||
@ -1,9 +0,0 @@ |
|||
BasedOnStyle: Google |
|||
AllowShortFunctionsOnASingleLine: Inline |
|||
ColumnLimit: 100 |
|||
CommentPragmas: NOLINT:.* |
|||
DerivePointerAlignment: false |
|||
IndentWidth: 2 |
|||
PointerAlignment: Left |
|||
TabWidth: 2 |
|||
UseTab: Never |
|||
@ -1,37 +0,0 @@ |
|||
cc_defaults { |
|||
name: "shim_defaults", |
|||
|
|||
srcs: [ |
|||
"shim.cpp", |
|||
"ext/gr_utils.cpp", |
|||
"ext/gr_adreno_info.cpp", |
|||
], |
|||
|
|||
shared_libs: [ |
|||
"liblog", |
|||
"libcutils", |
|||
"libhidlbase", |
|||
"libhardware", |
|||
"libutils", |
|||
], |
|||
|
|||
cflags: [ |
|||
"-Wno-error", |
|||
"-Wno-unused-parameter", |
|||
], |
|||
} |
|||
|
|||
cc_library_shared { |
|||
name: "vendor.qti.hardware.display.mappershim", |
|||
defaults: ["shim_defaults"], |
|||
} |
|||
|
|||
cc_library_shared { |
|||
name: "vendor.qti.hardware.display.mapperextensionsshim", |
|||
defaults: ["shim_defaults"], |
|||
} |
|||
|
|||
cc_library_shared { |
|||
name: "android.hardware.graphics.mappershim", |
|||
defaults: ["shim_defaults"], |
|||
} |
|||
@ -1,19 +0,0 @@ |
|||
## QtiMapper-shim |
|||
|
|||
A shim that translates between the IQtiMapper(2,3,4) API used by newer Adreno graphics drivers and gralloc1, which is the only available gralloc API on sdm845. |
|||
|
|||
### Method |
|||
|
|||
Exposes the same ABI as the newer mapper blobs and stubs enough functions to force the HAL to fallback to the 2.0 mapper/mapperextension API which is then shimmed with a passthrough to gralloc1. The blobs can then be patched to load the stub libs instead, see the blob-patcher script. |
|||
The code is fairly ugly but functional enough for the purpose, some functions are missing and will need to be implemented in the case that the driver starts using them. |
|||
|
|||
|
|||
### Building |
|||
|
|||
Chuck into a lineage tree, then: |
|||
``` |
|||
make vendor.qti.hardware.display.mappershim |
|||
make vendor.qti.hardware.display.mapperextensionsshim |
|||
make android.hardware.graphics.mappershim |
|||
``` |
|||
and grab SOs out of outputs dir |
|||
@ -1,173 +0,0 @@ |
|||
/* |
|||
* 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. |
|||
*/ |
|||
|
|||
#ifndef __QTIGRALLOCDEFS_H__ |
|||
#define __QTIGRALLOCDEFS_H__ |
|||
|
|||
// From gralloc_priv.h |
|||
|
|||
/* Gralloc usage bits indicating the type of allocation that should be used */ |
|||
/* Refer to BufferUsage in hardware/interfaces/graphics/common/<ver>/types.hal */ |
|||
|
|||
/* The bits below are in officially defined vendor space |
|||
* i.e bits 28-31 and 48-63*/ |
|||
/* Non linear, Universal Bandwidth Compression */ |
|||
#define GRALLOC_USAGE_PRIVATE_ALLOC_UBWC (UINT32_C(1) << 28) |
|||
|
|||
/* Set this for allocating uncached memory (using O_DSYNC), |
|||
* cannot be used with noncontiguous heaps */ |
|||
#define GRALLOC_USAGE_PRIVATE_UNCACHED (UINT32_C(1) << 29) |
|||
|
|||
/* This flag is used to indicate 10 bit format. |
|||
* When both GRALLOC_USAGE_PRIVATE_ALLOC_UBWC & GRALLOC_USAGE_PRIVATE_10BIT |
|||
* are set then it will indicate UBWC_TP10 format. |
|||
* When only GRALLOC_USAGE_PRIVATE_10BIT is set it will indicate linear P010 format. |
|||
*/ |
|||
#define GRALLOC_USAGE_PRIVATE_10BIT (UINT32_C(1) << 30) |
|||
|
|||
/* This flag is used for SECURE display usecase */ |
|||
#define GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY (UINT32_C(1) << 31) |
|||
|
|||
/* This flag is used to indicate video NV21 format */ |
|||
#define GRALLOC_USAGE_PRIVATE_VIDEO_NV21_ENCODER 1ULL << 48 |
|||
|
|||
/* unused legacy flags */ |
|||
#define GRALLOC_USAGE_PRIVATE_MM_HEAP 0 |
|||
#define GRALLOC_USAGE_PRIVATE_IOMMU_HEAP 0 |
|||
|
|||
/* This flag is set for WFD usecase */ |
|||
#define GRALLOC_USAGE_PRIVATE_WFD 1ULL << 51 |
|||
|
|||
/* This flag is set for HEIF usecase */ |
|||
#define GRALLOC_USAGE_PRIVATE_HEIF (UINT32_C(1) << 27) |
|||
|
|||
/* TODO(user): Remove when clients stop referencing this flag */ |
|||
#define GRALLOC_USAGE_PRIVATE_10BIT_TP 0 |
|||
|
|||
/* This flag indicates PI format is being used */ |
|||
#define GRALLOC_USAGE_PRIVATE_ALLOC_UBWC_PI 1ULL << 49 |
|||
|
|||
/* This flag is set while CDSP accesses the buffer */ |
|||
#define GRALLOC_USAGE_PRIVATE_CDSP 1ULL << 50 |
|||
|
|||
// OEM specific HAL formats |
|||
#define HAL_PIXEL_FORMAT_RGBA_5551 6 |
|||
#define HAL_PIXEL_FORMAT_RGBA_4444 7 |
|||
#define HAL_PIXEL_FORMAT_NV12_ENCODEABLE 0x102 |
|||
#define HAL_PIXEL_FORMAT_NV21_ENCODEABLE 0x7FA30C00 |
|||
#define HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS 0x7FA30C04 |
|||
#define HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED 0x7FA30C03 |
|||
#define HAL_PIXEL_FORMAT_YCbCr_420_SP 0x109 |
|||
#define HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO 0x7FA30C01 |
|||
#define HAL_PIXEL_FORMAT_YCrCb_422_SP 0x10B |
|||
#define HAL_PIXEL_FORMAT_R_8 0x10D |
|||
#define HAL_PIXEL_FORMAT_RG_88 0x10E |
|||
#define HAL_PIXEL_FORMAT_YCbCr_444_SP 0x10F |
|||
#define HAL_PIXEL_FORMAT_YCrCb_444_SP 0x110 |
|||
#define HAL_PIXEL_FORMAT_YCrCb_422_I 0x111 |
|||
#define HAL_PIXEL_FORMAT_BGRX_8888 0x112 |
|||
#define HAL_PIXEL_FORMAT_NV21_ZSL 0x113 |
|||
#define HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS 0x114 |
|||
#define HAL_PIXEL_FORMAT_BGR_565 0x115 |
|||
#define HAL_PIXEL_FORMAT_RAW8 0x123 |
|||
#define HAL_PIXEL_FORMAT_NV12_HEIF 0x116 |
|||
|
|||
// 10 bit |
|||
#define HAL_PIXEL_FORMAT_ARGB_2101010 0x117 |
|||
#define HAL_PIXEL_FORMAT_RGBX_1010102 0x118 |
|||
#define HAL_PIXEL_FORMAT_XRGB_2101010 0x119 |
|||
#define HAL_PIXEL_FORMAT_BGRA_1010102 0x11A |
|||
#define HAL_PIXEL_FORMAT_ABGR_2101010 0x11B |
|||
#define HAL_PIXEL_FORMAT_BGRX_1010102 0x11C |
|||
#define HAL_PIXEL_FORMAT_XBGR_2101010 0x11D |
|||
#define HAL_PIXEL_FORMAT_YCbCr_420_P010 0x36 // HAL_PIXEL_FORMAT_YCBCR_P010 |
|||
#define HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC 0x124 |
|||
#define HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS 0x7FA30C0A |
|||
|
|||
#define HAL_PIXEL_FORMAT_CbYCrY_422_I 0x120 |
|||
#define HAL_PIXEL_FORMAT_BGR_888 0x121 |
|||
|
|||
#define HAL_PIXEL_FORMAT_INTERLACE 0x180 |
|||
|
|||
// Camera utils format |
|||
#define HAL_PIXEL_FORMAT_NV12_LINEAR_FLEX 0x125 |
|||
#define HAL_PIXEL_FORMAT_NV12_UBWC_FLEX 0x126 |
|||
#define HAL_PIXEL_FORMAT_MULTIPLANAR_FLEX 0x127 |
|||
#define HAL_PIXEL_FORMAT_NV12_UBWC_FLEX_2_BATCH 0x128 |
|||
#define HAL_PIXEL_FORMAT_NV12_UBWC_FLEX_4_BATCH 0x129 |
|||
#define HAL_PIXEL_FORMAT_NV12_UBWC_FLEX_8_BATCH 0x130 |
|||
|
|||
// FSC Formats |
|||
#define HAL_PIXEL_FORMAT_RGB888_UBWC_FSC 0x131 |
|||
#define HAL_PIXEL_FORMAT_RGB101010_UBWC_FSC 0x132 |
|||
|
|||
// v4l2_fourcc('Y', 'U', 'Y', 'L'). 24 bpp YUYV 4:2:2 10 bit per component |
|||
#define HAL_PIXEL_FORMAT_YCbCr_422_I_10BIT 0x4C595559 |
|||
|
|||
// v4l2_fourcc('Y', 'B', 'W', 'C'). 10 bit per component. This compressed |
|||
// format reduces the memory access bandwidth |
|||
#define HAL_PIXEL_FORMAT_YCbCr_422_I_10BIT_COMPRESSED 0x43574259 |
|||
|
|||
// UBWC aligned Venus format |
|||
#define HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC 0x7FA30C06 |
|||
#define HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC 0x7FA30C09 |
|||
|
|||
// Khronos ASTC formats |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9 |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC |
|||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD |
|||
|
|||
enum { BUFFER_TYPE_UI = 0, BUFFER_TYPE_VIDEO }; |
|||
|
|||
#endif //__QTIGRALLOCDEFS_H__ |
|||
@ -1,86 +0,0 @@ |
|||
/* |
|||
* Copyright 2022 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. |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <hidl/HidlSupport.h> |
|||
#include <hidl/MQDescriptor.h> |
|||
#include <hidl/Status.h> |
|||
#include <utils/NativeHandle.h> |
|||
|
|||
#include "types/common.h" |
|||
|
|||
using namespace android::hardware; |
|||
using namespace android; |
|||
|
|||
/* Simplified version of hidl::base::V1_0::IBase */ |
|||
struct IBase : virtual public RefBase { |
|||
virtual bool isRemote() const; |
|||
|
|||
using interfaceChain_cb = std::function<void(const hidl_vec<hidl_string>& descriptors)>; |
|||
virtual Return<void> interfaceChain(interfaceChain_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
virtual Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
using interfaceDescriptor_cb = std::function<void(const hidl_string& descriptor)>; |
|||
virtual Return<void> interfaceDescriptor(interfaceDescriptor_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
using getHashChain_cb = std::function<void(const hidl_vec<hidl_array<uint8_t, 32>>& hashchain)>; |
|||
virtual Return<void> getHashChain(getHashChain_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
virtual Return<void> setHALInstrumentation() { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
virtual Return<bool> linkToDeath(const sp<hidl_death_recipient>& recipient, uint64_t cookie) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
virtual Return<void> ping() { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
using getDebugInfo_cb = std::function<void(const hidl::base::V1_0::DebugInfo& info)>; |
|||
virtual Return<void> getDebugInfo(getDebugInfo_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
virtual Return<void> notifySyspropsChanged() { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
virtual Return<bool> unlinkToDeath(const sp<hidl_death_recipient>& recipient) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
}; |
|||
@ -1,344 +0,0 @@ |
|||
/*
|
|||
* Copyright (c) 2011-2018, 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 "gr_adreno_info.h"
|
|||
|
|||
#include <cutils/properties.h>
|
|||
#include <dlfcn.h>
|
|||
#include <log/log.h>
|
|||
|
|||
#include <mutex>
|
|||
|
|||
#include "gr_utils.h"
|
|||
#include "gralloc_priv.h"
|
|||
|
|||
using std::lock_guard; |
|||
using std::mutex; |
|||
|
|||
namespace gralloc { |
|||
|
|||
AdrenoMemInfo* AdrenoMemInfo::s_instance = nullptr; |
|||
|
|||
AdrenoMemInfo* AdrenoMemInfo::GetInstance() { |
|||
static mutex s_lock; |
|||
lock_guard<mutex> obj(s_lock); |
|||
if (!s_instance) { |
|||
s_instance = new AdrenoMemInfo(); |
|||
} |
|||
|
|||
return s_instance; |
|||
} |
|||
|
|||
AdrenoMemInfo::AdrenoMemInfo() { |
|||
libadreno_utils_ = ::dlopen("libadreno_utils.so", RTLD_NOW); |
|||
if (libadreno_utils_) { |
|||
*reinterpret_cast<void**>(&LINK_adreno_compute_aligned_width_and_height) = |
|||
::dlsym(libadreno_utils_, "compute_aligned_width_and_height"); |
|||
*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_compute_compressedfmt_aligned_width_and_height) = |
|||
::dlsym(libadreno_utils_, "compute_compressedfmt_aligned_width_and_height"); |
|||
*reinterpret_cast<void**>(&LINK_adreno_isUBWCSupportedByGpu) = |
|||
::dlsym(libadreno_utils_, "isUBWCSupportedByGpu"); |
|||
*reinterpret_cast<void**>(&LINK_adreno_get_gpu_pixel_alignment) = |
|||
::dlsym(libadreno_utils_, "get_gpu_pixel_alignment"); |
|||
*reinterpret_cast<void**>(&LINK_adreno_get_metadata_blob_size) = |
|||
::dlsym(libadreno_utils_, "adreno_get_metadata_blob_size"); |
|||
*reinterpret_cast<void**>(&LINK_adreno_init_memory_layout) = |
|||
::dlsym(libadreno_utils_, "adreno_init_memory_layout"); |
|||
*reinterpret_cast<void**>(&LINK_adreno_get_aligned_gpu_buffer_size) = |
|||
::dlsym(libadreno_utils_, "adreno_get_aligned_gpu_buffer_size"); |
|||
} else { |
|||
ALOGE(" Failed to load libadreno_utils.so"); |
|||
} |
|||
|
|||
// Check if the overriding property debug.gralloc.gfx_ubwc_disable
|
|||
// that disables UBWC allocations for the graphics stack is set
|
|||
char property[PROPERTY_VALUE_MAX]; |
|||
property_get(DISABLE_UBWC_PROP, property, "0"); |
|||
if (!(strncmp(property, "1", PROPERTY_VALUE_MAX)) || |
|||
!(strncmp(property, "true", PROPERTY_VALUE_MAX))) { |
|||
gfx_ubwc_disable_ = true; |
|||
} |
|||
|
|||
property_get(DISABLE_AHARDWAREBUFFER_PROP, property, "0"); |
|||
if (!(strncmp(property, "1", PROPERTY_VALUE_MAX)) || |
|||
!(strncmp(property, "true", PROPERTY_VALUE_MAX))) { |
|||
gfx_ahardware_buffer_disable_ = true; |
|||
} |
|||
} |
|||
|
|||
AdrenoMemInfo::~AdrenoMemInfo() { |
|||
if (libadreno_utils_) { |
|||
::dlclose(libadreno_utils_); |
|||
} |
|||
} |
|||
|
|||
void AdrenoMemInfo::AlignUnCompressedRGB(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); |
|||
|
|||
int bpp = 4; |
|||
switch (format) { |
|||
case HAL_PIXEL_FORMAT_RGB_888: |
|||
case HAL_PIXEL_FORMAT_BGR_888: |
|||
bpp = 3; |
|||
break; |
|||
case HAL_PIXEL_FORMAT_RGB_565: |
|||
case HAL_PIXEL_FORMAT_BGR_565: |
|||
case HAL_PIXEL_FORMAT_RGBA_5551: |
|||
case HAL_PIXEL_FORMAT_RGBA_4444: |
|||
bpp = 2; |
|||
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) { |
|||
// We call into adreno_utils only for RGB formats. So plane_id is 0 and
|
|||
// num_samples is 1 always. We may have to add uitility function to
|
|||
// find out these if there is a need to call this API for YUV formats.
|
|||
LINK_adreno_compute_fmt_aligned_width_and_height( |
|||
width, height, 0 /*plane_id*/, GetGpuPixelFormat(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_aligned_width_and_height) { |
|||
LINK_adreno_compute_aligned_width_and_height( |
|||
width, height, bpp, 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
|
|||
*aligned_w = UINT(LINK_adreno_compute_padding(width, bpp, surface_tile_height, raster_mode, |
|||
padding_threshold)); |
|||
ALOGW("%s: Warning!! Old GFX API is used to calculate stride", __FUNCTION__); |
|||
} else { |
|||
ALOGW( |
|||
"%s: Warning!! Symbols compute_surface_padding and " |
|||
"compute_fmt_aligned_width_and_height and " |
|||
"compute_aligned_width_and_height not found", |
|||
__FUNCTION__); |
|||
} |
|||
} |
|||
|
|||
void AdrenoMemInfo::AlignCompressedRGB(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 { |
|||
*aligned_w = (unsigned int)ALIGN(width, 32); |
|||
*aligned_h = (unsigned int)ALIGN(height, 32); |
|||
ALOGW("%s: Warning!! compute_compressedfmt_aligned_width_and_height not found", __FUNCTION__); |
|||
} |
|||
} |
|||
|
|||
bool AdrenoMemInfo::IsUBWCSupportedByGPU(int format) { |
|||
if (!gfx_ubwc_disable_ && LINK_adreno_isUBWCSupportedByGpu) { |
|||
ADRENOPIXELFORMAT gpu_format = GetGpuPixelFormat(format); |
|||
return LINK_adreno_isUBWCSupportedByGpu(gpu_format); |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
uint32_t AdrenoMemInfo::GetGpuPixelAlignment() { |
|||
if (LINK_adreno_get_gpu_pixel_alignment) { |
|||
return LINK_adreno_get_gpu_pixel_alignment(); |
|||
} |
|||
|
|||
return 1; |
|||
} |
|||
|
|||
ADRENOPIXELFORMAT AdrenoMemInfo::GetGpuPixelFormat(int hal_format) { |
|||
switch (hal_format) { |
|||
case HAL_PIXEL_FORMAT_RGBA_8888: |
|||
return ADRENO_PIXELFORMAT_R8G8B8A8; |
|||
case HAL_PIXEL_FORMAT_RGBX_8888: |
|||
return ADRENO_PIXELFORMAT_R8G8B8X8; |
|||
case HAL_PIXEL_FORMAT_BGRA_8888: |
|||
return ADRENO_PIXELFORMAT_B8G8R8A8_UNORM; |
|||
case HAL_PIXEL_FORMAT_RGB_888: |
|||
return ADRENO_PIXELFORMAT_R8G8B8; |
|||
case HAL_PIXEL_FORMAT_RGB_565: |
|||
return ADRENO_PIXELFORMAT_B5G6R5; |
|||
case HAL_PIXEL_FORMAT_BGR_565: |
|||
return ADRENO_PIXELFORMAT_R5G6B5; |
|||
case HAL_PIXEL_FORMAT_RGBA_5551: |
|||
return ADRENO_PIXELFORMAT_R5G5B5A1; |
|||
case HAL_PIXEL_FORMAT_RGBA_4444: |
|||
return ADRENO_PIXELFORMAT_R4G4B4A4; |
|||
case HAL_PIXEL_FORMAT_RGBA_1010102: |
|||
return ADRENO_PIXELFORMAT_R10G10B10A2_UNORM; |
|||
case HAL_PIXEL_FORMAT_RGBX_1010102: |
|||
return ADRENO_PIXELFORMAT_R10G10B10X2_UNORM; |
|||
case HAL_PIXEL_FORMAT_ABGR_2101010: |
|||
return ADRENO_PIXELFORMAT_A2B10G10R10_UNORM; |
|||
case HAL_PIXEL_FORMAT_RGBA_FP16: |
|||
return ADRENO_PIXELFORMAT_R16G16B16A16_FLOAT; |
|||
case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: |
|||
return ADRENO_PIXELFORMAT_NV12; |
|||
case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: |
|||
case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: |
|||
return ADRENO_PIXELFORMAT_NV12_EXT; |
|||
case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: |
|||
return ADRENO_PIXELFORMAT_TP10; |
|||
case HAL_PIXEL_FORMAT_YCbCr_420_P010: |
|||
case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC: |
|||
case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS: |
|||
return ADRENO_PIXELFORMAT_P010; |
|||
case HAL_PIXEL_FORMAT_DEPTH_16: |
|||
return ADRENO_PIXELFORMAT_D16_UNORM; |
|||
case HAL_PIXEL_FORMAT_DEPTH_24: |
|||
return ADRENO_PIXELFORMAT_D24_UNORM_X8_UINT; |
|||
case HAL_PIXEL_FORMAT_DEPTH_24_STENCIL_8: |
|||
return ADRENO_PIXELFORMAT_D24_UNORM_S8_UINT; |
|||
case HAL_PIXEL_FORMAT_DEPTH_32F: |
|||
return ADRENO_PIXELFORMAT_D32_FLOAT; |
|||
case HAL_PIXEL_FORMAT_STENCIL_8: |
|||
return ADRENO_PIXELFORMAT_S8_UINT; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_4X4; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_4X4_SRGB; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x4_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_5X4; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_5X4_SRGB; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x5_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_5X5; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_5X5_SRGB; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x5_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_6X5; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_6X5_SRGB; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x6_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_6X6; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_6X6_SRGB; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x5_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_8X5; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_8X5_SRGB; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x6_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_8X6; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_8X6_SRGB; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_8X8; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_8X8_SRGB; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x5_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_10X5; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_10X5_SRGB; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x6_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_10X6; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_10X6_SRGB; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x8_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_10X8; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_10X8_SRGB; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x10_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_10X10; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_10X10_SRGB; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x10_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_12X10; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_12X10_SRGB; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x12_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_12X12; |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: |
|||
return ADRENO_PIXELFORMAT_ASTC_12X12_SRGB; |
|||
default: |
|||
ALOGE("%s: No map for format: 0x%x", __FUNCTION__, hal_format); |
|||
break; |
|||
} |
|||
|
|||
return ADRENO_PIXELFORMAT_UNKNOWN; |
|||
} |
|||
|
|||
uint32_t AdrenoMemInfo::AdrenoGetMetadataBlobSize() { |
|||
if (LINK_adreno_get_metadata_blob_size) { |
|||
return LINK_adreno_get_metadata_blob_size(); |
|||
} |
|||
return 0; |
|||
} |
|||
|
|||
int AdrenoMemInfo::AdrenoInitMemoryLayout(void* metadata_blob, int width, int height, int depth, |
|||
int format, int num_samples, int isUBWC, uint64_t usage, |
|||
uint32_t num_planes) { |
|||
if (LINK_adreno_init_memory_layout) { |
|||
surface_tile_mode_t tile_mode = static_cast<surface_tile_mode_t>(isUBWC); |
|||
return LINK_adreno_init_memory_layout(metadata_blob, width, height, depth, |
|||
GetGpuPixelFormat(format), num_samples, tile_mode, usage, |
|||
num_planes); |
|||
} |
|||
return -1; |
|||
} |
|||
|
|||
uint32_t AdrenoMemInfo::AdrenoGetAlignedGpuBufferSize(void* metadata_blob) { |
|||
if (LINK_adreno_get_aligned_gpu_buffer_size) { |
|||
return LINK_adreno_get_aligned_gpu_buffer_size(metadata_blob); |
|||
} |
|||
return -1; |
|||
} |
|||
|
|||
bool AdrenoMemInfo::AdrenoSizeAPIAvaliable() { |
|||
if (gfx_ahardware_buffer_disable_) { |
|||
return false; |
|||
} |
|||
|
|||
return (LINK_adreno_get_metadata_blob_size && LINK_adreno_init_memory_layout && |
|||
LINK_adreno_get_aligned_gpu_buffer_size); |
|||
} |
|||
|
|||
bool AdrenoMemInfo::IsPISupportedByGPU(int format, uint64_t usage) { |
|||
if (LINK_adreno_isPISupportedByGpu) { |
|||
return LINK_adreno_isPISupportedByGpu(format, usage); |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
} // namespace gralloc
|
|||
@ -1,234 +0,0 @@ |
|||
/* |
|||
* Copyright (c) 2011-2018, 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 __GR_ADRENO_INFO_H__ |
|||
#define __GR_ADRENO_INFO_H__ |
|||
|
|||
#include <stddef.h> |
|||
#include <stdint.h> |
|||
|
|||
namespace gralloc { |
|||
|
|||
// Adreno Pixel Formats |
|||
typedef enum { |
|||
ADRENO_PIXELFORMAT_UNKNOWN = 0, |
|||
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_D32_FLOAT = 40, |
|||
ADRENO_PIXELFORMAT_D24_UNORM_S8_UINT = 45, |
|||
ADRENO_PIXELFORMAT_D16_UNORM = 55, |
|||
ADRENO_PIXELFORMAT_B5G6R5 = 85, |
|||
ADRENO_PIXELFORMAT_B5G5R5A1 = 86, |
|||
ADRENO_PIXELFORMAT_B8G8R8A8_UNORM = 87, |
|||
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_A2B10G10R10_UNORM = 532, |
|||
// Vertex, Normalized GL_UNSIGNED_INT_10_10_10_2_OES |
|||
ADRENO_PIXELFORMAT_R10G10B10X2_UNORM = 537, |
|||
ADRENO_PIXELFORMAT_D24_UNORM_X8_UINT = 548, |
|||
ADRENO_PIXELFORMAT_D24_UNORM = 549, |
|||
ADRENO_PIXELFORMAT_D32_FLOAT_X24S8_UINT = 551, |
|||
ADRENO_PIXELFORMAT_S8_UINT = 552, |
|||
ADRENO_PIXELFORMAT_ASTC_4X4 = 568, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_5X4 = 569, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_5X5 = 570, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_6X5 = 571, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_6X6 = 572, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_8X5 = 573, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_8X6 = 574, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_8X8 = 575, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_10X5 = 576, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_10X6 = 577, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_10X8 = 578, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_10X10 = 579, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_12X10 = 580, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_12X12 = 581, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_4X4_SRGB = 582, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_5X4_SRGB = 583, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_5X5_SRGB = 584, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_6X5_SRGB = 585, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_6X6_SRGB = 586, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_8X5_SRGB = 587, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_8X6_SRGB = 588, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_8X8_SRGB = 589, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_10X5_SRGB = 590, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_10X6_SRGB = 591, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_10X8_SRGB = 592, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_10X10_SRGB = 593, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_12X10_SRGB = 594, // ASTC Compressed |
|||
ADRENO_PIXELFORMAT_ASTC_12X12_SRGB = 595, // ASTC Compressed |
|||
// Vertex, Normalized GL_UNSIGNED_INT_10_10_10_2_OES |
|||
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; |
|||
|
|||
typedef enum { |
|||
SURFACE_TILE_MODE_DISABLE = 0x0, // used for linear surface |
|||
SURFACE_TILE_MODE_ENABLE = 0x1 // used for tiled surface |
|||
} surface_tile_mode_t; |
|||
|
|||
class AdrenoMemInfo { |
|||
public: |
|||
/* |
|||
* Function to compute aligned width and aligned height based on |
|||
* width, height, format and usage flags. |
|||
* |
|||
* @return aligned width, aligned height |
|||
*/ |
|||
void GetAlignedWidthAndHeight(int width, int height, int format, int usage, |
|||
unsigned int* aligned_w, unsigned int* aligned_h, bool ubwc_enabled, |
|||
bool tile_enabled); |
|||
|
|||
/* |
|||
* Function to compute the adreno aligned width and aligned height |
|||
* based on the width and format. |
|||
* |
|||
* @return aligned width, aligned height |
|||
*/ |
|||
void AlignUnCompressedRGB(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 AlignCompressedRGB(int width, int height, int format, unsigned int* aligned_w, |
|||
unsigned int* aligned_h); |
|||
|
|||
/* |
|||
* Function to compute the pixel alignment requirement. |
|||
* |
|||
* @return alignment |
|||
*/ |
|||
uint32_t GetGpuPixelAlignment(); |
|||
|
|||
/* |
|||
* Function to query whether GPU supports UBWC for given HAL format |
|||
* @return > 0 : supported |
|||
* 0 : not supported |
|||
*/ |
|||
bool IsUBWCSupportedByGPU(int format); |
|||
|
|||
/* |
|||
* Function to check if GPU supports PI or not |
|||
*/ |
|||
bool IsPISupportedByGPU(int format, uint64_t usage); |
|||
/* |
|||
* Function to get the corresponding Adreno format for given HAL format |
|||
*/ |
|||
ADRENOPIXELFORMAT GetGpuPixelFormat(int hal_format); |
|||
|
|||
/* |
|||
* Function to get graphics metadata blob size |
|||
* @return graphics metadata size |
|||
*/ |
|||
uint32_t AdrenoGetMetadataBlobSize(); |
|||
|
|||
/* |
|||
* Function to populate the graphics metadata blob |
|||
* @return 1 : Successful |
|||
* 2 : Unsuccessful |
|||
*/ |
|||
int AdrenoInitMemoryLayout(void* metadata_blob, int width, int height, int depth, int format, |
|||
int num_samples, int isUBWC, uint64_t usage, uint32_t num_planes); |
|||
/* |
|||
* Function to get buffer size for based on graphcis metadata |
|||
* @return buffer size |
|||
*/ |
|||
uint32_t AdrenoGetAlignedGpuBufferSize(void* metadata_blob); |
|||
|
|||
/* |
|||
* Function to check if adreno size calculation APIs are avaliable |
|||
* @return true : Avaliable |
|||
* false : Unavaliable |
|||
*/ |
|||
bool AdrenoSizeAPIAvaliable(); |
|||
|
|||
static AdrenoMemInfo* GetInstance(); |
|||
|
|||
private: |
|||
AdrenoMemInfo(); |
|||
~AdrenoMemInfo(); |
|||
// 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_aligned_width_and_height)(int width, int height, int bpp, |
|||
int tile_mode, int raster_mode, |
|||
int padding_threshold, int* aligned_w, |
|||
int* aligned_h) = NULL; |
|||
void (*LINK_adreno_compute_fmt_aligned_width_and_height)(int width, int height, int plane_id, |
|||
int format, int num_samples, |
|||
int tile_mode, int raster_mode, |
|||
int padding_threshold, int* aligned_w, |
|||
int* aligned_h) = 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_isUBWCSupportedByGpu)(ADRENOPIXELFORMAT format) = NULL; |
|||
unsigned int (*LINK_adreno_get_gpu_pixel_alignment)() = NULL; |
|||
|
|||
uint32_t (*LINK_adreno_get_metadata_blob_size)() = NULL; |
|||
int (*LINK_adreno_init_memory_layout)(void* metadata_blob, int width, int height, int depth, |
|||
ADRENOPIXELFORMAT format, int num_samples, |
|||
surface_tile_mode_t tile_mode, uint64_t usage, |
|||
uint32_t num_planes) = NULL; |
|||
uint32_t (*LINK_adreno_get_aligned_gpu_buffer_size)(void* metadata_blob) = NULL; |
|||
int (*LINK_adreno_isPISupportedByGpu)(int format, uint64_t usage) = NULL; |
|||
|
|||
bool gfx_ubwc_disable_ = false; |
|||
bool gfx_ahardware_buffer_disable_ = false; |
|||
void* libadreno_utils_ = NULL; |
|||
|
|||
static AdrenoMemInfo* s_instance; |
|||
}; |
|||
|
|||
} // namespace gralloc |
|||
|
|||
#endif // __GR_ADRENO_INFO_H__ |
|||
@ -1,190 +0,0 @@ |
|||
/* |
|||
* Copyright (c) 2011-2019, The Linux Foundation. All rights reserved. |
|||
* Not a Contribution |
|||
* |
|||
* Copyright (C) 2008 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. |
|||
*/ |
|||
|
|||
#ifndef __GR_PRIV_HANDLE_H__ |
|||
#define __GR_PRIV_HANDLE_H__ |
|||
|
|||
#include <hardware/gralloc.h> |
|||
#include <hardware/gralloc1.h> |
|||
#include <log/log.h> |
|||
#ifdef __cplusplus |
|||
#include <cinttypes> |
|||
#endif |
|||
|
|||
#define GRALLOC1_FUNCTION_PERFORM 0x00001000 |
|||
|
|||
#define DBG_HANDLE false |
|||
|
|||
typedef gralloc1_error_t (*GRALLOC1_PFN_PERFORM)(gralloc1_device_t* device, int operation, ...); |
|||
|
|||
#define PRIV_HANDLE_CONST(exp) static_cast<const private_handle_t*>(exp) |
|||
|
|||
#pragma pack(push, 4) |
|||
#ifdef __cplusplus |
|||
struct private_handle_t : public native_handle_t { |
|||
#else |
|||
struct private_handle_t { |
|||
native_handle_t nativeHandle; |
|||
#endif |
|||
enum { |
|||
PRIV_FLAGS_FRAMEBUFFER = 0x00000001, |
|||
PRIV_FLAGS_USES_ION = 0x00000008, |
|||
PRIV_FLAGS_NEEDS_FLUSH = 0x00000020, |
|||
PRIV_FLAGS_INTERNAL_ONLY = 0x00000040, |
|||
PRIV_FLAGS_NON_CPU_WRITER = 0x00000080, |
|||
PRIV_FLAGS_CACHED = 0x00000200, |
|||
PRIV_FLAGS_SECURE_BUFFER = 0x00000400, |
|||
PRIV_FLAGS_EXTERNAL_ONLY = 0x00002000, |
|||
PRIV_FLAGS_PROTECTED_BUFFER = 0x00004000, |
|||
PRIV_FLAGS_VIDEO_ENCODER = 0x00010000, |
|||
PRIV_FLAGS_CAMERA_WRITE = 0x00020000, |
|||
PRIV_FLAGS_CAMERA_READ = 0x00040000, |
|||
PRIV_FLAGS_HW_COMPOSER = 0x00080000, |
|||
PRIV_FLAGS_HW_TEXTURE = 0x00100000, |
|||
PRIV_FLAGS_ITU_R_601 = 0x00200000, // Unused from display |
|||
PRIV_FLAGS_ITU_R_601_FR = 0x00400000, // Unused from display |
|||
PRIV_FLAGS_ITU_R_709 = 0x00800000, // Unused from display |
|||
PRIV_FLAGS_SECURE_DISPLAY = 0x01000000, |
|||
PRIV_FLAGS_TILE_RENDERED = 0x02000000, |
|||
PRIV_FLAGS_CPU_RENDERED = 0x04000000, |
|||
PRIV_FLAGS_UBWC_ALIGNED = 0x08000000, |
|||
PRIV_FLAGS_DISP_CONSUMER = 0x10000000, |
|||
PRIV_FLAGS_CLIENT_ALLOCATED = 0x20000000, // Ion buffer allocated outside of gralloc |
|||
PRIV_FLAGS_UBWC_ALIGNED_PI = 0x40000000, // PI format |
|||
}; |
|||
|
|||
// file-descriptors dup'd over IPC |
|||
int fd; |
|||
int fd_metadata; |
|||
|
|||
// values sent over IPC |
|||
int magic; |
|||
int flags; |
|||
int width; // holds width of the actual buffer allocated |
|||
int height; // holds height of the actual buffer allocated |
|||
int unaligned_width; // holds width client asked to allocate |
|||
int unaligned_height; // holds height client asked to allocate |
|||
int format; |
|||
int buffer_type; |
|||
unsigned int layer_count; |
|||
uint64_t id; |
|||
uint64_t usage; |
|||
|
|||
unsigned int size; |
|||
unsigned int offset; |
|||
unsigned int offset_metadata; |
|||
uint64_t base; |
|||
uint64_t base_metadata; |
|||
uint64_t gpuaddr; |
|||
#ifdef __cplusplus |
|||
static const int kNumFds = 2; |
|||
static const int kMagic = 'gmsm'; |
|||
|
|||
static inline int NumInts() { |
|||
return ((sizeof(private_handle_t) - sizeof(native_handle_t)) / sizeof(int)) - kNumFds; |
|||
} |
|||
|
|||
private_handle_t(int fd, int meta_fd, int flags, int width, int height, int uw, int uh, |
|||
int format, int buf_type, unsigned int size, uint64_t usage = 0) |
|||
: fd(fd), |
|||
fd_metadata(meta_fd), |
|||
magic(kMagic), |
|||
flags(flags), |
|||
width(width), |
|||
height(height), |
|||
unaligned_width(uw), |
|||
unaligned_height(uh), |
|||
format(format), |
|||
buffer_type(buf_type), |
|||
layer_count(1), |
|||
id(0), |
|||
usage(usage), |
|||
size(size), |
|||
offset(0), |
|||
offset_metadata(0), |
|||
base(0), |
|||
base_metadata(0), |
|||
gpuaddr(0) { |
|||
version = static_cast<int>(sizeof(native_handle)); |
|||
numInts = NumInts(); |
|||
numFds = kNumFds; |
|||
} |
|||
|
|||
// Legacy constructor used by some clients |
|||
private_handle_t(int fd, unsigned int size, int usage, int buf_type, int format, int w, int h) |
|||
: private_handle_t(fd, -1, PRIV_FLAGS_CLIENT_ALLOCATED, w, h, 0, 0, format, buf_type, size, |
|||
static_cast<uint64_t>(usage)) {} |
|||
|
|||
~private_handle_t() { |
|||
magic = 0; |
|||
ALOGE_IF(DBG_HANDLE, "Deleting buffer handle %p", this); |
|||
} |
|||
|
|||
static int validate(const native_handle* h) { |
|||
auto* hnd = static_cast<const private_handle_t*>(h); |
|||
if (!h || h->version != sizeof(native_handle) || h->numInts != NumInts() || |
|||
h->numFds != kNumFds) { |
|||
ALOGE("Invalid gralloc handle (at %p): ver(%d/%zu) ints(%d/%d) fds(%d/%d)", h, |
|||
h ? h->version : -1, sizeof(native_handle), h ? h->numInts : -1, NumInts(), |
|||
h ? h->numFds : -1, kNumFds); |
|||
return -EINVAL; |
|||
} |
|||
if (hnd->magic != kMagic) { |
|||
ALOGE("handle = %p invalid magic(%c%c%c%c/%c%c%c%c)", hnd, |
|||
hnd ? (((hnd->magic >> 24) & 0xFF) ? ((hnd->magic >> 24) & 0xFF) : '-') : '?', |
|||
hnd ? (((hnd->magic >> 16) & 0xFF) ? ((hnd->magic >> 16) & 0xFF) : '-') : '?', |
|||
hnd ? (((hnd->magic >> 8) & 0xFF) ? ((hnd->magic >> 8) & 0xFF) : '-') : '?', |
|||
hnd ? (((hnd->magic >> 0) & 0xFF) ? ((hnd->magic >> 0) & 0xFF) : '-') : '?', |
|||
(kMagic >> 24) & 0xFF, (kMagic >> 16) & 0xFF, (kMagic >> 8) & 0xFF, |
|||
(kMagic >> 0) & 0xFF); |
|||
return -EINVAL; |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
static void Dump(const private_handle_t* hnd) { |
|||
ALOGD("handle id:%" PRIu64 |
|||
" wxh:%dx%d uwxuh:%dx%d size: %d fd:%d fd_meta:%d flags:0x%x " |
|||
"usage:0x%" PRIx64 " format:0x%x layer_count: %d", |
|||
hnd->id, hnd->width, hnd->height, hnd->unaligned_width, hnd->unaligned_height, hnd->size, |
|||
hnd->fd, hnd->fd_metadata, hnd->flags, hnd->usage, hnd->format, hnd->layer_count); |
|||
} |
|||
|
|||
int GetUnalignedWidth() const { return unaligned_width; } |
|||
|
|||
int GetUnalignedHeight() const { return unaligned_height; } |
|||
|
|||
int GetColorFormat() const { return format; } |
|||
|
|||
unsigned int GetLayerCount() const { return layer_count; } |
|||
|
|||
int GetStride() const { |
|||
// In handle we currently store aligned width after allocation. |
|||
return width; |
|||
} |
|||
|
|||
uint64_t GetUsage() const { return usage; } |
|||
|
|||
uint64_t GetBackingstore() const { return id; } |
|||
#endif |
|||
}; |
|||
#pragma pack(pop) |
|||
|
|||
#endif // __GR_PRIV_HANDLE_H__ |
|||
@ -1,662 +0,0 @@ |
|||
/*
|
|||
* Copyright (c) 2011-2019, 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 "gr_utils.h"
|
|||
|
|||
#include <algorithm>
|
|||
|
|||
#include "gr_adreno_info.h"
|
|||
|
|||
#define ASTC_BLOCK_SIZE 16
|
|||
|
|||
#ifndef COLOR_FMT_P010_UBWC
|
|||
#define COLOR_FMT_P010_UBWC 9
|
|||
#endif
|
|||
|
|||
namespace gralloc { |
|||
|
|||
bool IsUncompressedRGBFormat(int format) { |
|||
switch (format) { |
|||
case HAL_PIXEL_FORMAT_RGBA_8888: |
|||
case HAL_PIXEL_FORMAT_RGBX_8888: |
|||
case HAL_PIXEL_FORMAT_RGB_888: |
|||
case HAL_PIXEL_FORMAT_RGB_565: |
|||
case HAL_PIXEL_FORMAT_BGR_565: |
|||
case HAL_PIXEL_FORMAT_BGRA_8888: |
|||
case HAL_PIXEL_FORMAT_RGBA_5551: |
|||
case HAL_PIXEL_FORMAT_RGBA_4444: |
|||
case HAL_PIXEL_FORMAT_R_8: |
|||
case HAL_PIXEL_FORMAT_RG_88: |
|||
case HAL_PIXEL_FORMAT_BGRX_8888: |
|||
case HAL_PIXEL_FORMAT_RGBA_1010102: |
|||
case HAL_PIXEL_FORMAT_ARGB_2101010: |
|||
case HAL_PIXEL_FORMAT_RGBX_1010102: |
|||
case HAL_PIXEL_FORMAT_XRGB_2101010: |
|||
case HAL_PIXEL_FORMAT_BGRA_1010102: |
|||
case HAL_PIXEL_FORMAT_ABGR_2101010: |
|||
case HAL_PIXEL_FORMAT_BGRX_1010102: |
|||
case HAL_PIXEL_FORMAT_XBGR_2101010: |
|||
case HAL_PIXEL_FORMAT_RGBA_FP16: |
|||
case HAL_PIXEL_FORMAT_BGR_888: |
|||
return true; |
|||
default: |
|||
break; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool IsCompressedRGBFormat(int format) { |
|||
switch (format) { |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x4_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x5_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x5_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x6_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x5_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x6_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x5_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x6_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x8_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x10_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x10_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x12_KHR: |
|||
case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: |
|||
return true; |
|||
default: |
|||
break; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
uint32_t GetBppForUncompressedRGB(int format) { |
|||
uint32_t bpp = 0; |
|||
switch (format) { |
|||
case HAL_PIXEL_FORMAT_RGBA_FP16: |
|||
bpp = 8; |
|||
break; |
|||
case HAL_PIXEL_FORMAT_RGBA_8888: |
|||
case HAL_PIXEL_FORMAT_RGBX_8888: |
|||
case HAL_PIXEL_FORMAT_BGRA_8888: |
|||
case HAL_PIXEL_FORMAT_BGRX_8888: |
|||
case HAL_PIXEL_FORMAT_RGBA_1010102: |
|||
case HAL_PIXEL_FORMAT_ARGB_2101010: |
|||
case HAL_PIXEL_FORMAT_RGBX_1010102: |
|||
case HAL_PIXEL_FORMAT_XRGB_2101010: |
|||
case HAL_PIXEL_FORMAT_BGRA_1010102: |
|||
case HAL_PIXEL_FORMAT_ABGR_2101010: |
|||
case HAL_PIXEL_FORMAT_BGRX_1010102: |
|||
case HAL_PIXEL_FORMAT_XBGR_2101010: |
|||
bpp = 4; |
|||
break; |
|||
case HAL_PIXEL_FORMAT_RGB_888: |
|||
case HAL_PIXEL_FORMAT_BGR_888: |
|||
bpp = 3; |
|||
break; |
|||
case HAL_PIXEL_FORMAT_RGB_565: |
|||
case HAL_PIXEL_FORMAT_BGR_565: |
|||
case HAL_PIXEL_FORMAT_RGBA_5551: |
|||
case HAL_PIXEL_FORMAT_RGBA_4444: |
|||
bpp = 2; |
|||
break; |
|||
default: |
|||
ALOGE("Error : %s New format request = 0x%x", __FUNCTION__, format); |
|||
break; |
|||
} |
|||
|
|||
return bpp; |
|||
} |
|||
|
|||
bool CpuCanAccess(uint64_t usage) { |
|||
return CpuCanRead(usage) || CpuCanWrite(usage); |
|||
} |
|||
|
|||
bool CpuCanRead(uint64_t usage) { |
|||
if (usage & BufferUsage::CPU_READ_MASK) { |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool CpuCanWrite(uint64_t usage) { |
|||
if (usage & BufferUsage::CPU_WRITE_MASK) { |
|||
// Application intends to use CPU for rendering
|
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
uint32_t GetDataAlignment(int format, uint64_t usage) { |
|||
uint32_t align = UINT(getpagesize()); |
|||
if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED) { |
|||
align = SIZE_8K; |
|||
} |
|||
|
|||
if (usage & BufferUsage::PROTECTED) { |
|||
if ((usage & BufferUsage::CAMERA_OUTPUT) || (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY)) { |
|||
// The alignment here reflects qsee mmu V7L/V8L requirement
|
|||
align = SZ_2M; |
|||
} else { |
|||
align = SECURE_ALIGN; |
|||
} |
|||
} |
|||
|
|||
return align; |
|||
} |
|||
|
|||
bool IsGPUFlagSupported(uint64_t usage) { |
|||
bool ret = true; |
|||
if ((usage & BufferUsage::GPU_MIPMAP_COMPLETE)) { |
|||
ALOGE("GPU_MIPMAP_COMPLETE not supported"); |
|||
ret = false; |
|||
} |
|||
|
|||
if ((usage & BufferUsage::GPU_CUBE_MAP)) { |
|||
ALOGE("GPU_CUBE_MAP not supported"); |
|||
ret = false; |
|||
} |
|||
|
|||
return ret; |
|||
} |
|||
|
|||
// Returns the final buffer size meant to be allocated with ion
|
|||
unsigned int GetSize(const BufferInfo& info, unsigned int alignedw, unsigned int alignedh) { |
|||
unsigned int size = 0; |
|||
int format = info.format; |
|||
int width = info.width; |
|||
int height = info.height; |
|||
uint64_t usage = info.usage; |
|||
|
|||
if (!IsGPUFlagSupported(usage)) { |
|||
ALOGE("Unsupported GPU usage flags present 0x%" PRIx64, usage); |
|||
return 0; |
|||
} |
|||
|
|||
if (IsUBwcEnabled(format, usage)) { |
|||
size = GetUBwcSize(width, height, format, alignedw, alignedh); |
|||
} else if (IsUncompressedRGBFormat(format)) { |
|||
uint32_t bpp = GetBppForUncompressedRGB(format); |
|||
size = alignedw * alignedh * bpp; |
|||
} else if (IsCompressedRGBFormat(format)) { |
|||
size = alignedw * alignedh * ASTC_BLOCK_SIZE; |
|||
} else { |
|||
// Below switch should be for only YUV/custom formats
|
|||
switch (format) { |
|||
case HAL_PIXEL_FORMAT_RAW16: |
|||
case HAL_PIXEL_FORMAT_Y16: |
|||
size = alignedw * alignedh * 2; |
|||
break; |
|||
case HAL_PIXEL_FORMAT_RAW10: |
|||
case HAL_PIXEL_FORMAT_RAW12: |
|||
size = ALIGN(alignedw * alignedh, SIZE_4K); |
|||
break; |
|||
case HAL_PIXEL_FORMAT_RAW8: |
|||
case HAL_PIXEL_FORMAT_Y8: |
|||
size = alignedw * alignedh * 1; |
|||
break; |
|||
// adreno formats
|
|||
case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: // NV21
|
|||
size = ALIGN(alignedw * alignedh, SIZE_4K); |
|||
size += (unsigned int)ALIGN(2 * ALIGN(width / 2, 32) * ALIGN(height / 2, 32), SIZE_4K); |
|||
break; |
|||
case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: // NV12
|
|||
// The chroma plane is subsampled,
|
|||
// but the pitch in bytes is unchanged
|
|||
// The GPU needs 4K alignment, but the video decoder needs 8K
|
|||
size = ALIGN(alignedw * alignedh, SIZE_8K); |
|||
size += ALIGN(alignedw * (unsigned int)ALIGN(height / 2, 32), SIZE_8K); |
|||
break; |
|||
case HAL_PIXEL_FORMAT_YV12: |
|||
if ((format == HAL_PIXEL_FORMAT_YV12) && ((width & 1) || (height & 1))) { |
|||
ALOGE("w or h is odd for the YV12 format"); |
|||
return 0; |
|||
} |
|||
size = alignedw * alignedh + (ALIGN(alignedw / 2, 16) * (alignedh / 2)) * 2; |
|||
size = ALIGN(size, (unsigned int)SIZE_4K); |
|||
break; |
|||
case HAL_PIXEL_FORMAT_YCbCr_420_SP: |
|||
case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
|||
size = ALIGN((alignedw * alignedh) + (alignedw * alignedh) / 2 + 1, SIZE_4K); |
|||
break; |
|||
case HAL_PIXEL_FORMAT_YCbCr_420_P010: |
|||
size = ALIGN((alignedw * alignedh * 2) + (alignedw * alignedh) + 1, SIZE_4K); |
|||
break; |
|||
case HAL_PIXEL_FORMAT_YCbCr_422_SP: |
|||
case HAL_PIXEL_FORMAT_YCrCb_422_SP: |
|||
case HAL_PIXEL_FORMAT_YCbCr_422_I: |
|||
case HAL_PIXEL_FORMAT_YCrCb_422_I: |
|||
case HAL_PIXEL_FORMAT_CbYCrY_422_I: |
|||
if (width & 1) { |
|||
ALOGE("width is odd for the YUV422_SP format"); |
|||
return 0; |
|||
} |
|||
size = ALIGN(alignedw * alignedh * 2, SIZE_4K); |
|||
break; |
|||
case HAL_PIXEL_FORMAT_BLOB: |
|||
case HAL_PIXEL_FORMAT_RAW_OPAQUE: |
|||
if (height != 1) { |
|||
ALOGE("%s: Buffers with HAL_PIXEL_FORMAT_BLOB must have height 1 ", __FUNCTION__); |
|||
return 0; |
|||
} |
|||
size = (unsigned int)width; |
|||
break; |
|||
case HAL_PIXEL_FORMAT_NV21_ZSL: |
|||
size = ALIGN((alignedw * alignedh) + (alignedw * alignedh) / 2, SIZE_4K); |
|||
break; |
|||
default: |
|||
ALOGE("%s: Unrecognized pixel format: 0x%x", __FUNCTION__, format); |
|||
return 0; |
|||
} |
|||
} |
|||
auto align = GetDataAlignment(format, usage); |
|||
size = ALIGN(size, align) * info.layer_count; |
|||
return size; |
|||
} |
|||
|
|||
// Explicitly defined UBWC formats
|
|||
bool IsUBwcFormat(int format) { |
|||
switch (format) { |
|||
case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: |
|||
case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: |
|||
case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC: |
|||
return true; |
|||
default: |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
bool IsUBwcSupported(int format) { |
|||
// Existing HAL formats with UBWC support
|
|||
switch (format) { |
|||
case HAL_PIXEL_FORMAT_BGR_565: |
|||
case HAL_PIXEL_FORMAT_RGBA_8888: |
|||
case HAL_PIXEL_FORMAT_RGBX_8888: |
|||
case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: |
|||
case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: |
|||
case HAL_PIXEL_FORMAT_RGBA_1010102: |
|||
case HAL_PIXEL_FORMAT_RGBX_1010102: |
|||
case HAL_PIXEL_FORMAT_DEPTH_16: |
|||
case HAL_PIXEL_FORMAT_DEPTH_24: |
|||
case HAL_PIXEL_FORMAT_DEPTH_24_STENCIL_8: |
|||
case HAL_PIXEL_FORMAT_DEPTH_32F: |
|||
case HAL_PIXEL_FORMAT_STENCIL_8: |
|||
return true; |
|||
default: |
|||
break; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool IsUBwcPISupported(int format, uint64_t usage) { |
|||
if (usage & BufferUsage::COMPOSER_OVERLAY || !(usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC_PI)) { |
|||
return false; |
|||
} |
|||
|
|||
// As of now only two formats
|
|||
switch (format) { |
|||
case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: |
|||
case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: { |
|||
if ((usage & BufferUsage::GPU_TEXTURE) || (usage & BufferUsage::GPU_RENDER_TARGET)) { |
|||
if (AdrenoMemInfo::GetInstance()) { |
|||
return AdrenoMemInfo::GetInstance()->IsPISupportedByGPU(format, usage); |
|||
} |
|||
} else { |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool IsUBwcEnabled(int format, uint64_t usage) { |
|||
// Allow UBWC, if client is using an explicitly defined UBWC pixel format.
|
|||
if (IsUBwcFormat(format)) { |
|||
return true; |
|||
} |
|||
|
|||
// Allow UBWC, if an OpenGL client sets UBWC usage flag and GPU plus MDP
|
|||
// support the format. OR if a non-OpenGL client like Rotator, sets UBWC
|
|||
// usage flag and MDP supports the format.
|
|||
if (((usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC) || |
|||
(usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC_PI) || |
|||
(usage & BufferUsage::COMPOSER_CLIENT_TARGET)) && |
|||
IsUBwcSupported(format)) { |
|||
bool enable = true; |
|||
// Query GPU for UBWC only if buffer is intended to be used by GPU.
|
|||
if ((usage & BufferUsage::GPU_TEXTURE) || (usage & BufferUsage::GPU_RENDER_TARGET)) { |
|||
if (AdrenoMemInfo::GetInstance()) { |
|||
enable = AdrenoMemInfo::GetInstance()->IsUBWCSupportedByGPU(format); |
|||
} |
|||
} |
|||
|
|||
// Allow UBWC, only if CPU usage flags are not set
|
|||
if (enable && !(CpuCanAccess(usage))) { |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
void GetRgbUBwcBlockSize(uint32_t bpp, int* block_width, int* block_height) { |
|||
*block_width = 0; |
|||
*block_height = 0; |
|||
|
|||
switch (bpp) { |
|||
case 2: |
|||
case 4: |
|||
*block_width = 16; |
|||
*block_height = 4; |
|||
break; |
|||
case 8: |
|||
*block_width = 8; |
|||
*block_height = 4; |
|||
break; |
|||
case 16: |
|||
*block_width = 4; |
|||
*block_height = 4; |
|||
break; |
|||
default: |
|||
ALOGE("%s: Unsupported bpp: %d", __FUNCTION__, bpp); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
unsigned int GetRgbUBwcMetaBufferSize(int width, int height, uint32_t bpp) { |
|||
unsigned int size = 0; |
|||
int meta_width, meta_height; |
|||
int block_width, block_height; |
|||
|
|||
GetRgbUBwcBlockSize(bpp, &block_width, &block_height); |
|||
if (!block_width || !block_height) { |
|||
ALOGE("%s: Unsupported bpp: %d", __FUNCTION__, bpp); |
|||
return size; |
|||
} |
|||
|
|||
// Align meta buffer height to 16 blocks
|
|||
meta_height = ALIGN(((height + block_height - 1) / block_height), 16); |
|||
|
|||
// Align meta buffer width to 64 blocks
|
|||
meta_width = ALIGN(((width + block_width - 1) / block_width), 64); |
|||
|
|||
// Align meta buffer size to 4K
|
|||
size = (unsigned int)ALIGN((meta_width * meta_height), 4096); |
|||
|
|||
return size; |
|||
} |
|||
|
|||
unsigned int GetUBwcSize(int width, int height, int format, unsigned int alignedw, |
|||
unsigned int alignedh) { |
|||
unsigned int size = 0; |
|||
uint32_t bpp = 0; |
|||
switch (format) { |
|||
case HAL_PIXEL_FORMAT_BGR_565: |
|||
case HAL_PIXEL_FORMAT_RGBA_8888: |
|||
case HAL_PIXEL_FORMAT_RGBX_8888: |
|||
case HAL_PIXEL_FORMAT_RGBA_1010102: |
|||
case HAL_PIXEL_FORMAT_RGBX_1010102: |
|||
bpp = GetBppForUncompressedRGB(format); |
|||
size = alignedw * alignedh * bpp; |
|||
size += GetRgbUBwcMetaBufferSize(width, height, bpp); |
|||
break; |
|||
default: |
|||
ALOGE("%s: Unsupported pixel format: 0x%x", __FUNCTION__, format); |
|||
break; |
|||
} |
|||
|
|||
return size; |
|||
} |
|||
|
|||
unsigned int GetRgbMetaSize(int format, uint32_t width, uint32_t height, uint64_t usage) { |
|||
unsigned int meta_size = 0; |
|||
if (!IsUBwcEnabled(format, usage)) { |
|||
return meta_size; |
|||
} |
|||
uint32_t bpp = GetBppForUncompressedRGB(format); |
|||
switch (format) { |
|||
case HAL_PIXEL_FORMAT_BGR_565: |
|||
case HAL_PIXEL_FORMAT_RGBA_8888: |
|||
case HAL_PIXEL_FORMAT_RGBX_8888: |
|||
case HAL_PIXEL_FORMAT_RGBA_1010102: |
|||
case HAL_PIXEL_FORMAT_RGBX_1010102: |
|||
case HAL_PIXEL_FORMAT_RGBA_FP16: |
|||
meta_size = GetRgbUBwcMetaBufferSize(width, height, bpp); |
|||
break; |
|||
default: |
|||
ALOGE("%s:Unsupported RGB format: 0x%x", __FUNCTION__, format); |
|||
break; |
|||
} |
|||
return meta_size; |
|||
} |
|||
|
|||
bool CanUseAdrenoForSize(int buffer_type, uint64_t usage) { |
|||
if (buffer_type == BUFFER_TYPE_VIDEO || !GetAdrenoSizeAPIStatus()) { |
|||
return false; |
|||
} |
|||
|
|||
if ((usage & BufferUsage::PROTECTED) && |
|||
((usage & BufferUsage::CAMERA_OUTPUT) || (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY))) { |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
bool GetAdrenoSizeAPIStatus() { |
|||
AdrenoMemInfo* adreno_mem_info = AdrenoMemInfo::GetInstance(); |
|||
if (adreno_mem_info) { |
|||
return adreno_mem_info->AdrenoSizeAPIAvaliable(); |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
bool UseUncached(int format, uint64_t usage) { |
|||
if ((usage & GRALLOC_USAGE_PRIVATE_UNCACHED) || (usage & BufferUsage::PROTECTED)) { |
|||
return true; |
|||
} |
|||
|
|||
// CPU read rarely
|
|||
if ((usage & BufferUsage::CPU_READ_MASK) == static_cast<uint64_t>(BufferUsage::CPU_READ_RARELY)) { |
|||
return true; |
|||
} |
|||
|
|||
// CPU write rarely
|
|||
if ((usage & BufferUsage::CPU_WRITE_MASK) == |
|||
static_cast<uint64_t>(BufferUsage::CPU_WRITE_RARELY)) { |
|||
return true; |
|||
} |
|||
|
|||
if ((usage & BufferUsage::SENSOR_DIRECT_DATA) || (usage & BufferUsage::GPU_DATA_BUFFER)) { |
|||
return true; |
|||
} |
|||
|
|||
if (format && IsUBwcEnabled(format, usage)) { |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
uint64_t GetHandleFlags(int format, uint64_t usage) { |
|||
uint64_t priv_flags = 0; |
|||
|
|||
if (usage & BufferUsage::VIDEO_ENCODER) { |
|||
priv_flags |= private_handle_t::PRIV_FLAGS_VIDEO_ENCODER; |
|||
} |
|||
|
|||
if (usage & BufferUsage::CAMERA_OUTPUT) { |
|||
priv_flags |= private_handle_t::PRIV_FLAGS_CAMERA_WRITE; |
|||
} |
|||
|
|||
if (usage & BufferUsage::CAMERA_INPUT) { |
|||
priv_flags |= private_handle_t::PRIV_FLAGS_CAMERA_READ; |
|||
} |
|||
|
|||
if (usage & BufferUsage::COMPOSER_OVERLAY) { |
|||
priv_flags |= private_handle_t::PRIV_FLAGS_DISP_CONSUMER; |
|||
} |
|||
|
|||
if (usage & BufferUsage::GPU_TEXTURE) { |
|||
priv_flags |= private_handle_t::PRIV_FLAGS_HW_TEXTURE; |
|||
} |
|||
|
|||
if (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY) { |
|||
priv_flags |= private_handle_t::PRIV_FLAGS_SECURE_DISPLAY; |
|||
} |
|||
|
|||
if (IsUBwcEnabled(format, usage)) { |
|||
if (IsUBwcPISupported(format, usage)) { |
|||
priv_flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED_PI; |
|||
} else { |
|||
priv_flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED; |
|||
} |
|||
} |
|||
|
|||
if (usage & (BufferUsage::CPU_READ_MASK | BufferUsage::CPU_WRITE_MASK)) { |
|||
priv_flags |= private_handle_t::PRIV_FLAGS_CPU_RENDERED; |
|||
} |
|||
|
|||
if ((usage & (BufferUsage::VIDEO_ENCODER | BufferUsage::VIDEO_DECODER | |
|||
BufferUsage::CAMERA_OUTPUT | BufferUsage::GPU_RENDER_TARGET))) { |
|||
priv_flags |= private_handle_t::PRIV_FLAGS_NON_CPU_WRITER; |
|||
} |
|||
|
|||
if (!UseUncached(format, usage)) { |
|||
priv_flags |= private_handle_t::PRIV_FLAGS_CACHED; |
|||
} |
|||
|
|||
return priv_flags; |
|||
} |
|||
|
|||
int GetImplDefinedFormat(uint64_t usage, int format) { |
|||
int gr_format = format; |
|||
|
|||
// If input format is HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED then based on
|
|||
// the usage bits, gralloc assigns a format.
|
|||
if (format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED || |
|||
format == HAL_PIXEL_FORMAT_YCbCr_420_888) { |
|||
if ((usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC || usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC_PI) && |
|||
format != HAL_PIXEL_FORMAT_YCbCr_420_888) { |
|||
gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC; |
|||
} else if (usage & BufferUsage::VIDEO_ENCODER) { |
|||
if (usage & GRALLOC_USAGE_PRIVATE_VIDEO_NV21_ENCODER) { |
|||
gr_format = HAL_PIXEL_FORMAT_NV21_ENCODEABLE; // NV21
|
|||
} else if (usage & GRALLOC_USAGE_PRIVATE_HEIF) { |
|||
gr_format = HAL_PIXEL_FORMAT_NV12_HEIF; |
|||
} else if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) { |
|||
gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS; |
|||
} else { |
|||
gr_format = HAL_PIXEL_FORMAT_NV12_ENCODEABLE; // NV12
|
|||
} |
|||
} else if (usage & BufferUsage::CAMERA_INPUT) { |
|||
if (usage & BufferUsage::CAMERA_OUTPUT) { |
|||
// Assumed ZSL if both producer and consumer camera flags set
|
|||
gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; // NV21
|
|||
} else { |
|||
gr_format = HAL_PIXEL_FORMAT_YCrCb_420_SP; // NV21
|
|||
} |
|||
} else if (usage & BufferUsage::CAMERA_OUTPUT) { |
|||
if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) { |
|||
gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; // NV21
|
|||
} else { |
|||
gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS; // NV12 preview
|
|||
} |
|||
} else if (usage & BufferUsage::COMPOSER_OVERLAY) { |
|||
// XXX: If we still haven't set a format, default to RGBA8888
|
|||
gr_format = HAL_PIXEL_FORMAT_RGBA_8888; |
|||
} else if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) { |
|||
// If no other usage flags are detected, default the
|
|||
// flexible YUV format to NV21_ZSL
|
|||
gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; |
|||
} |
|||
} |
|||
|
|||
return gr_format; |
|||
} |
|||
|
|||
bool HasAlphaComponent(int32_t format) { |
|||
switch (format) { |
|||
case HAL_PIXEL_FORMAT_RGBA_8888: |
|||
case HAL_PIXEL_FORMAT_BGRA_8888: |
|||
case HAL_PIXEL_FORMAT_RGBA_5551: |
|||
case HAL_PIXEL_FORMAT_RGBA_4444: |
|||
case HAL_PIXEL_FORMAT_RGBA_1010102: |
|||
case HAL_PIXEL_FORMAT_ARGB_2101010: |
|||
case HAL_PIXEL_FORMAT_BGRA_1010102: |
|||
case HAL_PIXEL_FORMAT_ABGR_2101010: |
|||
case HAL_PIXEL_FORMAT_RGBA_FP16: |
|||
return true; |
|||
default: |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
void GetRGBPlaneInfo(const BufferInfo& info, int32_t format, int32_t width, int32_t height, |
|||
int32_t /* flags */, int* plane_count, PlaneLayoutInfo* plane_info) { |
|||
uint64_t usage = info.usage; |
|||
*plane_count = 1; |
|||
uint32_t bpp = 0; |
|||
if (IsUncompressedRGBFormat(format)) { |
|||
bpp = GetBppForUncompressedRGB(format); |
|||
} |
|||
plane_info->component = |
|||
(PlaneComponent)(PLANE_COMPONENT_R | PLANE_COMPONENT_G | PLANE_COMPONENT_B); |
|||
if (HasAlphaComponent(format)) { |
|||
plane_info->component = (PlaneComponent)(plane_info->component | PLANE_COMPONENT_A); |
|||
} |
|||
plane_info->size = GetSize(info, width, height); |
|||
plane_info->step = bpp; |
|||
plane_info->offset = GetRgbMetaSize(format, width, height, usage); |
|||
plane_info->h_subsampling = 0; |
|||
plane_info->v_subsampling = 0; |
|||
plane_info->stride = width; |
|||
plane_info->stride_bytes = width * plane_info->step; |
|||
plane_info->scanlines = height; |
|||
} |
|||
|
|||
} // namespace gralloc
|
|||
@ -1,156 +0,0 @@ |
|||
/* |
|||
* Copyright (c) 2011-2016,2018-2019, 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 __GR_UTILS_H__ |
|||
#define __GR_UTILS_H__ |
|||
|
|||
#include "gralloc_priv.h" |
|||
#include "types/common.h" |
|||
|
|||
#define SZ_2M 0x200000 |
|||
#define SZ_1M 0x100000 |
|||
#define SZ_4K 0x1000 |
|||
|
|||
#define SIZE_4K 4096 |
|||
#define SIZE_8K 8192 |
|||
|
|||
#ifdef SLAVE_SIDE_CP |
|||
#define SECURE_ALIGN SZ_1M |
|||
#else // MASTER_SIDE_CP |
|||
#define SECURE_ALIGN SZ_4K |
|||
#endif |
|||
|
|||
#define INT(exp) static_cast<int>(exp) |
|||
#define UINT(exp) static_cast<unsigned int>(exp) |
|||
|
|||
using android::hardware::graphics::common::V1_1::BufferUsage; |
|||
|
|||
namespace gralloc { |
|||
struct BufferInfo { |
|||
BufferInfo(int w, int h, int f, uint64_t usage = 0) |
|||
: width(w), height(h), format(f), layer_count(1), usage(usage) {} |
|||
int width; |
|||
int height; |
|||
int format; |
|||
int layer_count; |
|||
uint64_t usage; |
|||
}; |
|||
|
|||
template <class Type1, class Type2> |
|||
inline Type1 ALIGN(Type1 x, Type2 align) { |
|||
return (Type1)((x + (Type1)align - 1) & ~((Type1)align - 1)); |
|||
} |
|||
|
|||
enum PlaneComponent { |
|||
/* luma */ |
|||
PLANE_COMPONENT_Y = 1 << 0, |
|||
/* chroma blue */ |
|||
PLANE_COMPONENT_Cb = 1 << 1, |
|||
/* chroma red */ |
|||
PLANE_COMPONENT_Cr = 1 << 2, |
|||
|
|||
/* red */ |
|||
PLANE_COMPONENT_R = 1 << 10, |
|||
/* green */ |
|||
PLANE_COMPONENT_G = 1 << 11, |
|||
/* blue */ |
|||
PLANE_COMPONENT_B = 1 << 12, |
|||
|
|||
/* alpha */ |
|||
PLANE_COMPONENT_A = 1 << 20, |
|||
|
|||
/* raw data plane */ |
|||
PLANE_COMPONENT_RAW = 1 << 30, |
|||
|
|||
/* meta information plane */ |
|||
PLANE_COMPONENT_META = 1 << 31, |
|||
}; |
|||
|
|||
struct PlaneLayoutInfo { |
|||
/** Components represented the type of plane. */ |
|||
PlaneComponent component; |
|||
|
|||
/** horizontal subsampling. Must be a positive power of 2. */ |
|||
uint32_t h_subsampling; |
|||
|
|||
/** vertical subsampling. Must be a positive power of 2. */ |
|||
uint32_t v_subsampling; |
|||
|
|||
/** offset to the first byte of the top-left pixel of the plane |
|||
* and it is calculated from the start of the buffer. |
|||
* Add base of the handle with offset to get the first byte of the plane. |
|||
*/ |
|||
uint32_t offset; |
|||
|
|||
/** step is the distance in bytes from one pixel value to the next. */ |
|||
int32_t step; |
|||
|
|||
/** stride of the plane in pixels */ |
|||
int32_t stride; |
|||
|
|||
/** stride of the plane in in bytes */ |
|||
int32_t stride_bytes; |
|||
|
|||
/** plane height or vertical stride */ |
|||
int32_t scanlines; |
|||
|
|||
/** size of the plane in bytes */ |
|||
uint32_t size; |
|||
}; |
|||
|
|||
bool IsCompressedRGBFormat(int format); |
|||
bool IsUncompressedRGBFormat(int format); |
|||
uint32_t GetBppForUncompressedRGB(int format); |
|||
bool CpuCanAccess(uint64_t usage); |
|||
bool CpuCanRead(uint64_t usage); |
|||
bool CpuCanWrite(uint64_t usage); |
|||
unsigned int GetSize(const BufferInfo& d, unsigned int alignedw, unsigned int alignedh); |
|||
void GetRGBPlaneInfo(const BufferInfo& info, int32_t format, int32_t width, int32_t height, |
|||
int32_t flags, int* plane_count, PlaneLayoutInfo* plane_info); |
|||
unsigned int GetRgbMetaSize(int format, uint32_t width, uint32_t height, uint64_t usage); |
|||
bool IsUBwcFormat(int format); |
|||
bool IsUBwcSupported(int format); |
|||
bool IsUBwcPISupported(int format, uint64_t usage); |
|||
bool IsUBwcEnabled(int format, uint64_t usage); |
|||
void GetRgbUBwcBlockSize(uint32_t bpp, int* block_width, int* block_height); |
|||
unsigned int GetRgbUBwcMetaBufferSize(int width, int height, uint32_t bpp); |
|||
unsigned int GetUBwcSize(int width, int height, int format, unsigned int alignedw, |
|||
unsigned int alignedh); |
|||
uint32_t GetDataAlignment(int format, uint64_t usage); |
|||
bool CanUseAdrenoForSize(int buffer_type, uint64_t usage); |
|||
bool GetAdrenoSizeAPIStatus(); |
|||
bool UseUncached(int format, uint64_t usage); |
|||
uint64_t GetHandleFlags(int format, uint64_t usage); |
|||
int GetImplDefinedFormat(uint64_t usage, int format); |
|||
int GetCustomFormatFlags(int format, uint64_t usage, int* custom_format, uint64_t* priv_flags); |
|||
bool IsGPUFlagSupported(uint64_t usage); |
|||
bool HasAlphaComponent(int32_t format); |
|||
} // namespace gralloc |
|||
|
|||
#endif // __GR_UTILS_H__ |
|||
@ -1,103 +0,0 @@ |
|||
/* |
|||
* Copyright (c) 2011-2021, The Linux Foundation. All rights reserved. |
|||
* Not a Contribution |
|||
* |
|||
* Copyright (C) 2008 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. |
|||
*/ |
|||
|
|||
#ifndef __GRALLOC_PRIV_H__ |
|||
#define __GRALLOC_PRIV_H__ |
|||
|
|||
#include <errno.h> |
|||
#include <unistd.h> |
|||
|
|||
#include "QtiGrallocDefs.h" |
|||
#include "gr_priv_handle.h" |
|||
|
|||
//#pragma message "Warning: gralloc_priv.h is deprecated" |
|||
|
|||
#define GRALLOC_PROP_PREFIX "vendor.gralloc." |
|||
#define GRALLOC_PROP(prop_name) GRALLOC_PROP_PREFIX prop_name |
|||
|
|||
#define DISABLE_UBWC_PROP GRALLOC_PROP("disable_ubwc") |
|||
#define DISABLE_AHARDWAREBUFFER_PROP GRALLOC_PROP("disable_ahardware_buffer") |
|||
#define ENABLE_FB_UBWC_PROP GRALLOC_PROP("enable_fb_ubwc") |
|||
#define MAP_FB_MEMORY_PROP GRALLOC_PROP("map_fb_memory") |
|||
#define USE_SYSTEM_HEAP_FOR_SENSORS GRALLOC_PROP("use_system_heap_for_sensors") |
|||
|
|||
#define ROUND_UP_PAGESIZE(x) roundUpToPageSize(x) |
|||
inline int roundUpToPageSize(int x) { |
|||
return (x + (getpagesize() - 1)) & ~(getpagesize() - 1); |
|||
} |
|||
|
|||
/* Legacy gralloc1 definitions */ |
|||
/* Some clients may still be using the old flags */ |
|||
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_ADSP_HEAP GRALLOC_USAGE_PRIVATE_ADSP_HEAP |
|||
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_ALLOC_UBWC GRALLOC_USAGE_PRIVATE_ALLOC_UBWC |
|||
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_UNCACHED GRALLOC_USAGE_PRIVATE_UNCACHED |
|||
#define GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY |
|||
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_MM_HEAP GRALLOC_USAGE_PRIVATE_MM_HEAP |
|||
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_10BIT GRALLOC_USAGE_PRIVATE_10BIT |
|||
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_10BIT_TP GRALLOC_USAGE_PRIVATE_10BIT_TP |
|||
#define GRALLOC1_CONSUMER_USAGE_PRIVATE_10BIT_TP GRALLOC_USAGE_PRIVATE_10BIT_TP |
|||
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_VIDEO_NV21_ENCODER GRALLOC_USAGE_PRIVATE_VIDEO_NV21_ENCODER |
|||
|
|||
// for PERFORM API : |
|||
#define GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER 1 |
|||
#define GRALLOC_MODULE_PERFORM_GET_STRIDE 2 |
|||
#define GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE 3 |
|||
#define GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE 4 |
|||
#define GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES 5 |
|||
#define GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE 6 |
|||
#define GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO 7 |
|||
#define GRALLOC_MODULE_PERFORM_GET_MAP_SECURE_BUFFER_INFO 8 |
|||
#define GRALLOC_MODULE_PERFORM_GET_UBWC_FLAG 9 |
|||
#define GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS 10 |
|||
#define GRALLOC_MODULE_PERFORM_GET_IGC 11 |
|||
#define GRALLOC_MODULE_PERFORM_SET_IGC 12 |
|||
#define GRALLOC_MODULE_PERFORM_SET_SINGLE_BUFFER_MODE 13 |
|||
#define GRALLOC1_MODULE_PERFORM_GET_BUFFER_SIZE_AND_DIMENSIONS 14 |
|||
#define GRALLOC1_MODULE_PERFORM_GET_INTERLACE_FLAG 15 |
|||
#define GRALLOC_MODULE_PERFORM_GET_GRAPHICS_METADATA 16 |
|||
|
|||
/* possible values for inverse gamma correction */ |
|||
#define HAL_IGC_NOT_SPECIFIED 0 |
|||
#define HAL_IGC_s_RGB 1 |
|||
|
|||
/* Color Space: Values maps to ColorSpace_t in qdMetadata.h */ |
|||
#define HAL_CSC_ITU_R_601 0 |
|||
#define HAL_CSC_ITU_R_601_FR 1 |
|||
#define HAL_CSC_ITU_R_709 2 |
|||
#define HAL_CSC_ITU_R_709_FR 3 |
|||
#define HAL_CSC_ITU_R_2020 4 |
|||
#define HAL_CSC_ITU_R_2020_FR 5 |
|||
|
|||
/* 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 |
|||
}; |
|||
|
|||
/* Flag to determine interlaced content |
|||
* Value maps to Flags presents in types.hal of QtiMapperextensions |
|||
*/ |
|||
enum { |
|||
LAYOUT_INTERLACED_FLAG = 1 << 0, |
|||
}; |
|||
|
|||
#endif // __GRALLOC_PRIV_H__ |
|||
@ -1,183 +0,0 @@ |
|||
/* |
|||
* Copyright (c) 2016-2022, 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. |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <hidl/HidlSupport.h> |
|||
#include <hidl/MQDescriptor.h> |
|||
#include <hidl/Status.h> |
|||
#include <utils/NativeHandle.h> |
|||
#include <utils/misc.h> |
|||
|
|||
#include "types/mapper.h" |
|||
|
|||
namespace vendor::qti::hardware::display::mapperextensions::V1_0 { |
|||
struct IQtiMapperExtensions; |
|||
} |
|||
|
|||
namespace android::hardware::graphics::mapper { |
|||
namespace V2_0 { |
|||
|
|||
struct IMapper : public IBase { |
|||
struct BufferDescriptorInfo final { |
|||
uint32_t width __attribute__((aligned(4))); |
|||
uint32_t height __attribute__((aligned(4))); |
|||
uint32_t layerCount __attribute__((aligned(4))); |
|||
graphics::common::V1_0::PixelFormat format __attribute__((aligned(4))); |
|||
hidl_bitfield<graphics::common::V1_0::BufferUsage> usage __attribute__((aligned(8))); |
|||
}; |
|||
|
|||
struct Rect final { |
|||
int32_t left __attribute__((aligned(4))); |
|||
int32_t top __attribute__((aligned(4))); |
|||
int32_t width __attribute__((aligned(4))); |
|||
int32_t height __attribute__((aligned(4))); |
|||
}; |
|||
|
|||
static sp<IMapper> getService(const std::string& /* serviceName */, const bool /* getStub */); |
|||
}; |
|||
|
|||
} // namespace V2_0 |
|||
namespace V3_0 { |
|||
|
|||
struct IMapper : public IBase { |
|||
static sp<IMapper> getService(const std::string& /* serviceName */, const bool /* getStub */); |
|||
}; |
|||
|
|||
} // namespace V3_0 |
|||
namespace V4_0 { |
|||
|
|||
struct IMapper : public IBase { |
|||
static sp<IMapper> getService(const std::string& /* serviceName */, const bool /* getStub */); |
|||
}; |
|||
|
|||
} // namespace V4_0 |
|||
} // namespace android::hardware::graphics::mapper |
|||
|
|||
namespace vendor::qti::hardware::display::mapper { |
|||
namespace V4_0 { |
|||
|
|||
struct IQtiMapper : public IBase { |
|||
static Return<sp<IQtiMapper>> castFrom(const sp<graphics::mapper::V4_0::IMapper>& /* parent */, |
|||
bool /* emitError */); |
|||
}; |
|||
|
|||
} // namespace V4_0 |
|||
namespace V3_0 { |
|||
|
|||
struct IQtiMapper : public IBase { |
|||
static Return<sp<IQtiMapper>> castFrom(const sp<graphics::mapper::V3_0::IMapper>& /* parent */, |
|||
bool /* emitError */); |
|||
}; |
|||
|
|||
} // namespace V3_0 |
|||
namespace V2_0 { |
|||
|
|||
struct IQtiMapper : public IBase { |
|||
using createDescriptor_cb = std::function<void(graphics::mapper::V2_0::Error error, |
|||
const hidl_vec<uint32_t>& descriptor)>; |
|||
virtual Return<void> createDescriptor( |
|||
const graphics::mapper::V2_0::IMapper::BufferDescriptorInfo& descriptorInfo, |
|||
createDescriptor_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
using importBuffer_cb = std::function<void(graphics::mapper::V2_0::Error error, void* buffer)>; |
|||
virtual Return<void> importBuffer(const hidl_handle& rawHandle, importBuffer_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
virtual Return<graphics::mapper::V2_0::Error> freeBuffer(void* buffer) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
using lock_cb = std::function<void(graphics::mapper::V2_0::Error error, void* data)>; |
|||
virtual Return<void> lock(void* buffer, |
|||
hidl_bitfield<graphics::common::V1_0::BufferUsage> cpuUsage, |
|||
const graphics::mapper::V2_0::IMapper::Rect& accessRegion, |
|||
const hidl_handle& acquireFence, lock_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
using lockYCbCr_cb = std::function<void(graphics::mapper::V2_0::Error error, |
|||
const graphics::mapper::V2_0::YCbCrLayout& layout)>; |
|||
virtual Return<void> lockYCbCr(void* buffer, |
|||
hidl_bitfield<graphics::common::V1_0::BufferUsage> cpuUsage, |
|||
const graphics::mapper::V2_0::IMapper::Rect& accessRegion, |
|||
const hidl_handle& acquireFence, lockYCbCr_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
using unlock_cb = |
|||
std::function<void(graphics::mapper::V2_0::Error error, const hidl_handle& releaseFence)>; |
|||
virtual Return<void> unlock(void* buffer, unlock_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
virtual Return<graphics::mapper::V2_0::Error> validateBufferSize( |
|||
void* buffer, const graphics::mapper::V2_0::IMapper::BufferDescriptorInfo& descriptorInfo, |
|||
uint32_t stride) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
using getTransportSize_cb = |
|||
std::function<void(graphics::mapper::V2_0::Error error, uint32_t numFds, uint32_t numInts)>; |
|||
virtual Return<void> getTransportSize(void* buffer, getTransportSize_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
using createDescriptor_2_1_cb = std::function<void(graphics::mapper::V2_0::Error error, |
|||
const hidl_vec<uint32_t>& descriptor)>; |
|||
virtual Return<void> createDescriptor_2_1( |
|||
const graphics::mapper::V2_0::IMapper::BufferDescriptorInfo& descriptorInfo, |
|||
createDescriptor_2_1_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
using getMapperExtensions_cb = |
|||
std::function<void(graphics::mapper::V2_0::Error error, |
|||
const ::android::sp<::vendor::qti::hardware::display::mapperextensions:: |
|||
V1_0::IQtiMapperExtensions>& extensions)>; |
|||
virtual Return<void> getMapperExtensions(getMapperExtensions_cb _hidl_cb); |
|||
|
|||
static Return<sp<IQtiMapper>> castFrom(const sp<graphics::mapper::V2_0::IMapper>& /* parent */, |
|||
bool /* emitError */); |
|||
}; |
|||
|
|||
} // namespace V2_0 |
|||
} // namespace vendor::qti::hardware::display::mapper |
|||
@ -1,224 +0,0 @@ |
|||
/* |
|||
* Copyright (c) 2016-2022, 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. |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <hidl/HidlSupport.h> |
|||
#include <hidl/MQDescriptor.h> |
|||
#include <hidl/Status.h> |
|||
#include <utils/NativeHandle.h> |
|||
#include <utils/misc.h> |
|||
|
|||
#include "gralloc_priv.h" |
|||
#include "types/mapperextensions.h" |
|||
|
|||
namespace vendor::qti::hardware::display::mapperextensions { |
|||
namespace V1_0 { |
|||
|
|||
struct IQtiMapperExtensions : public IBase { |
|||
IQtiMapperExtensions(){}; |
|||
}; |
|||
|
|||
} // namespace V1_0 |
|||
namespace V1_1 { |
|||
using Error = V1_0::Error; |
|||
using PlaneLayout = V1_0::PlaneLayout; |
|||
|
|||
struct IQtiMapperExtensions : public IBase { |
|||
IQtiMapperExtensions(); |
|||
|
|||
gralloc1_device_t* gralloc; |
|||
GRALLOC1_PFN_PERFORM perform; |
|||
|
|||
using getMapSecureBufferFlag_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, bool mapSecureBuffer)>; |
|||
virtual ::android::hardware::Return<void> getMapSecureBufferFlag( |
|||
void* buffer, getMapSecureBufferFlag_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
// Used, passthrough |
|||
using getInterlacedFlag_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, bool interlaced)>; |
|||
virtual ::android::hardware::Return<void> getInterlacedFlag(void* buffer, |
|||
getInterlacedFlag_cb _hidl_cb); |
|||
|
|||
using getCustomDimensions_cb = |
|||
std::function<void(::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, |
|||
int32_t stride, int32_t height)>; |
|||
virtual ::android::hardware::Return<void> getCustomDimensions(void* buffer, |
|||
getCustomDimensions_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
// Used, passthrough |
|||
using getRgbDataAddress_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, void* rgb_data)>; |
|||
virtual ::android::hardware::Return<void> getRgbDataAddress(void* buffer, |
|||
getRgbDataAddress_cb _hidl_cb); |
|||
|
|||
using calculateBufferAttributes_cb = |
|||
std::function<void(::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, |
|||
int32_t aligned_width, int32_t aligned_height, bool ubwc_enabled)>; |
|||
virtual ::android::hardware::Return<void> calculateBufferAttributes( |
|||
int32_t width, int32_t height, int32_t format, uint64_t usage, |
|||
calculateBufferAttributes_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
// Used, passhthrough |
|||
using getColorSpace_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, int32_t color_space)>; |
|||
virtual ::android::hardware::Return<void> getColorSpace(void* buffer, getColorSpace_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
// Used, passthrough with hidl fixups |
|||
using getYuvPlaneInfo_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, |
|||
const ::android::hardware::hidl_vec< |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::YCbCrLayout>& layout)>; |
|||
virtual ::android::hardware::Return<void> getYuvPlaneInfo(void* buffer, |
|||
getYuvPlaneInfo_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
virtual ::android::hardware::Return< |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error> |
|||
setSingleBufferMode(void* buffer, bool enable) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
using getCustomFormatFlags_cb = |
|||
std::function<void(::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, |
|||
int32_t format, uint64_t priv_flags)>; |
|||
virtual ::android::hardware::Return<void> getCustomFormatFlags(int32_t format, uint64_t usage, |
|||
getCustomFormatFlags_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
// Used, cast private data with no passthrough |
|||
using getFd_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, int32_t fd)>; |
|||
virtual ::android::hardware::Return<void> getFd(void* buffer, getFd_cb _hidl_cb); |
|||
|
|||
// Used, cast private data with no passthrough |
|||
using getWidth_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, int32_t width)>; |
|||
virtual ::android::hardware::Return<void> getWidth(void* buffer, getWidth_cb _hidl_cb); |
|||
|
|||
// Used, cast private data with no passthrough |
|||
using getHeight_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, int32_t height)>; |
|||
virtual ::android::hardware::Return<void> getHeight(void* buffer, getHeight_cb _hidl_cb); |
|||
|
|||
// Used, cast private data with no passthrough |
|||
using getOffset_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, uint64_t offset)>; |
|||
virtual ::android::hardware::Return<void> getOffset(void* buffer, getOffset_cb _hidl_cb); |
|||
|
|||
// Used, cast private data with no passthrough |
|||
using getSize_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, uint64_t size)>; |
|||
virtual ::android::hardware::Return<void> getSize(void* buffer, getSize_cb _hidl_cb); |
|||
|
|||
using getUnalignedWidth_cb = |
|||
std::function<void(::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, |
|||
int32_t unaligned_width)>; |
|||
virtual ::android::hardware::Return<void> getUnalignedWidth(void* buffer, |
|||
getUnalignedWidth_cb _hidl_cb); |
|||
|
|||
using getUnalignedHeight_cb = |
|||
std::function<void(::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, |
|||
int32_t unaligned_height)>; |
|||
virtual ::android::hardware::Return<void> getUnalignedHeight(void* buffer, |
|||
getUnalignedHeight_cb _hidl_cb); |
|||
|
|||
using getLayerCount_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, uint64_t layer_count)>; |
|||
virtual ::android::hardware::Return<void> getLayerCount(void* buffer, getLayerCount_cb _hidl_cb); |
|||
|
|||
using getId_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, uint64_t id)>; |
|||
virtual ::android::hardware::Return<void> getId(void* buffer, getId_cb _hidl_cb); |
|||
|
|||
using getUsageFlags_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, uint64_t usage)>; |
|||
virtual ::android::hardware::Return<void> getUsageFlags(void* buffer, getUsageFlags_cb _hidl_cb); |
|||
|
|||
// Used, cast private data with no passthrough |
|||
using getFormat_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, int32_t format)>; |
|||
virtual ::android::hardware::Return<void> getFormat(void* buffer, getFormat_cb _hidl_cb); |
|||
|
|||
// Used, cast private data with no passthrough |
|||
using getPrivateFlags_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, int32_t flags)>; |
|||
virtual ::android::hardware::Return<void> getPrivateFlags(void* buffer, |
|||
getPrivateFlags_cb _hidl_cb); |
|||
|
|||
using getSurfaceMetadata_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, void* metadata)>; |
|||
virtual ::android::hardware::Return<void> getSurfaceMetadata(void* buffer, |
|||
getSurfaceMetadata_cb _hidl_cb) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
// Used, PAIN |
|||
using getFormatLayout_cb = std::function<void( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error error, uint64_t size, |
|||
const ::android::hardware::hidl_vec< |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout>& plane_info)>; |
|||
virtual ::android::hardware::Return<void> getFormatLayout(int32_t format, uint64_t usage, |
|||
int32_t flags, int32_t width, |
|||
int32_t height, |
|||
getFormatLayout_cb _hidl_cb); |
|||
|
|||
// V1.1, Used, passthrough |
|||
virtual ::android::hardware::Return< |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error> |
|||
getSurfaceMetadata_V1(void* buffer, void* metadata) { |
|||
ALOGE("%s", __func__); |
|||
std::terminate(); |
|||
} |
|||
|
|||
static Return<sp<IQtiMapperExtensions>> castFrom( |
|||
android::sp<V1_0::IQtiMapperExtensions> const& /* parent */, bool /* emitError */); |
|||
}; |
|||
|
|||
} // namespace V1_1 |
|||
} // namespace vendor::qti::hardware::display::mapperextensions |
|||
6744
externals/libadrenotools/tools/qtimapper-shim/ext/types/common.h
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1,250 +0,0 @@ |
|||
#ifndef HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_TYPES_H |
|||
#define HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_TYPES_H |
|||
|
|||
#include <hidl/HidlSupport.h> |
|||
#include <hidl/MQDescriptor.h> |
|||
#include <utils/NativeHandle.h> |
|||
#include <utils/misc.h> |
|||
|
|||
namespace android { |
|||
namespace hardware { |
|||
namespace graphics { |
|||
namespace mapper { |
|||
namespace V2_0 { |
|||
|
|||
// Forward declaration for forward reference support: |
|||
enum class Error : int32_t; |
|||
struct YCbCrLayout; |
|||
|
|||
enum class Error : int32_t { |
|||
NONE = 0, |
|||
BAD_DESCRIPTOR = 1, |
|||
BAD_BUFFER = 2, |
|||
BAD_VALUE = 3, |
|||
NO_RESOURCES = 5, |
|||
UNSUPPORTED = 7, |
|||
}; |
|||
|
|||
/** |
|||
* A buffer descriptor is an implementation-defined opaque data returned by |
|||
* createDescriptor. It describes the properties of a buffer and is consumed |
|||
* by the allocator. |
|||
*/ |
|||
typedef ::android::hardware::hidl_vec<uint32_t> BufferDescriptor; |
|||
|
|||
/** |
|||
* Structure for describing YCbCr formats for consumption by applications. |
|||
* This is used with PixelFormat::YCBCR_*_888. |
|||
* |
|||
* Buffer chroma subsampling is defined in the format. |
|||
* e.g. PixelFormat::YCBCR_420_888 has subsampling 4:2:0. |
|||
* |
|||
* Buffers must have a 8 bit depth. |
|||
* |
|||
* y, cb, and cr point to the first byte of their respective planes. |
|||
* |
|||
* Stride describes the distance in bytes from the first value of one row of |
|||
* the image to the first value of the next row. It includes the width of the |
|||
* image plus padding. |
|||
* yStride is the stride of the luma plane. |
|||
* cStride is the stride of the chroma planes. |
|||
* |
|||
* chromaStep is the distance in bytes from one chroma pixel value to the |
|||
* next. This is 2 bytes for semiplanar (because chroma values are interleaved |
|||
* and each chroma value is one byte) and 1 for planar. |
|||
*/ |
|||
struct YCbCrLayout final { |
|||
void* y; |
|||
void* cb; |
|||
void* cr; |
|||
uint32_t yStride; |
|||
uint32_t cStride; |
|||
uint32_t chromaStep; |
|||
}; |
|||
|
|||
// |
|||
// type declarations for package |
|||
// |
|||
|
|||
template <typename> |
|||
static inline std::string toString(int32_t o); |
|||
static inline std::string toString(::android::hardware::graphics::mapper::V2_0::Error o); |
|||
|
|||
constexpr int32_t operator|(const ::android::hardware::graphics::mapper::V2_0::Error lhs, |
|||
const ::android::hardware::graphics::mapper::V2_0::Error rhs) { |
|||
return static_cast<int32_t>(static_cast<int32_t>(lhs) | static_cast<int32_t>(rhs)); |
|||
} |
|||
constexpr int32_t operator|(const int32_t lhs, |
|||
const ::android::hardware::graphics::mapper::V2_0::Error rhs) { |
|||
return static_cast<int32_t>(lhs | static_cast<int32_t>(rhs)); |
|||
} |
|||
constexpr int32_t operator|(const ::android::hardware::graphics::mapper::V2_0::Error lhs, |
|||
const int32_t rhs) { |
|||
return static_cast<int32_t>(static_cast<int32_t>(lhs) | rhs); |
|||
} |
|||
constexpr int32_t operator&(const ::android::hardware::graphics::mapper::V2_0::Error lhs, |
|||
const ::android::hardware::graphics::mapper::V2_0::Error rhs) { |
|||
return static_cast<int32_t>(static_cast<int32_t>(lhs) & static_cast<int32_t>(rhs)); |
|||
} |
|||
constexpr int32_t operator&(const int32_t lhs, |
|||
const ::android::hardware::graphics::mapper::V2_0::Error rhs) { |
|||
return static_cast<int32_t>(lhs & static_cast<int32_t>(rhs)); |
|||
} |
|||
constexpr int32_t operator&(const ::android::hardware::graphics::mapper::V2_0::Error lhs, |
|||
const int32_t rhs) { |
|||
return static_cast<int32_t>(static_cast<int32_t>(lhs) & rhs); |
|||
} |
|||
constexpr int32_t& operator|=(int32_t& v, |
|||
const ::android::hardware::graphics::mapper::V2_0::Error e) { |
|||
v |= static_cast<int32_t>(e); |
|||
return v; |
|||
} |
|||
constexpr int32_t& operator&=(int32_t& v, |
|||
const ::android::hardware::graphics::mapper::V2_0::Error e) { |
|||
v &= static_cast<int32_t>(e); |
|||
return v; |
|||
} |
|||
|
|||
static inline std::string toString( |
|||
const ::android::hardware::graphics::mapper::V2_0::YCbCrLayout& o); |
|||
// operator== and operator!= are not generated for YCbCrLayout |
|||
|
|||
// |
|||
// type header definitions for package |
|||
// |
|||
|
|||
template <> |
|||
inline std::string toString<::android::hardware::graphics::mapper::V2_0::Error>(int32_t o) { |
|||
using ::android::hardware::details::toHexString; |
|||
std::string os; |
|||
::android::hardware::hidl_bitfield<::android::hardware::graphics::mapper::V2_0::Error> flipped = |
|||
0; |
|||
bool first = true; |
|||
if ((o & ::android::hardware::graphics::mapper::V2_0::Error::NONE) == |
|||
static_cast<int32_t>(::android::hardware::graphics::mapper::V2_0::Error::NONE)) { |
|||
os += (first ? "" : " | "); |
|||
os += "NONE"; |
|||
first = false; |
|||
flipped |= ::android::hardware::graphics::mapper::V2_0::Error::NONE; |
|||
} |
|||
if ((o & ::android::hardware::graphics::mapper::V2_0::Error::BAD_DESCRIPTOR) == |
|||
static_cast<int32_t>(::android::hardware::graphics::mapper::V2_0::Error::BAD_DESCRIPTOR)) { |
|||
os += (first ? "" : " | "); |
|||
os += "BAD_DESCRIPTOR"; |
|||
first = false; |
|||
flipped |= ::android::hardware::graphics::mapper::V2_0::Error::BAD_DESCRIPTOR; |
|||
} |
|||
if ((o & ::android::hardware::graphics::mapper::V2_0::Error::BAD_BUFFER) == |
|||
static_cast<int32_t>(::android::hardware::graphics::mapper::V2_0::Error::BAD_BUFFER)) { |
|||
os += (first ? "" : " | "); |
|||
os += "BAD_BUFFER"; |
|||
first = false; |
|||
flipped |= ::android::hardware::graphics::mapper::V2_0::Error::BAD_BUFFER; |
|||
} |
|||
if ((o & ::android::hardware::graphics::mapper::V2_0::Error::BAD_VALUE) == |
|||
static_cast<int32_t>(::android::hardware::graphics::mapper::V2_0::Error::BAD_VALUE)) { |
|||
os += (first ? "" : " | "); |
|||
os += "BAD_VALUE"; |
|||
first = false; |
|||
flipped |= ::android::hardware::graphics::mapper::V2_0::Error::BAD_VALUE; |
|||
} |
|||
if ((o & ::android::hardware::graphics::mapper::V2_0::Error::NO_RESOURCES) == |
|||
static_cast<int32_t>(::android::hardware::graphics::mapper::V2_0::Error::NO_RESOURCES)) { |
|||
os += (first ? "" : " | "); |
|||
os += "NO_RESOURCES"; |
|||
first = false; |
|||
flipped |= ::android::hardware::graphics::mapper::V2_0::Error::NO_RESOURCES; |
|||
} |
|||
if ((o & ::android::hardware::graphics::mapper::V2_0::Error::UNSUPPORTED) == |
|||
static_cast<int32_t>(::android::hardware::graphics::mapper::V2_0::Error::UNSUPPORTED)) { |
|||
os += (first ? "" : " | "); |
|||
os += "UNSUPPORTED"; |
|||
first = false; |
|||
flipped |= ::android::hardware::graphics::mapper::V2_0::Error::UNSUPPORTED; |
|||
} |
|||
if (o != flipped) { |
|||
os += (first ? "" : " | "); |
|||
os += toHexString(o & (~flipped)); |
|||
} |
|||
os += " ("; |
|||
os += toHexString(o); |
|||
os += ")"; |
|||
return os; |
|||
} |
|||
|
|||
static inline std::string toString(::android::hardware::graphics::mapper::V2_0::Error o) { |
|||
using ::android::hardware::details::toHexString; |
|||
if (o == ::android::hardware::graphics::mapper::V2_0::Error::NONE) { |
|||
return "NONE"; |
|||
} |
|||
if (o == ::android::hardware::graphics::mapper::V2_0::Error::BAD_DESCRIPTOR) { |
|||
return "BAD_DESCRIPTOR"; |
|||
} |
|||
if (o == ::android::hardware::graphics::mapper::V2_0::Error::BAD_BUFFER) { |
|||
return "BAD_BUFFER"; |
|||
} |
|||
if (o == ::android::hardware::graphics::mapper::V2_0::Error::BAD_VALUE) { |
|||
return "BAD_VALUE"; |
|||
} |
|||
if (o == ::android::hardware::graphics::mapper::V2_0::Error::NO_RESOURCES) { |
|||
return "NO_RESOURCES"; |
|||
} |
|||
if (o == ::android::hardware::graphics::mapper::V2_0::Error::UNSUPPORTED) { |
|||
return "UNSUPPORTED"; |
|||
} |
|||
std::string os; |
|||
os += toHexString(static_cast<int32_t>(o)); |
|||
return os; |
|||
} |
|||
|
|||
static inline std::string toString( |
|||
const ::android::hardware::graphics::mapper::V2_0::YCbCrLayout& o) { |
|||
using ::android::hardware::toString; |
|||
std::string os; |
|||
os += "{"; |
|||
os += ".y = "; |
|||
os += ::android::hardware::toString(o.y); |
|||
os += ", .cb = "; |
|||
os += ::android::hardware::toString(o.cb); |
|||
os += ", .cr = "; |
|||
os += ::android::hardware::toString(o.cr); |
|||
os += ", .yStride = "; |
|||
os += ::android::hardware::toString(o.yStride); |
|||
os += ", .cStride = "; |
|||
os += ::android::hardware::toString(o.cStride); |
|||
os += ", .chromaStep = "; |
|||
os += ::android::hardware::toString(o.chromaStep); |
|||
os += "}"; |
|||
return os; |
|||
} |
|||
|
|||
// operator== and operator!= are not generated for YCbCrLayout |
|||
|
|||
} // namespace V2_0 |
|||
} // namespace mapper |
|||
} // namespace graphics |
|||
} // namespace hardware |
|||
} // namespace android |
|||
|
|||
// |
|||
// global type declarations for package |
|||
// |
|||
|
|||
namespace android { |
|||
namespace hardware { |
|||
namespace details { |
|||
template <> |
|||
constexpr std::array<::android::hardware::graphics::mapper::V2_0::Error, 6> |
|||
hidl_enum_values<::android::hardware::graphics::mapper::V2_0::Error> = { |
|||
::android::hardware::graphics::mapper::V2_0::Error::NONE, |
|||
::android::hardware::graphics::mapper::V2_0::Error::BAD_DESCRIPTOR, |
|||
::android::hardware::graphics::mapper::V2_0::Error::BAD_BUFFER, |
|||
::android::hardware::graphics::mapper::V2_0::Error::BAD_VALUE, |
|||
::android::hardware::graphics::mapper::V2_0::Error::NO_RESOURCES, |
|||
::android::hardware::graphics::mapper::V2_0::Error::UNSUPPORTED, |
|||
}; |
|||
} // namespace details |
|||
} // namespace hardware |
|||
} // namespace android |
|||
|
|||
#endif // HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_TYPES_H |
|||
@ -1,707 +0,0 @@ |
|||
#ifndef HIDL_GENERATED_VENDOR_QTI_HARDWARE_DISPLAY_MAPPEREXTENSIONS_V1_0_TYPES_H |
|||
#define HIDL_GENERATED_VENDOR_QTI_HARDWARE_DISPLAY_MAPPEREXTENSIONS_V1_0_TYPES_H |
|||
|
|||
#include <hidl/HidlSupport.h> |
|||
#include <hidl/MQDescriptor.h> |
|||
#include <utils/NativeHandle.h> |
|||
#include <utils/misc.h> |
|||
|
|||
namespace vendor { |
|||
namespace qti { |
|||
namespace hardware { |
|||
namespace display { |
|||
namespace mapperextensions { |
|||
namespace V1_0 { |
|||
|
|||
// Forward declaration for forward reference support: |
|||
enum class Error : int32_t; |
|||
struct YCbCrLayout; |
|||
enum class PlaneComponent : uint32_t; |
|||
enum class Flags : int32_t; |
|||
struct PlaneLayout; |
|||
|
|||
enum class Error : int32_t { |
|||
NONE = 0, |
|||
BAD_BUFFER = 2, |
|||
NO_RESOURCES = 5, |
|||
UNSUPPORTED = 7, |
|||
}; |
|||
|
|||
struct YCbCrLayout final { |
|||
void* y; |
|||
void* cb; |
|||
void* cr; |
|||
uint32_t yStride; |
|||
uint32_t cStride; |
|||
uint32_t chromaStep; |
|||
}; |
|||
|
|||
/** |
|||
* Plane Component type definitions. |
|||
*/ |
|||
enum class PlaneComponent : uint32_t { |
|||
PLANE_COMPONENT_Y = 1u /* (1 << 0) */, |
|||
PLANE_COMPONENT_Cb = 2u /* (1 << 1) */, |
|||
PLANE_COMPONENT_Cr = 4u /* (1 << 2) */, |
|||
PLANE_COMPONENT_R = 1024u /* (1 << 10) */, |
|||
PLANE_COMPONENT_G = 2048u /* (1 << 11) */, |
|||
PLANE_COMPONENT_B = 4096u /* (1 << 12) */, |
|||
PLANE_COMPONENT_A = 1048576u /* (1 << 20) */, |
|||
PLANE_COMPONENT_RAW = 1073741824u /* (1 << 30) */, |
|||
PLANE_COMPONENT_META = 2147483648u /* (1 << 31) */, |
|||
}; |
|||
|
|||
/** |
|||
* Flags to send with getFormatLayout for extra information for e.g. interlaced, |
|||
* otherwise send 0. |
|||
*/ |
|||
enum class Flags : int32_t { |
|||
LAYOUT_INTERLACED_FLAG = 1 /* (1 << 0) */, |
|||
}; |
|||
|
|||
/** |
|||
* Structure for describing plane layout information for YUVA/RGBA/RAW formats |
|||
* YUV formats can be planar or semi-planar. |
|||
* |
|||
* This layout structure is used with any pixel format that can be |
|||
* represented by it, such as: |
|||
* - HAL_PIXEL_FORMAT_YCbCr_* |
|||
* - HAL_PIXEL_FORMAT_RGB*_* |
|||
* - even implementation defined formats that can be represented by |
|||
* the structures |
|||
* |
|||
* Each plane can be made up of one or more PlaneComponents depending on |
|||
* the format. |
|||
* |
|||
* Each plane can be subsampled either vertically or horizontally by |
|||
* a power-of-two factor. |
|||
* |
|||
* 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. |
|||
* |
|||
* Stride is provided in both pixels and bytes. |
|||
* Stride_bytes 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. |
|||
* |
|||
* Scanlines describes the height of the plane in terms of number of rows. |
|||
* |
|||
* Size of plane is stride_bytes * scanlines + any padding required for |
|||
* alignment as per format specification. |
|||
* |
|||
*/ |
|||
struct PlaneLayout final { |
|||
::android::hardware::hidl_bitfield< |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent> |
|||
component __attribute__((aligned(4))); |
|||
uint32_t h_subsampling __attribute__((aligned(4))); |
|||
uint32_t v_subsampling __attribute__((aligned(4))); |
|||
uint32_t offset __attribute__((aligned(4))); |
|||
int32_t pixel_increment __attribute__((aligned(4))); |
|||
int32_t stride __attribute__((aligned(4))); |
|||
int32_t stride_bytes __attribute__((aligned(4))); |
|||
int32_t scanlines __attribute__((aligned(4))); |
|||
uint32_t size __attribute__((aligned(4))); |
|||
}; |
|||
|
|||
static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, |
|||
component) == 0, |
|||
"wrong offset"); |
|||
static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, |
|||
h_subsampling) == 4, |
|||
"wrong offset"); |
|||
static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, |
|||
v_subsampling) == 8, |
|||
"wrong offset"); |
|||
static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, |
|||
offset) == 12, |
|||
"wrong offset"); |
|||
static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, |
|||
pixel_increment) == 16, |
|||
"wrong offset"); |
|||
static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, |
|||
stride) == 20, |
|||
"wrong offset"); |
|||
static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, |
|||
stride_bytes) == 24, |
|||
"wrong offset"); |
|||
static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, |
|||
scanlines) == 28, |
|||
"wrong offset"); |
|||
static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, |
|||
size) == 32, |
|||
"wrong offset"); |
|||
static_assert(sizeof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout) == 36, |
|||
"wrong size"); |
|||
static_assert(__alignof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout) == 4, |
|||
"wrong alignment"); |
|||
|
|||
// |
|||
// type declarations for package |
|||
// |
|||
|
|||
template <typename> |
|||
static inline std::string toString(int32_t o); |
|||
static inline std::string toString( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error o); |
|||
|
|||
constexpr int32_t operator|( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error lhs, |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error rhs) { |
|||
return static_cast<int32_t>(static_cast<int32_t>(lhs) | static_cast<int32_t>(rhs)); |
|||
} |
|||
constexpr int32_t operator|( |
|||
const int32_t lhs, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error rhs) { |
|||
return static_cast<int32_t>(lhs | static_cast<int32_t>(rhs)); |
|||
} |
|||
constexpr int32_t operator|( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error lhs, const int32_t rhs) { |
|||
return static_cast<int32_t>(static_cast<int32_t>(lhs) | rhs); |
|||
} |
|||
constexpr int32_t operator&( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error lhs, |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error rhs) { |
|||
return static_cast<int32_t>(static_cast<int32_t>(lhs) & static_cast<int32_t>(rhs)); |
|||
} |
|||
constexpr int32_t operator&( |
|||
const int32_t lhs, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error rhs) { |
|||
return static_cast<int32_t>(lhs & static_cast<int32_t>(rhs)); |
|||
} |
|||
constexpr int32_t operator&( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error lhs, const int32_t rhs) { |
|||
return static_cast<int32_t>(static_cast<int32_t>(lhs) & rhs); |
|||
} |
|||
constexpr int32_t& operator|=( |
|||
int32_t& v, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error e) { |
|||
v |= static_cast<int32_t>(e); |
|||
return v; |
|||
} |
|||
constexpr int32_t& operator&=( |
|||
int32_t& v, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error e) { |
|||
v &= static_cast<int32_t>(e); |
|||
return v; |
|||
} |
|||
|
|||
static inline std::string toString( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::YCbCrLayout& o); |
|||
// operator== and operator!= are not generated for YCbCrLayout |
|||
|
|||
template <typename> |
|||
static inline std::string toString(uint32_t o); |
|||
static inline std::string toString( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent o); |
|||
|
|||
constexpr uint32_t operator|( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent lhs, |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent rhs) { |
|||
return static_cast<uint32_t>(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs)); |
|||
} |
|||
constexpr uint32_t operator|( |
|||
const uint32_t lhs, |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent rhs) { |
|||
return static_cast<uint32_t>(lhs | static_cast<uint32_t>(rhs)); |
|||
} |
|||
constexpr uint32_t operator|( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent lhs, |
|||
const uint32_t rhs) { |
|||
return static_cast<uint32_t>(static_cast<uint32_t>(lhs) | rhs); |
|||
} |
|||
constexpr uint32_t operator&( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent lhs, |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent rhs) { |
|||
return static_cast<uint32_t>(static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs)); |
|||
} |
|||
constexpr uint32_t operator&( |
|||
const uint32_t lhs, |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent rhs) { |
|||
return static_cast<uint32_t>(lhs & static_cast<uint32_t>(rhs)); |
|||
} |
|||
constexpr uint32_t operator&( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent lhs, |
|||
const uint32_t rhs) { |
|||
return static_cast<uint32_t>(static_cast<uint32_t>(lhs) & rhs); |
|||
} |
|||
constexpr uint32_t& operator|=( |
|||
uint32_t& v, const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent e) { |
|||
v |= static_cast<uint32_t>(e); |
|||
return v; |
|||
} |
|||
constexpr uint32_t& operator&=( |
|||
uint32_t& v, const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent e) { |
|||
v &= static_cast<uint32_t>(e); |
|||
return v; |
|||
} |
|||
|
|||
template <typename> |
|||
static inline std::string toString(int32_t o); |
|||
static inline std::string toString( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Flags o); |
|||
|
|||
constexpr int32_t operator|( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags lhs, |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags rhs) { |
|||
return static_cast<int32_t>(static_cast<int32_t>(lhs) | static_cast<int32_t>(rhs)); |
|||
} |
|||
constexpr int32_t operator|( |
|||
const int32_t lhs, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags rhs) { |
|||
return static_cast<int32_t>(lhs | static_cast<int32_t>(rhs)); |
|||
} |
|||
constexpr int32_t operator|( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags lhs, const int32_t rhs) { |
|||
return static_cast<int32_t>(static_cast<int32_t>(lhs) | rhs); |
|||
} |
|||
constexpr int32_t operator&( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags lhs, |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags rhs) { |
|||
return static_cast<int32_t>(static_cast<int32_t>(lhs) & static_cast<int32_t>(rhs)); |
|||
} |
|||
constexpr int32_t operator&( |
|||
const int32_t lhs, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags rhs) { |
|||
return static_cast<int32_t>(lhs & static_cast<int32_t>(rhs)); |
|||
} |
|||
constexpr int32_t operator&( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags lhs, const int32_t rhs) { |
|||
return static_cast<int32_t>(static_cast<int32_t>(lhs) & rhs); |
|||
} |
|||
constexpr int32_t& operator|=( |
|||
int32_t& v, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags e) { |
|||
v |= static_cast<int32_t>(e); |
|||
return v; |
|||
} |
|||
constexpr int32_t& operator&=( |
|||
int32_t& v, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags e) { |
|||
v &= static_cast<int32_t>(e); |
|||
return v; |
|||
} |
|||
|
|||
static inline std::string toString( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& o); |
|||
static inline bool operator==( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& lhs, |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& rhs); |
|||
static inline bool operator!=( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& lhs, |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& rhs); |
|||
|
|||
// |
|||
// type header definitions for package |
|||
// |
|||
|
|||
template <> |
|||
inline std::string toString<::vendor::qti::hardware::display::mapperextensions::V1_0::Error>( |
|||
int32_t o) { |
|||
using ::android::hardware::details::toHexString; |
|||
std::string os; |
|||
::android::hardware::hidl_bitfield< |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error> |
|||
flipped = 0; |
|||
bool first = true; |
|||
if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NONE) == |
|||
static_cast<int32_t>(::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NONE)) { |
|||
os += (first ? "" : " | "); |
|||
os += "NONE"; |
|||
first = false; |
|||
flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NONE; |
|||
} |
|||
if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::BAD_BUFFER) == |
|||
static_cast<int32_t>( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error::BAD_BUFFER)) { |
|||
os += (first ? "" : " | "); |
|||
os += "BAD_BUFFER"; |
|||
first = false; |
|||
flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::BAD_BUFFER; |
|||
} |
|||
if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NO_RESOURCES) == |
|||
static_cast<int32_t>( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NO_RESOURCES)) { |
|||
os += (first ? "" : " | "); |
|||
os += "NO_RESOURCES"; |
|||
first = false; |
|||
flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NO_RESOURCES; |
|||
} |
|||
if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::UNSUPPORTED) == |
|||
static_cast<int32_t>( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error::UNSUPPORTED)) { |
|||
os += (first ? "" : " | "); |
|||
os += "UNSUPPORTED"; |
|||
first = false; |
|||
flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::UNSUPPORTED; |
|||
} |
|||
if (o != flipped) { |
|||
os += (first ? "" : " | "); |
|||
os += toHexString(o & (~flipped)); |
|||
} |
|||
os += " ("; |
|||
os += toHexString(o); |
|||
os += ")"; |
|||
return os; |
|||
} |
|||
|
|||
static inline std::string toString( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error o) { |
|||
using ::android::hardware::details::toHexString; |
|||
if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NONE) { |
|||
return "NONE"; |
|||
} |
|||
if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::BAD_BUFFER) { |
|||
return "BAD_BUFFER"; |
|||
} |
|||
if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NO_RESOURCES) { |
|||
return "NO_RESOURCES"; |
|||
} |
|||
if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::UNSUPPORTED) { |
|||
return "UNSUPPORTED"; |
|||
} |
|||
std::string os; |
|||
os += toHexString(static_cast<int32_t>(o)); |
|||
return os; |
|||
} |
|||
|
|||
static inline std::string toString( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::YCbCrLayout& o) { |
|||
using ::android::hardware::toString; |
|||
std::string os; |
|||
os += "{"; |
|||
os += ".y = "; |
|||
os += ::android::hardware::toString(o.y); |
|||
os += ", .cb = "; |
|||
os += ::android::hardware::toString(o.cb); |
|||
os += ", .cr = "; |
|||
os += ::android::hardware::toString(o.cr); |
|||
os += ", .yStride = "; |
|||
os += ::android::hardware::toString(o.yStride); |
|||
os += ", .cStride = "; |
|||
os += ::android::hardware::toString(o.cStride); |
|||
os += ", .chromaStep = "; |
|||
os += ::android::hardware::toString(o.chromaStep); |
|||
os += "}"; |
|||
return os; |
|||
} |
|||
|
|||
// operator== and operator!= are not generated for YCbCrLayout |
|||
|
|||
template <> |
|||
inline std::string |
|||
toString<::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent>(uint32_t o) { |
|||
using ::android::hardware::details::toHexString; |
|||
std::string os; |
|||
::android::hardware::hidl_bitfield< |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent> |
|||
flipped = 0; |
|||
bool first = true; |
|||
if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_Y) == |
|||
static_cast<uint32_t>(::vendor::qti::hardware::display::mapperextensions::V1_0:: |
|||
PlaneComponent::PLANE_COMPONENT_Y)) { |
|||
os += (first ? "" : " | "); |
|||
os += "PLANE_COMPONENT_Y"; |
|||
first = false; |
|||
flipped |= |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_Y; |
|||
} |
|||
if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_Cb) == |
|||
static_cast<uint32_t>(::vendor::qti::hardware::display::mapperextensions::V1_0:: |
|||
PlaneComponent::PLANE_COMPONENT_Cb)) { |
|||
os += (first ? "" : " | "); |
|||
os += "PLANE_COMPONENT_Cb"; |
|||
first = false; |
|||
flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_Cb; |
|||
} |
|||
if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_Cr) == |
|||
static_cast<uint32_t>(::vendor::qti::hardware::display::mapperextensions::V1_0:: |
|||
PlaneComponent::PLANE_COMPONENT_Cr)) { |
|||
os += (first ? "" : " | "); |
|||
os += "PLANE_COMPONENT_Cr"; |
|||
first = false; |
|||
flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_Cr; |
|||
} |
|||
if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_R) == |
|||
static_cast<uint32_t>(::vendor::qti::hardware::display::mapperextensions::V1_0:: |
|||
PlaneComponent::PLANE_COMPONENT_R)) { |
|||
os += (first ? "" : " | "); |
|||
os += "PLANE_COMPONENT_R"; |
|||
first = false; |
|||
flipped |= |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_R; |
|||
} |
|||
if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_G) == |
|||
static_cast<uint32_t>(::vendor::qti::hardware::display::mapperextensions::V1_0:: |
|||
PlaneComponent::PLANE_COMPONENT_G)) { |
|||
os += (first ? "" : " | "); |
|||
os += "PLANE_COMPONENT_G"; |
|||
first = false; |
|||
flipped |= |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_G; |
|||
} |
|||
if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_B) == |
|||
static_cast<uint32_t>(::vendor::qti::hardware::display::mapperextensions::V1_0:: |
|||
PlaneComponent::PLANE_COMPONENT_B)) { |
|||
os += (first ? "" : " | "); |
|||
os += "PLANE_COMPONENT_B"; |
|||
first = false; |
|||
flipped |= |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_B; |
|||
} |
|||
if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_A) == |
|||
static_cast<uint32_t>(::vendor::qti::hardware::display::mapperextensions::V1_0:: |
|||
PlaneComponent::PLANE_COMPONENT_A)) { |
|||
os += (first ? "" : " | "); |
|||
os += "PLANE_COMPONENT_A"; |
|||
first = false; |
|||
flipped |= |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_A; |
|||
} |
|||
if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_RAW) == |
|||
static_cast<uint32_t>(::vendor::qti::hardware::display::mapperextensions::V1_0:: |
|||
PlaneComponent::PLANE_COMPONENT_RAW)) { |
|||
os += (first ? "" : " | "); |
|||
os += "PLANE_COMPONENT_RAW"; |
|||
first = false; |
|||
flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_RAW; |
|||
} |
|||
if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_META) == |
|||
static_cast<uint32_t>(::vendor::qti::hardware::display::mapperextensions::V1_0:: |
|||
PlaneComponent::PLANE_COMPONENT_META)) { |
|||
os += (first ? "" : " | "); |
|||
os += "PLANE_COMPONENT_META"; |
|||
first = false; |
|||
flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_META; |
|||
} |
|||
if (o != flipped) { |
|||
os += (first ? "" : " | "); |
|||
os += toHexString(o & (~flipped)); |
|||
} |
|||
os += " ("; |
|||
os += toHexString(o); |
|||
os += ")"; |
|||
return os; |
|||
} |
|||
|
|||
static inline std::string toString( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent o) { |
|||
using ::android::hardware::details::toHexString; |
|||
if (o == |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_Y) { |
|||
return "PLANE_COMPONENT_Y"; |
|||
} |
|||
if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_Cb) { |
|||
return "PLANE_COMPONENT_Cb"; |
|||
} |
|||
if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_Cr) { |
|||
return "PLANE_COMPONENT_Cr"; |
|||
} |
|||
if (o == |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_R) { |
|||
return "PLANE_COMPONENT_R"; |
|||
} |
|||
if (o == |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_G) { |
|||
return "PLANE_COMPONENT_G"; |
|||
} |
|||
if (o == |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_B) { |
|||
return "PLANE_COMPONENT_B"; |
|||
} |
|||
if (o == |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_A) { |
|||
return "PLANE_COMPONENT_A"; |
|||
} |
|||
if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_RAW) { |
|||
return "PLANE_COMPONENT_RAW"; |
|||
} |
|||
if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_META) { |
|||
return "PLANE_COMPONENT_META"; |
|||
} |
|||
std::string os; |
|||
os += toHexString(static_cast<uint32_t>(o)); |
|||
return os; |
|||
} |
|||
|
|||
template <> |
|||
inline std::string toString<::vendor::qti::hardware::display::mapperextensions::V1_0::Flags>( |
|||
int32_t o) { |
|||
using ::android::hardware::details::toHexString; |
|||
std::string os; |
|||
::android::hardware::hidl_bitfield< |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Flags> |
|||
flipped = 0; |
|||
bool first = true; |
|||
if ((o & |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Flags::LAYOUT_INTERLACED_FLAG) == |
|||
static_cast<int32_t>(::vendor::qti::hardware::display::mapperextensions::V1_0::Flags:: |
|||
LAYOUT_INTERLACED_FLAG)) { |
|||
os += (first ? "" : " | "); |
|||
os += "LAYOUT_INTERLACED_FLAG"; |
|||
first = false; |
|||
flipped |= |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Flags::LAYOUT_INTERLACED_FLAG; |
|||
} |
|||
if (o != flipped) { |
|||
os += (first ? "" : " | "); |
|||
os += toHexString(o & (~flipped)); |
|||
} |
|||
os += " ("; |
|||
os += toHexString(o); |
|||
os += ")"; |
|||
return os; |
|||
} |
|||
|
|||
static inline std::string toString( |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Flags o) { |
|||
using ::android::hardware::details::toHexString; |
|||
if (o == |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Flags::LAYOUT_INTERLACED_FLAG) { |
|||
return "LAYOUT_INTERLACED_FLAG"; |
|||
} |
|||
std::string os; |
|||
os += toHexString(static_cast<int32_t>(o)); |
|||
return os; |
|||
} |
|||
|
|||
static inline std::string toString( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& o) { |
|||
using ::android::hardware::toString; |
|||
std::string os; |
|||
os += "{"; |
|||
os += ".component = "; |
|||
os += ::vendor::qti::hardware::display::mapperextensions::V1_0::toString< |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent>(o.component); |
|||
os += ", .h_subsampling = "; |
|||
os += ::android::hardware::toString(o.h_subsampling); |
|||
os += ", .v_subsampling = "; |
|||
os += ::android::hardware::toString(o.v_subsampling); |
|||
os += ", .offset = "; |
|||
os += ::android::hardware::toString(o.offset); |
|||
os += ", .pixel_increment = "; |
|||
os += ::android::hardware::toString(o.pixel_increment); |
|||
os += ", .stride = "; |
|||
os += ::android::hardware::toString(o.stride); |
|||
os += ", .stride_bytes = "; |
|||
os += ::android::hardware::toString(o.stride_bytes); |
|||
os += ", .scanlines = "; |
|||
os += ::android::hardware::toString(o.scanlines); |
|||
os += ", .size = "; |
|||
os += ::android::hardware::toString(o.size); |
|||
os += "}"; |
|||
return os; |
|||
} |
|||
|
|||
static inline bool operator==( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& lhs, |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& rhs) { |
|||
if (lhs.component != rhs.component) { |
|||
return false; |
|||
} |
|||
if (lhs.h_subsampling != rhs.h_subsampling) { |
|||
return false; |
|||
} |
|||
if (lhs.v_subsampling != rhs.v_subsampling) { |
|||
return false; |
|||
} |
|||
if (lhs.offset != rhs.offset) { |
|||
return false; |
|||
} |
|||
if (lhs.pixel_increment != rhs.pixel_increment) { |
|||
return false; |
|||
} |
|||
if (lhs.stride != rhs.stride) { |
|||
return false; |
|||
} |
|||
if (lhs.stride_bytes != rhs.stride_bytes) { |
|||
return false; |
|||
} |
|||
if (lhs.scanlines != rhs.scanlines) { |
|||
return false; |
|||
} |
|||
if (lhs.size != rhs.size) { |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
static inline bool operator!=( |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& lhs, |
|||
const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& rhs) { |
|||
return !(lhs == rhs); |
|||
} |
|||
|
|||
} // namespace V1_0 |
|||
} // namespace mapperextensions |
|||
} // namespace display |
|||
} // namespace hardware |
|||
} // namespace qti |
|||
} // namespace vendor |
|||
|
|||
// |
|||
// global type declarations for package |
|||
// |
|||
|
|||
namespace android { |
|||
namespace hardware { |
|||
namespace details { |
|||
template <> |
|||
constexpr std::array<::vendor::qti::hardware::display::mapperextensions::V1_0::Error, 4> |
|||
hidl_enum_values<::vendor::qti::hardware::display::mapperextensions::V1_0::Error> = { |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NONE, |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error::BAD_BUFFER, |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NO_RESOURCES, |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Error::UNSUPPORTED, |
|||
}; |
|||
} // namespace details |
|||
} // namespace hardware |
|||
} // namespace android |
|||
|
|||
namespace android { |
|||
namespace hardware { |
|||
namespace details { |
|||
template <> |
|||
constexpr std::array<::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent, 9> |
|||
hidl_enum_values<::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent> = { |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_Y, |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_Cb, |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_Cr, |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_R, |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_G, |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_B, |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_A, |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_RAW, |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: |
|||
PLANE_COMPONENT_META, |
|||
}; |
|||
} // namespace details |
|||
} // namespace hardware |
|||
} // namespace android |
|||
|
|||
namespace android { |
|||
namespace hardware { |
|||
namespace details { |
|||
template <> |
|||
constexpr std::array<::vendor::qti::hardware::display::mapperextensions::V1_0::Flags, 1> |
|||
hidl_enum_values<::vendor::qti::hardware::display::mapperextensions::V1_0::Flags> = { |
|||
::vendor::qti::hardware::display::mapperextensions::V1_0::Flags::LAYOUT_INTERLACED_FLAG, |
|||
}; |
|||
} // namespace details |
|||
} // namespace hardware |
|||
} // namespace android |
|||
|
|||
#endif // HIDL_GENERATED_VENDOR_QTI_HARDWARE_DISPLAY_MAPPEREXTENSIONS_V1_0_TYPES_H |
|||
@ -1,472 +0,0 @@ |
|||
/*
|
|||
* Copyright (c) 2016-2022, 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. |
|||
*/ |
|||
|
|||
#define LOG_TAG "qtimapper-shim"
|
|||
|
|||
#include <android/hidl/base/1.0/BpHwBase.h>
|
|||
#include <dlfcn.h>
|
|||
#include <hidl/HidlSupport.h>
|
|||
#include <hidl/MQDescriptor.h>
|
|||
#include <hidl/Status.h>
|
|||
#include <log/log.h>
|
|||
#include <utils/NativeHandle.h>
|
|||
#include <utils/misc.h>
|
|||
|
|||
#include "ext/common.h"
|
|||
#include "ext/gr_utils.h"
|
|||
#include "ext/mapper.h"
|
|||
#include "ext/mapperextensions.h"
|
|||
|
|||
using namespace android::hardware; |
|||
using namespace android; |
|||
|
|||
// These two functions are used by the blob and aren't present on Q so weakly stub them
|
|||
extern "C" uint64_t __attribute__((weak)) atrace_get_enabled_tags() { |
|||
return 0; |
|||
} |
|||
|
|||
namespace android::hardware::details { |
|||
void __attribute__((weak)) return_status::onValueRetrieval() const {} |
|||
} // namespace android::hardware::details
|
|||
|
|||
bool IBase::isRemote() const { |
|||
return false; |
|||
} |
|||
|
|||
sp<graphics::mapper::V2_0::IMapper> (*Mapper20GetService)(const std::string&, const bool); |
|||
sp<graphics::mapper::V3_0::IMapper> (*Mapper30GetService)(const std::string&, const bool); |
|||
sp<graphics::mapper::V4_0::IMapper> (*Mapper40GetService)(const std::string&, const bool); |
|||
|
|||
Return<sp<vendor::qti::hardware::display::mapper::V2_0::IQtiMapper>> (*QtiMapper20CastFrom)( |
|||
const sp<graphics::mapper::V2_0::IMapper>&, bool); |
|||
Return<sp<vendor::qti::hardware::display::mapper::V3_0::IQtiMapper>> (*QtiMapper30CastFrom)( |
|||
const sp<graphics::mapper::V3_0::IMapper>&, bool); |
|||
Return<sp<vendor::qti::hardware::display::mapper::V4_0::IQtiMapper>> (*QtiMapper40CastFrom)( |
|||
const sp<graphics::mapper::V4_0::IMapper>&, bool); |
|||
|
|||
Return<sp<vendor::qti::hardware::display::mapperextensions::V1_1::IQtiMapperExtensions>> ( |
|||
*MapperExtensions11CastFrom)( |
|||
const sp<vendor::qti::hardware::display::mapperextensions::V1_0::IQtiMapperExtensions>&, bool); |
|||
|
|||
__attribute__((constructor)) static void initShim() { |
|||
void* qtiMapper40Hnd = |
|||
dlopen("vendor.qti.hardware.display.mapper@4.0.so", RTLD_LAZY | RTLD_LOCAL); |
|||
if (qtiMapper40Hnd) { |
|||
void* mapper40Hnd = dlopen("android.hardware.graphics.mapper@4.0.so", RTLD_LAZY | RTLD_LOCAL); |
|||
if (mapper40Hnd) { |
|||
Mapper40GetService = reinterpret_cast<decltype(Mapper40GetService)>( |
|||
dlsym(mapper40Hnd, |
|||
"_ZN7android8hardware8graphics6mapper4V4_07IMapper10getServiceERKNSt3__112basic_" |
|||
"stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEb")); |
|||
QtiMapper40CastFrom = reinterpret_cast<decltype(QtiMapper40CastFrom)>(dlsym( |
|||
qtiMapper40Hnd, |
|||
"_ZN6vendor3qti8hardware7display6mapper4V4_010IQtiMapper8castFromERKN7android2spINS6_" |
|||
"8hardware8graphics6mapper4V4_07IMapperEEEb")); |
|||
|
|||
ALOGD("%s: Mapper 4.0 present", __func__); |
|||
} |
|||
} |
|||
|
|||
void* qtiMapper30Hnd = |
|||
dlopen("vendor.qti.hardware.display.mapper@3.0.so", RTLD_LAZY | RTLD_LOCAL); |
|||
if (qtiMapper30Hnd) { |
|||
void* mapper30Hnd = dlopen("android.hardware.graphics.mapper@3.0.so", RTLD_LAZY | RTLD_LOCAL); |
|||
if (mapper30Hnd) { |
|||
Mapper30GetService = reinterpret_cast<decltype(Mapper30GetService)>( |
|||
dlsym(mapper30Hnd, |
|||
"_ZN7android8hardware8graphics6mapper4V3_07IMapper10getServiceERKNSt3__112basic_" |
|||
"stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEb")); |
|||
QtiMapper30CastFrom = reinterpret_cast<decltype(QtiMapper30CastFrom)>(dlsym( |
|||
qtiMapper30Hnd, |
|||
"_ZN6vendor3qti8hardware7display6mapper4V3_010IQtiMapper8castFromERKN7android2spINS6_" |
|||
"8hardware8graphics6mapper4V3_07IMapperEEEb")); |
|||
ALOGD("%s: Mapper 3.0 present", __func__); |
|||
} |
|||
} |
|||
|
|||
void* qtiMapper20Hnd = |
|||
dlopen("vendor.qti.hardware.display.mapper@2.0.so", RTLD_LAZY | RTLD_LOCAL); |
|||
if (qtiMapper20Hnd) { |
|||
void* mapper20Hnd = dlopen("android.hardware.graphics.mapper@2.0.so", RTLD_LAZY | RTLD_LOCAL); |
|||
if (mapper20Hnd) { |
|||
Mapper20GetService = reinterpret_cast<decltype(Mapper20GetService)>( |
|||
dlsym(mapper20Hnd, |
|||
"_ZN7android8hardware8graphics6mapper4V2_07IMapper10getServiceERKNSt3__112basic_" |
|||
"stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEb")); |
|||
QtiMapper20CastFrom = reinterpret_cast<decltype(QtiMapper20CastFrom)>(dlsym( |
|||
qtiMapper20Hnd, |
|||
"_ZN6vendor3qti8hardware7display6mapper4V2_010IQtiMapper8castFromERKN7android2spINS6_" |
|||
"8hardware8graphics6mapper4V2_07IMapperEEEb")); |
|||
ALOGD("%s: Mapper 2.0 present", __func__); |
|||
} |
|||
} |
|||
|
|||
void* mapperExtensions11Hnd = |
|||
dlopen("vendor.qti.hardware.display.mapperextensions@1.1.so", RTLD_LAZY | RTLD_LOCAL); |
|||
if (mapperExtensions11Hnd) { |
|||
MapperExtensions11CastFrom = reinterpret_cast<decltype(MapperExtensions11CastFrom)>(dlsym( |
|||
mapperExtensions11Hnd, |
|||
"_ZN6vendor3qti8hardware7display16mapperextensions4V1_" |
|||
"120IQtiMapperExtensions8castFromERKN7android2spINS3_4V1_020IQtiMapperExtensionsEEEb")); |
|||
ALOGD("%s: Mapper Extensions 1.1 present", __func__); |
|||
} |
|||
} |
|||
|
|||
namespace android::hardware::graphics::mapper { |
|||
namespace V2_0 { |
|||
|
|||
sp<IMapper> IMapper::getService(const std::string& serviceName, const bool getStub) { |
|||
if (Mapper20GetService) return Mapper20GetService(serviceName, getStub); |
|||
return nullptr; |
|||
} |
|||
|
|||
} // namespace V2_0
|
|||
namespace V3_0 { |
|||
|
|||
sp<IMapper> IMapper::getService(const std::string& serviceName, const bool getStub) { |
|||
if (Mapper30GetService) return Mapper30GetService(serviceName, getStub); |
|||
return nullptr; |
|||
} |
|||
|
|||
} // namespace V3_0
|
|||
namespace V4_0 { |
|||
|
|||
sp<IMapper> IMapper::getService(const std::string& serviceName, const bool getStub) { |
|||
if (Mapper40GetService) return Mapper40GetService(serviceName, getStub); |
|||
return nullptr; |
|||
} |
|||
|
|||
} // namespace V4_0
|
|||
} // namespace android::hardware::graphics::mapper
|
|||
namespace vendor::qti::hardware::display { |
|||
namespace mapper { |
|||
namespace V4_0 { |
|||
|
|||
Return<sp<IQtiMapper>> IQtiMapper::castFrom(const sp<graphics::mapper::V4_0::IMapper>& parent, |
|||
bool emitError) { |
|||
if (QtiMapper40CastFrom) return QtiMapper40CastFrom(parent, emitError); |
|||
return nullptr; |
|||
} |
|||
|
|||
} // namespace V4_0
|
|||
namespace V3_0 { |
|||
|
|||
Return<sp<IQtiMapper>> IQtiMapper::castFrom(const sp<graphics::mapper::V3_0::IMapper>& parent, |
|||
bool emitError) { |
|||
if (QtiMapper30CastFrom) return QtiMapper30CastFrom(parent, emitError); |
|||
return nullptr; |
|||
} |
|||
|
|||
} // namespace V3_0
|
|||
namespace V2_0 { |
|||
|
|||
Return<sp<IQtiMapper>> IQtiMapper::castFrom(const sp<graphics::mapper::V2_0::IMapper>& parent, |
|||
bool emitError) { |
|||
if (QtiMapper20CastFrom) return QtiMapper20CastFrom(parent, emitError); |
|||
|
|||
return new IQtiMapper(); |
|||
} |
|||
|
|||
Return<void> IQtiMapper::getMapperExtensions(getMapperExtensions_cb _hidl_cb) { |
|||
sp<mapperextensions::V1_0::IQtiMapperExtensions> ext{ |
|||
new mapperextensions::V1_0::IQtiMapperExtensions()}; |
|||
_hidl_cb(graphics::mapper::V2_0::Error::NONE, ext); |
|||
return Void(); |
|||
} |
|||
|
|||
} // namespace V2_0
|
|||
} // namespace mapper
|
|||
namespace mapperextensions { |
|||
namespace V1_1 { |
|||
|
|||
IQtiMapperExtensions::IQtiMapperExtensions() { |
|||
ALOGI("IQtiMapperExtensions shim active"); |
|||
|
|||
hw_module_t const* module; |
|||
if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module)) { |
|||
ALOGE("Failed to open gralloc module!"); |
|||
std::terminate(); |
|||
} |
|||
|
|||
if (gralloc1_open(module, &gralloc)) { |
|||
ALOGE("Failed to open gralloc HAL!"); |
|||
std::terminate(); |
|||
} |
|||
|
|||
perform = reinterpret_cast<GRALLOC1_PFN_PERFORM>( |
|||
gralloc->getFunction(gralloc, GRALLOC1_FUNCTION_PERFORM)); |
|||
if (!perform) { |
|||
ALOGE("Failed to get gralloc perform helper!"); |
|||
std::terminate(); |
|||
} |
|||
|
|||
ALOGD("Opened gralloc1 HAL"); |
|||
} |
|||
|
|||
Return<sp<IQtiMapperExtensions>> IQtiMapperExtensions::castFrom( |
|||
android::sp<V1_0::IQtiMapperExtensions> const& parent, bool emitError) { |
|||
if (MapperExtensions11CastFrom) return MapperExtensions11CastFrom(parent, emitError); |
|||
return new IQtiMapperExtensions(); |
|||
} |
|||
|
|||
Return<void> IQtiMapperExtensions::getRgbDataAddress(void* buffer, getRgbDataAddress_cb _hidl_cb) { |
|||
void* rgb_data = nullptr; |
|||
|
|||
auto err = perform(gralloc, GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS, buffer, &rgb_data) |
|||
? Error::BAD_BUFFER |
|||
: Error::NONE; |
|||
_hidl_cb(err, rgb_data); |
|||
|
|||
ALOGV("%s: err: %d rgb_data: %p", __func__, err, rgb_data); |
|||
return Void(); |
|||
} |
|||
|
|||
Return<void> IQtiMapperExtensions::getInterlacedFlag(void* buffer, getInterlacedFlag_cb _hidl_cb) { |
|||
int flag = 0; |
|||
auto perform = reinterpret_cast<GRALLOC1_PFN_PERFORM>( |
|||
gralloc->getFunction(gralloc, GRALLOC1_FUNCTION_PERFORM)); |
|||
auto err = perform(gralloc, GRALLOC1_MODULE_PERFORM_GET_INTERLACE_FLAG, buffer, &flag) |
|||
? Error::BAD_BUFFER |
|||
: Error::NONE; |
|||
_hidl_cb(err, flag); |
|||
ALOGV("%s: err: %d flag: %d", __func__, err, flag); |
|||
return Void(); |
|||
} |
|||
Return<void> IQtiMapperExtensions::getFd(void* buffer, getFd_cb hidl_cb) { |
|||
auto err = Error::BAD_BUFFER; |
|||
int fd = 0; |
|||
auto hnd = static_cast<private_handle_t*>(buffer); |
|||
if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { |
|||
err = Error::NONE; |
|||
fd = hnd->fd; |
|||
} |
|||
hidl_cb(err, fd); |
|||
ALOGV("%s: fd: %d", __func__, fd); |
|||
return Void(); |
|||
} |
|||
|
|||
Return<void> IQtiMapperExtensions::getWidth(void* buffer, getWidth_cb hidl_cb) { |
|||
auto err = Error::BAD_BUFFER; |
|||
int width = 0; |
|||
auto hnd = static_cast<private_handle_t*>(buffer); |
|||
if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { |
|||
err = Error::NONE; |
|||
width = hnd->width; |
|||
} |
|||
hidl_cb(err, width); |
|||
ALOGV("%s: width: %d", __func__, width); |
|||
return Void(); |
|||
} |
|||
|
|||
Return<void> IQtiMapperExtensions::getHeight(void* buffer, getHeight_cb hidl_cb) { |
|||
auto err = Error::BAD_BUFFER; |
|||
int height = 0; |
|||
auto hnd = static_cast<private_handle_t*>(buffer); |
|||
if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { |
|||
err = Error::NONE; |
|||
height = hnd->height; |
|||
} |
|||
hidl_cb(err, height); |
|||
ALOGV("%s: height: %d", __func__, height); |
|||
return Void(); |
|||
} |
|||
|
|||
Return<void> IQtiMapperExtensions::getFormat(void* buffer, getFormat_cb hidl_cb) { |
|||
auto err = Error::BAD_BUFFER; |
|||
int format = 0; |
|||
auto hnd = static_cast<private_handle_t*>(buffer); |
|||
if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { |
|||
err = Error::NONE; |
|||
format = hnd->format; |
|||
} |
|||
hidl_cb(err, format); |
|||
|
|||
ALOGV("%s: format: %d", __func__, format); |
|||
return Void(); |
|||
} |
|||
|
|||
Return<void> IQtiMapperExtensions::getPrivateFlags(void* buffer, getPrivateFlags_cb hidl_cb) { |
|||
auto err = Error::BAD_BUFFER; |
|||
int flags = 0; |
|||
auto hnd = static_cast<private_handle_t*>(buffer); |
|||
if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { |
|||
err = Error::NONE; |
|||
flags = hnd->flags; |
|||
} |
|||
hidl_cb(err, flags); |
|||
ALOGV("%s: flags: %d", __func__, flags); |
|||
return Void(); |
|||
} |
|||
|
|||
Return<void> IQtiMapperExtensions::getUnalignedWidth(void* buffer, getUnalignedWidth_cb hidl_cb) { |
|||
auto err = Error::BAD_BUFFER; |
|||
int unaligned_width = 0; |
|||
auto hnd = static_cast<private_handle_t*>(buffer); |
|||
if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { |
|||
err = Error::NONE; |
|||
unaligned_width = hnd->unaligned_width; |
|||
} |
|||
hidl_cb(err, unaligned_width); |
|||
|
|||
ALOGV("%s: unaligned_width: %u", __func__, unaligned_width); |
|||
return Void(); |
|||
} |
|||
|
|||
Return<void> IQtiMapperExtensions::getUnalignedHeight(void* buffer, getUnalignedHeight_cb hidl_cb) { |
|||
auto err = Error::BAD_BUFFER; |
|||
int unaligned_height = 0; |
|||
auto hnd = static_cast<private_handle_t*>(buffer); |
|||
if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { |
|||
err = Error::NONE; |
|||
unaligned_height = hnd->unaligned_height; |
|||
} |
|||
hidl_cb(err, unaligned_height); |
|||
ALOGV("%s: unaligned_height: %u", __func__, unaligned_height); |
|||
return Void(); |
|||
} |
|||
|
|||
Return<void> IQtiMapperExtensions::getLayerCount(void* buffer, getLayerCount_cb hidl_cb) { |
|||
auto err = Error::BAD_BUFFER; |
|||
unsigned int layer_count = 0; |
|||
auto hnd = static_cast<private_handle_t*>(buffer); |
|||
if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { |
|||
err = Error::NONE; |
|||
layer_count = hnd->layer_count; |
|||
} |
|||
hidl_cb(err, layer_count); |
|||
ALOGV("%s: layer_count: %u", __func__, layer_count); |
|||
return Void(); |
|||
} |
|||
|
|||
Return<void> IQtiMapperExtensions::getId(void* buffer, getId_cb hidl_cb) { |
|||
auto err = Error::BAD_BUFFER; |
|||
uint64_t id = 0; |
|||
auto hnd = static_cast<private_handle_t*>(buffer); |
|||
if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { |
|||
err = Error::NONE; |
|||
id = hnd->id; |
|||
} |
|||
hidl_cb(err, id); |
|||
ALOGV("%s: id: %" PRIu64, __func__, id); |
|||
return Void(); |
|||
} |
|||
|
|||
Return<void> IQtiMapperExtensions::getUsageFlags(void* buffer, getUsageFlags_cb hidl_cb) { |
|||
auto err = Error::BAD_BUFFER; |
|||
uint64_t usage = 0; |
|||
auto hnd = static_cast<private_handle_t*>(buffer); |
|||
if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { |
|||
err = Error::NONE; |
|||
usage = hnd->usage; |
|||
} |
|||
hidl_cb(err, usage); |
|||
ALOGV("%s: usage: %" PRIu64, __func__, usage); |
|||
|
|||
return Void(); |
|||
} |
|||
|
|||
Return<void> IQtiMapperExtensions::getSize(void* buffer, getSize_cb hidl_cb) { |
|||
auto err = Error::BAD_BUFFER; |
|||
unsigned int size = 0; |
|||
auto hnd = static_cast<private_handle_t*>(buffer); |
|||
if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { |
|||
err = Error::NONE; |
|||
size = hnd->size; |
|||
} |
|||
hidl_cb(err, size); |
|||
ALOGV("%s: size: %u", __func__, size); |
|||
return Void(); |
|||
} |
|||
|
|||
Return<void> IQtiMapperExtensions::getOffset(void* buffer, getOffset_cb hidl_cb) { |
|||
auto err = Error::BAD_BUFFER; |
|||
unsigned int offset = 0; |
|||
auto hnd = static_cast<private_handle_t*>(buffer); |
|||
if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { |
|||
err = Error::NONE; |
|||
offset = hnd->offset; |
|||
} |
|||
hidl_cb(err, offset); |
|||
ALOGV("%s: offset: %u", __func__, offset); |
|||
return Void(); |
|||
} |
|||
|
|||
Return<void> IQtiMapperExtensions::getFormatLayout(int32_t format, uint64_t usage, int32_t flags, |
|||
int32_t width, int32_t height, |
|||
getFormatLayout_cb _hidl_cb) { |
|||
hidl_vec<PlaneLayout> plane_info; |
|||
unsigned int alignedw = 0, alignedh = 0, tile_enabled = 0; |
|||
int plane_count = 0; |
|||
uint64_t size = 0; |
|||
int custom_format = gralloc::GetImplDefinedFormat(usage, format); |
|||
gralloc::BufferInfo info(width, height, custom_format, usage); |
|||
|
|||
auto err = perform(gralloc, GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES, width, height, custom_format, |
|||
usage, usage, &alignedw, &alignedh, &tile_enabled) |
|||
? Error::BAD_BUFFER |
|||
: Error::NONE; |
|||
if (err != Error::NONE) { |
|||
_hidl_cb(err, 0, plane_info); |
|||
return Void(); |
|||
} |
|||
|
|||
size = gralloc::GetSize(info, alignedw, alignedh); |
|||
gralloc::PlaneLayoutInfo plane_layout[8] = {}; |
|||
|
|||
if (gralloc::IsUncompressedRGBFormat(custom_format) || |
|||
gralloc::IsCompressedRGBFormat(custom_format)) { |
|||
gralloc::GetRGBPlaneInfo(info, custom_format, alignedw, alignedh, flags, &plane_count, |
|||
plane_layout); |
|||
} else { |
|||
ALOGE("%s: unsupported format %d", __func__, format); |
|||
err = Error::BAD_BUFFER; |
|||
_hidl_cb(err, size, plane_info); |
|||
return Void(); |
|||
} |
|||
|
|||
plane_info.resize(plane_count); |
|||
for (int i = 0; i < plane_count; i++) { |
|||
plane_info[i].component = plane_layout[i].component; |
|||
plane_info[i].h_subsampling = plane_layout[i].h_subsampling; |
|||
plane_info[i].v_subsampling = plane_layout[i].v_subsampling; |
|||
plane_info[i].offset = plane_layout[i].offset; |
|||
plane_info[i].pixel_increment = plane_layout[i].step; |
|||
plane_info[i].stride = plane_layout[i].stride; |
|||
plane_info[i].stride_bytes = plane_layout[i].stride_bytes; |
|||
plane_info[i].scanlines = plane_layout[i].scanlines; |
|||
plane_info[i].size = plane_layout[i].size; |
|||
} |
|||
|
|||
_hidl_cb(err, size, plane_info); |
|||
return Void(); |
|||
} |
|||
|
|||
} // namespace V1_1
|
|||
} // namespace mapperextensions
|
|||
} // namespace vendor::qti::hardware::display
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue