Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / xfree86 / modes / xf86DiDGA.c
CommitLineData
a09e091a
JB
1/*
2 * Copyright © 2006 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#ifdef HAVE_XORG_CONFIG_H
24#include <xorg-config.h>
25#else
26#ifdef HAVE_CONFIG_H
27#include <config.h>
28#endif
29#endif
30
31#include "xf86.h"
32#include "xf86DDC.h"
33#include "xf86_OSproc.h"
34#include "dgaproc.h"
35#include "xf86Crtc.h"
36#include "xf86Modes.h"
37#include "gcstruct.h"
38#include "scrnintstr.h"
39#include "windowstr.h"
40
41static Bool
42xf86_dga_get_modes(ScreenPtr pScreen)
43{
44 ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
45 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
46 DGAModePtr modes, mode;
47 DisplayModePtr display_mode;
48 int bpp = scrn->bitsPerPixel >> 3;
49 int num;
50
51 num = 0;
52 display_mode = scrn->modes;
53 while (display_mode) {
54 num++;
55 display_mode = display_mode->next;
56 if (display_mode == scrn->modes)
57 break;
58 }
59
60 if (!num)
61 return FALSE;
62
63 modes = malloc(num * sizeof(DGAModeRec));
64 if (!modes)
65 return FALSE;
66
67 num = 0;
68 display_mode = scrn->modes;
69 while (display_mode) {
70 mode = modes + num++;
71
72 mode->mode = display_mode;
73 mode->flags = DGA_CONCURRENT_ACCESS;
74 if (display_mode->Flags & V_DBLSCAN)
75 mode->flags |= DGA_DOUBLESCAN;
76 if (display_mode->Flags & V_INTERLACE)
77 mode->flags |= DGA_INTERLACED;
78 mode->byteOrder = scrn->imageByteOrder;
79 mode->depth = scrn->depth;
80 mode->bitsPerPixel = scrn->bitsPerPixel;
81 mode->red_mask = scrn->mask.red;
82 mode->green_mask = scrn->mask.green;
83 mode->blue_mask = scrn->mask.blue;
84 mode->visualClass = (bpp == 1) ? PseudoColor : TrueColor;
85 mode->viewportWidth = display_mode->HDisplay;
86 mode->viewportHeight = display_mode->VDisplay;
87 mode->xViewportStep = (bpp == 3) ? 2 : 1;
88 mode->yViewportStep = 1;
89 mode->viewportFlags = DGA_FLIP_RETRACE;
90 mode->offset = 0;
91 mode->address = 0;
92 mode->imageWidth = mode->viewportWidth;
93 mode->imageHeight = mode->viewportHeight;
94 mode->bytesPerScanline = (mode->imageWidth * scrn->bitsPerPixel) >> 3;
95 mode->pixmapWidth = mode->imageWidth;
96 mode->pixmapHeight = mode->imageHeight;
97 mode->maxViewportX = 0;
98 mode->maxViewportY = 0;
99
100 display_mode = display_mode->next;
101 if (display_mode == scrn->modes)
102 break;
103 }
104 free(xf86_config->dga_modes);
105 xf86_config->dga_nmode = num;
106 xf86_config->dga_modes = modes;
107 return TRUE;
108}
109
110static Bool
111xf86_dga_set_mode(ScrnInfoPtr scrn, DGAModePtr display_mode)
112{
113 ScreenPtr pScreen = scrn->pScreen;
114 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
115
116 if (!display_mode) {
117 if (xf86_config->dga_save_mode) {
118 xf86SwitchMode(pScreen, xf86_config->dga_save_mode);
119 xf86_config->dga_save_mode = NULL;
120 }
121 }
122 else {
123 if (!xf86_config->dga_save_mode) {
124 xf86_config->dga_save_mode = scrn->currentMode;
125 xf86SwitchMode(pScreen, display_mode->mode);
126 }
127 }
128 return TRUE;
129}
130
131static int
132xf86_dga_get_viewport(ScrnInfoPtr scrn)
133{
134 return 0;
135}
136
137static void
138xf86_dga_set_viewport(ScrnInfoPtr scrn, int x, int y, int flags)
139{
140 scrn->AdjustFrame(scrn, x, y);
141}
142
143static Bool
144xf86_dga_open_framebuffer(ScrnInfoPtr scrn,
145 char **name,
146 unsigned char **mem, int *size, int *offset,
147 int *flags)
148{
149 return FALSE;
150}
151
152static void
153xf86_dga_close_framebuffer(ScrnInfoPtr scrn)
154{
155}
156
157static DGAFunctionRec xf86_dga_funcs = {
158 xf86_dga_open_framebuffer,
159 xf86_dga_close_framebuffer,
160 xf86_dga_set_mode,
161 xf86_dga_set_viewport,
162 xf86_dga_get_viewport,
163 NULL,
164 NULL,
165 NULL,
166 NULL
167};
168
169Bool
170xf86DiDGAReInit(ScreenPtr pScreen)
171{
172 return TRUE;
173}
174
175Bool
176_xf86_di_dga_reinit_internal(ScreenPtr pScreen)
177{
178 ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
179 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
180
181 if (!DGAScreenAvailable(pScreen))
182 return TRUE;
183
184 if (!xf86_dga_get_modes(pScreen))
185 return FALSE;
186
187 return DGAReInitModes(pScreen, xf86_config->dga_modes,
188 xf86_config->dga_nmode);
189}
190
191Bool
192xf86DiDGAInit(ScreenPtr pScreen, unsigned long dga_address)
193{
194 return TRUE;
195}
196
197Bool
198_xf86_di_dga_init_internal(ScreenPtr pScreen)
199{
200 ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
201 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
202
203 xf86_config->dga_flags = 0;
204 xf86_config->dga_address = 0;
205 xf86_config->dga_width = 0;
206 xf86_config->dga_height = 0;
207 xf86_config->dga_stride = 0;
208
209 if (!xf86_dga_get_modes(pScreen))
210 return FALSE;
211
212 return DGAInit(pScreen, &xf86_dga_funcs, xf86_config->dga_modes,
213 xf86_config->dga_nmode);
214}