xf86DiDGA.c revision 6747b715
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 = xf86Screens[pScreen->myNum]; 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 { 55 num++; 56 display_mode = display_mode->next; 57 if (display_mode == scrn->modes) 58 break; 59 } 60 61 if (!num) 62 return FALSE; 63 64 modes = malloc(num * sizeof(DGAModeRec)); 65 if (!modes) 66 return FALSE; 67 68 num = 0; 69 display_mode = scrn->modes; 70 while (display_mode) 71 { 72 mode = modes + num++; 73 74 mode->mode = display_mode; 75 mode->flags = DGA_CONCURRENT_ACCESS; 76 if (display_mode->Flags & V_DBLSCAN) 77 mode->flags |= DGA_DOUBLESCAN; 78 if (display_mode->Flags & V_INTERLACE) 79 mode->flags |= DGA_INTERLACED; 80 mode->byteOrder = scrn->imageByteOrder; 81 mode->depth = scrn->depth; 82 mode->bitsPerPixel = scrn->bitsPerPixel; 83 mode->red_mask = scrn->mask.red; 84 mode->green_mask = scrn->mask.green; 85 mode->blue_mask = scrn->mask.blue; 86 mode->visualClass = (bpp == 1) ? PseudoColor : TrueColor; 87 mode->viewportWidth = display_mode->HDisplay; 88 mode->viewportHeight = display_mode->VDisplay; 89 mode->xViewportStep = (bpp == 3) ? 2 : 1; 90 mode->yViewportStep = 1; 91 mode->viewportFlags = DGA_FLIP_RETRACE; 92 mode->offset = 0; 93 mode->address = 0; 94 mode->imageWidth = mode->viewportWidth; 95 mode->imageHeight = mode->viewportHeight; 96 mode->bytesPerScanline = (mode->imageWidth * scrn->bitsPerPixel) >> 3; 97 mode->pixmapWidth = mode->imageWidth; 98 mode->pixmapHeight = mode->imageHeight; 99 mode->maxViewportX = 0; 100 mode->maxViewportY = 0; 101 102 display_mode = display_mode->next; 103 if (display_mode == scrn->modes) 104 break; 105 } 106 free(xf86_config->dga_modes); 107 xf86_config->dga_nmode = num; 108 xf86_config->dga_modes = modes; 109 return TRUE; 110} 111 112static Bool 113xf86_dga_set_mode(ScrnInfoPtr scrn, DGAModePtr display_mode) 114{ 115 ScreenPtr pScreen = scrn->pScreen; 116 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); 117 118 if (!display_mode) 119 { 120 if (xf86_config->dga_save_mode) 121 { 122 xf86SwitchMode(pScreen, xf86_config->dga_save_mode); 123 xf86_config->dga_save_mode = NULL; 124 } 125 } 126 else 127 { 128 if (!xf86_config->dga_save_mode) 129 { 130 xf86_config->dga_save_mode = scrn->currentMode; 131 xf86SwitchMode(pScreen, display_mode->mode); 132 } 133 } 134 return TRUE; 135} 136 137static int 138xf86_dga_get_viewport(ScrnInfoPtr scrn) 139{ 140 return 0; 141} 142 143static void 144xf86_dga_set_viewport(ScrnInfoPtr scrn, int x, int y, int flags) 145{ 146 scrn->AdjustFrame(scrn->pScreen->myNum, x, y, flags); 147} 148 149static Bool 150xf86_dga_open_framebuffer(ScrnInfoPtr scrn, 151 char **name, 152 unsigned char **mem, int *size, int *offset, int *flags) 153{ 154 return FALSE; 155} 156 157static void 158xf86_dga_close_framebuffer(ScrnInfoPtr scrn) 159{ 160} 161 162static DGAFunctionRec xf86_dga_funcs = { 163 xf86_dga_open_framebuffer, 164 xf86_dga_close_framebuffer, 165 xf86_dga_set_mode, 166 xf86_dga_set_viewport, 167 xf86_dga_get_viewport, 168 NULL, 169 NULL, 170 NULL, 171 NULL 172}; 173 174Bool 175xf86DiDGAReInit (ScreenPtr pScreen) 176{ 177 return TRUE; 178} 179 180Bool 181_xf86_di_dga_reinit_internal (ScreenPtr pScreen) 182{ 183 ScrnInfoPtr scrn = xf86Screens[pScreen->myNum]; 184 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); 185 186 if (!DGAAvailable(pScreen->myNum)) 187 return TRUE; 188 189 if (!xf86_dga_get_modes (pScreen)) 190 return FALSE; 191 192 return DGAReInitModes (pScreen, xf86_config->dga_modes, xf86_config->dga_nmode); 193} 194 195Bool 196xf86DiDGAInit (ScreenPtr pScreen, unsigned long dga_address) 197{ 198 return TRUE; 199} 200 201Bool 202_xf86_di_dga_init_internal (ScreenPtr pScreen) 203{ 204 ScrnInfoPtr scrn = xf86Screens[pScreen->myNum]; 205 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); 206 207 xf86_config->dga_flags = 0; 208 xf86_config->dga_address = 0; 209 xf86_config->dga_width = 0; 210 xf86_config->dga_height = 0; 211 xf86_config->dga_stride = 0; 212 213 if (!xf86_dga_get_modes (pScreen)) 214 return FALSE; 215 216 return DGAInit(pScreen, &xf86_dga_funcs, xf86_config->dga_modes, xf86_config->dga_nmode); 217} 218