VirtualBox

Changeset 97958 in vbox for trunk/src/VBox/Additions


Ignore:
Timestamp:
Jan 3, 2023 6:57:50 PM (2 years ago)
Author:
vboxsync
Message:

add/x11/VBoxClient: Address warnings in f86CVTMode and elsewhere in display-svga-x11.cpp. Cleanups. bugref:9637

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/display-svga-x11.cpp

    r96876 r97958  
    4848 *  - The following assumptions are done and should be taken into account when reading/chaning the code:
    4949 *    # The order of the outputs (monitors) is assumed to be the same in RANDROUTPUT array and
    50         XRRScreenResources.outputs array.
     50 *    XRRScreenResources.outputs array.
    5151 *  - This code does 2 related but separate things: 1- It resizes and enables/disables monitors upon host's
    52       requests (see the infinite loop in run()). 2- it listens to RandR events (caused by this or any other X11 client)
    53       on a different thread and notifies host about the new monitor positions. See sendMonitorPositions(...). This is
    54       mainly a work around since we have realized that vmsvga does not convey correct monitor positions thru FIFO.
     52 *    requests (see the infinite loop in run()). 2- it listens to RandR events (caused by this or any other X11 client)
     53 *    on a different thread and notifies host about the new monitor positions. See sendMonitorPositions(...). This is
     54 *    mainly a work around since we have realized that vmsvga does not convey correct monitor positions thru FIFO.
    5555 */
     56
     57
     58/*********************************************************************************************************************************
     59*   Header Files                                                                                                                 *
     60*********************************************************************************************************************************/
    5661#include <stdio.h>
    5762#include <dlfcn.h>
     
    7681#include <X11/extensions/panoramiXproto.h>
    7782
     83
     84/*********************************************************************************************************************************
     85*   Defined Constants And Macros                                                                                                 *
     86*********************************************************************************************************************************/
    7887#define MILLIS_PER_INCH (25.4)
    7988#define DEFAULT_DPI (96.0)
     
    8897 *  context structure. */
    8998#define VMW_MAX_HEADS 32
    90 /** Monitor positions array. Allocated here and deallocated in the class descructor. */
    91 RTPOINT *mpMonitorPositions;
    92 /** Thread to listen to some of the X server events. */
    93 RTTHREAD mX11MonitorThread = NIL_RTTHREAD;
    94 /** Shutdown indicator for the monitor thread. */
    95 static bool g_fMonitorThreadShutdown = false;
    96 
     99
     100#define checkFunctionPtrReturn(pFunction) \
     101    do { \
     102        if (pFunction) { } \
     103        else \
     104        { \
     105            VBClLogFatalError("Could not find symbol address (%s)\n", #pFunction); \
     106            dlclose(x11Context.pRandLibraryHandle); \
     107            x11Context.pRandLibraryHandle = NULL; \
     108            return VERR_NOT_FOUND; \
     109        } \
     110    } while (0)
     111
     112#define checkFunctionPtr(pFunction) \
     113    do { \
     114        if (pFunction) {} \
     115        else VBClLogError("Could not find symbol address (%s)\n", #pFunction);\
     116    } while (0)
     117
     118
     119/*********************************************************************************************************************************
     120*   Structures and Typedefs                                                                                                      *
     121*********************************************************************************************************************************/
    97122#define X_VMwareCtrlSetRes  1
    98123
     
    233258};
    234259
    235 /** Forward declarations. */
     260
     261/*********************************************************************************************************************************
     262*   Internal Functions                                                                                                           *
     263*********************************************************************************************************************************/
    236264static void x11Connect();
    237265static int determineOutputCount();
    238266
    239 #define checkFunctionPtrReturn(pFunction) \
    240     do { \
    241         if (!pFunction) \
    242         { \
    243             VBClLogFatalError("Could not find symbol address (%s)\n", #pFunction); \
    244             dlclose(x11Context.pRandLibraryHandle); \
    245             x11Context.pRandLibraryHandle = NULL; \
    246             return VERR_NOT_FOUND; \
    247         } \
    248     } while (0)
    249 
    250 #define checkFunctionPtr(pFunction) \
    251     do { \
    252         if (!pFunction) \
    253             VBClLogError("Could not find symbol address (%s)\n", #pFunction);\
    254     } while (0)
     267
     268/*********************************************************************************************************************************
     269*   Global Variables                                                                                                             *
     270*********************************************************************************************************************************/
     271/** Monitor positions array. Allocated here and deallocated in the class descructor. */
     272RTPOINT *mpMonitorPositions;
     273/** Thread to listen to some of the X server events. */
     274RTTHREAD mX11MonitorThread = NIL_RTTHREAD;
     275/** Shutdown indicator for the monitor thread. */
     276static bool g_fMonitorThreadShutdown = false;
    255277
    256278
     
    259281  * out of horizontal and vertical resolutions. Replicated here to avoid further
    260282  * dependencies. */
    261 DisplayModeR f86CVTMode(int HDisplay, int VDisplay, float VRefresh /* Herz */, Bool Reduced,
    262             Bool Interlaced)
     283DisplayModeR f86CVTMode(int HDisplay, int VDisplay, float VRefresh /* Herz */, Bool Reduced, Bool Interlaced)
    263284{
    264285    DisplayModeR Mode;
     
    301322    if (Margins) {
    302323        /* right margin is actually exactly the same as left */
    303         HMargin = (((float) HDisplayRnd) * CVT_MARGIN_PERCENTAGE / 100.0);
     324        HMargin = (int)((float)HDisplayRnd * CVT_MARGIN_PERCENTAGE / 100.0);
    304325        HMargin -= HMargin % CVT_H_GRANULARITY;
    305326    }
     
    320341    if (Margins)
    321342        /* top and bottom margins are equal again. */
    322         VMargin = (((float) VDisplayRnd) * CVT_MARGIN_PERCENTAGE / 100.0);
     343        VMargin = (int)((float)VDisplayRnd * CVT_MARGIN_PERCENTAGE / 100.0);
    323344    else
    324345        VMargin = 0;
     
    360381
    361382        /* 8. Estimated Horizontal period */
    362         HPeriod = ((float) (1000000.0 / VFieldRate - CVT_MIN_VSYNC_BP)) /
    363             (VDisplayRnd + 2 * VMargin + CVT_MIN_V_PORCH + Interlace);
     383        HPeriod = ((float)(1000000.0 / VFieldRate - CVT_MIN_VSYNC_BP))
     384                / (VDisplayRnd + 2 * VMargin + CVT_MIN_V_PORCH + Interlace);
    364385
    365386        /* 9. Find number of lines in sync + backporch */
    366         if (((int) (CVT_MIN_VSYNC_BP / HPeriod) + 1) <
    367             (VSync + CVT_MIN_V_PORCH))
     387        if ((int)(CVT_MIN_VSYNC_BP / HPeriod) + 1 < VSync + CVT_MIN_V_PORCH)
    368388            VSyncAndBackPorch = VSync + CVT_MIN_V_PORCH;
    369389        else
    370             VSyncAndBackPorch = (int) (CVT_MIN_VSYNC_BP / HPeriod) + 1;
     390            VSyncAndBackPorch = (int)(CVT_MIN_VSYNC_BP / HPeriod) + 1;
    371391
    372392        /* 10. Find number of lines in back porch */
     
    375395
    376396        /* 11. Find total number of lines in vertical field */
    377         Mode.VTotal = VDisplayRnd + 2 * VMargin + VSyncAndBackPorch + Interlace
    378             + CVT_MIN_V_PORCH;
     397        Mode.VTotal = VDisplayRnd + 2 * VMargin + VSyncAndBackPorch + Interlace + CVT_MIN_V_PORCH;
    379398
    380399        /* 5) Definition of Horizontal blanking time limitation */
     
    391410#define CVT_J_FACTOR 20
    392411
    393 #define CVT_M_PRIME CVT_M_FACTOR * CVT_K_FACTOR / 256
    394 #define CVT_C_PRIME (CVT_C_FACTOR - CVT_J_FACTOR) * CVT_K_FACTOR / 256 + \
    395         CVT_J_FACTOR
     412#define CVT_M_PRIME (CVT_M_FACTOR * CVT_K_FACTOR / 256)
     413#define CVT_C_PRIME ((CVT_C_FACTOR - CVT_J_FACTOR) * CVT_K_FACTOR / 256 + CVT_J_FACTOR)
    396414
    397415        /* 12. Find ideal blanking duty cycle from formula */
     
    402420            HBlankPercentage = 20;
    403421
    404         HBlank = Mode.HDisplay * HBlankPercentage / (100.0 - HBlankPercentage);
     422        HBlank = (int)(Mode.HDisplay * HBlankPercentage / (100.0 - HBlankPercentage));
    405423        HBlank -= HBlank % (2 * CVT_H_GRANULARITY);
    406424
     
    411429        Mode.HSyncEnd = Mode.HDisplay + HBlank / 2;
    412430
    413         Mode.HSyncStart = Mode.HSyncEnd -
    414             (Mode.HTotal * CVT_HSYNC_PERCENTAGE) / 100;
    415         Mode.HSyncStart += CVT_H_GRANULARITY -
    416             Mode.HSyncStart % CVT_H_GRANULARITY;
     431        Mode.HSyncStart = Mode.HSyncEnd - (Mode.HTotal * CVT_HSYNC_PERCENTAGE) / 100;
     432        Mode.HSyncStart += CVT_H_GRANULARITY - Mode.HSyncStart % CVT_H_GRANULARITY;
    417433
    418434        /* Fill in VSync values */
     
    437453
    438454        /* 8. Estimate Horizontal period. */
    439         HPeriod = ((float) (1000000.0 / VFieldRate - CVT_RB_MIN_VBLANK)) /
    440             (VDisplayRnd + 2 * VMargin);
     455        HPeriod = ((float)(1000000.0 / VFieldRate - CVT_RB_MIN_VBLANK)) / (VDisplayRnd + 2 * VMargin);
    441456
    442457        /* 9. Find number of lines in vertical blanking */
    443         VBILines = ((float) CVT_RB_MIN_VBLANK) / HPeriod + 1;
     458        VBILines = (int)((float)CVT_RB_MIN_VBLANK / HPeriod + 1);
    444459
    445460        /* 10. Check if vertical blanking is sufficient */
    446         if (VBILines < (CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH))
     461        if (VBILines < CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH)
    447462            VBILines = CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH;
    448463
    449464        /* 11. Find total number of lines in vertical field */
    450         Mode.VTotal = VDisplayRnd + 2 * VMargin + Interlace + VBILines;
     465        Mode.VTotal = (int)(VDisplayRnd + 2 * VMargin + Interlace + VBILines);
    451466
    452467        /* 12. Find total number of pixels in a line */
    453         Mode.HTotal = Mode.HDisplay + CVT_RB_H_BLANK;
     468        Mode.HTotal = (int)(Mode.HDisplay + CVT_RB_H_BLANK);
    454469
    455470        /* Fill in HSync values */
    456         Mode.HSyncEnd = Mode.HDisplay + CVT_RB_H_BLANK / 2;
    457         Mode.HSyncStart = Mode.HSyncEnd - CVT_RB_H_SYNC;
     471        Mode.HSyncEnd = (int)(Mode.HDisplay + CVT_RB_H_BLANK / 2);
     472        Mode.HSyncStart = (int)(Mode.HSyncEnd - CVT_RB_H_SYNC);
    458473
    459474        /* Fill in VSync values */
     
    462477    }
    463478    /* 15/13. Find pixel clock frequency (kHz for xf86) */
    464     Mode.Clock = Mode.HTotal * 1000.0 / HPeriod;
     479    Mode.Clock = (int)(Mode.HTotal * 1000.0 / HPeriod);
    465480    Mode.Clock -= Mode.Clock % CVT_CLOCK_STEP;
    466481
    467482    /* 16/14. Find actual Horizontal Frequency (kHz) */
    468     Mode.HSync = ((float) Mode.Clock) / ((float) Mode.HTotal);
     483    Mode.HSync = (float)Mode.Clock / (float)Mode.HTotal;
    469484
    470485    /* 17/15. Find actual Field rate */
    471     Mode.VRefresh = (1000.0 * ((float) Mode.Clock)) /
    472         ((float) (Mode.HTotal * Mode.VTotal));
     486    Mode.VRefresh = (1000.0 * (float)Mode.Clock) / (float)(Mode.HTotal * Mode.VTotal);
    473487
    474488    /* 18/16. Find actual vertical frame frequency */
     
    11491163{
    11501164   unsigned int dpi = 0;
    1151    if (mm > 0) {
    1152       dpi = (unsigned int)((double)pixels * MILLIS_PER_INCH /
    1153                            (double)mm + 0.5);
    1154    }
    1155    return (dpi > 0) ? dpi : DEFAULT_DPI;
     1165   if (mm > 0)
     1166      dpi = (unsigned int)((double)pixels * MILLIS_PER_INCH / (double)mm + 0.5);
     1167   return dpi > 0 ? dpi : (unsigned int)DEFAULT_DPI;
    11561168}
    11571169
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