예제 #1
0
/* MAKE_EXPORT GetMonitorInfoW_new=GetMonitorInfoW */
BOOL WINAPI GetMonitorInfoW_new(HMONITOR hMonitor, LPMONITORINFO lpmi)
{
	LPWSTR lpDevice = NULL;
	BOOL result;
	MONITORINFOEX miex;

	if(IsBadWritePtr(lpmi, sizeof(MONITORINFO)))
		return FALSE;

	if(lpmi->cbSize == sizeof(MONITORINFO))
		return GetMonitorInfoA(hMonitor, lpmi);

	if(lpmi->cbSize != sizeof(MONITORINFOEXW))
	{
		SetLastError(ERROR_INVALID_PARAMETER);
		return FALSE;
	}

	miex.cbSize = sizeof(MONITORINFOEXA);

	result = GetMonitorInfoA(hMonitor, &miex);

	if(!result)
		return FALSE;

	STACK_AtoW(miex.szDevice, lpDevice);

	//wcscpy(((LPMONITORINFOEXW)lpmi)->szDevice, lpDevice);

	return result;
}
예제 #2
0
파일: Display.cpp 프로젝트: Disar/Kore
		bool queryInformation(HMONITOR monitor) {
			MONITORINFOEXA info;
			memset(&info, 0, sizeof(MONITORINFOEXA));
			info.cbSize = sizeof(MONITORINFOEXA);

			if (GetMonitorInfoA(monitor, &info) == FALSE) {
				return false;
			}

			int freeSlot = 0;

			for (; freeSlot < MAXIMUM_DISPLAY_COUNT; ++freeSlot) {
				if (displays[freeSlot].id == monitor) {
					return false;
				}

				if (displays[freeSlot].id == NULL) {
					break;
				}
			}

			DeviceInfo& di = displays[freeSlot];

			strcpy_s(di.name, 32, info.szDevice);
			di.id = monitor;
			di.isAvailable = true;
			di.isPrimary = info.dwFlags == MONITORINFOF_PRIMARY;
			di.x = info.rcMonitor.left;
			di.y = info.rcMonitor.top;
			di.width = info.rcMonitor.right - info.rcMonitor.left;
			di.height = info.rcMonitor.bottom - info.rcMonitor.top;
			return true;
		}
예제 #3
0
static BOOL WINAPI DirectXOpenDDrawCallback(GUID *guid, LPTSTR desc,
                                            LPTSTR drivername, VOID *context,
                                            HMONITOR hmon)
{
    vout_display_t *vd = context;
    vout_display_sys_t *sys = vd->sys;

    /* This callback function is called by DirectDraw once for each
     * available DirectDraw device.
     *
     * Returning TRUE keeps enumerating.
     */
    if (!hmon)
        return TRUE;

    char *psz_drivername = FromT(drivername);
    char *psz_desc = FromT(desc);

    msg_Dbg(vd, "DirectXEnumCallback: %s, %s", psz_desc, psz_drivername);

    char *device = var_GetString(vd, "directx-device");

    /* Check for forced device */
    if (device && *device && !strcmp(psz_drivername, device)) {
        MONITORINFO monitor_info;
        monitor_info.cbSize = sizeof(MONITORINFO);

        if (GetMonitorInfoA(hmon, &monitor_info)) {
            RECT rect;

            /* Move window to the right screen */
            GetWindowRect(sys->hwnd, &rect);
            if (!IntersectRect(&rect, &rect, &monitor_info.rcWork)) {
                rect.left = monitor_info.rcWork.left;
                rect.top = monitor_info.rcWork.top;
                msg_Dbg(vd, "DirectXEnumCallback: setting window "
                            "position to %ld,%ld", rect.left, rect.top);
                SetWindowPos(sys->hwnd, NULL,
                             rect.left, rect.top, 0, 0,
                             SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
            }
        }
        sys->hmonitor = hmon;
    }
    free(device);

    if (hmon == sys->hmonitor) {
        msg_Dbg(vd, "selecting %s, %s", psz_desc, psz_drivername);

        free(sys->display_driver);
        sys->display_driver = malloc(sizeof(*guid));
        if (sys->display_driver)
            *sys->display_driver = *guid;
    }

    free(psz_drivername);
    free(psz_desc);
    return TRUE;
}
예제 #4
0
파일: Display.c 프로젝트: KTXSoftware/Kore
static BOOL CALLBACK EnumerationCallback(HMONITOR monitor, HDC hdc_unused, LPRECT rect_unused, LPARAM lparam) {
	MONITORINFOEXA info;
	memset(&info, 0, sizeof(MONITORINFOEXA));
	info.cbSize = sizeof(MONITORINFOEXA);
	
	if (GetMonitorInfoA(monitor, (MONITORINFO*)&info) == FALSE) {
		return FALSE;
	}

	int free_slot = 0;
	for (; free_slot < MAXIMUM_DISPLAYS; ++free_slot) {
		if (displays[free_slot].monitor == monitor) {
			return FALSE;
		}

		if (displays[free_slot].monitor == NULL) {
			break;
		}
	}

	DisplayData *display = &displays[free_slot];
	strcpy_s(display->name, 32, info.szDevice);
	display->index = free_slot;
	display->monitor = monitor;
	display->primary = (info.dwFlags & MONITORINFOF_PRIMARY) != 0;
	display->available = true;
	display->x = info.rcMonitor.left;
	display->y = info.rcMonitor.top;
	display->width = info.rcMonitor.right - info.rcMonitor.left;
	display->height = info.rcMonitor.bottom - info.rcMonitor.top;
		
	HDC hdc = CreateDCA(NULL, display->name, NULL, NULL);
	display->ppi = GetDeviceCaps(hdc, LOGPIXELSX);
	int scale = GetDeviceCaps(hdc, SCALINGFACTORX);
	DeleteDC(hdc);

	if (MyGetDpiForMonitor != NULL) {
		unsigned dpiX, dpiY;
		MyGetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
		display->ppi = (int)dpiX;
	}

	memset(&original_modes[free_slot], 0, sizeof(DEVMODEA));
	original_modes[free_slot].dmSize = sizeof(DEVMODEA);
	EnumDisplaySettingsA(display->name, ENUM_CURRENT_SETTINGS, &original_modes[free_slot]);
	display->frequency = original_modes[free_slot].dmDisplayFrequency;
	display->bpp = original_modes[free_slot].dmBitsPerPel;

	++screen_counter;
	return TRUE;
}
예제 #5
0
BOOL LSGetMonitorInfo(HMONITOR hMonitor, LPMONITORINFO lpmi)
{
    return GetMonitorInfoA(hMonitor, lpmi);
}
예제 #6
0
static int DirectXOpenDDraw(vout_display_t *vd)
{
    vout_display_sys_t *sys = vd->sys;
    HRESULT hr;

    /* */
    HRESULT (WINAPI *OurDirectDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
    OurDirectDrawCreate =
        (void *)GetProcAddress(sys->hddraw_dll, _T("DirectDrawCreate"));
    if (!OurDirectDrawCreate) {
        msg_Err(vd, "DirectXInitDDraw failed GetProcAddress");
        return VLC_EGENERIC;
    }

    /* */
    HRESULT (WINAPI *OurDirectDrawEnumerateEx)(LPDDENUMCALLBACKEXA, LPVOID, DWORD);
    OurDirectDrawEnumerateEx =
        (void *)GetProcAddress(sys->hddraw_dll, _T("DirectDrawEnumerateExA"));

    if (OurDirectDrawEnumerateEx) {
        char *device = var_GetString(vd, "directx-device");
        if (device) {
            msg_Dbg(vd, "directx-device: %s", device);
            free(device);
        }

        sys->hmonitor = MonitorFromWindow(sys->hwnd, MONITOR_DEFAULTTONEAREST);

        /* Enumerate displays */
        OurDirectDrawEnumerateEx(DirectXOpenDDrawCallback,
                                 vd, DDENUM_ATTACHEDSECONDARYDEVICES);
    }

    /* Initialize DirectDraw now */
    LPDIRECTDRAW ddobject;
    hr = OurDirectDrawCreate(sys->display_driver, &ddobject, NULL);
    if (hr != DD_OK) {
        msg_Err(vd, "DirectXInitDDraw cannot initialize DDraw");
        return VLC_EGENERIC;
    }

    /* Get the IDirectDraw2 interface */
    hr = IDirectDraw_QueryInterface(ddobject, &IID_IDirectDraw2,
                                    &sys->ddobject);
    /* Release the unused interface */
    IDirectDraw_Release(ddobject);

    if (hr != DD_OK) {
        msg_Err(vd, "cannot get IDirectDraw2 interface");
        sys->ddobject = NULL;
        return VLC_EGENERIC;
    }

    /* Set DirectDraw Cooperative level, ie what control we want over Windows
     * display */
    hr = IDirectDraw2_SetCooperativeLevel(sys->ddobject, NULL, DDSCL_NORMAL);
    if (hr != DD_OK) {
        msg_Err(vd, "cannot set direct draw cooperative level");
        return VLC_EGENERIC;
    }

    /* Get the size of the current display device */
    if (sys->hmonitor) {
        MONITORINFO monitor_info;
        monitor_info.cbSize = sizeof(MONITORINFO);
        GetMonitorInfoA(vd->sys->hmonitor, &monitor_info);
        sys->rect_display = monitor_info.rcMonitor;
    } else {
        sys->rect_display.left   = 0;
        sys->rect_display.top    = 0;
        sys->rect_display.right  = GetSystemMetrics(SM_CXSCREEN);
        sys->rect_display.bottom = GetSystemMetrics(SM_CYSCREEN);
    }

    msg_Dbg(vd, "screen dimensions (%lix%li,%lix%li)",
            sys->rect_display.left,
            sys->rect_display.top,
            sys->rect_display.right,
            sys->rect_display.bottom);

    /* Probe the capabilities of the hardware */
    DirectXGetDDrawCaps(vd);

    return VLC_SUCCESS;
}
예제 #7
0
static BOOL CALLBACK
enum_monitor (HMONITOR hmonitor,
	      HDC      hdc,
	      LPRECT   rect,
	      LPARAM   data)
{
  /* The struct MONITORINFOEX definition is for some reason different
   * in the winuser.h bundled with mingw64 from that in MSDN and the
   * official 32-bit mingw (the MONITORINFO part is in a separate "mi"
   * member). So to keep this easily compileable with either, repeat
   * the MSDN definition it here.
   */
  typedef struct tagMONITORINFOEXA2 {
    DWORD cbSize;
    RECT  rcMonitor;
    RECT  rcWork;
    DWORD dwFlags;
    CHAR szDevice[CCHDEVICENAME];
  } MONITORINFOEXA2;

  MONITORINFOEXA2 monitor_info;
  HDC hDC;

  gint *index = (gint *) data;
  GdkWin32Monitor *monitor;

  g_assert (*index < _gdk_num_monitors);

  monitor = _gdk_monitors + *index;

  monitor_info.cbSize = sizeof (MONITORINFOEX);
  GetMonitorInfoA (hmonitor, (MONITORINFO *) &monitor_info);

#ifndef MONITORINFOF_PRIMARY
#define MONITORINFOF_PRIMARY 1
#endif

  monitor->name = g_strdup (monitor_info.szDevice);
  hDC = CreateDCA ("DISPLAY", monitor_info.szDevice, NULL, NULL);
  monitor->width_mm = GetDeviceCaps (hDC, HORZSIZE);
  monitor->height_mm = GetDeviceCaps (hDC, VERTSIZE);
  DeleteDC (hDC);
  monitor->rect.x = monitor_info.rcMonitor.left;
  monitor->rect.y = monitor_info.rcMonitor.top;
  monitor->rect.width = monitor_info.rcMonitor.right - monitor_info.rcMonitor.left;
  monitor->rect.height = monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top;

  if (monitor_info.dwFlags & MONITORINFOF_PRIMARY &&
      *index != 0)
    {
      /* Put primary monitor at index 0, just in case somebody needs
       * to know which one is the primary.
       */
      GdkWin32Monitor temp = *monitor;
      *monitor = _gdk_monitors[0];
      _gdk_monitors[0] = temp;
    }

  (*index)++;

  return TRUE;
}
예제 #8
0
int DxVsyncSource::vsyncThread(void* context)
{
    DxVsyncSource* me = reinterpret_cast<DxVsyncSource*>(context);

    SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);

    D3DKMT_OPENADAPTERFROMHDC openAdapterParams = {};
    HMONITOR lastMonitor = nullptr;
    DEVMODEA monitorMode;
    monitorMode.dmSize = sizeof(monitorMode);

    while (SDL_AtomicGet(&me->m_Stopping) == 0) {
        D3DKMT_WAITFORVERTICALBLANKEVENT waitForVblankEventParams;
        NTSTATUS status;

        // If the monitor has changed from last time, open the new adapter
        HMONITOR currentMonitor = MonitorFromWindow(me->m_Window, MONITOR_DEFAULTTONEAREST);
        if (currentMonitor != lastMonitor) {
            MONITORINFOEXA monitorInfo = {};
            monitorInfo.cbSize = sizeof(monitorInfo);
            if (!GetMonitorInfoA(currentMonitor, &monitorInfo)) {
                SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
                             "GetMonitorInfo() failed: %d",
                             GetLastError());
                SDL_Delay(10);
                continue;
            }

            if (!EnumDisplaySettingsA(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &monitorMode)) {
                SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
                             "EnumDisplaySettings() failed: %d",
                             GetLastError());
                SDL_Delay(10);
                continue;
            }

            SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
                        "Monitor changed: %s %d Hz",
                        monitorInfo.szDevice,
                        monitorMode.dmDisplayFrequency);

            if (openAdapterParams.hAdapter != 0) {
                D3DKMT_CLOSEADAPTER closeAdapterParams = {};
                closeAdapterParams.hAdapter = openAdapterParams.hAdapter;
                me->m_D3DKMTCloseAdapter(&closeAdapterParams);
            }

            openAdapterParams.hDc = CreateDCA(nullptr, monitorInfo.szDevice, nullptr, nullptr);
            if (!openAdapterParams.hDc) {
                SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
                             "CreateDC() failed: %d",
                             GetLastError());
                SDL_Delay(10);
                continue;
            }

            status = me->m_D3DKMTOpenAdapterFromHdc(&openAdapterParams);
            DeleteDC(openAdapterParams.hDc);

            if (status != STATUS_SUCCESS) {
                SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
                             "D3DKMTOpenAdapterFromHdc() failed: %x",
                             status);
                SDL_Delay(10);
                continue;
            }

            lastMonitor = currentMonitor;
        }

        waitForVblankEventParams.hAdapter = openAdapterParams.hAdapter;
        waitForVblankEventParams.hDevice = 0;
        waitForVblankEventParams.VidPnSourceId = openAdapterParams.VidPnSourceId;

        status = me->m_D3DKMTWaitForVerticalBlankEvent(&waitForVblankEventParams);
        if (status != STATUS_SUCCESS) {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
                         "D3DKMTWaitForVerticalBlankEvent() failed: %x",
                         status);
            SDL_Delay(10);
            continue;
        }

        me->m_Pacer->vsyncCallback(1000 / me->m_DisplayFps);
    }

    if (openAdapterParams.hAdapter != 0) {
        D3DKMT_CLOSEADAPTER closeAdapterParams = {};
        closeAdapterParams.hAdapter = openAdapterParams.hAdapter;
        me->m_D3DKMTCloseAdapter(&closeAdapterParams);
    }

    return 0;
}