The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

c/window_android: Use cached surface from IPC.

Create window if activity is cached for in process.

+31 -17
+31 -17
src/xrt/compositor/main/comp_window_android.c
··· 85 85 (void)ct; 86 86 } 87 87 88 - static VkResult 89 - comp_window_android_create_surface(struct comp_window_android *cwa, 90 - VkSurfaceKHR *vk_surface) 88 + static struct ANativeWindow * 89 + _create_android_window(struct comp_window_android *cwa) 91 90 { 92 - struct vk_bundle *vk = get_vk(cwa); 93 - VkResult ret; 94 - 95 91 cwa->custom_surface = android_custom_surface_async_start( 96 92 android_globals_get_vm(), android_globals_get_activity()); 97 93 if (cwa->custom_surface == NULL) { ··· 99 95 cwa->base.base.c, 100 96 "comp_window_android_create_surface: could not " 101 97 "start asynchronous attachment of our custom surface"); 102 - return VK_ERROR_INITIALIZATION_FAILED; 98 + return NULL; 103 99 } 104 100 105 - struct ANativeWindow *window = 106 - android_custom_surface_wait_get_surface(cwa->custom_surface, 2000); 107 - if (window == NULL) { 108 - COMP_ERROR(cwa->base.base.c, 109 - "comp_window_android_create_surface: could not " 110 - "convert surface to ANativeWindow"); 111 - return VK_ERROR_INITIALIZATION_FAILED; 112 - } 101 + return android_custom_surface_wait_get_surface(cwa->custom_surface, 102 + 2000); 103 + } 104 + 105 + static VkResult 106 + comp_window_android_create_surface(struct comp_window_android *cwa, 107 + struct ANativeWindow *window, 108 + VkSurfaceKHR *vk_surface) 109 + { 110 + struct vk_bundle *vk = get_vk(cwa); 111 + VkResult ret; 113 112 114 113 VkAndroidSurfaceCreateInfoKHR surface_info = { 115 114 .sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR, ··· 139 138 struct comp_window_android *cwa = (struct comp_window_android *)ct; 140 139 VkResult ret; 141 140 142 - ret = 143 - comp_window_android_create_surface(cwa, &cwa->base.surface.handle); 141 + struct ANativeWindow *window = NULL; 142 + 143 + if (android_globals_get_activity() != NULL) { 144 + /* In process: Creating surface from activity */ 145 + window = _create_android_window(cwa); 146 + } else { 147 + /* Out of process: Getting cached surface */ 148 + window = (struct ANativeWindow *)android_globals_get_window(); 149 + } 150 + 151 + if (window == NULL) { 152 + COMP_ERROR(cwa->base.base.c, "could not get ANativeWindow"); 153 + return false; 154 + } 155 + 156 + ret = comp_window_android_create_surface(cwa, window, 157 + &cwa->base.surface.handle); 144 158 if (ret != VK_SUCCESS) { 145 159 COMP_ERROR(ct->c, "Failed to create surface '%s'!", 146 160 vk_result_string(ret));