Mercurial > mplayer.hg
annotate libvo/vo_macosx.m @ 16366:e054a3c93a26
custom quantization matrix for x264, original patch by Robert Swain < robert POUM swain AH gmail POUM com>
Lots of nits and improvement by the MPlayer team
Original thread:
Date: Jul 12, 2005 5:04 PM
Subject: [MPlayer-dev-eng] [PATCH] CQMs in x264
author | gpoirier |
---|---|
date | Fri, 02 Sep 2005 21:54:17 +0000 |
parents | fd51fd1ff231 |
children | 35b310d35aa0 |
rev | line source |
---|---|
15289 | 1 /* |
2 vo_macosx.m | |
3 by Nicolas Plourde <nicolasplourde@gmail.com> | |
4 | |
5 MPlayer Mac OSX video out module. | |
6 Copyright (c) Nicolas Plourde - 2005 | |
7 */ | |
8 | |
9 #import "vo_macosx.h" | |
10 | |
11 //MPLAYER | |
12 #include "config.h" | |
13 #include "fastmemcpy.h" | |
14 #include "video_out.h" | |
15 #include "video_out_internal.h" | |
16 #include "aspect.h" | |
17 #include "mp_msg.h" | |
18 #include "m_option.h" | |
19 | |
20 #include "input/input.h" | |
21 #include "input/mouse.h" | |
22 | |
23 #include "osdep/keycodes.h" | |
24 | |
25 //Cocoa | |
15611 | 26 MPlayerOpenGLView *mpGLView; |
15289 | 27 NSAutoreleasePool *autoreleasepool; |
28 OSType pixelFormat; | |
29 | |
15728 | 30 //Screen |
31 int screen_id; | |
32 BOOL screen_force; | |
33 NSRect screen_frame; | |
34 NSScreen *screen_handle; | |
35 NSArray *screen_array; | |
15289 | 36 |
37 //image | |
38 unsigned char *image_data; | |
39 static uint32_t image_width; | |
40 static uint32_t image_height; | |
41 static uint32_t image_depth; | |
42 static uint32_t image_bytes; | |
43 static uint32_t image_format; | |
44 | |
45 //vo | |
46 extern int vo_rootwin; | |
47 extern int vo_ontop; | |
48 extern int vo_fs; | |
49 static int isFullscreen; | |
15320 | 50 static int isOntop; |
15327 | 51 static int isRootwin; |
15289 | 52 extern float monitor_aspect; |
53 extern int vo_keepaspect; | |
54 extern float movie_aspect; | |
55 static float old_movie_aspect; | |
56 extern float vo_panscan; | |
57 | |
15731 | 58 static float winAlpha = 1; |
15289 | 59 static int int_pause = 0; |
60 | |
61 static vo_info_t info = | |
62 { | |
63 "Mac OSX Core Video", | |
64 "macosx", | |
65 "Nicolas Plourde <nicolas.plourde@gmail.com>", | |
66 "" | |
67 }; | |
68 | |
69 LIBVO_EXTERN(macosx) | |
70 | |
71 extern void mplayer_put_key(int code); | |
72 extern void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)); | |
73 | |
74 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride) | |
75 { | |
76 switch (image_format) | |
77 { | |
78 case IMGFMT_RGB32: | |
79 vo_draw_alpha_rgb32(w,h,src,srca,stride,image_data+4*(y0*image_width+x0),4*image_width); | |
80 break; | |
81 case IMGFMT_YUY2: | |
82 vo_draw_alpha_yuy2(w,h,src,srca,stride,image_data + (x0 + y0 * image_width) * 2,image_width*2); | |
83 break; | |
84 } | |
85 } | |
86 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
87 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) |
15289 | 88 { |
89 int i; | |
15728 | 90 |
91 //init screen | |
92 screen_array = [NSScreen screens]; | |
93 if(screen_id < [screen_array count]) | |
15289 | 94 { |
15728 | 95 screen_handle = [screen_array objectAtIndex:screen_id]; |
15289 | 96 } |
15728 | 97 else |
98 { | |
99 mp_msg(MSGT_VO, MSGL_FATAL, "Get device error: Device ID %d do not exist, falling back to main device.\n", screen_id); | |
100 screen_handle = [screen_array objectAtIndex:0]; | |
101 screen_id = 0; | |
102 } | |
103 screen_frame = [screen_handle frame]; | |
15289 | 104 |
15728 | 105 monitor_aspect = (float)screen_frame.size.width/(float)screen_frame.size.height; |
15289 | 106 |
107 //misc mplayer setup | |
108 image_width = width; | |
109 image_height = height; | |
110 switch (image_format) | |
111 { | |
112 case IMGFMT_BGR32: | |
113 case IMGFMT_RGB32: | |
114 image_depth = 32; | |
115 break; | |
116 case IMGFMT_YUY2: | |
117 image_depth = 16; | |
118 break; | |
119 } | |
120 image_bytes = (image_depth + 7) / 8; | |
121 image_data = (unsigned char*)malloc(image_width*image_height*image_bytes); | |
122 | |
123 //set aspect | |
124 panscan_init(); | |
125 aspect_save_orig(width,height); | |
126 aspect_save_prescale(d_width,d_height); | |
15728 | 127 aspect_save_screenres(screen_frame.size.width, screen_frame.size.height); |
15571 | 128 aspect((int *)&d_width,(int *)&d_height,A_NOZOOM); |
15289 | 129 |
130 movie_aspect = (float)d_width/(float)d_height; | |
131 old_movie_aspect = movie_aspect; | |
132 | |
133 vo_fs = flags & VOFLAG_FULLSCREEN; | |
15726 | 134 |
135 //config OpenGL View | |
136 [mpGLView config]; | |
16144 | 137 [mpGLView reshape]; |
15731 | 138 |
15289 | 139 return 0; |
140 } | |
141 | |
142 static void check_events(void) | |
143 { | |
15611 | 144 [mpGLView check_events]; |
15289 | 145 } |
146 | |
147 static void draw_osd(void) | |
148 { | |
149 vo_draw_text(image_width, image_height, draw_alpha); | |
150 } | |
151 | |
152 static void flip_page(void) | |
153 { | |
15611 | 154 [mpGLView render]; |
15289 | 155 } |
156 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
157 static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) |
15289 | 158 { |
15611 | 159 [mpGLView setCurrentTexture]; |
15289 | 160 return 0; |
161 } | |
162 | |
163 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
164 static int draw_frame(uint8_t *src[]) |
15289 | 165 { |
166 switch (image_format) | |
167 { | |
168 case IMGFMT_BGR32: | |
169 case IMGFMT_RGB32: | |
170 memcpy(image_data, src[0], image_width*image_height*image_bytes); | |
171 break; | |
172 | |
173 case IMGFMT_YUY2: | |
174 memcpy_pic(image_data, src[0], image_width * 2, image_height, image_width * 2, image_width * 2); | |
175 break; | |
176 } | |
15611 | 177 [mpGLView setCurrentTexture]; |
15289 | 178 return 0; |
179 } | |
180 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
181 static int query_format(uint32_t format) |
15289 | 182 { |
183 image_format = format; | |
184 | |
185 switch(format) | |
186 { | |
187 case IMGFMT_YUY2: | |
188 pixelFormat = kYUVSPixelFormat; | |
189 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN; | |
190 | |
191 case IMGFMT_RGB32: | |
192 case IMGFMT_BGR32: | |
193 pixelFormat = k32ARGBPixelFormat; | |
194 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN; | |
195 } | |
196 return 0; | |
197 } | |
198 | |
199 static void uninit(void) | |
200 { | |
16145 | 201 SetSystemUIMode( kUIModeNormal, 0); |
202 ShowCursor(); | |
203 | |
15289 | 204 [autoreleasepool release]; |
205 } | |
206 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
207 static int preinit(const char *arg) |
15289 | 208 { |
209 int parse_err = 0; | |
210 | |
211 #if !defined (MACOSX_FINDER_SUPPORT) || !defined (HAVE_SDL) | |
212 //this chunk of code is heavily based off SDL_macosx.m from SDL | |
213 //it uses an Apple private function to request foreground operation | |
214 void CPSEnableForegroundOperation(ProcessSerialNumber* psn); | |
215 ProcessSerialNumber myProc, frProc; | |
216 Boolean sameProc; | |
217 | |
218 if (GetFrontProcess(&frProc) == noErr) | |
219 { | |
220 if (GetCurrentProcess(&myProc) == noErr) | |
221 { | |
222 if (SameProcess(&frProc, &myProc, &sameProc) == noErr && !sameProc) | |
223 { | |
224 CPSEnableForegroundOperation(&myProc); | |
225 } | |
226 SetFrontProcess(&myProc); | |
227 } | |
228 } | |
229 #endif | |
230 | |
15728 | 231 if(arg) |
232 { | |
233 char *parse_pos = (char *)&arg[0]; | |
234 while (parse_pos[0] && !parse_err) | |
235 { | |
236 if (strncmp (parse_pos, "device_id=", 10) == 0) | |
237 { | |
238 parse_pos = &parse_pos[10]; | |
239 screen_id = strtol(parse_pos, &parse_pos, 0); | |
240 screen_force = YES; | |
241 } | |
242 if (parse_pos[0] == ':') parse_pos = &parse_pos[1]; | |
243 else if (parse_pos[0]) parse_err = 1; | |
244 } | |
245 } | |
246 | |
15737
0c3939433cef
set nsapp and setup cocoa with NSApplicationLoad
nplourde
parents:
15736
diff
changeset
|
247 NSApplicationLoad(); |
15289 | 248 autoreleasepool = [[NSAutoreleasePool alloc] init]; |
15737
0c3939433cef
set nsapp and setup cocoa with NSApplicationLoad
nplourde
parents:
15736
diff
changeset
|
249 NSApp = [NSApplication sharedApplication]; |
15726 | 250 |
16144 | 251 if(!mpGLView) |
252 { | |
253 mpGLView = [[MPlayerOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) pixelFormat:[MPlayerOpenGLView defaultPixelFormat]]; | |
254 [mpGLView autorelease]; | |
255 } | |
256 | |
257 [mpGLView display]; | |
15726 | 258 [mpGLView preinit]; |
259 | |
15289 | 260 return 0; |
261 } | |
262 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
263 static int control(uint32_t request, void *data, ...) |
15289 | 264 { |
265 switch (request) | |
266 { | |
267 case VOCTRL_PAUSE: return (int_pause=1); | |
268 case VOCTRL_RESUME: return (int_pause=0); | |
269 case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data)); | |
15611 | 270 case VOCTRL_ONTOP: vo_ontop = (!(vo_ontop)); [mpGLView ontop]; return VO_TRUE; |
271 case VOCTRL_ROOTWIN: vo_rootwin = (!(vo_rootwin)); [mpGLView rootwin]; return VO_TRUE; | |
272 case VOCTRL_FULLSCREEN: vo_fs = (!(vo_fs)); [mpGLView fullscreen: YES]; return VO_TRUE; | |
15289 | 273 case VOCTRL_GET_PANSCAN: return VO_TRUE; |
15611 | 274 case VOCTRL_SET_PANSCAN: [mpGLView panscan]; return VO_TRUE; |
15289 | 275 } |
276 return VO_NOTIMPL; | |
277 } | |
278 | |
279 ////////////////////////////////////////////////////////////////////////// | |
280 // NSOpenGLView Subclass | |
281 ////////////////////////////////////////////////////////////////////////// | |
15611 | 282 @implementation MPlayerOpenGLView |
15726 | 283 - (id) preinit |
15289 | 284 { |
15726 | 285 //init menu |
286 [self initMenu]; | |
287 | |
288 //create window | |
15747
fbf14e1ab725
osx 10.3 dont like to have a window init with no size
nplourde
parents:
15737
diff
changeset
|
289 window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) |
15726 | 290 styleMask:NSTitledWindowMask|NSTexturedBackgroundWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask |
291 backing:NSBackingStoreBuffered defer:NO]; | |
292 | |
16144 | 293 [window autorelease]; |
15726 | 294 [window setDelegate:mpGLView]; |
295 [window setContentView:mpGLView]; | |
296 [window setInitialFirstResponder:mpGLView]; | |
297 [window setAcceptsMouseMovedEvents:YES]; | |
298 [window setTitle:@"MPlayer - The Movie Player"]; | |
299 | |
300 isFullscreen = 0; | |
15855 | 301 winSizeMult = 1; |
15726 | 302 } |
303 | |
304 - (id) config | |
305 { | |
306 uint32_t d_width; | |
307 uint32_t d_height; | |
308 | |
15610 | 309 long swapInterval = 1; |
15726 | 310 |
311 NSRect frame; | |
15289 | 312 CVReturn error = kCVReturnSuccess; |
313 | |
15728 | 314 //config window |
15726 | 315 aspect((int *)&d_width, (int *)&d_height,A_NOZOOM); |
316 frame = NSMakeRect(0, 0, d_width, d_height); | |
317 [window setContentSize: frame.size]; | |
15570 | 318 |
15289 | 319 //create OpenGL Context |
320 glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil]; | |
15647 | 321 |
15289 | 322 [self setOpenGLContext:glContext]; |
15647 | 323 [glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval]; |
15289 | 324 [glContext setView:self]; |
325 [glContext makeCurrentContext]; | |
326 | |
15647 | 327 error = CVPixelBufferCreateWithBytes( NULL, image_width, image_height, pixelFormat, image_data, image_width*image_bytes, NULL, NULL, NULL, ¤tFrameBuffer); |
15289 | 328 if(error != kCVReturnSuccess) |
329 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create Pixel Buffer(%d)\n", error); | |
330 | |
331 error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache); | |
332 if(error != kCVReturnSuccess) | |
333 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture Cache(%d)\n", error); | |
334 | |
335 error = CVOpenGLTextureCacheCreateTextureFromImage( NULL, textureCache, currentFrameBuffer, 0, &texture); | |
336 if(error != kCVReturnSuccess) | |
337 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error); | |
338 | |
15728 | 339 //show window |
340 [window center]; | |
341 [window makeKeyAndOrderFront:mpGLView]; | |
342 | |
15726 | 343 if(vo_rootwin) |
344 [mpGLView rootwin]; | |
345 | |
346 if(vo_fs) | |
347 [mpGLView fullscreen: NO]; | |
348 | |
349 if(vo_ontop) | |
350 [mpGLView ontop]; | |
15289 | 351 } |
352 | |
353 /* | |
15570 | 354 Init Menu |
355 */ | |
356 - (void)initMenu | |
357 { | |
358 NSMenu *menu; | |
359 NSMenuItem *menuItem; | |
360 | |
361 [NSApp setMainMenu:[[NSMenu alloc] init]]; | |
362 | |
363 //Create Movie Menu | |
364 menu = [[NSMenu alloc] initWithTitle:@"Movie"]; | |
365 menuItem = [[NSMenuItem alloc] initWithTitle:@"Half Size" action:@selector(menuAction:) keyEquivalent:@"0"]; [menu addItem:menuItem]; | |
366 kHalfScreenCmd = menuItem; | |
367 menuItem = [[NSMenuItem alloc] initWithTitle:@"Normal Size" action:@selector(menuAction:) keyEquivalent:@"1"]; [menu addItem:menuItem]; | |
368 kNormalScreenCmd = menuItem; | |
369 menuItem = [[NSMenuItem alloc] initWithTitle:@"Double Size" action:@selector(menuAction:) keyEquivalent:@"2"]; [menu addItem:menuItem]; | |
370 kDoubleScreenCmd = menuItem; | |
371 menuItem = [[NSMenuItem alloc] initWithTitle:@"Full Size" action:@selector(menuAction:) keyEquivalent:@"f"]; [menu addItem:menuItem]; | |
372 kFullScreenCmd = menuItem; | |
15909 | 373 menuItem = (NSMenuItem *)[NSMenuItem separatorItem]; [menu addItem:menuItem]; |
15570 | 374 |
375 NSMenu *aspectMenu; | |
376 aspectMenu = [[NSMenu alloc] initWithTitle:@"Aspect Ratio"]; | |
377 menuItem = [[NSMenuItem alloc] initWithTitle:@"Keep" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
378 if(vo_keepaspect) [menuItem setState:NSOnState]; | |
379 kKeepAspectCmd = menuItem; | |
380 menuItem = [[NSMenuItem alloc] initWithTitle:@"Pan-Scan" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
381 if(vo_panscan) [menuItem setState:NSOnState]; | |
382 kPanScanCmd = menuItem; | |
15909 | 383 menuItem = (NSMenuItem *)[NSMenuItem separatorItem]; [aspectMenu addItem:menuItem]; |
15570 | 384 menuItem = [[NSMenuItem alloc] initWithTitle:@"Original" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; |
385 kAspectOrgCmd = menuItem; | |
386 menuItem = [[NSMenuItem alloc] initWithTitle:@"4:3" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
387 kAspectFullCmd = menuItem; | |
388 menuItem = [[NSMenuItem alloc] initWithTitle:@"16:9" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
389 kAspectWideCmd = menuItem; | |
390 menuItem = [[NSMenuItem alloc] initWithTitle:@"Aspect Ratio" action:nil keyEquivalent:@""]; | |
391 [menuItem setSubmenu:aspectMenu]; | |
392 [menu addItem:menuItem]; | |
393 [aspectMenu release]; | |
394 | |
395 //Add to menubar | |
396 menuItem = [[NSMenuItem alloc] initWithTitle:@"Movie" action:nil keyEquivalent:@""]; | |
397 [menuItem setSubmenu:menu]; | |
398 [[NSApp mainMenu] addItem:menuItem]; | |
399 | |
400 //Create Window Menu | |
401 menu = [[NSMenu alloc] initWithTitle:@"Window"]; | |
402 | |
403 menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; [menu addItem:menuItem]; | |
404 menuItem = [[NSMenuItem alloc] initWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""]; [menu addItem:menuItem]; | |
405 | |
406 //Add to menubar | |
407 menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; | |
408 [menuItem setSubmenu:menu]; | |
409 [[NSApp mainMenu] addItem:menuItem]; | |
410 [NSApp setWindowsMenu:menu]; | |
411 | |
412 [menu release]; | |
413 [menuItem release]; | |
414 } | |
415 | |
416 /* | |
417 Menu Action | |
418 */ | |
419 - (void)menuAction:(id)sender | |
420 { | |
421 uint32_t d_width; | |
422 uint32_t d_height; | |
423 NSRect frame; | |
424 | |
425 aspect((int *)&d_width, (int *)&d_height,A_NOZOOM); | |
15731 | 426 |
427 if(sender == kQuitCmd) | |
428 { | |
429 mplayer_put_key(KEY_ESC); | |
430 } | |
15570 | 431 |
432 if(sender == kHalfScreenCmd) | |
433 { | |
434 if(isFullscreen) { | |
435 vo_fs = (!(vo_fs)); [self fullscreen:YES]; | |
436 } | |
437 | |
15855 | 438 winSizeMult = 0.5; |
439 frame.size.width = (d_width*winSizeMult); | |
440 frame.size.height = ((d_width/movie_aspect)*winSizeMult); | |
15570 | 441 [window setContentSize: frame.size]; |
442 [self reshape]; | |
443 } | |
444 if(sender == kNormalScreenCmd) | |
445 { | |
446 if(isFullscreen) { | |
447 vo_fs = (!(vo_fs)); [self fullscreen:YES]; | |
448 } | |
449 | |
15855 | 450 winSizeMult = 1; |
15570 | 451 frame.size.width = d_width; |
452 frame.size.height = d_width/movie_aspect; | |
453 [window setContentSize: frame.size]; | |
454 [self reshape]; | |
455 } | |
456 if(sender == kDoubleScreenCmd) | |
457 { | |
458 if(isFullscreen) { | |
459 vo_fs = (!(vo_fs)); [self fullscreen:YES]; | |
460 } | |
461 | |
15855 | 462 winSizeMult = 2; |
463 frame.size.width = d_width*winSizeMult; | |
464 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
15570 | 465 [window setContentSize: frame.size]; |
466 [self reshape]; | |
467 } | |
468 if(sender == kFullScreenCmd) | |
469 { | |
470 vo_fs = (!(vo_fs)); | |
471 [self fullscreen:YES]; | |
472 } | |
473 | |
474 if(sender == kKeepAspectCmd) | |
475 { | |
476 vo_keepaspect = (!(vo_keepaspect)); | |
477 if(vo_keepaspect) | |
478 [kKeepAspectCmd setState:NSOnState]; | |
479 else | |
480 [kKeepAspectCmd setState:NSOffState]; | |
15909 | 481 |
482 [self reshape]; | |
15570 | 483 } |
484 | |
485 if(sender == kPanScanCmd) | |
486 { | |
487 vo_panscan = (!(vo_panscan)); | |
488 if(vo_panscan) | |
489 [kPanScanCmd setState:NSOnState]; | |
490 else | |
491 [kPanScanCmd setState:NSOffState]; | |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
492 |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
493 [self panscan]; |
15570 | 494 } |
495 | |
496 if(sender == kAspectOrgCmd) | |
497 { | |
498 movie_aspect = old_movie_aspect; | |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
499 |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
500 if(isFullscreen) |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
501 { |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
502 [self reshape]; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
503 } |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
504 else |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
505 { |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
506 frame.size.width = d_width*winSizeMult; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
507 frame.size.height = (d_width/movie_aspect)*winSizeMult; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
508 [window setContentSize: frame.size]; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
509 [self reshape]; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
510 } |
15570 | 511 } |
512 | |
513 if(sender == kAspectFullCmd) | |
514 { | |
515 movie_aspect = 4.0f/3.0f; | |
15882 | 516 |
517 if(isFullscreen) | |
518 { | |
519 [self reshape]; | |
520 } | |
521 else | |
522 { | |
523 frame.size.width = d_width*winSizeMult; | |
524 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
525 [window setContentSize: frame.size]; | |
526 [self reshape]; | |
527 } | |
15570 | 528 } |
529 | |
530 if(sender == kAspectWideCmd) | |
531 { | |
532 movie_aspect = 16.0f/9.0f; | |
15882 | 533 |
534 if(isFullscreen) | |
535 { | |
536 [self reshape]; | |
537 } | |
538 else | |
539 { | |
540 frame.size.width = d_width*winSizeMult; | |
541 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
542 [window setContentSize: frame.size]; | |
543 [self reshape]; | |
544 } | |
15570 | 545 } |
546 } | |
547 | |
548 /* | |
15289 | 549 Setup OpenGL |
550 */ | |
551 - (void)prepareOpenGL | |
552 { | |
15339 | 553 glEnable(GL_BLEND); |
15289 | 554 glDisable(GL_DEPTH_TEST); |
555 glDepthMask(GL_FALSE); | |
556 glDisable(GL_CULL_FACE); | |
557 [self reshape]; | |
558 } | |
559 | |
560 /* | |
561 reshape OpenGL viewport | |
562 */ | |
563 - (void)reshape | |
564 { | |
565 uint32_t d_width; | |
566 uint32_t d_height; | |
567 float aspectX; | |
568 float aspectY; | |
569 int padding = 0; | |
570 | |
571 NSRect frame = [self frame]; | |
572 | |
573 glViewport(0, 0, frame.size.width, frame.size.height); | |
574 glMatrixMode(GL_PROJECTION); | |
575 glLoadIdentity(); | |
576 glOrtho(0, frame.size.width, frame.size.height, 0, -1.0, 1.0); | |
577 glMatrixMode(GL_MODELVIEW); | |
578 glLoadIdentity(); | |
579 | |
15729 | 580 //set texture frame |
15289 | 581 if(vo_keepaspect) |
582 { | |
15571 | 583 aspect( (int *)&d_width, (int *)&d_height, A_NOZOOM); |
15289 | 584 d_height = ((float)d_width/movie_aspect); |
585 | |
586 aspectX = (float)((float)frame.size.width/(float)d_width); | |
587 aspectY = (float)((float)(frame.size.height)/(float)d_height); | |
588 | |
589 if((d_height*aspectX)>(frame.size.height)) | |
590 { | |
591 padding = (frame.size.width - d_width*aspectY)/2; | |
15729 | 592 textureFrame = NSMakeRect(padding, 0, d_width*aspectY+padding, d_height*aspectY); |
15289 | 593 } |
594 else | |
595 { | |
596 padding = ((frame.size.height) - d_height*aspectX)/2; | |
15729 | 597 textureFrame = NSMakeRect(0, padding, d_width*aspectX, d_height*aspectX+padding); |
15289 | 598 } |
599 } | |
600 else | |
601 { | |
15729 | 602 textureFrame = frame; |
15289 | 603 } |
604 } | |
605 | |
606 /* | |
607 Render frame | |
608 */ | |
609 - (void) render | |
610 { | |
611 glClear(GL_COLOR_BUFFER_BIT); | |
612 | |
613 glEnable(CVOpenGLTextureGetTarget(texture)); | |
614 glBindTexture(CVOpenGLTextureGetTarget(texture), CVOpenGLTextureGetName(texture)); | |
615 | |
616 glColor3f(1,1,1); | |
617 glBegin(GL_QUADS); | |
15729 | 618 glTexCoord2f(upperLeft[0], upperLeft[1]); glVertex2i( textureFrame.origin.x-(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); |
619 glTexCoord2f(lowerLeft[0], lowerLeft[1]); glVertex2i( textureFrame.origin.x-(vo_panscan_x >> 1), textureFrame.size.height+(vo_panscan_y >> 1)); | |
620 glTexCoord2f(lowerRight[0], lowerRight[1]); glVertex2i( textureFrame.size.width+(vo_panscan_x >> 1), textureFrame.size.height+(vo_panscan_y >> 1)); | |
621 glTexCoord2f(upperRight[0], upperRight[1]); glVertex2i( textureFrame.size.width+(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); | |
15289 | 622 glEnd(); |
15339 | 623 glDisable(CVOpenGLTextureGetTarget(texture)); |
624 | |
625 //render resize box | |
626 if(!isFullscreen) | |
627 { | |
628 NSRect frame = [self frame]; | |
629 | |
630 glBegin(GL_LINES); | |
631 glColor4f(0.2, 0.2, 0.2, 0.5); | |
632 glVertex2i(frame.size.width-1, frame.size.height-1); glVertex2i(frame.size.width-1, frame.size.height-1); | |
633 glVertex2i(frame.size.width-1, frame.size.height-5); glVertex2i(frame.size.width-5, frame.size.height-1); | |
634 glVertex2i(frame.size.width-1, frame.size.height-9); glVertex2i(frame.size.width-9, frame.size.height-1); | |
635 | |
636 glColor4f(0.4, 0.4, 0.4, 0.5); | |
637 glVertex2i(frame.size.width-1, frame.size.height-2); glVertex2i(frame.size.width-2, frame.size.height-1); | |
638 glVertex2i(frame.size.width-1, frame.size.height-6); glVertex2i(frame.size.width-6, frame.size.height-1); | |
639 glVertex2i(frame.size.width-1, frame.size.height-10); glVertex2i(frame.size.width-10, frame.size.height-1); | |
640 | |
641 glColor4f(0.6, 0.6, 0.6, 0.5); | |
642 glVertex2i(frame.size.width-1, frame.size.height-3); glVertex2i(frame.size.width-3, frame.size.height-1); | |
643 glVertex2i(frame.size.width-1, frame.size.height-7); glVertex2i(frame.size.width-7, frame.size.height-1); | |
644 glVertex2i(frame.size.width-1, frame.size.height-11); glVertex2i(frame.size.width-11, frame.size.height-1); | |
645 glEnd(); | |
646 } | |
15289 | 647 |
648 glFlush(); | |
649 | |
650 //auto hide mouse cursor and futur on-screen control? | |
15327 | 651 if(isFullscreen && !mouseHide && !isRootwin) |
15289 | 652 { |
653 DateTimeRec d; | |
654 unsigned long curTime; | |
655 static unsigned long lastTime = 0; | |
656 | |
657 GetTime(&d); | |
658 DateToSeconds( &d, &curTime); | |
659 | |
660 if( ((curTime - lastTime) >= 5) || (lastTime == 0) ) | |
661 { | |
662 HideCursor(); | |
663 mouseHide = YES; | |
664 lastTime = curTime; | |
665 } | |
666 } | |
667 } | |
668 | |
669 /* | |
670 Create OpenGL texture from current frame & set texco | |
671 */ | |
672 - (void) setCurrentTexture | |
673 { | |
674 CVReturn error = kCVReturnSuccess; | |
675 | |
676 error = CVOpenGLTextureCacheCreateTextureFromImage (NULL, textureCache, currentFrameBuffer, 0, &texture); | |
677 if(error != kCVReturnSuccess) | |
678 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error); | |
679 | |
680 CVOpenGLTextureGetCleanTexCoords(texture, lowerLeft, lowerRight, upperRight, upperLeft); | |
681 } | |
682 | |
683 /* | |
684 redraw win rect | |
685 */ | |
686 - (void) drawRect: (NSRect *) bounds | |
687 { | |
688 [self render]; | |
689 } | |
690 | |
691 /* | |
692 Toggle Fullscreen | |
693 */ | |
694 - (void) fullscreen: (BOOL) animate | |
695 { | |
696 static NSRect old_frame; | |
697 static NSRect old_view_frame; | |
15728 | 698 |
699 if(screen_force) | |
700 screen_frame = [screen_handle frame]; | |
701 else | |
702 screen_frame = [[window screen] frame]; | |
15289 | 703 |
15573 | 704 panscan_calc(); |
705 | |
15289 | 706 //go fullscreen |
707 if(vo_fs) | |
708 { | |
15327 | 709 if(!isRootwin) |
710 { | |
15882 | 711 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar); |
15327 | 712 HideCursor(); |
713 mouseHide = YES; | |
714 } | |
15289 | 715 |
716 old_frame = [window frame]; //save main window size & position | |
15728 | 717 [window setFrame:screen_frame display:YES animate:animate]; //zoom-in window with nice useless sfx |
15289 | 718 old_view_frame = [self bounds]; |
719 | |
720 //fix origin for multi screen setup | |
15728 | 721 screen_frame.origin.x = 0; |
722 screen_frame.origin.y = 0; | |
723 [self setFrame:screen_frame]; | |
15289 | 724 [self setNeedsDisplay:YES]; |
725 [window setHasShadow:NO]; | |
726 isFullscreen = 1; | |
727 } | |
728 else | |
15882 | 729 { |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
730 SetSystemUIMode( kUIModeNormal, 0); |
15882 | 731 |
15289 | 732 isFullscreen = 0; |
733 ShowCursor(); | |
734 mouseHide = NO; | |
735 | |
736 //revert window to previous setting | |
737 [self setFrame:old_view_frame]; | |
738 [self setNeedsDisplay:YES]; | |
16081
72c352edce8f
restore window shadow when quitting fullscreen mode
nplourde
parents:
15909
diff
changeset
|
739 [window setHasShadow:YES]; |
15289 | 740 [window setFrame:old_frame display:YES animate:animate];//zoom-out window with nice useless sfx |
741 } | |
742 } | |
743 | |
744 /* | |
745 Toggle ontop | |
746 */ | |
747 - (void) ontop | |
748 { | |
15320 | 749 if(vo_ontop) |
750 { | |
751 [window setLevel:NSScreenSaverWindowLevel]; | |
752 isOntop = YES; | |
753 } | |
754 else | |
755 { | |
756 [window setLevel:NSNormalWindowLevel]; | |
757 isOntop = NO; | |
758 } | |
15289 | 759 } |
760 | |
761 /* | |
762 Toggle panscan | |
763 */ | |
764 - (void) panscan | |
765 { | |
15331 | 766 panscan_calc(); |
15289 | 767 } |
768 | |
769 /* | |
15327 | 770 Toggle rootwin |
771 */ | |
772 - (void) rootwin | |
773 { | |
774 if(vo_rootwin) | |
775 { | |
776 [window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey)]; | |
777 [window orderBack:self]; | |
778 isRootwin = YES; | |
779 } | |
780 else | |
781 { | |
782 [window setLevel:NSNormalWindowLevel]; | |
783 isRootwin = NO; | |
784 } | |
785 } | |
786 | |
787 /* | |
15289 | 788 Check event for new event |
789 */ | |
790 - (void) check_events | |
791 { | |
792 event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0.0001] inMode:NSEventTrackingRunLoopMode dequeue:YES]; | |
793 [NSApp sendEvent:event]; | |
15612
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
794 |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
795 //update activity every 60 seconds to prevent |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
796 //screensaver from starting up. |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
797 DateTimeRec d; |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
798 unsigned long curTime; |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
799 static unsigned long lastTime = 0; |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
800 |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
801 GetTime(&d); |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
802 DateToSeconds( &d, &curTime); |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
803 |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
804 if( ( (curTime - lastTime) >= 60) || (lastTime == 0)) |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
805 { |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
806 UpdateSystemActivity(UsrActivity); |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
807 lastTime = curTime; |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
808 } |
15289 | 809 } |
810 | |
811 /* | |
15731 | 812 From NSView, respond to key equivalents. |
813 */ | |
814 - (BOOL)performKeyEquivalent:(NSEvent *)theEvent | |
815 { | |
816 switch([theEvent keyCode]) | |
817 { | |
818 case 0x21: [window setAlphaValue: winAlpha-=0.05]; return YES; | |
819 case 0x1e: [window setAlphaValue: winAlpha+=0.05]; return YES; | |
820 } | |
821 return NO; | |
822 } | |
823 | |
824 /* | |
15289 | 825 Process key event |
826 */ | |
827 - (void) keyDown: (NSEvent *) theEvent | |
828 { | |
829 unsigned int key; | |
830 | |
831 switch([theEvent keyCode]) | |
832 { | |
833 case 0x34: | |
834 case 0x24: key = KEY_ENTER; break; | |
835 case 0x35: key = KEY_ESC; break; | |
836 case 0x33: key = KEY_BACKSPACE; break; | |
837 case 0x3A: key = KEY_BACKSPACE; break; | |
838 case 0x3B: key = KEY_BACKSPACE; break; | |
839 case 0x38: key = KEY_BACKSPACE; break; | |
840 case 0x7A: key = KEY_F+1; break; | |
841 case 0x78: key = KEY_F+2; break; | |
842 case 0x63: key = KEY_F+3; break; | |
843 case 0x76: key = KEY_F+4; break; | |
844 case 0x60: key = KEY_F+5; break; | |
845 case 0x61: key = KEY_F+6; break; | |
846 case 0x62: key = KEY_F+7; break; | |
847 case 0x64: key = KEY_F+8; break; | |
848 case 0x65: key = KEY_F+9; break; | |
849 case 0x6D: key = KEY_F+10; break; | |
850 case 0x67: key = KEY_F+11; break; | |
851 case 0x6F: key = KEY_F+12; break; | |
852 case 0x72: key = KEY_INSERT; break; | |
853 case 0x75: key = KEY_DELETE; break; | |
854 case 0x73: key = KEY_HOME; break; | |
855 case 0x77: key = KEY_END; break; | |
856 case 0x45: key = '+'; break; | |
857 case 0x4E: key = '-'; break; | |
858 case 0x30: key = KEY_TAB; break; | |
859 case 0x74: key = KEY_PAGE_UP; break; | |
860 case 0x79: key = KEY_PAGE_DOWN; break; | |
861 case 0x7B: key = KEY_LEFT; break; | |
862 case 0x7C: key = KEY_RIGHT; break; | |
863 case 0x7D: key = KEY_DOWN; break; | |
864 case 0x7E: key = KEY_UP; break; | |
865 case 0x43: key = '*'; break; | |
866 case 0x4B: key = '/'; break; | |
867 case 0x4C: key = KEY_BACKSPACE; break; | |
868 case 0x41: key = KEY_KPDEC; break; | |
869 case 0x52: key = KEY_KP0; break; | |
870 case 0x53: key = KEY_KP1; break; | |
871 case 0x54: key = KEY_KP2; break; | |
872 case 0x55: key = KEY_KP3; break; | |
873 case 0x56: key = KEY_KP4; break; | |
874 case 0x57: key = KEY_KP5; break; | |
875 case 0x58: key = KEY_KP6; break; | |
876 case 0x59: key = KEY_KP7; break; | |
877 case 0x5B: key = KEY_KP8; break; | |
878 case 0x5C: key = KEY_KP9; break; | |
879 default: key = *[[theEvent characters] UTF8String]; break; | |
880 } | |
881 mplayer_put_key(key); | |
882 } | |
883 | |
884 /* | |
885 Process mouse button event | |
886 */ | |
887 - (void) mouseMoved: (NSEvent *) theEvent | |
888 { | |
15327 | 889 if(isFullscreen && !isRootwin) |
15289 | 890 { |
891 ShowCursor(); | |
892 mouseHide = NO; | |
893 } | |
894 } | |
895 | |
896 - (void) mouseDown: (NSEvent *) theEvent | |
897 { | |
898 [self mouseEvent: theEvent]; | |
899 } | |
900 | |
901 - (void) rightMouseDown: (NSEvent *) theEvent | |
902 { | |
903 [self mouseEvent: theEvent]; | |
904 } | |
905 | |
906 - (void) otherMouseDown: (NSEvent *) theEvent | |
907 { | |
908 [self mouseEvent: theEvent]; | |
909 } | |
910 | |
911 - (void) scrollWheel: (NSEvent *) theEvent | |
912 { | |
913 if([theEvent deltaY] > 0) | |
914 mplayer_put_key(MOUSE_BTN3); | |
915 else | |
916 mplayer_put_key(MOUSE_BTN4); | |
917 } | |
918 | |
919 - (void) mouseEvent: (NSEvent *) theEvent | |
920 { | |
921 switch( [theEvent buttonNumber] ) | |
922 { | |
923 case 0: mplayer_put_key(MOUSE_BTN0);break; | |
924 case 1: mplayer_put_key(MOUSE_BTN1);break; | |
925 case 2: mplayer_put_key(MOUSE_BTN2);break; | |
926 } | |
927 } | |
928 | |
929 /* | |
930 NSResponder | |
931 */ | |
932 - (BOOL) acceptsFirstResponder | |
933 { | |
934 return YES; | |
935 } | |
936 | |
937 - (BOOL) becomeFirstResponder | |
938 { | |
939 return YES; | |
940 } | |
941 | |
942 - (BOOL) resignFirstResponder | |
943 { | |
944 return YES; | |
945 } | |
15325 | 946 |
947 - (void)windowWillClose:(NSNotification *)aNotification | |
948 { | |
949 mplayer_put_key(KEY_ESC); | |
950 } | |
951 @end |