MCPcopy Create free account
hub / github.com/beefytech/Beef / VSyncThreadProc

Method VSyncThreadProc

BeefySysLib/platform/win/WinBFApp.cpp:1324–1388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1322}
1323
1324void WinBFApp::VSyncThreadProc()
1325{
1326 DWORD lastBlankFinish = GetTickCount();
1327
1328 Array<int> waitTimes;
1329
1330 while (!mClosing)
1331 {
1332 bool didWait = false;
1333
1334 IDXGIOutput* output = NULL;
1335
1336 //
1337 {
1338 AutoCrit autoCrit(mCritSect);
1339 if ((mRenderDevice != NULL) && (!mRenderDevice->mRenderWindowList.IsEmpty()))
1340 {
1341 auto renderWindow = (DXRenderWindow*)mRenderDevice->mRenderWindowList[0];
1342 renderWindow->mDXSwapChain->GetContainingOutput(&output);
1343 }
1344 }
1345
1346 if (output != NULL)
1347 {
1348 DWORD startTick = GetTickCount();
1349 bool success = output->WaitForVBlank() == 0;
1350 DWORD endTick = GetTickCount();
1351
1352 if (success)
1353 {
1354 int elapsed = (int)(endTick - startTick);
1355 waitTimes.Add(elapsed);
1356 if (waitTimes.mSize > 8)
1357 waitTimes.RemoveAt(0);
1358
1359 if (elapsed <= 1)
1360 {
1361 bool hadNonZero = false;
1362 for (auto waitTime : waitTimes)
1363 {
1364 if (waitTime > 1)
1365 hadNonZero = true;
1366 }
1367 if (!hadNonZero)
1368 success = false;
1369 }
1370 }
1371
1372 if (success)
1373 {
1374 didWait = true;
1375 mVSyncActive = true;
1376 mVSyncEvent.Set();
1377 }
1378
1379 output->Release();
1380 }
1381

Callers 1

VSyncThreadProcThunkMethod · 0.80

Calls 7

BfpThread_SleepFunction · 0.70
IsEmptyMethod · 0.45
WaitForVBlankMethod · 0.45
AddMethod · 0.45
RemoveAtMethod · 0.45
SetMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected