Merge remote branch 'origin/master' into lp-binning
[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_driver *vmw = modesettingPTR(crtc->scrn)->winsys_priv;
45 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
46 xf86CrtcFuncsPtr funcs = vmw->cursor_priv;
47 CursorPtr c = config->cursor;
48
49 /* Run the ioctl before uploading the image */
50 vmw_ioctl_cursor_bypass(vmw, c->bits->xhot, c->bits->yhot);
51
52 funcs->load_cursor_argb(crtc, image);
53 }
54
55 static void
56 vmw_screen_cursor_init(ScrnInfoPtr pScrn, struct vmw_driver *vmw)
57 {
58 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
59 int i;
60
61 /* XXX assume that all crtc's have the same function struct */
62
63 /* Save old struct need to call the old functions as well */
64 vmw->cursor_priv = (void*)(config->crtc[0]->funcs);
65 memcpy(&vmw_screen_crtc_funcs, vmw->cursor_priv, sizeof(xf86CrtcFuncsRec));
66 vmw_screen_crtc_funcs.load_cursor_argb = vmw_screen_cursor_load_argb;
67
68 for (i = 0; i < config->num_crtc; i++)
69 config->crtc[i]->funcs = &vmw_screen_crtc_funcs;
70 }
71
72 static void
73 vmw_screen_cursor_close(ScrnInfoPtr pScrn, struct vmw_driver *vmw)
74 {
75 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
76 int i;
77
78 vmw_ioctl_cursor_bypass(vmw, 0, 0);
79
80 for (i = 0; i < config->num_crtc; i++)
81 config->crtc[i]->funcs = vmw->cursor_priv;
82 }
83
84 static Bool
85 vmw_screen_init(ScrnInfoPtr pScrn)
86 {
87 modesettingPtr ms = modesettingPTR(pScrn);
88 struct vmw_driver *vmw;
89
90 vmw = xnfcalloc(sizeof(*vmw), 1);
91 if (!vmw)
92 return FALSE;
93
94 vmw->fd = ms->fd;
95 ms->winsys_priv = vmw;
96
97 vmw_screen_cursor_init(pScrn, vmw);
98
99 /* if gallium is used then we don't need to do anything more. */
100 if (ms->screen)
101 return TRUE;
102
103 vmw_video_init(pScrn, vmw);
104
105 return TRUE;
106 }
107
108 static Bool
109 vmw_screen_close(ScrnInfoPtr pScrn)
110 {
111 modesettingPtr ms = modesettingPTR(pScrn);
112 struct vmw_driver *vmw = vmw_driver(pScrn);
113
114 if (!vmw)
115 return TRUE;
116
117 vmw_screen_cursor_close(pScrn, vmw);
118
119 vmw_video_close(pScrn, vmw);
120
121 ms->winsys_priv = NULL;
122 xfree(vmw);
123
124 return TRUE;
125 }
126
127 static Bool
128 vmw_screen_enter_vt(ScrnInfoPtr pScrn)
129 {
130 debug_printf("%s: enter\n", __func__);
131
132 return TRUE;
133 }
134
135 static Bool
136 vmw_screen_leave_vt(ScrnInfoPtr pScrn)
137 {
138 struct vmw_driver *vmw = vmw_driver(pScrn);
139
140 debug_printf("%s: enter\n", __func__);
141
142 vmw_video_stop_all(pScrn, vmw);
143
144 return TRUE;
145 }
146
147 /*
148 * Functions for setting up hooks into the xorg state tracker
149 */
150
151 static Bool (*vmw_screen_pre_init_saved)(ScrnInfoPtr pScrn, int flags) = NULL;
152
153 static Bool
154 vmw_screen_pre_init(ScrnInfoPtr pScrn, int flags)
155 {
156 modesettingPtr ms;
157
158 pScrn->PreInit = vmw_screen_pre_init_saved;
159 if (!pScrn->PreInit(pScrn, flags))
160 return FALSE;
161
162 ms = modesettingPTR(pScrn);
163 ms->winsys_screen_init = vmw_screen_init;
164 ms->winsys_screen_close = vmw_screen_close;
165 ms->winsys_enter_vt = vmw_screen_enter_vt;
166 ms->winsys_leave_vt = vmw_screen_leave_vt;
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 }