Subversion Repositories eduke32

Rev

Rev 8631 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8631 Rev 8717
Line 27... Line 27...
27
static int win_silentfocuschange;
27
static int win_silentfocuschange;
28
28
29
static HANDLE  g_singleInstanceSemaphore = nullptr;
29
static HANDLE  g_singleInstanceSemaphore = nullptr;
30
static int32_t win_togglecomposition;
30
static int32_t win_togglecomposition;
31
static int32_t win_systemtimermode;
31
static int32_t win_systemtimermode;
-
 
32
static int32_t win_performancemode;
32
33
33
static OSVERSIONINFOEX osv;
34
static OSVERSIONINFOEX osv;
34
static FARPROC ntdll_wine_get_version;
35
static FARPROC ntdll_wine_get_version;
35
static char const *enUSLayoutString = "00000409";
36
static char const *enUSLayoutString = "00000409";
36
37
37
DWM_TIMING_INFO timingInfo;
38
DWM_TIMING_INFO timingInfo;
38
39
-
 
40
static HMODULE hPOWRPROF;
-
 
41
static GUID *systemPowerSchemeGUID;
-
 
42
-
 
43
typedef DWORD(WINAPI *PFNPOWERGETACTIVESCHEME)(HKEY, GUID **);
-
 
44
typedef DWORD(WINAPI *PFNPOWERSETACTIVESCHEME)(HKEY, CONST GUID *);
-
 
45
-
 
46
static PFNPOWERGETACTIVESCHEME powrprof_PowerGetActiveScheme;
-
 
47
static PFNPOWERSETACTIVESCHEME powrprof_PowerSetActiveScheme;
-
 
48
39
void windowsSetupTimer(int ntDllVoodoo)
49
void windowsSetupTimer(int ntDllVoodoo)
40
{
50
{
-
 
51
    if (ntdll_wine_get_version)
-
 
52
        return;
-
 
53
41
    typedef HRESULT(NTAPI* PFNSETTIMERRESOLUTION)(ULONG, BOOLEAN, PULONG);
54
    typedef HRESULT(NTAPI* PFNSETTIMERRESOLUTION)(ULONG, BOOLEAN, PULONG);
42
    typedef HRESULT(NTAPI* PFNQUERYTIMERRESOLUTION)(PULONG, PULONG, PULONG);
55
    typedef HRESULT(NTAPI* PFNQUERYTIMERRESOLUTION)(PULONG, PULONG, PULONG);
43
56
44
    TIMECAPS timeCaps;
57
    TIMECAPS timeCaps;
45
58
46
    if (ntdll_wine_get_version)
-
 
47
        return;
-
 
48
-
 
49
    if (timeGetDevCaps(&timeCaps, sizeof(TIMECAPS)) == MMSYSERR_NOERROR)
59
    if (timeGetDevCaps(&timeCaps, sizeof(TIMECAPS)) == MMSYSERR_NOERROR)
50
    {
60
    {
51
#if defined RENDERTYPESDL && SDL_MAJOR_VERSION >= 2
61
#if defined RENDERTYPESDL && SDL_MAJOR_VERSION >= 2
52
        int const onBattery = (SDL_GetPowerInfo(NULL, NULL) == SDL_POWERSTATE_ON_BATTERY);
62
        int const onBattery = (SDL_GetPowerInfo(NULL, NULL) == SDL_POWERSTATE_ON_BATTERY);
53
#else
63
#else
Line 296... Line 306...
296
          "Windows process priority class:\n"
306
          "Windows process priority class:\n"
297
          "  -1: do not alter process priority\n"
307
          "  -1: do not alter process priority\n"
298
          "   0: HIGH when game has focus, NORMAL when interacting with other programs\n"
308
          "   0: HIGH when game has focus, NORMAL when interacting with other programs\n"
299
          "   1: NORMAL when game has focus, IDLE when interacting with other programs",
309
          "   1: NORMAL when game has focus, IDLE when interacting with other programs",
300
          (void *)&win_priorityclass, CVAR_INT, -1, 1 },
310
          (void *)&win_priorityclass, CVAR_INT, -1, 1 },
-
 
311
-
 
312
        { "win_performancemode",
-
 
313
          "Windows performance mode:\n"
-
 
314
          "   0: do not alter performance mode\n"
-
 
315
          "   1: use HIGH PERFORMANCE power plan when game has focus",
-
 
316
          (void *)&win_performancemode, CVAR_BOOL, 0, 1 },
-
 
317
301
    };
318
    };
302
319
303
    static osdcvardata_t win_timer_cvar = { "win_systemtimermode",
320
    static osdcvardata_t win_timer_cvar = { "win_systemtimermode",
304
                                            "Windows timer interrupt resolution:\n"
321
                                            "Windows timer interrupt resolution:\n"
305
                                            "   0: 1.0ms\n"
322
                                            "   0: 1.0ms\n"
Line 316... Line 333...
316
    for (int i=0; i<ARRAY_SSIZE(cvars_win); i++)
333
    for (int i=0; i<ARRAY_SSIZE(cvars_win); i++)
317
        OSD_RegisterCvar(&cvars_win[i], osdcmd_cvar_set);
334
        OSD_RegisterCvar(&cvars_win[i], osdcmd_cvar_set);
318
335
319
    windowsPrintVersion();
336
    windowsPrintVersion();
320
    windowsSetupTimer(0);
337
    windowsSetupTimer(0);
-
 
338
-
 
339
    if (osv.dwMajorVersion >= 6)
-
 
340
    {
-
 
341
        if (!hPOWRPROF && (hPOWRPROF = GetModuleHandle("powrprof.dll")))
-
 
342
        {
-
 
343
            powrprof_PowerGetActiveScheme = (PFNPOWERGETACTIVESCHEME)(void(*))GetProcAddress(hPOWRPROF, "PowerGetActiveScheme");
-
 
344
            powrprof_PowerSetActiveScheme = (PFNPOWERSETACTIVESCHEME)(void(*))GetProcAddress(hPOWRPROF, "PowerSetActiveScheme");
-
 
345
-
 
346
            if (powrprof_PowerGetActiveScheme == nullptr || powrprof_PowerSetActiveScheme == nullptr)
-
 
347
                OSD_Printf("ERROR: unable to locate PowerGetActiveScheme or PowerSetActiveScheme symbols in powrprof.dll!\n");
-
 
348
            else if (!systemPowerSchemeGUID)
-
 
349
                powrprof_PowerGetActiveScheme(NULL, &systemPowerSchemeGUID);
-
 
350
        }
-
 
351
    }
321
}
352
}
322
353
323
typedef UINT D3DKMT_HANDLE;
354
typedef UINT D3DKMT_HANDLE;
324
typedef UINT D3DDDI_VIDEO_PRESENT_SOURCE_ID;
355
typedef UINT D3DDDI_VIDEO_PRESENT_SOURCE_ID;
325
356
Line 474... Line 505...
474
{
505
{
475
    if (g_singleInstanceSemaphore)
506
    if (g_singleInstanceSemaphore)
476
        CloseHandle(g_singleInstanceSemaphore);
507
        CloseHandle(g_singleInstanceSemaphore);
477
508
478
    windowsSetKeyboardLayout(windowsGetSystemKeyboardLayoutName());
509
    windowsSetKeyboardLayout(windowsGetSystemKeyboardLayoutName());
-
 
510
-
 
511
    if (systemPowerSchemeGUID)
-
 
512
    {
-
 
513
        powrprof_PowerSetActiveScheme(NULL, systemPowerSchemeGUID);
-
 
514
        LocalFree(systemPowerSchemeGUID);
-
 
515
    }
479
}
516
}
480
517
481
518
482
//
519
//
483
// GetWindowsErrorMsg() -- gives a pointer to a static buffer containing the Windows error message
520
// GetWindowsErrorMsg() -- gives a pointer to a static buffer containing the Windows error message
Line 589... Line 626...
589
        if (win_priorityclass != -1)
626
        if (win_priorityclass != -1)
590
            SetPriorityClass(GetCurrentProcess(), win_priorityclass ? BELOW_NORMAL_PRIORITY_CLASS : HIGH_PRIORITY_CLASS);
627
            SetPriorityClass(GetCurrentProcess(), win_priorityclass ? BELOW_NORMAL_PRIORITY_CLASS : HIGH_PRIORITY_CLASS);
591
628
592
        windowsSetupTimer(win_systemtimermode);
629
        windowsSetupTimer(win_systemtimermode);
593
        windowsSetKeyboardLayout(enUSLayoutString, true);
630
        windowsSetKeyboardLayout(enUSLayoutString, true);
-
 
631
-
 
632
        if (win_performancemode && systemPowerSchemeGUID)
-
 
633
            powrprof_PowerSetActiveScheme(NULL, &GUID_MIN_POWER_SAVINGS);
594
    }
634
    }
595
    else
635
    else
596
    {
636
    {
597
        if (win_priorityclass != -1)
637
        if (win_priorityclass != -1)
598
            SetPriorityClass(GetCurrentProcess(), win_priorityclass ? IDLE_PRIORITY_CLASS : ABOVE_NORMAL_PRIORITY_CLASS);
638
            SetPriorityClass(GetCurrentProcess(), win_priorityclass ? IDLE_PRIORITY_CLASS : ABOVE_NORMAL_PRIORITY_CLASS);
599
639
600
        windowsSetupTimer(0);
640
        windowsSetupTimer(0);
601
        windowsSetKeyboardLayout(windowsGetSystemKeyboardLayoutName(), true);
641
        windowsSetKeyboardLayout(windowsGetSystemKeyboardLayoutName(), true);
-
 
642
-
 
643
        if (systemPowerSchemeGUID)
-
 
644
            powrprof_PowerSetActiveScheme(NULL, systemPowerSchemeGUID);
602
    }
645
    }
603
646
604
    win_silentfocuschange = false;
647
    win_silentfocuschange = false;
605
}
648
}
606
649