Mercurial > mplayer.hg
annotate libvo/vo_macosx.m @ 15745:3d712cf823c0
Sync with 1.1010
author | gpoirier |
---|---|
date | Fri, 17 Jun 2005 11:31:25 +0000 |
parents | 0c3939433cef |
children | fbf14e1ab725 |
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 | |
280 window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 0, 0) | |
281 styleMask:NSTitledWindowMask|NSTexturedBackgroundWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask | |
282 backing:NSBackingStoreBuffered defer:NO]; | |
283 | |
284 [window autorelease]; | |
285 [window setDelegate:mpGLView]; | |
286 [window setContentView:mpGLView]; | |
287 [window setInitialFirstResponder:mpGLView]; | |
288 [window setAcceptsMouseMovedEvents:YES]; | |
289 [window setTitle:@"MPlayer - The Movie Player"]; | |
290 | |
291 isFullscreen = 0; | |
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]; | |
15726 | 311 [glContext autorelease]; |
15647 | 312 |
15289 | 313 [self setOpenGLContext:glContext]; |
15647 | 314 [glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval]; |
15289 | 315 [glContext setView:self]; |
316 [glContext makeCurrentContext]; | |
317 | |
15647 | 318 error = CVPixelBufferCreateWithBytes( NULL, image_width, image_height, pixelFormat, image_data, image_width*image_bytes, NULL, NULL, NULL, ¤tFrameBuffer); |
15289 | 319 if(error != kCVReturnSuccess) |
320 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create Pixel Buffer(%d)\n", error); | |
321 | |
322 error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache); | |
323 if(error != kCVReturnSuccess) | |
324 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture Cache(%d)\n", error); | |
325 | |
326 error = CVOpenGLTextureCacheCreateTextureFromImage( NULL, textureCache, currentFrameBuffer, 0, &texture); | |
327 if(error != kCVReturnSuccess) | |
328 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error); | |
329 | |
15728 | 330 //show window |
331 [window center]; | |
332 [window makeKeyAndOrderFront:mpGLView]; | |
333 | |
15726 | 334 if(vo_rootwin) |
335 [mpGLView rootwin]; | |
336 | |
337 if(vo_fs) | |
338 [mpGLView fullscreen: NO]; | |
339 | |
340 if(vo_ontop) | |
341 [mpGLView ontop]; | |
15289 | 342 } |
343 | |
344 /* | |
15570 | 345 Init Menu |
346 */ | |
347 - (void)initMenu | |
348 { | |
349 NSMenu *menu; | |
350 NSMenuItem *menuItem; | |
351 | |
352 [NSApp setMainMenu:[[NSMenu alloc] init]]; | |
353 | |
354 //Create Movie Menu | |
355 menu = [[NSMenu alloc] initWithTitle:@"Movie"]; | |
356 menuItem = [[NSMenuItem alloc] initWithTitle:@"Half Size" action:@selector(menuAction:) keyEquivalent:@"0"]; [menu addItem:menuItem]; | |
357 kHalfScreenCmd = menuItem; | |
358 menuItem = [[NSMenuItem alloc] initWithTitle:@"Normal Size" action:@selector(menuAction:) keyEquivalent:@"1"]; [menu addItem:menuItem]; | |
359 kNormalScreenCmd = menuItem; | |
360 menuItem = [[NSMenuItem alloc] initWithTitle:@"Double Size" action:@selector(menuAction:) keyEquivalent:@"2"]; [menu addItem:menuItem]; | |
361 kDoubleScreenCmd = menuItem; | |
362 menuItem = [[NSMenuItem alloc] initWithTitle:@"Full Size" action:@selector(menuAction:) keyEquivalent:@"f"]; [menu addItem:menuItem]; | |
363 kFullScreenCmd = menuItem; | |
15727 | 364 menuItem = (NSMenuItem *)[NSMenuItem separatorItem]; [menu addItem:menuItem]; |
15570 | 365 |
366 NSMenu *aspectMenu; | |
367 aspectMenu = [[NSMenu alloc] initWithTitle:@"Aspect Ratio"]; | |
368 menuItem = [[NSMenuItem alloc] initWithTitle:@"Keep" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
369 if(vo_keepaspect) [menuItem setState:NSOnState]; | |
370 kKeepAspectCmd = menuItem; | |
371 menuItem = [[NSMenuItem alloc] initWithTitle:@"Pan-Scan" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
372 if(vo_panscan) [menuItem setState:NSOnState]; | |
373 kPanScanCmd = menuItem; | |
15727 | 374 menuItem = (NSMenuItem *)[NSMenuItem separatorItem]; [menu addItem:menuItem]; |
15570 | 375 menuItem = [[NSMenuItem alloc] initWithTitle:@"Original" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; |
376 kAspectOrgCmd = menuItem; | |
377 menuItem = [[NSMenuItem alloc] initWithTitle:@"4:3" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
378 kAspectFullCmd = menuItem; | |
379 menuItem = [[NSMenuItem alloc] initWithTitle:@"16:9" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
380 kAspectWideCmd = menuItem; | |
381 menuItem = [[NSMenuItem alloc] initWithTitle:@"Aspect Ratio" action:nil keyEquivalent:@""]; | |
382 [menuItem setSubmenu:aspectMenu]; | |
383 [menu addItem:menuItem]; | |
384 [aspectMenu release]; | |
385 | |
386 //Add to menubar | |
387 menuItem = [[NSMenuItem alloc] initWithTitle:@"Movie" action:nil keyEquivalent:@""]; | |
388 [menuItem setSubmenu:menu]; | |
389 [[NSApp mainMenu] addItem:menuItem]; | |
390 | |
391 //Create Window Menu | |
392 menu = [[NSMenu alloc] initWithTitle:@"Window"]; | |
393 | |
394 menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; [menu addItem:menuItem]; | |
395 menuItem = [[NSMenuItem alloc] initWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""]; [menu addItem:menuItem]; | |
396 | |
397 //Add to menubar | |
398 menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; | |
399 [menuItem setSubmenu:menu]; | |
400 [[NSApp mainMenu] addItem:menuItem]; | |
401 [NSApp setWindowsMenu:menu]; | |
402 | |
403 [menu release]; | |
404 [menuItem release]; | |
405 } | |
406 | |
407 /* | |
408 Menu Action | |
409 */ | |
410 - (void)menuAction:(id)sender | |
411 { | |
412 uint32_t d_width; | |
413 uint32_t d_height; | |
414 NSRect frame; | |
415 | |
416 aspect((int *)&d_width, (int *)&d_height,A_NOZOOM); | |
15731 | 417 |
418 if(sender == kQuitCmd) | |
419 { | |
420 mplayer_put_key(KEY_ESC); | |
421 } | |
15570 | 422 |
423 if(sender == kHalfScreenCmd) | |
424 { | |
425 if(isFullscreen) { | |
426 vo_fs = (!(vo_fs)); [self fullscreen:YES]; | |
427 } | |
428 | |
429 frame.size.width = (d_width/2); | |
430 frame.size.height = ((d_width/movie_aspect)/2); | |
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 | |
440 frame.size.width = d_width; | |
441 frame.size.height = d_width/movie_aspect; | |
442 [window setContentSize: frame.size]; | |
443 [self reshape]; | |
444 } | |
445 if(sender == kDoubleScreenCmd) | |
446 { | |
447 if(isFullscreen) { | |
448 vo_fs = (!(vo_fs)); [self fullscreen:YES]; | |
449 } | |
450 | |
451 frame.size.width = d_width*2; | |
452 frame.size.height = (d_width/movie_aspect)*2; | |
453 [window setContentSize: frame.size]; | |
454 [self reshape]; | |
455 } | |
456 if(sender == kFullScreenCmd) | |
457 { | |
458 vo_fs = (!(vo_fs)); | |
459 [self fullscreen:YES]; | |
460 } | |
461 | |
462 if(sender == kKeepAspectCmd) | |
463 { | |
464 vo_keepaspect = (!(vo_keepaspect)); | |
465 if(vo_keepaspect) | |
466 [kKeepAspectCmd setState:NSOnState]; | |
467 else | |
468 [kKeepAspectCmd setState:NSOffState]; | |
469 } | |
470 | |
471 if(sender == kPanScanCmd) | |
472 { | |
473 vo_panscan = (!(vo_panscan)); | |
474 if(vo_panscan) | |
475 [kPanScanCmd setState:NSOnState]; | |
476 else | |
477 [kPanScanCmd setState:NSOffState]; | |
478 } | |
479 | |
480 if(sender == kAspectOrgCmd) | |
481 { | |
482 movie_aspect = old_movie_aspect; | |
483 frame.size.width = d_width; | |
484 frame.size.height = d_width/movie_aspect; | |
485 [window setContentSize: frame.size]; | |
486 [self reshape]; | |
487 } | |
488 | |
489 if(sender == kAspectFullCmd) | |
490 { | |
491 movie_aspect = 4.0f/3.0f; | |
492 frame.size.width = d_width; | |
493 frame.size.height = d_width/movie_aspect; | |
494 [window setContentSize: frame.size]; | |
495 [self reshape]; | |
496 } | |
497 | |
498 if(sender == kAspectWideCmd) | |
499 { | |
500 movie_aspect = 16.0f/9.0f; | |
501 frame.size.width = d_width; | |
502 frame.size.height = d_width/movie_aspect; | |
503 [window setContentSize: frame.size]; | |
504 [self reshape]; | |
505 } | |
506 } | |
507 | |
508 /* | |
15289 | 509 Setup OpenGL |
510 */ | |
511 - (void)prepareOpenGL | |
512 { | |
15339 | 513 glEnable(GL_BLEND); |
15289 | 514 glDisable(GL_DEPTH_TEST); |
515 glDepthMask(GL_FALSE); | |
516 glDisable(GL_CULL_FACE); | |
517 [self reshape]; | |
518 } | |
519 | |
520 /* | |
521 reshape OpenGL viewport | |
522 */ | |
523 - (void)reshape | |
524 { | |
525 uint32_t d_width; | |
526 uint32_t d_height; | |
527 float aspectX; | |
528 float aspectY; | |
529 int padding = 0; | |
530 | |
531 NSRect frame = [self frame]; | |
532 | |
533 glViewport(0, 0, frame.size.width, frame.size.height); | |
534 glMatrixMode(GL_PROJECTION); | |
535 glLoadIdentity(); | |
536 glOrtho(0, frame.size.width, frame.size.height, 0, -1.0, 1.0); | |
537 glMatrixMode(GL_MODELVIEW); | |
538 glLoadIdentity(); | |
539 | |
15729 | 540 //set texture frame |
15289 | 541 if(vo_keepaspect) |
542 { | |
15571 | 543 aspect( (int *)&d_width, (int *)&d_height, A_NOZOOM); |
15289 | 544 d_height = ((float)d_width/movie_aspect); |
545 | |
546 aspectX = (float)((float)frame.size.width/(float)d_width); | |
547 aspectY = (float)((float)(frame.size.height)/(float)d_height); | |
548 | |
549 if((d_height*aspectX)>(frame.size.height)) | |
550 { | |
551 padding = (frame.size.width - d_width*aspectY)/2; | |
15729 | 552 textureFrame = NSMakeRect(padding, 0, d_width*aspectY+padding, d_height*aspectY); |
15289 | 553 } |
554 else | |
555 { | |
556 padding = ((frame.size.height) - d_height*aspectX)/2; | |
15729 | 557 textureFrame = NSMakeRect(0, padding, d_width*aspectX, d_height*aspectX+padding); |
15289 | 558 } |
559 } | |
560 else | |
561 { | |
15729 | 562 textureFrame = frame; |
15289 | 563 } |
564 } | |
565 | |
566 /* | |
567 Render frame | |
568 */ | |
569 - (void) render | |
570 { | |
571 glClear(GL_COLOR_BUFFER_BIT); | |
572 | |
573 glEnable(CVOpenGLTextureGetTarget(texture)); | |
574 glBindTexture(CVOpenGLTextureGetTarget(texture), CVOpenGLTextureGetName(texture)); | |
575 | |
576 glColor3f(1,1,1); | |
577 glBegin(GL_QUADS); | |
15729 | 578 glTexCoord2f(upperLeft[0], upperLeft[1]); glVertex2i( textureFrame.origin.x-(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); |
579 glTexCoord2f(lowerLeft[0], lowerLeft[1]); glVertex2i( textureFrame.origin.x-(vo_panscan_x >> 1), textureFrame.size.height+(vo_panscan_y >> 1)); | |
580 glTexCoord2f(lowerRight[0], lowerRight[1]); glVertex2i( textureFrame.size.width+(vo_panscan_x >> 1), textureFrame.size.height+(vo_panscan_y >> 1)); | |
581 glTexCoord2f(upperRight[0], upperRight[1]); glVertex2i( textureFrame.size.width+(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); | |
15289 | 582 glEnd(); |
15339 | 583 glDisable(CVOpenGLTextureGetTarget(texture)); |
584 | |
585 //render resize box | |
586 if(!isFullscreen) | |
587 { | |
588 NSRect frame = [self frame]; | |
589 | |
590 glBegin(GL_LINES); | |
591 glColor4f(0.2, 0.2, 0.2, 0.5); | |
592 glVertex2i(frame.size.width-1, frame.size.height-1); glVertex2i(frame.size.width-1, frame.size.height-1); | |
593 glVertex2i(frame.size.width-1, frame.size.height-5); glVertex2i(frame.size.width-5, frame.size.height-1); | |
594 glVertex2i(frame.size.width-1, frame.size.height-9); glVertex2i(frame.size.width-9, frame.size.height-1); | |
595 | |
596 glColor4f(0.4, 0.4, 0.4, 0.5); | |
597 glVertex2i(frame.size.width-1, frame.size.height-2); glVertex2i(frame.size.width-2, frame.size.height-1); | |
598 glVertex2i(frame.size.width-1, frame.size.height-6); glVertex2i(frame.size.width-6, frame.size.height-1); | |
599 glVertex2i(frame.size.width-1, frame.size.height-10); glVertex2i(frame.size.width-10, frame.size.height-1); | |
600 | |
601 glColor4f(0.6, 0.6, 0.6, 0.5); | |
602 glVertex2i(frame.size.width-1, frame.size.height-3); glVertex2i(frame.size.width-3, frame.size.height-1); | |
603 glVertex2i(frame.size.width-1, frame.size.height-7); glVertex2i(frame.size.width-7, frame.size.height-1); | |
604 glVertex2i(frame.size.width-1, frame.size.height-11); glVertex2i(frame.size.width-11, frame.size.height-1); | |
605 glEnd(); | |
606 } | |
15289 | 607 |
608 glFlush(); | |
609 | |
610 //auto hide mouse cursor and futur on-screen control? | |
15327 | 611 if(isFullscreen && !mouseHide && !isRootwin) |
15289 | 612 { |
613 DateTimeRec d; | |
614 unsigned long curTime; | |
615 static unsigned long lastTime = 0; | |
616 | |
617 GetTime(&d); | |
618 DateToSeconds( &d, &curTime); | |
619 | |
620 if( ((curTime - lastTime) >= 5) || (lastTime == 0) ) | |
621 { | |
622 HideMenuBar(); | |
623 HideCursor(); | |
624 mouseHide = YES; | |
625 lastTime = curTime; | |
626 } | |
627 } | |
628 } | |
629 | |
630 /* | |
631 Create OpenGL texture from current frame & set texco | |
632 */ | |
633 - (void) setCurrentTexture | |
634 { | |
635 CVReturn error = kCVReturnSuccess; | |
636 | |
637 error = CVOpenGLTextureCacheCreateTextureFromImage (NULL, textureCache, currentFrameBuffer, 0, &texture); | |
638 if(error != kCVReturnSuccess) | |
639 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error); | |
640 | |
641 CVOpenGLTextureGetCleanTexCoords(texture, lowerLeft, lowerRight, upperRight, upperLeft); | |
642 } | |
643 | |
644 /* | |
645 redraw win rect | |
646 */ | |
647 - (void) drawRect: (NSRect *) bounds | |
648 { | |
649 [self render]; | |
650 } | |
651 | |
652 /* | |
653 Toggle Fullscreen | |
654 */ | |
655 - (void) fullscreen: (BOOL) animate | |
656 { | |
657 static NSRect old_frame; | |
658 static NSRect old_view_frame; | |
15728 | 659 |
660 if(screen_force) | |
661 screen_frame = [screen_handle frame]; | |
662 else | |
663 screen_frame = [[window screen] frame]; | |
15289 | 664 |
15573 | 665 panscan_calc(); |
666 | |
15289 | 667 //go fullscreen |
668 if(vo_fs) | |
669 { | |
15327 | 670 if(!isRootwin) |
671 { | |
672 //hide menubar and mouse if fullscreen on main display | |
673 HideMenuBar(); | |
674 HideCursor(); | |
675 mouseHide = YES; | |
676 } | |
15289 | 677 |
678 old_frame = [window frame]; //save main window size & position | |
15728 | 679 [window setFrame:screen_frame display:YES animate:animate]; //zoom-in window with nice useless sfx |
15289 | 680 old_view_frame = [self bounds]; |
681 | |
682 //fix origin for multi screen setup | |
15728 | 683 screen_frame.origin.x = 0; |
684 screen_frame.origin.y = 0; | |
685 [self setFrame:screen_frame]; | |
15289 | 686 [self setNeedsDisplay:YES]; |
687 [window setHasShadow:NO]; | |
688 isFullscreen = 1; | |
689 } | |
690 else | |
691 { | |
692 isFullscreen = 0; | |
693 ShowMenuBar(); | |
694 ShowCursor(); | |
695 mouseHide = NO; | |
696 | |
697 //revert window to previous setting | |
698 [self setFrame:old_view_frame]; | |
699 [self setNeedsDisplay:YES]; | |
700 [window setHasShadow:NO]; | |
701 [window setFrame:old_frame display:YES animate:animate];//zoom-out window with nice useless sfx | |
702 } | |
703 } | |
704 | |
705 /* | |
706 Toggle ontop | |
707 */ | |
708 - (void) ontop | |
709 { | |
15320 | 710 if(vo_ontop) |
711 { | |
712 [window setLevel:NSScreenSaverWindowLevel]; | |
713 isOntop = YES; | |
714 } | |
715 else | |
716 { | |
717 [window setLevel:NSNormalWindowLevel]; | |
718 isOntop = NO; | |
719 } | |
15289 | 720 } |
721 | |
722 /* | |
723 Toggle panscan | |
724 */ | |
725 - (void) panscan | |
726 { | |
15331 | 727 panscan_calc(); |
15289 | 728 } |
729 | |
730 /* | |
15327 | 731 Toggle rootwin |
732 */ | |
733 - (void) rootwin | |
734 { | |
735 if(vo_rootwin) | |
736 { | |
737 [window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey)]; | |
738 [window orderBack:self]; | |
739 isRootwin = YES; | |
740 } | |
741 else | |
742 { | |
743 [window setLevel:NSNormalWindowLevel]; | |
744 isRootwin = NO; | |
745 } | |
746 } | |
747 | |
748 /* | |
15289 | 749 Check event for new event |
750 */ | |
751 - (void) check_events | |
752 { | |
753 event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0.0001] inMode:NSEventTrackingRunLoopMode dequeue:YES]; | |
754 [NSApp sendEvent:event]; | |
15612
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
755 |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
756 //update activity every 60 seconds to prevent |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
757 //screensaver from starting up. |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
758 DateTimeRec d; |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
759 unsigned long curTime; |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
760 static unsigned long lastTime = 0; |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
761 |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
762 GetTime(&d); |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
763 DateToSeconds( &d, &curTime); |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
764 |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
765 if( ( (curTime - lastTime) >= 60) || (lastTime == 0)) |
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 UpdateSystemActivity(UsrActivity); |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
768 lastTime = curTime; |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
769 } |
15289 | 770 } |
771 | |
772 /* | |
15731 | 773 From NSView, respond to key equivalents. |
774 */ | |
775 - (BOOL)performKeyEquivalent:(NSEvent *)theEvent | |
776 { | |
777 switch([theEvent keyCode]) | |
778 { | |
779 case 0x21: [window setAlphaValue: winAlpha-=0.05]; return YES; | |
780 case 0x1e: [window setAlphaValue: winAlpha+=0.05]; return YES; | |
781 } | |
782 return NO; | |
783 } | |
784 | |
785 /* | |
15289 | 786 Process key event |
787 */ | |
788 - (void) keyDown: (NSEvent *) theEvent | |
789 { | |
790 unsigned int key; | |
791 | |
792 switch([theEvent keyCode]) | |
793 { | |
794 case 0x34: | |
795 case 0x24: key = KEY_ENTER; break; | |
796 case 0x35: key = KEY_ESC; break; | |
797 case 0x33: key = KEY_BACKSPACE; break; | |
798 case 0x3A: key = KEY_BACKSPACE; break; | |
799 case 0x3B: key = KEY_BACKSPACE; break; | |
800 case 0x38: key = KEY_BACKSPACE; break; | |
801 case 0x7A: key = KEY_F+1; break; | |
802 case 0x78: key = KEY_F+2; break; | |
803 case 0x63: key = KEY_F+3; break; | |
804 case 0x76: key = KEY_F+4; break; | |
805 case 0x60: key = KEY_F+5; break; | |
806 case 0x61: key = KEY_F+6; break; | |
807 case 0x62: key = KEY_F+7; break; | |
808 case 0x64: key = KEY_F+8; break; | |
809 case 0x65: key = KEY_F+9; break; | |
810 case 0x6D: key = KEY_F+10; break; | |
811 case 0x67: key = KEY_F+11; break; | |
812 case 0x6F: key = KEY_F+12; break; | |
813 case 0x72: key = KEY_INSERT; break; | |
814 case 0x75: key = KEY_DELETE; break; | |
815 case 0x73: key = KEY_HOME; break; | |
816 case 0x77: key = KEY_END; break; | |
817 case 0x45: key = '+'; break; | |
818 case 0x4E: key = '-'; break; | |
819 case 0x30: key = KEY_TAB; break; | |
820 case 0x74: key = KEY_PAGE_UP; break; | |
821 case 0x79: key = KEY_PAGE_DOWN; break; | |
822 case 0x7B: key = KEY_LEFT; break; | |
823 case 0x7C: key = KEY_RIGHT; break; | |
824 case 0x7D: key = KEY_DOWN; break; | |
825 case 0x7E: key = KEY_UP; break; | |
826 case 0x43: key = '*'; break; | |
827 case 0x4B: key = '/'; break; | |
828 case 0x4C: key = KEY_BACKSPACE; break; | |
829 case 0x41: key = KEY_KPDEC; break; | |
830 case 0x52: key = KEY_KP0; break; | |
831 case 0x53: key = KEY_KP1; break; | |
832 case 0x54: key = KEY_KP2; break; | |
833 case 0x55: key = KEY_KP3; break; | |
834 case 0x56: key = KEY_KP4; break; | |
835 case 0x57: key = KEY_KP5; break; | |
836 case 0x58: key = KEY_KP6; break; | |
837 case 0x59: key = KEY_KP7; break; | |
838 case 0x5B: key = KEY_KP8; break; | |
839 case 0x5C: key = KEY_KP9; break; | |
840 default: key = *[[theEvent characters] UTF8String]; break; | |
841 } | |
842 mplayer_put_key(key); | |
843 } | |
844 | |
845 /* | |
846 Process mouse button event | |
847 */ | |
848 - (void) mouseMoved: (NSEvent *) theEvent | |
849 { | |
15327 | 850 if(isFullscreen && !isRootwin) |
15289 | 851 { |
852 ShowMenuBar(); | |
853 ShowCursor(); | |
854 mouseHide = NO; | |
855 } | |
856 } | |
857 | |
858 - (void) mouseDown: (NSEvent *) theEvent | |
859 { | |
860 [self mouseEvent: theEvent]; | |
861 } | |
862 | |
863 - (void) rightMouseDown: (NSEvent *) theEvent | |
864 { | |
865 [self mouseEvent: theEvent]; | |
866 } | |
867 | |
868 - (void) otherMouseDown: (NSEvent *) theEvent | |
869 { | |
870 [self mouseEvent: theEvent]; | |
871 } | |
872 | |
873 - (void) scrollWheel: (NSEvent *) theEvent | |
874 { | |
875 if([theEvent deltaY] > 0) | |
876 mplayer_put_key(MOUSE_BTN3); | |
877 else | |
878 mplayer_put_key(MOUSE_BTN4); | |
879 } | |
880 | |
881 - (void) mouseEvent: (NSEvent *) theEvent | |
882 { | |
883 switch( [theEvent buttonNumber] ) | |
884 { | |
885 case 0: mplayer_put_key(MOUSE_BTN0);break; | |
886 case 1: mplayer_put_key(MOUSE_BTN1);break; | |
887 case 2: mplayer_put_key(MOUSE_BTN2);break; | |
888 } | |
889 } | |
890 | |
891 /* | |
892 NSResponder | |
893 */ | |
894 - (BOOL) acceptsFirstResponder | |
895 { | |
896 return YES; | |
897 } | |
898 | |
899 - (BOOL) becomeFirstResponder | |
900 { | |
901 return YES; | |
902 } | |
903 | |
904 - (BOOL) resignFirstResponder | |
905 { | |
906 return YES; | |
907 } | |
15325 | 908 |
909 - (void)windowWillClose:(NSNotification *)aNotification | |
910 { | |
911 mplayer_put_key(KEY_ESC); | |
912 } | |
913 @end |