1 /*
2 * Copyright (c) 2009-2024 Broadcom. All Rights Reserved.
3 * The term “Broadcom” refers to Broadcom Inc.
4 * and/or its subsidiaries.
5 * SPDX-License-Identifier: MIT
6 */
7
8 /**
9 * @file
10 * Surfaces for VMware SVGA winsys.
11 *
12 * @author Jose Fonseca <[email protected]>
13 */
14
15
16 #ifndef VMW_SURFACE_H_
17 #define VMW_SURFACE_H_
18
19
20 #include "util/compiler.h"
21 #include "util/u_atomic.h"
22 #include "util/u_inlines.h"
23 #include "util/u_thread.h"
24 #include "pipebuffer/pb_buffer.h"
25
26 #define VMW_MAX_PRESENTS 3
27
28
29
30 struct vmw_svga_winsys_surface
31 {
32 int32_t validated; /* atomic */
33 struct pipe_reference refcnt;
34
35 struct vmw_winsys_screen *screen;
36 uint32_t sid;
37
38 /* FIXME: make this thread safe */
39 unsigned next_present_no;
40 uint32_t present_fences[VMW_MAX_PRESENTS];
41
42 mtx_t mutex;
43 struct svga_winsys_buffer *buf; /* Current backing guest buffer */
44 uint32_t mapcount; /* Number of mappers */
45 uint32_t map_mode; /* PIPE_MAP_[READ|WRITE] */
46 void *data; /* Pointer to data if mapcount != 0*/
47 bool nodiscard; /* Never discard */
48 uint32_t size; /* Size of backing buffer */
49 bool rebind; /* Surface needs a rebind after next unmap */
50 };
51
52
53 static inline struct svga_winsys_surface *
svga_winsys_surface(struct vmw_svga_winsys_surface * surf)54 svga_winsys_surface(struct vmw_svga_winsys_surface *surf)
55 {
56 assert(!surf || surf->sid != SVGA3D_INVALID_ID);
57 return (struct svga_winsys_surface *)surf;
58 }
59
60
61 static inline struct vmw_svga_winsys_surface *
vmw_svga_winsys_surface(struct svga_winsys_surface * surf)62 vmw_svga_winsys_surface(struct svga_winsys_surface *surf)
63 {
64 return (struct vmw_svga_winsys_surface *)surf;
65 }
66
67
68 void
69 vmw_svga_winsys_surface_reference(struct vmw_svga_winsys_surface **pdst,
70 struct vmw_svga_winsys_surface *src);
71 void *
72 vmw_svga_winsys_surface_map(struct svga_winsys_context *swc,
73 struct svga_winsys_surface *srf,
74 unsigned flags, bool *retry,
75 bool *rebind);
76 void
77 vmw_svga_winsys_surface_unmap(struct svga_winsys_context *swc,
78 struct svga_winsys_surface *srf,
79 bool *rebind);
80
81 void
82 vmw_svga_winsys_surface_init(struct svga_winsys_screen *sws,
83 struct svga_winsys_surface *surface,
84 unsigned surf_size, SVGA3dSurfaceAllFlags flags);
85
86 #endif /* VMW_SURFACE_H_ */
87