• 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 #ifndef ANDROID_VIRTIO_GPU_OPS
15 #define ANDROID_VIRTIO_GPU_OPS
16 
17 /* virtio-gpu interface for color buffers
18  * (triggered by minigbm/egl calling virtio-gpu ioctls) */
19 typedef void (*create_color_buffer_with_handle_t)(
20     uint32_t width,
21     uint32_t height,
22     uint32_t format,
23     uint32_t fwkFormat,
24     uint32_t handle);
25 
26 /* create YUV textures with given width and height
27    type: FRAMEWORK_FORMAT_NV12 or FRAMEWORK_FORMAT_YUV_420_888
28    count: how many set of textures will be created
29    output: caller allocated storage to hold results: size should
30    be 2*count for NV12 or 3*cout for YUV_420_888
31  */
32 typedef void (*create_yuv_textures_t)(uint32_t type,
33                                       uint32_t count,
34                                       int width,
35                                       int height,
36                                       uint32_t* output);
37 
38 /* destroy YUV textures */
39 typedef void (*destroy_yuv_textures_t)(uint32_t type,
40                                        uint32_t count,
41                                        uint32_t* textures);
42 /* call the user provided func with privData to update the content
43    of textures.
44    type: FRAMEWORK_FORMAT_NV12 or FRAMEWORK_FORMAT_YUV_420_888
45    textures: size 2 (NV12) or 3 (YUV420)
46  */
47 typedef void (*update_yuv_textures_t)(uint32_t type,
48                                       uint32_t* textures,
49                                       void* privData,
50                                       void* func);
51 
52 /* swap out the yuv textures of the colorbuffer, and use the new yuv textures
53  * to update colorbuffer content; on return, textures will have the retired
54  * yuv textures that are free to hold new data
55  */
56 typedef void (*swap_textures_and_update_color_buffer_t)(
57         uint32_t colorbufferhandle,
58         int x,
59         int y,
60         int width,
61         int height,
62         uint32_t format,
63         uint32_t type,
64         uint32_t texture_type,
65         uint32_t* textures);
66 
67 typedef void (*open_color_buffer_t)(uint32_t handle);
68 typedef void (*close_color_buffer_t)(uint32_t handle);
69 typedef void (*update_color_buffer_t)(
70     uint32_t handle, int x, int y, int width, int height,
71     uint32_t format, uint32_t type, void* pixels);
72 typedef void (*read_color_buffer_t)(
73     uint32_t handle, int x, int y, int width, int height,
74     uint32_t format, uint32_t type, void* pixels);
75 typedef void (*read_color_buffer_yuv_t)(
76     uint32_t handle, int x, int y, int width, int height,
77     void* pixels, uint32_t pixels_size);
78 typedef void (*post_color_buffer_t)(uint32_t handle);
79 typedef void (*repost_t)(void);
80 typedef uint32_t (*get_last_posted_color_buffer_t)(void);
81 typedef void (*bind_color_buffer_to_texture_t)(uint32_t);
82 typedef void* (*get_global_egl_context_t)(void);
83 typedef void (*wait_for_gpu_t)(uint64_t eglsync);
84 typedef void (*wait_for_gpu_vulkan_t)(uint64_t device, uint64_t fence);
85 typedef void (*set_guest_managed_color_buffer_lifetime_t)(bool guest_managed);
86 
87 struct AndroidVirtioGpuOps {
88     create_color_buffer_with_handle_t create_color_buffer_with_handle;
89     open_color_buffer_t open_color_buffer;
90     close_color_buffer_t close_color_buffer;
91     update_color_buffer_t update_color_buffer;
92     read_color_buffer_t read_color_buffer;
93     read_color_buffer_yuv_t read_color_buffer_yuv;
94     post_color_buffer_t post_color_buffer;
95     repost_t repost;
96     /* yuv texture related */
97     create_yuv_textures_t create_yuv_textures;
98     destroy_yuv_textures_t destroy_yuv_textures;
99     update_yuv_textures_t update_yuv_textures;
100     swap_textures_and_update_color_buffer_t
101             swap_textures_and_update_color_buffer;
102     /* virtual device widget related */
103     get_last_posted_color_buffer_t get_last_posted_color_buffer;
104     bind_color_buffer_to_texture_t bind_color_buffer_to_texture;
105     get_global_egl_context_t get_global_egl_context;
106     wait_for_gpu_t wait_for_gpu;
107     wait_for_gpu_vulkan_t wait_for_gpu_vulkan;
108     set_guest_managed_color_buffer_lifetime_t set_guest_managed_color_buffer_lifetime;
109 };
110 
111 #endif // ANDROID_VIRTIO_GPU_OPS
112