2 * Copyright © 2006 Keith Packard
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.
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
23 #ifdef HAVE_XORG_CONFIG_H
24 #include <xorg-config.h>
33 #include "xf86_OSproc.h"
36 #include "xf86Modes.h"
38 #include "scrnintstr.h"
39 #include "windowstr.h"
42 xf86_dga_get_modes(ScreenPtr pScreen
)
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;
52 display_mode
= scrn
->modes
;
53 while (display_mode
) {
55 display_mode
= display_mode
->next
;
56 if (display_mode
== scrn
->modes
)
63 modes
= malloc(num
* sizeof(DGAModeRec
));
68 display_mode
= scrn
->modes
;
69 while (display_mode
) {
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
;
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;
100 display_mode
= display_mode
->next
;
101 if (display_mode
== scrn
->modes
)
104 free(xf86_config
->dga_modes
);
105 xf86_config
->dga_nmode
= num
;
106 xf86_config
->dga_modes
= modes
;
111 xf86_dga_set_mode(ScrnInfoPtr scrn
, DGAModePtr display_mode
)
113 ScreenPtr pScreen
= scrn
->pScreen
;
114 xf86CrtcConfigPtr xf86_config
= XF86_CRTC_CONFIG_PTR(scrn
);
117 if (xf86_config
->dga_save_mode
) {
118 xf86SwitchMode(pScreen
, xf86_config
->dga_save_mode
);
119 xf86_config
->dga_save_mode
= NULL
;
123 if (!xf86_config
->dga_save_mode
) {
124 xf86_config
->dga_save_mode
= scrn
->currentMode
;
125 xf86SwitchMode(pScreen
, display_mode
->mode
);
132 xf86_dga_get_viewport(ScrnInfoPtr scrn
)
138 xf86_dga_set_viewport(ScrnInfoPtr scrn
, int x
, int y
, int flags
)
140 scrn
->AdjustFrame(scrn
, x
, y
);
144 xf86_dga_open_framebuffer(ScrnInfoPtr scrn
,
146 unsigned char **mem
, int *size
, int *offset
,
153 xf86_dga_close_framebuffer(ScrnInfoPtr scrn
)
157 static DGAFunctionRec xf86_dga_funcs
= {
158 xf86_dga_open_framebuffer
,
159 xf86_dga_close_framebuffer
,
161 xf86_dga_set_viewport
,
162 xf86_dga_get_viewport
,
170 xf86DiDGAReInit(ScreenPtr pScreen
)
176 _xf86_di_dga_reinit_internal(ScreenPtr pScreen
)
178 ScrnInfoPtr scrn
= xf86ScreenToScrn(pScreen
);
179 xf86CrtcConfigPtr xf86_config
= XF86_CRTC_CONFIG_PTR(scrn
);
181 if (!DGAScreenAvailable(pScreen
))
184 if (!xf86_dga_get_modes(pScreen
))
187 return DGAReInitModes(pScreen
, xf86_config
->dga_modes
,
188 xf86_config
->dga_nmode
);
192 xf86DiDGAInit(ScreenPtr pScreen
, unsigned long dga_address
)
198 _xf86_di_dga_init_internal(ScreenPtr pScreen
)
200 ScrnInfoPtr scrn
= xf86ScreenToScrn(pScreen
);
201 xf86CrtcConfigPtr xf86_config
= XF86_CRTC_CONFIG_PTR(scrn
);
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;
209 if (!xf86_dga_get_modes(pScreen
))
212 return DGAInit(pScreen
, &xf86_dga_funcs
, xf86_config
->dga_modes
,
213 xf86_config
->dga_nmode
);