1
0

vidutils.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include "main.h"
  2. #include "api.h"
  3. #include <multimon.h>
  4. #undef GetSystemMetrics
  5. void getViewport(RECT *r, HWND wnd, int full, RECT *sr)
  6. {
  7. POINT *p = NULL;
  8. if (p || sr || wnd)
  9. {
  10. static int initted = 0;
  11. static HMONITOR (WINAPI *Mfp)(POINT pt, DWORD dwFlags);
  12. static HMONITOR (WINAPI *Mfr)(LPCRECT lpcr, DWORD dwFlags);
  13. static HMONITOR (WINAPI *Mfw)(HWND wnd, DWORD dwFlags);
  14. static BOOL (WINAPI *Gmi)(HMONITOR mon, LPMONITORINFOEX lpmi);
  15. if (!initted)
  16. {
  17. HINSTANCE h = LoadLibraryW(L"user32.dll");
  18. if (h)
  19. {
  20. Mfp = (HMONITOR (WINAPI *)(POINT, DWORD)) GetProcAddress(h, "MonitorFromPoint");
  21. Mfr = (HMONITOR (WINAPI *)(LPCRECT, DWORD)) GetProcAddress(h, "MonitorFromRect");
  22. Mfw = (HMONITOR (WINAPI *)(HWND, DWORD)) GetProcAddress(h, "MonitorFromWindow");
  23. Gmi = (BOOL (WINAPI *)(HMONITOR, LPMONITORINFOEX)) GetProcAddress(h, "GetMonitorInfoW");
  24. }
  25. initted = 1;
  26. }
  27. if (Mfp && Mfr && Mfw && Gmi)
  28. {
  29. HMONITOR hm = NULL;
  30. if (sr)
  31. hm = Mfr(sr, MONITOR_DEFAULTTONEAREST);
  32. else if (wnd)
  33. hm = Mfw(wnd, MONITOR_DEFAULTTONEAREST);
  34. else if (p)
  35. hm = Mfp(*p, MONITOR_DEFAULTTONEAREST);
  36. if (hm)
  37. {
  38. MONITORINFOEXW mi;
  39. memset(&mi, 0, sizeof(mi));
  40. mi.cbSize = sizeof(mi);
  41. if (Gmi(hm, &mi))
  42. {
  43. if (!full)
  44. *r = mi.rcWork;
  45. else
  46. *r = mi.rcMonitor;
  47. return ;
  48. }
  49. }
  50. }
  51. }
  52. if (full)
  53. { // this might be borked =)
  54. r->top = r->left = 0;
  55. r->right = GetSystemMetrics(SM_CXSCREEN);
  56. r->bottom = GetSystemMetrics(SM_CYSCREEN);
  57. }
  58. else
  59. {
  60. SystemParametersInfoW(SPI_GETWORKAREA, 0, r, 0);
  61. }
  62. }
  63. VideoConfig::VideoConfig() : group(0),
  64. itemYV12(0), itemOverlay(0), itemVsync(0), itemDDraw(0)
  65. {}
  66. bool VideoConfig::yv12()
  67. {
  68. GetGroup();
  69. if (!itemYV12)
  70. return false;
  71. return itemYV12->GetBool();
  72. }
  73. bool VideoConfig::overlays()
  74. {
  75. GetGroup();
  76. if (!itemOverlay)
  77. return true; // overlay by default
  78. return itemOverlay->GetBool();
  79. }
  80. bool VideoConfig::vsync()
  81. {
  82. GetGroup();
  83. if (!itemVsync)
  84. return false; // no vsync by default
  85. return itemVsync->GetBool();
  86. }
  87. bool VideoConfig::ddraw()
  88. {
  89. GetGroup();
  90. if (!itemDDraw)
  91. return true;
  92. return itemDDraw->GetBool();
  93. }
  94. void VideoConfig::GetGroup()
  95. {
  96. if (group)
  97. return ;
  98. // {2135E318-6919-4bcf-99D2-62BE3FCA8FA6}
  99. static const GUID videoConfigGroupGUID =
  100. { 0x2135e318, 0x6919, 0x4bcf, { 0x99, 0xd2, 0x62, 0xbe, 0x3f, 0xca, 0x8f, 0xa6 } };
  101. group = AGAVE_API_CONFIG->GetGroup(videoConfigGroupGUID);
  102. if (group)
  103. {
  104. itemYV12 = group->GetItem(L"YV12");
  105. itemOverlay = group->GetItem(L"overlay");
  106. itemVsync = group->GetItem(L"vsync");
  107. itemDDraw = group->GetItem(L"ddraw");
  108. }
  109. }
  110. VideoConfig config_video;