static int w32_init(struct MPGLContext *ctx, int flags) { if (!vo_w32_init(ctx->vo)) goto fail; struct w32_context *w32_ctx = ctx->priv; w32_ctx->flags = flags; vo_w32_run_on_thread(ctx->vo, create_ctx, ctx); if (!w32_ctx->context) goto fail; if (!ctx->gl->SwapInterval) MP_VERBOSE(ctx->vo, "WGL_EXT_swap_control missing.\n"); w32_ctx->real_wglSwapInterval = ctx->gl->SwapInterval; ctx->gl->SwapInterval = w32_swap_interval; w32_ctx->current_swapinterval = -1; current_w32_context = w32_ctx; wglMakeCurrent(w32_ctx->hdc, w32_ctx->context); DwmEnableMMCSS(TRUE); return 0; fail: w32_uninit(ctx); return -1; }
static void w32_uninit(MPGLContext *ctx) { struct w32_context *w32_ctx = ctx->priv; if (w32_ctx->context) wglMakeCurrent(w32_ctx->hdc, 0); vo_w32_run_on_thread(ctx->vo, destroy_gl, ctx); DwmEnableMMCSS(FALSE); vo_w32_uninit(ctx->vo); }
bool PlayerRenderer::init() { #ifdef Q_OS_WIN32 // Request Multimedia Class Schedule Service. DwmEnableMMCSS(TRUE); #endif // Signals presence of MPGetNativeDisplay(). const char *extensions = "GL_MP_MPGetNativeDisplay"; return mpv_opengl_cb_init_gl(m_mpvGL, extensions, get_proc_address, NULL) >= 0; }
void WWThreadCharacteristics::Unsetup(void) { HRESULT hr = S_OK; if (nullptr != m_mmcssHandle) { AvRevertMmThreadCharacteristics(m_mmcssHandle); m_mmcssHandle = nullptr; m_mmcssTaskIndex = 0; } if (WWMMCSSEnable == m_mmcssCallType) { hr = DwmEnableMMCSS(false); dprintf("D: %s() DwmEnableMMCSS(%d) 0x%08x\n", __FUNCTION__, false, hr); } }
void WWThreadCharacteristics::Setup(void) { HRESULT hr = S_OK; if (WWSTTNone != m_schedulerTaskType) { // マルチメディアクラススケジューラーサービスのスレッド特性設定。 dprintf("D: %s() AvSetMmThreadCharacteristics(%S)\n", __FUNCTION__, WWSchedulerTaskTypeToStr(m_schedulerTaskType)); m_mmcssHandle = AvSetMmThreadCharacteristics(WWSchedulerTaskTypeToStr(m_schedulerTaskType), &m_mmcssTaskIndex); if (nullptr == m_mmcssHandle) { dprintf("Failed to enable MMCSS on render thread: 0x%08x\n", GetLastError()); m_mmcssTaskIndex = 0; m_result.avSetMmThreadCharacteristicsResult = false; } else { m_result.avSetMmThreadCharacteristicsResult = true; } if (m_result.avSetMmThreadCharacteristicsResult && WWTPNone != m_threadPriority) { // スレッド優先度設定。 dprintf("D: %s() AvSetMmThreadPriority(%S)\n", __FUNCTION__, WWMMThreadPriorityTypeToStr(m_threadPriority)); assert(m_mmcssHandle != nullptr); m_result.avSetMmThreadPriorityResult = !!AvSetMmThreadPriority(m_mmcssHandle, WWMMThreadPriorityTypeToAvrtPriority(m_threadPriority)); } } if (WWMMCSSDoNotCall != m_mmcssCallType) { // MMCSSの有効、無効の設定。 hr = DwmEnableMMCSS(m_mmcssCallType==WWMMCSSEnable); dprintf("D: %s() DwmEnableMMCSS(%d) 0x%08x\n", __FUNCTION__, (int)(m_mmcssCallType==WWMMCSSEnable), hr); // 失敗することがあるが、続行する。 m_result.dwmEnableMMCSSResult = hr; } }
LONG WINAPI SetWindowLongA_Detour ( _In_ HWND hWnd, _In_ int nIndex, _In_ LONG dwNewLong ) { // Setup window message detouring as soon as a window is created.. if (pp::window.WndProc_Original == nullptr && nIndex == GWL_STYLE) { pp::window.hwnd = hWnd;//GetForegroundWindow_Original (); pp::RenderFix::hWndDevice = hWnd;//GetForegroundWindow_Original (); pp::window.WndProc_Original = (WNDPROC)GetWindowLongPtr (pp::RenderFix::hWndDevice, GWLP_WNDPROC); extern LRESULT CALLBACK DetourWindowProc ( _In_ HWND hWnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ); //SetWindowLongPtrW ( pp::RenderFix::hWndDevice, SetWindowLongA_Original ( pp::RenderFix::hWndDevice, GWLP_WNDPROC, (LONG_PTR)DetourWindowProc ); } if (nIndex == GWL_EXSTYLE || nIndex == GWL_STYLE) { dll_log.Log ( L"[Window Mgr] SetWindowLongA (0x%06X, %s, 0x%06X)", hWnd, nIndex == GWL_EXSTYLE ? L"GWL_EXSTYLE" : L" GWL_STYLE ", dwNewLong ); if (nIndex == GWL_STYLE && dwNewLong == 0xCF0000) windowed = true; else windowed = false; if (config.window.borderless) { if (nIndex == GWL_STYLE) dwNewLong = WS_POPUP | WS_MINIMIZEBOX; if (nIndex == GWL_EXSTYLE) dwNewLong = WS_EX_APPWINDOW; } SetWindowLongA_Original (hWnd, nIndex, dwNewLong); } #if 0 if (config.window.borderless && nIndex == GWL_STYLE && windowed) { HMONITOR hMonitor = MonitorFromWindow ( pp::RenderFix::hWndDevice, MONITOR_DEFAULTTONEAREST ); MONITORINFO mi = { 0 }; mi.cbSize = sizeof (mi); GetMonitorInfo (hMonitor, &mi); SetWindowPos_Original ( pp::RenderFix::hWndDevice, HWND_TOP, mi.rcMonitor.left, mi.rcMonitor.top, config.display.width <= 0 ? mi.rcMonitor.right - mi.rcMonitor.left : config.display.width, config.display.height <= 0 ? mi.rcMonitor.bottom - mi.rcMonitor.top : config.display.height, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOSENDCHANGING ); } ShowWindow (pp::RenderFix::hWndDevice, SW_SHOW); SetActiveWindow (pp::RenderFix::hWndDevice); BringWindowToTop (pp::RenderFix::hWndDevice); SetFocus (pp::RenderFix::hWndDevice); SetForegroundWindow (pp::RenderFix::hWndDevice); #endif DwmEnableMMCSS (TRUE); // TODO: Restore this functionality #if 0 // Override window styles if (nIndex == GWL_STYLE || nIndex == GWL_EXSTYLE) { // For proper return behavior DWORD dwOldStyle = GetWindowLong (hWnd, nIndex); // Allow the game to change its frame if (! config.window.borderless) return SetWindowLongA_Original (hWnd, nIndex, dwNewLong); return dwOldStyle; } #endif if (nIndex != GWL_STYLE && nIndex != GWL_EXSTYLE) return SetWindowLongA_Original (hWnd, nIndex, dwNewLong); return dwNewLong; }