First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / exa / examodule.c
blob4dce58fd8913cd86584a7fc8cb69b1d6ea2abf25
1 /*
2 * Copyright © 2006 Intel Corporation
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:
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.
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.
23 * Authors:
24 * Eric Anholt <anholt@FreeBSD.org>
28 #ifdef HAVE_CONFIG_H
29 #include <xorg-config.h>
30 #endif
32 #include <string.h>
34 #include "exa_priv.h"
36 #include "xf86str.h"
37 #include "xf86.h"
39 typedef struct _ExaXorgScreenPrivRec {
40 CloseScreenProcPtr SavedCloseScreen;
41 EnableDisableFBAccessProcPtr SavedEnableDisableFBAccess;
42 OptionInfoPtr options;
43 } ExaXorgScreenPrivRec, *ExaXorgScreenPrivPtr;
45 static int exaXorgServerGeneration;
46 static int exaXorgScreenPrivateIndex;
48 typedef enum {
49 EXAOPT_MIGRATION_HEURISTIC,
50 EXAOPT_NO_COMPOSITE,
51 EXAOPT_NO_UTS,
52 EXAOPT_NO_DFS,
53 } EXAOpts;
55 static const OptionInfoRec EXAOptions[] = {
56 { EXAOPT_MIGRATION_HEURISTIC, "MigrationHeuristic",
57 OPTV_ANYSTR, {0}, FALSE },
58 { EXAOPT_NO_COMPOSITE, "EXANoComposite",
59 OPTV_BOOLEAN, {0}, FALSE },
60 { EXAOPT_NO_UTS, "EXANoUploadToScreen",
61 OPTV_BOOLEAN, {0}, FALSE },
62 { EXAOPT_NO_DFS, "EXANoDownloadFromScreen",
63 OPTV_BOOLEAN, {0}, FALSE },
64 { -1, NULL,
65 OPTV_NONE, {0}, FALSE }
68 static Bool
69 exaXorgCloseScreen (int i, ScreenPtr pScreen)
71 ScrnInfoPtr pScrn = XF86SCRNINFO(pScreen);
72 ExaXorgScreenPrivPtr pScreenPriv =
73 pScreen->devPrivates[exaXorgScreenPrivateIndex].ptr;
75 pScreen->CloseScreen = pScreenPriv->SavedCloseScreen;
77 pScrn->EnableDisableFBAccess = pScreenPriv->SavedEnableDisableFBAccess;
79 xfree (pScreenPriv->options);
80 xfree (pScreenPriv);
82 return pScreen->CloseScreen (i, pScreen);
85 static void
86 exaXorgEnableDisableFBAccess (int index, Bool enable)
88 ScreenPtr pScreen = screenInfo.screens[index];
89 ExaXorgScreenPrivPtr pScreenPriv =
90 pScreen->devPrivates[exaXorgScreenPrivateIndex].ptr;
92 if (!enable)
93 exaEnableDisableFBAccess (index, enable);
95 if (pScreenPriv->SavedEnableDisableFBAccess)
96 pScreenPriv->SavedEnableDisableFBAccess (index, enable);
98 if (enable)
99 exaEnableDisableFBAccess (index, enable);
103 * This will be called during exaDriverInit, giving us the chance to set options
104 * and hook in our EnableDisableFBAccess.
106 void
107 exaDDXDriverInit(ScreenPtr pScreen)
109 ExaScreenPriv(pScreen);
110 /* Do NOT use XF86SCRNINFO macro here!! */
111 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
112 ExaXorgScreenPrivPtr pScreenPriv;
114 if (exaXorgServerGeneration != serverGeneration) {
115 exaXorgScreenPrivateIndex = AllocateScreenPrivateIndex();
116 exaXorgServerGeneration = serverGeneration;
119 pScreenPriv = xcalloc (1, sizeof(ExaXorgScreenPrivRec));
120 if (pScreenPriv == NULL)
121 return;
123 pScreenPriv->options = xnfalloc (sizeof(EXAOptions));
124 memcpy(pScreenPriv->options, EXAOptions, sizeof(EXAOptions));
125 xf86ProcessOptions (pScrn->scrnIndex, pScrn->options, pScreenPriv->options);
127 if ((pExaScr->info->flags & EXA_OFFSCREEN_PIXMAPS) &&
128 pExaScr->info->offScreenBase < pExaScr->info->memorySize)
130 char *heuristicName;
132 heuristicName = xf86GetOptValString (pScreenPriv->options,
133 EXAOPT_MIGRATION_HEURISTIC);
134 if (heuristicName != NULL) {
135 if (strcmp(heuristicName, "greedy") == 0)
136 pExaScr->migration = ExaMigrationGreedy;
137 else if (strcmp(heuristicName, "always") == 0)
138 pExaScr->migration = ExaMigrationAlways;
139 else if (strcmp(heuristicName, "smart") == 0)
140 pExaScr->migration = ExaMigrationSmart;
141 else {
142 xf86DrvMsg (pScreen->myNum, X_WARNING,
143 "EXA: unknown migration heuristic %s\n",
144 heuristicName);
149 if (xf86IsOptionSet(pScreenPriv->options, EXAOPT_NO_COMPOSITE)) {
150 xf86DrvMsg(pScreen->myNum, X_INFO,
151 "EXA: Disabling Composite operation "
152 "(RENDER acceleration)\n");
153 pExaScr->info->CheckComposite = NULL;
154 pExaScr->info->PrepareComposite = NULL;
157 if (xf86IsOptionSet(pScreenPriv->options, EXAOPT_NO_UTS)) {
158 xf86DrvMsg(pScreen->myNum, X_INFO,
159 "EXA: Disabling UploadToScreen\n");
160 pExaScr->info->UploadToScreen = NULL;
163 if (xf86IsOptionSet(pScreenPriv->options, EXAOPT_NO_DFS)) {
164 xf86DrvMsg(pScreen->myNum, X_INFO,
165 "EXA: Disabling DownloadFromScreen\n");
166 pExaScr->info->DownloadFromScreen = NULL;
169 pScreen->devPrivates[exaXorgScreenPrivateIndex].ptr = pScreenPriv;
171 pScreenPriv->SavedEnableDisableFBAccess = pScrn->EnableDisableFBAccess;
172 pScrn->EnableDisableFBAccess = exaXorgEnableDisableFBAccess;
174 pScreenPriv->SavedCloseScreen = pScreen->CloseScreen;
175 pScreen->CloseScreen = exaXorgCloseScreen;
179 static MODULESETUPPROTO(exaSetup);
181 /*ARGSUSED*/
182 static const OptionInfoRec *
183 EXAAvailableOptions(void *unused)
185 return (EXAOptions);
188 static XF86ModuleVersionInfo exaVersRec =
190 "exa",
191 MODULEVENDORSTRING,
192 MODINFOSTRING1,
193 MODINFOSTRING2,
194 XORG_VERSION_CURRENT,
195 EXA_VERSION_MAJOR, EXA_VERSION_MINOR, EXA_VERSION_RELEASE,
196 ABI_CLASS_VIDEODRV, /* requires the video driver ABI */
197 ABI_VIDEODRV_VERSION,
198 MOD_CLASS_NONE,
199 {0,0,0,0}
202 _X_EXPORT XF86ModuleData exaModuleData = { &exaVersRec, exaSetup, NULL };
204 static ModuleInfoRec EXA = {
206 "EXA",
207 NULL,
209 EXAAvailableOptions,
212 /*ARGSUSED*/
213 static pointer
214 exaSetup(pointer Module, pointer Options, int *ErrorMajor, int *ErrorMinor)
216 static Bool Initialised = FALSE;
218 if (!Initialised) {
219 Initialised = TRUE;
220 xf86AddModuleInfo(&EXA, Module);
223 return (pointer)TRUE;