Mercurial > mplayer.hg
comparison libvo/w32_common.c @ 29904:f529a2bb299d
Add support for Windows OpenGL rendering onto a device instead of into a window.
Has little use except for experimenting - on Windows 9x it could be used to
render on monitors that were not managed by Windows, but that feature was
removed in newer Windows versions.
author | reimar |
---|---|
date | Sat, 21 Nov 2009 22:27:40 +0000 |
parents | a2617c70b295 |
children | cd3f6962fcfd |
comparison
equal
deleted
inserted
replaced
29903:391e683541a7 | 29904:f529a2bb299d |
---|---|
49 static uint32_t o_dheight; | 49 static uint32_t o_dheight; |
50 | 50 |
51 static HINSTANCE hInstance; | 51 static HINSTANCE hInstance; |
52 #define vo_window vo_w32_window | 52 #define vo_window vo_w32_window |
53 HWND vo_window = 0; | 53 HWND vo_window = 0; |
54 /** HDC used when rendering to a device instead of window */ | |
55 static HDC dev_hdc; | |
54 static int event_flags; | 56 static int event_flags; |
55 static int mon_cnt; | 57 static int mon_cnt; |
56 | 58 |
57 static HMONITOR (WINAPI* myMonitorFromWindow)(HWND, DWORD); | 59 static HMONITOR (WINAPI* myMonitorFromWindow)(HWND, DWORD); |
58 static BOOL (WINAPI* myGetMonitorInfo)(HMONITOR, LPMONITORINFO); | 60 static BOOL (WINAPI* myGetMonitorInfo)(HMONITOR, LPMONITORINFO); |
326 } | 328 } |
327 | 329 |
328 static int createRenderingContext(void) { | 330 static int createRenderingContext(void) { |
329 HWND layer = HWND_NOTOPMOST; | 331 HWND layer = HWND_NOTOPMOST; |
330 PIXELFORMATDESCRIPTOR pfd; | 332 PIXELFORMATDESCRIPTOR pfd; |
331 HDC vo_hdc = GetDC(vo_window); | 333 HDC vo_hdc = vo_w32_get_dc(vo_window); |
332 RECT r; | 334 RECT r; |
333 int pf; | 335 int pf; |
334 if (WinID < 0) { | 336 if (WinID < 0) { |
335 int style = (vo_border && !vo_fs) ? | 337 int style = (vo_border && !vo_fs) ? |
336 (WS_OVERLAPPEDWINDOW | WS_SIZEBOX) : WS_POPUP; | 338 (WS_OVERLAPPEDWINDOW | WS_SIZEBOX) : WS_POPUP; |
393 | 395 |
394 SetPixelFormat(vo_hdc, pf, &pfd); | 396 SetPixelFormat(vo_hdc, pf, &pfd); |
395 | 397 |
396 mp_msg(MSGT_VO, MSGL_V, "vo: win32: running at %dx%d with depth %d\n", vo_screenwidth, vo_screenheight, vo_depthonscreen); | 398 mp_msg(MSGT_VO, MSGL_V, "vo: win32: running at %dx%d with depth %d\n", vo_screenwidth, vo_screenheight, vo_depthonscreen); |
397 | 399 |
398 ReleaseDC(vo_window, vo_hdc); | 400 vo_w32_release_dc(vo_window, vo_hdc); |
399 return 1; | 401 return 1; |
400 } | 402 } |
401 | 403 |
402 /** | 404 /** |
403 * \brief Configure and show window on the screen. | 405 * \brief Configure and show window on the screen. |
428 vo_vm = flags & VOFLAG_MODESWITCHING; | 430 vo_vm = flags & VOFLAG_MODESWITCHING; |
429 return createRenderingContext(); | 431 return createRenderingContext(); |
430 } | 432 } |
431 | 433 |
432 /** | 434 /** |
435 * \brief return the name of the selected device if it is indepedant | |
436 */ | |
437 static char *get_display_name(void) { | |
438 DISPLAY_DEVICE disp; | |
439 disp.cb = sizeof(disp); | |
440 EnumDisplayDevices(NULL, vo_adapter_num, &disp, 0); | |
441 if (disp.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) | |
442 return NULL; | |
443 return disp.DeviceName; | |
444 } | |
445 | |
446 /** | |
433 * \brief Initialize w32_common framework. | 447 * \brief Initialize w32_common framework. |
434 * | 448 * |
435 * The first function that should be called from the w32_common framework. | 449 * The first function that should be called from the w32_common framework. |
436 * It handles window creation on the screen with proper title and attributes. | 450 * It handles window creation on the screen with proper title and attributes. |
437 * It also initializes the framework's internal variables. The function should | 451 * It also initializes the framework's internal variables. The function should |
448 */ | 462 */ |
449 int vo_w32_init(void) { | 463 int vo_w32_init(void) { |
450 HICON mplayerIcon = 0; | 464 HICON mplayerIcon = 0; |
451 char exedir[MAX_PATH]; | 465 char exedir[MAX_PATH]; |
452 HINSTANCE user32; | 466 HINSTANCE user32; |
467 char *dev; | |
453 | 468 |
454 if (vo_window) | 469 if (vo_window) |
455 return 1; | 470 return 1; |
456 | 471 |
457 hInstance = GetModuleHandle(0); | 472 hInstance = GetModuleHandle(0); |
495 if (user32) { | 510 if (user32) { |
496 myMonitorFromWindow = (void *)GetProcAddress(user32, "MonitorFromWindow"); | 511 myMonitorFromWindow = (void *)GetProcAddress(user32, "MonitorFromWindow"); |
497 myGetMonitorInfo = GetProcAddress(user32, "GetMonitorInfoA"); | 512 myGetMonitorInfo = GetProcAddress(user32, "GetMonitorInfoA"); |
498 myEnumDisplayMonitors = GetProcAddress(user32, "EnumDisplayMonitors"); | 513 myEnumDisplayMonitors = GetProcAddress(user32, "EnumDisplayMonitors"); |
499 } | 514 } |
515 dev_hdc = 0; | |
516 dev = get_display_name(); | |
517 if (dev) dev_hdc = CreateDC(dev, NULL, NULL, NULL); | |
500 updateScreenProperties(); | 518 updateScreenProperties(); |
501 | 519 |
502 return 1; | 520 return 1; |
503 } | 521 } |
504 | 522 |
562 void vo_w32_uninit(void) { | 580 void vo_w32_uninit(void) { |
563 mp_msg(MSGT_VO, MSGL_V, "vo: win32: uninit\n"); | 581 mp_msg(MSGT_VO, MSGL_V, "vo: win32: uninit\n"); |
564 resetMode(); | 582 resetMode(); |
565 ShowCursor(1); | 583 ShowCursor(1); |
566 vo_depthonscreen = 0; | 584 vo_depthonscreen = 0; |
585 if (dev_hdc) DeleteDC(dev_hdc); | |
586 dev_hdc = 0; | |
567 DestroyWindow(vo_window); | 587 DestroyWindow(vo_window); |
568 vo_window = 0; | 588 vo_window = 0; |
569 UnregisterClass(classname, 0); | 589 UnregisterClass(classname, 0); |
570 } | 590 } |
591 | |
592 /** | |
593 * \brief get a device context to draw in | |
594 * | |
595 * \param wnd window the DC should belong to if it makes sense | |
596 */ | |
597 HDC vo_w32_get_dc(HWND wnd) { | |
598 if (dev_hdc) return dev_hdc; | |
599 return GetDC(wnd); | |
600 } | |
601 | |
602 /** | |
603 * \brief release a device context | |
604 * | |
605 * \param wnd window the DC probably belongs to | |
606 */ | |
607 void vo_w32_release_dc(HWND wnd, HDC dc) { | |
608 if (dev_hdc) return; | |
609 ReleaseDC(wnd, dc); | |
610 } |