Changeset 97960 in vbox for trunk/src/VBox/Additions/x11
- Timestamp:
- Jan 3, 2023 7:24:54 PM (2 years ago)
- Location:
- trunk/src/VBox/Additions/x11
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/x11/.scm-settings
r96407 r97960 39 39 /vboxvideo/edid.c: --license-based-on-mit 40 40 /vboxvideo/setmode.c: --license-based-on-mit 41 /VBoxClient/display-svga-xf86cvt.cpp: --license-based-on-mit 41 42 42 43 # Installer -
trunk/src/VBox/Additions/x11/VBoxClient/Makefile.kmk
r96407 r97960 145 145 VBoxClient_DEFS += VBOX_WITH_VMSVGA 146 146 VBoxClient_SOURCES += \ 147 display.cpp \ 148 display-svga-x11.cpp 147 display.cpp \ 148 display-svga-x11.cpp \ 149 display-svga-xf86cvt.cpp 149 150 VBoxClient_SOURCES.linux += \ 150 display-svga-session.cpp \151 display-ipc.cpp \152 display-helper-gnome3.cpp \153 display-helper-generic.cpp151 display-svga-session.cpp \ 152 display-ipc.cpp \ 153 display-helper-gnome3.cpp \ 154 display-helper-generic.cpp 154 155 155 156 ### include $(PATH_SUB_CURRENT)/helpers/Makefile.kmk -
trunk/src/VBox/Additions/x11/VBoxClient/display-svga-x11.cpp
r97958 r97960 80 80 #include <X11/extensions/Xrandr.h> 81 81 #include <X11/extensions/panoramiXproto.h> 82 83 #include "display-svga-xf86cvt.h" 82 84 83 85 … … 240 242 }; 241 243 242 struct DisplayModeR {243 244 /* These are the values that the user sees/provides */245 int Clock; /* pixel clock freq (kHz) */246 int HDisplay; /* horizontal timing */247 int HSyncStart;248 int HSyncEnd;249 int HTotal;250 int HSkew;251 int VDisplay; /* vertical timing */252 int VSyncStart;253 int VSyncEnd;254 int VTotal;255 int VScan;256 float HSync;257 float VRefresh;258 };259 260 244 261 245 /********************************************************************************************************************************* … … 277 261 278 262 279 /** A slightly modified version of the xf86CVTMode function from xf86cvt.c280 * from the xserver source code. Computes several parameters of a display mode281 * out of horizontal and vertical resolutions. Replicated here to avoid further282 * dependencies. */283 DisplayModeR f86CVTMode(int HDisplay, int VDisplay, float VRefresh /* Herz */, Bool Reduced, Bool Interlaced)284 {285 DisplayModeR Mode;286 287 /* 1) top/bottom margin size (% of height) - default: 1.8 */288 #define CVT_MARGIN_PERCENTAGE 1.8289 290 /* 2) character cell horizontal granularity (pixels) - default 8 */291 #define CVT_H_GRANULARITY 8292 293 /* 4) Minimum vertical porch (lines) - default 3 */294 #define CVT_MIN_V_PORCH 3295 296 /* 4) Minimum number of vertical back porch lines - default 6 */297 #define CVT_MIN_V_BPORCH 6298 299 /* Pixel Clock step (kHz) */300 #define CVT_CLOCK_STEP 250301 302 Bool Margins = false;303 float VFieldRate, HPeriod;304 int HDisplayRnd, HMargin;305 int VDisplayRnd, VMargin, VSync;306 float Interlace; /* Please rename this */307 308 /* CVT default is 60.0Hz */309 if (!VRefresh)310 VRefresh = 60.0;311 312 /* 1. Required field rate */313 if (Interlaced)314 VFieldRate = VRefresh * 2;315 else316 VFieldRate = VRefresh;317 318 /* 2. Horizontal pixels */319 HDisplayRnd = HDisplay - (HDisplay % CVT_H_GRANULARITY);320 321 /* 3. Determine left and right borders */322 if (Margins) {323 /* right margin is actually exactly the same as left */324 HMargin = (int)((float)HDisplayRnd * CVT_MARGIN_PERCENTAGE / 100.0);325 HMargin -= HMargin % CVT_H_GRANULARITY;326 }327 else328 HMargin = 0;329 330 /* 4. Find total active pixels */331 Mode.HDisplay = HDisplayRnd + 2 * HMargin;332 333 /* 5. Find number of lines per field */334 if (Interlaced)335 VDisplayRnd = VDisplay / 2;336 else337 VDisplayRnd = VDisplay;338 339 /* 6. Find top and bottom margins */340 /* nope. */341 if (Margins)342 /* top and bottom margins are equal again. */343 VMargin = (int)((float)VDisplayRnd * CVT_MARGIN_PERCENTAGE / 100.0);344 else345 VMargin = 0;346 347 Mode.VDisplay = VDisplay + 2 * VMargin;348 349 /* 7. Interlace */350 if (Interlaced)351 Interlace = 0.5;352 else353 Interlace = 0.0;354 355 /* Determine VSync Width from aspect ratio */356 if (!(VDisplay % 3) && ((VDisplay * 4 / 3) == HDisplay))357 VSync = 4;358 else if (!(VDisplay % 9) && ((VDisplay * 16 / 9) == HDisplay))359 VSync = 5;360 else if (!(VDisplay % 10) && ((VDisplay * 16 / 10) == HDisplay))361 VSync = 6;362 else if (!(VDisplay % 4) && ((VDisplay * 5 / 4) == HDisplay))363 VSync = 7;364 else if (!(VDisplay % 9) && ((VDisplay * 15 / 9) == HDisplay))365 VSync = 7;366 else /* Custom */367 VSync = 10;368 369 if (!Reduced) { /* simplified GTF calculation */370 371 /* 4) Minimum time of vertical sync + back porch interval (µs)372 * default 550.0 */373 #define CVT_MIN_VSYNC_BP 550.0374 375 /* 3) Nominal HSync width (% of line period) - default 8 */376 #define CVT_HSYNC_PERCENTAGE 8377 378 float HBlankPercentage;379 int VSyncAndBackPorch, VBackPorch;380 int HBlank;381 382 /* 8. Estimated Horizontal period */383 HPeriod = ((float)(1000000.0 / VFieldRate - CVT_MIN_VSYNC_BP))384 / (VDisplayRnd + 2 * VMargin + CVT_MIN_V_PORCH + Interlace);385 386 /* 9. Find number of lines in sync + backporch */387 if ((int)(CVT_MIN_VSYNC_BP / HPeriod) + 1 < VSync + CVT_MIN_V_PORCH)388 VSyncAndBackPorch = VSync + CVT_MIN_V_PORCH;389 else390 VSyncAndBackPorch = (int)(CVT_MIN_VSYNC_BP / HPeriod) + 1;391 392 /* 10. Find number of lines in back porch */393 VBackPorch = VSyncAndBackPorch - VSync;394 (void) VBackPorch;395 396 /* 11. Find total number of lines in vertical field */397 Mode.VTotal = VDisplayRnd + 2 * VMargin + VSyncAndBackPorch + Interlace + CVT_MIN_V_PORCH;398 399 /* 5) Definition of Horizontal blanking time limitation */400 /* Gradient (%/kHz) - default 600 */401 #define CVT_M_FACTOR 600402 403 /* Offset (%) - default 40 */404 #define CVT_C_FACTOR 40405 406 /* Blanking time scaling factor - default 128 */407 #define CVT_K_FACTOR 128408 409 /* Scaling factor weighting - default 20 */410 #define CVT_J_FACTOR 20411 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)414 415 /* 12. Find ideal blanking duty cycle from formula */416 HBlankPercentage = CVT_C_PRIME - CVT_M_PRIME * HPeriod / 1000.0;417 418 /* 13. Blanking time */419 if (HBlankPercentage < 20)420 HBlankPercentage = 20;421 422 HBlank = (int)(Mode.HDisplay * HBlankPercentage / (100.0 - HBlankPercentage));423 HBlank -= HBlank % (2 * CVT_H_GRANULARITY);424 425 /* 14. Find total number of pixels in a line. */426 Mode.HTotal = Mode.HDisplay + HBlank;427 428 /* Fill in HSync values */429 Mode.HSyncEnd = Mode.HDisplay + HBlank / 2;430 431 Mode.HSyncStart = Mode.HSyncEnd - (Mode.HTotal * CVT_HSYNC_PERCENTAGE) / 100;432 Mode.HSyncStart += CVT_H_GRANULARITY - Mode.HSyncStart % CVT_H_GRANULARITY;433 434 /* Fill in VSync values */435 Mode.VSyncStart = Mode.VDisplay + CVT_MIN_V_PORCH;436 Mode.VSyncEnd = Mode.VSyncStart + VSync;437 438 }439 else { /* Reduced blanking */440 /* Minimum vertical blanking interval time (µs) - default 460 */441 #define CVT_RB_MIN_VBLANK 460.0442 443 /* Fixed number of clocks for horizontal sync */444 #define CVT_RB_H_SYNC 32.0445 446 /* Fixed number of clocks for horizontal blanking */447 #define CVT_RB_H_BLANK 160.0448 449 /* Fixed number of lines for vertical front porch - default 3 */450 #define CVT_RB_VFPORCH 3451 452 int VBILines;453 454 /* 8. Estimate Horizontal period. */455 HPeriod = ((float)(1000000.0 / VFieldRate - CVT_RB_MIN_VBLANK)) / (VDisplayRnd + 2 * VMargin);456 457 /* 9. Find number of lines in vertical blanking */458 VBILines = (int)((float)CVT_RB_MIN_VBLANK / HPeriod + 1);459 460 /* 10. Check if vertical blanking is sufficient */461 if (VBILines < CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH)462 VBILines = CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH;463 464 /* 11. Find total number of lines in vertical field */465 Mode.VTotal = (int)(VDisplayRnd + 2 * VMargin + Interlace + VBILines);466 467 /* 12. Find total number of pixels in a line */468 Mode.HTotal = (int)(Mode.HDisplay + CVT_RB_H_BLANK);469 470 /* Fill in HSync values */471 Mode.HSyncEnd = (int)(Mode.HDisplay + CVT_RB_H_BLANK / 2);472 Mode.HSyncStart = (int)(Mode.HSyncEnd - CVT_RB_H_SYNC);473 474 /* Fill in VSync values */475 Mode.VSyncStart = Mode.VDisplay + CVT_RB_VFPORCH;476 Mode.VSyncEnd = Mode.VSyncStart + VSync;477 }478 /* 15/13. Find pixel clock frequency (kHz for xf86) */479 Mode.Clock = (int)(Mode.HTotal * 1000.0 / HPeriod);480 Mode.Clock -= Mode.Clock % CVT_CLOCK_STEP;481 482 /* 16/14. Find actual Horizontal Frequency (kHz) */483 Mode.HSync = (float)Mode.Clock / (float)Mode.HTotal;484 485 /* 17/15. Find actual Field rate */486 Mode.VRefresh = (1000.0 * (float)Mode.Clock) / (float)(Mode.HTotal * Mode.VTotal);487 488 /* 18/16. Find actual vertical frame frequency */489 /* ignore - just set the mode flag for interlaced */490 if (Interlaced)491 Mode.VTotal *= 2;492 return Mode;493 }494 263 495 264 #ifdef RT_OS_SOLARIS … … 1247 1016 pModeInfo->height = iYRes; 1248 1017 1249 DisplayModeR mode =f86CVTMode(iXRes, iYRes, 60 /*VRefresh */, true /*Reduced */, false /* Interlaced */);1018 DisplayModeR const mode = VBoxClient_xf86CVTMode(iXRes, iYRes, 60 /*VRefresh */, true /*Reduced */, false /* Interlaced */); 1250 1019 1251 1020 /* Convert kHz to Hz: f86CVTMode returns clock value in units of kHz, -
trunk/src/VBox/Additions/x11/VBoxClient/display-svga-xf86cvt.cpp
r97959 r97960 1 /* $Id$ */ 2 /** @file 3 * Guest Additions - Our version of xf86CVTMode. 4 */ 5 1 6 /* 7 * Copyright (C) 2006-2023 Oracle and/or its affiliates. 8 * This file is based on x.org server 1.18.0 file xf86cvt.c: 9 * 2 10 * Copyright 2005-2006 Luc Verhaegen. 3 11 * … … 21 29 */ 22 30 31 #if 0 23 32 /* 24 33 * The reason for having this function in a file of its own is … … 39 48 40 49 #include <string.h> 50 #else 51 # include "VBoxClient.h" 52 # include "display-svga-xf86cvt.h" 53 #endif 41 54 42 55 /* 56 * This is a slightly modified version of the xf86CVTMode function from 57 * xf86cvt.c from the xorg xserver source code. Computes several parameters 58 * of a display mode out of horizontal and vertical resolutions. Replicated 59 * here to avoid further dependencies. 60 * 61 *---------------------------------------------------------------------------- 62 * 43 63 * Generate a CVT standard mode from HDisplay, VDisplay and VRefresh. 44 64 * … … 64 84 * 65 85 */ 66 DisplayModePtr 67 xf86CVTMode(int HDisplay, int VDisplay, float VRefresh, Bool Reduced, 68 Bool Interlaced) 86 DisplayModeR VBoxClient_xf86CVTMode(int HDisplay, int VDisplay, float VRefresh /* Herz */, bool Reduced, bool Interlaced) 69 87 { 70 DisplayModeR ec *Mode = xnfcalloc(1, sizeof(DisplayModeRec));88 DisplayModeR Mode; 71 89 72 90 /* 1) top/bottom margin size (% of height) - default: 1.8 */ … … 85 103 #define CVT_CLOCK_STEP 250 86 104 87 Bool Margins = FALSE;105 bool Margins = false; 88 106 float VFieldRate, HPeriod; 89 107 int HDisplayRnd, HMargin; 90 108 int VDisplayRnd, VMargin, VSync; 91 109 float Interlace; /* Please rename this */ 92 char *tmp;93 110 94 111 /* CVT default is 60.0Hz */ … … 108 125 if (Margins) { 109 126 /* right margin is actually exactly the same as left */ 110 HMargin = ( ((float) HDisplayRnd)* CVT_MARGIN_PERCENTAGE / 100.0);127 HMargin = (int)((float)HDisplayRnd * CVT_MARGIN_PERCENTAGE / 100.0); 111 128 HMargin -= HMargin % CVT_H_GRANULARITY; 112 129 } … … 115 132 116 133 /* 4. Find total active pixels */ 117 Mode ->HDisplay = HDisplayRnd + 2 * HMargin;134 Mode.HDisplay = HDisplayRnd + 2 * HMargin; 118 135 119 136 /* 5. Find number of lines per field */ … … 127 144 if (Margins) 128 145 /* top and bottom margins are equal again. */ 129 VMargin = ( ((float) VDisplayRnd)* CVT_MARGIN_PERCENTAGE / 100.0);146 VMargin = (int)((float)VDisplayRnd * CVT_MARGIN_PERCENTAGE / 100.0); 130 147 else 131 148 VMargin = 0; 132 149 133 Mode ->VDisplay = VDisplay + 2 * VMargin;150 Mode.VDisplay = VDisplay + 2 * VMargin; 134 151 135 152 /* 7. Interlace */ … … 167 184 168 185 /* 8. Estimated Horizontal period */ 169 HPeriod = ((float) (1000000.0 / VFieldRate - CVT_MIN_VSYNC_BP)) /170 (VDisplayRnd + 2 * VMargin + CVT_MIN_V_PORCH + Interlace);186 HPeriod = ((float)(1000000.0 / VFieldRate - CVT_MIN_VSYNC_BP)) 187 / (VDisplayRnd + 2 * VMargin + CVT_MIN_V_PORCH + Interlace); 171 188 172 189 /* 9. Find number of lines in sync + backporch */ 173 if (((int) (CVT_MIN_VSYNC_BP / HPeriod) + 1) < 174 (VSync + CVT_MIN_V_PORCH)) 190 if ((int)(CVT_MIN_VSYNC_BP / HPeriod) + 1 < VSync + CVT_MIN_V_PORCH) 175 191 VSyncAndBackPorch = VSync + CVT_MIN_V_PORCH; 176 192 else 177 VSyncAndBackPorch = (int) 193 VSyncAndBackPorch = (int)(CVT_MIN_VSYNC_BP / HPeriod) + 1; 178 194 179 195 /* 10. Find number of lines in back porch */ … … 182 198 183 199 /* 11. Find total number of lines in vertical field */ 184 Mode->VTotal = VDisplayRnd + 2 * VMargin + VSyncAndBackPorch + Interlace 185 + CVT_MIN_V_PORCH; 200 Mode.VTotal = VDisplayRnd + 2 * VMargin + VSyncAndBackPorch + Interlace + CVT_MIN_V_PORCH; 186 201 187 202 /* 5) Definition of Horizontal blanking time limitation */ … … 198 213 #define CVT_J_FACTOR 20 199 214 200 #define CVT_M_PRIME CVT_M_FACTOR * CVT_K_FACTOR / 256 201 #define CVT_C_PRIME (CVT_C_FACTOR - CVT_J_FACTOR) * CVT_K_FACTOR / 256 + \ 202 CVT_J_FACTOR 215 #define CVT_M_PRIME (CVT_M_FACTOR * CVT_K_FACTOR / 256) 216 #define CVT_C_PRIME ((CVT_C_FACTOR - CVT_J_FACTOR) * CVT_K_FACTOR / 256 + CVT_J_FACTOR) 203 217 204 218 /* 12. Find ideal blanking duty cycle from formula */ … … 209 223 HBlankPercentage = 20; 210 224 211 HBlank = Mode->HDisplay * HBlankPercentage / (100.0 - HBlankPercentage);225 HBlank = (int)(Mode.HDisplay * HBlankPercentage / (100.0 - HBlankPercentage)); 212 226 HBlank -= HBlank % (2 * CVT_H_GRANULARITY); 213 227 214 228 /* 14. Find total number of pixels in a line. */ 215 Mode ->HTotal = Mode->HDisplay + HBlank;229 Mode.HTotal = Mode.HDisplay + HBlank; 216 230 217 231 /* Fill in HSync values */ 218 Mode->HSyncEnd = Mode->HDisplay + HBlank / 2; 219 220 Mode->HSyncStart = Mode->HSyncEnd - 221 (Mode->HTotal * CVT_HSYNC_PERCENTAGE) / 100; 222 Mode->HSyncStart += CVT_H_GRANULARITY - 223 Mode->HSyncStart % CVT_H_GRANULARITY; 232 Mode.HSyncEnd = Mode.HDisplay + HBlank / 2; 233 234 Mode.HSyncStart = Mode.HSyncEnd - (Mode.HTotal * CVT_HSYNC_PERCENTAGE) / 100; 235 Mode.HSyncStart += CVT_H_GRANULARITY - Mode.HSyncStart % CVT_H_GRANULARITY; 224 236 225 237 /* Fill in VSync values */ 226 Mode ->VSyncStart = Mode->VDisplay + CVT_MIN_V_PORCH;227 Mode ->VSyncEnd = Mode->VSyncStart + VSync;238 Mode.VSyncStart = Mode.VDisplay + CVT_MIN_V_PORCH; 239 Mode.VSyncEnd = Mode.VSyncStart + VSync; 228 240 229 241 } … … 244 256 245 257 /* 8. Estimate Horizontal period. */ 246 HPeriod = ((float) (1000000.0 / VFieldRate - CVT_RB_MIN_VBLANK)) / 247 (VDisplayRnd + 2 * VMargin); 258 HPeriod = ((float)(1000000.0 / VFieldRate - CVT_RB_MIN_VBLANK)) / (VDisplayRnd + 2 * VMargin); 248 259 249 260 /* 9. Find number of lines in vertical blanking */ 250 VBILines = ( (float) CVT_RB_MIN_VBLANK) / HPeriod + 1;261 VBILines = (int)((float)CVT_RB_MIN_VBLANK / HPeriod + 1); 251 262 252 263 /* 10. Check if vertical blanking is sufficient */ 253 if (VBILines < (CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH))264 if (VBILines < CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH) 254 265 VBILines = CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH; 255 266 256 267 /* 11. Find total number of lines in vertical field */ 257 Mode ->VTotal = VDisplayRnd + 2 * VMargin + Interlace + VBILines;268 Mode.VTotal = (int)(VDisplayRnd + 2 * VMargin + Interlace + VBILines); 258 269 259 270 /* 12. Find total number of pixels in a line */ 260 Mode ->HTotal = Mode->HDisplay + CVT_RB_H_BLANK;271 Mode.HTotal = (int)(Mode.HDisplay + CVT_RB_H_BLANK); 261 272 262 273 /* Fill in HSync values */ 263 Mode ->HSyncEnd = Mode->HDisplay + CVT_RB_H_BLANK / 2;264 Mode ->HSyncStart = Mode->HSyncEnd - CVT_RB_H_SYNC;274 Mode.HSyncEnd = (int)(Mode.HDisplay + CVT_RB_H_BLANK / 2); 275 Mode.HSyncStart = (int)(Mode.HSyncEnd - CVT_RB_H_SYNC); 265 276 266 277 /* Fill in VSync values */ 267 Mode ->VSyncStart = Mode->VDisplay + CVT_RB_VFPORCH;268 Mode ->VSyncEnd = Mode->VSyncStart + VSync;278 Mode.VSyncStart = Mode.VDisplay + CVT_RB_VFPORCH; 279 Mode.VSyncEnd = Mode.VSyncStart + VSync; 269 280 } 270 271 281 /* 15/13. Find pixel clock frequency (kHz for xf86) */ 272 Mode ->Clock = Mode->HTotal * 1000.0 / HPeriod;273 Mode ->Clock -= Mode->Clock % CVT_CLOCK_STEP;282 Mode.Clock = (int)(Mode.HTotal * 1000.0 / HPeriod); 283 Mode.Clock -= Mode.Clock % CVT_CLOCK_STEP; 274 284 275 285 /* 16/14. Find actual Horizontal Frequency (kHz) */ 276 Mode ->HSync = ((float) Mode->Clock) / ((float) Mode->HTotal);286 Mode.HSync = (float)Mode.Clock / (float)Mode.HTotal; 277 287 278 288 /* 17/15. Find actual Field rate */ 279 Mode->VRefresh = (1000.0 * ((float) Mode->Clock)) / 280 ((float) (Mode->HTotal * Mode->VTotal)); 289 Mode.VRefresh = (1000.0 * (float)Mode.Clock) / (float)(Mode.HTotal * Mode.VTotal); 281 290 282 291 /* 18/16. Find actual vertical frame frequency */ 283 292 /* ignore - just set the mode flag for interlaced */ 284 293 if (Interlaced) 285 Mode->VTotal *= 2; 286 294 Mode.VTotal *= 2; 295 296 #if 0 287 297 XNFasprintf(&tmp, "%dx%d", HDisplay, VDisplay); 288 298 Mode->name = tmp; … … 295 305 if (Interlaced) 296 306 Mode->Flags |= V_INTERLACE; 307 #endif 297 308 298 309 return Mode;
Note:
See TracChangeset
for help on using the changeset viewer.