c/main: Tidy comp_android_window

This commit is contained in:
Jakob Bornecrantz 2020-11-09 00:48:36 +00:00
parent f4c1ebe90c
commit ea723240e3

View file

@ -9,19 +9,23 @@
* @ingroup comp_main
*/
#include <errno.h>
#include <linux/input.h>
#include <poll.h>
#include <stdlib.h>
#include <string.h>
#include "xrt/xrt_compiler.h"
#include "main/comp_window.h"
#include "util/u_misc.h"
#include "android/android_globals.h"
#include "android/android_custom_surface.h"
#include "main/comp_window.h"
#include <android/native_window.h>
#include <poll.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <linux/input.h>
/*
*
@ -41,6 +45,7 @@ struct comp_window_android
struct android_custom_surface *custom_surface;
};
/*
*
* Functions.
@ -81,39 +86,44 @@ comp_window_android_update_window_title(struct comp_target *ct,
}
static VkResult
comp_window_android_create_surface(struct comp_window_android *w,
comp_window_android_create_surface(struct comp_window_android *cwa,
VkSurfaceKHR *vk_surface)
{
struct vk_bundle *vk = get_vk(w);
struct vk_bundle *vk = get_vk(cwa);
VkResult ret;
w->custom_surface = android_custom_surface_async_start(
cwa->custom_surface = android_custom_surface_async_start(
android_globals_get_vm(), android_globals_get_activity());
if (w->custom_surface == NULL) {
if (cwa->custom_surface == NULL) {
COMP_ERROR(
w->base.base.c,
cwa->base.base.c,
"comp_window_android_create_surface: could not "
"start asynchronous attachment of our custom surface");
return VK_ERROR_INITIALIZATION_FAILED;
}
struct ANativeWindow *window =
android_custom_surface_wait_get_surface(w->custom_surface, 2000);
android_custom_surface_wait_get_surface(cwa->custom_surface, 2000);
if (window == NULL) {
COMP_ERROR(w->base.base.c,
COMP_ERROR(cwa->base.base.c,
"comp_window_android_create_surface: could not "
"convert surface to ANativeWindow");
return VK_ERROR_INITIALIZATION_FAILED;
}
VkAndroidSurfaceCreateInfoKHR surface_info = {
.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR,
.flags = 0,
.window = window,
};
ret = vk->vkCreateAndroidSurfaceKHR(vk->instance, &surface_info, NULL,
vk_surface);
ret = vk->vkCreateAndroidSurfaceKHR( //
vk->instance, //
&surface_info, //
NULL, //
vk_surface); //
if (ret != VK_SUCCESS) {
COMP_ERROR(w->base.base.c, "vkCreateAndroidSurfaceKHR: %s",
COMP_ERROR(cwa->base.base.c, "vkCreateAndroidSurfaceKHR: %s",
vk_result_string(ret));
return ret;
}
@ -126,22 +136,20 @@ comp_window_android_init_swapchain(struct comp_target *ct,
uint32_t width,
uint32_t height)
{
struct comp_window_android *w_android =
(struct comp_window_android *)ct;
struct comp_window_android *cwa = (struct comp_window_android *)ct;
VkResult ret;
ret = comp_window_android_create_surface( //
w_android, //
&w_android->base.surface.handle); //
ret =
comp_window_android_create_surface(cwa, &cwa->base.surface.handle);
if (ret != VK_SUCCESS) {
COMP_ERROR(ct->c, "Failed to create surface!");
COMP_ERROR(ct->c, "Failed to create surface '%s'!",
vk_result_string(ret));
return false;
}
return true;
}
static void
comp_window_android_flush(struct comp_target *ct)
{