• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)(
28     uint32_t width,
29     uint32_t height,
30     uint32_t format,
31     uint32_t fwkFormat,
32     uint32_t handle);
33 
34 /* create YUV textures with given width and height
35    type: FRAMEWORK_FORMAT_NV12 or FRAMEWORK_FORMAT_YUV_420_888
36    count: how many set of textures will be created
37    output: caller allocated storage to hold results: size should
38    be 2*count for NV12 or 3*cout for YUV_420_888
39  */
40 typedef void (*create_yuv_textures_t)(uint32_t type,
41                                       uint32_t count,
42                                       int width,
43                                       int height,
44                                       uint32_t* output);
45 
46 /* destroy YUV textures */
47 typedef void (*destroy_yuv_textures_t)(uint32_t type,
48                                        uint32_t count,
49                                        uint32_t* textures);
50 /* call the user provided func with privData to update the content
51    of textures.
52    type: FRAMEWORK_FORMAT_NV12 or FRAMEWORK_FORMAT_YUV_420_888
53    textures: size 2 (NV12) or 3 (YUV420)
54  */
55 typedef void (*update_yuv_textures_t)(uint32_t type,
56                                       uint32_t* textures,
57                                       void* privData,
58                                       void* func);
59 
60 /* swap out the yuv textures of the colorbuffer, and use the new yuv textures
61  * to update colorbuffer content; on return, textures will have the retired
62  * yuv textures that are free to hold new data
63  */
64 typedef void (*swap_textures_and_update_color_buffer_t)(
65         uint32_t colorbufferhandle,
66         int x,
67         int y,
68         int width,
69         int height,
70         uint32_t format,
71         uint32_t type,
72         uint32_t texture_type,
73         uint32_t* textures,
74         void* metadata);
75 
76 typedef void (*open_color_buffer_t)(uint32_t handle);
77 typedef void (*close_buffer_t)(uint32_t handle);
78 typedef void (*close_color_buffer_t)(uint32_t handle);
79 typedef void (*update_buffer_t)(uint32_t handle, uint64_t offset, uint64_t sizeToRead, void* bytes);
80 typedef void (*update_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_buffer_t)(uint32_t handle, uint64_t offset, uint64_t sizeToRead, void* bytes);
84 typedef void (*read_color_buffer_t)(
85     uint32_t handle, int x, int y, int width, int height,
86     uint32_t format, uint32_t type, void* pixels);
87 typedef void (*read_color_buffer_yuv_t)(
88     uint32_t handle, int x, int y, int width, int height,
89     void* pixels, uint32_t pixels_size);
90 typedef void (*post_color_buffer_t)(uint32_t handle);
91 #ifdef __cplusplus
92 using CpuCompletionCallback = std::function<void(std::shared_future<void> waitForGpu)>;
93 typedef void (*async_post_color_buffer_t)(uint32_t, CpuCompletionCallback);
94 #else
95 typedef void* async_post_color_buffer_t;
96 #endif
97 typedef void (*repost_t)(void);
98 typedef uint32_t (*get_last_posted_color_buffer_t)(void);
99 typedef void (*bind_color_buffer_to_texture_t)(uint32_t);
100 typedef void* (*get_global_egl_context_t)(void);
101 typedef void (*wait_for_gpu_t)(uint64_t eglsync);
102 typedef void (*wait_for_gpu_vulkan_t)(uint64_t device, uint64_t fence);
103 typedef void (*set_guest_managed_color_buffer_lifetime_t)(bool guest_managed);
104 typedef void (*update_color_buffer_from_framework_format_t)(uint32_t handle,
105                                                             int x,
106                                                             int y,
107                                                             int width,
108                                                             int height,
109                                                             uint32_t fwkFormat,
110                                                             uint32_t format,
111                                                             uint32_t type,
112                                                             void* pixels,
113                                                             void* metadata);
114 
115 #ifdef __cplusplus
116 using FenceCompletionCallback = std::function<void()>;
117 typedef void (*async_wait_for_gpu_with_cb_t)(uint64_t eglsync, FenceCompletionCallback);
118 typedef void (*async_wait_for_gpu_vulkan_with_cb_t)(uint64_t device, uint64_t fence, FenceCompletionCallback);
119 typedef void (*async_wait_for_gpu_vulkan_qsri_with_cb_t)(uint64_t image, FenceCompletionCallback);
120 #else
121 typedef void* async_wait_for_gpu_with_cb_t;
122 typedef void* async_wait_for_gpu_vulkan_with_cb_t;
123 typedef void* async_wait_for_gpu_vulkan_qsri_with_cb_t;
124 #endif
125 typedef void (*wait_for_gpu_vulkan_qsri_t)(uint64_t image);
126 
127 // Platform resources and contexts support
128 #define RESOURCE_TYPE_MASK 0x0F
129 #define RESOURCE_USE_MASK  0xF0
130 
131 // types
132 #define RESOURCE_TYPE_EGL_NATIVE_PIXMAP 0x01
133 #define RESOURCE_TYPE_EGL_IMAGE 0x02
134 
135 // uses
136 #define RESOURCE_USE_PRESERVE 0x10
137 
138 typedef bool (*platform_import_resource_t)(uint32_t handle, uint32_t info, void* resource);
139 typedef bool (*platform_resource_info_t)(uint32_t handle, int32_t* width, int32_t* height, int32_t* internal_format);
140 typedef void* (*platform_create_shared_egl_context_t)(void);
141 typedef bool (*platform_destroy_shared_egl_context_t)(void* context);
142 
143 struct AndroidVirtioGpuOps {
144     create_buffer_with_handle_t create_buffer_with_handle;
145     create_color_buffer_with_handle_t create_color_buffer_with_handle;
146     open_color_buffer_t open_color_buffer;
147     close_buffer_t close_buffer;
148     close_color_buffer_t close_color_buffer;
149     update_buffer_t update_buffer;
150     update_color_buffer_t update_color_buffer;
151     read_buffer_t read_buffer;
152     read_color_buffer_t read_color_buffer;
153     read_color_buffer_yuv_t read_color_buffer_yuv;
154     post_color_buffer_t post_color_buffer;
155     async_post_color_buffer_t async_post_color_buffer;
156     repost_t repost;
157     /* yuv texture related */
158     create_yuv_textures_t create_yuv_textures;
159     destroy_yuv_textures_t destroy_yuv_textures;
160     update_yuv_textures_t update_yuv_textures;
161     swap_textures_and_update_color_buffer_t
162             swap_textures_and_update_color_buffer;
163     /* virtual device widget related */
164     get_last_posted_color_buffer_t get_last_posted_color_buffer;
165     bind_color_buffer_to_texture_t bind_color_buffer_to_texture;
166     get_global_egl_context_t get_global_egl_context;
167     wait_for_gpu_t wait_for_gpu;
168     wait_for_gpu_vulkan_t wait_for_gpu_vulkan;
169     set_guest_managed_color_buffer_lifetime_t set_guest_managed_color_buffer_lifetime;
170     async_wait_for_gpu_with_cb_t async_wait_for_gpu_with_cb;
171     async_wait_for_gpu_vulkan_with_cb_t async_wait_for_gpu_vulkan_with_cb;
172 
173     async_wait_for_gpu_vulkan_qsri_with_cb_t async_wait_for_gpu_vulkan_qsri_with_cb;
174     wait_for_gpu_vulkan_qsri_t wait_for_gpu_vulkan_qsri;
175 
176     update_color_buffer_from_framework_format_t update_color_buffer_from_framework_format;
177 
178     platform_import_resource_t platform_import_resource;
179     platform_resource_info_t platform_resource_info;
180     platform_create_shared_egl_context_t platform_create_shared_egl_context;
181     platform_destroy_shared_egl_context_t platform_destroy_shared_egl_context;
182 };
183