| 91 | // initializes the objects needed to use GDI |
| 92 | |
| 93 | bool ddgr_gdi_Init(oeApplication *app, bool fullscreen, bool ddraw) { |
| 94 | HRESULT hres; |
| 95 | |
| 96 | GDI_DATA(fullscreen) = fullscreen; |
| 97 | GDI_DATA(hPrimaryWnd) = (HWND)((oeWin32Application *)app)->m_hWnd; |
| 98 | |
| 99 | GDI_DATA(lpDD) = NULL; |
| 100 | if (ddraw) { |
| 101 | hres = DirectDrawCreate(NULL, &GDI_DATA(lpDD), NULL); |
| 102 | if (hres != DD_OK) { |
| 103 | ddgr_PushError("Failure to initialize DirectDraw driver (%d)", LOWORD(hres)); |
| 104 | return false; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // Initialize DirectDraw exclusive system if we're going fullscreen, and GDIX system |
| 109 | if (GDI_DATA(fullscreen)) { |
| 110 | if (ddraw) { |
| 111 | hres = GDI_DATA(lpDD)->SetCooperativeLevel(GDI_DATA(hPrimaryWnd), |
| 112 | DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); |
| 113 | |
| 114 | if (hres != DD_OK) { |
| 115 | ddgr_PushError("Failed to set DirectDraw fullscreen access level (%d)", LOWORD(hres)); |
| 116 | return false; |
| 117 | } |
| 118 | } else { |
| 119 | // grab all device modes for the current display device. |
| 120 | unsigned i; |
| 121 | for (i = 0; i < GDI_MAX_DEVMODES; i++) { |
| 122 | if (EnumDisplaySettings(NULL, i, &GDI_DATA(devmodes[i])) == FALSE) { |
| 123 | break; |
| 124 | } |
| 125 | HDC hdc = GetDC(GDI_DATA(hPrimaryWnd)); |
| 126 | |
| 127 | if (GDI_DATA(devmodes[i].dmBitsPerPel) == (uint32_t)GetDeviceCaps(hdc, BITSPIXEL) && |
| 128 | GDI_DATA(devmodes[i].dmPelsWidth) == (uint32_t)GetDeviceCaps(hdc, HORZRES) && |
| 129 | GDI_DATA(devmodes[i].dmPelsHeight) == (uint32_t)GetDeviceCaps(hdc, VERTRES)) |
| 130 | GDI_DATA(olddispmode) = i; |
| 131 | |
| 132 | ReleaseDC(GDI_DATA(hPrimaryWnd), hdc); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | GDI_DATA(ddraw) = ddraw; |
| 137 | } else { |
| 138 | if (ddraw) { |
| 139 | hres = GDI_DATA(lpDD)->SetCooperativeLevel(GDI_DATA(hPrimaryWnd), DDSCL_NORMAL); |
| 140 | if (hres != DD_OK) { |
| 141 | ddgr_PushError("Failed to set DirectDraw normal access level (%d)", LOWORD(hres)); |
| 142 | return false; |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | GDI_DATA(hOffscreenDC) = NULL; |
| 148 | GDI_DATA(vidrefs) = 0; // reset video reference count. |
| 149 | GDI_DATA(init) = true; |
| 150 |
no test coverage detected