Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Monado
Monado
Commits
86d93601
Commit
86d93601
authored
Jul 07, 2020
by
Ryan Pavlik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ipc: Work on Android using AHardwareBuffer instead of FDs for graphics
parent
030e5564
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
0 deletions
+65
-0
src/xrt/include/xrt/xrt_handles.h
src/xrt/include/xrt/xrt_handles.h
+9
-0
src/xrt/ipc/ipc_utils.c
src/xrt/ipc/ipc_utils.c
+56
-0
No files found.
src/xrt/include/xrt/xrt_handles.h
View file @
86d93601
...
...
@@ -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
}
...
...
src/xrt/ipc/ipc_utils.c
View file @
86d93601
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment