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
)
56 static char *vidix_name
;
58 static int depthonscreen
;
59 /* Image parameters */
60 static uint32_t image_width
;
61 static uint32_t image_height
;
62 static uint32_t image_format
;
63 /* Window parameters */
64 static HWND hWnd
=NULL
,hWndFS
=NULL
;
65 static float window_aspect
;
67 static vidix_grkey_t gr_key
;
70 void set_video_eq(int cap
);
73 static LRESULT CALLBACK
WndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
80 mplayer_put_key(KEY_CLOSE_WIN
);
82 case WM_WINDOWPOSCHANGED
:
85 /*calculate new window rect*/
93 ClientToScreen(hWnd
,&point_window
);
94 GetClientRect(hWnd
,&rd
);
96 vo_dwidth
=rd
.right
- rd
.left
;
97 vo_dheight
=rd
.bottom
- rd
.top
;
98 vo_dx
=point_window
.x
;
99 vo_dy
=point_window
.y
;
100 // aspect(&vo_dwidth, &vo_dheight, A_NOZOOM);
102 /* keep aspect on resize, borrowed from vo_directx.c */
103 tmpheight
= ((float)vo_dwidth
/window_aspect
);
104 tmpheight
+= tmpheight
% 2;
105 if(tmpheight
> vo_dheight
)
107 vo_dwidth
= ((float)vo_dheight
*window_aspect
);
108 vo_dwidth
+= vo_dwidth
% 2;
110 else vo_dheight
= tmpheight
;
111 rd
.right
= rd
.left
+ vo_dwidth
;
112 rd
.bottom
= rd
.top
+ vo_dheight
;
114 if(rd
.left
< 0) rd
.left
= 0;
115 if(rd
.right
> vo_screenwidth
) rd
.right
= vo_screenwidth
;
116 if(rd
.top
< 0) rd
.top
= 0;
117 if(rd
.bottom
> vo_screenheight
) rd
.bottom
= vo_screenheight
;
119 AdjustWindowRect(&rd
, WS_OVERLAPPEDWINDOW
| WS_SIZEBOX
, 0);
120 SetWindowPos(hWnd
, HWND_TOPMOST
, vo_dx
+rd
.left
, vo_dy
+rd
.top
, rd
.right
-rd
.left
, rd
.bottom
-rd
.top
, SWP_NOOWNERZORDER
);
123 if(ShowCursor(FALSE
)>=0)while(ShowCursor(FALSE
)>=0){}
124 aspect(&vo_dwidth
, &vo_dheight
, A_ZOOM
);
125 vo_dx
= (vo_screenwidth
- vo_dwidth
)/2;
126 vo_dy
= (vo_screenheight
- vo_dheight
)/2;
129 /* FIXME: implement runtime resize/move if possible, this way is very ugly! */
131 if(vidix_init(image_width
, image_height
, vo_dx
, vo_dy
, vo_dwidth
, vo_dheight
, image_format
, depthonscreen
, vo_screenwidth
, vo_screenheight
) != 0)
132 mp_msg(MSGT_VO
, MSGL_FATAL
, "Can't initialize VIDIX driver: %s\n", strerror(errno
));
135 mp_msg(MSGT_VO
, MSGL_V
, "[winvidix] window properties: pos: %dx%d, size: %dx%d\n",vo_dx
, vo_dy
, vo_dwidth
, vo_dheight
);
136 if(vidix_grkey_support()){
137 vidix_grkey_get(&gr_key
);
138 gr_key
.key_op
= KEYS_PUT
;
139 gr_key
.ckey
.op
= CKEY_TRUE
;
140 if(vo_fs
)gr_key
.ckey
.red
= gr_key
.ckey
.green
= gr_key
.ckey
.blue
= 0;
142 gr_key
.ckey
.red
= gr_key
.ckey
.blue
= 255;
143 gr_key
.ckey
.green
= 0;
145 vidix_grkey_set(&gr_key
);
153 case SC_MONITORPOWER
:
160 {mplayer_put_key(KEY_LEFT
);break;}
162 {mplayer_put_key(KEY_UP
);break;}
164 {mplayer_put_key(KEY_RIGHT
);break;}
166 {mplayer_put_key(KEY_DOWN
);break;}
168 {mplayer_put_key(KEY_TAB
);break;}
170 {mplayer_put_key(KEY_CTRL
);break;}
172 {mplayer_put_key(KEY_DELETE
);break;}
174 {mplayer_put_key(KEY_INSERT
);break;}
176 {mplayer_put_key(KEY_HOME
);break;}
178 {mplayer_put_key(KEY_END
);break;}
180 {mplayer_put_key(KEY_PAGE_UP
);break;}
182 {mplayer_put_key(KEY_PAGE_DOWN
);break;}
184 {mplayer_put_key(KEY_ESC
);break;}
188 mplayer_put_key(wParam
);
191 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
195 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
){
196 title
= "MPlayer VIDIX WIN32 Overlay";
200 image_height
= height
;
202 image_format
= format
;
203 vo_screenwidth
= GetSystemMetrics(SM_CXSCREEN
);
204 vo_screenheight
= GetSystemMetrics(SM_CYSCREEN
);
205 depthonscreen
= GetDeviceCaps(GetDC(GetDesktopWindow()),BITSPIXEL
);
208 aspect_save_orig(width
, height
);
209 aspect_save_prescale(d_width
, d_height
);
210 aspect_save_screenres(vo_screenwidth
, vo_screenheight
);
215 vo_dx
=( vo_screenwidth
- d_width
) / 2; vo_dy
=( vo_screenheight
- d_height
) / 2;
216 geometry(&vo_dx
, &vo_dy
, &d_width
, &d_height
, vo_screenwidth
, vo_screenheight
);
218 vo_fs
= flags
&VOFLAG_FULLSCREEN
;
221 aspect(&d_width
, &d_height
, A_NOZOOM
);
222 vo_dwidth
=d_width
; vo_dheight
=d_height
;
223 window_aspect
= (float)d_width
/ (float)d_height
;
226 if(!vo_config_count
){
227 HINSTANCE hInstance
= GetModuleHandle(NULL
);
232 rd
.right
= rd
.left
+ vo_dwidth
;
233 rd
.bottom
= rd
.top
+ vo_dheight
;
234 AdjustWindowRect(&rd
,WS_OVERLAPPEDWINDOW
| WS_SIZEBOX
,0);
235 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
236 wc
.lpfnWndProc
= WndProc
;
239 wc
.hInstance
= hInstance
;
240 wc
.hCursor
= LoadCursor(NULL
,IDC_ARROW
);
241 wc
.hIcon
=ExtractIcon(hInstance
,"mplayer.exe",0);
242 //LoadIcon(NULL,IDI_APPLICATION);
243 wc
.hbrBackground
= CreateSolidBrush(RGB(255,0,255));
244 wc
.lpszClassName
= "MPlayer - The Movie Player";
245 wc
.lpszMenuName
= NULL
;
247 hWnd
= CreateWindow("MPlayer - The Movie Player",
249 WS_OVERLAPPEDWINDOW
| WS_SIZEBOX
,
258 wc
.hbrBackground
= CreateSolidBrush(RGB(0,0,0));
259 wc
.lpszClassName
= "MPlayer - Fullscreen";
261 hWndFS
= CreateWindow("MPlayer - Fullscreen","MPlayer VIDIX Fullscreen",WS_POPUP
,0,0,vo_screenwidth
,vo_screenheight
,hWnd
,NULL
,hInstance
,NULL
);
268 ShowWindow(hWnd
,SW_SHOW
);
269 if(vo_fs
)ShowWindow(hWndFS
,SW_SHOW
);
274 static void check_events(void){
276 while (PeekMessage(&msg
, NULL
, 0, 0,PM_REMOVE
))
278 TranslateMessage(&msg
);
279 DispatchMessage(&msg
);
283 /* draw_osd, flip_page, draw_slice, draw_frame should be
284 overwritten with vidix functions (vosub_vidix.c) */
285 static void draw_osd(void){
286 mp_msg(MSGT_VO
, MSGL_FATAL
, "[winvidix] error: didn't use vidix draw_osd!\n");
290 static void flip_page(void){
291 mp_msg(MSGT_VO
, MSGL_FATAL
, "[winvidix] error: didn't use vidix flip_page!\n");
295 static int draw_slice(uint8_t *src
[], int stride
[],int w
, int h
, int x
, int y
){
296 mp_msg(MSGT_VO
, MSGL_FATAL
, "[winvidix] error: didn't use vidix draw_slice!\n");
300 static int draw_frame(uint8_t *src
[]){
301 mp_msg(MSGT_VO
, MSGL_FATAL
, "[winvidix] error: didn't use vidix draw_frame!\n");
305 static int query_format(uint32_t format
){
306 return vidix_query_fourcc(format
);
309 static void uninit(void){
310 DestroyWindow(hWndFS
);
312 if ( !vo_config_count
) return;
319 static int preinit(const char *arg
){
321 vidix_name
= strdup(arg
);
324 mp_msg(MSGT_VO
, MSGL_INFO
, "No vidix driver name provided, probing available ones (-v option for details)!\n");
328 if (vidix_preinit(vidix_name
, video_out_winvidix
.old_functions
) != 0)
334 static int control(uint32_t request
, void *data
){
336 case VOCTRL_FULLSCREEN
:
337 if(!vo_fs
){vo_fs
=1;ShowWindow(hWndFS
,SW_SHOW
);SetForegroundWindow(hWndFS
);}
338 else {vo_fs
=0; ShowWindow(hWndFS
,SW_HIDE
);}
340 case VOCTRL_QUERY_FORMAT
:
341 return query_format(*((uint32_t*)data
));
343 return vidix_control(request
, data
);
344 // return VO_NOTIMPL;