xf86DiDGA.c revision b1d344b3
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 = xalloc(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 if (xf86_config->dga_modes) 107 xfree (xf86_config->dga_modes); 108 xf86_config->dga_nmode = num; 109 xf86_config->dga_modes = modes; 110 return TRUE; 111} 112 113static Bool 114xf86_dga_set_mode(ScrnInfoPtr scrn, DGAModePtr display_mode) 115{ 116 ScreenPtr pScreen = scrn->pScreen; 117 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); 118 119 if (!display_mode) 120 { 121 if (xf86_config->dga_save_mode) 122 { 123 xf86SwitchMode(pScreen, xf86_config->dga_save_mode); 124 xf86_config->dga_save_mode = NULL; 125 } 126 } 127 else 128 { 129 if (!xf86_config->dga_save_mode) 130 { 131 xf86_config->dga_save_mode = scrn->currentMode; 132 xf86SwitchMode(pScreen, display_mode->mode); 133 } 134 } 135 return TRUE; 136} 137 138static int 139xf86_dga_get_viewport(ScrnInfoPtr scrn) 140{ 141 return 0; 142} 143 144static void 145xf86_dga_set_viewport(ScrnInfoPtr scrn, int x, int y, int flags) 146{ 147 scrn->AdjustFrame(scrn->pScreen->myNum, x, y, flags); 148} 149 150static Bool 151xf86_dga_open_framebuffer(ScrnInfoPtr scrn, 152 char **name, 153 unsigned char **mem, int *size, int *offset, int *flags) 154{ 155 return FALSE; 156} 157 158static void 159xf86_dga_close_framebuffer(ScrnInfoPtr scrn) 160{ 161} 162 163static DGAFunctionRec xf86_dga_funcs = { 164 xf86_dga_open_framebuffer, 165 xf86_dga_close_framebuffer, 166 xf86_dga_set_mode, 167 xf86_dga_set_viewport, 168 xf86_dga_get_viewport, 169 NULL, 170 NULL, 171 NULL, 172 NULL 173}; 174 175_X_EXPORT Bool 176xf86DiDGAReInit (ScreenPtr pScreen) 177{ 178 return TRUE; 179} 180 181Bool 182_xf86_di_dga_reinit_internal (ScreenPtr pScreen) 183{ 184 ScrnInfoPtr scrn = xf86Screens[pScreen->myNum]; 185 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); 186 187 if (!DGAAvailable(pScreen->myNum)) 188 return TRUE; 189 190 if (!xf86_dga_get_modes (pScreen)) 191 return FALSE; 192 193 return DGAReInitModes (pScreen, xf86_config->dga_modes, xf86_config->dga_nmode); 194} 195 196_X_EXPORT Bool 197xf86DiDGAInit (ScreenPtr pScreen, unsigned long dga_address) 198{ 199 return TRUE; 200} 201 202Bool 203_xf86_di_dga_init_internal (ScreenPtr pScreen) 204{ 205 ScrnInfoPtr scrn = xf86Screens[pScreen->myNum]; 206 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); 207 208 xf86_config->dga_flags = 0; 209 xf86_config->dga_address = 0; 210 xf86_config->dga_width = 0; 211 xf86_config->dga_height = 0; 212 xf86_config->dga_stride = 0; 213 214 if (!xf86_dga_get_modes (pScreen)) 215 return FALSE; 216 217 return DGAInit(pScreen, &xf86_dga_funcs, xf86_config->dga_modes, xf86_config->dga_nmode); 218} 219