VirtualBox

Changeset 6484 in vbox


Ignore:
Timestamp:
Jan 24, 2008 2:59:40 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
27485
Message:

Additions (x11): added randr 1.2 support to the graphics driver

Location:
trunk/src/VBox/Additions/x11/xgraphics
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/xgraphics/Makefile.kmk

    r6301 r6484  
    2525# for BUILD_TARGET=l4
    2626SUFF_DLL = .so
     27
     28# For now
     29VBOX_LIB_VBGL_R3 := $(PATH_LIB)/VBoxGuestR3LibLinux.a
     30VBOX_LIB_IPRT_GUEST_R3 := $(PATH_LIB)/RuntimeLnx32GuestR3.a
    2731
    2832vboxvideo_drv_TEMPLATE = VBOXLNX32GUESTR3EXE
     
    102106        vboxvideo_68.c \
    103107        vboxutils.c
    104 
     108vboxvideo_drv_LIBS = \
     109        $(VBOX_LIB_VBGL_R3) \
     110        $(VBOX_LIB_IPRT_GUEST_R3)
    105111
    106112vboxvideo_drv_70_TEMPLATE = VBOXLNX32GUESTR3DLLNOCPP
     
    119125        vboxvideo_70.c \
    120126        vboxutils.c
    121 
     127vboxvideo_drv_70_LIBS = \
     128        $(VBOX_LIB_VBGL_R3) \
     129        $(VBOX_LIB_IPRT_GUEST_R3)
    122130
    123131vboxvideo_drv_71_TEMPLATE = VBOXLNX32GUESTR3DLLNOCPP
     
    132140        vboxvideo_70.c \
    133141        vboxutils.c
     142vboxvideo_drv_71_LIBS = \
     143        $(VBOX_LIB_VBGL_R3) \
     144        $(VBOX_LIB_IPRT_GUEST_R3)
    134145
    135146vboxvideo_drv_13_TEMPLATE = VBOXLNX32GUESTR3DLLNOCPP
     
    144155        vboxvideo_13.c \
    145156        vboxutils.c
     157vboxvideo_drv_13_LIBS = \
     158        $(VBOX_LIB_VBGL_R3) \
     159        $(VBOX_LIB_IPRT_GUEST_R3)
    146160
    147161vboxvideo_drv_14_TEMPLATE = VBOXLNX32GUESTR3DLLNOCPP
     
    153167        ../x11include/1.4/X11 \
    154168        ../x11include/1.4/xorg
     169# The actual source has not changed from the 1.3 driver, but the headers
     170# have.  To be safe, build the driver for 1.4 separately.
    155171vboxvideo_drv_14_SOURCES  = \
    156         vboxvideo_14.c \
     172        vboxvideo_13.c \
    157173        vboxutils.c
     174vboxvideo_drv_14_LIBS = \
     175        $(VBOX_LIB_VBGL_R3) \
     176        $(VBOX_LIB_IPRT_GUEST_R3)
    158177endif
    159178
  • trunk/src/VBox/Additions/x11/xgraphics/vboxutils.c

    r6483 r6484  
    954954    return TRUE;
    955955}
     956
     957
     958/**
     959 * Query the last display change request.
     960 *
     961 * @returns iprt status value
     962 * @retval xres     horizontal pixel resolution (0 = do not change)
     963 * @retval yres     vertical pixel resolution (0 = do not change)
     964 * @retval bpp      bits per pixel (0 = do not change)
     965 * @param  eventAck Flag that the request is an acknowlegement for the
     966 *                  VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST.
     967 *                  Values:
     968 *                      0                                   - just querying,
     969 *                      VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST - event acknowledged.
     970 * @param  display  0 for primary display, 1 for the first secondary, etc.
     971 */
     972Bool
     973vboxGetDisplayChangeRequest(ScrnInfoPtr pScrn, uint32_t *px, uint32_t *py,
     974                            uint32_t *pbpp, uint32_t eventAck, uint32_t display)
     975{
     976    int rc, scrnIndex = pScrn->scrnIndex;
     977    VBOXPtr pVBox = pScrn->driverPrivate;
     978
     979    VMMDevDisplayChangeRequest2 Req;
     980    vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
     981    Req.xres = 0;
     982    Req.yres = 0;
     983    Req.bpp = 0;
     984    Req.eventAck = eventAck;
     985    Req.display = display;
     986    rc = vbox_vmmcall(pScrn, pVBox, &Req.header);
     987    if (RT_SUCCESS(rc))
     988    {
     989        *px = Req.xres;
     990        *py = Req.yres;
     991        *pbpp = Req.bpp;
     992        return TRUE;
     993    }
     994    xf86DrvMsg(scrnIndex, X_ERROR,
     995               "Failed to request the last resolution requested from the guest, rc=%d.\n",
     996               rc);
     997    return FALSE;
     998}
  • trunk/src/VBox/Additions/x11/xgraphics/vboxvideo.h

    r6301 r6484  
    205205vboxDisableVbva(ScrnInfoPtr pScrn);
    206206
     207/**
     208 * Query the last display change request.
     209 *
     210 * @returns iprt status value
     211 * @retval xres     horizontal pixel resolution (0 = do not change)
     212 * @retval yres     vertical pixel resolution (0 = do not change)
     213 * @retval bpp      bits per pixel (0 = do not change)
     214 * @param  eventAck Flag that the request is an acknowlegement for the
     215 *                  VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST.
     216 *                  Values:
     217 *                      0                                   - just querying,
     218 *                      VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST - event acknowledged.
     219 * @param  display  0 for primary display, 1 for the first secondary, etc.
     220 */
     221extern Bool
     222vboxGetDisplayChangeRequest(ScrnInfoPtr pScrn, uint32_t *px, uint32_t *py,
     223                            uint32_t *pbpp, uint32_t eventAck, uint32_t display);
     224
    207225#endif /* _VBOXVIDEO_H_ */
  • trunk/src/VBox/Additions/x11/xgraphics/vboxvideo_13.c

    r6202 r6484  
    5050#define DEBUG_VERB 2
    5151
     52#define TRACE \
     53do { \
     54    xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
     55    xf86Msg(X_INFO, ": entering\n"); \
     56} while(0)
     57#define TRACE2 \
     58do { \
     59    xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
     60    xf86Msg(X_INFO, ": leaving\n"); \
     61} while(0)
     62#define TRACE3(...) \
     63do { \
     64    xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
     65    xf86Msg(X_INFO, __VA_ARGS__); \
     66} while(0)
    5267#ifdef XFree86LOADER
    5368# include "xorg-server.h"
     
    7590#include "extensions/dpms.h" */
    7691
     92/* X.org 1.3+ mode setting */
     93#include "xf86Crtc.h"
     94#include "xf86Modes.h"
     95
    7796/* Mandatory functions */
    7897
     
    86105static void VBOXLeaveVT(int scrnIndex, int flags);
    87106static Bool VBOXCloseScreen(int scrnIndex, ScreenPtr pScreen);
    88 static Bool VBOXSaveScreen(ScreenPtr pScreen, int mode);
    89107static Bool VBOXSwitchMode(int scrnIndex, DisplayModePtr pMode, int flags);
    90108static ModeStatus VBOXValidMode(int scrn, DisplayModePtr p, Bool flag, int pass);
     
    93111static void VBOXFreeScreen(int scrnIndex, int flags);
    94112static void VBOXFreeRec(ScrnInfoPtr pScrn);
    95 static void VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode,
    96                                           int flags);
    97113
    98114/* locally used functions */
     
    107123                            vbeSaveRestoreFunction function);
    108124
    109 /* Initialise DGA */
    110 
    111 static Bool VBOXDGAInit(ScrnInfoPtr pScrn, ScreenPtr pScreen);
    112 
    113125/*
    114126 * This contains the functions needed by the server after loading the
     
    142154};
    143155
    144 typedef enum {
    145     OPTION_SHADOW_FB,
    146     OPTION_DFLT_REFRESH,
    147     OPTION_MODESET_CLEAR_SCREEN
    148 } VBOXOpts;
    149 
    150156/* No options for now */
    151157static const OptionInfoRec VBOXOptions[] = {
     
    153159};
    154160
     161static VBOXPtr
     162VBOXGetRec(ScrnInfoPtr pScrn)
     163{
     164    if (!pScrn->driverPrivate) {
     165        pScrn->driverPrivate = xcalloc(sizeof(VBOXRec), 1);
     166        ((VBOXPtr)pScrn->driverPrivate)->vbox_fd = -1;
     167    }
     168
     169    return ((VBOXPtr)pScrn->driverPrivate);
     170}
     171
     172static void
     173VBOXFreeRec(ScrnInfoPtr pScrn)
     174{
     175    VBOXPtr pVBox = VBOXGetRec(pScrn);
     176#if 0
     177    xfree(pVBox->vbeInfo);
     178#endif
     179    xfree(pVBox->savedPal);
     180    xfree(pVBox->fonts);
     181    xfree(pScrn->driverPrivate);
     182    pScrn->driverPrivate = NULL;
     183}
     184
     185/* X.org 1.3+ mode-setting support ******************************************/
     186
     187/* For descriptions of these functions and structures, see
     188   hw/xfree86/modes/xf86Crtc.h and hw/xfree86/modes/xf86Modes.h in the
     189   X.Org source tree. */
     190
     191static Bool
     192VBOXCrtcResize(ScrnInfoPtr scrn, int width, int height)
     193{
     194    int bpp = scrn->bitsPerPixel;
     195    ScreenPtr pScreen = scrn->pScreen;
     196    PixmapPtr pPixmap = NULL;
     197    VBOXPtr pVBox = VBOXGetRec(scrn);
     198    Bool rc = TRUE;
     199
     200    TRACE3("width=%d, height=%d\n", width, height);
     201    /* We only support horizontal resolutions which are a multiple of 8.  Round down if
     202       necessary. */
     203    if (width % 8 != 0)
     204    {
     205        xf86DrvMsg(scrn->scrnIndex, X_WARNING,
     206                   "VirtualBox only supports virtual screen widths which are a multiple of 8.  Rounding up from %d to %d\n",
     207                   width, width - (width % 8) + 8);
     208        width = width - (width % 8) + 8;
     209    }
     210    if (width * height * bpp / 8 >= scrn->videoRam * 1024)
     211    {
     212        xf86DrvMsg(scrn->scrnIndex, X_ERROR,
     213                   "Unable to set up a virtual screen size of %dx%d with %d Kb of video memory.  Please increase the video memory size.\n",
     214                   width, height, scrn->videoRam);
     215        rc = FALSE;
     216    }
     217    if (rc) {
     218        pPixmap = pScreen->GetScreenPixmap(pScreen);
     219        if (NULL == pPixmap) {
     220            xf86DrvMsg(scrn->scrnIndex, X_ERROR,
     221                       "Failed to get the screen pixmap.\n");
     222            rc = FALSE;
     223        }
     224    }
     225    if (rc) {
     226        TRACE3("Setting screen pixmap parameters: width=%d, height=%d, depth=%d, bpp=%d, stride=%d, VRAM=%p\n", width, height, scrn->depth, bpp, width * bpp / 8, pVBox->base);
     227        if (
     228            !pScreen->ModifyPixmapHeader(pPixmap, width, height,
     229                                         scrn->depth, bpp, width * bpp / 8,
     230                                         pVBox->base)
     231           ) {
     232            xf86DrvMsg(scrn->scrnIndex, X_ERROR,
     233                       "Failed to set up the screen pixmap.\n");
     234            rc = FALSE;
     235        }
     236    }
     237    if (rc) {
     238        scrn->virtualX = width;
     239        scrn->virtualY = height;
     240        scrn->displayWidth = width;
     241    }
     242    TRACE3("returning %s\n", rc ? "TRUE" : "FALSE");
     243    return rc;
     244}
     245
     246static const xf86CrtcConfigFuncsRec VBOXCrtcConfigFuncs = {
     247    VBOXCrtcResize
     248};
     249
     250static void
     251vbox_crtc_dpms(xf86CrtcPtr crtc, int mode)
     252{ TRACE; (void) crtc; (void) mode; }
     253
     254static Bool
     255vbox_crtc_lock (xf86CrtcPtr crtc)
     256{ TRACE; (void) crtc; return FALSE; }
     257
     258static Bool
     259vbox_crtc_mode_fixup (xf86CrtcPtr crtc, DisplayModePtr mode,
     260                      DisplayModePtr adjusted_mode)
     261{
     262    ScrnInfoPtr pScrn = crtc->scrn;
     263    int xRes = adjusted_mode->HDisplay;
     264
     265    TRACE;
     266    (void) mode;
     267    /* We only support horizontal resolutions which are a multiple of 8.  Round down if
     268       necessary. */
     269    if (xRes % 8 != 0)
     270    {
     271        xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
     272                   "VirtualBox only supports screen widths which are a multiple of 8.  Rounding down from %d to %d\n",
     273                   xRes, xRes - (xRes % 8));
     274        adjusted_mode->HDisplay = xRes - (xRes % 8);
     275    }
     276    TRACE2;
     277    return TRUE;
     278}
     279
     280static void
     281vbox_crtc_stub (xf86CrtcPtr crtc)
     282{ TRACE; (void) crtc; }
     283
     284static void
     285vbox_crtc_mode_set (xf86CrtcPtr crtc, DisplayModePtr mode,
     286                    DisplayModePtr adjusted_mode, int x, int y)
     287{
     288    (void) mode;
     289    TRACE;
     290    VBOXSetMode(crtc->scrn, adjusted_mode);
     291    VBOXAdjustFrame(crtc->scrn->scrnIndex, x, y, 0);
     292    TRACE2;
     293}
     294
     295static void
     296vbox_crtc_gamma_set (xf86CrtcPtr crtc, CARD16 *red,
     297                     CARD16 *green, CARD16 *blue, int size)
     298{ TRACE; (void) crtc; (void) red; (void) green; (void) blue; (void) size; }
     299
     300static void *
     301vbox_crtc_shadow_allocate (xf86CrtcPtr crtc, int width, int height)
     302{ TRACE; (void) crtc; (void) width; (void) height; return NULL; }
     303
     304static const xf86CrtcFuncsRec VBOXCrtcFuncs = {
     305    .dpms = vbox_crtc_dpms,
     306    .save = NULL, /* These two are never called by the server. */
     307    .restore = NULL,
     308    .lock = vbox_crtc_lock,
     309    .unlock = NULL, /* This will not be invoked if lock returns FALSE. */
     310    .mode_fixup = vbox_crtc_mode_fixup,
     311    .prepare = vbox_crtc_stub,
     312    .mode_set = vbox_crtc_mode_set,
     313    .commit = vbox_crtc_stub,
     314    .gamma_set = vbox_crtc_gamma_set,
     315    .shadow_allocate = vbox_crtc_shadow_allocate,
     316    .shadow_create = NULL, /* These two should not be invoked if allocate
     317                              returns NULL. */
     318    .shadow_destroy = NULL,
     319    .set_cursor_colors = NULL, /* We are still using the old cursor API. */
     320    .set_cursor_position = NULL,
     321    .show_cursor = NULL,
     322    .hide_cursor = NULL,
     323    .load_cursor_argb = NULL,
     324    .destroy = vbox_crtc_stub
     325};
     326
     327static void
     328vbox_output_stub (xf86OutputPtr output)
     329{ TRACE; (void) output; }
     330
     331static void
     332vbox_output_dpms (xf86OutputPtr output, int mode)
     333{ TRACE; (void) output; (void) mode; }
     334
     335static int
     336vbox_output_mode_valid (xf86OutputPtr output, DisplayModePtr mode)
     337{
     338    TRACE3("Modeline %s   %f  %d %d %d %d  %d %d %d %d\n",
     339           mode->name, mode->Clock * 1.0 / 1000, mode->HDisplay, mode->HSyncStart,
     340           mode->HSyncEnd, mode->HTotal, mode->VDisplay, mode->VSyncStart,
     341           mode->VSyncEnd, mode->VTotal);
     342    (void) output; (void) mode;
     343    return MODE_OK;
     344}
     345
     346static Bool
     347vbox_output_mode_fixup (xf86OutputPtr output, DisplayModePtr mode,
     348                        DisplayModePtr adjusted_mode)
     349{ TRACE; (void) output; (void) mode; (void) adjusted_mode; return TRUE; }
     350
     351static void
     352vbox_output_mode_set (xf86OutputPtr output, DisplayModePtr mode,
     353                        DisplayModePtr adjusted_mode)
     354{ TRACE; (void) output; (void) mode; (void) adjusted_mode; }
     355
     356/* A virtual monitor is always connected. */
     357static xf86OutputStatus
     358vbox_output_detect (xf86OutputPtr output)
     359{
     360    (void) output;
     361    return XF86OutputStatusConnected;
     362}
     363
     364static void
     365vbox_output_add_mode (DisplayModePtr *pModes, const char *pszName, int x, int y,
     366                      Bool isPreferred)
     367{
     368    DisplayModePtr pMode = xnfcalloc(1, sizeof(DisplayModeRec));
     369
     370    pMode->status        = MODE_OK;
     371    pMode->type          = isPreferred ? M_T_PREFERRED : M_T_BUILTIN;
     372    /* VBox only supports screen widths which are a multiple of 8 */
     373    pMode->HDisplay      = (x + 7) & ~7;
     374    pMode->HSyncStart    = pMode->HDisplay + 2;
     375    pMode->HSyncEnd      = pMode->HDisplay + 4;
     376    pMode->HTotal        = pMode->HDisplay + 6;
     377    pMode->VDisplay      = y;
     378    pMode->VSyncStart    = pMode->VDisplay + 2;
     379    pMode->VSyncEnd      = pMode->VDisplay + 4;
     380    pMode->VTotal        = pMode->VDisplay + 6;
     381    pMode->Clock         = pMode->HTotal * pMode->VTotal * 60 / 1000; /* kHz */
     382    if (NULL == pszName) {
     383        xf86SetModeDefaultName(pMode);
     384    } else {
     385        pMode->name          = xnfstrdup(pszName);
     386    }
     387    *pModes = xf86ModesAdd(*pModes, pMode);
     388}
     389
     390static DisplayModePtr
     391vbox_output_get_modes (xf86OutputPtr output)
     392{
     393    uint32_t x, y, bpp;
     394    int rc;
     395    DisplayModePtr pModes = NULL;
     396    ScrnInfoPtr pScrn = output->scrn;
     397
     398    TRACE;
     399    rc = vboxGetDisplayChangeRequest(pScrn, &x, &y, &bpp, 0, 0);
     400    if (RT_SUCCESS(rc) && (0 != x) && (0 != y)) {
     401        TRACE3("Adding host mode %dx%d\n", x, y);
     402        vbox_output_add_mode(&pModes, NULL, x, y, TRUE);
     403        vbox_output_add_mode(&pModes, "1024x768", 1024, 768, FALSE);
     404        vbox_output_add_mode(&pModes, "800x600", 800, 600, FALSE);
     405        vbox_output_add_mode(&pModes, "640x480", 640, 480, FALSE);
     406    } else {
     407        vbox_output_add_mode(&pModes, "1024x768", 1024, 768, FALSE);
     408        vbox_output_add_mode(&pModes, "800x600", 800, 600, FALSE);
     409        vbox_output_add_mode(&pModes, "640x480", 640, 480, FALSE);
     410    }
     411    TRACE2;
     412    return pModes;
     413}
     414
     415#ifdef RANDR_12_INTERFACE
     416/* We don't yet have mutable properties, whatever they are. */
     417static Bool
     418vbox_output_set_property(xf86OutputPtr output, Atom property,
     419                         RRPropertyValuePtr value)
     420{ TRACE; (void) output, (void) property, (void) value; return FALSE; }
     421#endif
     422
     423static const xf86OutputFuncsRec VBOXOutputFuncs = {
     424    .create_resources = vbox_output_stub,
     425    .dpms = vbox_output_dpms,
     426    .save = NULL, /* These two are never called by the server. */
     427    .restore = NULL,
     428    .mode_valid = vbox_output_mode_valid,
     429    .mode_fixup = vbox_output_mode_fixup,
     430    .prepare = vbox_output_stub,
     431    .commit = vbox_output_stub,
     432    .mode_set = vbox_output_mode_set,
     433    .detect = vbox_output_detect,
     434    .get_modes = vbox_output_get_modes,
     435#ifdef RANDR_12_INTERFACE
     436     .set_property = vbox_output_set_property,
     437#endif
     438    .destroy = vbox_output_stub
     439};
     440
    155441/*
    156442 * List of symbols from other modules that this module references.  This
    157443 * list is used to tell the loader that it is OK for symbols here to be
    158  * unresolved providing that it hasn't been told that they haven't been
    159  * told that they are essential via a call to xf86LoaderReqSymbols() or
    160  * xf86LoaderReqSymLists().  The purpose is this is to avoid warnings about
    161  * unresolved symbols that are not required.
     444 * unresolved providing that it hasn't been told that they are essential
     445 * via a call to xf86LoaderReqSymbols() or xf86LoaderReqSymLists().  The
     446 * purpose is this is to avoid warnings about unresolved symbols that are
     447 * not required.
    162448 */
    163449static const char *fbSymbols[] = {
     
    323609}
    324610
    325 static VBOXPtr
    326 VBOXGetRec(ScrnInfoPtr pScrn)
    327 {
    328     if (!pScrn->driverPrivate)
    329     {
    330         pScrn->driverPrivate = xcalloc(sizeof(VBOXRec), 1);
    331         ((VBOXPtr)pScrn->driverPrivate)->vbox_fd = -1;
    332     }
    333 
    334     return ((VBOXPtr)pScrn->driverPrivate);
    335 }
    336 
    337 static void
    338 VBOXFreeRec(ScrnInfoPtr pScrn)
    339 {
    340     VBOXPtr pVBox = VBOXGetRec(pScrn);
    341 #if 0
    342     xfree(pVBox->vbeInfo);
    343 #endif
    344     xfree(pVBox->savedPal);
    345     xfree(pVBox->fonts);
    346     xfree(pScrn->driverPrivate);
    347     pScrn->driverPrivate = NULL;
    348 }
    349 
    350611/*
    351612 * QUOTE from the XFree86 DESIGN document:
     
    378639    Gamma gzeros = {0.0, 0.0, 0.0};
    379640    rgb rzeros = {0, 0, 0};
    380     ClockRange *clockRanges;
    381     int i;
    382     DisplayModePtr m_prev;
     641    xf86OutputPtr output;
    383642
    384643    /* Are we really starting the server, or is this just a dummy run? */
     
    428687    pScrn->rgbBits = 8;
    429688
    430     /* Let's create a nice, capable virtual monitor. */
     689    /* I assume that this is no longer a requirement in the config file. */
    431690    pScrn->monitor = pScrn->confScreen->monitor;
    432     pScrn->monitor->DDC = NULL;
    433     pScrn->monitor->nHsync = 1;
    434     pScrn->monitor->hsync[0].lo = 1;
    435     pScrn->monitor->hsync[0].hi = 10000;
    436     pScrn->monitor->nVrefresh = 1;
    437     pScrn->monitor->vrefresh[0].lo = 1;
    438     pScrn->monitor->vrefresh[0].hi = 100;
    439691
    440692    pScrn->chipset = "vbox";
    441693    pScrn->progClock = TRUE;
    442694
    443     /* Determine the size of the VBox video RAM from PCI data*/
    444 #if 0
    445     pScrn->videoRam = 1 << pVBox->pciInfo->size[0];
    446 #endif
    447695    /* Using the PCI information caused problems with non-powers-of-two
    448696       sized video RAM configurations */
    449697    pScrn->videoRam = inl(VBE_DISPI_IOPORT_DATA) / 1024;
    450 
    451     /* Set up clock information that will support all modes we need. */
    452     clockRanges = xnfcalloc(sizeof(ClockRange), 1);
    453     clockRanges->next = NULL;
    454     clockRanges->minClock = 1000;
    455     clockRanges->maxClock = 1000000000;
    456     clockRanges->clockIndex = -1;
    457     clockRanges->ClockMulFactor = 1;
    458     clockRanges->ClockDivFactor = 1;
    459698
    460699    /* This function asks X to choose a depth and bpp based on the
     
    476715    xf86PrintDepthBpp(pScrn);
    477716
    478     /* Colour weight - we always call this, since we are always in
    479        truecolour. */
    480     if (!xf86SetWeight(pScrn, rzeros, rzeros))
    481         return (FALSE);
    482 
    483     /* visual init */
    484     if (!xf86SetDefaultVisual(pScrn, -1))
    485         return (FALSE);
    486 
    487     xf86SetGamma(pScrn, gzeros);
    488 
    489     /* To get around the problem of SUSE specifying a single, invalid mode in their
    490      * Xorg.conf by default, we add an additional mode to the end of the user specified
    491      * list. This means that if all user modes are invalid, X will try our mode before
    492      * falling back to its standard mode list. */
    493     if (pScrn->display->modes == NULL)
    494     {
    495         /* The user specified no modes at all - specify 1024x768 as a default. */
    496         pScrn->display->modes    = xnfalloc(4 * sizeof(char*));
    497         pScrn->display->modes[0] = "1024x768";
    498         pScrn->display->modes[1] = "800x600";
    499         pScrn->display->modes[2] = "640x480";
    500         pScrn->display->modes[3] = NULL;
    501     }
    502     else
    503     {
    504         /* Add 1024x768 to the end of the mode list in case the others are all invalid. */
    505         for (i = 0; pScrn->display->modes[i] != NULL; i++);
    506         pScrn->display->modes      = xnfrealloc(pScrn->display->modes, (i + 4)
    507                                    * sizeof(char *));
    508         pScrn->display->modes[i  ] = "1024x768";
    509         pScrn->display->modes[i+1] = "800x600";
    510         pScrn->display->modes[i+2] = "640x480";
    511         pScrn->display->modes[i+3] = NULL;
    512     }
    513 
    514     /* Determine the virtual screen resolution from the first mode (which will be selected) */
    515     sscanf(pScrn->display->modes[0], "%dx%d",
    516            &pScrn->display->virtualX, &pScrn->display->virtualY);
    517     pScrn->display->virtualX = (pScrn->display->virtualX + 7) & ~7;
    518 
    519     /* Create a builtin mode for every specified mode. This allows to specify arbitrary
    520      * screen resolutions */
    521     m_prev = NULL;
    522     for (i = 0; pScrn->display->modes[i] != NULL; i++)
    523     {
    524         DisplayModePtr m;
    525         int x = 0, y = 0;
    526 
    527         sscanf(pScrn->display->modes[i], "%dx%d", &x, &y);
    528         /* sanity check, smaller resolutions does not make sense */
    529         if (x < 64 || y < 64)
    530         {
    531             xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Ignoring mode \"%s\"\n",
    532                        pScrn->display->modes[i]);
    533             continue;
    534         }
    535         m                = xnfcalloc(sizeof(DisplayModeRec), 1);
    536         m->status        = MODE_OK;
    537         m->type          = M_T_BUILTIN;
    538         /* VBox does only support screen widths which are a multiple of 8 */
    539         m->HDisplay      = (x + 7) & ~7;
    540         m->HSyncStart    = m->HDisplay + 2;
    541         m->HSyncEnd      = m->HDisplay + 4;
    542         m->HTotal        = m->HDisplay + 6;
    543         m->VDisplay      = y;
    544         m->VSyncStart    = m->VDisplay + 2;
    545         m->VSyncEnd      = m->VDisplay + 4;
    546         m->VTotal        = m->VDisplay + 6;
    547         m->Clock         = m->HTotal * m->VTotal * 60 / 1000; /* kHz */
    548         m->name          = strdup(pScrn->display->modes[i]);
    549         if (!m_prev)
    550             pScrn->modePool = m;
    551         else
    552             m_prev->next = m;
    553         m->prev = m_prev;
    554         m_prev  = m;
    555     }
    556 
    557     /* Filter out video modes not supported by the virtual hardware
    558        we described.  All modes used by the Windows additions should
    559        work fine. */
    560     i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
    561                           pScrn->display->modes,
    562                           clockRanges, NULL, 0, 6400, 1, 0, 1440,
    563                           pScrn->display->virtualX,
    564                           pScrn->display->virtualY,
    565                           pScrn->videoRam, LOOKUP_BEST_REFRESH);
    566 
    567     if (i <= 0) {
    568         xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No usable graphics modes found.\n");
    569         return (FALSE);
    570     }
    571     xf86PruneDriverModes(pScrn);
    572 
    573     pScrn->currentMode = pScrn->modes;
    574     pScrn->displayWidth = pScrn->virtualX;
    575 
    576     xf86PrintModes(pScrn);
    577 
    578     /* Set display resolution.  This was arbitrarily chosen to be about the same as my monitor. */
    579     xf86SetDpi(pScrn, 100, 100);
    580 
    581     if (pScrn->modes == NULL) {
    582         xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No graphics modes available\n");
    583         return (FALSE);
    584     }
    585 
    586717    /* options */
    587718    xf86CollectOptions(pScrn, NULL);
     
    591722    xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pVBox->Options);
    592723
     724    /* Initialise CRTC and output configuration for use with randr1.2. */
     725    xf86CrtcConfigInit(pScrn, &VBOXCrtcConfigFuncs);
     726
     727    /* Setup our single virtual CRTC. */
     728    xf86CrtcCreate(pScrn, &VBOXCrtcFuncs);
     729
     730    /* Set up our single virtual output. */
     731    output = xf86OutputCreate(pScrn, &VBOXOutputFuncs, "Virtual Output");
     732
     733    /* Set a sane minimum and maximum mode size */
     734    xf86CrtcSetSizeRange(pScrn, 64, 64, 102400, 76800);
     735
     736    /* I don't know exactly what these are for (and they are only used in a couple
     737       of places in the X server code), but due to a bug in RandR 1.2 they place
     738       an upper limit on possible resolutions.  To add to the fun, they get set
     739       automatically if we don't do it ourselves. */
     740    pScrn->display->virtualX = 102400;
     741    pScrn->display->virtualY = 76800;
     742
     743    /* We are not interested in the monitor section in the configuration file. */
     744    xf86OutputUseScreenMonitor(output, FALSE);
     745    output->possible_crtcs = 1;
     746    output->possible_clones = 0;
     747
     748    /* Now create our initial CRTC/output configuration. */
     749    if (!xf86InitialConfiguration(pScrn, TRUE)) {
     750        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Initial CRTC configuration failed!\n");
     751        return (FALSE);
     752    }
     753
     754    /* Colour weight - we always call this, since we are always in
     755       truecolour. */
     756    if (!xf86SetWeight(pScrn, rzeros, rzeros))
     757        return (FALSE);
     758
     759    /* visual init */
     760    if (!xf86SetDefaultVisual(pScrn, -1))
     761        return (FALSE);
     762
     763    xf86SetGamma(pScrn, gzeros);
     764
     765    /* Set a default display resolution. */
     766    xf86SetDpi(pScrn, 96, 96);
     767
    593768    /* Framebuffer-related setup */
    594769    pScrn->bitmapBitOrder = BITMAP_BIT_ORDER;
     770
    595771    return (TRUE);
    596772}
     
    641817    pVBox->savedPal = VBESetGetPaletteData(pVBox->pVbe, FALSE, 0, 256,
    642818                                           NULL, FALSE, FALSE);
    643 
    644     /* set first video mode */
    645     if (!VBOXSetMode(pScrn, pScrn->currentMode))
    646         return FALSE;
    647 
    648     /* set the viewport */
    649     VBOXAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
    650 
    651     /* Blank the screen for aesthetic reasons. */
    652     VBOXSaveScreen(pScreen, SCREEN_SAVER_ON);
    653819
    654820    /* mi layer - reset the visual list (?)*/
     
    667833                      pScrn->virtualX, pScrn->virtualY,
    668834                      pScrn->xDpi, pScrn->yDpi,
    669                       pScrn->displayWidth, pScrn->bitsPerPixel))
     835                      pScrn->virtualX, pScrn->bitsPerPixel))
    670836        return (FALSE);
    671837
     
    686852    fbPictureInit(pScreen, 0, 0);
    687853
    688     VBOXDGAInit(pScrn, pScreen);
    689 
    690854    xf86SetBlackWhitePixels(pScreen);
    691855    miInitializeBackingStore(pScreen);
    692856    xf86SetBackingStore(pScreen);
     857
     858    /* Initialise DGA.  The cast is unfortunately correct - it gets cast back
     859       to (unsigned char *) later. */
     860    xf86DiDGAInit(pScreen, (unsigned long) pVBox->base);
     861
     862    /* Initialise randr 1.2 mode-setting functions and set first mode. */
     863    if (!xf86CrtcScreenInit(pScreen)) {
     864        return FALSE;
     865    }
     866
     867    if (!xf86SetDesiredModes(pScrn)) {
     868        return FALSE;
     869    }
     870
     871    /* set the viewport */
     872    VBOXAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
    693873
    694874    /* software cursor */
     
    708888    pVBox->CloseScreen = pScreen->CloseScreen;
    709889    pScreen->CloseScreen = VBOXCloseScreen;
    710     pScreen->SaveScreen = VBOXSaveScreen;
    711 
    712     /* However, we probably do want to support power management -
    713        even if we just use a dummy function. */
    714     xf86DPMSInit(pScreen, VBOXDisplayPowerManagementSet, 0);
     890    pScreen->SaveScreen = xf86SaveScreen;
     891
     892    /* We probably do want to support power management - even if we just use
     893       a dummy function. */
     894    xf86DPMSInit(pScreen, xf86DPMSSet, 0);
    715895
    716896    /* Report any unused options (only for the first generation) */
     
    734914{
    735915    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
    736     VBOXPtr pVBox = VBOXGetRec(pScrn);
    737 
    738     if (!VBOXSetMode(pScrn, pScrn->currentMode))
    739         return FALSE;
    740     VBOXAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
    741     if (pVBox->useVbva == TRUE)
    742         vboxEnableVbva(pScrn);
    743     return TRUE;
     916
     917    return xf86SetDesiredModes(pScrn);
    744918}
    745919
     
    770944        VBOXUnmapVidMem(pScrn);
    771945    }
    772     if (pVBox->pDGAMode) {
    773         xfree(pVBox->pDGAMode);
    774         pVBox->pDGAMode = NULL;
    775         pVBox->nDGAMode = 0;
    776     }
    777946    pScrn->vtSema = FALSE;
    778947
     
    811980        }
    812981    }
     982#if 0
    813983    /*
    814984     * First off, if this isn't a mode we handed to the server (ie,
     
    817987    if (!(p->type & M_T_BUILTIN))
    818988        return MODE_NOMODE;
     989#endif
    819990    /*
    820991     * Finally, walk through the vsync rates 1Hz at a time looking for a mode
     
    8421013{
    8431014    ScrnInfoPtr pScrn;
     1015
     1016    pScrn = xf86Screens[scrnIndex];  /* Why does X have three ways of refering to the screen? */
     1017    return xf86SetSingleMode(pScrn, pMode, 0);
     1018}
     1019
     1020/* Set a graphics mode */
     1021static Bool
     1022VBOXSetMode(ScrnInfoPtr pScrn, DisplayModePtr pMode)
     1023{
    8441024    VBOXPtr pVBox;
    8451025
    846     pScrn = xf86Screens[scrnIndex];  /* Why does X have three ways of refering to the screen? */
     1026    int bpp = pScrn->depth == 24 ? 32 : 16;
    8471027    pVBox = VBOXGetRec(pScrn);
    8481028    if (pVBox->useVbva == TRUE)
    8491029        if (vboxDisableVbva(pScrn) != TRUE)  /* This would be bad. */
    8501030            return FALSE;
    851     if (VBOXSetMode(pScrn, pMode) != TRUE)
    852         return FALSE;
    853     if (pVBox->useVbva == TRUE)
    854         if (vboxEnableVbva(pScrn) != TRUE)  /* Bad but not fatal */
    855             pVBox->useVbva = FALSE;
    856     return TRUE;
    857 }
    858 
    859 /* Set a graphics mode */
    860 static Bool
    861 VBOXSetMode(ScrnInfoPtr pScrn, DisplayModePtr pMode)
    862 {
    863     VBOXPtr pVBox;
    864 
    865     int bpp = pScrn->depth == 24 ? 32 : 16;
    866     int xRes = pMode->HDisplay;
    867     if (pScrn->virtualX * pScrn->virtualY * bpp / 8
    868         >= pScrn->videoRam * 1024)
    869     {
    870         xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
    871                    "Unable to set up a virtual screen size of %dx%d with %d Kb of video memory.  Please increase the video memory size.\n",
    872                    pScrn->virtualX, pScrn->virtualY, pScrn->videoRam);
    873         return FALSE;
    874     }
    875     /* We only support horizontal resolutions which are a multiple of 8.  Round down if
    876        necessary. */
    877     if (xRes % 8 != 0)
    878     {
    879         xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
    880                    "VirtualBox only supports screen widths which are a multiple of 8.  Rounding down from %d to %d\n",
    881                    xRes, xRes - (xRes % 8));
    882         xRes = xRes - (xRes % 8);
    883     }
    884     pVBox = VBOXGetRec(pScrn);
    8851031    pScrn->vtSema = TRUE;
    8861032    /* Disable linear framebuffer mode before making changes to the resolution. */
     
    8951041       the display part of the scanlines. */
    8961042    outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_XRES);
    897     outw(VBE_DISPI_IOPORT_DATA, xRes);
     1043    outw(VBE_DISPI_IOPORT_DATA, pMode->HDisplay);
    8981044    outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_YRES);
    8991045    outw(VBE_DISPI_IOPORT_DATA, pMode->VDisplay);
     
    9061052    outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_VIRT_WIDTH);
    9071053    outw(VBE_DISPI_IOPORT_DATA, pScrn->displayWidth);
     1054    if (pVBox->useVbva == TRUE)
     1055        if (vboxEnableVbva(pScrn) != TRUE)  /* Bad but not fatal */
     1056            pVBox->useVbva = FALSE;
    9081057    return (TRUE);
    9091058}
     
    11881337}
    11891338
    1190 static Bool
    1191 VBOXSaveScreen(ScreenPtr pScreen, int mode)
    1192 {
    1193     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
    1194     VBOXPtr pVBox = VBOXGetRec(pScrn);
    1195     Bool on = xf86IsUnblank(mode);
    1196 
    1197     if (on)
    1198         SetTimeSinceLastInputEvent();
    1199 
    1200     if (pScrn->vtSema) {
    1201         unsigned char scrn = ReadSeq(pVBox, 0x01);
    1202 
    1203         if (on)
    1204             scrn &= ~0x20;
    1205         else
    1206             scrn |= 0x20;
    1207         SeqReset(pVBox, TRUE);
    1208         WriteSeq(0x01, scrn);
    1209         SeqReset(pVBox, FALSE);
    1210     }
    1211 
    1212     return (TRUE);
    1213 }
    1214 
    12151339Bool
    12161340VBOXSaveRestore(ScrnInfoPtr pScrn, vbeSaveRestoreFunction function)
     
    12711395    return (TRUE);
    12721396}
    1273 
    1274 static void
    1275 VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode,
    1276                 int flags)
    1277 {
    1278     /* VBox is always power efficient... */
    1279 }
    1280 
    1281 
    1282 
    1283 
    1284 /***********************************************************************
    1285  * DGA stuff
    1286  ***********************************************************************/
    1287 static Bool VBOXDGAOpenFramebuffer(ScrnInfoPtr pScrn, char **DeviceName,
    1288                                    unsigned char **ApertureBase,
    1289                                    int *ApertureSize, int *ApertureOffset,
    1290                                    int *flags);
    1291 static Bool VBOXDGASetMode(ScrnInfoPtr pScrn, DGAModePtr pDGAMode);
    1292 static void VBOXDGASetViewport(ScrnInfoPtr pScrn, int x, int y, int flags);
    1293 
    1294 static Bool
    1295 VBOXDGAOpenFramebuffer(ScrnInfoPtr pScrn, char **DeviceName,
    1296                        unsigned char **ApertureBase, int *ApertureSize,
    1297                        int *ApertureOffset, int *flags)
    1298 {
    1299     VBOXPtr pVBox = VBOXGetRec(pScrn);
    1300 
    1301     *DeviceName = NULL;         /* No special device */
    1302     *ApertureBase = (unsigned char *)(long)(pVBox->mapPhys);
    1303     *ApertureSize = pVBox->mapSize;
    1304     *ApertureOffset = pVBox->mapOff;
    1305     *flags = DGA_NEED_ROOT;
    1306 
    1307     return (TRUE);
    1308 }
    1309 
    1310 static Bool
    1311 VBOXDGASetMode(ScrnInfoPtr pScrn, DGAModePtr pDGAMode)
    1312 {
    1313     DisplayModePtr pMode;
    1314     int scrnIdx = pScrn->pScreen->myNum;
    1315     int frameX0, frameY0;
    1316 
    1317     if (pDGAMode) {
    1318         pMode = pDGAMode->mode;
    1319         frameX0 = frameY0 = 0;
    1320     }
    1321     else {
    1322         if (!(pMode = pScrn->currentMode))
    1323             return (TRUE);
    1324 
    1325         frameX0 = pScrn->frameX0;
    1326         frameY0 = pScrn->frameY0;
    1327     }
    1328 
    1329     if (!(*pScrn->SwitchMode)(scrnIdx, pMode, 0))
    1330         return (FALSE);
    1331     (*pScrn->AdjustFrame)(scrnIdx, frameX0, frameY0, 0);
    1332 
    1333     return (TRUE);
    1334 }
    1335 
    1336 static void
    1337 VBOXDGASetViewport(ScrnInfoPtr pScrn, int x, int y, int flags)
    1338 {
    1339     (*pScrn->AdjustFrame)(pScrn->pScreen->myNum, x, y, flags);
    1340 }
    1341 
    1342 static int
    1343 VBOXDGAGetViewport(ScrnInfoPtr pScrn)
    1344 {
    1345     return (0);
    1346 }
    1347 
    1348 static DGAFunctionRec VBOXDGAFunctions =
    1349 {
    1350     VBOXDGAOpenFramebuffer,
    1351     NULL,       /* CloseFramebuffer */
    1352     VBOXDGASetMode,
    1353     VBOXDGASetViewport,
    1354     VBOXDGAGetViewport,
    1355     NULL,       /* Sync */
    1356     NULL,       /* FillRect */
    1357     NULL,       /* BlitRect */
    1358     NULL,       /* BlitTransRect */
    1359 };
    1360 
    1361 static void
    1362 VBOXDGAAddModes(ScrnInfoPtr pScrn)
    1363 {
    1364     VBOXPtr pVBox = VBOXGetRec(pScrn);
    1365     DisplayModePtr pMode = pScrn->modes;
    1366     DGAModePtr pDGAMode;
    1367 
    1368     do {
    1369         pDGAMode = xrealloc(pVBox->pDGAMode,
    1370                             (pVBox->nDGAMode + 1) * sizeof(DGAModeRec));
    1371         if (!pDGAMode)
    1372             break;
    1373 
    1374         pVBox->pDGAMode = pDGAMode;
    1375         pDGAMode += pVBox->nDGAMode;
    1376         (void)memset(pDGAMode, 0, sizeof(DGAModeRec));
    1377 
    1378         ++pVBox->nDGAMode;
    1379         pDGAMode->mode = pMode;
    1380         pDGAMode->flags = DGA_CONCURRENT_ACCESS | DGA_PIXMAP_AVAILABLE;
    1381         pDGAMode->byteOrder = pScrn->imageByteOrder;
    1382         pDGAMode->depth = pScrn->depth;
    1383         pDGAMode->bitsPerPixel = pScrn->bitsPerPixel;
    1384         pDGAMode->red_mask = pScrn->mask.red;
    1385         pDGAMode->green_mask = pScrn->mask.green;
    1386         pDGAMode->blue_mask = pScrn->mask.blue;
    1387         pDGAMode->visualClass = TrueColor;
    1388         pDGAMode->xViewportStep = 1;
    1389         pDGAMode->yViewportStep = 1;
    1390         pDGAMode->viewportWidth = pMode->HDisplay;
    1391         pDGAMode->viewportHeight = pMode->VDisplay;
    1392 
    1393         pDGAMode->bytesPerScanline = pVBox->maxBytesPerScanline;
    1394         pDGAMode->imageWidth = pMode->HDisplay;
    1395         pDGAMode->imageHeight =  pMode->VDisplay;
    1396         pDGAMode->pixmapWidth = pDGAMode->imageWidth;
    1397         pDGAMode->pixmapHeight = pDGAMode->imageHeight;
    1398         pDGAMode->maxViewportX = pScrn->virtualX -
    1399                                     pDGAMode->viewportWidth;
    1400         pDGAMode->maxViewportY = pScrn->virtualY -
    1401                                     pDGAMode->viewportHeight;
    1402 
    1403         pDGAMode->address = pVBox->base;
    1404 
    1405         pMode = pMode->next;
    1406     } while (pMode != pScrn->modes);
    1407 }
    1408 
    1409 static Bool
    1410 VBOXDGAInit(ScrnInfoPtr pScrn, ScreenPtr pScreen)
    1411 {
    1412     VBOXPtr pVBox = VBOXGetRec(pScrn);
    1413 
    1414     if (!pVBox->nDGAMode)
    1415         VBOXDGAAddModes(pScrn);
    1416 
    1417     return (DGAInit(pScreen, &VBOXDGAFunctions,
    1418             pVBox->pDGAMode, pVBox->nDGAMode));
    1419 }
Note: See TracChangeset for help on using the changeset viewer.

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