wgl: Don't set a pixel format on windows that already have one.

This commit is contained in:
Chris Robinson 2007-09-19 03:21:08 -07:00 committed by Alexandre Julliard
parent f8f07dfe54
commit 87e3cd66ab
2 changed files with 23 additions and 7 deletions

View File

@ -176,10 +176,12 @@ static void test_pbuffers(HDC hdc)
else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
}
static void test_setpixelformat(void)
static void test_setpixelformat(HDC winhdc)
{
int res = 0;
int nCfgs;
int pf;
int i;
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1, /* version */
@ -211,6 +213,17 @@ static void test_setpixelformat(void)
/* SetPixelFormat on the main device context 'X root window' should fail */
res = SetPixelFormat(hdc, pf, &pfd);
ok(res == 0, "SetPixelFormat on main device context should fail\n");
/* Setting the same format that was set on the HDC is allowed; other
formats fail */
nCfgs = DescribePixelFormat(winhdc, 0, 0, NULL);
pf = GetPixelFormat(winhdc);
for(i = 1;i <= nCfgs;i++)
{
int res = SetPixelFormat(winhdc, i, NULL);
if(i == pf) ok(res, "Failed to set the same pixel format\n");
else ok(!res, "Unexpectedly set an alternate pixel format\n");
}
}
static void test_colorbits(HDC hdc)
@ -366,7 +379,7 @@ START_TEST(opengl)
ok(res, "wglMakeCurrent failed!\n");
init_functions();
test_setpixelformat();
test_setpixelformat(hdc);
test_colorbits(hdc);
test_gdi_dbuf(hdc);

View File

@ -1369,35 +1369,38 @@ BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
if (!has_opengl()) {
ERR("No libGL on this box - disabling OpenGL support !\n");
return 0;
return FALSE;
}
/* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
if(get_glxdrawable(physDev) == root_window)
{
ERR("Invalid operation on root_window\n");
return 0;
return FALSE;
}
/* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
if(!fmt) {
ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
return 0;
return FALSE;
}
if(physDev->current_pf) /* cannot change it if already set */
return (physDev->current_pf == iPixelFormat);
pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
hwnd = WindowFromDC(physDev->hdc);
if(hwnd) {
if(!(value&GLX_WINDOW_BIT)) {
WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
return 0;
return FALSE;
}
if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, (WPARAM)fmt->fmt_id, 0)) {
ERR("Couldn't set format of the window, returning failure\n");
return 0;
return FALSE;
}
}