Changeset 97958 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Jan 3, 2023 6:57:50 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/x11/VBoxClient/display-svga-x11.cpp
r96876 r97958 48 48 * - The following assumptions are done and should be taken into account when reading/chaning the code: 49 49 * # The order of the outputs (monitors) is assumed to be the same in RANDROUTPUT array and 50 50 * XRRScreenResources.outputs array. 51 51 * - This code does 2 related but separate things: 1- It resizes and enables/disables monitors upon host's 52 53 54 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. 55 55 */ 56 57 58 /********************************************************************************************************************************* 59 * Header Files * 60 *********************************************************************************************************************************/ 56 61 #include <stdio.h> 57 62 #include <dlfcn.h> … … 76 81 #include <X11/extensions/panoramiXproto.h> 77 82 83 84 /********************************************************************************************************************************* 85 * Defined Constants And Macros * 86 *********************************************************************************************************************************/ 78 87 #define MILLIS_PER_INCH (25.4) 79 88 #define DEFAULT_DPI (96.0) … … 88 97 * context structure. */ 89 98 #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 *********************************************************************************************************************************/ 97 122 #define X_VMwareCtrlSetRes 1 98 123 … … 233 258 }; 234 259 235 /** Forward declarations. */ 260 261 /********************************************************************************************************************************* 262 * Internal Functions * 263 *********************************************************************************************************************************/ 236 264 static void x11Connect(); 237 265 static int determineOutputCount(); 238 266 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. */ 272 RTPOINT *mpMonitorPositions; 273 /** Thread to listen to some of the X server events. */ 274 RTTHREAD mX11MonitorThread = NIL_RTTHREAD; 275 /** Shutdown indicator for the monitor thread. */ 276 static bool g_fMonitorThreadShutdown = false; 255 277 256 278 … … 259 281 * out of horizontal and vertical resolutions. Replicated here to avoid further 260 282 * dependencies. */ 261 DisplayModeR f86CVTMode(int HDisplay, int VDisplay, float VRefresh /* Herz */, Bool Reduced, 262 Bool Interlaced) 283 DisplayModeR f86CVTMode(int HDisplay, int VDisplay, float VRefresh /* Herz */, Bool Reduced, Bool Interlaced) 263 284 { 264 285 DisplayModeR Mode; … … 301 322 if (Margins) { 302 323 /* 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); 304 325 HMargin -= HMargin % CVT_H_GRANULARITY; 305 326 } … … 320 341 if (Margins) 321 342 /* 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); 323 344 else 324 345 VMargin = 0; … … 360 381 361 382 /* 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); 364 385 365 386 /* 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) 368 388 VSyncAndBackPorch = VSync + CVT_MIN_V_PORCH; 369 389 else 370 VSyncAndBackPorch = (int) 390 VSyncAndBackPorch = (int)(CVT_MIN_VSYNC_BP / HPeriod) + 1; 371 391 372 392 /* 10. Find number of lines in back porch */ … … 375 395 376 396 /* 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; 379 398 380 399 /* 5) Definition of Horizontal blanking time limitation */ … … 391 410 #define CVT_J_FACTOR 20 392 411 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) 396 414 397 415 /* 12. Find ideal blanking duty cycle from formula */ … … 402 420 HBlankPercentage = 20; 403 421 404 HBlank = Mode.HDisplay * HBlankPercentage / (100.0 - HBlankPercentage);422 HBlank = (int)(Mode.HDisplay * HBlankPercentage / (100.0 - HBlankPercentage)); 405 423 HBlank -= HBlank % (2 * CVT_H_GRANULARITY); 406 424 … … 411 429 Mode.HSyncEnd = Mode.HDisplay + HBlank / 2; 412 430 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; 417 433 418 434 /* Fill in VSync values */ … … 437 453 438 454 /* 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); 441 456 442 457 /* 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); 444 459 445 460 /* 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) 447 462 VBILines = CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH; 448 463 449 464 /* 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); 451 466 452 467 /* 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); 454 469 455 470 /* 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); 458 473 459 474 /* Fill in VSync values */ … … 462 477 } 463 478 /* 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); 465 480 Mode.Clock -= Mode.Clock % CVT_CLOCK_STEP; 466 481 467 482 /* 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; 469 484 470 485 /* 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); 473 487 474 488 /* 18/16. Find actual vertical frame frequency */ … … 1149 1163 { 1150 1164 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; 1156 1168 } 1157 1169
Note:
See TracChangeset
for help on using the changeset viewer.