DRI2: report swap events correctly in direct rendered case
[mesa.git] / src / gallium / winsys / drm / vmware / xorg / vmw_screen.c
1 /**********************************************************
2 * Copyright 2009 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **********************************************************/
25
26 /**
27 * @file
28 * Contains the init code for the VMware Xorg driver.
29 *
30 * @author Jakob Bornecrantz <jakob@vmware.com>
31 */
32
33 #include "vmw_hook.h"
34 #include "vmw_driver.h"
35
36 #include "cursorstr.h"
37
38 /* modified version of crtc functions */
39 xf86CrtcFuncsRec vmw_screen_crtc_funcs;
40
41 static void
42 vmw_screen_cursor_load_argb(xf86CrtcPtr crtc, CARD32 *image)
43 {
44 struct vmw_customizer *vmw =
45 vmw_customizer(xorg_customizer(crtc->scrn));
46 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
47 xf86CrtcFuncsPtr funcs = vmw->cursor_priv;
48 CursorPtr c = config->cursor;
49
50 /* Run the ioctl before uploading the image */
51 vmw_ioctl_cursor_bypass(vmw, c->bits->xhot, c->bits->yhot);
52
53 funcs->load_cursor_argb(crtc, image);
54 }
55
56 static void
57 vmw_screen_cursor_init(struct vmw_customizer *vmw)
58 {
59 ScrnInfoPtr pScrn = vmw->pScrn;
60 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
61 int i;
62
63 /* XXX assume that all crtc's have the same function struct */
64
65 /* Save old struct need to call the old functions as well */
66 vmw->cursor_priv = (void*)(config->crtc[0]->funcs);
67 memcpy(&vmw_screen_crtc_funcs, vmw->cursor_priv, sizeof(xf86CrtcFuncsRec));
68 vmw_screen_crtc_funcs.load_cursor_argb = vmw_screen_cursor_load_argb;
69
70 for (i = 0; i < config->num_crtc; i++)
71 config->crtc[i]->funcs = &vmw_screen_crtc_funcs;
72 }
73
74 static void
75 vmw_screen_cursor_close(struct vmw_customizer *vmw)
76 {
77 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(vmw->pScrn);
78 int i;
79
80 vmw_ioctl_cursor_bypass(vmw, 0, 0);
81
82 for (i = 0; i < config->num_crtc; i++)
83 config->crtc[i]->funcs = vmw->cursor_priv;
84 }
85
86 static Bool
87 vmw_screen_init(CustomizerPtr cust, int fd)
88 {
89 struct vmw_customizer *vmw = vmw_customizer(cust);
90
91 vmw->fd = fd;
92 vmw_screen_cursor_init(vmw);
93
94 /* if gallium is used then we don't need to do anything more. */
95 if (xorg_has_gallium(vmw->pScrn))
96 return TRUE;
97
98 vmw_video_init(vmw);
99
100 return TRUE;
101 }
102
103 static Bool
104 vmw_screen_close(CustomizerPtr cust)
105 {
106 struct vmw_customizer *vmw = vmw_customizer(cust);
107
108 if (!vmw)
109 return TRUE;
110
111 vmw_screen_cursor_close(vmw);
112
113 vmw_video_close(vmw);
114
115 return TRUE;
116 }
117
118 static Bool
119 vmw_screen_enter_vt(CustomizerPtr cust)
120 {
121 debug_printf("%s: enter\n", __func__);
122
123 return TRUE;
124 }
125
126 static Bool
127 vmw_screen_leave_vt(CustomizerPtr cust)
128 {
129 struct vmw_customizer *vmw = vmw_customizer(cust);
130
131 debug_printf("%s: enter\n", __func__);
132
133 vmw_video_stop_all(vmw);
134
135 return TRUE;
136 }
137
138 /*
139 * Functions for setting up hooks into the xorg state tracker
140 */
141
142 static Bool (*vmw_screen_pre_init_saved)(ScrnInfoPtr pScrn, int flags) = NULL;
143
144 static Bool
145 vmw_screen_pre_init(ScrnInfoPtr pScrn, int flags)
146 {
147 struct vmw_customizer *vmw;
148 CustomizerPtr cust;
149
150 vmw = xnfcalloc(1, sizeof(*vmw));
151 if (!vmw)
152 return FALSE;
153
154 cust = &vmw->base;
155
156 cust->winsys_screen_init = vmw_screen_init;
157 cust->winsys_screen_close = vmw_screen_close;
158 cust->winsys_enter_vt = vmw_screen_enter_vt;
159 cust->winsys_leave_vt = vmw_screen_leave_vt;
160 vmw->pScrn = pScrn;
161
162 pScrn->driverPrivate = cust;
163
164 pScrn->PreInit = vmw_screen_pre_init_saved;
165 if (!pScrn->PreInit(pScrn, flags))
166 return FALSE;
167
168 return TRUE;
169 }
170
171 void
172 vmw_screen_set_functions(ScrnInfoPtr pScrn)
173 {
174 assert(!vmw_screen_pre_init_saved);
175
176 vmw_screen_pre_init_saved = pScrn->PreInit;
177 pScrn->PreInit = vmw_screen_pre_init;
178 }