void SettingsVideo::ApplySettings() { UINT adapterID = (UINT)SendMessage(GetDlgItem(hwnd, IDC_DEVICE), CB_GETCURSEL, 0, 0); if (adapterID == CB_ERR) adapterID = 0; GlobalConfig->SetInt(TEXT("Video"), TEXT("Adapter"), adapterID); int curSel = (int)SendMessage(GetDlgItem(hwnd, IDC_MONITOR), CB_GETCURSEL, 0, 0); if(curSel != CB_ERR) AppConfig->SetInt(TEXT("Video"), TEXT("Monitor"), curSel); int iVal = GetEditText(GetDlgItem(hwnd, IDC_SIZEX)).ToInt(); if(iVal >= 128) AppConfig->SetInt(TEXT("Video"), TEXT("BaseWidth"), iVal); iVal = GetEditText(GetDlgItem(hwnd, IDC_SIZEY)).ToInt(); if(iVal >= 128) AppConfig->SetInt(TEXT("Video"), TEXT("BaseHeight"), iVal); BOOL bDisableAero = SendMessage(GetDlgItem(hwnd, IDC_DISABLEAERO), BM_GETCHECK, 0, 0) == BST_CHECKED ? TRUE : FALSE; AppConfig->SetInt(TEXT("Video"), TEXT("DisableAero"), bDisableAero); BOOL bFailed; int fps = (int)SendMessage(GetDlgItem(hwnd, IDC_FPS), UDM_GETPOS32, 0, (LPARAM)&bFailed); AppConfig->SetInt(TEXT("Video"), TEXT("FPS"), (bFailed) ? 30 : fps); curSel = (int)SendMessage(GetDlgItem(hwnd, IDC_DOWNSCALE), CB_GETCURSEL, 0, 0); if(curSel != CB_ERR) AppConfig->SetFloat(TEXT("Video"), TEXT("Downscale"), downscaleMultipliers[curSel]); curSel = (int)SendMessage(GetDlgItem(hwnd, IDC_FILTER), CB_GETCURSEL, 0, 0); if(curSel == CB_ERR) curSel = 0; AppConfig->SetInt(TEXT("Video"), TEXT("Filter"), curSel); int gammaVal = (int)SendMessage(GetDlgItem(hwnd, IDC_GAMMA), TBM_GETPOS, 0, 0); AppConfig->SetInt(TEXT("Video"), TEXT("Gamma"), gammaVal); //------------------------------------ if(!App->bRunning) App->ResizeWindow(false); if(OSGetVersion() < 8) { if (bDisableAero) { Log(TEXT("Settings::Video: Disabling Aero")); DwmEnableComposition(DWM_EC_DISABLECOMPOSITION); } else { Log(TEXT("Settings::Video: Enabling Aero")); DwmEnableComposition(DWM_EC_ENABLECOMPOSITION); } } }
BOOL DisableAeroTheme() { HRESULT hr = S_OK; BOOL isDwmCompositiondEnabled = FALSE; hr = DwmIsCompositionEnabled(&isDwmCompositiondEnabled); if (SUCCEEDED(hr)) { //printf("isDwmCompositiondEnabled: %d\n", isDwmCompositiondEnabled); } else { printf("DwmIsCompositionEnabledFn is Failed (Or) DWM composition is not Enabled!, Error Code:%d\n", GetLastError()); } //if DWM composition is Enabled, Disable DWM composition. if (isDwmCompositiondEnabled) { //Disable Desktop Window Manager (DWM) composition. hr = DwmEnableComposition(FALSE); if (SUCCEEDED(hr)) { return TRUE; } else { printf("DwmEnableCompositionFn is Failed, Error Code:%d\n", GetLastError()); } } else { printf("DWM composition is not Enabled\n"); return FALSE; } }
static screenshot *take_screenshot_with_gdi(uint32_t x, uint32_t y, uint32_t width, uint32_t height) { HRESULT hr; int ir; BOOL r; // DWM causes screenshotting with GDI to be very slow. The only fix is to // disable DWM during the test. DWM will automatically be re-enabled when the // process exits. This API stops working on Windows 8 (though it returns // success regardless). if (!composition_disabled) { // HACK: DwmEnableComposition fails unless GetDC(NULL) has been called // first. Who knows why. HDC workaround = GetDC(NULL); int ir = ReleaseDC(NULL, workaround); assert(ir); hr = DwmEnableComposition(DWM_EC_DISABLECOMPOSITION); assert(hr == S_OK); // DWM takes a little while to repain the screen after being disabled. Sleep(1000); composition_disabled = true; } int virtual_x = ((int)x) - GetSystemMetrics(SM_XVIRTUALSCREEN); int virtual_y = ((int)y) - GetSystemMetrics(SM_YVIRTUALSCREEN); width = min(width, (uint32_t)GetSystemMetrics(SM_CXVIRTUALSCREEN)); height = min(height, (uint32_t)GetSystemMetrics(SM_CYVIRTUALSCREEN)); HDC screen_dc = GetDC(NULL); assert(screen_dc); HDC memory_dc = CreateCompatibleDC(screen_dc); assert(memory_dc); BITMAPINFO bitmap_info; memset(&bitmap_info, 0, sizeof(BITMAPINFO)); bitmap_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bitmap_info.bmiHeader.biWidth = width; bitmap_info.bmiHeader.biHeight = -(int)height; bitmap_info.bmiHeader.biPlanes = 1; bitmap_info.bmiHeader.biBitCount = 32; bitmap_info.bmiHeader.biCompression = BI_RGB; uint8_t *pixels = NULL; HBITMAP hbitmap = CreateDIBSection(screen_dc, &bitmap_info, DIB_RGB_COLORS, (void **)&pixels, NULL, 0); assert(hbitmap); SelectObject(memory_dc, hbitmap); r = BitBlt(memory_dc, 0, 0, width, height, screen_dc, virtual_x, virtual_y, SRCCOPY); assert(r); ir = ReleaseDC(NULL, screen_dc); assert(ir); r = DeleteObject(memory_dc); assert(r); screenshot *shot = (screenshot *)malloc(sizeof(screenshot)); shot->pixels = pixels; shot->width = width; shot->height = height; shot->stride = width * 4; shot->platform_specific_data = hbitmap; shot->time_nanoseconds = get_nanoseconds(); return shot; }
Drawable::Drawable(DirectDrawWriter &writer) : isOK(false), isOverlay(false), paused(false), writer(writer), flip(0), DDraw(NULL), DDClipper(NULL), DDSPrimary(NULL), DDSSecondary(NULL), DDSBackBuffer(NULL), DDrawColorCtrl(NULL), DwmEnableComposition(NULL) { setMouseTracking(true); grabGesture(Qt::PinchGesture); if (DirectDrawCreate(NULL, &DDraw, NULL) == DD_OK && DDraw->SetCooperativeLevel(NULL, DDSCL_NORMAL) == DD_OK) { DDSURFACEDESC ddsd_primary = { sizeof ddsd_primary }; ddsd_primary.dwFlags = DDSD_CAPS; ddsd_primary.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; if (DDraw->CreateSurface(&ddsd_primary, &DDSPrimary, NULL) == DD_OK) { LPDIRECTDRAWSURFACE DDrawTestSurface; DDSURFACEDESC ddsd_test = { sizeof ddsd_test }; ddsd_test.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd_test.dwWidth = 8; ddsd_test.dwHeight = 2; ddsd_test.ddpfPixelFormat.dwSize = sizeof ddsd_test.ddpfPixelFormat; ddsd_test.ddpfPixelFormat.dwFlags = DDPF_FOURCC; ddsd_test.ddpfPixelFormat.dwFourCC = MAKEFOURCC('Y', 'V', '1', '2'); /* Overlay YV12 test */ if (QSysInfo::windowsVersion() < QSysInfo::WV_6_2) //Windows 8 and 10 can't disable DWM, so overlay won't work { DDCAPS ddCaps = { sizeof ddCaps }; DDraw->GetCaps(&ddCaps, NULL); if (ddCaps.dwCaps & (DDCAPS_OVERLAY | DDCAPS_OVERLAYFOURCC | DDCAPS_OVERLAYSTRETCH)) { ddsd_test.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY; if (DDraw->CreateSurface(&ddsd_test, &DDrawTestSurface, NULL) == DD_OK) { RECT destRect = { 0, 0, 1, 1 }; HRESULT res = DDrawTestSurface->UpdateOverlay(NULL, DDSPrimary, &destRect, DDOVER_SHOW, NULL); if (res == DDERR_OUTOFCAPS && QSysInfo::windowsVersion() >= QSysInfo::WV_6_0) { /* Disable DWM to use overlay */ DwmEnableComposition = (DwmEnableCompositionProc)GetProcAddress(GetModuleHandleA("dwmapi.dll"), "DwmEnableComposition"); if (DwmEnableComposition) { if (DwmEnableComposition(DWM_EC_DISABLECOMPOSITION) == S_OK) res = DDrawTestSurface->UpdateOverlay(NULL, DDSPrimary, &destRect, DDOVER_SHOW, NULL); else DwmEnableComposition = NULL; } } if (res == DD_OK) { DDrawTestSurface->UpdateOverlay(NULL, DDSPrimary, NULL, DDOVER_HIDE, NULL); setAutoFillBackground(true); setPalette(QColor(ColorKEY)); connect(&QMPlay2Core, SIGNAL(videoDockMoved()), this, SLOT(updateOverlay())); connect(&QMPlay2Core, SIGNAL(videoDockVisible(bool)), this, SLOT(overlayVisible(bool))); connect(&QMPlay2Core, SIGNAL(mainWidgetNotMinimized(bool)), this, SLOT(overlayVisible(bool))); connect(&visibleTim, SIGNAL(timeout()), this, SLOT(doOverlayVisible())); visibleTim.setSingleShot(true); isOK = isOverlay = true; }