• 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 #include <functional>
17 
18 /* virtio-gpu interface for color buffers
19  * (triggered by minigbm/egl calling virtio-gpu ioctls) */
20 typedef void (*create_color_buffer_with_handle_t)(
21     uint32_t width,
22     uint32_t height,
23     uint32_t format,
24     uint32_t fwkFormat,
25     uint32_t handle);
26 
27 /* create YUV textures with given width and height
28    type: FRAMEWORK_FORMAT_NV12 or FRAMEWORK_FORMAT_YUV_420_888
29    count: how many set of textures will be created
30    output: caller allocated storage to hold results: size should
31    be 2*count for NV12 or 3*cout for YUV_420_888
32  */
33 typedef void (*create_yuv_textures_t)(uint32_t type,
34                                       uint32_t count,
35                                       int width,
36                                       int height,
37                                       uint32_t* output);
38 
39 /* destroy YUV textures */
40 typedef void (*destroy_yuv_textures_t)(uint32_t type,
41                                        uint32_t count,
42                                        uint32_t* textures);
43 /* call the user provided func with privData to update the content
44    of textures.
45    type: FRAMEWORK_FORMAT_NV12 or FRAMEWORK_FORMAT_YUV_420_888
46    textures: size 2 (NV12) or 3 (YUV420)
47  */
48 typedef void (*update_yuv_textures_t)(uint32_t type,
49                                       uint32_t* textures,
50                                       void* privData,
51                                       void* func);
52 
53 /* swap out the yuv textures of the colorbuffer, and use the new yuv textures
54  * to update colorbuffer content; on return, textures will have the retired
55  * yuv textures that are free to hold new data
56  */
57 typedef void (*swap_textures_and_update_color_buffer_t)(
58         uint32_t colorbufferhandle,
59         int x,
60         int y,
61         int width,
62         int height,
63         uint32_t format,
64         uint32_t type,
65         uint32_t texture_type,
66         uint32_t* textures);
67 
68 typedef void (*open_color_buffer_t)(uint32_t handle);
69 typedef void (*close_color_buffer_t)(uint32_t handle);
70 typedef void (*update_color_buffer_t)(
71     uint32_t handle, int x, int y, int width, int height,
72     uint32_t format, uint32_t type, void* pixels);
73 typedef void (*read_color_buffer_t)(
74     uint32_t handle, int x, int y, int width, int height,
75     uint32_t format, uint32_t type, void* pixels);
76 typedef void (*read_color_buffer_yuv_t)(
77     uint32_t handle, int x, int y, int width, int height,
78     void* pixels, uint32_t pixels_size);
79 typedef void (*post_color_buffer_t)(uint32_t handle);
80 typedef void (*repost_t)(void);
81 typedef uint32_t (*get_last_posted_color_buffer_t)(void);
82 typedef void (*bind_color_buffer_to_texture_t)(uint32_t);
83 typedef void* (*get_global_egl_context_t)(void);
84 typedef void (*wait_for_gpu_t)(uint64_t eglsync);
85 typedef void (*wait_for_gpu_vulkan_t)(uint64_t device, uint64_t fence);
86 typedef void (*set_guest_managed_color_buffer_lifetime_t)(bool guest_managed);
87 
88 using FenceCompletionCallback = std::function<void()>;
89 typedef void (*async_wait_for_gpu_with_cb_t)(uint64_t eglsync, FenceCompletionCallback);
90 typedef void (*async_wait_for_gpu_vulkan_with_cb_t)(uint64_t device, uint64_t fence, FenceCompletionCallback);
91 
92 typedef void (*async_wait_for_gpu_vulkan_qsri_with_cb_t)(uint64_t image, FenceCompletionCallback);
93 typedef void (*wait_for_gpu_vulkan_qsri_t)(uint64_t image);
94 
95 // Platform resources and contexts support
96 #define RESOURCE_TYPE_EGL_NATIVE_PIXMAP 0x01
97 #define RESOURCE_TYPE_EGL_IMAGE 0x02
98 
99 typedef bool (*platform_import_resource_t)(uint32_t handle, uint32_t type, void* resource);
100 typedef bool (*platform_resource_info_t)(uint32_t handle, int32_t* width, int32_t* height, int32_t* internal_format);
101 typedef void* (*platform_create_shared_egl_context_t)(void);
102 typedef bool (*platform_destroy_shared_egl_context_t)(void* context);
103 
104 struct AndroidVirtioGpuOps {
105     create_color_buffer_with_handle_t create_color_buffer_with_handle;
106     open_color_buffer_t open_color_buffer;
107     close_color_buffer_t close_color_buffer;
108     update_color_buffer_t update_color_buffer;
109     read_color_buffer_t read_color_buffer;
110     read_color_buffer_yuv_t read_color_buffer_yuv;
111     post_color_buffer_t post_color_buffer;
112     repost_t repost;
113     /* yuv texture related */
114     create_yuv_textures_t create_yuv_textures;
115     destroy_yuv_textures_t destroy_yuv_textures;
116     update_yuv_textures_t update_yuv_textures;
117     swap_textures_and_update_color_buffer_t
118             swap_textures_and_update_color_buffer;
119     /* virtual device widget related */
120     get_last_posted_color_buffer_t get_last_posted_color_buffer;
121     bind_color_buffer_to_texture_t bind_color_buffer_to_texture;
122     get_global_egl_context_t get_global_egl_context;
123     wait_for_gpu_t wait_for_gpu;
124     wait_for_gpu_vulkan_t wait_for_gpu_vulkan;
125     set_guest_managed_color_buffer_lifetime_t set_guest_managed_color_buffer_lifetime;
126     async_wait_for_gpu_with_cb_t async_wait_for_gpu_with_cb;
127     async_wait_for_gpu_vulkan_with_cb_t async_wait_for_gpu_vulkan_with_cb;
128 
129     async_wait_for_gpu_vulkan_qsri_with_cb_t async_wait_for_gpu_vulkan_qsri_with_cb;
130     wait_for_gpu_vulkan_qsri_t wait_for_gpu_vulkan_qsri;
131 
132     platform_import_resource_t platform_import_resource;
133     platform_resource_info_t platform_resource_info;
134     platform_create_shared_egl_context_t platform_create_shared_egl_context;
135     platform_destroy_shared_egl_context_t platform_destroy_shared_egl_context;
136 };
137