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