VirtualBox

Changeset 7168 in vbox for trunk/src/VBox/Additions/x11


Ignore:
Timestamp:
Feb 27, 2008 12:47:42 PM (17 years ago)
Author:
vboxsync
Message:

Additions/X11: updated mode setting in the X11 additions

Location:
trunk/src/VBox/Additions/x11/xgraphics
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/xgraphics/vboxutils.c

    r7087 r7168  
    119119    xfree (pVBox->reqp);
    120120    pVBox->reqp = NULL;
    121 
    122     VbglR3Term();
    123121}
    124122
     
    308306
    309307Bool
     308vbox_init(int scrnIndex)
     309{
     310    Bool rc = TRUE;
     311    int vrc = VbglR3Init();
     312    if (RT_FAILURE(vrc))
     313    {
     314        xf86DrvMsg(scrnIndex, X_ERROR, "VbglR3Init failed rc=%d.\n", rc);
     315        rc = FALSE;
     316    }
     317    return rc;
     318}
     319
     320Bool
    310321vbox_open(ScrnInfoPtr pScrn, ScreenPtr pScreen, VBOXPtr pVBox)
    311322{
     
    324335        pVBox->useVbva = vboxInitVbva(scrnIndex, pScreen, pVBox);
    325336        return TRUE;
    326     }
    327 
    328     rc = VbglR3Init();
    329     if (RT_FAILURE(rc))
    330     {
    331         xf86DrvMsg(scrnIndex, X_ERROR, "VbglR3Init failed rc=%d.\n", rc);
    332         return FALSE;
    333337    }
    334338
     
    352356    }
    353357    xf86DrvMsg(scrnIndex, X_ERROR, "Could not allocate %lu bytes for VMM request\n", (unsigned long)size);
    354     VbglR3Term();
    355358    return FALSE;
    356359}
  • trunk/src/VBox/Additions/x11/xgraphics/vboxvideo.h

    r6849 r7168  
    183183#endif
    184184
    185 Bool vbox_cursor_init (ScreenPtr pScreen);
    186 Bool vbox_open (ScrnInfoPtr pScrn, ScreenPtr pScreen, VBOXPtr pVBOX);
    187 void vbox_close (ScrnInfoPtr pScrn, VBOXPtr pVBOX);
     185extern Bool vbox_init(int scrnIndex);
     186extern Bool vbox_cursor_init (ScreenPtr pScreen);
     187extern Bool vbox_open (ScrnInfoPtr pScrn, ScreenPtr pScreen, VBOXPtr pVBOX);
     188extern void vbox_close (ScrnInfoPtr pScrn, VBOXPtr pVBOX);
    188189
    189190extern Bool vboxEnableVbva(ScrnInfoPtr pScrn);
  • trunk/src/VBox/Additions/x11/xgraphics/vboxvideo_13.c

    r6849 r7168  
    409409        vbox_output_add_mode(&pModes, NULL, x, y, TRUE);
    410410    }
    411     vbox_output_add_mode(&pModes, "1024x768", 1024, 768, FALSE);
    412     vbox_output_add_mode(&pModes, "800x600", 800, 600, FALSE);
    413     vbox_output_add_mode(&pModes, "640x480", 640, 480, FALSE);
     411    vbox_output_add_mode(&pModes, NULL, 1024, 768, FALSE);
     412    vbox_output_add_mode(&pModes, NULL, 800, 600, FALSE);
     413    vbox_output_add_mode(&pModes, NULL, 640, 480, FALSE);
    414414    TRACE2;
    415415    return pModes;
     
    648648        return (FALSE);
    649649
    650     xf86Msg(X_INFO,
    651             "VirtualBox guest additions video driver version "
    652             VBOX_VERSION_STRING "\n");
     650    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
     651               "VirtualBox guest additions video driver version "
     652               VBOX_VERSION_STRING "\n");
     653
     654    /* Initialise the guest library */
     655    if (!vbox_init(pScrn->scrnIndex))
     656        return FALSE;
    653657
    654658    /* Get our private data from the ScrnInfoRec structure. */
     
    700704    pScrn->videoRam = inl(VBE_DISPI_IOPORT_DATA) / 1024;
    701705
    702     /* This function asks X to choose a depth and bpp based on the
    703        config file and the command line, and gives a default in
    704        case none is specified.  Note that we only support 32bpp, not
    705        24bpp.  After spending ages looking through the XFree86 4.2
    706        source code however, I realised that it automatically uses
    707        32bpp for depth 24 unless you explicitly add a "24 24"
    708        format to its internal list. */
    709     if (!xf86SetDepthBpp(pScrn, pScrn->videoRam >= 2048 ? 24 : 16, 0, 0,
    710                          Support32bppFb))
    711         return FALSE;
    712     if (pScrn->depth != 24 && pScrn->depth != 16)
     706    /* Query the host for the preferred colour depth */
     707    {
     708        uint32_t cx, cy, iDisplay, cBits = 24;
     709
     710        /* We only support 16 and 24 bits depth (i.e. 16 and 32bpp) */
     711        if (   vboxGetDisplayChangeRequest(pScrn, &cx, &cy, &cBits, &iDisplay)
     712            && (cBits != 16))
     713            cBits = 24;
     714        if (!xf86SetDepthBpp(pScrn, cBits, 0, 0, Support32bppFb))
     715            return FALSE;
     716    }
     717    if (pScrn->bitsPerPixel != 32 && pScrn->bitsPerPixel != 16)
    713718    {
    714719        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
     
    734739    output = xf86OutputCreate(pScrn, &VBOXOutputFuncs, "Virtual Output");
    735740
    736     /* Set a sane minimum and maximum mode size */
    737     xf86CrtcSetSizeRange(pScrn, 64, 64, 64000, 64000);
    738 
    739     /* I don't know exactly what these are for (and they are only used in a couple
    740        of places in the X server code), but due to a bug in RandR 1.2 they place
    741        an upper limit on possible resolutions.  To add to the fun, they get set
    742        automatically if we don't do it ourselves. */
    743     pScrn->display->virtualX = 64000;
    744     pScrn->display->virtualY = 64000;
     741    /* Set a sane minimum mode size and the maximum allowed by the available VRAM */
     742    /** @todo Make sure that the host resolution is supported if it fits into VRAM. */
     743    {
     744        unsigned maxSize, trySize = 512;
     745
     746        do {
     747            maxSize = trySize;
     748            trySize += 128;
     749        } while (trySize * trySize * pScrn->bitsPerPixel / 8 < pScrn->videoRam * 1024);
     750
     751        xf86CrtcSetSizeRange(pScrn, 64, 64, maxSize, maxSize);
     752
     753        /* I don't know exactly what these are for (and they are only used in a couple
     754           of places in the X server code), but due to a bug in RandR 1.2 they place
     755           an upper limit on possible resolutions.  To add to the fun, they get set
     756           automatically if we don't do it ourselves. */
     757        pScrn->display->virtualX = maxSize;
     758        pScrn->display->virtualY = maxSize;
     759        xf86DrvMsg(pScrn->scrnIndex, X_INFO,
     760                   "The maximum supported resolution is currently %dx%d\n", maxSize, maxSize);
     761    }
    745762
    746763    /* We are not interested in the monitor section in the configuration file. */
     
    10471064    outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_YRES);
    10481065    outw(VBE_DISPI_IOPORT_DATA, pMode->VDisplay);
     1066    /* Set the virtual resolution.  We are still using VESA to control
     1067       the virtual offset. */
     1068    outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_VIRT_WIDTH);
     1069    outw(VBE_DISPI_IOPORT_DATA, pScrn->displayWidth);
    10491070    /* Enable linear framebuffer mode. */
    10501071    outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ENABLE);
    10511072    outw(VBE_DISPI_IOPORT_DATA,
    10521073         VBE_DISPI_ENABLED | VBE_DISPI_LFB_ENABLED);
    1053     /* Set the virtual resolution.  We are still using VESA to control
    1054        the virtual offset. */
    1055     outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_VIRT_WIDTH);
    1056     outw(VBE_DISPI_IOPORT_DATA, pScrn->displayWidth);
    10571074    if (pVBox->useVbva == TRUE)
    10581075        if (vboxEnableVbva(pScrn) != TRUE)  /* Bad but not fatal */
  • trunk/src/VBox/Additions/x11/xgraphics/vboxvideo_68.c

    r6643 r7168  
    371371        return (FALSE);
    372372
    373     xf86Msg(X_INFO,
    374             "VirtualBox guest additions video driver version "
    375             VBOX_VERSION_STRING "\n");
     373    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
     374               "VirtualBox guest additions video driver version "
     375               VBOX_VERSION_STRING "\n");
    376376
    377377    /* Get our private data from the ScrnInfoRec structure. */
     
    453453                         Support32bppFb))
    454454        return FALSE;
    455     if (pScrn->depth != 24 && pScrn->depth != 16)
     455    if (pScrn->bitsPerPixel != 32 && pScrn->bitsPerPixel != 16)
    456456    {
    457457        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
     
    497497    }
    498498
    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 
    504499    /* Create a builtin mode for every specified mode. This allows to specify arbitrary
    505500     * screen resolutions */
     
    511506
    512507        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         }
    520508        m                = xnfcalloc(sizeof(DisplayModeRec), 1);
    521509        m->status        = MODE_OK;
     
    533521    }
    534522
     523    /* Set a sane minimum mode size and the maximum allowed by the available VRAM */
     524    {
     525        unsigned maxSize, trySize = 512;
     526
     527        do {
     528            maxSize = trySize;
     529            trySize += 128;
     530        } while (trySize * trySize * pScrn->bitsPerPixel / 8 < pScrn->videoRam * 1024);
     531
     532        /* I don't know exactly what these are for (and they are only used in a couple
     533           of places in the X server code). */
     534        pScrn->display->virtualX = maxSize;
     535        pScrn->display->virtualY = maxSize;
     536        xf86DrvMsg(pScrn->scrnIndex, X_INFO,
     537                   "The maximum supported resolution is currently %dx%d\n", maxSize, maxSize);
     538    }
     539
    535540    /* Filter out video modes not supported by the virtual hardware
    536        we described.  All modes used by the Windows additions should
    537        work fine. */
     541       we described. */
    538542    i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
    539543                          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                          clockRanges, NULL, 64, pScrn->display->virtualX, 1,
     545                          64, pScrn->display->virtualY, 0, 0,
     546                          pScrn->videoRam * 1024, LOOKUP_BEST_REFRESH);
    544547
    545548    if (i <= 0) {
     
    554557    xf86PrintModes(pScrn);
    555558
    556     /* Set display resolution.  This was arbitrarily chosen to be about the same as my monitor. */
    557     xf86SetDpi(pScrn, 100, 100);
     559    /* Set display resolution.  Perhaps we should read this from the host. */
     560    xf86SetDpi(pScrn, 96, 96);
    558561
    559562    if (pScrn->modes == NULL) {
  • trunk/src/VBox/Additions/x11/xgraphics/vboxvideo_70.c

    r6642 r7168  
    381381    int i;
    382382    DisplayModePtr m_prev;
     383    char *pcHostModeName = NULL;
    383384
    384385    /* Are we really starting the server, or is this just a dummy run? */
     
    386387        return (FALSE);
    387388
    388     xf86Msg(X_INFO,
    389             "VirtualBox guest additions video driver version "
    390             VBOX_VERSION_STRING "\n");
    391 
    392     /* Get our private data from the ScrnInfoRec structure. */
     389    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
     390               "VirtualBox guest additions video driver version "
     391               VBOX_VERSION_STRING "\n");
     392
     393    /* Initialise the guest library */
     394    if (!vbox_init(pScrn->scrnIndex))
     395        return FALSE;
     396
     397     /* Get our private data from the ScrnInfoRec structure. */
    393398    pVBox = VBOXGetRec(pScrn);
    394399
     
    458463    clockRanges->ClockDivFactor = 1;
    459464
    460     /* This function asks X to choose a depth and bpp based on the
    461        config file and the command line, and gives a default in
    462        case none is specified.  Note that we only support 32bpp, not
    463        24bpp.  After spending ages looking through the XFree86 4.2
    464        source code however, I realised that it automatically uses
    465        32bpp for depth 24 unless you explicitly add a "24 24"
    466        format to its internal list. */
    467     if (!xf86SetDepthBpp(pScrn, pScrn->videoRam >= 2048 ? 24 : 16, 0, 0,
    468                          Support32bppFb))
    469         return FALSE;
    470     if (pScrn->depth != 24 && pScrn->depth != 16)
     465    /* Query the host for the preferred resolution and colour depth */
     466    {
     467        uint32_t cx, cy, iDisplay, cBits = 24;
     468
     469        if (vboxGetDisplayChangeRequest(pScrn, &cx, &cy, &cBits, &iDisplay))
     470        {
     471            /* We only support 16 and 24 bits depth (i.e. 16 and 32bpp) */
     472            if (cBits != 16)
     473                cBits = 24;
     474            pcHostModeName = XNFprintf("%dx%d", cx, cy);
     475        }
     476        if (!xf86SetDepthBpp(pScrn, cBits, 0, 0, Support32bppFb))
     477            return FALSE;
     478    }
     479    if (pScrn->bitsPerPixel != 32 && pScrn->bitsPerPixel != 16)
    471480    {
    472481        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
     
    476485    xf86PrintDepthBpp(pScrn);
    477486
    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 
    489487    /* 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
     488     * Xorg.conf by default, we add additional modes to the end of the user specified
    491489     * list. This means that if all user modes are invalid, X will try our mode before
    492490     * falling back to its standard mode list. */
    493491    if (pScrn->display->modes == NULL)
    494492    {
    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;
     493        i = 0;
     494        /* The user specified no modes at all. */
     495        pScrn->display->modes = xnfalloc(5 * sizeof(char*));
    501496    }
    502497    else
    503498    {
    504         /* Add 1024x768 to the end of the mode list in case the others are all invalid. */
    505499        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;
     500        pScrn->display->modes =   xnfrealloc(pScrn->display->modes, (i + 5)
     501                                * sizeof(char *));
     502    }
     503    /* Add additional modes to the end of the mode list in case the others are
     504       all invalid. */
     505    if (pcHostModeName != NULL)
     506        pScrn->display->modes[i] = pcHostModeName;
     507    else
     508        --i;
     509    pScrn->display->modes[i+1] = "1024x768";
     510    pScrn->display->modes[i+2] = "800x600";
     511    pScrn->display->modes[i+3] = "640x480";
     512    pScrn->display->modes[i+4] = NULL;
    518513
    519514    /* Create a builtin mode for every specified mode. This allows to specify arbitrary
     
    526521
    527522        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         }
    535523        m                = xnfcalloc(sizeof(DisplayModeRec), 1);
    536524        m->status        = MODE_OK;
     
    555543    }
    556544
     545    /* Colour weight - we always call this, since we are always in
     546       truecolour. */
     547    if (!xf86SetWeight(pScrn, rzeros, rzeros))
     548        return (FALSE);
     549
     550    /* visual init */
     551    if (!xf86SetDefaultVisual(pScrn, -1))
     552        return (FALSE);
     553
     554    xf86SetGamma(pScrn, gzeros);
     555
     556    /* Set a sane minimum mode size and the maximum allowed by the available VRAM */
     557    {
     558        unsigned maxSize, trySize = 512;
     559
     560        do {
     561            maxSize = trySize;
     562            trySize += 128;
     563        } while (trySize * trySize * pScrn->bitsPerPixel / 8 < pScrn->videoRam * 1024);
     564
     565        /* I don't know exactly what these are for (and they are only used in a couple
     566           of places in the X server code). */
     567        pScrn->display->virtualX = maxSize;
     568        pScrn->display->virtualY = maxSize;
     569        xf86DrvMsg(pScrn->scrnIndex, X_INFO,
     570                   "The maximum supported resolution is currently %dx%d\n", maxSize, maxSize);
     571    }
     572
    557573    /* Filter out video modes not supported by the virtual hardware
    558        we described.  All modes used by the Windows additions should
    559        work fine. */
     574       we described. */
    560575    i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
    561576                          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);
     577                          clockRanges, NULL, 64, pScrn->display->virtualX, 1,
     578                          64, pScrn->display->virtualY, 0, 0,
     579                          pScrn->videoRam * 1024, LOOKUP_BEST_REFRESH);
    566580
    567581    if (i <= 0) {
     
    576590    xf86PrintModes(pScrn);
    577591
    578     /* Set display resolution.  This was arbitrarily chosen to be about the same as my monitor. */
    579     xf86SetDpi(pScrn, 100, 100);
     592    /* Set display resolution.  Perhaps we should read this from the host. */
     593    xf86SetDpi(pScrn, 96, 96);
    580594
    581595    if (pScrn->modes == NULL) {
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