VirtualBox

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

Last change on this file since 6675 was 6643, checked in by vboxsync, 17 years ago

Additions/x11: Disable unused vboxutils.c specific fields.

File size: 38.9 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 <[email protected]>
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#if 0
315 ((VBOXPtr)pScrn->driverPrivate)->vbox_fd = -1;
316#endif
317 }
318
319 return ((VBOXPtr)pScrn->driverPrivate);
320}
321
322static void
323VBOXFreeRec(ScrnInfoPtr pScrn)
324{
325 VBOXPtr pVBox = VBOXGetRec(pScrn);
326#if 0
327 xfree(pVBox->vbeInfo);
328#endif
329 xfree(pVBox->savedPal);
330 xfree(pVBox->fonts);
331 xfree(pScrn->driverPrivate);
332 pScrn->driverPrivate = NULL;
333}
334
335/*
336 * QUOTE from the XFree86 DESIGN document:
337 *
338 * The purpose of this function is to find out all the information
339 * required to determine if the configuration is usable, and to initialise
340 * those parts of the ScrnInfoRec that can be set once at the beginning of
341 * the first server generation.
342 *
343 * (...)
344 *
345 * This includes probing for video memory, clocks, ramdac, and all other
346 * HW info that is needed. It includes determining the depth/bpp/visual
347 * and related info. It includes validating and determining the set of
348 * video modes that will be used (and anything that is required to
349 * determine that).
350 *
351 * This information should be determined in the least intrusive way
352 * possible. The state of the HW must remain unchanged by this function.
353 * Although video memory (including MMIO) may be mapped within this
354 * function, it must be unmapped before returning.
355 *
356 * END QUOTE
357 */
358
359static Bool
360VBOXPreInit(ScrnInfoPtr pScrn, int flags)
361{
362 VBOXPtr pVBox;
363 Gamma gzeros = {0.0, 0.0, 0.0};
364 rgb rzeros = {0, 0, 0};
365 ClockRange *clockRanges;
366 int i;
367 DisplayModePtr m_prev;
368
369 /* Are we really starting the server, or is this just a dummy run? */
370 if (flags & PROBE_DETECT)
371 return (FALSE);
372
373 xf86Msg(X_INFO,
374 "VirtualBox guest additions video driver version "
375 VBOX_VERSION_STRING "\n");
376
377 /* Get our private data from the ScrnInfoRec structure. */
378 pVBox = VBOXGetRec(pScrn);
379
380 /* Entity information seems to mean bus information. */
381 pVBox->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
382 if (pVBox->pEnt->location.type != BUS_PCI)
383 return FALSE;
384
385 /* The ramdac module is needed for the hardware cursor. */
386 if (!xf86LoadSubModule(pScrn, "ramdac"))
387 return FALSE;
388 xf86LoaderReqSymLists(ramdacSymbols, NULL);
389
390 /* We need the vbe module because we use VBE code to save and restore
391 text mode, in order to keep our code simple. */
392 if (!xf86LoadSubModule(pScrn, "vbe"))
393 return (FALSE);
394 xf86LoaderReqSymLists(vbeSymbols, NULL);
395
396 /* The framebuffer module. */
397 if (xf86LoadSubModule(pScrn, "fb") == NULL)
398 return (FALSE);
399 xf86LoaderReqSymLists(fbSymbols, NULL);
400
401 if (!xf86LoadSubModule(pScrn, "shadowfb"))
402 return FALSE;
403 xf86LoaderReqSymLists(shadowfbSymbols, NULL);
404
405 pVBox->pciInfo = xf86GetPciInfoForEntity(pVBox->pEnt->index);
406 pVBox->pciTag = pciTag(pVBox->pciInfo->bus,
407 pVBox->pciInfo->device,
408 pVBox->pciInfo->func);
409
410 /* Set up our ScrnInfoRec structure to describe our virtual
411 capabilities to X. */
412
413 pScrn->rgbBits = 8;
414
415 /* Let's create a nice, capable virtual monitor. */
416 pScrn->monitor = pScrn->confScreen->monitor;
417 pScrn->monitor->DDC = NULL;
418 pScrn->monitor->nHsync = 1;
419 pScrn->monitor->hsync[0].lo = 1;
420 pScrn->monitor->hsync[0].hi = 10000;
421 pScrn->monitor->nVrefresh = 1;
422 pScrn->monitor->vrefresh[0].lo = 1;
423 pScrn->monitor->vrefresh[0].hi = 100;
424
425 pScrn->chipset = "vbox";
426 pScrn->progClock = TRUE;
427
428 /* Determine the size of the VBox video RAM from PCI data*/
429#if 0
430 pScrn->videoRam = 1 << pVBox->pciInfo->size[0];
431#endif
432 /* Using the PCI information caused problems with non-powers-of-two
433 sized video RAM configurations */
434 pScrn->videoRam = inl(VBE_DISPI_IOPORT_DATA) / 1024;
435
436 /* Set up clock information that will support all modes we need. */
437 clockRanges = xnfcalloc(sizeof(ClockRange), 1);
438 clockRanges->next = NULL;
439 clockRanges->minClock = 1000;
440 clockRanges->maxClock = 1000000000;
441 clockRanges->clockIndex = -1;
442 clockRanges->ClockMulFactor = 1;
443 clockRanges->ClockDivFactor = 1;
444
445 /* This function asks X to choose a depth and bpp based on the
446 config file and the command line, and gives a default in
447 case none is specified. Note that we only support 32bpp, not
448 24bpp. After spending ages looking through the XFree86 4.2
449 source code however, I realised that it automatically uses
450 32bpp for depth 24 unless you explicitly add a "24 24"
451 format to its internal list. */
452 if (!xf86SetDepthBpp(pScrn, pScrn->videoRam >= 2048 ? 24 : 16, 0, 0,
453 Support32bppFb))
454 return FALSE;
455 if (pScrn->depth != 24 && pScrn->depth != 16)
456 {
457 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
458 "The VBox additions only support 16 and 32bpp graphics modes\n");
459 return FALSE;
460 }
461 xf86PrintDepthBpp(pScrn);
462
463 /* Colour weight - we always call this, since we are always in
464 truecolour. */
465 if (!xf86SetWeight(pScrn, rzeros, rzeros))
466 return (FALSE);
467
468 /* visual init */
469 if (!xf86SetDefaultVisual(pScrn, -1))
470 return (FALSE);
471
472 xf86SetGamma(pScrn, gzeros);
473
474 /* To get around the problem of SUSE specifying a single, invalid mode in their
475 * Xorg.conf by default, we add an additional mode to the end of the user specified
476 * list. This means that if all user modes are invalid, X will try our mode before
477 * falling back to its standard mode list. */
478 if (pScrn->display->modes == NULL)
479 {
480 /* The user specified no modes at all - specify 1024x768 as a default. */
481 pScrn->display->modes = xnfalloc(4 * sizeof(char*));
482 pScrn->display->modes[0] = "1024x768";
483 pScrn->display->modes[1] = "800x600";
484 pScrn->display->modes[2] = "640x480";
485 pScrn->display->modes[3] = NULL;
486 }
487 else
488 {
489 /* Add 1024x768 to the end of the mode list in case the others are all invalid. */
490 for (i = 0; pScrn->display->modes[i] != NULL; i++);
491 pScrn->display->modes = xnfrealloc(pScrn->display->modes, (i + 4)
492 * sizeof(char *));
493 pScrn->display->modes[i ] = "1024x768";
494 pScrn->display->modes[i+1] = "800x600";
495 pScrn->display->modes[i+2] = "640x480";
496 pScrn->display->modes[i+3] = NULL;
497 }
498
499 /* Determine the virtual screen resolution from the first mode (which will be selected) */
500 sscanf(pScrn->display->modes[0], "%dx%d",
501 &pScrn->display->virtualX, &pScrn->display->virtualY);
502 pScrn->display->virtualX = (pScrn->display->virtualX + 7) & ~7;
503
504 /* Create a builtin mode for every specified mode. This allows to specify arbitrary
505 * screen resolutions */
506 m_prev = NULL;
507 for (i = 0; pScrn->display->modes[i] != NULL; i++)
508 {
509 DisplayModePtr m;
510 int x = 0, y = 0;
511
512 sscanf(pScrn->display->modes[i], "%dx%d", &x, &y);
513 /* sanity check, smaller resolutions does not make sense */
514 if (x < 64 || y < 64)
515 {
516 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Ignoring mode \"%s\"\n",
517 pScrn->display->modes[i]);
518 continue;
519 }
520 m = xnfcalloc(sizeof(DisplayModeRec), 1);
521 m->status = MODE_OK;
522 m->type = M_T_BUILTIN;
523 /* VBox does only support screen widths which are a multiple of 8 */
524 m->HDisplay = (x + 7) & ~7;
525 m->VDisplay = y;
526 m->name = strdup(pScrn->display->modes[i]);
527 if (!m_prev)
528 pScrn->modePool = m;
529 else
530 m_prev->next = m;
531 m->prev = m_prev;
532 m_prev = m;
533 }
534
535 /* Filter out video modes not supported by the virtual hardware
536 we described. All modes used by the Windows additions should
537 work fine. */
538 i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
539 pScrn->display->modes,
540 clockRanges, NULL, 0, 6400, 1, 0, 1440,
541 pScrn->display->virtualX,
542 pScrn->display->virtualY,
543 pScrn->videoRam, LOOKUP_BEST_REFRESH);
544
545 if (i <= 0) {
546 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No usable graphics modes found.\n");
547 return (FALSE);
548 }
549 xf86PruneDriverModes(pScrn);
550
551 pScrn->currentMode = pScrn->modes;
552 pScrn->displayWidth = pScrn->virtualX;
553
554 xf86PrintModes(pScrn);
555
556 /* Set display resolution. This was arbitrarily chosen to be about the same as my monitor. */
557 xf86SetDpi(pScrn, 100, 100);
558
559 if (pScrn->modes == NULL) {
560 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No graphics modes available\n");
561 return (FALSE);
562 }
563
564 /* options */
565 xf86CollectOptions(pScrn, NULL);
566 if (!(pVBox->Options = xalloc(sizeof(VBOXOptions))))
567 return FALSE;
568 memcpy(pVBox->Options, VBOXOptions, sizeof(VBOXOptions));
569 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pVBox->Options);
570
571 /* Framebuffer-related setup */
572 pScrn->bitmapBitOrder = BITMAP_BIT_ORDER;
573 return (TRUE);
574}
575
576/*
577 * QUOTE from the XFree86 DESIGN document:
578 *
579 * This is called at the start of each server generation.
580 *
581 * (...)
582 *
583 * Decide which operations need to be placed under resource access
584 * control. (...) Map any video memory or other memory regions. (...)
585 * Save the video card state. (...) Initialise the initial video
586 * mode.
587 *
588 * End QUOTE.Initialise the initial video mode.
589 */
590static Bool
591VBOXScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
592{
593 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
594 VBOXPtr pVBox = VBOXGetRec(pScrn);
595 VisualPtr visual;
596 unsigned flags;
597
598 /* We make use of the X11 VBE code to save and restore text mode, in
599 order to keep our code simple. */
600 if ((pVBox->pVbe = VBEInit(NULL, pVBox->pEnt->index)) == NULL)
601 return (FALSE);
602
603 if (pVBox->mapPhys == 0) {
604 pVBox->mapPhys = pVBox->pciInfo->memBase[0];
605/* pVBox->mapSize = 1 << pVBox->pciInfo->size[0]; */
606 /* Using the PCI information caused problems with
607 non-powers-of-two sized video RAM configurations */
608 pVBox->mapSize = inl(VBE_DISPI_IOPORT_DATA);
609 pVBox->mapOff = 0;
610 }
611
612 if (!VBOXMapVidMem(pScrn))
613 return (FALSE);
614
615 /* save current video state */
616 VBOXSaveRestore(pScrn, MODE_SAVE);
617 pVBox->savedPal = VBESetGetPaletteData(pVBox->pVbe, FALSE, 0, 256,
618 NULL, FALSE, FALSE);
619
620 /* set first video mode */
621 if (!VBOXSetMode(pScrn, pScrn->currentMode))
622 return FALSE;
623
624 /* mi layer - reset the visual list (?)*/
625 miClearVisualTypes();
626 if (!xf86SetDefaultVisual(pScrn, -1))
627 return (FALSE);
628 if (!miSetVisualTypes(pScrn->depth, TrueColorMask,
629 pScrn->rgbBits, TrueColor))
630 return (FALSE);
631 if (!miSetPixmapDepths())
632 return (FALSE);
633
634 /* I checked in the sources, and XFree86 4.2 does seem to support
635 this function for 32bpp. */
636 if (!fbScreenInit(pScreen, pVBox->base,
637 pScrn->virtualX, pScrn->virtualY,
638 pScrn->xDpi, pScrn->yDpi,
639 pScrn->displayWidth, pScrn->bitsPerPixel))
640 return (FALSE);
641
642 /* Fixup RGB ordering */
643 visual = pScreen->visuals + pScreen->numVisuals;
644 while (--visual >= pScreen->visuals) {
645 if ((visual->class | DynamicClass) == DirectColor) {
646 visual->offsetRed = pScrn->offset.red;
647 visual->offsetGreen = pScrn->offset.green;
648 visual->offsetBlue = pScrn->offset.blue;
649 visual->redMask = pScrn->mask.red;
650 visual->greenMask = pScrn->mask.green;
651 visual->blueMask = pScrn->mask.blue;
652 }
653 }
654
655 /* must be after RGB ordering fixed */
656 fbPictureInit(pScreen, 0, 0);
657
658 VBOXDGAInit(pScrn, pScreen);
659
660 xf86SetBlackWhitePixels(pScreen);
661 miInitializeBackingStore(pScreen);
662 xf86SetBackingStore(pScreen);
663
664 /* software cursor */
665 miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
666
667 /* colourmap code - apparently, we need this even in Truecolour */
668 if (!miCreateDefColormap(pScreen))
669 return (FALSE);
670
671 flags = CMAP_RELOAD_ON_MODE_SWITCH;
672
673 if(!xf86HandleColormaps(pScreen, 256,
674 8 /* DAC is switchable to 8 bits per primary color */,
675 VBOXLoadPalette, NULL, flags))
676 return (FALSE);
677
678 pVBox->CloseScreen = pScreen->CloseScreen;
679 pScreen->CloseScreen = VBOXCloseScreen;
680 pScreen->SaveScreen = VBOXSaveScreen;
681
682 /* However, we probably do want to support power management -
683 even if we just use a dummy function. */
684 xf86DPMSInit(pScreen, VBOXDisplayPowerManagementSet, 0);
685
686 /* Report any unused options (only for the first generation) */
687 if (serverGeneration == 1)
688 xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
689
690 if (vbox_open (pScrn, pScreen, pVBox)) {
691 if (vbox_cursor_init(pScreen) != TRUE)
692 xf86DrvMsg(scrnIndex, X_ERROR,
693 "Unable to start the VirtualBox mouse pointer integration with the host system.\n");
694 if (vboxEnableVbva(pScrn) == TRUE)
695 xf86DrvMsg(scrnIndex, X_INFO,
696 "The VBox video extensions are now enabled.\n");
697 } else
698 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");
699 return (TRUE);
700}
701
702static Bool
703VBOXEnterVT(int scrnIndex, int flags)
704{
705 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
706 VBOXPtr pVBox = VBOXGetRec(pScrn);
707
708 if (!VBOXSetMode(pScrn, pScrn->currentMode))
709 return FALSE;
710 if (pVBox->useVbva == TRUE)
711 vboxEnableVbva(pScrn);
712 return TRUE;
713}
714
715static void
716VBOXLeaveVT(int scrnIndex, int flags)
717{
718 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
719 VBOXPtr pVBox = VBOXGetRec(pScrn);
720
721 VBOXSaveRestore(pScrn, MODE_RESTORE);
722 if (pVBox->useVbva == TRUE)
723 vboxDisableVbva(pScrn);
724}
725
726static Bool
727VBOXCloseScreen(int scrnIndex, ScreenPtr pScreen)
728{
729 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
730 VBOXPtr pVBox = VBOXGetRec(pScrn);
731
732 if (pVBox->useVbva == TRUE)
733 vboxDisableVbva(pScrn);
734 if (pScrn->vtSema) {
735 VBOXSaveRestore(xf86Screens[scrnIndex], MODE_RESTORE);
736 VBESetGetPaletteData(pVBox->pVbe, TRUE, 0, 256,
737 pVBox->savedPal, FALSE, TRUE);
738 VBOXUnmapVidMem(pScrn);
739 }
740 if (pVBox->pDGAMode) {
741 xfree(pVBox->pDGAMode);
742 pVBox->pDGAMode = NULL;
743 pVBox->nDGAMode = 0;
744 }
745 pScrn->vtSema = FALSE;
746
747 pScreen->CloseScreen = pVBox->CloseScreen;
748 return pScreen->CloseScreen(scrnIndex, pScreen);
749}
750
751static Bool
752VBOXSwitchMode(int scrnIndex, DisplayModePtr pMode, int flags)
753{
754 ScrnInfoPtr pScrn;
755 VBOXPtr pVBox;
756
757 pScrn = xf86Screens[scrnIndex]; /* Why does X have three ways of refering to the screen? */
758 pVBox = VBOXGetRec(pScrn);
759 if (pVBox->useVbva == TRUE)
760 if (vboxDisableVbva(pScrn) != TRUE) /* This would be bad. */
761 return FALSE;
762 if (VBOXSetMode(pScrn, pMode) != TRUE)
763 return FALSE;
764 if (pVBox->useVbva == TRUE)
765 if (vboxEnableVbva(pScrn) != TRUE) /* Bad but not fatal */
766 pVBox->useVbva = FALSE;
767 return TRUE;
768}
769
770/* Set a graphics mode */
771static Bool
772VBOXSetMode(ScrnInfoPtr pScrn, DisplayModePtr pMode)
773{
774 VBOXPtr pVBox;
775
776 int bpp = pScrn->depth == 24 ? 32 : 16;
777 int xRes = pMode->HDisplay;
778 if (pScrn->virtualX * pScrn->virtualY * bpp / 8
779 >= pScrn->videoRam * 1024)
780 {
781 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
782 "Unable to set up a virtual screen size of %dx%d with %d Kb of video memory. Please increase the video memory size.\n",
783 pScrn->virtualX, pScrn->virtualY, pScrn->videoRam);
784 return FALSE;
785 }
786 /* We only support horizontal resolutions which are a multiple of 8. Round down if
787 necessary. */
788 if (xRes % 8 != 0)
789 {
790 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
791 "VirtualBox only supports screen widths which are a multiple of 8. Rounding down from %d to %d\n",
792 xRes, xRes - (xRes % 8));
793 xRes = xRes - (xRes % 8);
794 }
795 pVBox = VBOXGetRec(pScrn);
796 pScrn->vtSema = TRUE;
797 /* Disable linear framebuffer mode before making changes to the resolution. */
798 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ENABLE);
799 outw(VBE_DISPI_IOPORT_DATA,
800 VBE_DISPI_DISABLED);
801 /* Unlike the resolution, the depth is fixed for a given screen
802 for the lifetime of the X session. */
803 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_BPP);
804 outw(VBE_DISPI_IOPORT_DATA, bpp);
805 /* HDisplay and VDisplay are actually monitor information about
806 the display part of the scanlines. */
807 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_XRES);
808 outw(VBE_DISPI_IOPORT_DATA, xRes);
809 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_YRES);
810 outw(VBE_DISPI_IOPORT_DATA, pMode->VDisplay);
811 /* Enable linear framebuffer mode. */
812 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ENABLE);
813 outw(VBE_DISPI_IOPORT_DATA,
814 VBE_DISPI_ENABLED | VBE_DISPI_LFB_ENABLED);
815 /* Set the virtual resolution. We are still using VESA to control
816 the virtual offset. */
817 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_VIRT_WIDTH);
818 outw(VBE_DISPI_IOPORT_DATA, pScrn->displayWidth);
819 return (TRUE);
820}
821
822static void
823VBOXAdjustFrame(int scrnIndex, int x, int y, int flags)
824{
825 VBOXPtr pVBox = VBOXGetRec(xf86Screens[scrnIndex]);
826
827 VBESetDisplayStart(pVBox->pVbe, x, y, TRUE);
828}
829
830static void
831VBOXFreeScreen(int scrnIndex, int flags)
832{
833 VBOXFreeRec(xf86Screens[scrnIndex]);
834}
835
836static Bool
837VBOXMapVidMem(ScrnInfoPtr pScrn)
838{
839 VBOXPtr pVBox = VBOXGetRec(pScrn);
840
841 if (pVBox->base != NULL)
842 return (TRUE);
843
844 pScrn->memPhysBase = pVBox->mapPhys;
845 pScrn->fbOffset = pVBox->mapOff;
846
847 pVBox->base = xf86MapPciMem(pScrn->scrnIndex,
848 VIDMEM_FRAMEBUFFER,
849 pVBox->pciTag, pVBox->mapPhys,
850 (unsigned) pVBox->mapSize);
851
852 if (pVBox->base) {
853 pScrn->memPhysBase = pVBox->mapPhys;
854 pVBox->VGAbase = xf86MapVidMem(pScrn->scrnIndex, 0,
855 0xa0000, 0x10000);
856 }
857
858 return (pVBox->base != NULL);
859}
860
861static void
862VBOXUnmapVidMem(ScrnInfoPtr pScrn)
863{
864 VBOXPtr pVBox = VBOXGetRec(pScrn);
865
866 if (pVBox->base == NULL)
867 return;
868
869 xf86UnMapVidMem(pScrn->scrnIndex, pVBox->base,
870 (unsigned) pVBox->mapSize);
871 xf86UnMapVidMem(pScrn->scrnIndex, pVBox->VGAbase, 0x10000);
872 pVBox->base = NULL;
873}
874
875static void
876VBOXLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
877 LOCO *colors, VisualPtr pVisual)
878{
879#define WriteDacWriteAddr(value) outb(VGA_DAC_WRITE_ADDR, value)
880#define WriteDacData(value) outb(VGA_DAC_DATA, value);
881#undef DACDelay
882#define DACDelay() \
883 do { \
884 unsigned char temp = inb(VGA_IOBASE_COLOR + VGA_IN_STAT_1_OFFSET); \
885 temp = inb(VGA_IOBASE_COLOR + VGA_IN_STAT_1_OFFSET); \
886 } while (0)
887 int i, idx;
888
889 for (i = 0; i < numColors; i++) {
890 idx = indices[i];
891 WriteDacWriteAddr(idx);
892 DACDelay();
893 WriteDacData(colors[idx].red);
894 DACDelay();
895 WriteDacData(colors[idx].green);
896 DACDelay();
897 WriteDacData(colors[idx].blue);
898 DACDelay();
899 }
900}
901
902/*
903 * Just adapted from the std* functions in vgaHW.c
904 */
905static void
906WriteAttr(int index, int value)
907{
908 CARD8 tmp;
909
910 tmp = inb(VGA_IOBASE_COLOR + VGA_IN_STAT_1_OFFSET);
911
912 index |= 0x20;
913 outb(VGA_ATTR_INDEX, index);
914 outb(VGA_ATTR_DATA_W, value);
915}
916
917static int
918ReadAttr(int index)
919{
920 CARD8 tmp;
921
922 tmp = inb(VGA_IOBASE_COLOR + VGA_IN_STAT_1_OFFSET);
923
924 index |= 0x20;
925 outb(VGA_ATTR_INDEX, index);
926 return (inb(VGA_ATTR_DATA_R));
927}
928
929#define WriteMiscOut(value) outb(VGA_MISC_OUT_W, value)
930#define ReadMiscOut() inb(VGA_MISC_OUT_R)
931#define WriteSeq(index, value) \
932 outb(VGA_SEQ_INDEX, (index));\
933 outb(VGA_SEQ_DATA, value)
934
935static int
936ReadSeq(int index)
937{
938 outb(VGA_SEQ_INDEX, index);
939
940 return (inb(VGA_SEQ_DATA));
941}
942
943#define WriteGr(index, value) outb(VGA_GRAPH_INDEX, index);\
944 outb(VGA_GRAPH_DATA, value)
945
946static int
947ReadGr(int index)
948{
949 outb(VGA_GRAPH_INDEX, index);
950
951 return (inb(VGA_GRAPH_DATA));
952}
953
954#define WriteCrtc(index, value) outb(VGA_CRTC_INDEX_OFFSET, index);\
955 outb(VGA_CRTC_DATA_OFFSET, value)
956
957static void
958SeqReset(Bool start)
959{
960 if (start) {
961 WriteSeq(0x00, 0x01); /* Synchronous Reset */
962 }
963 else {
964 WriteSeq(0x00, 0x03); /* End Reset */
965 }
966}
967
968static void
969SaveFonts(ScrnInfoPtr pScrn)
970{
971 VBOXPtr pVBox = VBOXGetRec(pScrn);
972 unsigned char miscOut, attr10, gr4, gr5, gr6, seq2, seq4, scrn;
973
974 if (pVBox->fonts != NULL)
975 return;
976
977 /* If in graphics mode, don't save anything */
978 attr10 = ReadAttr(0x10);
979 if (attr10 & 0x01)
980 return;
981
982 pVBox->fonts = xalloc(16384);
983
984 /* save the registers that are needed here */
985 miscOut = ReadMiscOut();
986 gr4 = ReadGr(0x04);
987 gr5 = ReadGr(0x05);
988 gr6 = ReadGr(0x06);
989 seq2 = ReadSeq(0x02);
990 seq4 = ReadSeq(0x04);
991
992 /* Force into colour mode */
993 WriteMiscOut(miscOut | 0x01);
994
995 scrn = ReadSeq(0x01) | 0x20;
996 SeqReset(TRUE);
997 WriteSeq(0x01, scrn);
998 SeqReset(FALSE);
999
1000 WriteAttr(0x10, 0x01); /* graphics mode */
1001
1002 /*font1 */
1003 WriteSeq(0x02, 0x04); /* write to plane 2 */
1004 WriteSeq(0x04, 0x06); /* enable plane graphics */
1005 WriteGr(0x04, 0x02); /* read plane 2 */
1006 WriteGr(0x05, 0x00); /* write mode 0, read mode 0 */
1007 WriteGr(0x06, 0x05); /* set graphics */
1008 slowbcopy_frombus(pVBox->VGAbase, pVBox->fonts, 8192);
1009
1010 /* font2 */
1011 WriteSeq(0x02, 0x08); /* write to plane 3 */
1012 WriteSeq(0x04, 0x06); /* enable plane graphics */
1013 WriteGr(0x04, 0x03); /* read plane 3 */
1014 WriteGr(0x05, 0x00); /* write mode 0, read mode 0 */
1015 WriteGr(0x06, 0x05); /* set graphics */
1016 slowbcopy_frombus(pVBox->VGAbase, pVBox->fonts + 8192, 8192);
1017
1018 scrn = ReadSeq(0x01) & ~0x20;
1019 SeqReset(TRUE);
1020 WriteSeq(0x01, scrn);
1021 SeqReset(FALSE);
1022
1023 /* Restore clobbered registers */
1024 WriteAttr(0x10, attr10);
1025 WriteSeq(0x02, seq2);
1026 WriteSeq(0x04, seq4);
1027 WriteGr(0x04, gr4);
1028 WriteGr(0x05, gr5);
1029 WriteGr(0x06, gr6);
1030 WriteMiscOut(miscOut);
1031}
1032
1033static void
1034RestoreFonts(ScrnInfoPtr pScrn)
1035{
1036 VBOXPtr pVBox = VBOXGetRec(pScrn);
1037 unsigned char miscOut, attr10, gr1, gr3, gr4, gr5, gr6, gr8, seq2, seq4, scrn;
1038
1039 if (pVBox->fonts == NULL)
1040 return;
1041
1042 /* save the registers that are needed here */
1043 miscOut = ReadMiscOut();
1044 attr10 = ReadAttr(0x10);
1045 gr1 = ReadGr(0x01);
1046 gr3 = ReadGr(0x03);
1047 gr4 = ReadGr(0x04);
1048 gr5 = ReadGr(0x05);
1049 gr6 = ReadGr(0x06);
1050 gr8 = ReadGr(0x08);
1051 seq2 = ReadSeq(0x02);
1052 seq4 = ReadSeq(0x04);
1053
1054 /* Force into colour mode */
1055 WriteMiscOut(miscOut | 0x01);
1056
1057 scrn = ReadSeq(0x01) | 0x20;
1058 SeqReset(TRUE);
1059 WriteSeq(0x01, scrn);
1060 SeqReset(FALSE);
1061
1062 WriteAttr(0x10, 0x01); /* graphics mode */
1063 if (pScrn->depth == 4) {
1064 /* GJA */
1065 WriteGr(0x03, 0x00); /* don't rotate, write unmodified */
1066 WriteGr(0x08, 0xFF); /* write all bits in a byte */
1067 WriteGr(0x01, 0x00); /* all planes come from CPU */
1068 }
1069
1070 WriteSeq(0x02, 0x04); /* write to plane 2 */
1071 WriteSeq(0x04, 0x06); /* enable plane graphics */
1072 WriteGr(0x04, 0x02); /* read plane 2 */
1073 WriteGr(0x05, 0x00); /* write mode 0, read mode 0 */
1074 WriteGr(0x06, 0x05); /* set graphics */
1075 slowbcopy_tobus(pVBox->fonts, pVBox->VGAbase, 8192);
1076
1077 WriteSeq(0x02, 0x08); /* write to plane 3 */
1078 WriteSeq(0x04, 0x06); /* enable plane graphics */
1079 WriteGr(0x04, 0x03); /* read plane 3 */
1080 WriteGr(0x05, 0x00); /* write mode 0, read mode 0 */
1081 WriteGr(0x06, 0x05); /* set graphics */
1082 slowbcopy_tobus(pVBox->fonts + 8192, pVBox->VGAbase, 8192);
1083
1084 scrn = ReadSeq(0x01) & ~0x20;
1085 SeqReset(TRUE);
1086 WriteSeq(0x01, scrn);
1087 SeqReset(FALSE);
1088
1089 /* restore the registers that were changed */
1090 WriteMiscOut(miscOut);
1091 WriteAttr(0x10, attr10);
1092 WriteGr(0x01, gr1);
1093 WriteGr(0x03, gr3);
1094 WriteGr(0x04, gr4);
1095 WriteGr(0x05, gr5);
1096 WriteGr(0x06, gr6);
1097 WriteGr(0x08, gr8);
1098 WriteSeq(0x02, seq2);
1099 WriteSeq(0x04, seq4);
1100}
1101
1102static Bool
1103VBOXSaveScreen(ScreenPtr pScreen, int mode)
1104{
1105 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
1106 Bool on = xf86IsUnblank(mode);
1107
1108 if (on)
1109 SetTimeSinceLastInputEvent();
1110
1111 if (pScrn->vtSema) {
1112 unsigned char scrn = ReadSeq(0x01);
1113
1114 if (on)
1115 scrn &= ~0x20;
1116 else
1117 scrn |= 0x20;
1118 SeqReset(TRUE);
1119 WriteSeq(0x01, scrn);
1120 SeqReset(FALSE);
1121 }
1122
1123 return (TRUE);
1124}
1125
1126Bool
1127VBOXSaveRestore(ScrnInfoPtr pScrn, vbeSaveRestoreFunction function)
1128{
1129 VBOXPtr pVBox;
1130
1131 if (MODE_QUERY < 0 || function > MODE_RESTORE)
1132 return (FALSE);
1133
1134 pVBox = VBOXGetRec(pScrn);
1135
1136
1137 /* Query amount of memory to save state */
1138 if (function == MODE_QUERY ||
1139 (function == MODE_SAVE && pVBox->state == NULL))
1140 {
1141
1142 /* Make sure we save at least this information in case of failure */
1143 (void)VBEGetVBEMode(pVBox->pVbe, &pVBox->stateMode);
1144 SaveFonts(pScrn);
1145
1146 if (!VBESaveRestore(pVBox->pVbe,function,(pointer)&pVBox->state,
1147 &pVBox->stateSize,&pVBox->statePage))
1148 return FALSE;
1149 }
1150
1151 /* Save/Restore Super VGA state */
1152 if (function != MODE_QUERY) {
1153 Bool retval = TRUE;
1154
1155 if (function == MODE_RESTORE)
1156 memcpy(pVBox->state, pVBox->pstate,
1157 (unsigned) pVBox->stateSize);
1158
1159 if ((retval = VBESaveRestore(pVBox->pVbe,function,
1160 (pointer)&pVBox->state,
1161 &pVBox->stateSize,&pVBox->statePage))
1162 && function == MODE_SAVE)
1163 {
1164 /* don't rely on the memory not being touched */
1165 if (pVBox->pstate == NULL)
1166 pVBox->pstate = xalloc(pVBox->stateSize);
1167 memcpy(pVBox->pstate, pVBox->state,
1168 (unsigned) pVBox->stateSize);
1169 }
1170
1171 if (function == MODE_RESTORE)
1172 {
1173 VBESetVBEMode(pVBox->pVbe, pVBox->stateMode, NULL);
1174 RestoreFonts(pScrn);
1175 }
1176
1177 if (!retval)
1178 return (FALSE);
1179
1180 }
1181
1182 return (TRUE);
1183}
1184
1185static void
1186VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode,
1187 int flags)
1188{
1189 /* VBox is always power efficient... */
1190}
1191
1192
1193
1194
1195/***********************************************************************
1196 * DGA stuff
1197 ***********************************************************************/
1198static Bool VBOXDGAOpenFramebuffer(ScrnInfoPtr pScrn, char **DeviceName,
1199 unsigned char **ApertureBase,
1200 int *ApertureSize, int *ApertureOffset,
1201 int *flags);
1202static Bool VBOXDGASetMode(ScrnInfoPtr pScrn, DGAModePtr pDGAMode);
1203static void VBOXDGASetViewport(ScrnInfoPtr pScrn, int x, int y, int flags);
1204
1205static Bool
1206VBOXDGAOpenFramebuffer(ScrnInfoPtr pScrn, char **DeviceName,
1207 unsigned char **ApertureBase, int *ApertureSize,
1208 int *ApertureOffset, int *flags)
1209{
1210 VBOXPtr pVBox = VBOXGetRec(pScrn);
1211
1212 *DeviceName = NULL; /* No special device */
1213 *ApertureBase = (unsigned char *)(long)(pVBox->mapPhys);
1214 *ApertureSize = pVBox->mapSize;
1215 *ApertureOffset = pVBox->mapOff;
1216 *flags = DGA_NEED_ROOT;
1217
1218 return (TRUE);
1219}
1220
1221static Bool
1222VBOXDGASetMode(ScrnInfoPtr pScrn, DGAModePtr pDGAMode)
1223{
1224 DisplayModePtr pMode;
1225 int scrnIdx = pScrn->pScreen->myNum;
1226 int frameX0, frameY0;
1227
1228 if (pDGAMode) {
1229 pMode = pDGAMode->mode;
1230 frameX0 = frameY0 = 0;
1231 }
1232 else {
1233 if (!(pMode = pScrn->currentMode))
1234 return (TRUE);
1235
1236 frameX0 = pScrn->frameX0;
1237 frameY0 = pScrn->frameY0;
1238 }
1239
1240 if (!(*pScrn->SwitchMode)(scrnIdx, pMode, 0))
1241 return (FALSE);
1242 (*pScrn->AdjustFrame)(scrnIdx, frameX0, frameY0, 0);
1243
1244 return (TRUE);
1245}
1246
1247static void
1248VBOXDGASetViewport(ScrnInfoPtr pScrn, int x, int y, int flags)
1249{
1250 (*pScrn->AdjustFrame)(pScrn->pScreen->myNum, x, y, flags);
1251}
1252
1253static int
1254VBOXDGAGetViewport(ScrnInfoPtr pScrn)
1255{
1256 return (0);
1257}
1258
1259static DGAFunctionRec VBOXDGAFunctions =
1260{
1261 VBOXDGAOpenFramebuffer,
1262 NULL, /* CloseFramebuffer */
1263 VBOXDGASetMode,
1264 VBOXDGASetViewport,
1265 VBOXDGAGetViewport,
1266 NULL, /* Sync */
1267 NULL, /* FillRect */
1268 NULL, /* BlitRect */
1269 NULL, /* BlitTransRect */
1270};
1271
1272static void
1273VBOXDGAAddModes(ScrnInfoPtr pScrn)
1274{
1275 VBOXPtr pVBox = VBOXGetRec(pScrn);
1276 DisplayModePtr pMode = pScrn->modes;
1277 DGAModePtr pDGAMode;
1278
1279 do {
1280 pDGAMode = xrealloc(pVBox->pDGAMode,
1281 (pVBox->nDGAMode + 1) * sizeof(DGAModeRec));
1282 if (!pDGAMode)
1283 break;
1284
1285 pVBox->pDGAMode = pDGAMode;
1286 pDGAMode += pVBox->nDGAMode;
1287 (void)memset(pDGAMode, 0, sizeof(DGAModeRec));
1288
1289 ++pVBox->nDGAMode;
1290 pDGAMode->mode = pMode;
1291 pDGAMode->flags = DGA_CONCURRENT_ACCESS | DGA_PIXMAP_AVAILABLE;
1292 pDGAMode->byteOrder = pScrn->imageByteOrder;
1293 pDGAMode->depth = pScrn->depth;
1294 pDGAMode->bitsPerPixel = pScrn->bitsPerPixel;
1295 pDGAMode->red_mask = pScrn->mask.red;
1296 pDGAMode->green_mask = pScrn->mask.green;
1297 pDGAMode->blue_mask = pScrn->mask.blue;
1298 pDGAMode->visualClass = TrueColor;
1299 pDGAMode->xViewportStep = 1;
1300 pDGAMode->yViewportStep = 1;
1301 pDGAMode->viewportWidth = pMode->HDisplay;
1302 pDGAMode->viewportHeight = pMode->VDisplay;
1303
1304 pDGAMode->bytesPerScanline = pVBox->maxBytesPerScanline;
1305 pDGAMode->imageWidth = pMode->HDisplay;
1306 pDGAMode->imageHeight = pMode->VDisplay;
1307 pDGAMode->pixmapWidth = pDGAMode->imageWidth;
1308 pDGAMode->pixmapHeight = pDGAMode->imageHeight;
1309 pDGAMode->maxViewportX = pScrn->virtualX -
1310 pDGAMode->viewportWidth;
1311 pDGAMode->maxViewportY = pScrn->virtualY -
1312 pDGAMode->viewportHeight;
1313
1314 pDGAMode->address = pVBox->base;
1315
1316 pMode = pMode->next;
1317 } while (pMode != pScrn->modes);
1318}
1319
1320static Bool
1321VBOXDGAInit(ScrnInfoPtr pScrn, ScreenPtr pScreen)
1322{
1323 VBOXPtr pVBox = VBOXGetRec(pScrn);
1324
1325 if (!pVBox->nDGAMode)
1326 VBOXDGAAddModes(pScrn);
1327
1328 return (DGAInit(pScreen, &VBOXDGAFunctions,
1329 pVBox->pDGAMode, pVBox->nDGAMode));
1330}
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