xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/virgl/virgl_video.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2022 Kylin Software Co., Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * on the rights to use, copy, modify, merge, publish, distribute, sub
8  * license, and/or sell copies of the Software, and to permit persons to whom
9  * the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 /**
25  * @file
26  * Virgl video driver interface.
27  *
28  * This file defines two objects:
29  *   virgl_video_buffer: Buffer for storing raw YUV formatted data.
30  *   virgl_video_codec : Represents an encoder or decoder.
31  *
32  * @author Feng Jiang <[email protected]>
33  */
34 
35 #ifndef VIRGL_VIDEO_H
36 #define VIRGL_VIDEO_H
37 
38 
39 #include "virgl_context.h"
40 #include "vl/vl_video_buffer.h"
41 #include "pipe/p_video_codec.h"
42 #include "virtio-gpu/virgl_video_hw.h"
43 
44 #define VIRGL_VIDEO_CODEC_BUF_NUM    10
45 
46 struct virgl_video_codec {
47     struct pipe_video_codec base;       /* must be first */
48 
49     uint32_t handle;
50     struct virgl_context *vctx;
51     union virgl_picture_desc desc;
52 
53     uint32_t bs_size;                   /* size of data in bs_buffer */
54     uint32_t cur_buffer;                /* index of current bs/desc buffer */
55     struct pipe_resource *bs_buffers[VIRGL_VIDEO_CODEC_BUF_NUM];
56     struct pipe_resource *desc_buffers[VIRGL_VIDEO_CODEC_BUF_NUM];
57     struct pipe_resource *feed_buffers[VIRGL_VIDEO_CODEC_BUF_NUM];
58 };
59 
60 struct virgl_video_buffer {
61     uint32_t handle;
62     enum pipe_format buffer_format;
63     unsigned width;
64     unsigned height;
65     struct virgl_context *vctx;
66     struct pipe_video_buffer *buf;
67     unsigned num_planes;
68     struct pipe_sampler_view **plane_views;
69 };
70 
71 static inline struct virgl_video_codec *
virgl_video_codec(struct pipe_video_codec * codec)72 virgl_video_codec(struct pipe_video_codec *codec)
73 {
74     return (struct virgl_video_codec *)codec;
75 }
76 
77 static inline struct virgl_video_buffer *
virgl_video_buffer(struct pipe_video_buffer * buffer)78 virgl_video_buffer(struct pipe_video_buffer *buffer)
79 {
80     return buffer ? vl_video_buffer_get_associated_data(buffer, NULL) : NULL;
81 }
82 
83 struct pipe_video_codec *
84 virgl_video_create_codec(struct pipe_context *ctx,
85                          const struct pipe_video_codec *templ);
86 
87 struct pipe_video_buffer *
88 virgl_video_create_buffer(struct pipe_context *ctx,
89                           const struct pipe_video_buffer *tmpl);
90 
91 #endif /* VIRGL_VIDEO_H */
92 
93