examodule.c revision 52397711
1/* 2 * Copyright � 2006 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 * 23 * Authors: 24 * Eric Anholt <anholt@FreeBSD.org> 25 * 26 */ 27 28#ifdef HAVE_CONFIG_H 29#include <xorg-config.h> 30#endif 31 32#include <string.h> 33 34#include "exa_priv.h" 35 36#include "xf86str.h" 37#include "xf86.h" 38 39typedef struct _ExaXorgScreenPrivRec { 40 CloseScreenProcPtr SavedCloseScreen; 41 EnableDisableFBAccessProcPtr SavedEnableDisableFBAccess; 42 OptionInfoPtr options; 43} ExaXorgScreenPrivRec, *ExaXorgScreenPrivPtr; 44 45static int exaXorgScreenPrivateKeyIndex; 46static DevPrivateKey exaXorgScreenPrivateKey = &exaXorgScreenPrivateKeyIndex; 47 48typedef enum { 49 EXAOPT_MIGRATION_HEURISTIC, 50 EXAOPT_NO_COMPOSITE, 51 EXAOPT_NO_UTS, 52 EXAOPT_NO_DFS, 53 EXAOPT_OPTIMIZE_MIGRATION 54} EXAOpts; 55 56static const OptionInfoRec EXAOptions[] = { 57 { EXAOPT_MIGRATION_HEURISTIC, "MigrationHeuristic", 58 OPTV_ANYSTR, {0}, FALSE }, 59 { EXAOPT_NO_COMPOSITE, "EXANoComposite", 60 OPTV_BOOLEAN, {0}, FALSE }, 61 { EXAOPT_NO_UTS, "EXANoUploadToScreen", 62 OPTV_BOOLEAN, {0}, FALSE }, 63 { EXAOPT_NO_DFS, "EXANoDownloadFromScreen", 64 OPTV_BOOLEAN, {0}, FALSE }, 65 { EXAOPT_OPTIMIZE_MIGRATION, "EXAOptimizeMigration", 66 OPTV_BOOLEAN, {0}, FALSE }, 67 { -1, NULL, 68 OPTV_NONE, {0}, FALSE } 69}; 70 71static Bool 72exaXorgCloseScreen (int i, ScreenPtr pScreen) 73{ 74 ScrnInfoPtr pScrn = XF86SCRNINFO(pScreen); 75 ExaXorgScreenPrivPtr pScreenPriv = (ExaXorgScreenPrivPtr) 76 dixLookupPrivate(&pScreen->devPrivates, exaXorgScreenPrivateKey); 77 78 pScreen->CloseScreen = pScreenPriv->SavedCloseScreen; 79 80 pScrn->EnableDisableFBAccess = pScreenPriv->SavedEnableDisableFBAccess; 81 82 xfree (pScreenPriv->options); 83 xfree (pScreenPriv); 84 85 return pScreen->CloseScreen (i, pScreen); 86} 87 88static void 89exaXorgEnableDisableFBAccess (int index, Bool enable) 90{ 91 ScreenPtr pScreen = screenInfo.screens[index]; 92 ExaXorgScreenPrivPtr pScreenPriv = (ExaXorgScreenPrivPtr) 93 dixLookupPrivate(&pScreen->devPrivates, exaXorgScreenPrivateKey); 94 95 if (!enable) 96 exaEnableDisableFBAccess (index, enable); 97 98 if (pScreenPriv->SavedEnableDisableFBAccess) 99 pScreenPriv->SavedEnableDisableFBAccess (index, enable); 100 101 if (enable) 102 exaEnableDisableFBAccess (index, enable); 103} 104 105/** 106 * This will be called during exaDriverInit, giving us the chance to set options 107 * and hook in our EnableDisableFBAccess. 108 */ 109void 110exaDDXDriverInit(ScreenPtr pScreen) 111{ 112 ExaScreenPriv(pScreen); 113 /* Do NOT use XF86SCRNINFO macro here!! */ 114 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 115 ExaXorgScreenPrivPtr pScreenPriv; 116 117 pScreenPriv = xcalloc (1, sizeof(ExaXorgScreenPrivRec)); 118 if (pScreenPriv == NULL) 119 return; 120 121 pScreenPriv->options = xnfalloc (sizeof(EXAOptions)); 122 memcpy(pScreenPriv->options, EXAOptions, sizeof(EXAOptions)); 123 xf86ProcessOptions (pScrn->scrnIndex, pScrn->options, pScreenPriv->options); 124 125 if ((pExaScr->info->flags & EXA_OFFSCREEN_PIXMAPS) && 126 pExaScr->info->offScreenBase < pExaScr->info->memorySize) 127 { 128 char *heuristicName; 129 130 heuristicName = xf86GetOptValString (pScreenPriv->options, 131 EXAOPT_MIGRATION_HEURISTIC); 132 if (heuristicName != NULL) { 133 if (strcmp(heuristicName, "greedy") == 0) 134 pExaScr->migration = ExaMigrationGreedy; 135 else if (strcmp(heuristicName, "always") == 0) 136 pExaScr->migration = ExaMigrationAlways; 137 else if (strcmp(heuristicName, "smart") == 0) 138 pExaScr->migration = ExaMigrationSmart; 139 else { 140 xf86DrvMsg (pScreen->myNum, X_WARNING, 141 "EXA: unknown migration heuristic %s\n", 142 heuristicName); 143 } 144 } 145 146 pExaScr->optimize_migration = 147 xf86ReturnOptValBool(pScreenPriv->options, 148 EXAOPT_OPTIMIZE_MIGRATION, 149 FALSE); 150 } 151 152 if (xf86ReturnOptValBool(pScreenPriv->options, 153 EXAOPT_NO_COMPOSITE, FALSE)) { 154 xf86DrvMsg(pScreen->myNum, X_CONFIG, 155 "EXA: Disabling Composite operation " 156 "(RENDER acceleration)\n"); 157 pExaScr->info->CheckComposite = NULL; 158 pExaScr->info->PrepareComposite = NULL; 159 } 160 161 if (xf86ReturnOptValBool(pScreenPriv->options, EXAOPT_NO_UTS, FALSE)) { 162 xf86DrvMsg(pScreen->myNum, X_CONFIG, 163 "EXA: Disabling UploadToScreen\n"); 164 pExaScr->info->UploadToScreen = NULL; 165 } 166 167 if (xf86ReturnOptValBool(pScreenPriv->options, EXAOPT_NO_DFS, FALSE)) { 168 xf86DrvMsg(pScreen->myNum, X_CONFIG, 169 "EXA: Disabling DownloadFromScreen\n"); 170 pExaScr->info->DownloadFromScreen = NULL; 171 } 172 173 dixSetPrivate(&pScreen->devPrivates, exaXorgScreenPrivateKey, pScreenPriv); 174 175 pScreenPriv->SavedEnableDisableFBAccess = pScrn->EnableDisableFBAccess; 176 pScrn->EnableDisableFBAccess = exaXorgEnableDisableFBAccess; 177 178 pScreenPriv->SavedCloseScreen = pScreen->CloseScreen; 179 pScreen->CloseScreen = exaXorgCloseScreen; 180 181} 182 183static XF86ModuleVersionInfo exaVersRec = 184{ 185 "exa", 186 MODULEVENDORSTRING, 187 MODINFOSTRING1, 188 MODINFOSTRING2, 189 XORG_VERSION_CURRENT, 190 EXA_VERSION_MAJOR, EXA_VERSION_MINOR, EXA_VERSION_RELEASE, 191 ABI_CLASS_VIDEODRV, /* requires the video driver ABI */ 192 ABI_VIDEODRV_VERSION, 193 MOD_CLASS_NONE, 194 {0,0,0,0} 195}; 196 197_X_EXPORT XF86ModuleData exaModuleData = { &exaVersRec, NULL, NULL }; 198