VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/xgraphics/vboxvideo_68.c@ 6356

Last change on this file since 6356 was 6202, checked in by vboxsync, 17 years ago

re-export x11

File size: 38.8 KB
Line 
1/** @file
2 *
3 * Linux Additions X11 graphics driver
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 * --------------------------------------------------------------------
17 *
18 * This code is based on:
19 *
20 * X11 VESA driver
21 *
22 * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com)
23 *
24 * Permission is hereby granted, free of charge, to any person obtaining a
25 * copy of this software and associated documentation files (the "Software"),
26 * to deal in the Software without restriction, including without limitation
27 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
28 * and/or sell copies of the Software, and to permit persons to whom the
29 * Software is furnished to do so, subject to the following conditions:
30 *
31 * The above copyright notice and this permission notice shall be included in
32 * all copies or substantial portions of the Software.
33 *
34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
37 * CONECTIVA LINUX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
38 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
39 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40 * SOFTWARE.
41 *
42 * Except as contained in this notice, the name of Conectiva Linux shall
43 * not be used in advertising or otherwise to promote the sale, use or other
44 * dealings in this Software without prior written authorization from
45 * Conectiva Linux.
46 *
47 * Authors: Paulo César Pereira de Andrade <pcpa@conectiva.com.br>
48 */
49
50#define DEBUG_VERB 2
51
52#include "vboxvideo.h"
53#include "version-generated.h"
54
55/* All drivers initialising the SW cursor need this */
56#include "mipointer.h"
57
58/* All drivers implementing backing store need this */
59#include "mibstore.h"
60
61/* Colormap handling */
62#include "micmap.h"
63#include "xf86cmap.h"
64
65/* DPMS */
66/* #define DPMS_SERVER
67#include "extensions/dpms.h" */
68
69/* Mandatory functions */
70
71static const OptionInfoRec * VBOXAvailableOptions(int chipid, int busid);
72static void VBOXIdentify(int flags);
73static Bool VBOXProbe(DriverPtr drv, int flags);
74static Bool VBOXPreInit(ScrnInfoPtr pScrn, int flags);
75static Bool VBOXScreenInit(int Index, ScreenPtr pScreen, int argc,
76 char **argv);
77static Bool VBOXEnterVT(int scrnIndex, int flags);
78static void VBOXLeaveVT(int scrnIndex, int flags);
79static Bool VBOXCloseScreen(int scrnIndex, ScreenPtr pScreen);
80static Bool VBOXSaveScreen(ScreenPtr pScreen, int mode);
81static Bool VBOXSwitchMode(int scrnIndex, DisplayModePtr pMode, int flags);
82static Bool VBOXSetMode(ScrnInfoPtr pScrn, DisplayModePtr pMode);
83static void VBOXAdjustFrame(int scrnIndex, int x, int y, int flags);
84static void VBOXFreeScreen(int scrnIndex, int flags);
85static void VBOXFreeRec(ScrnInfoPtr pScrn);
86static void VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode,
87 int flags);
88
89/* locally used functions */
90static Bool VBOXMapVidMem(ScrnInfoPtr pScrn);
91static void VBOXUnmapVidMem(ScrnInfoPtr pScrn);
92static void VBOXLoadPalette(ScrnInfoPtr pScrn, int numColors,
93 int *indices,
94 LOCO *colors, VisualPtr pVisual);
95static void SaveFonts(ScrnInfoPtr pScrn);
96static void RestoreFonts(ScrnInfoPtr pScrn);
97static Bool VBOXSaveRestore(ScrnInfoPtr pScrn,
98 vbeSaveRestoreFunction function);
99
100/* Initialise DGA */
101
102static Bool VBOXDGAInit(ScrnInfoPtr pScrn, ScreenPtr pScreen);
103
104/*
105 * This contains the functions needed by the server after loading the
106 * driver module. It must be supplied, and gets added the driver list by
107 * the Module Setup funtion in the dynamic case. In the static case a
108 * reference to this is compiled in, and this requires that the name of
109 * this DriverRec be an upper-case version of the driver name.
110 */
111
112DriverRec VBOXDRV = {
113 VBOX_VERSION,
114 VBOX_DRIVER_NAME,
115 VBOXIdentify,
116 VBOXProbe,
117 VBOXAvailableOptions,
118 NULL,
119 0
120};
121
122/* Supported chipsets */
123static SymTabRec VBOXChipsets[] =
124{
125 {VBOX_VESA_DEVICEID, "vbox"},
126 {-1, NULL}
127};
128
129static PciChipsets VBOXPCIchipsets[] = {
130 { VBOX_DEVICEID, VBOX_DEVICEID, RES_SHARED_VGA },
131 { -1, -1, RES_UNDEFINED },
132};
133
134typedef enum {
135 OPTION_SHADOW_FB
136} VBOXOpts;
137
138/* No options for now */
139static const OptionInfoRec VBOXOptions[] = {
140 { -1, NULL, OPTV_NONE, {0}, FALSE }
141};
142
143/*
144 * List of symbols from other modules that this module references. This
145 * list is used to tell the loader that it is OK for symbols here to be
146 * unresolved providing that it hasn't been told that they haven't been
147 * told that they are essential via a call to xf86LoaderReqSymbols() or
148 * xf86LoaderReqSymLists(). The purpose is this is to avoid warnings about
149 * unresolved symbols that are not required.
150 */
151static const char *fbSymbols[] = {
152 "fbPictureInit",
153 "fbScreenInit",
154 NULL
155};
156
157static const char *shadowfbSymbols[] = {
158 "ShadowFBInit2",
159 NULL
160};
161
162static const char *vbeSymbols[] = {
163 "VBEFreeModeInfo",
164 "VBEGetModeInfo",
165 "VBEGetVBEInfo",
166 "VBEGetVBEMode",
167 "VBEInit",
168 "VBESaveRestore",
169 "VBESetDisplayStart",
170 "VBESetGetDACPaletteFormat",
171 "VBESetGetLogicalScanlineLength",
172 "VBESetGetPaletteData",
173 "VBESetVBEMode",
174 "vbeDoEDID",
175 "vbeFree",
176 NULL
177};
178
179static const char *ramdacSymbols[] = {
180 "xf86InitCursor",
181 "xf86CreateCursorInfoRec",
182 NULL
183};
184
185#ifdef XFree86LOADER
186/* Module loader interface */
187static MODULESETUPPROTO(vboxSetup);
188
189static XF86ModuleVersionInfo vboxVersionRec =
190{
191 VBOX_DRIVER_NAME,
192 "innotek GmbH",
193 MODINFOSTRING1,
194 MODINFOSTRING2,
195 XF86_VERSION_CURRENT,
196 1, /* Module major version. Xorg-specific */
197 0, /* Module minor version. Xorg-specific */
198 0, /* Module patchlevel. Xorg-specific */
199 ABI_CLASS_VIDEODRV, /* This is a video driver */
200 ABI_VIDEODRV_VERSION,
201 MOD_CLASS_VIDEODRV,
202 {0, 0, 0, 0}
203};
204
205/*
206 * This data is accessed by the loader. The name must be the module name
207 * followed by "ModuleData".
208 */
209XF86ModuleData vboxvideoModuleData = { &vboxVersionRec, vboxSetup, NULL };
210
211static pointer
212vboxSetup(pointer Module, pointer Options, int *ErrorMajor, int *ErrorMinor)
213{
214 static Bool Initialised = FALSE;
215
216 if (!Initialised)
217 {
218 Initialised = TRUE;
219 xf86AddDriver(&VBOXDRV, Module, 0);
220 LoaderRefSymLists(fbSymbols,
221 shadowfbSymbols,
222 vbeSymbols,
223 ramdacSymbols,
224 NULL);
225 return (pointer)TRUE;
226 }
227
228 if (ErrorMajor)
229 *ErrorMajor = LDR_ONCEONLY;
230 return (NULL);
231}
232
233#endif /* XFree86Loader defined */
234
235static const OptionInfoRec *
236VBOXAvailableOptions(int chipid, int busid)
237{
238 return (VBOXOptions);
239}
240
241static void
242VBOXIdentify(int flags)
243{
244 xf86PrintChipsets(VBOX_NAME, "guest driver for VirtualBox", VBOXChipsets);
245}
246
247/*
248 * This function is called once, at the start of the first server generation to
249 * do a minimal probe for supported hardware.
250 */
251
252static Bool
253VBOXProbe(DriverPtr drv, int flags)
254{
255 Bool foundScreen = FALSE;
256 int numDevSections, numUsed;
257 GDevPtr *devSections;
258 int *usedChips;
259 int i;
260
261 /*
262 * Find the config file Device sections that match this
263 * driver, and return if there are none.
264 */
265 if ((numDevSections = xf86MatchDevice(VBOX_NAME,
266 &devSections)) <= 0)
267 return (FALSE);
268
269 /* PCI BUS */
270 if (xf86GetPciVideoInfo()) {
271 numUsed = xf86MatchPciInstances(VBOX_NAME, VBOX_VENDORID,
272 VBOXChipsets, VBOXPCIchipsets,
273 devSections, numDevSections,
274 drv, &usedChips);
275 if (numUsed > 0) {
276 if (flags & PROBE_DETECT)
277 foundScreen = TRUE;
278 else {
279 for (i = 0; i < numUsed; i++) {
280 ScrnInfoPtr pScrn = NULL;
281 /* Allocate a ScrnInfoRec */
282 if ((pScrn = xf86ConfigPciEntity(pScrn,0,usedChips[i],
283 VBOXPCIchipsets,NULL,
284 NULL,NULL,NULL,NULL))) {
285 pScrn->driverVersion = VBOX_VERSION;
286 pScrn->driverName = VBOX_DRIVER_NAME;
287 pScrn->name = VBOX_NAME;
288 pScrn->Probe = VBOXProbe;
289 pScrn->PreInit = VBOXPreInit;
290 pScrn->ScreenInit = VBOXScreenInit;
291 pScrn->SwitchMode = VBOXSwitchMode;
292 pScrn->AdjustFrame = VBOXAdjustFrame;
293 pScrn->EnterVT = VBOXEnterVT;
294 pScrn->LeaveVT = VBOXLeaveVT;
295 pScrn->FreeScreen = VBOXFreeScreen;
296 foundScreen = TRUE;
297 }
298 }
299 }
300 xfree(usedChips);
301 }
302 }
303 xfree(devSections);
304
305 return (foundScreen);
306}
307
308static VBOXPtr
309VBOXGetRec(ScrnInfoPtr pScrn)
310{
311 if (!pScrn->driverPrivate)
312 {
313 pScrn->driverPrivate = xcalloc(sizeof(VBOXRec), 1);
314 ((VBOXPtr)pScrn->driverPrivate)->vbox_fd = -1;
315 }
316
317 return ((VBOXPtr)pScrn->driverPrivate);
318}
319
320static void
321VBOXFreeRec(ScrnInfoPtr pScrn)
322{
323 VBOXPtr pVBox = VBOXGetRec(pScrn);
324#if 0
325 xfree(pVBox->vbeInfo);
326#endif
327 xfree(pVBox->savedPal);
328 xfree(pVBox->fonts);
329 xfree(pScrn->driverPrivate);
330 pScrn->driverPrivate = NULL;
331}
332
333/*
334 * QUOTE from the XFree86 DESIGN document:
335 *
336 * The purpose of this function is to find out all the information
337 * required to determine if the configuration is usable, and to initialise
338 * those parts of the ScrnInfoRec that can be set once at the beginning of
339 * the first server generation.
340 *
341 * (...)
342 *
343 * This includes probing for video memory, clocks, ramdac, and all other
344 * HW info that is needed. It includes determining the depth/bpp/visual
345 * and related info. It includes validating and determining the set of
346 * video modes that will be used (and anything that is required to
347 * determine that).
348 *
349 * This information should be determined in the least intrusive way
350 * possible. The state of the HW must remain unchanged by this function.
351 * Although video memory (including MMIO) may be mapped within this
352 * function, it must be unmapped before returning.
353 *
354 * END QUOTE
355 */
356
357static Bool
358VBOXPreInit(ScrnInfoPtr pScrn, int flags)
359{
360 VBOXPtr pVBox;
361 Gamma gzeros = {0.0, 0.0, 0.0};
362 rgb rzeros = {0, 0, 0};
363 ClockRange *clockRanges;
364 int i;
365 DisplayModePtr m_prev;
366
367 /* Are we really starting the server, or is this just a dummy run? */
368 if (flags & PROBE_DETECT)
369 return (FALSE);
370
371 xf86Msg(X_INFO,
372 "VirtualBox guest additions video driver version "
373 VBOX_VERSION_STRING "\n");
374
375 /* Get our private data from the ScrnInfoRec structure. */
376 pVBox = VBOXGetRec(pScrn);
377
378 /* Entity information seems to mean bus information. */
379 pVBox->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
380 if (pVBox->pEnt->location.type != BUS_PCI)
381 return FALSE;
382
383 /* The ramdac module is needed for the hardware cursor. */
384 if (!xf86LoadSubModule(pScrn, "ramdac"))
385 return FALSE;
386 xf86LoaderReqSymLists(ramdacSymbols, NULL);
387
388 /* We need the vbe module because we use VBE code to save and restore
389 text mode, in order to keep our code simple. */
390 if (!xf86LoadSubModule(pScrn, "vbe"))
391 return (FALSE);
392 xf86LoaderReqSymLists(vbeSymbols, NULL);
393
394 /* The framebuffer module. */
395 if (xf86LoadSubModule(pScrn, "fb") == NULL)
396 return (FALSE);
397 xf86LoaderReqSymLists(fbSymbols, NULL);
398
399 if (!xf86LoadSubModule(pScrn, "shadowfb"))
400 return FALSE;
401 xf86LoaderReqSymLists(shadowfbSymbols, NULL);
402
403 pVBox->pciInfo = xf86GetPciInfoForEntity(pVBox->pEnt->index);
404 pVBox->pciTag = pciTag(pVBox->pciInfo->bus,
405 pVBox->pciInfo->device,
406 pVBox->pciInfo->func);
407
408 /* Set up our ScrnInfoRec structure to describe our virtual
409 capabilities to X. */
410
411 pScrn->rgbBits = 8;
412
413 /* Let's create a nice, capable virtual monitor. */
414 pScrn->monitor = pScrn->confScreen->monitor;
415 pScrn->monitor->DDC = NULL;
416 pScrn->monitor->nHsync = 1;
417 pScrn->monitor->hsync[0].lo = 1;
418 pScrn->monitor->hsync[0].hi = 10000;
419 pScrn->monitor->nVrefresh = 1;
420 pScrn->monitor->vrefresh[0].lo = 1;
421 pScrn->monitor->vrefresh[0].hi = 100;
422
423 pScrn->chipset = "vbox";
424 pScrn->progClock = TRUE;
425
426 /* Determine the size of the VBox video RAM from PCI data*/
427#if 0
428 pScrn->videoRam = 1 << pVBox->pciInfo->size[0];
429#endif
430 /* Using the PCI information caused problems with non-powers-of-two
431 sized video RAM configurations */
432 pScrn->videoRam = inl(VBE_DISPI_IOPORT_DATA) / 1024;
433
434 /* Set up clock information that will support all modes we need. */
435 clockRanges = xnfcalloc(sizeof(ClockRange), 1);
436 clockRanges->next = NULL;
437 clockRanges->minClock = 1000;
438 clockRanges->maxClock = 1000000000;
439 clockRanges->clockIndex = -1;
440 clockRanges->ClockMulFactor = 1;
441 clockRanges->ClockDivFactor = 1;
442
443 /* This function asks X to choose a depth and bpp based on the
444 config file and the command line, and gives a default in
445 case none is specified. Note that we only support 32bpp, not
446 24bpp. After spending ages looking through the XFree86 4.2
447 source code however, I realised that it automatically uses
448 32bpp for depth 24 unless you explicitly add a "24 24"
449 format to its internal list. */
450 if (!xf86SetDepthBpp(pScrn, pScrn->videoRam >= 2048 ? 24 : 16, 0, 0,
451 Support32bppFb))
452 return FALSE;
453 if (pScrn->depth != 24 && pScrn->depth != 16)
454 {
455 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
456 "The VBox additions only support 16 and 32bpp graphics modes\n");
457 return FALSE;
458 }
459 xf86PrintDepthBpp(pScrn);
460
461 /* Colour weight - we always call this, since we are always in
462 truecolour. */
463 if (!xf86SetWeight(pScrn, rzeros, rzeros))
464 return (FALSE);
465
466 /* visual init */
467 if (!xf86SetDefaultVisual(pScrn, -1))
468 return (FALSE);
469
470 xf86SetGamma(pScrn, gzeros);
471
472 /* To get around the problem of SUSE specifying a single, invalid mode in their
473 * Xorg.conf by default, we add an additional mode to the end of the user specified
474 * list. This means that if all user modes are invalid, X will try our mode before
475 * falling back to its standard mode list. */
476 if (pScrn->display->modes == NULL)
477 {
478 /* The user specified no modes at all - specify 1024x768 as a default. */
479 pScrn->display->modes = xnfalloc(4 * sizeof(char*));
480 pScrn->display->modes[0] = "1024x768";
481 pScrn->display->modes[1] = "800x600";
482 pScrn->display->modes[2] = "640x480";
483 pScrn->display->modes[3] = NULL;
484 }
485 else
486 {
487 /* Add 1024x768 to the end of the mode list in case the others are all invalid. */
488 for (i = 0; pScrn->display->modes[i] != NULL; i++);
489 pScrn->display->modes = xnfrealloc(pScrn->display->modes, (i + 4)
490 * sizeof(char *));
491 pScrn->display->modes[i ] = "1024x768";
492 pScrn->display->modes[i+1] = "800x600";
493 pScrn->display->modes[i+2] = "640x480";
494 pScrn->display->modes[i+3] = NULL;
495 }
496
497 /* Determine the virtual screen resolution from the first mode (which will be selected) */
498 sscanf(pScrn->display->modes[0], "%dx%d",
499 &pScrn->display->virtualX, &pScrn->display->virtualY);
500 pScrn->display->virtualX = (pScrn->display->virtualX + 7) & ~7;
501
502 /* Create a builtin mode for every specified mode. This allows to specify arbitrary
503 * screen resolutions */
504 m_prev = NULL;
505 for (i = 0; pScrn->display->modes[i] != NULL; i++)
506 {
507 DisplayModePtr m;
508 int x = 0, y = 0;
509
510 sscanf(pScrn->display->modes[i], "%dx%d", &x, &y);
511 /* sanity check, smaller resolutions does not make sense */
512 if (x < 64 || y < 64)
513 {
514 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Ignoring mode \"%s\"\n",
515 pScrn->display->modes[i]);
516 continue;
517 }
518 m = xnfcalloc(sizeof(DisplayModeRec), 1);
519 m->status = MODE_OK;
520 m->type = M_T_BUILTIN;
521 /* VBox does only support screen widths which are a multiple of 8 */
522 m->HDisplay = (x + 7) & ~7;
523 m->VDisplay = y;
524 m->name = strdup(pScrn->display->modes[i]);
525 if (!m_prev)
526 pScrn->modePool = m;
527 else
528 m_prev->next = m;
529 m->prev = m_prev;
530 m_prev = m;
531 }
532
533 /* Filter out video modes not supported by the virtual hardware
534 we described. All modes used by the Windows additions should
535 work fine. */
536 i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
537 pScrn->display->modes,
538 clockRanges, NULL, 0, 6400, 1, 0, 1440,
539 pScrn->display->virtualX,
540 pScrn->display->virtualY,
541 pScrn->videoRam, LOOKUP_BEST_REFRESH);
542
543 if (i <= 0) {
544 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No usable graphics modes found.\n");
545 return (FALSE);
546 }
547 xf86PruneDriverModes(pScrn);
548
549 pScrn->currentMode = pScrn->modes;
550 pScrn->displayWidth = pScrn->virtualX;
551
552 xf86PrintModes(pScrn);
553
554 /* Set display resolution. This was arbitrarily chosen to be about the same as my monitor. */
555 xf86SetDpi(pScrn, 100, 100);
556
557 if (pScrn->modes == NULL) {
558 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No graphics modes available\n");
559 return (FALSE);
560 }
561
562 /* options */
563 xf86CollectOptions(pScrn, NULL);
564 if (!(pVBox->Options = xalloc(sizeof(VBOXOptions))))
565 return FALSE;
566 memcpy(pVBox->Options, VBOXOptions, sizeof(VBOXOptions));
567 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pVBox->Options);
568
569 /* Framebuffer-related setup */
570 pScrn->bitmapBitOrder = BITMAP_BIT_ORDER;
571 return (TRUE);
572}
573
574/*
575 * QUOTE from the XFree86 DESIGN document:
576 *
577 * This is called at the start of each server generation.
578 *
579 * (...)
580 *
581 * Decide which operations need to be placed under resource access
582 * control. (...) Map any video memory or other memory regions. (...)
583 * Save the video card state. (...) Initialise the initial video
584 * mode.
585 *
586 * End QUOTE.Initialise the initial video mode.
587 */
588static Bool
589VBOXScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
590{
591 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
592 VBOXPtr pVBox = VBOXGetRec(pScrn);
593 VisualPtr visual;
594 unsigned flags;
595
596 /* We make use of the X11 VBE code to save and restore text mode, in
597 order to keep our code simple. */
598 if ((pVBox->pVbe = VBEInit(NULL, pVBox->pEnt->index)) == NULL)
599 return (FALSE);
600
601 if (pVBox->mapPhys == 0) {
602 pVBox->mapPhys = pVBox->pciInfo->memBase[0];
603/* pVBox->mapSize = 1 << pVBox->pciInfo->size[0]; */
604 /* Using the PCI information caused problems with
605 non-powers-of-two sized video RAM configurations */
606 pVBox->mapSize = inl(VBE_DISPI_IOPORT_DATA);
607 pVBox->mapOff = 0;
608 }
609
610 if (!VBOXMapVidMem(pScrn))
611 return (FALSE);
612
613 /* save current video state */
614 VBOXSaveRestore(pScrn, MODE_SAVE);
615 pVBox->savedPal = VBESetGetPaletteData(pVBox->pVbe, FALSE, 0, 256,
616 NULL, FALSE, FALSE);
617
618 /* set first video mode */
619 if (!VBOXSetMode(pScrn, pScrn->currentMode))
620 return FALSE;
621
622 /* mi layer - reset the visual list (?)*/
623 miClearVisualTypes();
624 if (!xf86SetDefaultVisual(pScrn, -1))
625 return (FALSE);
626 if (!miSetVisualTypes(pScrn->depth, TrueColorMask,
627 pScrn->rgbBits, TrueColor))
628 return (FALSE);
629 if (!miSetPixmapDepths())
630 return (FALSE);
631
632 /* I checked in the sources, and XFree86 4.2 does seem to support
633 this function for 32bpp. */
634 if (!fbScreenInit(pScreen, pVBox->base,
635 pScrn->virtualX, pScrn->virtualY,
636 pScrn->xDpi, pScrn->yDpi,
637 pScrn->displayWidth, pScrn->bitsPerPixel))
638 return (FALSE);
639
640 /* Fixup RGB ordering */
641 visual = pScreen->visuals + pScreen->numVisuals;
642 while (--visual >= pScreen->visuals) {
643 if ((visual->class | DynamicClass) == DirectColor) {
644 visual->offsetRed = pScrn->offset.red;
645 visual->offsetGreen = pScrn->offset.green;
646 visual->offsetBlue = pScrn->offset.blue;
647 visual->redMask = pScrn->mask.red;
648 visual->greenMask = pScrn->mask.green;
649 visual->blueMask = pScrn->mask.blue;
650 }
651 }
652
653 /* must be after RGB ordering fixed */
654 fbPictureInit(pScreen, 0, 0);
655
656 VBOXDGAInit(pScrn, pScreen);
657
658 xf86SetBlackWhitePixels(pScreen);
659 miInitializeBackingStore(pScreen);
660 xf86SetBackingStore(pScreen);
661
662 /* software cursor */
663 miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
664
665 /* colourmap code - apparently, we need this even in Truecolour */
666 if (!miCreateDefColormap(pScreen))
667 return (FALSE);
668
669 flags = CMAP_RELOAD_ON_MODE_SWITCH;
670
671 if(!xf86HandleColormaps(pScreen, 256,
672 8 /* DAC is switchable to 8 bits per primary color */,
673 VBOXLoadPalette, NULL, flags))
674 return (FALSE);
675
676 pVBox->CloseScreen = pScreen->CloseScreen;
677 pScreen->CloseScreen = VBOXCloseScreen;
678 pScreen->SaveScreen = VBOXSaveScreen;
679
680 /* However, we probably do want to support power management -
681 even if we just use a dummy function. */
682 xf86DPMSInit(pScreen, VBOXDisplayPowerManagementSet, 0);
683
684 /* Report any unused options (only for the first generation) */
685 if (serverGeneration == 1)
686 xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
687
688 if (vbox_open (pScrn, pScreen, pVBox)) {
689 if (vbox_cursor_init(pScreen) != TRUE)
690 xf86DrvMsg(scrnIndex, X_ERROR,
691 "Unable to start the VirtualBox mouse pointer integration with the host system.\n");
692 if (vboxEnableVbva(pScrn) == TRUE)
693 xf86DrvMsg(scrnIndex, X_INFO,
694 "The VBox video extensions are now enabled.\n");
695 } else
696 xf86DrvMsg(scrnIndex, X_ERROR, "Failed to open the VBox system device - make sure that the VirtualBox guest additions are properly installed. If you are not sure, try reinstalling them.\n");
697 return (TRUE);
698}
699
700static Bool
701VBOXEnterVT(int scrnIndex, int flags)
702{
703 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
704 VBOXPtr pVBox = VBOXGetRec(pScrn);
705
706 if (!VBOXSetMode(pScrn, pScrn->currentMode))
707 return FALSE;
708 if (pVBox->useVbva == TRUE)
709 vboxEnableVbva(pScrn);
710 return TRUE;
711}
712
713static void
714VBOXLeaveVT(int scrnIndex, int flags)
715{
716 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
717 VBOXPtr pVBox = VBOXGetRec(pScrn);
718
719 VBOXSaveRestore(pScrn, MODE_RESTORE);
720 if (pVBox->useVbva == TRUE)
721 vboxDisableVbva(pScrn);
722}
723
724static Bool
725VBOXCloseScreen(int scrnIndex, ScreenPtr pScreen)
726{
727 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
728 VBOXPtr pVBox = VBOXGetRec(pScrn);
729
730 if (pVBox->useVbva == TRUE)
731 vboxDisableVbva(pScrn);
732 if (pScrn->vtSema) {
733 VBOXSaveRestore(xf86Screens[scrnIndex], MODE_RESTORE);
734 VBESetGetPaletteData(pVBox->pVbe, TRUE, 0, 256,
735 pVBox->savedPal, FALSE, TRUE);
736 VBOXUnmapVidMem(pScrn);
737 }
738 if (pVBox->pDGAMode) {
739 xfree(pVBox->pDGAMode);
740 pVBox->pDGAMode = NULL;
741 pVBox->nDGAMode = 0;
742 }
743 pScrn->vtSema = FALSE;
744
745 pScreen->CloseScreen = pVBox->CloseScreen;
746 return pScreen->CloseScreen(scrnIndex, pScreen);
747}
748
749static Bool
750VBOXSwitchMode(int scrnIndex, DisplayModePtr pMode, int flags)
751{
752 ScrnInfoPtr pScrn;
753 VBOXPtr pVBox;
754
755 pScrn = xf86Screens[scrnIndex]; /* Why does X have three ways of refering to the screen? */
756 pVBox = VBOXGetRec(pScrn);
757 if (pVBox->useVbva == TRUE)
758 if (vboxDisableVbva(pScrn) != TRUE) /* This would be bad. */
759 return FALSE;
760 if (VBOXSetMode(pScrn, pMode) != TRUE)
761 return FALSE;
762 if (pVBox->useVbva == TRUE)
763 if (vboxEnableVbva(pScrn) != TRUE) /* Bad but not fatal */
764 pVBox->useVbva = FALSE;
765 return TRUE;
766}
767
768/* Set a graphics mode */
769static Bool
770VBOXSetMode(ScrnInfoPtr pScrn, DisplayModePtr pMode)
771{
772 VBOXPtr pVBox;
773
774 int bpp = pScrn->depth == 24 ? 32 : 16;
775 int xRes = pMode->HDisplay;
776 if (pScrn->virtualX * pScrn->virtualY * bpp / 8
777 >= pScrn->videoRam * 1024)
778 {
779 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
780 "Unable to set up a virtual screen size of %dx%d with %d Kb of video memory. Please increase the video memory size.\n",
781 pScrn->virtualX, pScrn->virtualY, pScrn->videoRam);
782 return FALSE;
783 }
784 /* We only support horizontal resolutions which are a multiple of 8. Round down if
785 necessary. */
786 if (xRes % 8 != 0)
787 {
788 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
789 "VirtualBox only supports screen widths which are a multiple of 8. Rounding down from %d to %d\n",
790 xRes, xRes - (xRes % 8));
791 xRes = xRes - (xRes % 8);
792 }
793 pVBox = VBOXGetRec(pScrn);
794 pScrn->vtSema = TRUE;
795 /* Disable linear framebuffer mode before making changes to the resolution. */
796 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ENABLE);
797 outw(VBE_DISPI_IOPORT_DATA,
798 VBE_DISPI_DISABLED);
799 /* Unlike the resolution, the depth is fixed for a given screen
800 for the lifetime of the X session. */
801 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_BPP);
802 outw(VBE_DISPI_IOPORT_DATA, bpp);
803 /* HDisplay and VDisplay are actually monitor information about
804 the display part of the scanlines. */
805 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_XRES);
806 outw(VBE_DISPI_IOPORT_DATA, xRes);
807 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_YRES);
808 outw(VBE_DISPI_IOPORT_DATA, pMode->VDisplay);
809 /* Enable linear framebuffer mode. */
810 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ENABLE);
811 outw(VBE_DISPI_IOPORT_DATA,
812 VBE_DISPI_ENABLED | VBE_DISPI_LFB_ENABLED);
813 /* Set the virtual resolution. We are still using VESA to control
814 the virtual offset. */
815 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_VIRT_WIDTH);
816 outw(VBE_DISPI_IOPORT_DATA, pScrn->displayWidth);
817 return (TRUE);
818}
819
820static void
821VBOXAdjustFrame(int scrnIndex, int x, int y, int flags)
822{
823 VBOXPtr pVBox = VBOXGetRec(xf86Screens[scrnIndex]);
824
825 VBESetDisplayStart(pVBox->pVbe, x, y, TRUE);
826}
827
828static void
829VBOXFreeScreen(int scrnIndex, int flags)
830{
831 VBOXFreeRec(xf86Screens[scrnIndex]);
832}
833
834static Bool
835VBOXMapVidMem(ScrnInfoPtr pScrn)
836{
837 VBOXPtr pVBox = VBOXGetRec(pScrn);
838
839 if (pVBox->base != NULL)
840 return (TRUE);
841
842 pScrn->memPhysBase = pVBox->mapPhys;
843 pScrn->fbOffset = pVBox->mapOff;
844
845 pVBox->base = xf86MapPciMem(pScrn->scrnIndex,
846 VIDMEM_FRAMEBUFFER,
847 pVBox->pciTag, pVBox->mapPhys,
848 (unsigned) pVBox->mapSize);
849
850 if (pVBox->base) {
851 pScrn->memPhysBase = pVBox->mapPhys;
852 pVBox->VGAbase = xf86MapVidMem(pScrn->scrnIndex, 0,
853 0xa0000, 0x10000);
854 }
855
856 return (pVBox->base != NULL);
857}
858
859static void
860VBOXUnmapVidMem(ScrnInfoPtr pScrn)
861{
862 VBOXPtr pVBox = VBOXGetRec(pScrn);
863
864 if (pVBox->base == NULL)
865 return;
866
867 xf86UnMapVidMem(pScrn->scrnIndex, pVBox->base,
868 (unsigned) pVBox->mapSize);
869 xf86UnMapVidMem(pScrn->scrnIndex, pVBox->VGAbase, 0x10000);
870 pVBox->base = NULL;
871}
872
873static void
874VBOXLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
875 LOCO *colors, VisualPtr pVisual)
876{
877#define WriteDacWriteAddr(value) outb(VGA_DAC_WRITE_ADDR, value)
878#define WriteDacData(value) outb(VGA_DAC_DATA, value);
879#undef DACDelay
880#define DACDelay() \
881 do { \
882 unsigned char temp = inb(VGA_IOBASE_COLOR + VGA_IN_STAT_1_OFFSET); \
883 temp = inb(VGA_IOBASE_COLOR + VGA_IN_STAT_1_OFFSET); \
884 } while (0)
885 int i, idx;
886
887 for (i = 0; i < numColors; i++) {
888 idx = indices[i];
889 WriteDacWriteAddr(idx);
890 DACDelay();
891 WriteDacData(colors[idx].red);
892 DACDelay();
893 WriteDacData(colors[idx].green);
894 DACDelay();
895 WriteDacData(colors[idx].blue);
896 DACDelay();
897 }
898}
899
900/*
901 * Just adapted from the std* functions in vgaHW.c
902 */
903static void
904WriteAttr(int index, int value)
905{
906 CARD8 tmp;
907
908 tmp = inb(VGA_IOBASE_COLOR + VGA_IN_STAT_1_OFFSET);
909
910 index |= 0x20;
911 outb(VGA_ATTR_INDEX, index);
912 outb(VGA_ATTR_DATA_W, value);
913}
914
915static int
916ReadAttr(int index)
917{
918 CARD8 tmp;
919
920 tmp = inb(VGA_IOBASE_COLOR + VGA_IN_STAT_1_OFFSET);
921
922 index |= 0x20;
923 outb(VGA_ATTR_INDEX, index);
924 return (inb(VGA_ATTR_DATA_R));
925}
926
927#define WriteMiscOut(value) outb(VGA_MISC_OUT_W, value)
928#define ReadMiscOut() inb(VGA_MISC_OUT_R)
929#define WriteSeq(index, value) \
930 outb(VGA_SEQ_INDEX, (index));\
931 outb(VGA_SEQ_DATA, value)
932
933static int
934ReadSeq(int index)
935{
936 outb(VGA_SEQ_INDEX, index);
937
938 return (inb(VGA_SEQ_DATA));
939}
940
941#define WriteGr(index, value) outb(VGA_GRAPH_INDEX, index);\
942 outb(VGA_GRAPH_DATA, value)
943
944static int
945ReadGr(int index)
946{
947 outb(VGA_GRAPH_INDEX, index);
948
949 return (inb(VGA_GRAPH_DATA));
950}
951
952#define WriteCrtc(index, value) outb(VGA_CRTC_INDEX_OFFSET, index);\
953 outb(VGA_CRTC_DATA_OFFSET, value)
954
955static void
956SeqReset(Bool start)
957{
958 if (start) {
959 WriteSeq(0x00, 0x01); /* Synchronous Reset */
960 }
961 else {
962 WriteSeq(0x00, 0x03); /* End Reset */
963 }
964}
965
966static void
967SaveFonts(ScrnInfoPtr pScrn)
968{
969 VBOXPtr pVBox = VBOXGetRec(pScrn);
970 unsigned char miscOut, attr10, gr4, gr5, gr6, seq2, seq4, scrn;
971
972 if (pVBox->fonts != NULL)
973 return;
974
975 /* If in graphics mode, don't save anything */
976 attr10 = ReadAttr(0x10);
977 if (attr10 & 0x01)
978 return;
979
980 pVBox->fonts = xalloc(16384);
981
982 /* save the registers that are needed here */
983 miscOut = ReadMiscOut();
984 gr4 = ReadGr(0x04);
985 gr5 = ReadGr(0x05);
986 gr6 = ReadGr(0x06);
987 seq2 = ReadSeq(0x02);
988 seq4 = ReadSeq(0x04);
989
990 /* Force into colour mode */
991 WriteMiscOut(miscOut | 0x01);
992
993 scrn = ReadSeq(0x01) | 0x20;
994 SeqReset(TRUE);
995 WriteSeq(0x01, scrn);
996 SeqReset(FALSE);
997
998 WriteAttr(0x10, 0x01); /* graphics mode */
999
1000 /*font1 */
1001 WriteSeq(0x02, 0x04); /* write to plane 2 */
1002 WriteSeq(0x04, 0x06); /* enable plane graphics */
1003 WriteGr(0x04, 0x02); /* read plane 2 */
1004 WriteGr(0x05, 0x00); /* write mode 0, read mode 0 */
1005 WriteGr(0x06, 0x05); /* set graphics */
1006 slowbcopy_frombus(pVBox->VGAbase, pVBox->fonts, 8192);
1007
1008 /* font2 */
1009 WriteSeq(0x02, 0x08); /* write to plane 3 */
1010 WriteSeq(0x04, 0x06); /* enable plane graphics */
1011 WriteGr(0x04, 0x03); /* read plane 3 */
1012 WriteGr(0x05, 0x00); /* write mode 0, read mode 0 */
1013 WriteGr(0x06, 0x05); /* set graphics */
1014 slowbcopy_frombus(pVBox->VGAbase, pVBox->fonts + 8192, 8192);
1015
1016 scrn = ReadSeq(0x01) & ~0x20;
1017 SeqReset(TRUE);
1018 WriteSeq(0x01, scrn);
1019 SeqReset(FALSE);
1020
1021 /* Restore clobbered registers */
1022 WriteAttr(0x10, attr10);
1023 WriteSeq(0x02, seq2);
1024 WriteSeq(0x04, seq4);
1025 WriteGr(0x04, gr4);
1026 WriteGr(0x05, gr5);
1027 WriteGr(0x06, gr6);
1028 WriteMiscOut(miscOut);
1029}
1030
1031static void
1032RestoreFonts(ScrnInfoPtr pScrn)
1033{
1034 VBOXPtr pVBox = VBOXGetRec(pScrn);
1035 unsigned char miscOut, attr10, gr1, gr3, gr4, gr5, gr6, gr8, seq2, seq4, scrn;
1036
1037 if (pVBox->fonts == NULL)
1038 return;
1039
1040 /* save the registers that are needed here */
1041 miscOut = ReadMiscOut();
1042 attr10 = ReadAttr(0x10);
1043 gr1 = ReadGr(0x01);
1044 gr3 = ReadGr(0x03);
1045 gr4 = ReadGr(0x04);
1046 gr5 = ReadGr(0x05);
1047 gr6 = ReadGr(0x06);
1048 gr8 = ReadGr(0x08);
1049 seq2 = ReadSeq(0x02);
1050 seq4 = ReadSeq(0x04);
1051
1052 /* Force into colour mode */
1053 WriteMiscOut(miscOut | 0x01);
1054
1055 scrn = ReadSeq(0x01) | 0x20;
1056 SeqReset(TRUE);
1057 WriteSeq(0x01, scrn);
1058 SeqReset(FALSE);
1059
1060 WriteAttr(0x10, 0x01); /* graphics mode */
1061 if (pScrn->depth == 4) {
1062 /* GJA */
1063 WriteGr(0x03, 0x00); /* don't rotate, write unmodified */
1064 WriteGr(0x08, 0xFF); /* write all bits in a byte */
1065 WriteGr(0x01, 0x00); /* all planes come from CPU */
1066 }
1067
1068 WriteSeq(0x02, 0x04); /* write to plane 2 */
1069 WriteSeq(0x04, 0x06); /* enable plane graphics */
1070 WriteGr(0x04, 0x02); /* read plane 2 */
1071 WriteGr(0x05, 0x00); /* write mode 0, read mode 0 */
1072 WriteGr(0x06, 0x05); /* set graphics */
1073 slowbcopy_tobus(pVBox->fonts, pVBox->VGAbase, 8192);
1074
1075 WriteSeq(0x02, 0x08); /* write to plane 3 */
1076 WriteSeq(0x04, 0x06); /* enable plane graphics */
1077 WriteGr(0x04, 0x03); /* read plane 3 */
1078 WriteGr(0x05, 0x00); /* write mode 0, read mode 0 */
1079 WriteGr(0x06, 0x05); /* set graphics */
1080 slowbcopy_tobus(pVBox->fonts + 8192, pVBox->VGAbase, 8192);
1081
1082 scrn = ReadSeq(0x01) & ~0x20;
1083 SeqReset(TRUE);
1084 WriteSeq(0x01, scrn);
1085 SeqReset(FALSE);
1086
1087 /* restore the registers that were changed */
1088 WriteMiscOut(miscOut);
1089 WriteAttr(0x10, attr10);
1090 WriteGr(0x01, gr1);
1091 WriteGr(0x03, gr3);
1092 WriteGr(0x04, gr4);
1093 WriteGr(0x05, gr5);
1094 WriteGr(0x06, gr6);
1095 WriteGr(0x08, gr8);
1096 WriteSeq(0x02, seq2);
1097 WriteSeq(0x04, seq4);
1098}
1099
1100static Bool
1101VBOXSaveScreen(ScreenPtr pScreen, int mode)
1102{
1103 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
1104 Bool on = xf86IsUnblank(mode);
1105
1106 if (on)
1107 SetTimeSinceLastInputEvent();
1108
1109 if (pScrn->vtSema) {
1110 unsigned char scrn = ReadSeq(0x01);
1111
1112 if (on)
1113 scrn &= ~0x20;
1114 else
1115 scrn |= 0x20;
1116 SeqReset(TRUE);
1117 WriteSeq(0x01, scrn);
1118 SeqReset(FALSE);
1119 }
1120
1121 return (TRUE);
1122}
1123
1124Bool
1125VBOXSaveRestore(ScrnInfoPtr pScrn, vbeSaveRestoreFunction function)
1126{
1127 VBOXPtr pVBox;
1128
1129 if (MODE_QUERY < 0 || function > MODE_RESTORE)
1130 return (FALSE);
1131
1132 pVBox = VBOXGetRec(pScrn);
1133
1134
1135 /* Query amount of memory to save state */
1136 if (function == MODE_QUERY ||
1137 (function == MODE_SAVE && pVBox->state == NULL))
1138 {
1139
1140 /* Make sure we save at least this information in case of failure */
1141 (void)VBEGetVBEMode(pVBox->pVbe, &pVBox->stateMode);
1142 SaveFonts(pScrn);
1143
1144 if (!VBESaveRestore(pVBox->pVbe,function,(pointer)&pVBox->state,
1145 &pVBox->stateSize,&pVBox->statePage))
1146 return FALSE;
1147 }
1148
1149 /* Save/Restore Super VGA state */
1150 if (function != MODE_QUERY) {
1151 Bool retval = TRUE;
1152
1153 if (function == MODE_RESTORE)
1154 memcpy(pVBox->state, pVBox->pstate,
1155 (unsigned) pVBox->stateSize);
1156
1157 if ((retval = VBESaveRestore(pVBox->pVbe,function,
1158 (pointer)&pVBox->state,
1159 &pVBox->stateSize,&pVBox->statePage))
1160 && function == MODE_SAVE)
1161 {
1162 /* don't rely on the memory not being touched */
1163 if (pVBox->pstate == NULL)
1164 pVBox->pstate = xalloc(pVBox->stateSize);
1165 memcpy(pVBox->pstate, pVBox->state,
1166 (unsigned) pVBox->stateSize);
1167 }
1168
1169 if (function == MODE_RESTORE)
1170 {
1171 VBESetVBEMode(pVBox->pVbe, pVBox->stateMode, NULL);
1172 RestoreFonts(pScrn);
1173 }
1174
1175 if (!retval)
1176 return (FALSE);
1177
1178 }
1179
1180 return (TRUE);
1181}
1182
1183static void
1184VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode,
1185 int flags)
1186{
1187 /* VBox is always power efficient... */
1188}
1189
1190
1191
1192
1193/***********************************************************************
1194 * DGA stuff
1195 ***********************************************************************/
1196static Bool VBOXDGAOpenFramebuffer(ScrnInfoPtr pScrn, char **DeviceName,
1197 unsigned char **ApertureBase,
1198 int *ApertureSize, int *ApertureOffset,
1199 int *flags);
1200static Bool VBOXDGASetMode(ScrnInfoPtr pScrn, DGAModePtr pDGAMode);
1201static void VBOXDGASetViewport(ScrnInfoPtr pScrn, int x, int y, int flags);
1202
1203static Bool
1204VBOXDGAOpenFramebuffer(ScrnInfoPtr pScrn, char **DeviceName,
1205 unsigned char **ApertureBase, int *ApertureSize,
1206 int *ApertureOffset, int *flags)
1207{
1208 VBOXPtr pVBox = VBOXGetRec(pScrn);
1209
1210 *DeviceName = NULL; /* No special device */
1211 *ApertureBase = (unsigned char *)(long)(pVBox->mapPhys);
1212 *ApertureSize = pVBox->mapSize;
1213 *ApertureOffset = pVBox->mapOff;
1214 *flags = DGA_NEED_ROOT;
1215
1216 return (TRUE);
1217}
1218
1219static Bool
1220VBOXDGASetMode(ScrnInfoPtr pScrn, DGAModePtr pDGAMode)
1221{
1222 DisplayModePtr pMode;
1223 int scrnIdx = pScrn->pScreen->myNum;
1224 int frameX0, frameY0;
1225
1226 if (pDGAMode) {
1227 pMode = pDGAMode->mode;
1228 frameX0 = frameY0 = 0;
1229 }
1230 else {
1231 if (!(pMode = pScrn->currentMode))
1232 return (TRUE);
1233
1234 frameX0 = pScrn->frameX0;
1235 frameY0 = pScrn->frameY0;
1236 }
1237
1238 if (!(*pScrn->SwitchMode)(scrnIdx, pMode, 0))
1239 return (FALSE);
1240 (*pScrn->AdjustFrame)(scrnIdx, frameX0, frameY0, 0);
1241
1242 return (TRUE);
1243}
1244
1245static void
1246VBOXDGASetViewport(ScrnInfoPtr pScrn, int x, int y, int flags)
1247{
1248 (*pScrn->AdjustFrame)(pScrn->pScreen->myNum, x, y, flags);
1249}
1250
1251static int
1252VBOXDGAGetViewport(ScrnInfoPtr pScrn)
1253{
1254 return (0);
1255}
1256
1257static DGAFunctionRec VBOXDGAFunctions =
1258{
1259 VBOXDGAOpenFramebuffer,
1260 NULL, /* CloseFramebuffer */
1261 VBOXDGASetMode,
1262 VBOXDGASetViewport,
1263 VBOXDGAGetViewport,
1264 NULL, /* Sync */
1265 NULL, /* FillRect */
1266 NULL, /* BlitRect */
1267 NULL, /* BlitTransRect */
1268};
1269
1270static void
1271VBOXDGAAddModes(ScrnInfoPtr pScrn)
1272{
1273 VBOXPtr pVBox = VBOXGetRec(pScrn);
1274 DisplayModePtr pMode = pScrn->modes;
1275 DGAModePtr pDGAMode;
1276
1277 do {
1278 pDGAMode = xrealloc(pVBox->pDGAMode,
1279 (pVBox->nDGAMode + 1) * sizeof(DGAModeRec));
1280 if (!pDGAMode)
1281 break;
1282
1283 pVBox->pDGAMode = pDGAMode;
1284 pDGAMode += pVBox->nDGAMode;
1285 (void)memset(pDGAMode, 0, sizeof(DGAModeRec));
1286
1287 ++pVBox->nDGAMode;
1288 pDGAMode->mode = pMode;
1289 pDGAMode->flags = DGA_CONCURRENT_ACCESS | DGA_PIXMAP_AVAILABLE;
1290 pDGAMode->byteOrder = pScrn->imageByteOrder;
1291 pDGAMode->depth = pScrn->depth;
1292 pDGAMode->bitsPerPixel = pScrn->bitsPerPixel;
1293 pDGAMode->red_mask = pScrn->mask.red;
1294 pDGAMode->green_mask = pScrn->mask.green;
1295 pDGAMode->blue_mask = pScrn->mask.blue;
1296 pDGAMode->visualClass = TrueColor;
1297 pDGAMode->xViewportStep = 1;
1298 pDGAMode->yViewportStep = 1;
1299 pDGAMode->viewportWidth = pMode->HDisplay;
1300 pDGAMode->viewportHeight = pMode->VDisplay;
1301
1302 pDGAMode->bytesPerScanline = pVBox->maxBytesPerScanline;
1303 pDGAMode->imageWidth = pMode->HDisplay;
1304 pDGAMode->imageHeight = pMode->VDisplay;
1305 pDGAMode->pixmapWidth = pDGAMode->imageWidth;
1306 pDGAMode->pixmapHeight = pDGAMode->imageHeight;
1307 pDGAMode->maxViewportX = pScrn->virtualX -
1308 pDGAMode->viewportWidth;
1309 pDGAMode->maxViewportY = pScrn->virtualY -
1310 pDGAMode->viewportHeight;
1311
1312 pDGAMode->address = pVBox->base;
1313
1314 pMode = pMode->next;
1315 } while (pMode != pScrn->modes);
1316}
1317
1318static Bool
1319VBOXDGAInit(ScrnInfoPtr pScrn, ScreenPtr pScreen)
1320{
1321 VBOXPtr pVBox = VBOXGetRec(pScrn);
1322
1323 if (!pVBox->nDGAMode)
1324 VBOXDGAAddModes(pScrn);
1325
1326 return (DGAInit(pScreen, &VBOXDGAFunctions,
1327 pVBox->pDGAMode, pVBox->nDGAMode));
1328}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette