Mercurial > mplayer.hg
annotate libvo/vo_macosx.m @ 15918:8f6c98310f38
initial translation, synced with 1.12
author | gabrov |
---|---|
date | Mon, 04 Jul 2005 18:29:48 +0000 |
parents | b1bc923b38fe |
children | 72c352edce8f |
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; | |
15909 | 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; | |
15909 | 373 menuItem = (NSMenuItem *)[NSMenuItem separatorItem]; [aspectMenu 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]; | |
15909 | 471 |
472 [self reshape]; | |
15570 | 473 } |
474 | |
475 if(sender == kPanScanCmd) | |
476 { | |
477 vo_panscan = (!(vo_panscan)); | |
478 if(vo_panscan) | |
479 [kPanScanCmd setState:NSOnState]; | |
480 else | |
481 [kPanScanCmd setState:NSOffState]; | |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
482 |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
483 [self panscan]; |
15570 | 484 } |
485 | |
486 if(sender == kAspectOrgCmd) | |
487 { | |
488 movie_aspect = old_movie_aspect; | |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
489 |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
490 if(isFullscreen) |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
491 { |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
492 [self reshape]; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
493 } |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
494 else |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
495 { |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
496 frame.size.width = d_width*winSizeMult; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
497 frame.size.height = (d_width/movie_aspect)*winSizeMult; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
498 [window setContentSize: frame.size]; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
499 [self reshape]; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
500 } |
15570 | 501 } |
502 | |
503 if(sender == kAspectFullCmd) | |
504 { | |
505 movie_aspect = 4.0f/3.0f; | |
15882 | 506 |
507 if(isFullscreen) | |
508 { | |
509 [self reshape]; | |
510 } | |
511 else | |
512 { | |
513 frame.size.width = d_width*winSizeMult; | |
514 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
515 [window setContentSize: frame.size]; | |
516 [self reshape]; | |
517 } | |
15570 | 518 } |
519 | |
520 if(sender == kAspectWideCmd) | |
521 { | |
522 movie_aspect = 16.0f/9.0f; | |
15882 | 523 |
524 if(isFullscreen) | |
525 { | |
526 [self reshape]; | |
527 } | |
528 else | |
529 { | |
530 frame.size.width = d_width*winSizeMult; | |
531 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
532 [window setContentSize: frame.size]; | |
533 [self reshape]; | |
534 } | |
15570 | 535 } |
536 } | |
537 | |
538 /* | |
15289 | 539 Setup OpenGL |
540 */ | |
541 - (void)prepareOpenGL | |
542 { | |
15339 | 543 glEnable(GL_BLEND); |
15289 | 544 glDisable(GL_DEPTH_TEST); |
545 glDepthMask(GL_FALSE); | |
546 glDisable(GL_CULL_FACE); | |
547 [self reshape]; | |
548 } | |
549 | |
550 /* | |
551 reshape OpenGL viewport | |
552 */ | |
553 - (void)reshape | |
554 { | |
555 uint32_t d_width; | |
556 uint32_t d_height; | |
557 float aspectX; | |
558 float aspectY; | |
559 int padding = 0; | |
560 | |
561 NSRect frame = [self frame]; | |
562 | |
563 glViewport(0, 0, frame.size.width, frame.size.height); | |
564 glMatrixMode(GL_PROJECTION); | |
565 glLoadIdentity(); | |
566 glOrtho(0, frame.size.width, frame.size.height, 0, -1.0, 1.0); | |
567 glMatrixMode(GL_MODELVIEW); | |
568 glLoadIdentity(); | |
569 | |
15729 | 570 //set texture frame |
15289 | 571 if(vo_keepaspect) |
572 { | |
15571 | 573 aspect( (int *)&d_width, (int *)&d_height, A_NOZOOM); |
15289 | 574 d_height = ((float)d_width/movie_aspect); |
575 | |
576 aspectX = (float)((float)frame.size.width/(float)d_width); | |
577 aspectY = (float)((float)(frame.size.height)/(float)d_height); | |
578 | |
579 if((d_height*aspectX)>(frame.size.height)) | |
580 { | |
581 padding = (frame.size.width - d_width*aspectY)/2; | |
15729 | 582 textureFrame = NSMakeRect(padding, 0, d_width*aspectY+padding, d_height*aspectY); |
15289 | 583 } |
584 else | |
585 { | |
586 padding = ((frame.size.height) - d_height*aspectX)/2; | |
15729 | 587 textureFrame = NSMakeRect(0, padding, d_width*aspectX, d_height*aspectX+padding); |
15289 | 588 } |
589 } | |
590 else | |
591 { | |
15729 | 592 textureFrame = frame; |
15289 | 593 } |
594 } | |
595 | |
596 /* | |
597 Render frame | |
598 */ | |
599 - (void) render | |
600 { | |
601 glClear(GL_COLOR_BUFFER_BIT); | |
602 | |
603 glEnable(CVOpenGLTextureGetTarget(texture)); | |
604 glBindTexture(CVOpenGLTextureGetTarget(texture), CVOpenGLTextureGetName(texture)); | |
605 | |
606 glColor3f(1,1,1); | |
607 glBegin(GL_QUADS); | |
15729 | 608 glTexCoord2f(upperLeft[0], upperLeft[1]); glVertex2i( textureFrame.origin.x-(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); |
609 glTexCoord2f(lowerLeft[0], lowerLeft[1]); glVertex2i( textureFrame.origin.x-(vo_panscan_x >> 1), textureFrame.size.height+(vo_panscan_y >> 1)); | |
610 glTexCoord2f(lowerRight[0], lowerRight[1]); glVertex2i( textureFrame.size.width+(vo_panscan_x >> 1), textureFrame.size.height+(vo_panscan_y >> 1)); | |
611 glTexCoord2f(upperRight[0], upperRight[1]); glVertex2i( textureFrame.size.width+(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); | |
15289 | 612 glEnd(); |
15339 | 613 glDisable(CVOpenGLTextureGetTarget(texture)); |
614 | |
615 //render resize box | |
616 if(!isFullscreen) | |
617 { | |
618 NSRect frame = [self frame]; | |
619 | |
620 glBegin(GL_LINES); | |
621 glColor4f(0.2, 0.2, 0.2, 0.5); | |
622 glVertex2i(frame.size.width-1, frame.size.height-1); glVertex2i(frame.size.width-1, frame.size.height-1); | |
623 glVertex2i(frame.size.width-1, frame.size.height-5); glVertex2i(frame.size.width-5, frame.size.height-1); | |
624 glVertex2i(frame.size.width-1, frame.size.height-9); glVertex2i(frame.size.width-9, frame.size.height-1); | |
625 | |
626 glColor4f(0.4, 0.4, 0.4, 0.5); | |
627 glVertex2i(frame.size.width-1, frame.size.height-2); glVertex2i(frame.size.width-2, frame.size.height-1); | |
628 glVertex2i(frame.size.width-1, frame.size.height-6); glVertex2i(frame.size.width-6, frame.size.height-1); | |
629 glVertex2i(frame.size.width-1, frame.size.height-10); glVertex2i(frame.size.width-10, frame.size.height-1); | |
630 | |
631 glColor4f(0.6, 0.6, 0.6, 0.5); | |
632 glVertex2i(frame.size.width-1, frame.size.height-3); glVertex2i(frame.size.width-3, frame.size.height-1); | |
633 glVertex2i(frame.size.width-1, frame.size.height-7); glVertex2i(frame.size.width-7, frame.size.height-1); | |
634 glVertex2i(frame.size.width-1, frame.size.height-11); glVertex2i(frame.size.width-11, frame.size.height-1); | |
635 glEnd(); | |
636 } | |
15289 | 637 |
638 glFlush(); | |
639 | |
640 //auto hide mouse cursor and futur on-screen control? | |
15327 | 641 if(isFullscreen && !mouseHide && !isRootwin) |
15289 | 642 { |
643 DateTimeRec d; | |
644 unsigned long curTime; | |
645 static unsigned long lastTime = 0; | |
646 | |
647 GetTime(&d); | |
648 DateToSeconds( &d, &curTime); | |
649 | |
650 if( ((curTime - lastTime) >= 5) || (lastTime == 0) ) | |
651 { | |
652 HideCursor(); | |
653 mouseHide = YES; | |
654 lastTime = curTime; | |
655 } | |
656 } | |
657 } | |
658 | |
659 /* | |
660 Create OpenGL texture from current frame & set texco | |
661 */ | |
662 - (void) setCurrentTexture | |
663 { | |
664 CVReturn error = kCVReturnSuccess; | |
665 | |
666 error = CVOpenGLTextureCacheCreateTextureFromImage (NULL, textureCache, currentFrameBuffer, 0, &texture); | |
667 if(error != kCVReturnSuccess) | |
668 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error); | |
669 | |
670 CVOpenGLTextureGetCleanTexCoords(texture, lowerLeft, lowerRight, upperRight, upperLeft); | |
671 } | |
672 | |
673 /* | |
674 redraw win rect | |
675 */ | |
676 - (void) drawRect: (NSRect *) bounds | |
677 { | |
678 [self render]; | |
679 } | |
680 | |
681 /* | |
682 Toggle Fullscreen | |
683 */ | |
684 - (void) fullscreen: (BOOL) animate | |
685 { | |
686 static NSRect old_frame; | |
687 static NSRect old_view_frame; | |
15728 | 688 |
689 if(screen_force) | |
690 screen_frame = [screen_handle frame]; | |
691 else | |
692 screen_frame = [[window screen] frame]; | |
15289 | 693 |
15573 | 694 panscan_calc(); |
695 | |
15289 | 696 //go fullscreen |
697 if(vo_fs) | |
698 { | |
15327 | 699 if(!isRootwin) |
700 { | |
15882 | 701 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar); |
15327 | 702 HideCursor(); |
703 mouseHide = YES; | |
704 } | |
15289 | 705 |
706 old_frame = [window frame]; //save main window size & position | |
15728 | 707 [window setFrame:screen_frame display:YES animate:animate]; //zoom-in window with nice useless sfx |
15289 | 708 old_view_frame = [self bounds]; |
709 | |
710 //fix origin for multi screen setup | |
15728 | 711 screen_frame.origin.x = 0; |
712 screen_frame.origin.y = 0; | |
713 [self setFrame:screen_frame]; | |
15289 | 714 [self setNeedsDisplay:YES]; |
715 [window setHasShadow:NO]; | |
716 isFullscreen = 1; | |
717 } | |
718 else | |
15882 | 719 { |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
720 SetSystemUIMode( kUIModeNormal, 0); |
15882 | 721 |
15289 | 722 isFullscreen = 0; |
723 ShowCursor(); | |
724 mouseHide = NO; | |
725 | |
726 //revert window to previous setting | |
727 [self setFrame:old_view_frame]; | |
728 [self setNeedsDisplay:YES]; | |
729 [window setHasShadow:NO]; | |
730 [window setFrame:old_frame display:YES animate:animate];//zoom-out window with nice useless sfx | |
731 } | |
732 } | |
733 | |
734 /* | |
735 Toggle ontop | |
736 */ | |
737 - (void) ontop | |
738 { | |
15320 | 739 if(vo_ontop) |
740 { | |
741 [window setLevel:NSScreenSaverWindowLevel]; | |
742 isOntop = YES; | |
743 } | |
744 else | |
745 { | |
746 [window setLevel:NSNormalWindowLevel]; | |
747 isOntop = NO; | |
748 } | |
15289 | 749 } |
750 | |
751 /* | |
752 Toggle panscan | |
753 */ | |
754 - (void) panscan | |
755 { | |
15331 | 756 panscan_calc(); |
15289 | 757 } |
758 | |
759 /* | |
15327 | 760 Toggle rootwin |
761 */ | |
762 - (void) rootwin | |
763 { | |
764 if(vo_rootwin) | |
765 { | |
766 [window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey)]; | |
767 [window orderBack:self]; | |
768 isRootwin = YES; | |
769 } | |
770 else | |
771 { | |
772 [window setLevel:NSNormalWindowLevel]; | |
773 isRootwin = NO; | |
774 } | |
775 } | |
776 | |
777 /* | |
15289 | 778 Check event for new event |
779 */ | |
780 - (void) check_events | |
781 { | |
782 event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0.0001] inMode:NSEventTrackingRunLoopMode dequeue:YES]; | |
783 [NSApp sendEvent:event]; | |
15612
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
784 |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
785 //update activity every 60 seconds to prevent |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
786 //screensaver from starting up. |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
787 DateTimeRec d; |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
788 unsigned long curTime; |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
789 static unsigned long lastTime = 0; |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
790 |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
791 GetTime(&d); |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
792 DateToSeconds( &d, &curTime); |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
793 |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
794 if( ( (curTime - lastTime) >= 60) || (lastTime == 0)) |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
795 { |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
796 UpdateSystemActivity(UsrActivity); |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
797 lastTime = curTime; |
06e30282b170
Moved event update inside cocoa openglview class
nplourde
parents:
15611
diff
changeset
|
798 } |
15289 | 799 } |
800 | |
801 /* | |
15731 | 802 From NSView, respond to key equivalents. |
803 */ | |
804 - (BOOL)performKeyEquivalent:(NSEvent *)theEvent | |
805 { | |
806 switch([theEvent keyCode]) | |
807 { | |
808 case 0x21: [window setAlphaValue: winAlpha-=0.05]; return YES; | |
809 case 0x1e: [window setAlphaValue: winAlpha+=0.05]; return YES; | |
810 } | |
811 return NO; | |
812 } | |
813 | |
814 /* | |
15289 | 815 Process key event |
816 */ | |
817 - (void) keyDown: (NSEvent *) theEvent | |
818 { | |
819 unsigned int key; | |
820 | |
821 switch([theEvent keyCode]) | |
822 { | |
823 case 0x34: | |
824 case 0x24: key = KEY_ENTER; break; | |
825 case 0x35: key = KEY_ESC; break; | |
826 case 0x33: key = KEY_BACKSPACE; break; | |
827 case 0x3A: key = KEY_BACKSPACE; break; | |
828 case 0x3B: key = KEY_BACKSPACE; break; | |
829 case 0x38: key = KEY_BACKSPACE; break; | |
830 case 0x7A: key = KEY_F+1; break; | |
831 case 0x78: key = KEY_F+2; break; | |
832 case 0x63: key = KEY_F+3; break; | |
833 case 0x76: key = KEY_F+4; break; | |
834 case 0x60: key = KEY_F+5; break; | |
835 case 0x61: key = KEY_F+6; break; | |
836 case 0x62: key = KEY_F+7; break; | |
837 case 0x64: key = KEY_F+8; break; | |
838 case 0x65: key = KEY_F+9; break; | |
839 case 0x6D: key = KEY_F+10; break; | |
840 case 0x67: key = KEY_F+11; break; | |
841 case 0x6F: key = KEY_F+12; break; | |
842 case 0x72: key = KEY_INSERT; break; | |
843 case 0x75: key = KEY_DELETE; break; | |
844 case 0x73: key = KEY_HOME; break; | |
845 case 0x77: key = KEY_END; break; | |
846 case 0x45: key = '+'; break; | |
847 case 0x4E: key = '-'; break; | |
848 case 0x30: key = KEY_TAB; break; | |
849 case 0x74: key = KEY_PAGE_UP; break; | |
850 case 0x79: key = KEY_PAGE_DOWN; break; | |
851 case 0x7B: key = KEY_LEFT; break; | |
852 case 0x7C: key = KEY_RIGHT; break; | |
853 case 0x7D: key = KEY_DOWN; break; | |
854 case 0x7E: key = KEY_UP; break; | |
855 case 0x43: key = '*'; break; | |
856 case 0x4B: key = '/'; break; | |
857 case 0x4C: key = KEY_BACKSPACE; break; | |
858 case 0x41: key = KEY_KPDEC; break; | |
859 case 0x52: key = KEY_KP0; break; | |
860 case 0x53: key = KEY_KP1; break; | |
861 case 0x54: key = KEY_KP2; break; | |
862 case 0x55: key = KEY_KP3; break; | |
863 case 0x56: key = KEY_KP4; break; | |
864 case 0x57: key = KEY_KP5; break; | |
865 case 0x58: key = KEY_KP6; break; | |
866 case 0x59: key = KEY_KP7; break; | |
867 case 0x5B: key = KEY_KP8; break; | |
868 case 0x5C: key = KEY_KP9; break; | |
869 default: key = *[[theEvent characters] UTF8String]; break; | |
870 } | |
871 mplayer_put_key(key); | |
872 } | |
873 | |
874 /* | |
875 Process mouse button event | |
876 */ | |
877 - (void) mouseMoved: (NSEvent *) theEvent | |
878 { | |
15327 | 879 if(isFullscreen && !isRootwin) |
15289 | 880 { |
881 ShowCursor(); | |
882 mouseHide = NO; | |
883 } | |
884 } | |
885 | |
886 - (void) mouseDown: (NSEvent *) theEvent | |
887 { | |
888 [self mouseEvent: theEvent]; | |
889 } | |
890 | |
891 - (void) rightMouseDown: (NSEvent *) theEvent | |
892 { | |
893 [self mouseEvent: theEvent]; | |
894 } | |
895 | |
896 - (void) otherMouseDown: (NSEvent *) theEvent | |
897 { | |
898 [self mouseEvent: theEvent]; | |
899 } | |
900 | |
901 - (void) scrollWheel: (NSEvent *) theEvent | |
902 { | |
903 if([theEvent deltaY] > 0) | |
904 mplayer_put_key(MOUSE_BTN3); | |
905 else | |
906 mplayer_put_key(MOUSE_BTN4); | |
907 } | |
908 | |
909 - (void) mouseEvent: (NSEvent *) theEvent | |
910 { | |
911 switch( [theEvent buttonNumber] ) | |
912 { | |
913 case 0: mplayer_put_key(MOUSE_BTN0);break; | |
914 case 1: mplayer_put_key(MOUSE_BTN1);break; | |
915 case 2: mplayer_put_key(MOUSE_BTN2);break; | |
916 } | |
917 } | |
918 | |
919 /* | |
920 NSResponder | |
921 */ | |
922 - (BOOL) acceptsFirstResponder | |
923 { | |
924 return YES; | |
925 } | |
926 | |
927 - (BOOL) becomeFirstResponder | |
928 { | |
929 return YES; | |
930 } | |
931 | |
932 - (BOOL) resignFirstResponder | |
933 { | |
934 return YES; | |
935 } | |
15325 | 936 |
937 - (void)windowWillClose:(NSNotification *)aNotification | |
938 { | |
939 mplayer_put_key(KEY_ESC); | |
940 } | |
941 @end |