You've already forked libmali-rockchip
mirror of
https://github.com/armbian/libmali-rockchip.git
synced 2026-01-06 12:03:41 -08:00
Merge branch 'libmali' of github.com:JeffyCN/mirrors
This commit is contained in:
131
hook/hook.c
131
hook/hook.c
@@ -60,20 +60,57 @@ int mali_injected = 0;
|
||||
/* Override libmali symbols */
|
||||
|
||||
#ifdef HAS_GBM
|
||||
#ifndef HAS_gbm_bo_map
|
||||
static int (* _gbm_device_get_fd)(struct gbm_device *gbm) = NULL;
|
||||
#endif
|
||||
static struct gbm_surface * (* _gbm_surface_create)(struct gbm_device *, uint32_t, uint32_t, uint32_t, uint32_t) = NULL;
|
||||
static struct gbm_bo * (* _gbm_bo_create) (struct gbm_device *, uint32_t, uint32_t, uint32_t, uint32_t) = NULL;
|
||||
#ifdef HAS_gbm_surface_create_with_modifiers
|
||||
static struct gbm_surface *(* _gbm_surface_create_with_modifiers) (struct gbm_device *gbm, uint32_t width, uint32_t height, uint32_t format, const uint64_t *modifiers, const unsigned int count);
|
||||
#endif
|
||||
static struct gbm_bo * (* _gbm_bo_create)(struct gbm_device *, uint32_t, uint32_t, uint32_t, uint32_t) = NULL;
|
||||
#ifdef HAS_gbm_bo_create_with_modifiers
|
||||
static struct gbm_bo * (* _gbm_bo_create_with_modifiers)(struct gbm_device *gbm, uint32_t width, uint32_t height, uint32_t format, const uint64_t *modifiers, const unsigned int count) = NULL;
|
||||
#endif
|
||||
#ifdef HAS_gbm_bo_get_modifier
|
||||
static uint64_t (* _gbm_bo_get_modifier) (struct gbm_bo *bo) = NULL;
|
||||
static uint64_t (* _gbm_bo_get_modifier)(struct gbm_bo *bo) = NULL;
|
||||
#endif
|
||||
#ifndef HAS_gbm_bo_map
|
||||
static uint32_t (* _gbm_bo_get_width)(struct gbm_bo *bo) = NULL;
|
||||
#endif
|
||||
#if !defined(HAS_gbm_bo_map) || !defined(HAS_gbm_bo_unmap)
|
||||
static uint32_t (* _gbm_bo_get_height)(struct gbm_bo *bo) = NULL;
|
||||
#endif
|
||||
#if !defined(HAS_gbm_bo_map) || !defined(HAS_gbm_bo_unmap) || \
|
||||
!defined(HAS_gbm_bo_get_stride_for_plane)
|
||||
static uint32_t (* _gbm_bo_get_stride)(struct gbm_bo *bo) = NULL;
|
||||
#endif
|
||||
#ifndef HAS_gbm_bo_get_bpp
|
||||
static uint32_t (* _gbm_bo_get_format)(struct gbm_bo *bo) = NULL;
|
||||
#endif
|
||||
#ifndef HAS_gbm_bo_map
|
||||
static uint32_t (* _gbm_bo_get_bpp)(struct gbm_bo *bo) = NULL;
|
||||
static struct gbm_device * (* _gbm_bo_get_device)(struct gbm_bo *bo) = NULL;
|
||||
#endif
|
||||
#if !defined(HAS_gbm_bo_map) || !defined(HAS_gbm_bo_get_handle_for_plane)
|
||||
static union gbm_bo_handle (* _gbm_bo_get_handle)(struct gbm_bo *bo) = NULL;
|
||||
#endif
|
||||
#ifndef HAS_gbm_bo_get_fd_for_plane
|
||||
static int (* _gbm_bo_get_fd)(struct gbm_bo *bo) = NULL;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAS_EGL
|
||||
static PFNEGLGETCURRENTSURFACEPROC _eglGetCurrentSurface = NULL;
|
||||
static PFNEGLGETDISPLAYPROC _eglGetDisplay = NULL;
|
||||
static PFNEGLGETPROCADDRESSPROC _eglGetProcAddress = NULL;
|
||||
static PFNEGLGETPLATFORMDISPLAYPROC _eglGetPlatformDisplay = NULL;
|
||||
#ifdef HAS_X11
|
||||
static PFNEGLGETPLATFORMDISPLAYEXTPROC _eglGetPlatformDisplayEXT = NULL;
|
||||
#endif
|
||||
static PFNEGLCREATEPIXMAPSURFACEPROC _eglCreatePixmapSurface = NULL;
|
||||
static PFNEGLCREATEWINDOWSURFACEPROC _eglCreateWindowSurface = NULL;
|
||||
static EGLBoolean (* _eglDestroySurface)(EGLDisplay dpy, EGLSurface surface) = NULL;
|
||||
static PFNEGLMAKECURRENTPROC _eglMakeCurrent = NULL;
|
||||
#endif
|
||||
|
||||
#define MALI_SYMBOL(func) { #func, (void **)(&_ ## func), }
|
||||
@@ -82,15 +119,52 @@ static struct {
|
||||
void **symbol;
|
||||
} mali_symbols[] = {
|
||||
#ifdef HAS_GBM
|
||||
#ifndef HAS_gbm_bo_map
|
||||
MALI_SYMBOL(gbm_device_get_fd),
|
||||
#endif
|
||||
MALI_SYMBOL(gbm_surface_create),
|
||||
#ifdef HAS_gbm_surface_create_with_modifiers
|
||||
MALI_SYMBOL(gbm_surface_create_with_modifiers),
|
||||
#endif
|
||||
MALI_SYMBOL(gbm_bo_create),
|
||||
#ifdef HAS_gbm_bo_create_with_modifiers
|
||||
MALI_SYMBOL(gbm_bo_create_with_modifiers),
|
||||
#endif
|
||||
#ifdef HAS_gbm_bo_get_modifier
|
||||
MALI_SYMBOL(gbm_bo_get_modifier),
|
||||
#endif
|
||||
#ifndef HAS_gbm_bo_map
|
||||
MALI_SYMBOL(gbm_bo_get_width),
|
||||
#endif
|
||||
#if !defined(HAS_gbm_bo_map) || !defined(HAS_gbm_bo_unmap)
|
||||
MALI_SYMBOL(gbm_bo_get_height),
|
||||
#endif
|
||||
#if !defined(HAS_gbm_bo_map) || !defined(HAS_gbm_bo_unmap) || \
|
||||
!defined(HAS_gbm_bo_get_stride_for_plane)
|
||||
MALI_SYMBOL(gbm_bo_get_stride),
|
||||
#endif
|
||||
#ifndef HAS_gbm_bo_get_bpp
|
||||
MALI_SYMBOL(gbm_bo_get_format),
|
||||
#endif
|
||||
#ifndef HAS_gbm_bo_map
|
||||
MALI_SYMBOL(gbm_bo_get_bpp),
|
||||
MALI_SYMBOL(gbm_bo_get_device),
|
||||
#endif
|
||||
#if !defined(HAS_gbm_bo_map) || !defined(HAS_gbm_bo_get_handle_for_plane)
|
||||
MALI_SYMBOL(gbm_bo_get_handle),
|
||||
#endif
|
||||
#ifndef HAS_gbm_bo_get_fd_for_plane
|
||||
MALI_SYMBOL(gbm_bo_get_fd),
|
||||
#endif
|
||||
#endif
|
||||
#ifdef HAS_EGL
|
||||
MALI_SYMBOL(eglGetCurrentSurface),
|
||||
MALI_SYMBOL(eglGetDisplay),
|
||||
MALI_SYMBOL(eglGetProcAddress),
|
||||
MALI_SYMBOL(eglCreatePixmapSurface),
|
||||
MALI_SYMBOL(eglCreateWindowSurface),
|
||||
MALI_SYMBOL(eglDestroySurface),
|
||||
MALI_SYMBOL(eglMakeCurrent),
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -178,7 +252,7 @@ gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane)
|
||||
if (plane)
|
||||
return 0;
|
||||
|
||||
return gbm_bo_get_stride(bo);
|
||||
return _gbm_bo_get_stride(bo);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -189,7 +263,7 @@ gbm_bo_get_fd_for_plane(struct gbm_bo *bo, int plane)
|
||||
if (plane)
|
||||
return -1;
|
||||
|
||||
return gbm_bo_get_fd(bo);
|
||||
return _gbm_bo_get_fd(bo);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -203,7 +277,7 @@ gbm_bo_get_handle_for_plane(struct gbm_bo *bo, int plane)
|
||||
if (plane)
|
||||
return ret;
|
||||
|
||||
return gbm_bo_get_handle(bo);
|
||||
return _gbm_bo_get_handle(bo);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -228,8 +302,8 @@ gbm_bo_create_with_modifiers2(struct gbm_device *gbm,
|
||||
{
|
||||
#ifdef HAS_gbm_bo_create_with_modifiers
|
||||
/* flags ignored */
|
||||
return gbm_bo_create_with_modifiers(gbm, width, height, format,
|
||||
modifiers, count);
|
||||
return _gbm_bo_create_with_modifiers(gbm, width, height, format,
|
||||
modifiers, count);
|
||||
#else
|
||||
if (!can_ignore_modifiers(modifiers, count))
|
||||
return NULL;
|
||||
@@ -263,8 +337,8 @@ gbm_surface_create_with_modifiers2(struct gbm_device *gbm,
|
||||
{
|
||||
#ifdef HAS_gbm_surface_create_with_modifiers
|
||||
/* flags ignored */
|
||||
return gbm_surface_create_with_modifiers(gbm, width, height, format,
|
||||
modifiers, count);
|
||||
return _gbm_surface_create_with_modifiers(gbm, width, height, format,
|
||||
modifiers, count);
|
||||
#else
|
||||
if (!can_ignore_modifiers(modifiers, count))
|
||||
return NULL;
|
||||
@@ -299,27 +373,27 @@ gbm_bo_map(struct gbm_bo *bo,
|
||||
void *map;
|
||||
int fd, ret;
|
||||
|
||||
if (!bo || !map_data || width <= 0 || width > gbm_bo_get_width(bo) ||
|
||||
height <= 0 || height > gbm_bo_get_height(bo)) {
|
||||
if (!bo || !map_data || width <= 0 || width > _gbm_bo_get_width(bo) ||
|
||||
height <= 0 || height > _gbm_bo_get_height(bo)) {
|
||||
errno = EINVAL;
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
gbm_dev = gbm_bo_get_device(bo);
|
||||
gbm_dev = _gbm_bo_get_device(bo);
|
||||
if (!gbm_dev)
|
||||
return MAP_FAILED;
|
||||
|
||||
fd = gbm_device_get_fd(gbm_dev);
|
||||
fd = _gbm_device_get_fd(gbm_dev);
|
||||
if (fd < 0)
|
||||
return MAP_FAILED;
|
||||
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
arg.handle = gbm_bo_get_handle(bo).u32;
|
||||
arg.handle = _gbm_bo_get_handle(bo).u32;
|
||||
ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &arg);
|
||||
if (ret)
|
||||
return MAP_FAILED;
|
||||
|
||||
map = mmap(NULL, gbm_bo_get_stride(bo) * gbm_bo_get_height(bo),
|
||||
map = mmap(NULL, _gbm_bo_get_stride(bo) * _gbm_bo_get_height(bo),
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, fd, arg.offset);
|
||||
if (map == MAP_FAILED)
|
||||
return map;
|
||||
@@ -327,9 +401,9 @@ gbm_bo_map(struct gbm_bo *bo,
|
||||
*map_data = map;
|
||||
|
||||
if (stride)
|
||||
*stride = gbm_bo_get_stride(bo);
|
||||
*stride = _gbm_bo_get_stride(bo);
|
||||
|
||||
return map + y * gbm_bo_get_stride(bo) + x * (gbm_bo_get_bpp(bo) >> 3);
|
||||
return map + y * _gbm_bo_get_stride(bo) + x * (_gbm_bo_get_bpp(bo) >> 3);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -338,7 +412,7 @@ void
|
||||
gbm_bo_unmap(struct gbm_bo *bo, void *map_data)
|
||||
{
|
||||
if (map_data)
|
||||
munmap(map_data, gbm_bo_get_stride(bo) * gbm_bo_get_height(bo));
|
||||
munmap(map_data, _gbm_bo_get_stride(bo) * _gbm_bo_get_height(bo));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -347,7 +421,7 @@ gbm_bo_unmap(struct gbm_bo *bo, void *map_data)
|
||||
uint32_t
|
||||
gbm_bo_get_bpp(struct gbm_bo *bo)
|
||||
{
|
||||
switch (gbm_bo_get_format(bo)) {
|
||||
switch (_gbm_bo_get_format(bo)) {
|
||||
default:
|
||||
return 0;
|
||||
case GBM_FORMAT_C8:
|
||||
@@ -586,6 +660,9 @@ eglGetProcAddress(const char *procname)
|
||||
return (__eglMustCastToProperFunctionPointerType)eglGetPlatformDisplayEXT;
|
||||
}
|
||||
|
||||
if (!strcmp(procname, "eglDestroySurface"))
|
||||
return (__eglMustCastToProperFunctionPointerType)eglDestroySurface;
|
||||
|
||||
return _eglGetProcAddress(procname);
|
||||
}
|
||||
|
||||
@@ -616,7 +693,7 @@ eglGetDisplay (EGLNativeDisplayType display_id)
|
||||
|
||||
/* Export for EGL 1.5 */
|
||||
|
||||
#define GET_PROC_ADDR(v, n) v = (typeof(v))eglGetProcAddress(n)
|
||||
#define GET_PROC_ADDR(v, n) v = (typeof(v))_eglGetProcAddress(n)
|
||||
|
||||
/* From mesa3d mesa-23.1.3-1 : src/egl/main/egldisplay.h */
|
||||
static inline size_t
|
||||
@@ -692,7 +769,7 @@ eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config, void *native_wi
|
||||
EGLint *int_attribs = _eglConvertAttribsToInt(attrib_list);
|
||||
if (!int_attribs == !attrib_list) {
|
||||
EGLSurface surface =
|
||||
eglCreateWindowSurface(dpy, config, native_window, int_attribs);
|
||||
_eglCreateWindowSurface(dpy, config, native_window, int_attribs);
|
||||
free(int_attribs);
|
||||
return surface;
|
||||
}
|
||||
@@ -712,7 +789,7 @@ eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config, void *native_pi
|
||||
EGLint *int_attribs = _eglConvertAttribsToInt(attrib_list);
|
||||
if (!int_attribs == !attrib_list) {
|
||||
EGLSurface surface =
|
||||
eglCreatePixmapSurface(dpy, config, native_pixmap, int_attribs);
|
||||
_eglCreatePixmapSurface(dpy, config, native_pixmap, int_attribs);
|
||||
free(int_attribs);
|
||||
return surface;
|
||||
}
|
||||
@@ -721,4 +798,14 @@ eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config, void *native_pi
|
||||
return create_platform_pixmap_surface(dpy, config, native_pixmap, attrib_list);
|
||||
}
|
||||
|
||||
/* Unset current surface before destroying it */
|
||||
EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
|
||||
{
|
||||
if (_eglGetCurrentSurface(EGL_DRAW) == surface ||
|
||||
_eglGetCurrentSurface(EGL_READ) == surface)
|
||||
_eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
|
||||
return _eglDestroySurface(dpy, surface);
|
||||
}
|
||||
|
||||
#endif // HAS_EGL
|
||||
|
||||
@@ -21,10 +21,11 @@ libhook_cflags = [
|
||||
'-DLIBMALI_SO="libmali.so.' + mali_version.split('.')[0] + '"',
|
||||
]
|
||||
|
||||
libhook_dep = [mali]
|
||||
libhook_dep += dependency('threads')
|
||||
libhook_dep += cc.find_library('dl', required : false)
|
||||
libhook_dep += dependency('libdrm', version : '>= 2.4.0')
|
||||
libhook_dep = [
|
||||
dependency('threads'),
|
||||
cc.find_library('dl', required : false),
|
||||
dependency('libdrm', version : '>= 2.4.0'),
|
||||
]
|
||||
|
||||
libhook_inc = []
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user