mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-28 18:46:18 +00:00
ipc: Work on Android using AHardwareBuffer instead of FDs for graphics
This commit is contained in:
parent
030e5564ff
commit
86d93601d7
|
@ -9,6 +9,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "xrt_config_os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -20,6 +22,12 @@ extern "C" {
|
|||
*/
|
||||
typedef int xrt_shmem_handle_t;
|
||||
|
||||
#if defined(XRT_OS_ANDROID)
|
||||
typedef struct AHardwareBuffer AHardwareBuffer;
|
||||
|
||||
typedef AHardwareBuffer *xrt_graphics_buffer_handle_t;
|
||||
#else
|
||||
|
||||
/*!
|
||||
* The type underlying buffers shared between compositor clients and the main
|
||||
* compositor.
|
||||
|
@ -27,6 +35,7 @@ typedef int xrt_shmem_handle_t;
|
|||
* On Linux, this is a file descriptor.
|
||||
*/
|
||||
typedef int xrt_graphics_buffer_handle_t;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -237,6 +237,60 @@ ipc_send_handles_shmem(struct ipc_message_channel *imc,
|
|||
return ipc_send_fds(imc, data, size, handles, num_handles);
|
||||
}
|
||||
|
||||
#if defined(XRT_OS_ANDROID)
|
||||
|
||||
#include <android/hardware_buffer.h>
|
||||
|
||||
#if __ANDROID_API__ < 26
|
||||
#error "Android API level 26 or higher needed for AHardwareBuffer"
|
||||
#endif
|
||||
|
||||
xrt_result_t
|
||||
ipc_receive_handles_graphics_buffer(struct ipc_message_channel *imc,
|
||||
void *out_data,
|
||||
size_t size,
|
||||
xrt_graphics_buffer_handle_t *out_handles,
|
||||
uint32_t num_handles)
|
||||
{
|
||||
xrt_result_t result = ipc_receive(imc, out_data, size);
|
||||
if (result != XRT_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
bool failed = false;
|
||||
for (uint32_t i = 0; i < num_handles; ++i) {
|
||||
int err = AHardwareBuffer_recvHandleFromUnixSocket(
|
||||
imc->socket_fd, &(out_handles[i]));
|
||||
if (err != 0) {
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
return failed ? XRT_ERROR_IPC_FAILURE : XRT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
xrt_result_t
|
||||
ipc_send_handles_graphics_buffer(struct ipc_message_channel *imc,
|
||||
const void *data,
|
||||
size_t size,
|
||||
const xrt_graphics_buffer_handle_t *handles,
|
||||
uint32_t num_handles)
|
||||
{
|
||||
xrt_result_t result = ipc_send(imc, data, size);
|
||||
if (result != XRT_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
bool failed = false;
|
||||
for (uint32_t i = 0; i < num_handles; ++i) {
|
||||
int err = AHardwareBuffer_sendHandleToUnixSocket(
|
||||
handles[i], imc->socket_fd);
|
||||
if (err != 0) {
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
return failed ? XRT_ERROR_IPC_FAILURE : XRT_SUCCESS;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
xrt_result_t
|
||||
ipc_receive_handles_graphics_buffer(struct ipc_message_channel *imc,
|
||||
|
@ -258,3 +312,5 @@ ipc_send_handles_graphics_buffer(struct ipc_message_channel *imc,
|
|||
{
|
||||
return ipc_send_fds(imc, data, size, handles, num_handles);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue