~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xfree86/drivers/dummy/dummy_driver.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

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