manpage: Fix wrong option name in input example
[mplayer/glamo.git] / libvo / vo_winvidix.c
blob3c3f0419d8367fc86dfbcf0af66fa655141963b5
1 /*
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.
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <math.h>
27 #include <errno.h>
29 #include "config.h"
30 #include "video_out.h"
31 #include "video_out_internal.h"
33 #include <windows.h>
34 #include "osdep/keycodes.h"
35 #include "input/input.h"
37 #include "aspect.h"
38 #include "mp_msg.h"
39 #include "mp_fifo.h"
41 #include "vosub_vidix.h"
42 #include "vidix/vidix.h"
45 static const vo_info_t info =
47 "WIN32 (VIDIX)",
48 "winvidix",
49 "Sascha Sommer",
53 LIBVO_EXTERN(winvidix)
55 #define UNUSED(x) ((void)(x)) /* Removes warning about unused arguments */
57 /* VIDIX related */
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)
77 switch (message){
78 case WM_DESTROY:
79 PostQuitMessage(0);
80 return 0;
81 case WM_CLOSE:
82 mplayer_put_key(KEY_CLOSE_WIN);
83 break;
84 case WM_WINDOWPOSCHANGED:
86 int tmpheight=0;
87 /*calculate new window rect*/
88 if(!vo_fs){
89 RECT rd;
90 POINT point_window;
91 if(!hWnd)hWnd=hwnd;
92 ShowCursor(TRUE);
93 point_window.x = 0;
94 point_window.y = 0;
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);
124 else {
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;
130 /*update vidix*/
131 /* FIXME: implement runtime resize/move if possible, this way is very ugly! */
132 vidix_stop();
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));
135 /*set colorkey*/
136 vidix_start();
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;
143 else {
144 gr_key.ckey.red = gr_key.ckey.blue = 255;
145 gr_key.ckey.green = 0;
147 vidix_grkey_set(&gr_key);
151 break;
152 case WM_SYSCOMMAND:
153 switch (wParam){
154 case SC_SCREENSAVE:
155 case SC_MONITORPOWER:
156 return 0;
158 break;
159 case WM_KEYDOWN:
160 switch (wParam){
161 case VK_LEFT:
162 {mplayer_put_key(KEY_LEFT);break;}
163 case VK_UP:
164 {mplayer_put_key(KEY_UP);break;}
165 case VK_RIGHT:
166 {mplayer_put_key(KEY_RIGHT);break;}
167 case VK_DOWN:
168 {mplayer_put_key(KEY_DOWN);break;}
169 case VK_TAB:
170 {mplayer_put_key(KEY_TAB);break;}
171 case VK_CONTROL:
172 {mplayer_put_key(KEY_CTRL);break;}
173 case VK_DELETE:
174 {mplayer_put_key(KEY_DELETE);break;}
175 case VK_INSERT:
176 {mplayer_put_key(KEY_INSERT);break;}
177 case VK_HOME:
178 {mplayer_put_key(KEY_HOME);break;}
179 case VK_END:
180 {mplayer_put_key(KEY_END);break;}
181 case VK_PRIOR:
182 {mplayer_put_key(KEY_PAGE_UP);break;}
183 case VK_NEXT:
184 {mplayer_put_key(KEY_PAGE_DOWN);break;}
185 case VK_ESCAPE:
186 {mplayer_put_key(KEY_ESC);break;}
188 break;
189 case WM_CHAR:
190 mplayer_put_key(wParam);
191 break;
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";
200 panscan_init();
202 image_height = height;
203 image_width = width;
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);
214 vo_dx = 0;
215 vo_dy = 0;
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);
230 WNDCLASS wc;
231 RECT rd;
232 rd.left = vo_dx;
233 rd.top = vo_dy;
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;
239 wc.cbClsExtra = 0;
240 wc.cbWndExtra = 0;
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;
248 RegisterClass(&wc);
249 hWnd = CreateWindow("MPlayer - The Movie Player",
250 title,
251 WS_OVERLAPPEDWINDOW| WS_SIZEBOX,
252 rd.left,
253 rd.top,
254 rd.right - rd.left,
255 rd.bottom - rd.top,
256 NULL,
257 NULL,
258 hInstance,
259 NULL);
260 wc.hbrBackground = CreateSolidBrush(RGB(0,0,0));
261 wc.lpszClassName = "MPlayer - Fullscreen";
262 RegisterClass(&wc);
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);
273 return 0;
276 static void check_events(void){
277 MSG msg;
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");
289 return;
292 static void flip_page(void){
293 mp_msg(MSGT_VO, MSGL_FATAL, "[winvidix] error: didn't use vidix flip_page!\n");
294 return;
297 static int draw_slice(uint8_t *src[], int stride[],int w, int h, int x, int y){
298 UNUSED(src);
299 UNUSED(stride);
300 UNUSED(w);
301 UNUSED(h);
302 UNUSED(x);
303 UNUSED(y);
304 mp_msg(MSGT_VO, MSGL_FATAL, "[winvidix] error: didn't use vidix draw_slice!\n");
305 return -1;
308 static int draw_frame(uint8_t *src[]){
309 UNUSED(src);
310 mp_msg(MSGT_VO, MSGL_FATAL, "[winvidix] error: didn't use vidix draw_frame!\n");
311 return -1;
314 static int query_format(uint32_t format){
315 return vidix_query_fourcc(format);
318 static void uninit(void){
319 DestroyWindow(hWndFS);
320 DestroyWindow(hWnd);
321 if ( !vo_config_count ) return;
322 vidix_term();
324 if (vidix_name){
325 free(vidix_name);
326 vidix_name = NULL;
331 static int preinit(const char *arg){
332 if (arg)
333 vidix_name = strdup(arg);
334 else
336 mp_msg(MSGT_VO, MSGL_INFO, "No vidix driver name provided, probing available ones (-v option for details)!\n");
337 vidix_name = NULL;
340 if (vidix_preinit(vidix_name, video_out_winvidix.old_functions) != 0)
341 return 1;
343 return 0;
346 static int control(uint32_t request, void *data){
347 switch (request) {
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);}
351 break;
352 case VOCTRL_QUERY_FORMAT:
353 return query_format(*((uint32_t*)data));
355 return vidix_control(request, data);
356 // return VO_NOTIMPL;