2 * VIDIX-accelerated overlay in a Win32 window
4 * copyright (C) 2003 Sascha Sommer
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include "video_out.h"
31 #include "video_out_internal.h"
34 #include "osdep/keycodes.h"
35 #include "input/input.h"
41 #include "vosub_vidix.h"
42 #include "vidix/vidix.h"
45 static const vo_info_t info
=
53 LIBVO_EXTERN(winvidix
)
55 #define UNUSED(x) ((void)(x)) /* Removes warning about unused arguments */
58 static char *vidix_name
;
60 static int depthonscreen
;
61 /* Image parameters */
62 static uint32_t image_width
;
63 static uint32_t image_height
;
64 static uint32_t image_format
;
65 /* Window parameters */
66 static HWND hWnd
=NULL
,hWndFS
=NULL
;
67 static float window_aspect
;
69 static vidix_grkey_t gr_key
;
72 void set_video_eq(int cap
);
75 static LRESULT CALLBACK
WndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
82 mplayer_put_key(KEY_CLOSE_WIN
);
84 case WM_WINDOWPOSCHANGED
:
87 /*calculate new window rect*/
95 ClientToScreen(hWnd
,&point_window
);
96 GetClientRect(hWnd
,&rd
);
98 vo_dwidth
=rd
.right
- rd
.left
;
99 vo_dheight
=rd
.bottom
- rd
.top
;
100 vo_dx
=point_window
.x
;
101 vo_dy
=point_window
.y
;
102 // aspect(&vo_dwidth, &vo_dheight, A_NOZOOM);
104 /* keep aspect on resize, borrowed from vo_directx.c */
105 tmpheight
= ((float)vo_dwidth
/window_aspect
);
106 tmpheight
+= tmpheight
% 2;
107 if(tmpheight
> vo_dheight
)
109 vo_dwidth
= ((float)vo_dheight
*window_aspect
);
110 vo_dwidth
+= vo_dwidth
% 2;
112 else vo_dheight
= tmpheight
;
113 rd
.right
= rd
.left
+ vo_dwidth
;
114 rd
.bottom
= rd
.top
+ vo_dheight
;
116 if(rd
.left
< 0) rd
.left
= 0;
117 if(rd
.right
> vo_screenwidth
) rd
.right
= vo_screenwidth
;
118 if(rd
.top
< 0) rd
.top
= 0;
119 if(rd
.bottom
> vo_screenheight
) rd
.bottom
= vo_screenheight
;
121 AdjustWindowRect(&rd
, WS_OVERLAPPEDWINDOW
| WS_SIZEBOX
, 0);
122 SetWindowPos(hWnd
, HWND_TOPMOST
, vo_dx
+rd
.left
, vo_dy
+rd
.top
, rd
.right
-rd
.left
, rd
.bottom
-rd
.top
, SWP_NOOWNERZORDER
);
125 if(ShowCursor(FALSE
)>=0)while(ShowCursor(FALSE
)>=0){}
126 aspect(&vo_dwidth
, &vo_dheight
, A_ZOOM
);
127 vo_dx
= (vo_screenwidth
- vo_dwidth
)/2;
128 vo_dy
= (vo_screenheight
- vo_dheight
)/2;
131 /* FIXME: implement runtime resize/move if possible, this way is very ugly! */
133 if(vidix_init(image_width
, image_height
, vo_dx
, vo_dy
, vo_dwidth
, vo_dheight
, image_format
, depthonscreen
, vo_screenwidth
, vo_screenheight
) != 0)
134 mp_msg(MSGT_VO
, MSGL_FATAL
, "Can't initialize VIDIX driver: %s\n", strerror(errno
));
137 mp_msg(MSGT_VO
, MSGL_V
, "[winvidix] window properties: pos: %dx%d, size: %dx%d\n",vo_dx
, vo_dy
, vo_dwidth
, vo_dheight
);
138 if(vidix_grkey_support()){
139 vidix_grkey_get(&gr_key
);
140 gr_key
.key_op
= KEYS_PUT
;
141 gr_key
.ckey
.op
= CKEY_TRUE
;
142 if(vo_fs
)gr_key
.ckey
.red
= gr_key
.ckey
.green
= gr_key
.ckey
.blue
= 0;
144 gr_key
.ckey
.red
= gr_key
.ckey
.blue
= 255;
145 gr_key
.ckey
.green
= 0;
147 vidix_grkey_set(&gr_key
);
155 case SC_MONITORPOWER
:
162 {mplayer_put_key(KEY_LEFT
);break;}
164 {mplayer_put_key(KEY_UP
);break;}
166 {mplayer_put_key(KEY_RIGHT
);break;}
168 {mplayer_put_key(KEY_DOWN
);break;}
170 {mplayer_put_key(KEY_TAB
);break;}
172 {mplayer_put_key(KEY_CTRL
);break;}
174 {mplayer_put_key(KEY_DELETE
);break;}
176 {mplayer_put_key(KEY_INSERT
);break;}
178 {mplayer_put_key(KEY_HOME
);break;}
180 {mplayer_put_key(KEY_END
);break;}
182 {mplayer_put_key(KEY_PAGE_UP
);break;}
184 {mplayer_put_key(KEY_PAGE_DOWN
);break;}
186 {mplayer_put_key(KEY_ESC
);break;}
190 mplayer_put_key(wParam
);
193 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
197 static int config(uint32_t width
, uint32_t height
, uint32_t d_width
,uint32_t d_height
, uint32_t flags
, char *title
, uint32_t format
){
198 title
= "MPlayer VIDIX WIN32 Overlay";
202 image_height
= height
;
204 image_format
= format
;
205 vo_screenwidth
= GetSystemMetrics(SM_CXSCREEN
);
206 vo_screenheight
= GetSystemMetrics(SM_CYSCREEN
);
207 depthonscreen
= GetDeviceCaps(GetDC(GetDesktopWindow()),BITSPIXEL
);
210 aspect_save_orig(width
, height
);
211 aspect_save_prescale(d_width
, d_height
);
212 aspect_save_screenres(vo_screenwidth
, vo_screenheight
);
217 vo_dx
=( vo_screenwidth
- d_width
) / 2; vo_dy
=( vo_screenheight
- d_height
) / 2;
218 geometry(&vo_dx
, &vo_dy
, &d_width
, &d_height
, vo_screenwidth
, vo_screenheight
);
220 vo_fs
= flags
&VOFLAG_FULLSCREEN
;
223 aspect(&d_width
, &d_height
, A_NOZOOM
);
224 vo_dwidth
=d_width
; vo_dheight
=d_height
;
225 window_aspect
= (float)d_width
/ (float)d_height
;
228 if(!vo_config_count
){
229 HINSTANCE hInstance
= GetModuleHandle(NULL
);
234 rd
.right
= rd
.left
+ vo_dwidth
;
235 rd
.bottom
= rd
.top
+ vo_dheight
;
236 AdjustWindowRect(&rd
,WS_OVERLAPPEDWINDOW
| WS_SIZEBOX
,0);
237 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
238 wc
.lpfnWndProc
= WndProc
;
241 wc
.hInstance
= hInstance
;
242 wc
.hCursor
= LoadCursor(NULL
,IDC_ARROW
);
243 wc
.hIcon
=ExtractIcon(hInstance
,"mplayer.exe",0);
244 //LoadIcon(NULL,IDI_APPLICATION);
245 wc
.hbrBackground
= CreateSolidBrush(RGB(255,0,255));
246 wc
.lpszClassName
= "MPlayer - The Movie Player";
247 wc
.lpszMenuName
= NULL
;
249 hWnd
= CreateWindow("MPlayer - The Movie Player",
251 WS_OVERLAPPEDWINDOW
| WS_SIZEBOX
,
260 wc
.hbrBackground
= CreateSolidBrush(RGB(0,0,0));
261 wc
.lpszClassName
= "MPlayer - Fullscreen";
263 hWndFS
= CreateWindow("MPlayer - Fullscreen","MPlayer VIDIX Fullscreen",WS_POPUP
,0,0,vo_screenwidth
,vo_screenheight
,hWnd
,NULL
,hInstance
,NULL
);
270 ShowWindow(hWnd
,SW_SHOW
);
271 if(vo_fs
)ShowWindow(hWndFS
,SW_SHOW
);
276 static void check_events(void){
278 while (PeekMessage(&msg
, NULL
, 0, 0,PM_REMOVE
))
280 TranslateMessage(&msg
);
281 DispatchMessage(&msg
);
285 /* draw_osd, flip_page, draw_slice, draw_frame should be
286 overwritten with vidix functions (vosub_vidix.c) */
287 static void draw_osd(void){
288 mp_msg(MSGT_VO
, MSGL_FATAL
, "[winvidix] error: didn't use vidix draw_osd!\n");
292 static void flip_page(void){
293 mp_msg(MSGT_VO
, MSGL_FATAL
, "[winvidix] error: didn't use vidix flip_page!\n");
297 static int draw_slice(uint8_t *src
[], int stride
[],int w
, int h
, int x
, int y
){
304 mp_msg(MSGT_VO
, MSGL_FATAL
, "[winvidix] error: didn't use vidix draw_slice!\n");
308 static int draw_frame(uint8_t *src
[]){
310 mp_msg(MSGT_VO
, MSGL_FATAL
, "[winvidix] error: didn't use vidix draw_frame!\n");
314 static int query_format(uint32_t format
){
315 return vidix_query_fourcc(format
);
318 static void uninit(void){
319 DestroyWindow(hWndFS
);
321 if ( !vo_config_count
) return;
331 static int preinit(const char *arg
){
333 vidix_name
= strdup(arg
);
336 mp_msg(MSGT_VO
, MSGL_INFO
, "No vidix driver name provided, probing available ones (-v option for details)!\n");
340 if (vidix_preinit(vidix_name
, video_out_winvidix
.old_functions
) != 0)
346 static int control(uint32_t request
, void *data
){
348 case VOCTRL_FULLSCREEN
:
349 if(!vo_fs
){vo_fs
=1;ShowWindow(hWndFS
,SW_SHOW
);SetForegroundWindow(hWndFS
);}
350 else {vo_fs
=0; ShowWindow(hWndFS
,SW_HIDE
);}
352 case VOCTRL_QUERY_FORMAT
:
353 return query_format(*((uint32_t*)data
));
355 return vidix_control(request
, data
);
356 // return VO_NOTIMPL;