-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
addpkg(main/termux-wsi-layer): 0.0.1
- Loading branch information
Showing
10 changed files
with
2,313 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"file_format_version": "1.0.0", | ||
"ICD": { | ||
"library_path": "termux-wsi-layer.so" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cmake_minimum_required(VERSION 3.29) | ||
project(termux-wsi-layer C) | ||
|
||
set(CMAKE_BUILD_TYPE Debug) | ||
set(CMAKE_C_STANDARD 11) | ||
find_package(PkgConfig REQUIRED) | ||
pkg_check_modules(X11 REQUIRED x11 x11-xcb xcb xcb-dri3 xcb-present) | ||
|
||
add_library(termux-wsi-layer SHARED egl.c window.c sync.c) | ||
set_target_properties(termux-wsi-layer PROPERTIES PREFIX "") | ||
target_include_directories(termux-wsi-layer PRIVATE include) | ||
target_compile_options(termux-wsi-layer PRIVATE ${X11_CFLAGS}) | ||
target_link_options(termux-wsi-layer PRIVATE -Wl,--no-as-needed -landroid -Wl,--as-needed -ggdb ${X11_LDFLAGS}) | ||
|
||
add_executable(test test.c) | ||
target_link_options(test PRIVATE -lEGL -lGLESv2 -lX11 -lm) | ||
|
||
install(TARGETS termux-wsi-layer LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) | ||
install(FILES 10_termux.json DESTINATION ${CMAKE_INSTALL_PREFIX}/share/glvnd/egl_vendor.d) | ||
add_custom_target(uninstall) | ||
add_custom_command(TARGET uninstall POST_BUILD COMMAND rm ARGS -v -f | ||
${CMAKE_INSTALL_PREFIX}/share/glvnd/egl_vendor.d/10_termux.json | ||
${CMAKE_INSTALL_PREFIX}/lib/termux-wsi-layer.so | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
TERMUX_PKG_HOMEPAGE=https://termux.dev | ||
TERMUX_PKG_DESCRIPTION="Termux's ICD/WSI wrapper for using with proprietary Android drivers" | ||
TERMUX_PKG_LICENSE="GPL-3.0" | ||
TERMUX_PKG_MAINTAINER="@termux" | ||
TERMUX_PKG_VERSION="0.0.1" | ||
TERMUX_PKG_SKIP_SRC_EXTRACT=true | ||
TERMUX_PKG_BUILD_DEPENDS="libglvnd, libxcb, libx11" | ||
TERMUX_PKG_NO_STRIP=true | ||
|
||
TERMUX_PKG_SRCDIR="$TERMUX_PREFIX/opt/termux-wsi-layer/src" | ||
|
||
termux_step_pre_configure() { | ||
mkdir -p "$TERMUX_PREFIX/opt/termux-wsi-layer/src" | ||
cp -r "${TERMUX_PKG_BUILDER_DIR}/"{include,*.c,*.h,*.json,CMakeLists.txt} "$TERMUX_PREFIX/opt/termux-wsi-layer/src" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2024 Twaik Yont <[email protected]> | ||
* | ||
* Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* | ||
* 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 | ||
|
||
// Workaround for `error: 'AHardwareBuffer_describe' is unavailable: introduced in Android 26` | ||
// We will explicitly mark these symbols as weak to avoid using `ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK` | ||
// These symbols will equal to NULL in the case if they were not linked and we can check this in __eglMain | ||
#define AHardwareBuffer_allocate _AHardwareBuffer_allocate | ||
#define AHardwareBuffer_release _AHardwareBuffer_release | ||
#define AHardwareBuffer_describe _AHardwareBuffer_describe | ||
#define AHardwareBuffer_sendHandleToUnixSocket _AHardwareBuffer_sendHandleToUnixSocket | ||
#include <android/hardware_buffer.h> | ||
#undef AHardwareBuffer_allocate | ||
#undef AHardwareBuffer_release | ||
#undef AHardwareBuffer_describe | ||
#undef AHardwareBuffer_sendHandleToUnixSocket | ||
|
||
#define WEAK __attribute__((weak)) | ||
int AHardwareBuffer_allocate(const AHardwareBuffer_Desc* _Nonnull desc, AHardwareBuffer* _Nullable* _Nonnull outBuffer) WEAK; | ||
void AHardwareBuffer_release(AHardwareBuffer* _Nonnull buffer) WEAK; | ||
void AHardwareBuffer_describe(const AHardwareBuffer* _Nonnull buffer, AHardwareBuffer_Desc* _Nonnull outDesc) WEAK; | ||
int AHardwareBuffer_sendHandleToUnixSocket(const AHardwareBuffer* _Nonnull buffer, int socketFd) WEAK; | ||
|
||
// We can not link to these functions directly for two reasons | ||
// 1. This API is not exposed to NDK. | ||
// 2. The `libui.so` is explicitly blocklisted for linking. | ||
// So our solution is to declare these symbols as weak and let linker override them. | ||
// We use GraphicBuffer_getNativeBuffer only as fallback in the case if AHardwareBuffer_to_ANativeWindowBuffer is unavailable. | ||
// Both AHardwareBuffer_to_ANativeWindowBuffer and GraphicBuffer_getNativeBuffer are aliases to make code easier to read. | ||
|
||
#define AHardwareBuffer_to_ANativeWindowBuffer _ZN7android38AHardwareBuffer_to_ANativeWindowBufferEP15AHardwareBuffer | ||
#define GraphicBuffer_getNativeBuffer _ZNK7android13GraphicBuffer15getNativeBufferEv | ||
size_t AHardwareBuffer_to_ANativeWindowBuffer(void* _Nullable) WEAK; | ||
size_t GraphicBuffer_getNativeBuffer(void* _Nullable) WEAK; |
Oops, something went wrong.