1 | |
---|
2 | /* |
---|
3 | * Copyright 2002, SuSE Linux AG, Author: Egbert Eich |
---|
4 | */ |
---|
5 | |
---|
6 | #ifdef HAVE_CONFIG_H |
---|
7 | #include "config.h" |
---|
8 | #endif |
---|
9 | |
---|
10 | /* All drivers should typically include these */ |
---|
11 | #include "xf86.h" |
---|
12 | #include "xf86_OSproc.h" |
---|
13 | |
---|
14 | /* All drivers initialising the SW cursor need this */ |
---|
15 | #include "mipointer.h" |
---|
16 | |
---|
17 | /* All drivers using the mi colormap manipulation need this */ |
---|
18 | #include "micmap.h" |
---|
19 | |
---|
20 | #ifdef RANDR |
---|
21 | #include "randrstr.h" |
---|
22 | #endif |
---|
23 | |
---|
24 | #include "windowstr.h" |
---|
25 | |
---|
26 | /* identifying atom needed by magnifiers */ |
---|
27 | #include <X11/Xatom.h> |
---|
28 | #include "property.h" |
---|
29 | |
---|
30 | #include "xf86cmap.h" |
---|
31 | |
---|
32 | #include "xf86fbman.h" |
---|
33 | |
---|
34 | #include "fb.h" |
---|
35 | |
---|
36 | #include "picturestr.h" |
---|
37 | |
---|
38 | #ifdef XvExtension |
---|
39 | #include "xf86xv.h" |
---|
40 | #include <X11/extensions/Xv.h> |
---|
41 | #endif |
---|
42 | |
---|
43 | /* |
---|
44 | * Driver data structures. |
---|
45 | */ |
---|
46 | #include "dummy.h" |
---|
47 | |
---|
48 | /* These need to be checked */ |
---|
49 | #include <X11/X.h> |
---|
50 | #include <X11/Xproto.h> |
---|
51 | #include "scrnintstr.h" |
---|
52 | #include "servermd.h" |
---|
53 | #ifdef USE_DGA |
---|
54 | #define _XF86DGA_SERVER_ |
---|
55 | #include <X11/extensions/xf86dgaproto.h> |
---|
56 | #endif |
---|
57 | |
---|
58 | /* Mandatory functions */ |
---|
59 | static const OptionInfoRec * DUMMYAvailableOptions(int chipid, int busid); |
---|
60 | static void DUMMYIdentify(int flags); |
---|
61 | static Bool DUMMYProbe(DriverPtr drv, int flags); |
---|
62 | static Bool DUMMYPreInit(ScrnInfoPtr pScrn, int flags); |
---|
63 | static Bool DUMMYScreenInit(SCREEN_INIT_ARGS_DECL); |
---|
64 | static Bool DUMMYEnterVT(VT_FUNC_ARGS_DECL); |
---|
65 | static void DUMMYLeaveVT(VT_FUNC_ARGS_DECL); |
---|
66 | static Bool DUMMYCloseScreen(CLOSE_SCREEN_ARGS_DECL); |
---|
67 | static Bool DUMMYCreateWindow(WindowPtr pWin); |
---|
68 | static void DUMMYFreeScreen(FREE_SCREEN_ARGS_DECL); |
---|
69 | static ModeStatus DUMMYValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, |
---|
70 | Bool verbose, int flags); |
---|
71 | static Bool DUMMYSaveScreen(ScreenPtr pScreen, int mode); |
---|
72 | |
---|
73 | /* Internally used functions */ |
---|
74 | static Bool dummyModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode); |
---|
75 | static void dummySave(ScrnInfoPtr pScrn); |
---|
76 | static void dummyRestore(ScrnInfoPtr pScrn, Bool restoreText); |
---|
77 | static Bool dummyDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, |
---|
78 | pointer ptr); |
---|
79 | |
---|
80 | |
---|
81 | /* static void DUMMYDisplayPowerManagementSet(ScrnInfoPtr pScrn, */ |
---|
82 | /* int PowerManagementMode, |
---|
83 | * int flags); */ |
---|
84 | |
---|
85 | #define DUMMY_VERSION 4000 |
---|
86 | #define DUMMY_NAME "DUMMY" |
---|
87 | #define DUMMY_DRIVER_NAME "dummy" |
---|
88 | |
---|
89 | #define DUMMY_MAJOR_VERSION PACKAGE_VERSION_MAJOR |
---|
90 | #define DUMMY_MINOR_VERSION PACKAGE_VERSION_MINOR |
---|
91 | #define DUMMY_PATCHLEVEL PACKAGE_VERSION_PATCHLEVEL |
---|
92 | |
---|
93 | #define DUMMY_MAX_WIDTH 32767 |
---|
94 | #define DUMMY_MAX_HEIGHT 32767 |
---|
95 | |
---|
96 | /* |
---|
97 | * This is intentionally screen-independent. It indicates the binding |
---|
98 | * choice made in the first PreInit. |
---|
99 | */ |
---|
100 | static int pix24bpp = 0; |
---|
101 | |
---|
102 | |
---|
103 | /* |
---|
104 | * This contains the functions needed by the server after loading the driver |
---|
105 | * module. It must be supplied, and gets passed back by the SetupProc |
---|
106 | * function in the dynamic case. In the static case, a reference to this |
---|
107 | * is compiled in, and this requires that the name of this DriverRec be |
---|
108 | * an upper-case version of the driver name. |
---|
109 | */ |
---|
110 | |
---|
111 | _X_EXPORT DriverRec DUMMY = { |
---|
112 | DUMMY_VERSION, |
---|
113 | DUMMY_DRIVER_NAME, |
---|
114 | DUMMYIdentify, |
---|
115 | DUMMYProbe, |
---|
116 | DUMMYAvailableOptions, |
---|
117 | NULL, |
---|
118 | 0, |
---|
119 | dummyDriverFunc |
---|
120 | }; |
---|
121 | |
---|
122 | static SymTabRec DUMMYChipsets[] = { |
---|
123 | { DUMMY_CHIP, "dummy" }, |
---|
124 | { -1, NULL } |
---|
125 | }; |
---|
126 | |
---|
127 | typedef enum { |
---|
128 | OPTION_SW_CURSOR, |
---|
129 | OPTION_CONSTANT_DPI |
---|
130 | } DUMMYOpts; |
---|
131 | |
---|
132 | static const OptionInfoRec DUMMYOptions[] = { |
---|
133 | { OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE }, |
---|
134 | #ifdef RANDR |
---|
135 | { OPTION_CONSTANT_DPI, "ConstantDPI", OPTV_BOOLEAN, {0}, FALSE }, |
---|
136 | #endif |
---|
137 | { -1, NULL, OPTV_NONE, {0}, FALSE } |
---|
138 | }; |
---|
139 | |
---|
140 | #ifdef XFree86LOADER |
---|
141 | |
---|
142 | static MODULESETUPPROTO(dummySetup); |
---|
143 | |
---|
144 | static XF86ModuleVersionInfo dummyVersRec = |
---|
145 | { |
---|
146 | "dummy", |
---|
147 | MODULEVENDORSTRING, |
---|
148 | MODINFOSTRING1, |
---|
149 | MODINFOSTRING2, |
---|
150 | XORG_VERSION_CURRENT, |
---|
151 | DUMMY_MAJOR_VERSION, DUMMY_MINOR_VERSION, DUMMY_PATCHLEVEL, |
---|
152 | ABI_CLASS_VIDEODRV, |
---|
153 | ABI_VIDEODRV_VERSION, |
---|
154 | MOD_CLASS_VIDEODRV, |
---|
155 | {0,0,0,0} |
---|
156 | }; |
---|
157 | |
---|
158 | /* |
---|
159 | * This is the module init data. |
---|
160 | * Its name has to be the driver name followed by ModuleData |
---|
161 | */ |
---|
162 | _X_EXPORT XF86ModuleData dummyModuleData = { &dummyVersRec, dummySetup, NULL }; |
---|
163 | |
---|
164 | static pointer |
---|
165 | dummySetup(pointer module, pointer opts, int *errmaj, int *errmin) |
---|
166 | { |
---|
167 | static Bool setupDone = FALSE; |
---|
168 | |
---|
169 | if (!setupDone) { |
---|
170 | setupDone = TRUE; |
---|
171 | xf86AddDriver(&DUMMY, module, HaveDriverFuncs); |
---|
172 | |
---|
173 | /* |
---|
174 | * Modules that this driver always requires can be loaded here |
---|
175 | * by calling LoadSubModule(). |
---|
176 | */ |
---|
177 | |
---|
178 | /* |
---|
179 | * The return value must be non-NULL on success even though there |
---|
180 | * is no TearDownProc. |
---|
181 | */ |
---|
182 | return (pointer)1; |
---|
183 | } else { |
---|
184 | if (errmaj) |
---|
185 | *errmaj = LDR_ONCEONLY; |
---|
186 | return NULL; |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | #endif /* XFree86LOADER */ |
---|
191 | |
---|
192 | static Bool |
---|
193 | DUMMYGetRec(ScrnInfoPtr pScrn) |
---|
194 | { |
---|
195 | /* |
---|
196 | * Allocate a DUMMYRec, and hook it into pScrn->driverPrivate. |
---|
197 | * pScrn->driverPrivate is initialised to NULL, so we can check if |
---|
198 | * the allocation has already been done. |
---|
199 | */ |
---|
200 | if (pScrn->driverPrivate != NULL) |
---|
201 | return TRUE; |
---|
202 | |
---|
203 | pScrn->driverPrivate = xnfcalloc(sizeof(DUMMYRec), 1); |
---|
204 | |
---|
205 | if (pScrn->driverPrivate == NULL) |
---|
206 | return FALSE; |
---|
207 | return TRUE; |
---|
208 | } |
---|
209 | |
---|
210 | static void |
---|
211 | DUMMYFreeRec(ScrnInfoPtr pScrn) |
---|
212 | { |
---|
213 | if (pScrn->driverPrivate == NULL) |
---|
214 | return; |
---|
215 | free(pScrn->driverPrivate); |
---|
216 | pScrn->driverPrivate = NULL; |
---|
217 | } |
---|
218 | |
---|
219 | static const OptionInfoRec * |
---|
220 | DUMMYAvailableOptions(int chipid, int busid) |
---|
221 | { |
---|
222 | return DUMMYOptions; |
---|
223 | } |
---|
224 | |
---|
225 | /* Mandatory */ |
---|
226 | static void |
---|
227 | DUMMYIdentify(int flags) |
---|
228 | { |
---|
229 | xf86PrintChipsets(DUMMY_NAME, "Driver for Dummy chipsets", |
---|
230 | DUMMYChipsets); |
---|
231 | } |
---|
232 | |
---|
233 | /* Mandatory */ |
---|
234 | static Bool |
---|
235 | DUMMYProbe(DriverPtr drv, int flags) |
---|
236 | { |
---|
237 | Bool foundScreen = FALSE; |
---|
238 | int numDevSections, numUsed; |
---|
239 | GDevPtr *devSections; |
---|
240 | int i; |
---|
241 | |
---|
242 | if (flags & PROBE_DETECT) |
---|
243 | return FALSE; |
---|
244 | /* |
---|
245 | * Find the config file Device sections that match this |
---|
246 | * driver, and return if there are none. |
---|
247 | */ |
---|
248 | if ((numDevSections = xf86MatchDevice(DUMMY_DRIVER_NAME, |
---|
249 | &devSections)) <= 0) { |
---|
250 | return FALSE; |
---|
251 | } |
---|
252 | |
---|
253 | numUsed = numDevSections; |
---|
254 | |
---|
255 | if (numUsed > 0) { |
---|
256 | for (i = 0; i < numUsed; i++) { |
---|
257 | ScrnInfoPtr pScrn = NULL; |
---|
258 | int entityIndex = |
---|
259 | xf86ClaimNoSlot(drv,DUMMY_CHIP,devSections[i],TRUE); |
---|
260 | /* Allocate a ScrnInfoRec and claim the slot */ |
---|
261 | if ((pScrn = xf86AllocateScreen(drv,0 ))) { |
---|
262 | xf86AddEntityToScreen(pScrn,entityIndex); |
---|
263 | pScrn->driverVersion = DUMMY_VERSION; |
---|
264 | pScrn->driverName = DUMMY_DRIVER_NAME; |
---|
265 | pScrn->name = DUMMY_NAME; |
---|
266 | pScrn->Probe = DUMMYProbe; |
---|
267 | pScrn->PreInit = DUMMYPreInit; |
---|
268 | pScrn->ScreenInit = DUMMYScreenInit; |
---|
269 | pScrn->SwitchMode = DUMMYSwitchMode; |
---|
270 | pScrn->AdjustFrame = DUMMYAdjustFrame; |
---|
271 | pScrn->EnterVT = DUMMYEnterVT; |
---|
272 | pScrn->LeaveVT = DUMMYLeaveVT; |
---|
273 | pScrn->FreeScreen = DUMMYFreeScreen; |
---|
274 | pScrn->ValidMode = DUMMYValidMode; |
---|
275 | |
---|
276 | foundScreen = TRUE; |
---|
277 | } |
---|
278 | } |
---|
279 | } |
---|
280 | return foundScreen; |
---|
281 | } |
---|
282 | |
---|
283 | # define RETURN \ |
---|
284 | { DUMMYFreeRec(pScrn);\ |
---|
285 | return FALSE;\ |
---|
286 | } |
---|
287 | |
---|
288 | /* Mandatory */ |
---|
289 | Bool |
---|
290 | DUMMYPreInit(ScrnInfoPtr pScrn, int flags) |
---|
291 | { |
---|
292 | ClockRangePtr clockRanges; |
---|
293 | int i; |
---|
294 | DUMMYPtr dPtr; |
---|
295 | int maxClock = 230000; |
---|
296 | GDevPtr device = xf86GetEntityInfo(pScrn->entityList[0])->device; |
---|
297 | |
---|
298 | if (flags & PROBE_DETECT) { |
---|
299 | return TRUE; |
---|
300 | } |
---|
301 | |
---|
302 | /* Allocate the DummyRec driverPrivate */ |
---|
303 | if (!DUMMYGetRec(pScrn)) { |
---|
304 | return FALSE; |
---|
305 | } |
---|
306 | |
---|
307 | dPtr = DUMMYPTR(pScrn); |
---|
308 | |
---|
309 | pScrn->chipset = (char *)xf86TokenToString(DUMMYChipsets, |
---|
310 | DUMMY_CHIP); |
---|
311 | |
---|
312 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Chipset is a DUMMY\n"); |
---|
313 | |
---|
314 | pScrn->monitor = pScrn->confScreen->monitor; |
---|
315 | |
---|
316 | if (!xf86SetDepthBpp(pScrn, 0, 0, 0, Support24bppFb | Support32bppFb)) |
---|
317 | return FALSE; |
---|
318 | |
---|
319 | /* Check that the returned depth is one we support */ |
---|
320 | switch (pScrn->depth) { |
---|
321 | case 8: |
---|
322 | case 15: |
---|
323 | case 16: |
---|
324 | case 24: |
---|
325 | break; |
---|
326 | default: |
---|
327 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR, |
---|
328 | "Given depth (%d) is not supported by this driver\n", |
---|
329 | pScrn->depth); |
---|
330 | return FALSE; |
---|
331 | } |
---|
332 | |
---|
333 | xf86PrintDepthBpp(pScrn); |
---|
334 | if (pScrn->depth == 8) |
---|
335 | pScrn->rgbBits = 8; |
---|
336 | |
---|
337 | /* Get the depth24 pixmap format */ |
---|
338 | if (pScrn->depth == 24 && pix24bpp == 0) |
---|
339 | pix24bpp = xf86GetBppFromDepth(pScrn, 24); |
---|
340 | |
---|
341 | /* |
---|
342 | * This must happen after pScrn->display has been set because |
---|
343 | * xf86SetWeight references it. |
---|
344 | */ |
---|
345 | if (pScrn->depth > 8) { |
---|
346 | /* The defaults are OK for us */ |
---|
347 | rgb zeros = {0, 0, 0}; |
---|
348 | |
---|
349 | if (!xf86SetWeight(pScrn, zeros, zeros)) { |
---|
350 | return FALSE; |
---|
351 | } else { |
---|
352 | /* XXX check that weight returned is supported */ |
---|
353 | ; |
---|
354 | } |
---|
355 | } |
---|
356 | |
---|
357 | if (!xf86SetDefaultVisual(pScrn, -1)) { |
---|
358 | return FALSE; |
---|
359 | } |
---|
360 | |
---|
361 | if (pScrn->depth > 1) { |
---|
362 | Gamma zeros = {0.0, 0.0, 0.0}; |
---|
363 | |
---|
364 | if (!xf86SetGamma(pScrn, zeros)) { |
---|
365 | return FALSE; |
---|
366 | } |
---|
367 | } |
---|
368 | |
---|
369 | xf86CollectOptions(pScrn, device->options); |
---|
370 | /* Process the options */ |
---|
371 | if (!(dPtr->Options = malloc(sizeof(DUMMYOptions)))) { |
---|
372 | return FALSE; |
---|
373 | } |
---|
374 | memcpy(dPtr->Options, DUMMYOptions, sizeof(DUMMYOptions)); |
---|
375 | |
---|
376 | xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, dPtr->Options); |
---|
377 | |
---|
378 | xf86GetOptValBool(dPtr->Options, OPTION_SW_CURSOR,&dPtr->swCursor); |
---|
379 | xf86GetOptValBool(dPtr->Options, OPTION_CONSTANT_DPI, &dPtr->constantDPI); |
---|
380 | |
---|
381 | if (device->videoRam != 0) { |
---|
382 | pScrn->videoRam = device->videoRam; |
---|
383 | xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "VideoRAM: %d kByte\n", |
---|
384 | pScrn->videoRam); |
---|
385 | } else { |
---|
386 | pScrn->videoRam = 4096; |
---|
387 | xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "VideoRAM: %d kByte\n", |
---|
388 | pScrn->videoRam); |
---|
389 | } |
---|
390 | |
---|
391 | if (device->dacSpeeds[0] != 0) { |
---|
392 | maxClock = device->dacSpeeds[0]; |
---|
393 | xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Max Clock: %d kHz\n", |
---|
394 | maxClock); |
---|
395 | } else { |
---|
396 | xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Max Clock: %d kHz\n", |
---|
397 | maxClock); |
---|
398 | } |
---|
399 | |
---|
400 | pScrn->progClock = TRUE; |
---|
401 | /* |
---|
402 | * Setup the ClockRanges, which describe what clock ranges are available, |
---|
403 | * and what sort of modes they can be used for. |
---|
404 | */ |
---|
405 | clockRanges = (ClockRangePtr)xnfcalloc(sizeof(ClockRange), 1); |
---|
406 | clockRanges->next = NULL; |
---|
407 | clockRanges->ClockMulFactor = 1; |
---|
408 | clockRanges->minClock = 11000; /* guessed §§§ */ |
---|
409 | clockRanges->maxClock = 300000; |
---|
410 | clockRanges->clockIndex = -1; /* programmable */ |
---|
411 | clockRanges->interlaceAllowed = TRUE; |
---|
412 | clockRanges->doubleScanAllowed = TRUE; |
---|
413 | |
---|
414 | /* Subtract memory for HW cursor */ |
---|
415 | |
---|
416 | { |
---|
417 | int apertureSize = (pScrn->videoRam * 1024); |
---|
418 | i = xf86ValidateModes(pScrn, pScrn->monitor->Modes, |
---|
419 | pScrn->display->modes, clockRanges, |
---|
420 | NULL, 256, DUMMY_MAX_WIDTH, |
---|
421 | (8 * pScrn->bitsPerPixel), |
---|
422 | 128, DUMMY_MAX_HEIGHT, pScrn->display->virtualX, |
---|
423 | pScrn->display->virtualY, apertureSize, |
---|
424 | LOOKUP_BEST_REFRESH); |
---|
425 | |
---|
426 | if (i == -1) { |
---|
427 | RETURN; |
---|
428 | } |
---|
429 | } |
---|
430 | |
---|
431 | /* Prune the modes marked as invalid */ |
---|
432 | xf86PruneDriverModes(pScrn); |
---|
433 | |
---|
434 | if (i == 0 || pScrn->modes == NULL) { |
---|
435 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes found\n"); |
---|
436 | RETURN; |
---|
437 | } |
---|
438 | |
---|
439 | /* |
---|
440 | * Set the CRTC parameters for all of the modes based on the type |
---|
441 | * of mode, and the chipset's interlace requirements. |
---|
442 | * |
---|
443 | * Calling this is required if the mode->Crtc* values are used by the |
---|
444 | * driver and if the driver doesn't provide code to set them. They |
---|
445 | * are not pre-initialised at all. |
---|
446 | */ |
---|
447 | xf86SetCrtcForModes(pScrn, 0); |
---|
448 | |
---|
449 | /* Set the current mode to the first in the list */ |
---|
450 | pScrn->currentMode = pScrn->modes; |
---|
451 | |
---|
452 | /* Print the list of modes being used */ |
---|
453 | xf86PrintModes(pScrn); |
---|
454 | |
---|
455 | /* If monitor resolution is set on the command line, use it */ |
---|
456 | xf86SetDpi(pScrn, 0, 0); |
---|
457 | |
---|
458 | if (xf86LoadSubModule(pScrn, "fb") == NULL) { |
---|
459 | RETURN; |
---|
460 | } |
---|
461 | |
---|
462 | if (!dPtr->swCursor) { |
---|
463 | if (!xf86LoadSubModule(pScrn, "ramdac")) { |
---|
464 | RETURN; |
---|
465 | } |
---|
466 | } |
---|
467 | |
---|
468 | /* We have no contiguous physical fb in physical memory */ |
---|
469 | pScrn->memPhysBase = 0; |
---|
470 | pScrn->fbOffset = 0; |
---|
471 | |
---|
472 | return TRUE; |
---|
473 | } |
---|
474 | #undef RETURN |
---|
475 | |
---|
476 | /* Mandatory */ |
---|
477 | static Bool |
---|
478 | DUMMYEnterVT(VT_FUNC_ARGS_DECL) |
---|
479 | { |
---|
480 | SCRN_INFO_PTR(arg); |
---|
481 | |
---|
482 | /* Should we re-save the text mode on each VT enter? */ |
---|
483 | if(!dummyModeInit(pScrn, pScrn->currentMode)) { |
---|
484 | return FALSE; |
---|
485 | } |
---|
486 | |
---|
487 | DUMMYAdjustFrame(ADJUST_FRAME_ARGS(pScrn, pScrn->frameX0, pScrn->frameY0)); |
---|
488 | return TRUE; |
---|
489 | } |
---|
490 | |
---|
491 | /* Mandatory */ |
---|
492 | static void |
---|
493 | DUMMYLeaveVT(VT_FUNC_ARGS_DECL) |
---|
494 | { |
---|
495 | SCRN_INFO_PTR(arg); |
---|
496 | dummyRestore(pScrn, TRUE); |
---|
497 | } |
---|
498 | |
---|
499 | static void |
---|
500 | DUMMYLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, |
---|
501 | LOCO *colors, VisualPtr pVisual) |
---|
502 | { |
---|
503 | int i, index, shift, Gshift; |
---|
504 | DUMMYPtr dPtr = DUMMYPTR(pScrn); |
---|
505 | |
---|
506 | switch(pScrn->depth) { |
---|
507 | case 15: |
---|
508 | shift = Gshift = 1; |
---|
509 | break; |
---|
510 | case 16: |
---|
511 | shift = 0; |
---|
512 | Gshift = 0; |
---|
513 | break; |
---|
514 | default: |
---|
515 | shift = Gshift = 0; |
---|
516 | break; |
---|
517 | } |
---|
518 | |
---|
519 | for(i = 0; i < numColors; i++) { |
---|
520 | index = indices[i]; |
---|
521 | dPtr->colors[index].red = colors[index].red << shift; |
---|
522 | dPtr->colors[index].green = colors[index].green << Gshift; |
---|
523 | dPtr->colors[index].blue = colors[index].blue << shift; |
---|
524 | } |
---|
525 | } |
---|
526 | |
---|
527 | static ScrnInfoPtr DUMMYScrn; /* static-globalize it */ |
---|
528 | |
---|
529 | /* Mandatory */ |
---|
530 | static Bool |
---|
531 | DUMMYScreenInit(SCREEN_INIT_ARGS_DECL) |
---|
532 | { |
---|
533 | ScrnInfoPtr pScrn; |
---|
534 | DUMMYPtr dPtr; |
---|
535 | int ret; |
---|
536 | VisualPtr visual; |
---|
537 | |
---|
538 | /* |
---|
539 | * we need to get the ScrnInfoRec for this screen, so let's allocate |
---|
540 | * one first thing |
---|
541 | */ |
---|
542 | pScrn = xf86ScreenToScrn(pScreen); |
---|
543 | dPtr = DUMMYPTR(pScrn); |
---|
544 | DUMMYScrn = pScrn; |
---|
545 | |
---|
546 | if (!(dPtr->FBBase = malloc(pScrn->videoRam * 1024))) { |
---|
547 | return FALSE; |
---|
548 | } |
---|
549 | |
---|
550 | /* |
---|
551 | * next we save the current state and setup the first mode |
---|
552 | */ |
---|
553 | dummySave(pScrn); |
---|
554 | |
---|
555 | if (!dummyModeInit(pScrn,pScrn->currentMode)) { |
---|
556 | return FALSE; |
---|
557 | } |
---|
558 | DUMMYAdjustFrame(ADJUST_FRAME_ARGS(pScrn, pScrn->frameX0, pScrn->frameY0)); |
---|
559 | |
---|
560 | /* |
---|
561 | * Reset visual list. |
---|
562 | */ |
---|
563 | miClearVisualTypes(); |
---|
564 | |
---|
565 | /* Setup the visuals we support. */ |
---|
566 | |
---|
567 | if (!miSetVisualTypes(pScrn->depth, |
---|
568 | miGetDefaultVisualMask(pScrn->depth), |
---|
569 | pScrn->rgbBits, pScrn->defaultVisual)) { |
---|
570 | return FALSE; |
---|
571 | } |
---|
572 | |
---|
573 | if (!miSetPixmapDepths ()) { |
---|
574 | return FALSE; |
---|
575 | } |
---|
576 | |
---|
577 | /* |
---|
578 | * Call the framebuffer layer's ScreenInit function, and fill in other |
---|
579 | * pScreen fields. |
---|
580 | */ |
---|
581 | ret = fbScreenInit(pScreen, dPtr->FBBase, |
---|
582 | pScrn->virtualX, pScrn->virtualY, |
---|
583 | pScrn->xDpi, pScrn->yDpi, |
---|
584 | pScrn->displayWidth, pScrn->bitsPerPixel); |
---|
585 | if (!ret) { |
---|
586 | return FALSE; |
---|
587 | } |
---|
588 | |
---|
589 | if (pScrn->depth > 8) { |
---|
590 | /* Fixup RGB ordering */ |
---|
591 | visual = pScreen->visuals + pScreen->numVisuals; |
---|
592 | while (--visual >= pScreen->visuals) { |
---|
593 | if ((visual->class | DynamicClass) == DirectColor) { |
---|
594 | visual->offsetRed = pScrn->offset.red; |
---|
595 | visual->offsetGreen = pScrn->offset.green; |
---|
596 | visual->offsetBlue = pScrn->offset.blue; |
---|
597 | visual->redMask = pScrn->mask.red; |
---|
598 | visual->greenMask = pScrn->mask.green; |
---|
599 | visual->blueMask = pScrn->mask.blue; |
---|
600 | } |
---|
601 | } |
---|
602 | } |
---|
603 | |
---|
604 | /* must be after RGB ordering fixed */ |
---|
605 | fbPictureInit(pScreen, 0, 0); |
---|
606 | |
---|
607 | xf86SetBlackWhitePixels(pScreen); |
---|
608 | |
---|
609 | #ifdef USE_DGA |
---|
610 | DUMMYDGAInit(pScreen); |
---|
611 | #endif |
---|
612 | |
---|
613 | if (dPtr->swCursor) { |
---|
614 | xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Using Software Cursor.\n"); |
---|
615 | } |
---|
616 | |
---|
617 | |
---|
618 | { |
---|
619 | BoxRec AvailFBArea; |
---|
620 | int lines = pScrn->videoRam * 1024 / |
---|
621 | (pScrn->displayWidth * (pScrn->bitsPerPixel >> 3)); |
---|
622 | AvailFBArea.x1 = 0; |
---|
623 | AvailFBArea.y1 = 0; |
---|
624 | AvailFBArea.x2 = pScrn->displayWidth; |
---|
625 | AvailFBArea.y2 = lines; |
---|
626 | xf86InitFBManager(pScreen, &AvailFBArea); |
---|
627 | |
---|
628 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, |
---|
629 | "Using %i scanlines of offscreen memory \n" |
---|
630 | , lines - pScrn->virtualY); |
---|
631 | } |
---|
632 | |
---|
633 | xf86SetBackingStore(pScreen); |
---|
634 | xf86SetSilkenMouse(pScreen); |
---|
635 | |
---|
636 | /* Initialise cursor functions */ |
---|
637 | miDCInitialize (pScreen, xf86GetPointerScreenFuncs()); |
---|
638 | |
---|
639 | |
---|
640 | if (!dPtr->swCursor) { |
---|
641 | /* HW cursor functions */ |
---|
642 | if (!DUMMYCursorInit(pScreen)) { |
---|
643 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR, |
---|
644 | "Hardware cursor initialization failed\n"); |
---|
645 | return FALSE; |
---|
646 | } |
---|
647 | } |
---|
648 | |
---|
649 | /* Initialise default colourmap */ |
---|
650 | if (!miCreateDefColormap(pScreen)) { |
---|
651 | return FALSE; |
---|
652 | } |
---|
653 | |
---|
654 | if (!xf86HandleColormaps(pScreen, 256, pScrn->rgbBits, |
---|
655 | DUMMYLoadPalette, NULL, |
---|
656 | CMAP_PALETTED_TRUECOLOR |
---|
657 | | CMAP_RELOAD_ON_MODE_SWITCH)) { |
---|
658 | return FALSE; |
---|
659 | } |
---|
660 | |
---|
661 | /* DUMMYInitVideo(pScreen); */ |
---|
662 | |
---|
663 | pScreen->SaveScreen = DUMMYSaveScreen; |
---|
664 | |
---|
665 | |
---|
666 | /* Wrap the current CloseScreen function */ |
---|
667 | dPtr->CloseScreen = pScreen->CloseScreen; |
---|
668 | pScreen->CloseScreen = DUMMYCloseScreen; |
---|
669 | |
---|
670 | /* Wrap the current CreateWindow function */ |
---|
671 | dPtr->CreateWindow = pScreen->CreateWindow; |
---|
672 | pScreen->CreateWindow = DUMMYCreateWindow; |
---|
673 | |
---|
674 | /* Report any unused options (only for the first generation) */ |
---|
675 | if (serverGeneration == 1) { |
---|
676 | xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); |
---|
677 | } |
---|
678 | |
---|
679 | return TRUE; |
---|
680 | } |
---|
681 | |
---|
682 | const char *XDPY_PROPERTY = "dummy-constant-xdpi"; |
---|
683 | const char *YDPY_PROPERTY = "dummy-constant-ydpi"; |
---|
684 | static int get_dpi_value(WindowPtr root, const char *property_name, int default_dpi) |
---|
685 | { |
---|
686 | PropertyPtr prop; |
---|
687 | Atom type_atom = MakeAtom("CARDINAL", 8, TRUE); |
---|
688 | Atom prop_atom = MakeAtom(property_name, strlen(property_name), FALSE); |
---|
689 | |
---|
690 | for (prop = wUserProps(root); prop; prop = prop->next) { |
---|
691 | if (prop->propertyName == prop_atom && prop->type == type_atom && prop->data) { |
---|
692 | int v = (int) (*((CARD32 *) prop->data)); |
---|
693 | if ((v>0) && (v<4096)) { |
---|
694 | xf86DrvMsg(0, X_INFO, "get_constant_dpi_value() found property \"%s\" with value=%i\n", property_name, (int) v); |
---|
695 | return (int) v; |
---|
696 | } |
---|
697 | break; |
---|
698 | } |
---|
699 | } |
---|
700 | return default_dpi; |
---|
701 | } |
---|
702 | |
---|
703 | /* Mandatory */ |
---|
704 | Bool |
---|
705 | DUMMYSwitchMode(SWITCH_MODE_ARGS_DECL) |
---|
706 | { |
---|
707 | SCRN_INFO_PTR(arg); |
---|
708 | if (!dummyModeInit(pScrn, mode)) { |
---|
709 | return FALSE; |
---|
710 | } |
---|
711 | #ifdef RANDR |
---|
712 | DUMMYPtr dPtr = DUMMYPTR(pScrn); |
---|
713 | if (dPtr->constantDPI) { |
---|
714 | int xDpi = get_dpi_value(pScrn->pScreen->root, XDPY_PROPERTY, pScrn->xDpi); |
---|
715 | int yDpi = get_dpi_value(pScrn->pScreen->root, YDPY_PROPERTY, pScrn->yDpi); |
---|
716 | //25.4 mm per inch: (254/10) |
---|
717 | pScrn->pScreen->mmWidth = mode->HDisplay * 254 / xDpi / 10; |
---|
718 | pScrn->pScreen->mmHeight = mode->VDisplay * 254 / yDpi / 10; |
---|
719 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "mm(dpi %ix%i)=%ix%i\n", xDpi, yDpi, pScrn->pScreen->mmWidth, pScrn->pScreen->mmHeight); |
---|
720 | RRScreenSizeNotify(pScrn->pScreen); |
---|
721 | RRTellChanged(pScrn->pScreen); |
---|
722 | } |
---|
723 | #endif |
---|
724 | return TRUE; |
---|
725 | } |
---|
726 | |
---|
727 | /* Mandatory */ |
---|
728 | void |
---|
729 | DUMMYAdjustFrame(ADJUST_FRAME_ARGS_DECL) |
---|
730 | { |
---|
731 | SCRN_INFO_PTR(arg); |
---|
732 | int Base; |
---|
733 | |
---|
734 | Base = (y * pScrn->displayWidth + x) >> 2; |
---|
735 | |
---|
736 | /* Scale Base by the number of bytes per pixel. */ |
---|
737 | switch (pScrn->depth) { |
---|
738 | case 8 : |
---|
739 | break; |
---|
740 | case 15 : |
---|
741 | case 16 : |
---|
742 | Base *= 2; |
---|
743 | break; |
---|
744 | case 24 : |
---|
745 | Base *= 3; |
---|
746 | break; |
---|
747 | default : |
---|
748 | break; |
---|
749 | } |
---|
750 | } |
---|
751 | |
---|
752 | /* Mandatory */ |
---|
753 | static Bool |
---|
754 | DUMMYCloseScreen(CLOSE_SCREEN_ARGS_DECL) |
---|
755 | { |
---|
756 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); |
---|
757 | DUMMYPtr dPtr = DUMMYPTR(pScrn); |
---|
758 | |
---|
759 | if (pScrn->vtSema) { |
---|
760 | dummyRestore(pScrn, TRUE); |
---|
761 | free(dPtr->FBBase); |
---|
762 | } |
---|
763 | |
---|
764 | if (dPtr->CursorInfo) { |
---|
765 | xf86DestroyCursorInfoRec(dPtr->CursorInfo); |
---|
766 | } |
---|
767 | |
---|
768 | pScrn->vtSema = FALSE; |
---|
769 | pScreen->CloseScreen = dPtr->CloseScreen; |
---|
770 | return (*pScreen->CloseScreen)(CLOSE_SCREEN_ARGS); |
---|
771 | } |
---|
772 | |
---|
773 | /* Optional */ |
---|
774 | static void |
---|
775 | DUMMYFreeScreen(FREE_SCREEN_ARGS_DECL) |
---|
776 | { |
---|
777 | SCRN_INFO_PTR(arg); |
---|
778 | DUMMYFreeRec(pScrn); |
---|
779 | } |
---|
780 | |
---|
781 | static Bool |
---|
782 | DUMMYSaveScreen(ScreenPtr pScreen, int mode) |
---|
783 | { |
---|
784 | ScrnInfoPtr pScrn = NULL; |
---|
785 | DUMMYPtr dPtr; |
---|
786 | |
---|
787 | if (pScreen != NULL) { |
---|
788 | pScrn = xf86ScreenToScrn(pScreen); |
---|
789 | dPtr = DUMMYPTR(pScrn); |
---|
790 | |
---|
791 | dPtr->screenSaver = xf86IsUnblank(mode); |
---|
792 | } |
---|
793 | return TRUE; |
---|
794 | } |
---|
795 | |
---|
796 | /* Optional */ |
---|
797 | static ModeStatus |
---|
798 | DUMMYValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags) |
---|
799 | { |
---|
800 | return(MODE_OK); |
---|
801 | } |
---|
802 | |
---|
803 | static void |
---|
804 | dummySave(ScrnInfoPtr pScrn) |
---|
805 | { |
---|
806 | } |
---|
807 | |
---|
808 | static void |
---|
809 | dummyRestore(ScrnInfoPtr pScrn, Bool restoreText) |
---|
810 | { |
---|
811 | } |
---|
812 | |
---|
813 | static Bool |
---|
814 | dummyModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode) |
---|
815 | { |
---|
816 | dummyRestore(pScrn, FALSE); |
---|
817 | |
---|
818 | return(TRUE); |
---|
819 | } |
---|
820 | |
---|
821 | Atom VFB_PROP = 0; |
---|
822 | #define VFB_PROP_NAME "VFB_IDENT" |
---|
823 | |
---|
824 | static Bool |
---|
825 | DUMMYCreateWindow(WindowPtr pWin) |
---|
826 | { |
---|
827 | ScreenPtr pScreen = pWin->drawable.pScreen; |
---|
828 | DUMMYPtr dPtr = DUMMYPTR(DUMMYScrn); |
---|
829 | WindowPtr pWinRoot; |
---|
830 | int ret; |
---|
831 | |
---|
832 | pScreen->CreateWindow = dPtr->CreateWindow; |
---|
833 | ret = pScreen->CreateWindow(pWin); |
---|
834 | dPtr->CreateWindow = pScreen->CreateWindow; |
---|
835 | pScreen->CreateWindow = DUMMYCreateWindow; |
---|
836 | |
---|
837 | if (ret != TRUE) { |
---|
838 | return(ret); |
---|
839 | } |
---|
840 | |
---|
841 | if (dPtr->prop == FALSE) { |
---|
842 | #if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 8 |
---|
843 | pWinRoot = WindowTable[DUMMYScrn->pScreen->myNum]; |
---|
844 | #else |
---|
845 | pWinRoot = DUMMYScrn->pScreen->root; |
---|
846 | #endif |
---|
847 | if (!ValidAtom(VFB_PROP)) { |
---|
848 | VFB_PROP = MakeAtom(VFB_PROP_NAME, strlen(VFB_PROP_NAME), 1); |
---|
849 | } |
---|
850 | |
---|
851 | ret = ChangeWindowProperty(pWinRoot, VFB_PROP, XA_STRING, |
---|
852 | 8, PropModeReplace, (int)4, (pointer)"TRUE", FALSE); |
---|
853 | if (ret != Success) { |
---|
854 | ErrorF("Could not set VFB root window property"); |
---|
855 | } |
---|
856 | dPtr->prop = TRUE; |
---|
857 | } |
---|
858 | return TRUE; |
---|
859 | } |
---|
860 | |
---|
861 | #ifndef HW_SKIP_CONSOLE |
---|
862 | #define HW_SKIP_CONSOLE 4 |
---|
863 | #endif |
---|
864 | |
---|
865 | static Bool |
---|
866 | dummyDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, pointer ptr) |
---|
867 | { |
---|
868 | CARD32 *flag; |
---|
869 | |
---|
870 | switch (op) { |
---|
871 | case GET_REQUIRED_HW_INTERFACES: |
---|
872 | flag = (CARD32*)ptr; |
---|
873 | (*flag) = HW_SKIP_CONSOLE; |
---|
874 | return TRUE; |
---|
875 | default: |
---|
876 | return FALSE; |
---|
877 | } |
---|
878 | } |
---|