1 /*
2  * Copyright 2011 VMWare, Inc.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sub license, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial portions
15  * of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  * Author: Thomas Hellstrom <thellstrom@vmware.com>
26  */
27 
28 #ifndef _VMWGFX_SAA_H_
29 #define _VMWGFX_SAA_H_
30 
31 #include "saa.h"
32 #include <xa_composite.h>
33 #include "vmwgfx_drmi.h"
34 #include "wsbm_util.h"
35 
36 
37 #define VMWGFX_FLAG_FORCE_GMR     (1 << 0) /* Create with GMR as backing store */
38 #define VMWGFX_FLAG_FORCE_SURFACE (1 << 1) /* Create with surface as backing store */
39 #define VMWGFX_FLAG_AVOID_HWACCEL (1 << 2) /* Avoid Hardware acceleration on this pixmap */
40 #define VMWGFX_FLAG_USE_PRESENT   (1 << 3) /* Use presents when copying to this pixmap */
41 
42 struct vmwgfx_saa_pixmap {
43     struct saa_pixmap base;
44     RegionPtr dirty_present;
45     RegionPtr present_damage;
46     RegionPtr pending_update;
47     RegionPtr pending_present;
48     uint32_t usage_flags;
49     uint32_t backing;
50     void *malloc;
51     struct vmwgfx_dmabuf *gmr;
52     struct xa_surface *hw;
53     uint32_t fb_id;
54     int hw_is_dri2_fronts;
55     Bool hw_is_hosted;
56     struct _WsbmListHead sync_x_head;
57     struct _WsbmListHead scanout_list;
58     struct _WsbmListHead pixmap_list;
59     Bool scanout_hw;
60 
61     uint32_t xa_flags;
62     uint32_t staging_add_flags;
63     uint32_t staging_remove_flags;
64     enum xa_formats staging_format;
65 };
66 
67 struct vmwgfx_screen_entry {
68     struct _WsbmListHead scanout_head;
69     PixmapPtr pixmap;
70 };
71 
72 static inline struct vmwgfx_saa_pixmap *
to_vmwgfx_saa_pixmap(struct saa_pixmap * spix)73 to_vmwgfx_saa_pixmap(struct saa_pixmap *spix)
74 {
75     return (struct vmwgfx_saa_pixmap *) spix;
76 }
77 
78 static inline struct vmwgfx_saa_pixmap*
vmwgfx_saa_pixmap(PixmapPtr pix)79 vmwgfx_saa_pixmap(PixmapPtr pix)
80 {
81     return to_vmwgfx_saa_pixmap(saa_get_saa_pixmap(pix));
82 }
83 
84 extern Bool
85 vmwgfx_saa_init(ScreenPtr pScreen, int drm_fd, struct xa_tracker *xat,
86 		void (*present_flush)(ScreenPtr pScreen),
87 		Bool direct_presents,
88 		Bool only_hw_presents,
89 		Bool rendercheck,
90 		Bool has_screen_targets);
91 
92 extern uint32_t
93 vmwgfx_scanout_ref(struct vmwgfx_screen_entry *entry,
94 		   Bool scanout_equals_pixmap);
95 
96 extern void
97 vmwgfx_scanout_unref(struct vmwgfx_screen_entry *box);
98 
99 extern void
100 vmwgfx_scanout_refresh(PixmapPtr pixmap);
101 
102 extern void
103 vmwgfx_remove_dri2_list(struct vmwgfx_saa_pixmap *vpix);
104 
105 extern void
106 vmwgfx_flush_dri2(ScreenPtr pScreen);
107 
108 extern Bool
109 vmwgfx_hw_dri2_validate(PixmapPtr pixmap, unsigned int depth);
110 
111 Bool
112 vmwgfx_hw_accel_validate(PixmapPtr pixmap, unsigned int depth,
113 			 uint32_t add_flags, uint32_t remove_flags,
114 			 RegionPtr region);
115 
116 void
117 vmwgfx_saa_set_master(ScreenPtr pScreen);
118 
119 void
120 vmwgfx_saa_drop_master(ScreenPtr pScreen);
121 
122 #if (XA_TRACKER_VERSION_MAJOR >= 2) && defined(HAVE_LIBDRM_2_4_38)
123 Bool
124 vmwgfx_saa_copy_to_surface(DrawablePtr pDraw, uint32_t surface_fd,
125 			   const BoxRec *dst_box, RegionPtr region);
126 #endif /* (XA_TRACKER_VERSION_MAJOR >= 2) && defined(HAVE_LIBDRM_2_4_38) */
127 
128 #if (XA_TRACKER_VERSION_MAJOR <= 1) && !defined(HAVE_XA_2)
129 
130 #define _xa_surface_handle(_a, _b, _c) xa_surface_handle(_a, _b, _c)
131 #define xa_context_flush(_a)
132 
133 #else
134 
135 #define xa_surface_destroy(_a) xa_surface_unref(_a)
136 #define _xa_surface_handle(_a, _b, _c)		\
137     xa_surface_handle(_a, xa_handle_type_shared, _b, _c)
138 
139 #endif /*  (XA_TRACKER_VERSION_MAJOR <= 1) */
140 #endif
141