1 // Copyright (C) 2020 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 #pragma once 15 16 #ifdef __cplusplus 17 #include <functional> 18 #include <future> 19 #endif 20 21 /* virtio-gpu interface for buffers 22 * (triggered by minigbm/egl calling virtio-gpu ioctls) */ 23 typedef void (*create_buffer_with_handle_t)(uint64_t size, uint32_t handle); 24 25 /* virtio-gpu interface for color buffers 26 * (triggered by minigbm/egl calling virtio-gpu ioctls) */ 27 typedef void (*create_color_buffer_with_handle_t)(uint32_t width, uint32_t height, uint32_t format, 28 uint32_t fwkFormat, uint32_t handle, bool linear); 29 30 /* create YUV textures with given width and height 31 type: FRAMEWORK_FORMAT_NV12 or FRAMEWORK_FORMAT_YUV_420_888 32 count: how many set of textures will be created 33 output: caller allocated storage to hold results: size should 34 be 2*count for NV12 or 3*cout for YUV_420_888 35 */ 36 typedef void (*create_yuv_textures_t)(uint32_t type, 37 uint32_t count, 38 int width, 39 int height, 40 uint32_t* output); 41 42 /* destroy YUV textures */ 43 typedef void (*destroy_yuv_textures_t)(uint32_t type, 44 uint32_t count, 45 uint32_t* textures); 46 /* call the user provided func with privData to update the content 47 of textures. 48 type: FRAMEWORK_FORMAT_NV12 or FRAMEWORK_FORMAT_YUV_420_888 49 textures: size 2 (NV12) or 3 (YUV420) 50 */ 51 typedef void (*update_yuv_textures_t)(uint32_t type, 52 uint32_t* textures, 53 void* privData, 54 void* func); 55 56 /* swap out the yuv textures of the colorbuffer, and use the new yuv textures 57 * to update colorbuffer content; on return, textures will have the retired 58 * yuv textures that are free to hold new data 59 */ 60 typedef void (*swap_textures_and_update_color_buffer_t)( 61 uint32_t colorbufferhandle, 62 int x, 63 int y, 64 int width, 65 int height, 66 uint32_t format, 67 uint32_t type, 68 uint32_t texture_type, 69 uint32_t* textures, 70 void* metadata); 71 72 typedef void (*open_color_buffer_t)(uint32_t handle); 73 typedef void (*close_buffer_t)(uint32_t handle); 74 typedef void (*close_color_buffer_t)(uint32_t handle); 75 typedef void (*update_buffer_t)(uint32_t handle, uint64_t offset, uint64_t sizeToRead, void* bytes); 76 typedef void (*update_color_buffer_t)( 77 uint32_t handle, int x, int y, int width, int height, 78 uint32_t format, uint32_t type, void* pixels); 79 typedef void (*read_buffer_t)(uint32_t handle, uint64_t offset, uint64_t sizeToRead, void* bytes); 80 typedef void (*read_color_buffer_t)( 81 uint32_t handle, int x, int y, int width, int height, 82 uint32_t format, uint32_t type, void* pixels); 83 typedef void (*read_color_buffer_yuv_t)( 84 uint32_t handle, int x, int y, int width, int height, 85 void* pixels, uint32_t pixels_size); 86 typedef void (*post_color_buffer_t)(uint32_t handle); 87 #ifdef __cplusplus 88 using CpuCompletionCallback = std::function<void(std::shared_future<void> waitForGpu)>; 89 typedef void (*async_post_color_buffer_t)(uint32_t, CpuCompletionCallback); 90 #else 91 typedef void* async_post_color_buffer_t; 92 #endif 93 typedef void (*repost_t)(void); 94 typedef uint32_t (*get_last_posted_color_buffer_t)(void); 95 typedef void (*bind_color_buffer_to_texture_t)(uint32_t); 96 typedef void* (*get_global_egl_context_t)(void); 97 typedef void (*wait_for_gpu_t)(uint64_t eglsync); 98 typedef void (*wait_for_gpu_vulkan_t)(uint64_t device, uint64_t fence); 99 typedef void (*set_guest_managed_color_buffer_lifetime_t)(bool guest_managed); 100 typedef void (*update_color_buffer_from_framework_format_t)(uint32_t handle, 101 int x, 102 int y, 103 int width, 104 int height, 105 uint32_t fwkFormat, 106 uint32_t format, 107 uint32_t type, 108 void* pixels, 109 void* metadata); 110 111 #ifdef __cplusplus 112 using FenceCompletionCallback = std::function<void()>; 113 typedef void (*async_wait_for_gpu_with_cb_t)(uint64_t eglsync, FenceCompletionCallback); 114 typedef void (*async_wait_for_gpu_vulkan_with_cb_t)(uint64_t device, uint64_t fence, FenceCompletionCallback); 115 typedef void (*async_wait_for_gpu_vulkan_qsri_with_cb_t)(uint64_t image, FenceCompletionCallback); 116 #else 117 typedef void* async_wait_for_gpu_with_cb_t; 118 typedef void* async_wait_for_gpu_vulkan_with_cb_t; 119 typedef void* async_wait_for_gpu_vulkan_qsri_with_cb_t; 120 #endif 121 typedef void (*wait_for_gpu_vulkan_qsri_t)(uint64_t image); 122 123 // Platform resources and contexts support 124 #define RESOURCE_TYPE_MASK 0x0F 125 #define RESOURCE_USE_MASK 0xF0 126 127 // types 128 #define RESOURCE_TYPE_EGL_NATIVE_PIXMAP 0x01 129 #define RESOURCE_TYPE_EGL_IMAGE 0x02 130 #define RESOURCE_TYPE_VK_EXT_MEMORY_HANDLE 0x03 131 132 // uses 133 #define RESOURCE_USE_PRESERVE 0x10 134 135 typedef bool (*platform_import_resource_t)(uint32_t handle, uint32_t info, void* resource); 136 typedef bool (*platform_resource_info_t)(uint32_t handle, int32_t* width, int32_t* height, int32_t* internal_format); 137 typedef void* (*platform_create_shared_egl_context_t)(void); 138 typedef bool (*platform_destroy_shared_egl_context_t)(void* context); 139 140 struct AndroidVirtioGpuOps { 141 create_buffer_with_handle_t create_buffer_with_handle; 142 create_color_buffer_with_handle_t create_color_buffer_with_handle; 143 open_color_buffer_t open_color_buffer; 144 close_buffer_t close_buffer; 145 close_color_buffer_t close_color_buffer; 146 update_buffer_t update_buffer; 147 update_color_buffer_t update_color_buffer; 148 read_buffer_t read_buffer; 149 read_color_buffer_t read_color_buffer; 150 read_color_buffer_yuv_t read_color_buffer_yuv; 151 post_color_buffer_t post_color_buffer; 152 async_post_color_buffer_t async_post_color_buffer; 153 repost_t repost; 154 /* yuv texture related */ 155 create_yuv_textures_t create_yuv_textures; 156 destroy_yuv_textures_t destroy_yuv_textures; 157 update_yuv_textures_t update_yuv_textures; 158 swap_textures_and_update_color_buffer_t 159 swap_textures_and_update_color_buffer; 160 /* virtual device widget related */ 161 get_last_posted_color_buffer_t get_last_posted_color_buffer; 162 bind_color_buffer_to_texture_t bind_color_buffer_to_texture; 163 get_global_egl_context_t get_global_egl_context; 164 wait_for_gpu_t wait_for_gpu; 165 wait_for_gpu_vulkan_t wait_for_gpu_vulkan; 166 set_guest_managed_color_buffer_lifetime_t set_guest_managed_color_buffer_lifetime; 167 async_wait_for_gpu_with_cb_t async_wait_for_gpu_with_cb; 168 async_wait_for_gpu_vulkan_with_cb_t async_wait_for_gpu_vulkan_with_cb; 169 170 async_wait_for_gpu_vulkan_qsri_with_cb_t async_wait_for_gpu_vulkan_qsri_with_cb; 171 wait_for_gpu_vulkan_qsri_t wait_for_gpu_vulkan_qsri; 172 173 update_color_buffer_from_framework_format_t update_color_buffer_from_framework_format; 174 175 platform_import_resource_t platform_import_resource; 176 platform_resource_info_t platform_resource_info; 177 platform_create_shared_egl_context_t platform_create_shared_egl_context; 178 platform_destroy_shared_egl_context_t platform_destroy_shared_egl_context; 179 }; 180