VirtualBox

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

Last change on this file since 8640 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

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